mirror of
https://github.com/sfall-team/sfall.git
synced 2026-07-27 16:52:34 -07:00
Prevent RegisterHook() from registering placeholder hooks
Minor edits to code and documents.
This commit is contained in:
@@ -818,18 +818,23 @@
|
||||
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.
|
||||
Runs before each weapon sound effect is played or added to the animation queue to determine the name of the 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
|
||||
int arg0 - weapon sound effect type:
|
||||
0 - ready/reload
|
||||
1 - attack
|
||||
2 - out of ammo
|
||||
3 - flying (for projectiles from 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)
|
||||
Obj arg3 - the target of the attack (can be 0)
|
||||
|
||||
String ret0 - the new sound file name to use, without extension (relative to "sound\sfx" path)
|
||||
String ret0 - the filename of the new sound effect to use, without extension (relative to the sound\sfx\ directory)
|
||||
```
|
||||
|
||||
@@ -941,13 +941,18 @@ int ret0 - overrides the result of engine function. Any non-zero value allow
|
||||
|
||||
#### `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.
|
||||
Runs before each weapon sound effect is played or added to the animation queue to determine the name of the 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
|
||||
int arg0 - weapon sound effect type:
|
||||
0 - ready/reload
|
||||
1 - attack
|
||||
2 - out of ammo
|
||||
3 - flying (for projectiles from 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)
|
||||
Obj arg3 - the target of the attack (can be 0)
|
||||
|
||||
String ret0 - the new sound file name to use, without extension (relative to "sound\sfx" path)
|
||||
String ret0 - the filename of the new sound effect to use, without extension (relative to the sound\sfx\ directory)
|
||||
```
|
||||
|
||||
@@ -143,7 +143,7 @@ bool HookScripts::HookHasScript(int hookId) {
|
||||
}
|
||||
|
||||
void HookScripts::RegisterHook(fo::Program* script, int id, int procNum, bool specReg) {
|
||||
if (id >= numHooks) return;
|
||||
if (id >= numHooks || injectHooks[id].id < 0) return;
|
||||
for (std::vector<HookScript>::iterator it = hooks[id].begin(); it != hooks[id].end(); ++it) {
|
||||
if (it->prog.ptr == script) {
|
||||
if (procNum == 0) hooks[id].erase(it); // unregister
|
||||
|
||||
@@ -7,11 +7,10 @@
|
||||
|
||||
using namespace sfall::script;
|
||||
|
||||
// Object hook scripts
|
||||
namespace sfall
|
||||
{
|
||||
|
||||
static DWORD __fastcall BuildSfxNameHook_Script(long effectType, fo::GameObject* weapon, long hitMode, fo::GameObject* target) {
|
||||
static DWORD __fastcall BuildSfxWeaponHook_Script(long effectType, fo::GameObject* weapon, long hitMode, fo::GameObject* target) {
|
||||
BeginHook();
|
||||
allowNonIntReturn = true;
|
||||
argCount = 4;
|
||||
@@ -37,9 +36,8 @@ static __declspec(naked) void gsnd_build_weapon_sfx_name_hook() {
|
||||
push ebx;
|
||||
push ecx; // target
|
||||
push ebx; // hitMode
|
||||
// edx - weapon
|
||||
mov ecx, eax; // effectType
|
||||
call BuildSfxNameHook_Script;
|
||||
call BuildSfxWeaponHook_Script; // edx - weapon
|
||||
test eax, eax; // pointer to text
|
||||
pop ebx; // restore state
|
||||
pop ecx;
|
||||
@@ -56,15 +54,15 @@ skip:
|
||||
|
||||
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
|
||||
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_
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -1061,7 +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
|
||||
SafeWrite8(0x4AA060, 127); // fix crash when ACM file has name longer than 12 characters
|
||||
}
|
||||
|
||||
if (IniReader::GetConfigString("Sound", "MainMenuMusic", "", mainMenuMusic, 9)) {
|
||||
|
||||
@@ -460,7 +460,9 @@
|
||||
<ClInclude Include="Modules\ExtraArt.h">
|
||||
<Filter>Modules</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Modules\HookScripts\SoundHs.h" />
|
||||
<ClInclude Include="Modules\HookScripts\SoundHs.h">
|
||||
<Filter>Modules\HookScripts</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="main.cpp" />
|
||||
@@ -841,7 +843,9 @@
|
||||
<ClCompile Include="Modules\ExtraArt.cpp">
|
||||
<Filter>Modules</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Modules\HookScripts\SoundHs.cpp" />
|
||||
<ClCompile Include="Modules\HookScripts\SoundHs.cpp">
|
||||
<Filter>Modules\HookScripts</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ResourceCompile Include="version.rc" />
|
||||
|
||||
Reference in New Issue
Block a user