Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG - Experiemental] RegisterHook generally not working in Grounded #626

Open
Aidanamite opened this issue Aug 20, 2024 · 9 comments
Open

Comments

@Aidanamite
Copy link

Aidanamite commented Aug 20, 2024

Branch or Release
Experimental 3.0.1-151

Game and Engine Version
Grounded
UE 4.27

Describe the bug
Most of the functions in Grounded do not seem to be able to be hooked. Some can, but most not. Calling the RegisterHook function says that it was successful in the log, but when the function is supposed to occur, the function provided to the hook is simply not run.

I have attempted to fix the issue by both configuring the engine version override to the game's engine version and delaying registering the hooks even as late as after I've loaded into a world.

Based on what I can tell from using the zDev tools for UE4SS, the functions that are not hookable are any function that is both Final and BlueprintCallable

Using the UE4SS header dumps, I was able to use Cheat Engine to find the function and add a breakpoint to verify that the function is being called and it is, just that the hook itself isn't

To Reproduce

  1. Use the RegisterHook function on any function that is Final & BlueprintCallable
  2. Do something that would trigger that function

In my case, the main function I've been trying to hook is the /Script/Maine.Item:RemoveDurability function

Expected behavior
I expected the hook function to be run.

Desktop (please complete the following information):

  • OS: Win10
@jgold189
Copy link

@Aidanamite can you possibly explain your steps a bit more in-depth for how you confirmed the function were still being called even though the registered hook was never triggering? I'm trying to figure out if I'm running into the same issue when trying to mod Echo Point Nova which is unreal engine version 4.27.2.0. I'm on the 3.0.1 release so slightly different from the experimental branch but I checked 2.5.2 and nothing was different.

@Aidanamite
Copy link
Author

can you possibly explain your steps a bit more in-depth for how you confirmed the function were still being called even though the registered hook was never triggering?

i used cheat engine to manually locate the function's native code and used breakpoints to check if the code worked how i thought it did

@Aidanamite
Copy link
Author

as a side note to that: i've been "modding" the game using cheat engine for a while now, making fairly complex scripts to add in various behaviours.

i was hoping to be able to use ue4ss to remake the same sort of tweaks in a more dynamic and maintainable way

@igromanru
Copy link
Contributor

as a side note to that: i've been "modding" the game using cheat engine for a while now, making fairly complex scripts to add in various behaviours.

i was hoping to be able to use ue4ss to remake the same sort of tweaks in a more dynamic and maintainable way

Make a UE4SS C++ mod then. It has more freedom, Lua implementation is still very limited.

@Aidanamite
Copy link
Author

Aidanamite commented Oct 22, 2024

can the c++ mods hook functions that lua can't? as far as i can tell, the issue is that it's failing to hook the functions, therefore wouldn't it have the same issue regardless of if i'm using lua or c++ or does it use a completely different hooking system for c++ mods?

@igromanru
Copy link
Contributor

igromanru commented Oct 22, 2024

can the c++ mods hook functions that lua can't? as far as i can tell, the issue is that it's failing to hook the functions, therefore wouldn't it have the same issue regardless of if i'm using lua or c++ or does it use a completely different hooking system for c++ mods?

Lua is just basically an API to call C++ functions, but it's not just a simple 1:1 call, it's more complicated and depends on the implementation.
UE4SS C++ has much more options that you can use. In worst case you can always use RegisterProcessEventPreCallback or RegisterProcessEventPostCallback and catch the call of your function this way.
You can even hook native or vtable functions that are not reflected, but it would obviously require some reverse engineering.
Long story short, in C++ you can do anything.

@Aidanamite
Copy link
Author

so do you think the issue of the lua hook not working is caused by the hook just failing to call the lua callback and not because the hook isn't attaching to the function correctly?

@igromanru
Copy link
Contributor

igromanru commented Oct 22, 2024

so do you think the issue of the lua hook not working is caused by the hook just failing to call the lua callback and not because the hook isn't attaching to the function correctly?

No, it's definitely not it. I just say that in a C++ mod you have much more options.

After reading the first post once again, I think that the problem is that the game never calls the function over ProcessEvent, but calls it over it's native function.
It is quite common that there are functions that are exposed to reflection but are only called by C++ code, which then uses its underlined native function. That's most likely the reason why you can breakpoint the function with CE but the hook in Lua never gets triggered.
In such case the only solution is to hook the native function with a detour hook, which is only possible with a C++ DLL inside the game.

@Aidanamite
Copy link
Author

i assumed the hooks were detour hooks by default. because that's the more reliable way to ensure the hook gets called.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants