Skip to content

Commit 268407e

Browse files
committed
- fix crash when going into director
1 parent 3416150 commit 268407e

File tree

1 file changed

+21
-18
lines changed

1 file changed

+21
-18
lines changed

DriverNGHook/Patches/All/LuaPatches.cpp

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
#include <Windows.h>
66
#include <stdio.h>
77
#include <mutex>
8-
#include <sol/sol.hpp>
98
#include "Delegates/IInputDelegate.h"
109

1110
namespace DriverNG
@@ -24,6 +23,7 @@ namespace DriverNG
2423
static constexpr uintptr_t kStepLuaOrigAddress = 0x005E4A70;
2524

2625
static constexpr uintptr_t ksafe_vsprintfOrigAdress = 0x00903EBA;
26+
static constexpr uintptr_t kgameLuaStateAddr = 0x0122B498;
2727
}
2828

2929
namespace Globals
@@ -57,35 +57,38 @@ namespace DriverNG
5757
Globals::InitializeLuaStateBindings(state);
5858
}
5959

60-
void StepLua_Hooked(lua_State* state, bool paused)
60+
void StepLua_Hooked(bool consolePaused)
6161
{
62-
typedef void (*StepLua_t)(lua_State*, bool);
62+
typedef void (*StepLua_t)(bool);
6363
auto origStepLua = (StepLua_t)Consts::kStepLuaOrigAddress;
6464

6565
{
6666
//std::lock_guard g(Globals::g_drawMutex[1]);
67-
origStepLua(state, paused);
67+
origStepLua(consolePaused);
6868
}
6969

70-
auto callLuaFunc = Globals::g_luaDelegate.GetCallLuaFunction();
70+
if (!consolePaused)
71+
{
72+
auto callLuaFunc = Globals::g_luaDelegate.GetCallLuaFunction();
7173

72-
if (callLuaFunc && state)
73-
{
74-
std::lock_guard g(Globals::g_drawMutex[0]);
74+
if (callLuaFunc)
75+
{
76+
std::lock_guard g(Globals::g_drawMutex[0]);
7577

76-
Globals::g_dataDrawn = false;
78+
Globals::g_dataDrawn = false;
7779

78-
Globals::g_luaDelegate.BeginRender();
80+
Globals::g_luaDelegate.BeginRender();
7981

80-
bool shouldBlockUI = false;
81-
callLuaFunc("ImGui_RenderUpdate", ">b", &shouldBlockUI);
82-
Globals::g_pInputDelegate->setGameInputBlocked(shouldBlockUI);
82+
bool shouldBlockUI = false;
83+
callLuaFunc("ImGui_RenderUpdate", ">b", &shouldBlockUI);
84+
Globals::g_pInputDelegate->setGameInputBlocked(shouldBlockUI);
8385

84-
Globals::g_luaDelegate.EndRender();
85-
}
86+
Globals::g_luaDelegate.EndRender();
87+
}
8688

87-
// do commands after
88-
Globals::g_luaDelegate.DoCommands();
89+
// do commands after
90+
Globals::g_luaDelegate.DoCommands(*reinterpret_cast<lua_State**>(Consts::kgameLuaStateAddr));
91+
}
8992
}
9093

9194
void DeleteLuaState_Hooked(lua_State* state)
@@ -159,7 +162,7 @@ namespace DriverNG
159162
return false;
160163
}
161164

162-
m_stepLuaHook = HF::Hook::HookFunction<void(*)(lua_State*, bool), kStepLuaPatchSize>(
165+
m_stepLuaHook = HF::Hook::HookFunction<void(*)(bool), kStepLuaPatchSize>(
163166
process,
164167
Consts::kStepLuaCallAddress,
165168
&Callbacks::StepLua_Hooked,

0 commit comments

Comments
 (0)