**mod#game#com/mod/145572**](mod#game#com/mod/145572)### Script Hook RDR2 SDK:主要编译是基于ScriptHookRDR2.dll,当游戏更新时,只需要更新ScriptHookRDR2.dll即可,一般情况开发文件不需要进行更新,不过不排除特殊情况。### DeBug: - 如果想让游戏重新加载asi脚本,但不想重启游戏,只需在游戏目录中创建一个空的“ScriptHookRDR2.dev”文件,然后在游戏中按“Ctrl+R”,听到“滴”的声音,即表示脚本卸载完成,再次按“Ctrl+R”,听到“滴滴滴”的声音,即表示脚本加载完成;- 若想让DeBug功能在游戏中正常工作,必须在主函数“DllMain()”中调用“scriptUnregister()”方法,具体请查阅“NativeTrainer\main.cpp”中的代码;- 脚本重载只适用于正常加载的*.asi文件,不支持加载中途加入的*.asi文件,
[比如说,游戏运行时有个test.asi文件,如果先按“Ctrl+R”卸载,然后加一个“test2.asi”文件,重载的时候将无法识别新的“test2.asi”文件]### Keyboard hook: - 你必须使用keyboard hook 代替 GetKeyState/GetAsyncKeyState API,这样才能确保所有按键都可以正常工作; - 需要在主函数“DllMain()”中调用keyboardHandlerRegister() /keyboardHandlerUnregister()函数来处理按键操作的加载/卸载;- 具体详细可参看NativeTrainer\main.cpp中的代码示例;### 实体示例: - 游戏当前使用的实体都储存在pools中,每种类型的实体都有一个单独的pools,使用“worldGetAllVehicles()”方法可以让您访问任何类型的实体; - 在访问这些实体时,请注意,不是通过脚本创建许多实体,所以脚本对实体并没有完全的控制权,如果您想防止实体被游戏删除或想删除实体,则需要将实体转换为“任务实体[[SET_ENTITY_AS_MISSION_ENTITY](mod#game#com/NativeDB/536)]”来获取完全控制权,未设置为任务实体的实体随时都可能被游戏删除,因此,我们需要在脚本执行的间隔中调用一下这些实体(即WAIT (0)函数的调用)- 原始脚本也遵循上面的规则,如同时使用从世界访问实体“[GET_PED_NEARBY_VEHICLES [获取ped周围的载具]](mod#game#com/NativeDB/1300)”和“[GET_PED_NEARBY_PEDS [获取ped周围的ped]](mod#game#com/NativeDB/1301)”时,也请调用 “[IS_ENTITY_A_MISSION_ENTITY [是否为任务实体]](mod#game#com/NativeDB/441)”和“[SET_ENTITY_AS_MISSION_ENTITY [设置为任务实体]](mod#game#com/NativeDB/536)” - 可以在Pools\script.cpp中查看实体相关的代码示例;### 编译: - 实例中的脚本需要“Visual Studio 2013”或更高的版本才能正常编译 ### 使用条款: - 您只能使用此SDK编译/制作线下的脚本Mod,禁止用于线上; - 您在发布脚本时,请勿包含“ScriptHookRDR2.dll”文件,需要将ScriptHookRDR2.dll的下载指向 [www#dev-c#com/rdr2/scripthookrdr2/](www#dev-c#com/rdr2/scripthookrdr2/) ,以避免玩家下载的Script Hook RDR2不是最新版本;### 实例- 压缩包中包含 “NativeTrainer”和 Pools的源码,如需获取更多详细,请自行查看NativeTrainer\script.cpp和Pools\script.cpp* * *### EN:; THIS ARCHIVE REDISTRIBUTION IS NOT ALLOWED, USE THE FOLLOWING LINK INSTEAD; www#dev-c#com/rdr2/scripthookrdr2/SCRIPT HOOK RDR 2 SDKv1#0#1207.731\. General conceptThe main concept is that your compiled script plugin depends only on ScriptHookRDR2.dll,so when the game updates the only thing that user must do in order to make yourscript working again is to update script hook runtime (i.e. ScriptHookRDR2.dll).2\. Changesv1#0#1207.73- initial release3\. FeaturesRuntime asi script reloading:In order to use this feature you must create empty file called "ScriptHookRDR2.dev"in you game’s main dir. While being ingame press CTRL + R, beep sound will tellyou that all loaded scripts are fully unloaded and you can replace your *.asi,press CTRL + R again to load the scripts, triple beep will indicate thateverything is loaded. You must have the call to scriptUnregister() SDK func inyour plugin’s DllMain in order reloading feature to work correctly, seeNativeTrainer\main.cpp for more details.Script reloading can be applied only to the *.asi plugins which were loadednormally, i.e. using asi loader when the game was started. Script reloading isperformed by script hook and not by asi loader.Keyboard hook:You must use keyboard hook instead of GetKeyState/GetAsyncKeyState WIN API funcs,because it guarantees that all key presses will be handled correctly. Keyboardhandler must be registered/unregistered in DllMain of your plugin using SDK funcskeyboardHandlerRegister/keyboardHandlerUnregister, see NativeTrainer\main.cpp formore details. Example of using keyboard hook can be found in NativeTrainer\keyboard.cpp, thetrainer script is using keyboard.cpp provided functions, your projects should dothe same.Entity pools:All entities that game currently uses are stored in pools, each type of entityhas a separate pool. Using SDK funcs worldGetAllVehicles/Peds/Objects you canaccess any entity you need.While accessing these pools you should remember that lots of entities are beingcreated not by scripts, so scripts have no full control over that entities andfor ex. if you want to prevent entity from deletion by the engine or delete itby yourself you will need to gain script control over it via setting this entityas mission entity. Entities which are not set as mission ones can be deleted bythe engine at any time, so you must not reuse handles of these entities betweenengine ticks (i.e. WAIT calls).Original scripts follow the same rules as written above while using the nativeswhich access entities from the world, for ex. GET_PED_NEARBY_VEHICLES andGET_PED_NEARBY_PEDS. See these natives as well: IS_ENTITY_A_MISSION_ENTITY,SET_ENTITY_AS_MISSION_ENTITY.Example of using entity pools can be found in Pools\script.cpp file.4\. CompilationAll samples here can be compiled using MSVC 2013 or higher.5\. Terms of use- You are allowed to use this SDK only for writing scripts intended to work offline.- You are not allowed to redistribute ScriptHookRDR2.dll with your script plugins, provide the link to the latest runtime instead:www#dev-c#com/rdr2/scripthookrdr2/6\. SamplesThere are few samples included - NativeTrainer and Pools, for more detailssee NativeTrainer\script.cpp and Pools\script.cpp.(C) Alexander Blade 2019
演示截图: