From 1839790dfbb5a61e785ecdec36cdcc3390955e79 Mon Sep 17 00:00:00 2001 From: NovaRain Date: Thu, 23 Apr 2020 12:42:20 +0800 Subject: [PATCH] Fixed AllowDShowSound=2 not working Limited NumSoundBuffers to the max of 32. Fixed replacing Body_Torso with Body_Uncalled (from commit 62f890d) Corrected the code in the previous commit. --- artifacts/ddraw.ini | 2 +- sfall/BugFixes.cpp | 19 ++++++++++--------- sfall/Combat.cpp | 15 ++++++++++++--- sfall/FalloutEngine.cpp | 3 +++ sfall/FalloutEngine.h | 3 +++ sfall/InputFuncs.cpp | 4 ++-- sfall/Sound.cpp | 6 ++++-- 7 files changed, 35 insertions(+), 17 deletions(-) diff --git a/artifacts/ddraw.ini b/artifacts/ddraw.ini index d4933d27..566b99f7 100644 --- a/artifacts/ddraw.ini +++ b/artifacts/ddraw.ini @@ -93,7 +93,7 @@ WorldMapTerrainInfo=0 ;XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX [Sound] ;Sets the number of allowed simultaneous sound effects -;Set to 0 to leave the default unchanged (i.e. 4) +;Set to 0 to leave the default unchanged (i.e. 4). The maximum is 32 NumSoundBuffers=0 ;Set to 1 to allow attaching sound files to combat float messages diff --git a/sfall/BugFixes.cpp b/sfall/BugFixes.cpp index 0bbefc6a..e7767ba8 100644 --- a/sfall/BugFixes.cpp +++ b/sfall/BugFixes.cpp @@ -1435,15 +1435,16 @@ end: static void __declspec(naked) combat_display_hack() { __asm { test [esi + 0x24], 0x8; // ctd.mainTarget (ObjectFlag Flat) - jnz flatTarget; // Flat flag is set - mov ebx, 0x42536B; - je end; // This is a critter - cmp dword ptr [ecx+0x78], -1; // Does the target have a script? - jne end; // Yes -flatTarget: - mov ebx, 0x425413; + jnz end; // Main target is flat (engine jump) + cmp eax, OBJ_TYPE_CRITTER << 24; // Is this a critter? + je end; // Yes (engine no jump) + cmp dword ptr [ecx + 0x78], -1; // Does the target have a script? +// jne hasScript; // Yes (engine no jump) + lahf; + xor ah, 0x40; // invert ZF (01000000b) + sahf; // if there is a script, do not jump (ZF is set) end: - jmp ebx; + retn; } } @@ -2986,7 +2987,7 @@ void BugFixesInit() // Fix for the displayed message when the attack randomly hits a target that is not a critter and has a script attached // Tweak: if the main target has Flat flag set, display the "You missed" message instead of the message of hitting another object - MakeJump(0x425365, combat_display_hack, 1); + MakeCall(0x42535F, combat_display_hack, 1); // Fix for damage_p_proc being called for misses if the target is not a critter MakeCall(0x424CD2, apply_damage_hack); diff --git a/sfall/Combat.cpp b/sfall/Combat.cpp index 7b10d096..ac0e85e7 100644 --- a/sfall/Combat.cpp +++ b/sfall/Combat.cpp @@ -29,7 +29,7 @@ static const DWORD bodypartAddr[] = { 0x425562, // combat_display_ 0x42A68F, 0x42A739, // ai_called_shot_ - 0x429E82, 0x429EC2, 0x429EFF, // ai_pick_hit_mode_ +// 0x429E82, 0x429EC2, 0x429EFF, // ai_pick_hit_mode_ 0x423231, 0x423268, // check_ranged_miss_ 0x4242D4, // attack_crit_failure_ // for combat_ctd_init_ func @@ -291,7 +291,7 @@ static long __fastcall CheckDisableBurst(TGameObj* critter) { return 0; } -static void __declspec(naked) ai_pick_hit_mode_hack() { +static void __declspec(naked) ai_pick_hit_mode_hack_noSecondary() { __asm { mov ebx, [eax + 0x94]; // cap->area_attack_mode push eax; @@ -491,6 +491,13 @@ static void BodypartHitReadConfig() { bodypartHit.Uncalled = static_cast(GetConfigInt("Misc", "BodyHit_Torso_Uncalled", 0)); } +static void __declspec(naked) ai_pick_hit_mode_hook_bodypart() { + __asm { + mov ebx, 8; // replace Body_Torso with Body_Uncalled + jmp determine_to_hit_; + } +} + static void __declspec(naked) apply_damage_hack() { __asm { xor edx, edx; @@ -538,7 +545,7 @@ void CombatInit() { BlockCall(0x424796); // Actually disables all secondary attacks for the critter, regardless of whether the weapon has a burst attack - MakeCall(0x429E44, ai_pick_hit_mode_hack, 1); // NoBurst + MakeCall(0x429E44, ai_pick_hit_mode_hack_noSecondary, 1); // NoBurst if (GetConfigInt("Misc", "CheckWeaponAmmoCost", 0)) { MakeCall(0x4234B3, compute_spray_hack, 1); @@ -556,4 +563,6 @@ void CombatInit() { 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 + const DWORD pickHitBodypartAddr[] = {0x429E8C, 0x429ECC, 0x429F09}; + HookCalls(ai_pick_hit_mode_hook_bodypart, pickHitBodypartAddr); } diff --git a/sfall/FalloutEngine.cpp b/sfall/FalloutEngine.cpp index d23558e1..ee0389ec 100644 --- a/sfall/FalloutEngine.cpp +++ b/sfall/FalloutEngine.cpp @@ -349,7 +349,10 @@ const DWORD dbase_open_ = 0x4E4F58; const DWORD debug_log_ = 0x4C7028; const DWORD debug_printf_ = 0x4C6F48; const DWORD debug_register_env_ = 0x4C6D90; +const DWORD determine_to_hit_ = 0x42436C; +const DWORD determine_to_hit_from_tile_ = 0x424394; const DWORD determine_to_hit_func_ = 0x4243A8; +const DWORD determine_to_hit_no_range_ = 0x424380; const DWORD dialog_out_ = 0x41CF20; const DWORD displayInWindow_ = 0x4B8B10; const DWORD display_inventory_ = 0x46FDF4; diff --git a/sfall/FalloutEngine.h b/sfall/FalloutEngine.h index ef16fea5..abd9532d 100644 --- a/sfall/FalloutEngine.h +++ b/sfall/FalloutEngine.h @@ -610,7 +610,10 @@ extern const DWORD dbase_open_; extern const DWORD debug_log_; extern const DWORD debug_printf_; extern const DWORD debug_register_env_; +extern const DWORD determine_to_hit_; +extern const DWORD determine_to_hit_from_tile_; extern const DWORD determine_to_hit_func_; +extern const DWORD determine_to_hit_no_range_; extern const DWORD dialog_out_; extern const DWORD displayInWindow_; extern const DWORD display_inventory_; diff --git a/sfall/InputFuncs.cpp b/sfall/InputFuncs.cpp index 5fda2342..17558345 100644 --- a/sfall/InputFuncs.cpp +++ b/sfall/InputFuncs.cpp @@ -407,6 +407,8 @@ HRESULT _stdcall FakeDirectInputCreate(HINSTANCE a, DWORD b, IDirectInputA** c, HRESULT hr = proc(a, b, c, d); if (FAILED(hr)) return hr; + *c = (IDirectInputA*)new FakeDirectInput(*c); + reverseMouse = GetConfigInt("Input", "ReverseMouseButtons", 0) != 0; useScrollWheel = GetConfigInt("Input", "UseScrollWheel", 1) != 0; @@ -427,8 +429,6 @@ HRESULT _stdcall FakeDirectInputCreate(HINSTANCE a, DWORD b, IDirectInputA** c, if (isDebug) debugEditorKey = GetConfigInt("Input", "DebugEditorKey", 0); - *c = (IDirectInputA*)new FakeDirectInput(*c); - keyboardLayout = GetKeyboardLayout(0); return hr; diff --git a/sfall/Sound.cpp b/sfall/Sound.cpp index f060553e..c1dd8180 100644 --- a/sfall/Sound.cpp +++ b/sfall/Sound.cpp @@ -574,7 +574,8 @@ void SoundInit() { // Pause and resume sound playback when the game loses focus SetFocusFunc(SoundLostFocus); - if (int allowDShowSound = GetConfigInt("Sound", "AllowDShowSound", 0) > 0) { + int allowDShowSound = GetConfigInt("Sound", "AllowDShowSound", 0); + if (allowDShowSound > 0) { MakeJump(0x4AD499, soundLoad_hack); const DWORD gmoviePlayStopAddr[] = {0x44E80A, 0x445280}; HookCalls(gmovie_play_hook_stop, gmoviePlayStopAddr); // only play looping music @@ -584,7 +585,8 @@ void SoundInit() { CreateSndWnd(); } - if (int sBuff = GetConfigInt("Sound", "NumSoundBuffers", 0)) { + int sBuff = GetConfigInt("Sound", "NumSoundBuffers", 0); + if (sBuff > 0 && sBuff <= 32) { SafeWrite8(0x451129, (BYTE)sBuff); }