Skip to content

Commit

Permalink
Add HookEngineTick setting and EngineTick as GUI RenderMode (#794)
Browse files Browse the repository at this point in the history
* feat: Add HookEngineTick setting
feat: Implement new RenderMode -> EngineTick
refactor: Changed gui_render_thread_GameViewportClientTick to gui_render_thread_tick, to be a generic function that can be used in all Tick function hooks

---------

Co-authored-by: UE4SS <91646798+UE4SS@users.noreply.github.com>
  • Loading branch information
igromanru and UE4SS authored Feb 20, 2025
1 parent dd2da52 commit 72c00a9
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 6 deletions.
5 changes: 4 additions & 1 deletion UE4SS/include/GUI/GUI.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ namespace RC::GUI
enum class RenderMode
{
ExternalThread,
GameViewportClientTick,
EngineTick,
GameViewportClientTick
};

inline auto render_mode_to_string(RenderMode mode) -> std::string
Expand All @@ -34,6 +35,8 @@ namespace RC::GUI
{
case RenderMode::ExternalThread:
return "ExternalThread";
case RenderMode::EngineTick:
return "EngineTick";
case RenderMode::GameViewportClientTick:
return "GameViewportClientTick";
}
Expand Down
1 change: 1 addition & 0 deletions UE4SS/include/SettingsManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ namespace RC
bool HookEndPlay{true};
bool HookLocalPlayerExec{true};
bool HookAActorTick{true};
bool HookEngineTick{true};
bool HookGameViewportClientTick{true};
int64_t FExecVTableOffsetInLocalPlayer{0x28};
} Hooks;
Expand Down
2 changes: 1 addition & 1 deletion UE4SS/include/UE4SSProgram.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,6 @@ namespace RC
friend void* HookedLoadLibraryExA(const char* dll_name, void* file, int32_t flags);
friend void* HookedLoadLibraryW(const wchar_t* dll_name);
friend void* HookedLoadLibraryExW(const wchar_t* dll_name, void* file, int32_t flags);
friend auto gui_render_thread_GameViewportClientTick(Unreal::UGameViewportClient*, float) -> void;
friend auto gui_render_thread_tick(Unreal::UObject*, float) -> void;
};
} // namespace RC
5 changes: 5 additions & 0 deletions UE4SS/src/SettingsManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ namespace RC
{
Debug.RenderMode = GUI::RenderMode::ExternalThread;
}
else if (String::iequal(render_mode_string, STR("EngineTick")))
{
Debug.RenderMode = GUI::RenderMode::EngineTick;
}
else if (String::iequal(render_mode_string, STR("GameViewportClientTick")))
{
Debug.RenderMode = GUI::RenderMode::GameViewportClientTick;
Expand All @@ -126,6 +130,7 @@ namespace RC
REGISTER_BOOL_SETTING(Hooks.HookEndPlay, section_hooks, HookEndPlay)
REGISTER_BOOL_SETTING(Hooks.HookLocalPlayerExec, section_hooks, HookLocalPlayerExec)
REGISTER_BOOL_SETTING(Hooks.HookAActorTick, section_hooks, HookAActorTick)
REGISTER_BOOL_SETTING(Hooks.HookEngineTick, section_hooks, HookEngineTick)
REGISTER_BOOL_SETTING(Hooks.HookGameViewportClientTick, section_hooks, HookGameViewportClientTick)
REGISTER_INT64_SETTING(Hooks.FExecVTableOffsetInLocalPlayer, section_hooks, FExecVTableOffsetInLocalPlayer)

Expand Down
13 changes: 10 additions & 3 deletions UE4SS/src/UE4SSProgram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ namespace RC
case GUI::RenderMode::ExternalThread:
m_render_thread = std::jthread{&GUI::gui_thread, &m_debugging_gui};
break;
case GUI::RenderMode::EngineTick:
case GUI::RenderMode::GameViewportClientTick:
// The hooked game function will pick up on the window being "open", and start rendering.
get_debugging_ui().set_open(true);
Expand Down Expand Up @@ -778,6 +779,7 @@ namespace RC
config.bHookEndPlay = settings_manager.Hooks.HookEndPlay;
config.bHookLocalPlayerExec = settings_manager.Hooks.HookLocalPlayerExec;
config.bHookAActorTick = settings_manager.Hooks.HookAActorTick;
config.bHookEngineTick = settings_manager.Hooks.HookEngineTick;
config.bHookGameViewportClientTick = settings_manager.Hooks.HookGameViewportClientTick;
config.FExecVTableOffsetInLocalPlayer = settings_manager.Hooks.FExecVTableOffsetInLocalPlayer;
// Apply Debug Build setting from settings file only for now.
Expand Down Expand Up @@ -817,7 +819,7 @@ namespace RC

static bool s_gui_initialized_for_game_thread{};
static bool s_gui_initializing_for_game_thread{};
auto gui_render_thread_GameViewportClientTick(Unreal::UGameViewportClient*, float) -> void
auto gui_render_thread_tick(Unreal::UObject*, float) -> void
{
if (UE4SSProgram::settings_manager.Debug.RenderMode == GUI::RenderMode::ExternalThread)
{
Expand Down Expand Up @@ -856,9 +858,13 @@ namespace RC
UObjectArray::AddUObjectCreateListener(&FUEDeathListener::UEDeathListener);
//*/

if (settings_manager.Debug.RenderMode == GUI::RenderMode::GameViewportClientTick)
if (settings_manager.Debug.RenderMode == GUI::RenderMode::EngineTick)
{
Hook::RegisterGameViewportClientTickPostCallback(gui_render_thread_GameViewportClientTick);
Hook::RegisterEngineTickPostCallback(gui_render_thread_tick);
}
else if (settings_manager.Debug.RenderMode == GUI::RenderMode::GameViewportClientTick)
{
Hook::RegisterGameViewportClientTickPostCallback(gui_render_thread_tick);
}

if (settings_manager.Debug.DebugConsoleEnabled)
Expand Down Expand Up @@ -889,6 +895,7 @@ namespace RC
case GUI::RenderMode::ExternalThread:
m_render_thread = std::jthread{&GUI::gui_thread, &m_debugging_gui};
break;
case GUI::RenderMode::EngineTick:
case GUI::RenderMode::GameViewportClientTick:
// The hooked game function will pick up on the window being "open", and start rendering.
s_gui_initialized_for_game_thread = false;
Expand Down
4 changes: 3 additions & 1 deletion assets/Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ Added custom game configurations for Abiotic Factor ([UE4SS #709](https://github
Added custom game configurations for Psychonauts 2 ([UE4SS #731](https://github.com/UE4SS-RE/RE-UE4SS/pull/731))

The GUI can now be rendered in the game thread if `RenderMode` in UE4SS-settings.ini is set to
`GameViewportClientTick` ([UE4SS #768](https://github.com/UE4SS-RE/RE-UE4SS/pull/768)).
`EngineTick` or `GameViewportClientTick` ([UE4SS #768](https://github.com/UE4SS-RE/RE-UE4SS/pull/768), [UE4SS #794](https://github.com/UE4SS-RE/RE-UE4SS/pull/794)).


### Live View
Added search filter: `IncludeClassNames`. ([UE4SS #472](https://github.com/UE4SS-RE/RE-UE4SS/pull/472)) - Buckminsterfullerene
Expand Down Expand Up @@ -264,6 +265,7 @@ RenderMode = ExternalThread
[Hooks]
HookLoadMap = 1
HookAActorTick = 1
HookEngineTick = 1
HookGameViewportClientTick = 1
```

Expand Down
2 changes: 2 additions & 0 deletions assets/UE4SS-settings.ini
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ GraphicsAPI = opengl
; The method with which the GUI will be rendered.
; Valid values (case-insensitive):
; ExternalThread: A separate thread will be used.
; EngineTick: The UEngine::Tick function will be used.
; GameViewportClientTick: The UGameViewportClient::Tick function will be used.
; Default: ExternalThread
RenderMode = ExternalThread
Expand Down Expand Up @@ -137,6 +138,7 @@ HookCallFunctionByNameWithArguments = 1
HookBeginPlay = 1
HookLocalPlayerExec = 1
HookAActorTick = 1
HookEngineTick = 1
HookGameViewportClientTick = 1
FExecVTableOffsetInLocalPlayer = 0x28

Expand Down

0 comments on commit 72c00a9

Please sign in to comment.