Skip to content

Commit

Permalink
- fix crash when going into director
Browse files Browse the repository at this point in the history
  • Loading branch information
SoapyMan committed Jan 9, 2025
1 parent 3416150 commit 268407e
Showing 1 changed file with 21 additions and 18 deletions.
39 changes: 21 additions & 18 deletions DriverNGHook/Patches/All/LuaPatches.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include <Windows.h>
#include <stdio.h>
#include <mutex>
#include <sol/sol.hpp>
#include "Delegates/IInputDelegate.h"

namespace DriverNG
Expand All @@ -24,6 +23,7 @@ namespace DriverNG
static constexpr uintptr_t kStepLuaOrigAddress = 0x005E4A70;

static constexpr uintptr_t ksafe_vsprintfOrigAdress = 0x00903EBA;
static constexpr uintptr_t kgameLuaStateAddr = 0x0122B498;
}

namespace Globals
Expand Down Expand Up @@ -57,35 +57,38 @@ namespace DriverNG
Globals::InitializeLuaStateBindings(state);
}

void StepLua_Hooked(lua_State* state, bool paused)
void StepLua_Hooked(bool consolePaused)
{
typedef void (*StepLua_t)(lua_State*, bool);
typedef void (*StepLua_t)(bool);
auto origStepLua = (StepLua_t)Consts::kStepLuaOrigAddress;

{
//std::lock_guard g(Globals::g_drawMutex[1]);
origStepLua(state, paused);
origStepLua(consolePaused);
}

auto callLuaFunc = Globals::g_luaDelegate.GetCallLuaFunction();
if (!consolePaused)
{
auto callLuaFunc = Globals::g_luaDelegate.GetCallLuaFunction();

if (callLuaFunc && state)
{
std::lock_guard g(Globals::g_drawMutex[0]);
if (callLuaFunc)
{
std::lock_guard g(Globals::g_drawMutex[0]);

Globals::g_dataDrawn = false;
Globals::g_dataDrawn = false;

Globals::g_luaDelegate.BeginRender();
Globals::g_luaDelegate.BeginRender();

bool shouldBlockUI = false;
callLuaFunc("ImGui_RenderUpdate", ">b", &shouldBlockUI);
Globals::g_pInputDelegate->setGameInputBlocked(shouldBlockUI);
bool shouldBlockUI = false;
callLuaFunc("ImGui_RenderUpdate", ">b", &shouldBlockUI);
Globals::g_pInputDelegate->setGameInputBlocked(shouldBlockUI);

Globals::g_luaDelegate.EndRender();
}
Globals::g_luaDelegate.EndRender();
}

// do commands after
Globals::g_luaDelegate.DoCommands();
// do commands after
Globals::g_luaDelegate.DoCommands(*reinterpret_cast<lua_State**>(Consts::kgameLuaStateAddr));
}
}

void DeleteLuaState_Hooked(lua_State* state)
Expand Down Expand Up @@ -159,7 +162,7 @@ namespace DriverNG
return false;
}

m_stepLuaHook = HF::Hook::HookFunction<void(*)(lua_State*, bool), kStepLuaPatchSize>(
m_stepLuaHook = HF::Hook::HookFunction<void(*)(bool), kStepLuaPatchSize>(
process,
Consts::kStepLuaCallAddress,
&Callbacks::StepLua_Hooked,
Expand Down

0 comments on commit 268407e

Please sign in to comment.