Added new HOOK_BUILDSFXWEAPON (#560)

* Hook for gsnd_build_weapon_sfx_name
* Fixed long name ACM crash in AutoSearchSFX
* Updated documents
This commit is contained in:
Vlad
2024-07-19 19:36:04 +08:00
committed by GitHub
parent 87202bb124
commit 9fdbacf4ca
10 changed files with 138 additions and 0 deletions
+2
View File
@@ -76,6 +76,8 @@
#define HOOK_ROLLCHECK (46)
#define HOOK_BESTWEAPON (47)
#define HOOK_CANUSEWEAPON (48)
// RESERVED 49..60
#define HOOK_BUILDSFXWEAPON (61)
// Valid arguments to list_begin
#define LIST_CRITTERS (0)
+14
View File
@@ -818,4 +818,18 @@
int arg3 - original result of engine function: 1 - can use, 0 - cannot use
int ret0 - overrides the result of engine function. Any non-zero value allows using the weapon
- name: BuildSfxWeapon
id: HOOK_BUILDSFXWEAPON
doc: |
Runs before each weapon sound effect is played or put in the animation queue to determine the name of sound effect file based on the weapon, target and action being performed.
```
int arg0 - weapon sound effect type: 0 - ready/reload, 1 - attack, 2 - out of ammo, 3 - flying (for projectile weapons), 4 - hit
Item arg1 - the weapon being used
int arg2 - attack type (see ATKTYPE_* constants)
Obj arg3 - target of the attack (can be 0)
String ret0 - the new sound file name to use, without extension (relative to "sound\sfx" path)
```
+15
View File
@@ -936,3 +936,18 @@ int arg3 - original result of engine function: 1 - can use, 0 - cannot use
int ret0 - overrides the result of engine function. Any non-zero value allows using the weapon
```
-------------------------------------------
#### `HOOK_BUILDSFXWEAPON (hs_buildsfxweapon.int)`
Runs before each weapon sound effect is played or put in the animation queue to determine the name of sound effect file based on the weapon, target and action being performed.
```
int arg0 - weapon sound effect type: 0 - ready/reload, 1 - attack, 2 - out of ammo, 3 - flying (for projectile weapons), 4 - hit
Item arg1 - the weapon being used
int arg2 - attack type (see ATKTYPE_* constants)
Obj arg3 - target of the attack (can be 0)
String ret0 - the new sound file name to use, without extension (relative to "sound\sfx" path)
```
+15
View File
@@ -31,6 +31,7 @@
#include "HookScripts\InventoryHs.h"
#include "HookScripts\ObjectHs.h"
#include "HookScripts\MiscHs.h"
#include "HookScripts\SoundHs.h"
#include "HookScripts.h"
@@ -110,6 +111,19 @@ static HooksInjectInfo injectHooks[] = {
{HOOK_ROLLCHECK, Inject_RollCheckHook, 0},
{HOOK_BESTWEAPON, Inject_BestWeaponHook, 0},
{HOOK_CANUSEWEAPON, Inject_CanUseWeaponHook, 0},
{-1}, // RESERVED
{-1}, // RESERVED
{-1}, // HOOK_MOUSEWHEEL
{-1}, // RESERVED
{-1}, // RESERVED
{-1}, // RESERVED
{-1}, // HOOK_COMBATATTACK
{-1}, // RESERVED
{-1}, // RESERVED
{-1}, // RESERVED
{-1}, // RESERVED
{-1}, // RESERVED
{HOOK_BUILDSFXWEAPON, Inject_BuildSfxWeaponHook, 0},
};
void HookScripts::InjectingHook(int hookId) {
@@ -216,6 +230,7 @@ void HookScripts::LoadHookScripts() {
InitInventoryHookScripts();
InitObjectHookScripts();
InitMiscHookScripts();
InitSoundHookScripts();
HookScripts::LoadHookScript("hs_keypress", HOOK_KEYPRESS);
HookScripts::LoadHookScript("hs_mouseclick", HOOK_MOUSECLICK);
+2
View File
@@ -75,6 +75,8 @@ enum HookType
HOOK_ROLLCHECK = 46,
HOOK_BESTWEAPON = 47,
HOOK_CANUSEWEAPON = 48,
// RESERVED 49 to 60
HOOK_BUILDSFXWEAPON = 61,
HOOK_COUNT
};
+75
View File
@@ -0,0 +1,75 @@
#include "..\..\FalloutEngine\Fallout2.h"
#include "..\..\SafeWrite.h"
#include "..\HookScripts.h"
#include "Common.h"
#include "SoundHs.h"
using namespace sfall::script;
// Object hook scripts
namespace sfall
{
static DWORD __fastcall BuildSfxNameHook_Script(long effectType, fo::GameObject* weapon, long hitMode, fo::GameObject* target) {
BeginHook();
allowNonIntReturn = true;
argCount = 4;
args[0] = effectType;
args[1] = (DWORD)weapon;
args[2] = (DWORD)hitMode;
args[3] = (DWORD)target;
RunHookScript(HOOK_BUILDSFXWEAPON);
DWORD textPtr = cRet > 0 && retTypes[0] == DataType::STR
? rets[0]
: 0;
EndHook();
return textPtr; // -1 - default handler
}
static __declspec(naked) void gsnd_build_weapon_sfx_name_hook() {
__asm {
pushadc; // save state
push ebx;
push ecx; // target
push ebx; // hitMode
// edx - weapon
mov ecx, eax; // effectType
call BuildSfxNameHook_Script;
test eax, eax; // pointer to text
pop ebx; // restore state
pop ecx;
pop edx;
jnz skip;
pop eax;
jmp fo::funcoffs::gsnd_build_weapon_sfx_name_;
skip:
add esp, 4;
retn;
}
}
void Inject_BuildSfxWeaponHook() {
HookCalls(gsnd_build_weapon_sfx_name_hook, {
0x410DB3, // show_damage_to_object
0x411397, 0x411538, // action_melee
0x411787, 0x41196C, 0x411A96, 0x411B82, // action_ranged
0x4268F5, // combat_attack_this
0x42A9B4, 0x42AA92, 0x42AAF0, // ai_try_attack
0x42AF4C, // cai_attempt_w_reload
0x45BD31, // op_sfx_build_weapon_name
0x460B87, // intface_item_reload
0x476629, // drop_ammo_into_weapon
});
}
void InitSoundHookScripts() {
HookScripts::LoadHookScript("hs_buildsfxweapon", HOOK_BUILDSFXWEAPON);
}
}
+10
View File
@@ -0,0 +1,10 @@
#pragma once
namespace sfall
{
void InitSoundHookScripts();
void Inject_BuildSfxWeaponHook();
}
+1
View File
@@ -1061,6 +1061,7 @@ void Sound::init() {
if (IniReader::GetConfigInt("Sound", "AutoSearchSFX", 1)) {
HookCalls(sfxl_init_hook, {0x4A9999, 0x4A9B34});
SafeWrite8(0x4A9B3F, 0xA9); // jz 0x4A9BEC (skip error message)
SafeWrite8(0x4AA060, 127); // fix crash when ACM file has name longer than 12 symbols
}
if (IniReader::GetConfigString("Sound", "MainMenuMusic", "", mainMenuMusic, 9)) {
+2
View File
@@ -402,6 +402,7 @@
<ClInclude Include="Modules\CritterStats.h" />
<ClInclude Include="Modules\EngineTweaks.h" />
<ClInclude Include="Modules\ExtraArt.h" />
<ClInclude Include="Modules\HookScripts\SoundHs.h" />
<ClInclude Include="Modules\Interface.h" />
<ClInclude Include="Modules\Drugs.h" />
<ClInclude Include="Modules\HookScripts\CombatHs.h" />
@@ -544,6 +545,7 @@
<ClCompile Include="Modules\CritterStats.cpp" />
<ClCompile Include="Modules\EngineTweaks.cpp" />
<ClCompile Include="Modules\ExtraArt.cpp" />
<ClCompile Include="Modules\HookScripts\SoundHs.cpp" />
<ClCompile Include="Modules\Interface.cpp" />
<ClCompile Include="Modules\Drugs.cpp" />
<ClCompile Include="Modules\HookScripts\CombatHs.cpp" />
+2
View File
@@ -460,6 +460,7 @@
<ClInclude Include="Modules\ExtraArt.h">
<Filter>Modules</Filter>
</ClInclude>
<ClInclude Include="Modules\HookScripts\SoundHs.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="main.cpp" />
@@ -840,6 +841,7 @@
<ClCompile Include="Modules\ExtraArt.cpp">
<Filter>Modules</Filter>
</ClCompile>
<ClCompile Include="Modules\HookScripts\SoundHs.cpp" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="version.rc" />