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.
This commit is contained in:
NovaRain
2020-04-23 12:42:20 +08:00
parent cb1d5d359f
commit 1839790dfb
7 changed files with 35 additions and 17 deletions
+1 -1
View File
@@ -93,7 +93,7 @@ WorldMapTerrainInfo=0
;XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ;XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
[Sound] [Sound]
;Sets the number of allowed simultaneous sound effects ;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 NumSoundBuffers=0
;Set to 1 to allow attaching sound files to combat float messages ;Set to 1 to allow attaching sound files to combat float messages
+10 -9
View File
@@ -1435,15 +1435,16 @@ end:
static void __declspec(naked) combat_display_hack() { static void __declspec(naked) combat_display_hack() {
__asm { __asm {
test [esi + 0x24], 0x8; // ctd.mainTarget (ObjectFlag Flat) test [esi + 0x24], 0x8; // ctd.mainTarget (ObjectFlag Flat)
jnz flatTarget; // Flat flag is set jnz end; // Main target is flat (engine jump)
mov ebx, 0x42536B; cmp eax, OBJ_TYPE_CRITTER << 24; // Is this a critter?
je end; // This is a critter je end; // Yes (engine no jump)
cmp dword ptr [ecx+0x78], -1; // Does the target have a script? cmp dword ptr [ecx + 0x78], -1; // Does the target have a script?
jne end; // Yes // jne hasScript; // Yes (engine no jump)
flatTarget: lahf;
mov ebx, 0x425413; xor ah, 0x40; // invert ZF (01000000b)
sahf; // if there is a script, do not jump (ZF is set)
end: 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 // 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 // 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 // Fix for damage_p_proc being called for misses if the target is not a critter
MakeCall(0x424CD2, apply_damage_hack); MakeCall(0x424CD2, apply_damage_hack);
+12 -3
View File
@@ -29,7 +29,7 @@
static const DWORD bodypartAddr[] = { static const DWORD bodypartAddr[] = {
0x425562, // combat_display_ 0x425562, // combat_display_
0x42A68F, 0x42A739, // ai_called_shot_ 0x42A68F, 0x42A739, // ai_called_shot_
0x429E82, 0x429EC2, 0x429EFF, // ai_pick_hit_mode_ // 0x429E82, 0x429EC2, 0x429EFF, // ai_pick_hit_mode_
0x423231, 0x423268, // check_ranged_miss_ 0x423231, 0x423268, // check_ranged_miss_
0x4242D4, // attack_crit_failure_ 0x4242D4, // attack_crit_failure_
// for combat_ctd_init_ func // for combat_ctd_init_ func
@@ -291,7 +291,7 @@ static long __fastcall CheckDisableBurst(TGameObj* critter) {
return 0; return 0;
} }
static void __declspec(naked) ai_pick_hit_mode_hack() { static void __declspec(naked) ai_pick_hit_mode_hack_noSecondary() {
__asm { __asm {
mov ebx, [eax + 0x94]; // cap->area_attack_mode mov ebx, [eax + 0x94]; // cap->area_attack_mode
push eax; push eax;
@@ -491,6 +491,13 @@ static void BodypartHitReadConfig() {
bodypartHit.Uncalled = static_cast<long>(GetConfigInt("Misc", "BodyHit_Torso_Uncalled", 0)); bodypartHit.Uncalled = static_cast<long>(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() { static void __declspec(naked) apply_damage_hack() {
__asm { __asm {
xor edx, edx; xor edx, edx;
@@ -538,7 +545,7 @@ void CombatInit() {
BlockCall(0x424796); BlockCall(0x424796);
// Actually disables all secondary attacks for the critter, regardless of whether the weapon has a burst attack // 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)) { if (GetConfigInt("Misc", "CheckWeaponAmmoCost", 0)) {
MakeCall(0x4234B3, compute_spray_hack, 1); MakeCall(0x4234B3, compute_spray_hack, 1);
@@ -556,4 +563,6 @@ void CombatInit() {
BlockCall(0x42303F); // block Body_Torso check (combat_attack_) BlockCall(0x42303F); // block Body_Torso check (combat_attack_)
SafeWrite8(0x42A713, 7); // Body_Uncalled > Body_Groin (ai_called_shot_) SafeWrite8(0x42A713, 7); // Body_Uncalled > Body_Groin (ai_called_shot_)
SafeWriteBatch<BYTE>(8, bodypartAddr); // replace Body_Torso with Body_Uncalled SafeWriteBatch<BYTE>(8, bodypartAddr); // replace Body_Torso with Body_Uncalled
const DWORD pickHitBodypartAddr[] = {0x429E8C, 0x429ECC, 0x429F09};
HookCalls(ai_pick_hit_mode_hook_bodypart, pickHitBodypartAddr);
} }
+3
View File
@@ -349,7 +349,10 @@ const DWORD dbase_open_ = 0x4E4F58;
const DWORD debug_log_ = 0x4C7028; const DWORD debug_log_ = 0x4C7028;
const DWORD debug_printf_ = 0x4C6F48; const DWORD debug_printf_ = 0x4C6F48;
const DWORD debug_register_env_ = 0x4C6D90; 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_func_ = 0x4243A8;
const DWORD determine_to_hit_no_range_ = 0x424380;
const DWORD dialog_out_ = 0x41CF20; const DWORD dialog_out_ = 0x41CF20;
const DWORD displayInWindow_ = 0x4B8B10; const DWORD displayInWindow_ = 0x4B8B10;
const DWORD display_inventory_ = 0x46FDF4; const DWORD display_inventory_ = 0x46FDF4;
+3
View File
@@ -610,7 +610,10 @@ extern const DWORD dbase_open_;
extern const DWORD debug_log_; extern const DWORD debug_log_;
extern const DWORD debug_printf_; extern const DWORD debug_printf_;
extern const DWORD debug_register_env_; 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_func_;
extern const DWORD determine_to_hit_no_range_;
extern const DWORD dialog_out_; extern const DWORD dialog_out_;
extern const DWORD displayInWindow_; extern const DWORD displayInWindow_;
extern const DWORD display_inventory_; extern const DWORD display_inventory_;
+2 -2
View File
@@ -407,6 +407,8 @@ HRESULT _stdcall FakeDirectInputCreate(HINSTANCE a, DWORD b, IDirectInputA** c,
HRESULT hr = proc(a, b, c, d); HRESULT hr = proc(a, b, c, d);
if (FAILED(hr)) return hr; if (FAILED(hr)) return hr;
*c = (IDirectInputA*)new FakeDirectInput(*c);
reverseMouse = GetConfigInt("Input", "ReverseMouseButtons", 0) != 0; reverseMouse = GetConfigInt("Input", "ReverseMouseButtons", 0) != 0;
useScrollWheel = GetConfigInt("Input", "UseScrollWheel", 1) != 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); if (isDebug) debugEditorKey = GetConfigInt("Input", "DebugEditorKey", 0);
*c = (IDirectInputA*)new FakeDirectInput(*c);
keyboardLayout = GetKeyboardLayout(0); keyboardLayout = GetKeyboardLayout(0);
return hr; return hr;
+4 -2
View File
@@ -574,7 +574,8 @@ void SoundInit() {
// Pause and resume sound playback when the game loses focus // Pause and resume sound playback when the game loses focus
SetFocusFunc(SoundLostFocus); SetFocusFunc(SoundLostFocus);
if (int allowDShowSound = GetConfigInt("Sound", "AllowDShowSound", 0) > 0) { int allowDShowSound = GetConfigInt("Sound", "AllowDShowSound", 0);
if (allowDShowSound > 0) {
MakeJump(0x4AD499, soundLoad_hack); MakeJump(0x4AD499, soundLoad_hack);
const DWORD gmoviePlayStopAddr[] = {0x44E80A, 0x445280}; const DWORD gmoviePlayStopAddr[] = {0x44E80A, 0x445280};
HookCalls(gmovie_play_hook_stop, gmoviePlayStopAddr); // only play looping music HookCalls(gmovie_play_hook_stop, gmoviePlayStopAddr); // only play looping music
@@ -584,7 +585,8 @@ void SoundInit() {
CreateSndWnd(); CreateSndWnd();
} }
if (int sBuff = GetConfigInt("Sound", "NumSoundBuffers", 0)) { int sBuff = GetConfigInt("Sound", "NumSoundBuffers", 0);
if (sBuff > 0 && sBuff <= 32) {
SafeWrite8(0x451129, (BYTE)sBuff); SafeWrite8(0x451129, (BYTE)sBuff);
} }