From 229371e4ab180538582b9a98031a6c623bbb9952 Mon Sep 17 00:00:00 2001 From: NovaRain Date: Sat, 18 Apr 2020 21:19:22 +0800 Subject: [PATCH] Added use_item_on_dude macro to sfall.h Various code edits: * Implemented more HookCalls/MakeCalls/SafeWriteBatch in code. * Moved return/jump address consts into their respective functions. * Changed for-loop with iterators to use pre-increment. --- artifacts/scripting/headers/sfall.h | 6 +++ sfall/ModuleManager.cpp | 4 +- sfall/Modules/Animations.cpp | 4 +- sfall/Modules/BarBoxes.cpp | 10 ++--- sfall/Modules/Books.cpp | 2 +- sfall/Modules/BugFixes.cpp | 2 +- sfall/Modules/BurstMods.cpp | 2 +- sfall/Modules/Combat.cpp | 10 ++--- sfall/Modules/Console.cpp | 2 +- sfall/Modules/DamageMod.cpp | 2 +- sfall/Modules/DebugEditor.cpp | 2 +- sfall/Modules/Drugs.cpp | 2 +- sfall/Modules/Elevators.cpp | 10 ++--- sfall/Modules/FileSystem.cpp | 44 +++++++++---------- sfall/Modules/HeroAppearance.cpp | 2 +- sfall/Modules/HookScripts/CombatHs.cpp | 2 +- sfall/Modules/HookScripts/HexBlockingHs.cpp | 2 +- sfall/Modules/HookScripts/InventoryHs.cpp | 16 +++---- sfall/Modules/HookScripts/MiscHs.cpp | 2 +- sfall/Modules/Interface.cpp | 4 +- sfall/Modules/Inventory.cpp | 19 ++++---- sfall/Modules/LoadOrder.cpp | 2 +- sfall/Modules/MainMenu.cpp | 4 +- sfall/Modules/MiscPatches.cpp | 2 +- sfall/Modules/Perks.cpp | 37 ++++++---------- sfall/Modules/QuestList.cpp | 6 +-- sfall/Modules/ScriptExtender.cpp | 14 +++--- sfall/Modules/Scripting/Arrays.cpp | 2 +- sfall/Modules/Scripting/Handlers/Metarule.cpp | 2 +- sfall/Modules/Skills.cpp | 11 +++-- sfall/Modules/SpeedPatch.cpp | 4 +- sfall/Modules/SubModules/CombatBlock.cpp | 4 +- sfall/Modules/TalkingHeads.cpp | 2 +- sfall/Modules/Worldmap.cpp | 2 +- 34 files changed, 116 insertions(+), 125 deletions(-) diff --git a/artifacts/scripting/headers/sfall.h b/artifacts/scripting/headers/sfall.h index f18965c5..210a259f 100644 --- a/artifacts/scripting/headers/sfall.h +++ b/artifacts/scripting/headers/sfall.h @@ -266,6 +266,12 @@ #define ADD_PERK_MODE_PERK (2) // add to the player's perks #define ADD_PERK_MODE_REMOVE (4) // remove from the list of selectable perks (after added to the player) +// instantly apply the item to dude_obj (w/o animation) +#define use_item_on_dude(item) set_self(dude_obj); \ + set_self(dude_obj); \ + use_obj_on_obj(item, dude_obj); \ + set_self(0) + // sfall_funcX macros #define add_extra_msg_file(name) sfall_func1("add_extra_msg_file", name) #define add_global_timer_event(time, fixedParam) sfall_func2("add_g_timer_event", time, fixedParam) diff --git a/sfall/ModuleManager.cpp b/sfall/ModuleManager.cpp index cea44e52..13ebfbde 100644 --- a/sfall/ModuleManager.cpp +++ b/sfall/ModuleManager.cpp @@ -11,13 +11,13 @@ ModuleManager::ModuleManager() { } ModuleManager::~ModuleManager() { - for (auto it = _modules.cbegin(); it != _modules.cend(); it++) { + for (auto it = _modules.cbegin(); it != _modules.cend(); ++it) { (*it)->exit(); } } void ModuleManager::initAll() { - for (auto it = _modules.cbegin(); it != _modules.cend(); it++) { + for (auto it = _modules.cbegin(); it != _modules.cend(); ++it) { dlog_f("Initializing module %s...\n", DL_INIT, (*it)->name()); (*it)->init(); } diff --git a/sfall/Modules/Animations.cpp b/sfall/Modules/Animations.cpp index 36f21331..379afd52 100644 --- a/sfall/Modules/Animations.cpp +++ b/sfall/Modules/Animations.cpp @@ -191,9 +191,9 @@ static DWORD __fastcall CheckSetSad(BYTE openFlag, DWORD valueMul) { return result; } -static const DWORD object_move_back0 = 0x417611; -static const DWORD object_move_back1 = 0x417616; static void __declspec(naked) object_move_hack() { + static const DWORD object_move_back0 = 0x417611; + static const DWORD object_move_back1 = 0x417616; __asm { mov ecx, ds:[ecx + 0x3C]; // openFlag mov edx, [esp + 0x4C - 0x20]; // valueMul diff --git a/sfall/Modules/BarBoxes.cpp b/sfall/Modules/BarBoxes.cpp index 8aefbcf2..84d82599 100644 --- a/sfall/Modules/BarBoxes.cpp +++ b/sfall/Modules/BarBoxes.cpp @@ -61,9 +61,9 @@ static const DWORD bboxSlotAddr[] = { 0x4616F7, 0x46170F, 0x461736, 0x4616B1, 0x46151D, 0x4615B3 }; -static const DWORD DisplayBoxesRet1 = 0x4615A8; -static const DWORD DisplayBoxesRet2 = 0x4615BE; static void __declspec(naked) DisplayBoxesHack() { + static const DWORD DisplayBoxesRet1 = 0x4615A8; + static const DWORD DisplayBoxesRet2 = 0x4615BE; __asm { mov edx, [boxText]; xor ebx, ebx; @@ -115,8 +115,8 @@ skip: } } -static const DWORD SetIndexBoxRet = 0x4612E8; static void __declspec(naked) BarBoxesIndexHack() { + static const DWORD SetIndexBoxRet = 0x4612E8; __asm { mov eax, ds:[0x4612E2]; // fontnum mov ecx, setBoxIndex; // start index @@ -125,9 +125,9 @@ static void __declspec(naked) BarBoxesIndexHack() { } } -static const DWORD SizeLoopBoxRet = 0x461477; -static const DWORD ExitLoopBoxRet = 0x461498; static void __declspec(naked) BarBoxesSizeHack() { + static const DWORD SizeLoopBoxRet = 0x461477; + static const DWORD ExitLoopBoxRet = 0x461498; __asm { cmp edx, sizeBox; jz exitLoop; diff --git a/sfall/Modules/Books.cpp b/sfall/Modules/Books.cpp index d267d54d..4144dc8f 100644 --- a/sfall/Modules/Books.cpp +++ b/sfall/Modules/Books.cpp @@ -45,8 +45,8 @@ static sBook* __fastcall FindBook(DWORD pid) { return 0; } -static const DWORD obj_use_book_hook_back = 0x49BA5A; static void __declspec(naked) obj_use_book_hook() { + static const DWORD obj_use_book_hook_back = 0x49BA5A; __asm { mov edi, -1; mov ecx, eax; diff --git a/sfall/Modules/BugFixes.cpp b/sfall/Modules/BugFixes.cpp index 2e5635f0..f512c3fa 100644 --- a/sfall/Modules/BugFixes.cpp +++ b/sfall/Modules/BugFixes.cpp @@ -41,7 +41,7 @@ void BugFixes::DrugsSaveFix(HANDLE file) { DWORD sizeWrite, count = drugsPid.size(); WriteFile(file, &count, 4, &sizeWrite, 0); if (!count) return; - for (auto it = drugsPid.begin(); it != drugsPid.end(); it++) { + for (auto it = drugsPid.begin(); it != drugsPid.end(); ++it) { int pid = *it; WriteFile(file, &pid, 4, &sizeWrite, 0); } diff --git a/sfall/Modules/BurstMods.cpp b/sfall/Modules/BurstMods.cpp index 790b878e..42a9c996 100644 --- a/sfall/Modules/BurstMods.cpp +++ b/sfall/Modules/BurstMods.cpp @@ -49,8 +49,8 @@ static long __fastcall ComputeSpray(DWORD* roundsLeftOut, DWORD* roundsRightOut, return (result % compute_spray_target_div) ? ++roundsMainTarget : roundsMainTarget; // if remainder then round up } -static const DWORD compute_spray_rounds_back = 0x42353A; static void __declspec(naked) compute_spray_rounds_distribution() { + static const DWORD compute_spray_rounds_back = 0x42353A; __asm { push ecx; lea ecx, [esp + 8 + 4]; // roundsLeft - out diff --git a/sfall/Modules/Combat.cpp b/sfall/Modules/Combat.cpp index e137b04d..93ea14f1 100644 --- a/sfall/Modules/Combat.cpp +++ b/sfall/Modules/Combat.cpp @@ -132,9 +132,9 @@ static void __declspec(naked) ai_search_inven_weap_hook() { } // switch weapon mode from secondary to primary if there is not enough ammo to shoot -static const DWORD ai_try_attack_search_ammo = 0x42AA1E; -static const DWORD ai_try_attack_continue = 0x42A929; static void __declspec(naked) ai_try_attack_hook() { + static const DWORD ai_try_attack_search_ammo = 0x42AA1E; + static const DWORD ai_try_attack_continue = 0x42A929; using namespace fo; using namespace Fields; __asm { @@ -221,8 +221,8 @@ static void __declspec(naked) compute_damage_hack() { } } -static const DWORD KnockbackRetAddr = 0x4136E1; static void __declspec(naked) compute_dmg_damage_hack() { + static const DWORD KnockbackRetAddr = 0x4136E1; __asm { push ecx push esi; // Target @@ -376,9 +376,9 @@ static int __fastcall AimedShotTest(DWORD pid) { return 0; } -static const DWORD aimedShotRet1 = 0x478EE4; -static const DWORD aimedShotRet2 = 0x478EEA; static void __declspec(naked) item_w_called_shot_hook() { + static const DWORD aimedShotRet1 = 0x478EE4; + static const DWORD aimedShotRet2 = 0x478EEA; __asm { push edx; mov ecx, edx; // item diff --git a/sfall/Modules/Console.cpp b/sfall/Modules/Console.cpp index 8e53493d..eed99bff 100644 --- a/sfall/Modules/Console.cpp +++ b/sfall/Modules/Console.cpp @@ -31,8 +31,8 @@ static void __stdcall ConsoleFilePrint(const char* msg) { consoleFile << msg << std::endl; } -static const DWORD ConsoleHookRet = 0x431871; static void __declspec(naked) ConsoleHook() { + static const DWORD ConsoleHookRet = 0x431871; __asm { pushadc; push eax; diff --git a/sfall/Modules/DamageMod.cpp b/sfall/Modules/DamageMod.cpp index a768c5e0..d0512a71 100644 --- a/sfall/Modules/DamageMod.cpp +++ b/sfall/Modules/DamageMod.cpp @@ -366,8 +366,8 @@ static void __declspec(naked) DisplayBonusHtHDmg1_hook() { } } -static const DWORD DisplayBonusHtHDmg2Exit = 0x472569; static void __declspec(naked) DisplayBonusHtHDmg2_hack() { + static const DWORD DisplayBonusHtHDmg2Exit = 0x472569; __asm { mov ecx, eax; call fo::funcoffs::stat_level_; diff --git a/sfall/Modules/DebugEditor.cpp b/sfall/Modules/DebugEditor.cpp index 1219ae70..c64d94e0 100644 --- a/sfall/Modules/DebugEditor.cpp +++ b/sfall/Modules/DebugEditor.cpp @@ -296,8 +296,8 @@ void RunDebugEditor() { WSACleanup(); } -static const DWORD dbg_error_ret = 0x453FD8; static void __declspec(naked) dbg_error_hack() { + static const DWORD dbg_error_ret = 0x453FD8; __asm { cmp ebx, 1; je hide; diff --git a/sfall/Modules/Drugs.cpp b/sfall/Modules/Drugs.cpp index 088471e4..b71cf0d5 100644 --- a/sfall/Modules/Drugs.cpp +++ b/sfall/Modules/Drugs.cpp @@ -151,8 +151,8 @@ static long __fastcall PrintAddictionList(long isSeparator) { return isSelect; } -static const DWORD list_karma_Ret = 0x43C1A3; static void __declspec(naked) list_karma_hack() { + static const DWORD list_karma_Ret = 0x43C1A3; __asm { mov ecx, [esp + 0x168 - 0x1C + 4]; call PrintAddictionList; diff --git a/sfall/Modules/Elevators.cpp b/sfall/Modules/Elevators.cpp index 048ef0cc..16c3d0a1 100644 --- a/sfall/Modules/Elevators.cpp +++ b/sfall/Modules/Elevators.cpp @@ -144,19 +144,15 @@ void ElevatorsInit() { //HookCall(0x43F2D2, UnknownHook2); // unused SafeWrite8(0x43EF76, (BYTE)elevatorCount); - SafeWrite32(0x43EFA4, (DWORD)elevatorExits); - SafeWrite32(0x43EFB9, (DWORD)elevatorExits); - SafeWrite32(0x43F2FC, (DWORD)elevatorExits); - SafeWrite32(0x43EFEA, (DWORD)&elevatorExits[0][0].tile); - SafeWrite32(0x43F315, (DWORD)&elevatorExits[0][0].tile); + SafeWriteBatch((DWORD)elevatorExits, {0x43EFA4, 0x43EFB9, 0x43F2FC}); + SafeWriteBatch((DWORD)&elevatorExits[0][0].tile, {0x43EFEA, 0x43F315}); SafeWrite32(0x43F309, (DWORD)&elevatorExits[0][0].elevation); SafeWrite32(0x43F438, (DWORD)&elevatorsFrms[0].main); SafeWrite32(0x43F475, (DWORD)&elevatorsFrms[0].buttons); // _btncnt - SafeWrite32(0x43F65E, (DWORD)elevatorsBtnCount); - SafeWrite32(0x43F6BB, (DWORD)elevatorsBtnCount); + SafeWriteBatch((DWORD)elevatorsBtnCount, {0x43F65E, 0x43F6BB}); MakeCall(0x43F05D, GetNumButtonsHook1, 2); MakeCall(0x43F184, GetNumButtonsHook2, 2); MakeCall(0x43F1E4, GetNumButtonsHook3, 2); diff --git a/sfall/Modules/FileSystem.cpp b/sfall/Modules/FileSystem.cpp index 60f43ac0..bdb95a45 100644 --- a/sfall/Modules/FileSystem.cpp +++ b/sfall/Modules/FileSystem.cpp @@ -37,11 +37,11 @@ struct fsFile { BYTE isSave; }; -struct openFile { +struct OpenFile { DWORD pos; // current xread/xwrite position fsFile* file; - openFile(fsFile* pFile) { + OpenFile(fsFile* pFile) { pos = 0; file = pFile; } @@ -49,7 +49,7 @@ struct openFile { struct sFile { DWORD type; - openFile* opnFile; + OpenFile* openFile; }; std::vector files; @@ -58,7 +58,7 @@ static DWORD loadedFiles = 0; // used for internal sfall data bool FileSystem::UsingFileSystem = false; static long _stdcall xfclose(sFile* file) { - delete file->opnFile; + delete file->openFile; delete file; return 0; } @@ -84,7 +84,7 @@ static sFile* _stdcall xfopen(const char* path, const char* mode) { if (!_stricmp(path, files[i].name)) { sFile* file = new sFile(); file->type = 3; - file->opnFile = new openFile(&files[i]); + file->openFile = new OpenFile(&files[i]); return file; } } @@ -128,8 +128,8 @@ end: } static DWORD _stdcall xfgetc(sFile* file) { - if (file->opnFile->pos >= file->opnFile->file->length) return -1; - return static_cast(file->opnFile->file->data[file->opnFile->pos++]); + if (file->openFile->pos >= file->openFile->file->length) return -1; + return static_cast(file->openFile->file->data[file->openFile->pos++]); } static __declspec(naked) int asm_xfgetc(sFile* file) { @@ -149,7 +149,7 @@ end: } static char* _stdcall xfgets(char* buf, int max_count, sFile* file) { - if (file->opnFile->pos >= file->opnFile->file->length) return 0; + if (file->openFile->pos >= file->openFile->file->length) return 0; for (int i = 0; i < max_count; i++) { int c = xfgetc(file); if (c == -1) { @@ -218,9 +218,9 @@ end: } static int _stdcall xfungetc(int c, sFile* file) { - if (file->opnFile->pos == 0) return -1; - if (file->opnFile->file->data[file->opnFile->pos - 1] != static_cast(c)) return -1; - file->opnFile->pos--; + if (file->openFile->pos == 0) return -1; + if (file->openFile->file->data[file->openFile->pos - 1] != static_cast(c)) return -1; + file->openFile->pos--; return c; } @@ -241,10 +241,10 @@ end: static int __fastcall xfread(sFile* file, int elsize, void* buf, int count) { for (int i = 0; i < count; i++) { - if (file->opnFile->pos + elsize > file->opnFile->file->length) return i; + if (file->openFile->pos + elsize > file->openFile->file->length) return i; - memcpy(buf, &file->opnFile->file->data[file->opnFile->pos], elsize); - file->opnFile->pos += elsize; + memcpy(buf, &file->openFile->file->data[file->openFile->pos], elsize); + file->openFile->pos += elsize; } return count; } @@ -301,13 +301,13 @@ end: static int _stdcall xfseek(sFile* file, long pos, int origin) { switch(origin) { case 0: - file->opnFile->pos = pos; + file->openFile->pos = pos; break; case 1: - file->opnFile->pos += pos; + file->openFile->pos += pos; break; case 2: - file->opnFile->pos = file->opnFile->file->length + pos; + file->openFile->pos = file->openFile->file->length + pos; break; } return 0; @@ -330,7 +330,7 @@ end: } static long _stdcall xftell(sFile* file) { - return file->opnFile->pos; + return file->openFile->pos; } static __declspec(naked) long asm_xftell(sFile* file) { @@ -350,7 +350,7 @@ end: } static void _stdcall xfrewind(sFile* file) { - file->opnFile->pos = 0; + file->openFile->pos = 0; } static __declspec(naked) void asm_xfrewind(sFile* file) { @@ -368,7 +368,7 @@ end: } static int _stdcall xfeof(sFile* file) { - if (file->opnFile->pos >= file->opnFile->file->length) { + if (file->openFile->pos >= file->openFile->file->length) { return 1; } return 0; @@ -391,7 +391,7 @@ end: } static int _stdcall xfilelength(sFile* file) { - return file->opnFile->file->length; + return file->openFile->file->length; } static __declspec(naked) int asm_xfilelength(sFile* file) { @@ -458,8 +458,8 @@ static void FileSystemLoad() { } } -static const DWORD LoadHookRetAddr = 0x47CCEE; static void __declspec(naked) FSLoadHook() { + static const DWORD LoadHookRetAddr = 0x47CCEE; __asm { pushadc; call FileSystemLoad; diff --git a/sfall/Modules/HeroAppearance.cpp b/sfall/Modules/HeroAppearance.cpp index a8a4b977..be59916d 100644 --- a/sfall/Modules/HeroAppearance.cpp +++ b/sfall/Modules/HeroAppearance.cpp @@ -1296,8 +1296,8 @@ endFunc: } } -static const DWORD op_obj_art_fid_Ret = 0x45C5D9; static void __declspec(naked) op_obj_art_fid_hack() { + static const DWORD op_obj_art_fid_Ret = 0x45C5D9; using namespace Fields; __asm { mov esi, [edi + artFid]; diff --git a/sfall/Modules/HookScripts/CombatHs.cpp b/sfall/Modules/HookScripts/CombatHs.cpp index aaf776a4..00a35921 100644 --- a/sfall/Modules/HookScripts/CombatHs.cpp +++ b/sfall/Modules/HookScripts/CombatHs.cpp @@ -419,8 +419,8 @@ skip: } } -static const DWORD combat_hook_end_combat = 0x422E91; static void __declspec(naked) combat_hook_fix_load() { + static const DWORD combat_hook_end_combat = 0x422E91; __asm { call fo::funcoffs::combat_sequence_; mov eax, countCombat; diff --git a/sfall/Modules/HookScripts/HexBlockingHs.cpp b/sfall/Modules/HookScripts/HexBlockingHs.cpp index d8548a9f..2a137c6f 100644 --- a/sfall/Modules/HookScripts/HexBlockingHs.cpp +++ b/sfall/Modules/HookScripts/HexBlockingHs.cpp @@ -8,8 +8,8 @@ namespace sfall { -static const DWORD _obj_blocking_at = 0x48B84E; static void __declspec(naked) HexMBlockingHook() { + static const DWORD _obj_blocking_at = 0x48B84E; __asm { HookBegin; mov args[0], eax; diff --git a/sfall/Modules/HookScripts/InventoryHs.cpp b/sfall/Modules/HookScripts/InventoryHs.cpp index 4720c1db..ab376e86 100644 --- a/sfall/Modules/HookScripts/InventoryHs.cpp +++ b/sfall/Modules/HookScripts/InventoryHs.cpp @@ -11,8 +11,8 @@ namespace sfall { -static const DWORD RemoveObjHookRet = 0x477497; static void __declspec(naked) RemoveObjHook() { + static const DWORD RemoveObjHookRet = 0x477497; __asm { mov ecx, [esp + 8]; // call addr HookBegin; @@ -126,10 +126,10 @@ static int __fastcall InventoryMoveHook_Script(DWORD itemReplace, DWORD item, in return result; } -static const DWORD UseArmorHack_back = 0x4713AF; // normal operation (old 0x4713A9) -static const DWORD UseArmorHack_skip = 0x471481; // skip code, prevent wearing armor // This hack is called when an armor is dropped into the armor slot at inventory screen static void __declspec(naked) UseArmorHack() { + static const DWORD UseArmorHack_back = 0x4713AF; // normal operation (old 0x4713A9) + static const DWORD UseArmorHack_skip = 0x471481; // skip code, prevent wearing armor __asm { mov ecx, ds:[FO_VAR_i_worn]; // replacement item (override code) mov edx, [esp + 0x58 - 0x40]; // item @@ -236,9 +236,9 @@ static int __fastcall DropIntoContainer(DWORD ptrCont, DWORD item, DWORD addrCal return InventoryMoveHook_Script(ptrCont, item, type); } -static const DWORD DropIntoContainer_back = 0x47649D; // normal operation -static const DWORD DropIntoContainer_skip = 0x476503; static void __declspec(naked) DropIntoContainerHack() { + static const DWORD DropIntoContainer_back = 0x47649D; // normal operation + static const DWORD DropIntoContainer_skip = 0x476503; __asm { pushadc; mov ecx, ebp; // contaner ptr @@ -256,17 +256,17 @@ skipdrop: } } -static const DWORD DropIntoContainerRet = 0x471481; static void __declspec(naked) DropIntoContainerHandSlotHack() { + static const DWORD DropIntoContainerRet = 0x471481; __asm { call fo::funcoffs::drop_into_container_; jmp DropIntoContainerRet; } } -//static const DWORD DropAmmoIntoWeaponHack_back = 0x47658D; // proceed with reloading -static const DWORD DropAmmoIntoWeaponHack_return = 0x476643; static void __declspec(naked) DropAmmoIntoWeaponHook() { + //static const DWORD DropAmmoIntoWeaponHack_back = 0x47658D; // proceed with reloading + static const DWORD DropAmmoIntoWeaponHack_return = 0x476643; __asm { pushadc; mov ecx, ebp; // weapon ptr diff --git a/sfall/Modules/HookScripts/MiscHs.cpp b/sfall/Modules/HookScripts/MiscHs.cpp index ed903c58..a46f0c9e 100644 --- a/sfall/Modules/HookScripts/MiscHs.cpp +++ b/sfall/Modules/HookScripts/MiscHs.cpp @@ -358,8 +358,8 @@ static void CarTravelHook_Script() { EndHook(); } -static const DWORD CarTravelHack_back = 0x4BFF43; static void __declspec(naked) CarTravelHack() { + static const DWORD CarTravelHack_back = 0x4BFF43; __asm { pushad; call CarTravelHook_Script; diff --git a/sfall/Modules/Interface.cpp b/sfall/Modules/Interface.cpp index 47f1b999..7c7f07ce 100644 --- a/sfall/Modules/Interface.cpp +++ b/sfall/Modules/Interface.cpp @@ -66,8 +66,8 @@ static void __declspec(naked) intface_init_hack() { } } -static const DWORD intface_update_move_points_ret = 0x45EE3E; static void __declspec(naked) intface_update_move_points_hack() { + static const DWORD intface_update_move_points_ret = 0x45EE3E; __asm { mov eax, 16 * 9 push eax; @@ -237,8 +237,8 @@ static const DWORD wmViewportEndBottom[] = { 0x4C44BE, // wmCursorIsVisible_ }; -static const DWORD wmInterfaceInit_Ret = 0x4C23A7; static void __declspec(naked) wmInterfaceInit_hack() { + static const DWORD wmInterfaceInit_Ret = 0x4C23A7; __asm { push eax; mov eax, 640 - WMAP_WIN_WIDTH; diff --git a/sfall/Modules/Inventory.cpp b/sfall/Modules/Inventory.cpp index 10ebd111..5310ac03 100644 --- a/sfall/Modules/Inventory.cpp +++ b/sfall/Modules/Inventory.cpp @@ -181,9 +181,9 @@ static int __fastcall BarterAttemptTransaction(fo::GameObject* critter, fo::Game return (sizeTable <= size) ? 1 : 0; } -static const DWORD BarterAttemptTransactionPCFail = 0x474C81; -static const DWORD BarterAttemptTransactionPCRet = 0x474CA8; static __declspec(naked) void barter_attempt_transaction_hack_pc() { + static const DWORD BarterAttemptTransactionPCFail = 0x474C81; + static const DWORD BarterAttemptTransactionPCRet = 0x474CA8; __asm { /* cmp eax, edx */ jg fail; // if there's no available weight @@ -200,9 +200,9 @@ fail: } } -static const DWORD BarterAttemptTransactionPMFail = 0x474CD8; -static const DWORD BarterAttemptTransactionPMRet = 0x474D01; static __declspec(naked) void barter_attempt_transaction_hack_pm() { + static const DWORD BarterAttemptTransactionPMFail = 0x474CD8; + static const DWORD BarterAttemptTransactionPMRet = 0x474D01; __asm { /* cmp eax, edx */ jg fail; // if there's no available weight @@ -260,8 +260,8 @@ static void __cdecl DisplaySizeStats(fo::GameObject* critter, const char* &messa strcpy(InvenFmt, InvenFmt1); } -static const DWORD DisplayStatsRet = 0x4725E5; static __declspec(naked) void display_stats_hack() { + static const DWORD DisplayStatsRet = 0x4725E5; using namespace fo; __asm { mov ecx, esp; @@ -311,8 +311,8 @@ static __declspec(naked) void inven_obj_examine_func_hook() { } } -static const DWORD ControlUpdateInfoRet = 0x44912A; static void __declspec(naked) gdControlUpdateInfo_hack() { + static const DWORD ControlUpdateInfoRet = 0x44912A; using namespace fo; __asm { mov ebx, eax; @@ -342,8 +342,8 @@ static int __fastcall SuperStimFix(fo::GameObject* item, fo::GameObject* target) return -1; } -static const DWORD protinst_use_item_on_Ret = 0x49C5F4; static void __declspec(naked) protinst_use_item_on_hack() { + static const DWORD protinst_use_item_on_Ret = 0x49C5F4; __asm { push ecx; mov ecx, ebx; // ecx - item @@ -634,8 +634,8 @@ static void __declspec(naked) adjust_fid_hack_replacement() { } } -static const DWORD DoMoveTimer_Ret = 0x476920; static void __declspec(naked) do_move_timer_hook() { + static const DWORD DoMoveTimer_Ret = 0x476920; __asm { cmp eax, 4; jnz end; @@ -674,8 +674,9 @@ static void __declspec(naked) do_move_timer_hack() { static int invenApCost, invenApCostDef; static char invenApQPReduction; -static const DWORD inven_ap_cost_Ret = 0x46E812; + static void __declspec(naked) inven_ap_cost_hack() { + static const DWORD inven_ap_cost_Ret = 0x46E812; _asm { mul byte ptr invenApQPReduction; mov edx, invenApCost; diff --git a/sfall/Modules/LoadOrder.cpp b/sfall/Modules/LoadOrder.cpp index 4f51b262..8c268df2 100644 --- a/sfall/Modules/LoadOrder.cpp +++ b/sfall/Modules/LoadOrder.cpp @@ -154,7 +154,7 @@ end: } static void InitExtraPatches() { - for (auto it = patchFiles.begin(); it != patchFiles.end(); it++) { + for (auto it = patchFiles.begin(); it != patchFiles.end(); ++it) { if (!it->empty()) fo::func::db_init(it->c_str(), 0); } // free memory diff --git a/sfall/Modules/MainMenu.cpp b/sfall/Modules/MainMenu.cpp index 954bf94a..baa2bc21 100644 --- a/sfall/Modules/MainMenu.cpp +++ b/sfall/Modules/MainMenu.cpp @@ -36,8 +36,8 @@ static DWORD MainMenuTextOffset; static long OverrideColour, OverrideColour2; -static const DWORD MainMenuButtonYHookRet = 0x48184A; static void __declspec(naked) MainMenuButtonYHook() { + static const DWORD MainMenuButtonYHookRet = 0x48184A; __asm { xor edi, edi; xor esi, esi; @@ -66,8 +66,8 @@ override: } } -static const DWORD MainMenuTextRet = 0x4817B0; static void __declspec(naked) MainMenuTextHook() { + static const DWORD MainMenuTextRet = 0x4817B0; __asm { mov esi, eax; // winptr mov ebp, ecx; // keep xpos diff --git a/sfall/Modules/MiscPatches.cpp b/sfall/Modules/MiscPatches.cpp index d60f91bd..9a34340a 100644 --- a/sfall/Modules/MiscPatches.cpp +++ b/sfall/Modules/MiscPatches.cpp @@ -710,7 +710,7 @@ void MiscPatches::init() { } // Highlight "Radiated" in red color when the player is under the influence of negative effects of radiation - HookCalls(ListDrvdStats_hook, { 0x43549C, 0x4354BE }); + HookCalls(ListDrvdStats_hook, {0x43549C, 0x4354BE}); // Increase the max text width of the information card in the character screen SafeWriteBatch(145, {0x43ACD5, 0x43DD37}); // 136, 133 diff --git a/sfall/Modules/Perks.cpp b/sfall/Modules/Perks.cpp index a8755fbd..563d4370 100644 --- a/sfall/Modules/Perks.cpp +++ b/sfall/Modules/Perks.cpp @@ -454,9 +454,9 @@ fake: } // Search all available perks for the player to display them in the character screen -static const DWORD EndPerkLoopExit = 0x434446; -static const DWORD EndPerkLoopCont = 0x4343A5; static void __declspec(naked) EndPerkLoopHack() { + static const DWORD EndPerkLoopExit = 0x434446; + static const DWORD EndPerkLoopCont = 0x4343A5; __asm { jl cLoop; // if ebx < 119 push ecx; @@ -718,9 +718,9 @@ static PerkInfo* __fastcall CanAddPerk(DWORD perkID) { return 0; } -static const DWORD perk_can_add_exit = 0x496A03; -static const DWORD perk_can_add_check = 0x496872; static void __declspec(naked) perk_can_add_hack() { + static const DWORD perk_can_add_exit = 0x496A03; + static const DWORD perk_can_add_check = 0x496872; __asm { test edx, edx; jz end; @@ -746,9 +746,9 @@ static PerkInfo* __fastcall PerkData(DWORD perkID, fo::GameObject* critter, long return 0; } -static const DWORD perk_add_effect_exit = 0x496CD9; -static const DWORD perk_add_effect_continue = 0x496C4A; static void __declspec(naked) perk_add_effect_hook() { + static const DWORD perk_add_effect_exit = 0x496CD9; + static const DWORD perk_add_effect_continue = 0x496C4A; __asm { cmp edx, startFakeID; jge end; @@ -766,9 +766,9 @@ end: } } -static const DWORD perk_remove_effect_exit = 0x496D99; -static const DWORD perk_remove_effect_continue = 0x496D2E; static void __declspec(naked) perk_remove_effect_hook() { + static const DWORD perk_remove_effect_exit = 0x496D99; + static const DWORD perk_remove_effect_continue = 0x496D2E; __asm { cmp edx, startFakeID; jge end; @@ -858,8 +858,7 @@ static void PerkSetup() { if (!perksReInit) { // _perk_data SafeWriteBatch((DWORD)perks, {0x496669, 0x496837, 0x496BAD, 0x496C41, 0x496D25}); - SafeWrite32(0x496696, (DWORD)&perks[0].description); - SafeWrite32(0x496BD1, (DWORD)&perks[0].description); + SafeWriteBatch((DWORD)&perks[0].description, {0x496696, 0x496BD1}); SafeWrite32(0x496BF5, (DWORD)&perks[0].image); SafeWrite32(0x496AD4, (DWORD)&perks[0].ranks); } @@ -1119,10 +1118,8 @@ static void TraitSetup() { memcpy(traits, var::trait_data, sizeof(TraitInfo) * TRAIT_count); // _trait_data - SafeWrite32(0x4B3A81, (DWORD)traits); - SafeWrite32(0x4B3B80, (DWORD)traits); - SafeWrite32(0x4B3AAE, (DWORD)&traits[0].description); - SafeWrite32(0x4B3BA0, (DWORD)&traits[0].description); + SafeWriteBatch((DWORD)traits, {0x4B3A81, 0x4B3B80}); + SafeWriteBatch((DWORD)&traits[0].description, {0x4B3AAE, 0x4B3BA0}); SafeWrite32(0x4B3BC0, (DWORD)&traits[0].image); char buf[512], num[5] = {'t'}; @@ -1214,9 +1211,9 @@ static __declspec(naked) void TraitInitWrapper() { } } -static const DWORD FastShotTraitFixEnd1 = 0x478E7F; -static const DWORD FastShotTraitFixEnd2 = 0x478E7B; static void __declspec(naked) item_w_called_shot_hack() { + static const DWORD FastShotTraitFixEnd1 = 0x478E7F; + static const DWORD FastShotTraitFixEnd2 = 0x478E7B; __asm { test eax, eax; // does player have Fast Shot trait? je ajmp; // skip ahead if no @@ -1234,10 +1231,6 @@ bjmp: } } -static const DWORD FastShotFixF1[] = { - 0x478BB8, 0x478BC7, 0x478BD6, 0x478BEA, 0x478BF9, 0x478C08, 0x478C2F, -}; - static void FastShotTraitFix() { switch (GetConfigInt("Misc", "FastShotFix", 1)) { case 1: @@ -1247,9 +1240,7 @@ static void FastShotTraitFix() { case 2: dlog("Applying Fast Shot Trait Fix. (Fallout 1 version)", DL_INIT); SafeWrite16(0x478C9F, 0x9090); - for (int i = 0; i < sizeof(FastShotFixF1) / 4; i++) { - HookCall(FastShotFixF1[i], (void*)0x478C7D); - } + HookCalls((void*)0x478C7D, {0x478BB8, 0x478BC7, 0x478BD6, 0x478BEA, 0x478BF9, 0x478C08, 0x478C2F}); done: dlogr(" Done", DL_INIT); break; diff --git a/sfall/Modules/QuestList.cpp b/sfall/Modules/QuestList.cpp index e5078eed..63cc11dc 100644 --- a/sfall/Modules/QuestList.cpp +++ b/sfall/Modules/QuestList.cpp @@ -217,10 +217,10 @@ static long __fastcall QuestsPrint(const char* text, int width, DWORD* buf, BYTE return ExitCode::Normal; } -static const DWORD PipStatus_NormalRet = 0x49818B; -static const DWORD PipStatus_NextRet = 0x498237; -static const DWORD PipStatus_BreakRet = 0x4982A4; static void __declspec(naked) PipStatus_hack_print() { + static const DWORD PipStatus_NormalRet = 0x49818B; + static const DWORD PipStatus_NextRet = 0x498237; + static const DWORD PipStatus_BreakRet = 0x4982A4; __asm { push ecx; push ebx; diff --git a/sfall/Modules/ScriptExtender.cpp b/sfall/Modules/ScriptExtender.cpp index 7a9f65bb..6d1cc2f1 100644 --- a/sfall/Modules/ScriptExtender.cpp +++ b/sfall/Modules/ScriptExtender.cpp @@ -634,7 +634,7 @@ static void RunGlobalScriptsOnWorldMap() { static DWORD __stdcall HandleMapUpdateForScripts(const DWORD procId) { if (procId == fo::Scripts::ScriptProc::map_enter_p_proc) { // map changed, all game objects were destroyed and scripts detached, need to re-insert global scripts into the game - for (std::vector::const_iterator it = globalScripts.cbegin(); it != globalScripts.cend(); it++) { + for (std::vector::const_iterator it = globalScripts.cbegin(); it != globalScripts.cend(); ++it) { fo::func::runProgram(it->prog.ptr); } } else if (procId == fo::Scripts::ScriptProc::map_exit_p_proc) onMapExit.invoke(); @@ -649,7 +649,7 @@ static DWORD HandleTimedEventScripts() { DWORD currentTime = fo::var::fallout_game_time; bool wasRunning = false; auto timerIt = timerEventScripts.cbegin(); - for (; timerIt != timerEventScripts.cend(); timerIt++) { + for (; timerIt != timerEventScripts.cend(); ++timerIt) { if (currentTime >= timerIt->time) { timedEvent = const_cast(&(*timerIt)); fo::func::dev_printf("\n[TimedEventScripts] run event: %d", timerIt->time); @@ -660,7 +660,7 @@ static DWORD HandleTimedEventScripts() { } } if (wasRunning) { - for (auto _it = timerEventScripts.cbegin(); _it != timerIt; _it++) { + for (auto _it = timerEventScripts.cbegin(); _it != timerIt; ++_it) { fo::func::dev_printf("\n[TimedEventScripts] delete event: %d", _it->time); } timerEventScripts.erase(timerEventScripts.cbegin(), timerIt); @@ -744,7 +744,7 @@ void SaveGlobals(HANDLE h) { var.id = itr->first; var.val = itr->second; WriteFile(h, &var, sizeof(GlobalVar), &unused, 0); - itr++; + ++itr; } } @@ -767,7 +767,7 @@ void GetGlobals(GlobalVar* globals) { while (itr != globalVars.end()) { globals[i].id = itr->first; globals[i++].val = itr->second; - itr++; + ++itr; } } @@ -776,7 +776,7 @@ void SetGlobals(GlobalVar* globals) { int i = 0; while (itr != globalVars.end()) { itr->second = globals[i++].val; - itr++; + ++itr; } } @@ -858,7 +858,7 @@ void ScriptExtender::init() { MakeJump(0x4A67F0, ExecMapScriptsHack); HookCall(0x4A26D6, HandleTimedEventScripts); // queue_process_ - MakeCalls(TimedEventNextTime, { + HookCalls(TimedEventNextTime, { 0x4C1C67, // wmGameTimeIncrement_ 0x4A3E1C, // script_chk_timed_events_ 0x499AFA, 0x499CD7, 0x499E2B // TimedRest_ diff --git a/sfall/Modules/Scripting/Arrays.cpp b/sfall/Modules/Scripting/Arrays.cpp index c91da440..a9b68645 100644 --- a/sfall/Modules/Scripting/Arrays.cpp +++ b/sfall/Modules/Scripting/Arrays.cpp @@ -326,7 +326,7 @@ void GetArrays(int* _arrays) { _arrays[pos++] = itr->second.isAssoc() ? 1 : 0; _arrays[pos++] = itr->second.val.size(); _arrays[pos++] = itr->second.flags; - itr++; + ++itr; } } diff --git a/sfall/Modules/Scripting/Handlers/Metarule.cpp b/sfall/Modules/Scripting/Handlers/Metarule.cpp index e240048f..a84beca7 100644 --- a/sfall/Modules/Scripting/Handlers/Metarule.cpp +++ b/sfall/Modules/Scripting/Handlers/Metarule.cpp @@ -153,7 +153,7 @@ static const SfallMetarule metarules[] = { static void sf_get_metarule_table(OpcodeContext& ctx) { DWORD arrId = TempArray(metaruleTable.size(), 0); int i = 0; - for (auto it = metaruleTable.begin(); it != metaruleTable.end(); it++) { + for (auto it = metaruleTable.begin(); it != metaruleTable.end(); ++it) { arrays[arrId].val[i].set(it->first.c_str()); i++; } diff --git a/sfall/Modules/Skills.cpp b/sfall/Modules/Skills.cpp index 5d5985aa..74997ee5 100644 --- a/sfall/Modules/Skills.cpp +++ b/sfall/Modules/Skills.cpp @@ -143,8 +143,8 @@ notNeg: } } -static const DWORD skill_dec_point_limit_Ret = 0x4AAA91; static void __declspec(naked) skill_dec_point_hack_limit() { + static const DWORD skill_dec_point_limit_Ret = 0x4AAA91; __asm { cmp edi, SKILL_MIN_LIMIT; jle skip; // if raw skill point <= -128 @@ -196,8 +196,8 @@ static int __fastcall GetStatBonus(fo::GameObject* critter, const fo::SkillInfo* //On input, ebx/edx contains the skill id, ecx contains the critter, edi contains a SkillInfo*, ebp contains the number of skill points //On exit ebx, ecx, edi, ebp are preserved, esi contains skill base + stat bonus + skillpoints * multiplier -static const DWORD StatBonusHookRet = 0x4AA5D6; static void __declspec(naked) skill_level_hack_bonus() { + static const DWORD StatBonusHookRet = 0x4AA5D6; __asm { push ecx; push ebp; // points @@ -210,8 +210,8 @@ static void __declspec(naked) skill_level_hack_bonus() { } } -static const DWORD SkillIncCostRet = 0x4AA7C1; static void __declspec(naked) skill_inc_point_hack_cost() { + static const DWORD SkillIncCostRet = 0x4AA7C1; __asm { // eax - current skill level, ebx - current skill, ecx - num free skill points mov edx, basedOnPoints; test edx, edx; @@ -231,8 +231,8 @@ skip: } } -static const DWORD SkillDecCostRet = 0x4AA98D; static void __declspec(naked) skill_dec_point_hack_cost() { + static const DWORD SkillDecCostRet = 0x4AA98D; __asm { // ecx - current skill level, ebx - current skill, esi - num free skill points mov edx, basedOnPoints; test edx, edx; @@ -317,8 +317,7 @@ void Skills::init() { HookCall(0x4AA574, skill_level_hook); // change the lower limit for negative skill points MakeCall(0x4AAA84, skill_dec_point_hack_limit); - SafeWrite8(0x4AA91B, SKILL_MIN_LIMIT); - SafeWrite8(0x4AAA1A, SKILL_MIN_LIMIT); + SafeWriteBatch(SKILL_MIN_LIMIT, {0x4AA91B, 0x4AAA1A}); SafeWrite32(0x4AAA23, SKILL_MIN_LIMIT); MakeCall(0x4ABC62, skill_check_stealing_hack); // PickpocketMod diff --git a/sfall/Modules/SpeedPatch.cpp b/sfall/Modules/SpeedPatch.cpp index c306d837..fd429f23 100644 --- a/sfall/Modules/SpeedPatch.cpp +++ b/sfall/Modules/SpeedPatch.cpp @@ -170,9 +170,7 @@ void SpeedPatch::init() { int size = sizeof(offsets) / 4; if (GetConfigInt("Speed", "AffectPlayback", 0) == 0) size -= 4; - for (int i = 0; i < size; i++) { - SafeWrite32(offsets[i], (DWORD)&sf_GetTickCount); - } + SafeWriteBatch((DWORD)&sf_GetTickCount, offsets); SafeWrite32(0x4FDF58, (DWORD)&sf_GetLocalTime); HookCall(0x4A433E, scripts_check_state_hook); diff --git a/sfall/Modules/SubModules/CombatBlock.cpp b/sfall/Modules/SubModules/CombatBlock.cpp index 8c8f928e..791aa83f 100644 --- a/sfall/Modules/SubModules/CombatBlock.cpp +++ b/sfall/Modules/SubModules/CombatBlock.cpp @@ -31,9 +31,9 @@ static void __stdcall CombatBlocked() { fo::func::display_print(combatBlockedMessage.c_str()); } -static const DWORD BlockCombatHook1Ret1 = 0x45F6AF; -static const DWORD BlockCombatHook1Ret2 = 0x45F6D7; static void __declspec(naked) intface_use_item_hook() { + static const DWORD BlockCombatHook1Ret1 = 0x45F6AF; + static const DWORD BlockCombatHook1Ret2 = 0x45F6D7; __asm { cmp combatDisabled, 0; jne block; diff --git a/sfall/Modules/TalkingHeads.cpp b/sfall/Modules/TalkingHeads.cpp index 9499bd30..ede3e9a2 100644 --- a/sfall/Modules/TalkingHeads.cpp +++ b/sfall/Modules/TalkingHeads.cpp @@ -179,8 +179,8 @@ loadFail: Graphics::SetDefaultTechnique(); } -static const DWORD gdDisplayFrameRet = 0x44AD06; static void __declspec(naked) gdDisplayFrame_hack() { + static const DWORD gdDisplayFrameRet = 0x44AD06; __asm { push edx; push eax; diff --git a/sfall/Modules/Worldmap.cpp b/sfall/Modules/Worldmap.cpp index 6d551351..15703f5c 100644 --- a/sfall/Modules/Worldmap.cpp +++ b/sfall/Modules/Worldmap.cpp @@ -507,7 +507,7 @@ void Worldmap::SaveData(HANDLE file) { DWORD sizeWrite, count = mapRestInfo.size(); WriteFile(file, &count, 4, &sizeWrite, 0); std::unordered_map::iterator it; - for (it = mapRestInfo.begin(); it != mapRestInfo.end(); it++) { + for (it = mapRestInfo.begin(); it != mapRestInfo.end(); ++it) { WriteFile(file, &it->first, 4, &sizeWrite, 0); WriteFile(file, &it->second, sizeof(levelRest), &sizeWrite, 0); }