From b178e15b31b04ea45a3f49ced17fbc0c2c6a4c96 Mon Sep 17 00:00:00 2001 From: NovaRain Date: Tue, 21 Jul 2020 12:28:15 +0800 Subject: [PATCH] Implemented CodeType enums in some SafeWrite8 Replaced some SafeWriteX with SafeWriteBatch. Minor edits to documents. --- artifacts/ddraw.ini | 2 +- artifacts/scripting/compiler/sslc_readme.txt | 3 + sfall/FalloutEngine/EngineUtils.h | 1 + sfall/Modules/BugFixes.cpp | 25 ++- sfall/Modules/Combat.cpp | 2 +- sfall/Modules/Criticals.cpp | 5 +- sfall/Modules/DebugEditor.cpp | 4 +- sfall/Modules/HeroAppearance.cpp | 7 +- sfall/Modules/Inventory.cpp | 6 +- sfall/Modules/MiscPatches.cpp | 10 +- sfall/Modules/Objects.cpp | 2 +- sfall/Modules/PartyControl.cpp | 2 +- sfall/Modules/Perks.cpp | 2 +- sfall/Modules/Scripting/Handlers/Misc.cpp | 4 +- sfall/Modules/Sound.cpp | 2 +- sfall/Modules/Worldmap.cpp | 4 +- sfall/ddraw.vcxproj.filters | 198 +++++++++---------- 17 files changed, 135 insertions(+), 144 deletions(-) diff --git a/artifacts/ddraw.ini b/artifacts/ddraw.ini index a7b75216..3ef37d75 100644 --- a/artifacts/ddraw.ini +++ b/artifacts/ddraw.ini @@ -340,7 +340,7 @@ DialogueFix=1 ;Prevents you from using number keys to enter unvisited areas on a town map TownMapHotkeysFix=1 -;Set to 1 to disable the horrigan encounter +;Set to 1 to disable the Horrigan encounter DisableHorrigan=0 ;Set to 1 to disable the random element in NPC levelling. diff --git a/artifacts/scripting/compiler/sslc_readme.txt b/artifacts/scripting/compiler/sslc_readme.txt index 745ef0e2..f5de9bfc 100644 --- a/artifacts/scripting/compiler/sslc_readme.txt +++ b/artifacts/scripting/compiler/sslc_readme.txt @@ -340,6 +340,9 @@ There are several changes in this version of sslc which may result in problems f === Changelog === ================= +> sfall 4.2.7 +- added ability to declare local variables anywhere in the procedure body + > sfall 4.2.3 - fixed compiler giving "assignment operator expected" error when a variable-like macro is not being defined properly - added new logical operators "AndAlso", "OrElse" for short-circuit evaluation of logical expressions diff --git a/sfall/FalloutEngine/EngineUtils.h b/sfall/FalloutEngine/EngineUtils.h index dba60259..e0cd86dc 100644 --- a/sfall/FalloutEngine/EngineUtils.h +++ b/sfall/FalloutEngine/EngineUtils.h @@ -15,6 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ + #pragma once #include diff --git a/sfall/Modules/BugFixes.cpp b/sfall/Modules/BugFixes.cpp index 48e59f70..877154f0 100644 --- a/sfall/Modules/BugFixes.cpp +++ b/sfall/Modules/BugFixes.cpp @@ -2753,7 +2753,7 @@ void BugFixes::init() // // removes this line by making unconditional jump: // if ( who == obj_dude ) // dist -= 2 * perk_level_(obj_dude, PERK_sharpshooter); - SafeWrite8(0x424527, 0xEB); // in detemine_to_hit_func_() + SafeWrite8(0x424527, CodeType::JumpShort); // in detemine_to_hit_func_() dlogr(" Done", DL_INIT); //} @@ -2806,7 +2806,7 @@ void BugFixes::init() // Fix for move_obj_inven_to_obj function HookCall(0x45C49A, op_move_obj_inven_to_obj_hook); SafeWrite16(0x45C496, 0x9090); - SafeWrite8(0x45C4A3, 0x75); // jmp > jnz + SafeWrite8(0x45C4A3, CodeType::JumpNZ); // jmp > jnz // Fix for drop_obj function HookCall(0x49B965, obj_drop_hook); dlogr(" Done", DL_INIT); @@ -2853,8 +2853,7 @@ void BugFixes::init() //} // Corrects the max text width of the item weight in trading interface to be 64 (was 80), which matches the table width - SafeWrite8(0x475541, 64); - SafeWrite8(0x475789, 64); + SafeWriteBatch(64, {0x475541, 0x475789}); // Corrects the max text width of the player name in inventory to be 140 (was 80), which matches the width for item name SafeWrite32(0x471E48, 140); @@ -2917,7 +2916,7 @@ void BugFixes::init() //if (GetConfigInt("Misc", "ShivPatch", 1)) { dlog("Applying shiv patch.", DL_INIT); - SafeWrite8(0x477B2B, 0xEB); + SafeWrite8(0x477B2B, CodeType::JumpShort); dlogr(" Done", DL_INIT); //} @@ -2926,8 +2925,7 @@ void BugFixes::init() // http://teamx.ru/site_arc/smf/index.php-topic=398.0.htm SafeWrite16(0x46B35B, 0x1C60); // Fix problems with the temporary stack SafeWrite32(0x46B35D, 0x90909090); - SafeWrite8(0x46DBF1, 0xEB); // Disable warnings - SafeWrite8(0x46DDC4, 0xEB); // Disable warnings + SafeWriteBatch(CodeType::JumpShort, {0x46DBF1, 0x46DDC4}); // Disable warnings SafeWrite8(0x4415CC, 0x00); // Prevent crashes when re-exporting dlogr(" Done", DL_INIT); //} @@ -2988,8 +2986,7 @@ void BugFixes::init() // Fix for being unable to sell used geiger counters or stealth boys if (GetConfigInt("Misc", "CanSellUsedGeiger", 1)) { dlog("Applying fix for being unable to sell used geiger counters or stealth boys.", DL_INIT); - SafeWrite8(0x478115, 0xBA); - SafeWrite8(0x478138, 0xBA); + SafeWriteBatch(0xBA, {0x478115, 0x478138}); // mov eax, 1 > mov edx, 1 MakeJump(0x474D22, barter_attempt_transaction_hack); HookCall(0x4798B1, item_m_turn_off_hook); dlogr(" Done", DL_INIT); @@ -3131,8 +3128,8 @@ void BugFixes::init() // Fix broken op_obj_can_hear_obj_ function if (GetConfigInt("Misc", "ObjCanHearObjFix", 0)) { dlog("Applying obj_can_hear_obj fix.", DL_INIT); - SafeWrite8(0x4583D8, 0x3B); // jz loc_458414 - SafeWrite8(0x4583DE, 0x74); // jz loc_458414 + SafeWrite8(0x4583D8, 0x3B); // jz loc_458414 + SafeWrite8(0x4583DE, CodeType::JumpZ); // jz loc_458414 MakeCall(0x4583E0, op_obj_can_hear_obj_hack, 1); dlogr(" Done", DL_INIT); } @@ -3195,7 +3192,7 @@ void BugFixes::init() // Display messages about radiation for the active geiger counter if (GetConfigInt("Misc", "ActiveGeigerMsgs", 1)) { dlog("Applying active geiger counter messages patch.", DL_INIT); - SafeWriteBatch(0x74, {0x42D424, 0x42D444}); // jnz > jz + SafeWriteBatch(CodeType::JumpZ, {0x42D424, 0x42D444}); // jnz > jz dlogr(" Done", DL_INIT); } // Display a pop-up message box about death from radiation @@ -3206,8 +3203,8 @@ void BugFixes::init() dlog("Applying AI drug use preference fix.", DL_INIT); MakeCall(0x42869D, ai_check_drugs_hack_break); MakeCall(0x4286AB, ai_check_drugs_hack_check); - SafeWrite16(0x4286B0, 0x7490); // jnz > jz - SafeWrite8(0x4286C5, 0x75); // jz > jnz + SafeWrite16(0x4286B0, 0x7490); // jnz > jz + SafeWrite8(0x4286C5, CodeType::JumpNZ); // jz > jnz MakeCall(0x4286C7, ai_check_drugs_hack_use); dlogr(" Done", DL_INIT); } diff --git a/sfall/Modules/Combat.cpp b/sfall/Modules/Combat.cpp index ba528fa1..84e88153 100644 --- a/sfall/Modules/Combat.cpp +++ b/sfall/Modules/Combat.cpp @@ -514,7 +514,7 @@ void Combat::init() { LoadGameHook::OnBeforeGameStart() += BodypartHitChances; // set on start & load // Remove the dependency of Body_Torso from Body_Uncalled - SafeWrite8(0x423830, 0xEB); // compute_attack_ + SafeWrite8(0x423830, CodeType::JumpShort); // compute_attack_ BlockCall(0x42303F); // block Body_Torso check (combat_attack_) SafeWrite8(0x42A713, 7); // Body_Uncalled > Body_Groin (ai_called_shot_) SafeWriteBatch(8, bodypartAddr); // replace Body_Torso with Body_Uncalled diff --git a/sfall/Modules/Criticals.cpp b/sfall/Modules/Criticals.cpp index 434e0b29..87c7c495 100644 --- a/sfall/Modules/Criticals.cpp +++ b/sfall/Modules/Criticals.cpp @@ -255,9 +255,8 @@ static void CriticalTableOverride() { static void RemoveCriticalTimeLimitsPatch() { if (GetConfigInt("Misc", "RemoveCriticalTimelimits", 0)) { dlog("Removing critical time limits.", DL_INIT); - SafeWrite8(0x424118, 0xEB); // jump to 0x424131 - SafeWrite16(0x4A3052, 0x9090); - SafeWrite16(0x4A3093, 0x9090); + SafeWrite8(0x424118, CodeType::JumpShort); // jump to 0x424131 + SafeWriteBatch(0x9090, {0x4A3052, 0x4A3093}); dlogr(" Done", DL_INIT); } } diff --git a/sfall/Modules/DebugEditor.cpp b/sfall/Modules/DebugEditor.cpp index 30df38c6..3818af19 100644 --- a/sfall/Modules/DebugEditor.cpp +++ b/sfall/Modules/DebugEditor.cpp @@ -374,7 +374,7 @@ static void DebugModePatch() { SafeWrite32(0x4C6D9C, (DWORD)debugLog); if (dbgMode & 1) { SafeWrite16(0x4C6E75, 0x66EB); // jmps 0x4C6EDD - SafeWrite8(0x4C6EF2, 0xEB); + SafeWrite8(0x4C6EF2, CodeType::JumpShort); SafeWrite8(0x4C7034, 0x0); MakeCall(0x4DC319, win_debug_hook, 2); } @@ -403,7 +403,7 @@ static void DebugModePatch() { static void DontDeleteProtosPatch() { if (iniGetInt("Debugging", "DontDeleteProtos", 0, ::sfall::ddrawIni)) { dlog("Applying permanent protos patch.", DL_INIT); - SafeWrite8(0x48007E, 0xEB); + SafeWrite8(0x48007E, CodeType::JumpShort); dlogr(" Done", DL_INIT); } } diff --git a/sfall/Modules/HeroAppearance.cpp b/sfall/Modules/HeroAppearance.cpp index 87d4aa86..3dfffb44 100644 --- a/sfall/Modules/HeroAppearance.cpp +++ b/sfall/Modules/HeroAppearance.cpp @@ -727,7 +727,7 @@ void __stdcall HeroSelectWindow(int raceStyleFlag) { DWORD RedrawTick = 0, NewTick = 0, OldTick = 0; DWORD critNum = fo::var::art_vault_guy_num; // pointer to current base hero critter FrmID - //DWORD critNum = fo::var::obj_dude->artFID; // pointer to current armored hero critter FrmID + //DWORD critNum = fo::var::obj_dude->artFid; // pointer to current armored hero critter FrmID int raceVal = currentRaceVal, styleVal = currentStyleVal; // show default style when setting race if (!isStyle) styleVal = 0; @@ -1410,7 +1410,7 @@ static void EnableHeroAppearanceMod() { MakeCall(0x4DEEE5, LoadNewHeroArt, 1); // Divert critter frm file name function exit for file checking (art_get_name_) - SafeWrite8(0x419520, 0xEB); // divert func exit + SafeWrite8(0x419520, CodeType::JumpShort); // divert func exit SafeWrite32(0x419521, 0x9090903E); // Check if new hero art exists otherwise use regular art (art_get_name_) @@ -1496,8 +1496,7 @@ static void EnableHeroAppearanceMod() { HookCall(0x42613A, FixPcCriticalHitMsg); // Force Criticals For Testing - //SafeWrite32(0x423A8F, 0x90909090); - //SafeWrite32(0x423A93, 0x90909090); + //SafeMemSet(0x423A8F, 0x90, 8); } static void HeroAppearanceModExit() { diff --git a/sfall/Modules/Inventory.cpp b/sfall/Modules/Inventory.cpp index 45f0c548..f896288b 100644 --- a/sfall/Modules/Inventory.cpp +++ b/sfall/Modules/Inventory.cpp @@ -717,10 +717,8 @@ void Inventory::init() { if (sizeLimitMode >= 4) { sizeLimitMode -= 4; // item_total_weight_ patch - SafeWrite8(0x477EB3, 0xEB); - SafeWrite8(0x477EF5, 0); - SafeWrite8(0x477F11, 0); - SafeWrite8(0x477F29, 0); + SafeWrite8(0x477EB3, CodeType::JumpShort); + SafeWriteBatch(0, {0x477EF5, 0x477F11, 0x477F29}); } invSizeMaxLimit = GetConfigInt("Misc", "CritterInvSizeLimit", 100); diff --git a/sfall/Modules/MiscPatches.cpp b/sfall/Modules/MiscPatches.cpp index d33b0a42..ca366374 100644 --- a/sfall/Modules/MiscPatches.cpp +++ b/sfall/Modules/MiscPatches.cpp @@ -317,7 +317,7 @@ static void ScienceOnCrittersPatch() { HookCall(0x41276E, action_use_skill_on_hook_science); break; case 2: - SafeWrite8(0x41276A, 0xEB); + SafeWrite8(0x41276A, CodeType::JumpShort); break; } } @@ -366,7 +366,7 @@ static void InstantWeaponEquipPatch() { if (GetConfigInt("Misc", "InstantWeaponEquip", 0)) { //Skip weapon equip/unequip animations dlog("Applying instant weapon equip patch.", DL_INIT); - SafeWriteBatch(0xEB, PutAwayWeapon); // jmps + SafeWriteBatch(CodeType::JumpShort, PutAwayWeapon); // jmps BlockCall(0x472AD5); // BlockCall(0x472AE0); // invenUnwieldFunc_ BlockCall(0x472AF0); // @@ -378,7 +378,7 @@ static void InstantWeaponEquipPatch() { static void DontTurnOffSneakIfYouRunPatch() { if (GetConfigInt("Misc", "DontTurnOffSneakIfYouRun", 0)) { dlog("Applying DontTurnOffSneakIfYouRun patch.", DL_INIT); - SafeWrite8(0x418135, 0xEB); + SafeWrite8(0x418135, CodeType::JumpShort); dlogr(" Done", DL_INIT); } } @@ -467,7 +467,7 @@ static void AlwaysReloadMsgs() { static void RemoveWindowRoundingPatch() { if (GetConfigInt("Misc", "RemoveWindowRounding", 1)) { - SafeWriteBatch(0xEB, {0x4D6EDD, 0x4D6F12}); + SafeWriteBatch(CodeType::JumpShort, {0x4D6EDD, 0x4D6F12}); //SafeWrite16(0x4B8090, 0x04EB); // jmps 0x4B8096 (old) } } @@ -593,7 +593,7 @@ static void F1EngineBehaviorPatch() { if (GetConfigInt("Misc", "Fallout1Behavior", 0)) { dlog("Applying Fallout 1 engine behavior patch.", DL_INIT); BlockCall(0x4A4343); // disable playing the final movie/credits after the endgame slideshow - SafeWrite8(0x477C71, 0xEB); // disable halving the weight for power armor items + SafeWrite8(0x477C71, CodeType::JumpShort); // disable halving the weight for power armor items HookCall(0x43F872, endgame_movie_hook); // play movie 10 or 11 based on the player's gender before the credits dlogr(" Done", DL_INIT); } diff --git a/sfall/Modules/Objects.cpp b/sfall/Modules/Objects.cpp index 110015ee..b0eb7d74 100644 --- a/sfall/Modules/Objects.cpp +++ b/sfall/Modules/Objects.cpp @@ -166,7 +166,7 @@ void Objects::SetAutoUnjamLockTime(DWORD time) { } unjamTimeState = 1; } else { - SafeWrite8(0x4831DA, 0xEB); // disable auto unjam + SafeWrite8(0x4831DA, CodeType::JumpShort); // disable auto unjam unjamTimeState = 2; } } diff --git a/sfall/Modules/PartyControl.cpp b/sfall/Modules/PartyControl.cpp index 262852bb..eaf31566 100644 --- a/sfall/Modules/PartyControl.cpp +++ b/sfall/Modules/PartyControl.cpp @@ -527,7 +527,7 @@ static void NpcAutoLevelPatch() { npcAutoLevelEnabled = GetConfigInt("Misc", "NPCAutoLevel", 0) != 0; if (npcAutoLevelEnabled) { dlog("Applying NPC autolevel patch.", DL_INIT); - SafeWrite8(0x495CFB, 0xEB); // jmps 0x495D28 (skip random check) + SafeWrite8(0x495CFB, CodeType::JumpShort); // jmps 0x495D28 (skip random check) dlogr(" Done", DL_INIT); } } diff --git a/sfall/Modules/Perks.cpp b/sfall/Modules/Perks.cpp index b00c589b..03487f72 100644 --- a/sfall/Modules/Perks.cpp +++ b/sfall/Modules/Perks.cpp @@ -857,7 +857,7 @@ static void PerkEngineInit() { // perk_owed hooks MakeCall(0x4AFB2F, LevelUpHack, 1); // replaces 'mov edx, ds:[PlayerLevel]' - SafeWrite8(0x43C2EC, 0xEB); // skip the block of code which checks if the player has gained a perk (now handled in level up code) + SafeWrite8(0x43C2EC, CodeType::JumpShort); // skip the block of code which checks if the player has gained a perk (now handled in level up code) } static void PerkSetup() { diff --git a/sfall/Modules/Scripting/Handlers/Misc.cpp b/sfall/Modules/Scripting/Handlers/Misc.cpp index 277549ce..a496077a 100644 --- a/sfall/Modules/Scripting/Handlers/Misc.cpp +++ b/sfall/Modules/Scripting/Handlers/Misc.cpp @@ -251,7 +251,7 @@ static void __cdecl IncNPCLevel(const char* fmt, const char* name) { //SafeMemSet(0x495C8C, 0x90, 6); // Check that the npc isn't already at its maximum level SafeMemSet(0x495CEC, 0x90, 6); // Check that the npc hasn't already levelled up recently if (!npcAutoLevelEnabled) { - SafeWrite8(0x495CFB, 0xEB); // Disable random element + SafeWrite8(0x495CFB, CodeType::JumpShort); // Disable random element } __asm mov [ebp + 0x150 - 0x28 + 16], 255; // set counter for exit loop } else { @@ -281,7 +281,7 @@ void op_inc_npc_level(OpcodeContext& ctx) { data = 0x0130850F; SafeWriteBytes(0x495CEC, (BYTE*)&data, 6); if (!npcAutoLevelEnabled) { - SafeWrite8(0x495CFB, 0x74); + SafeWrite8(0x495CFB, CodeType::JumpZ); } } diff --git a/sfall/Modules/Sound.cpp b/sfall/Modules/Sound.cpp index 903603ab..29992bfb 100644 --- a/sfall/Modules/Sound.cpp +++ b/sfall/Modules/Sound.cpp @@ -586,7 +586,7 @@ void Sound::init() { //Yes, I did leave this in on purpose. Will be of use to anyone trying to add in the sound effects if (isDebug && iniGetInt("Debugging", "Test_ForceFloats", 0, ::sfall::ddrawIni)) { - SafeWrite8(0x42B6F5, 0xEB); // bypass chance + SafeWrite8(0x42B6F5, CodeType::JumpShort); // bypass chance } } } diff --git a/sfall/Modules/Worldmap.cpp b/sfall/Modules/Worldmap.cpp index 15b90f36..eb73773a 100644 --- a/sfall/Modules/Worldmap.cpp +++ b/sfall/Modules/Worldmap.cpp @@ -361,8 +361,8 @@ static void WorldLimitsPatches() { //if (GetConfigInt("Misc", "CitiesLimitFix", 0)) { dlog("Applying cities limit patch.", DL_INIT); - if (*((BYTE*)0x4BF3BB) != 0xEB) { - SafeWrite8(0x4BF3BB, 0xEB); + if (*((BYTE*)0x4BF3BB) != CodeType::JumpShort) { + SafeWrite8(0x4BF3BB, CodeType::JumpShort); } dlogr(" Done", DL_INIT); //} diff --git a/sfall/ddraw.vcxproj.filters b/sfall/ddraw.vcxproj.filters index 81ae99f0..17ce79f4 100644 --- a/sfall/ddraw.vcxproj.filters +++ b/sfall/ddraw.vcxproj.filters @@ -19,12 +19,6 @@ {023f674e-f534-4889-af91-c5f1ef3a8913} - - {f35af494-a226-4c24-9ac2-9876f46b7a6b} - - - {66d430dc-ddd0-41e3-a13d-bf1d5a1a1064} - @@ -40,6 +34,15 @@ Modules + + Modules + + + Modules + + + Modules + Modules @@ -55,15 +58,24 @@ Modules + + Modules + Modules Modules + + Modules + Modules + + Modules + Modules @@ -73,9 +85,21 @@ Modules + + Modules + + + Modules + + + Modules + Modules + + Modules + @@ -88,6 +112,9 @@ Modules + + Modules + Modules @@ -168,15 +195,30 @@ + + Modules + Modules + + Modules + Modules Modules + + Modules + + + Modules + + + Modules + Modules @@ -250,57 +292,9 @@ Modules\SubModules - - Modules\SimplePatches - - - Modules\SimplePatches - - - Modules\SimplePatches - - - Modules\SimplePatches - - - Modules\SimplePatches - - - Modules\SimplePatches - - - Modules\SimplePatches - - - Modules\SimplePatches - - - Modules\SimplePatches - - - Modules\SimplePatches - - - Modules\SimplePatches - - - Modules\Features - - - Modules\Features - - - Modules\Features - - - Modules\Features - Modules\Scripting\Handlers - - Modules - FalloutEngine @@ -319,6 +313,15 @@ Modules + + Modules + + + Modules + + + Modules + Modules @@ -334,15 +337,24 @@ Modules + + Modules + Modules Modules + + Modules + Modules + + Modules + Modules @@ -352,9 +364,21 @@ Modules + + Modules + + + Modules + + + Modules + Modules + + Modules + @@ -367,6 +391,9 @@ Modules + + Modules + Modules @@ -432,15 +459,30 @@ Modules + + Modules + Modules + + Modules + Modules Modules + + Modules + + + Modules + + + Modules + Modules @@ -505,57 +547,9 @@ Modules\SubModules - - Modules\SimplePatches - - - Modules\SimplePatches - - - Modules\SimplePatches - - - Modules\SimplePatches - - - Modules\SimplePatches - - - Modules\SimplePatches - - - Modules\SimplePatches - - - Modules\SimplePatches - - - Modules\SimplePatches - - - Modules\SimplePatches - - - Modules\SimplePatches - - - Modules\Features - - - Modules\Features - - - Modules\Features - - - Modules\Features - Modules\Scripting\Handlers - - Modules -