@@ -22,25 +22,19 @@ namespace DriverNG
22
22
static constexpr uintptr_t kStepLuaCallAddress = 0x0079B811 ; // to the call CState_Main::Step
23
23
static constexpr uintptr_t kStepLuaOrigAddress = 0x005E4A70 ;
24
24
25
+ static constexpr uintptr_t kGetProfileNameCallAddress = 0x008534C2 ;
25
26
static constexpr uintptr_t ksafe_vsprintfOrigAdress = 0x00903EBA ;
26
27
static constexpr uintptr_t kgameLuaStateAddr = 0x0122B498 ;
27
28
}
28
29
29
30
namespace Globals
30
31
{
31
32
extern std::unique_ptr<IInputDelegate> g_pInputDelegate;
32
- extern std::mutex g_drawMutex[2 ];
33
- extern volatile bool g_dataDrawn;
33
+ static std::string g_profileName;
34
+ extern std::mutex g_drawMutex[2 ];
35
+ extern volatile bool g_dataDrawn;
34
36
35
37
static ILuaDelegate& g_luaDelegate = ILuaDelegate::GetInstance();
36
-
37
- static void InitializeLuaStateBindings (lua_State* newState)
38
- {
39
- // report to the game state
40
- auto callLuaFunction = (CallLuaFunction_t)Consts::kCallLuaFunctionAddress ;
41
-
42
- g_luaDelegate.OnInitialised (newState, callLuaFunction);
43
- }
44
38
}
45
39
46
40
namespace Callbacks
@@ -54,7 +48,9 @@ namespace DriverNG
54
48
origOpenScriptLoader (state);
55
49
56
50
// get the lua state from the address
57
- Globals::InitializeLuaStateBindings (state);
51
+ // report to the game state
52
+ auto callLuaFunction = (CallLuaFunction_t)Consts::kCallLuaFunctionAddress ;
53
+ Globals::g_luaDelegate.OnInitialised (state, callLuaFunction, Globals::g_profileName.c_str ());
58
54
}
59
55
60
56
void StepLua_Hooked (bool consolePaused)
@@ -124,6 +120,13 @@ namespace DriverNG
124
120
125
121
return ret;
126
122
}
123
+
124
+ const char * GetProfileNameHooked (const void * _this)
125
+ {
126
+ const char * profileName = (const char *)_this + 4 ;
127
+ Globals::g_profileName = profileName;
128
+ return profileName;
129
+ }
127
130
}
128
131
129
132
const char * LuaPatches::GetName () const { return " Lua Patch" ; }
@@ -219,6 +222,27 @@ namespace DriverNG
219
222
return false ;
220
223
}
221
224
225
+
226
+ // Do not revert this patch!
227
+ if (!HF::Hook::FillMemoryByNOPs (process, Consts::kGetProfileNameCallAddress , kprofileNamePatchSize))
228
+ {
229
+ MsgError (" Failed to cleanup memory\n " );
230
+ return false ;
231
+ }
232
+
233
+ m_getProfileNameHook = HF::Hook::HookFunction<const char *(*)(const void *), kprofileNamePatchSize>(
234
+ process,
235
+ Consts::kGetProfileNameCallAddress ,
236
+ &Callbacks::GetProfileNameHooked,
237
+ { HF::X86::PUSH_ECX },
238
+ { HF::X86::POP_ECX }
239
+ );
240
+
241
+ if (!m_getProfileNameHook->setup ())
242
+ {
243
+ MsgError (" Failed to setup patch to DeleteLuaState!\n " );
244
+ return false ;
245
+ }
222
246
return BasicPatch::Apply (modules);
223
247
}
224
248
0 commit comments