REFramework
REFramework copied to clipboard
MHRise: failed to hook: MH_ERROR_MEMORY_ALLOC
If this error occurs, some hook function never worked again, even if reset script
has no errors in the log.
I found this error is probably due to the framework can only hook a limited number of functions to a certain type.
This happens in some popular types like snow.gui.GuiManager
, so many mods hook this type, so some of them just don't work because the hook failed.
When the limit is reached, even the Hook function in DeveloperTools will not work correctly.
However, the error does not always occur. Occasionally it may not appear, but it is more likely to occur.
Here is a sample log
[2022-11-29 10:46:23.205] [REFramework] [info] [HookManager] Adding hook for 'calcPhysicalDamageEquipSkill224' @ 0x1422c4900...
[2022-11-29 10:46:23.205] [REFramework] [info] [HookManager] Creating a new hook...
[2022-11-29 10:46:23.205] [REFramework] [info] [HookManager] Hook assigned ID 0
[2022-11-29 10:46:23.205] [REFramework] [info] Attempting to hook 0x1422c4900->0x1eee44500
[2022-11-29 10:46:23.216] [REFramework] [error] Failed to hook 0x1422c4900: MH_ERROR_MEMORY_ALLOC
[2022-11-29 10:46:23.216] [REFramework] [error] FunctionHook not initialized
Okay. Looks like it's time to switch to safetyhook. MinHook doesn't handle allocating nearby memory and jmp instructions very well.
I also found that some update
function always can't be hooked after the game is updated.
update
of snow.gui.fsm.title.GuiGameStartFsm_CAPCOMLogoFadeIn
and snow.gui.fsm.title.GuiGameStartFsm_RELogoFadeIn
[2022-11-29 16:15:06.643] [REFramework] [info] [HookManager] Hook 0 added for 'update' @ 0x23fff0c13
[2022-11-29 16:15:06.643] [REFramework] [info] [HookManager] Using actual function @ 0x23fff0c13 for wrapper function @ 0x140fbcbf0
[2022-11-29 16:15:06.643] [REFramework] [info] [HookManager] Adding hook for 'update' @ 0x23fff0c13...
[2022-11-29 16:15:06.643] [REFramework] [info] [HookManager] Creating a new hook...
[2022-11-29 16:15:06.643] [REFramework] [info] [HookManager] Hook assigned ID 0
[2022-11-29 16:15:06.643] [REFramework] [info] Attempting to hook 0x23fff0c13->0x1ef6f0640
[2022-11-29 16:15:06.643] [REFramework] [error] Failed to hook 0x23fff0c13: MH_ERROR_NOT_EXECUTABLE
[2022-11-29 16:15:06.643] [REFramework] [error] FunctionHook not initialized
To this day I still get this error, two thirds of the time when I launch the game half of my scripts just won't load
[2023-03-01 15:24:39.183] [REFramework] [info] [HookManager] Hook 245 added for 'calcPhysicalDamageAssassin' @ 0x142d04b50 [2023-03-01 15:24:39.183] [REFramework] [info] [HookManager] Adding hook for 'calcHitAttackResultForEnemy' @ 0x142d01550... [2023-03-01 15:24:39.183] [REFramework] [info] [HookManager] Creating a new hook... [2023-03-01 15:24:39.183] [REFramework] [info] [HookManager] Hook assigned ID 247 [2023-03-01 15:24:39.183] [REFramework] [info] Attempting to hook 0x142d01550->0x1d6e09200 [2023-03-01 15:24:39.197] [REFramework] [error] Failed to hook 0x142d01550: MH_ERROR_MEMORY_ALLOC [2023-03-01 15:24:39.197] [REFramework] [error] FunctionHook not initialized
Short jmp expansion is making its way into safetyhook soon which is why this hasn't been worked on recently. When I was originally working on this issue I ran into the roadblock of some hooks failing because of the short jmps near the beginning of the function failing to be expanded.
still running into this error as well, i'm guessing this is the main reason why some scripts just don't seem to function consistently between launches?
Now that I'm getting into finishing the game and modding heavily, I'm running in to this too. As soon as it hits an alloc error, every hook after that fails which kills all the later-loading hooks. Has this been looked at again recently?
Fixed in 4948ab9a99d6d8498a40c784fdc31698747bccfe