Skip to content

Commit 4c04aa8

Browse files
committed
- better script loading handling, renamed allowOnlineCheats to allowCustomGameScripts since check doesn't work always
1 parent 76a4c34 commit 4c04aa8

File tree

2 files changed

+37
-14
lines changed

2 files changed

+37
-14
lines changed

DriverNGHook/DriverNG/include/Delegates/LuaDelegate.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ namespace DriverNG
3939
sol::function m_onInit{ };
4040
sol::function m_onUpdate{ };
4141

42-
bool m_allowOnlineCheats{ false };
42+
bool m_allowCustomGameScripts{ false };
4343
bool m_allowDeveloperConsole{ false };
4444
};
4545
}

DriverNGHook/DriverNG/source/Delegates/LuaDelegate.cpp

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#include <spdlog/spdlog.h>
44
#include <UI/DebugTools.h>
55
#include <imgui.h>
6-
#include <sol_imgui/sol_imgui.h>
6+
//#include <sol_imgui/sol_imgui.h>
77
#include <lfs.h>
88
#include "lstate.h"
99

@@ -111,6 +111,11 @@ LuaAsyncQueue g_luaAsyncQueue;
111111

112112
namespace DriverNG
113113
{
114+
namespace Consts
115+
{
116+
static const std::string luaScriptsPath = "plugins/DriverNGHook/scripts/";
117+
}
118+
114119
namespace Globals
115120
{
116121
extern std::unique_ptr<DebugTools> g_pDebugTools;
@@ -189,11 +194,14 @@ namespace DriverNG
189194
Globals::g_pDebugTools->LogGameToConsole(oss.str());
190195
};
191196

197+
// set folder
198+
sv["DNGHookScriptPath"] = Consts::luaScriptsPath;
199+
192200
if (firstTimeInit)
193201
{
194202
// init other lua state
195203
m_luaState.open_libraries(sol::lib::base, sol::lib::string, sol::lib::io, sol::lib::math, sol::lib::package, sol::lib::os, sol::lib::table);
196-
sol_ImGui::InitBindings(m_luaState);
204+
//sol_ImGui::InitBindings(m_luaState);
197205

198206
m_luaState["registerForEvent"] = [this](const std::string& acName, sol::function aCallback)
199207
{
@@ -205,12 +213,12 @@ namespace DriverNG
205213
spdlog::error("Tried to register an unknown event '{}'!", acName);
206214
};
207215

208-
m_luaState["setAllowOnlineCheats"] = [this](bool enable)
216+
m_luaState["allowCustomGameScripts"] = [this](bool enable)
209217
{
210218
if (enable)
211-
Globals::g_pDebugTools->LogGameToConsole("WARNING: Online cheats ARE ALLOWED");
219+
Globals::g_pDebugTools->LogGameToConsole("Custom game scripts are allowed");
212220

213-
m_allowOnlineCheats = enable;
221+
m_allowCustomGameScripts = enable;
214222
};
215223

216224
m_luaState["setAllowDeveloperConsole"] = [this](bool enable)
@@ -220,21 +228,36 @@ namespace DriverNG
220228

221229
// Driver NG hook internals
222230
{
223-
m_luaState.script_file("plugins/DriverNGHook/scripts/autoexec.lua");
231+
m_luaState.script_file(Consts::luaScriptsPath + "autoexec.lua");
224232
TryLuaFunction(m_onInit);
225233

226234
InitializeGameDevelopmentLib();
227235
}
228236
}
229237

230-
bool isOnline = IsOnlineGame();
238+
// little game hooks to allow console stuff
239+
if (m_allowDeveloperConsole)
240+
{
241+
try
242+
{
243+
sv.do_file(Consts::luaScriptsPath + "driverNGConsole.lua");
244+
}
245+
catch (sol::error& err)
246+
{
247+
spdlog::warn("driverNGConsole.lua failed to load");
248+
}
249+
}
231250

232251
// init game Lua hooks
233-
//if (!isOnline || isOnline && m_allowOnlineCheats)
252+
if (m_allowCustomGameScripts && m_callLuaFunc)
234253
{
235-
if (m_callLuaFunc)
254+
try
255+
{
256+
sv.do_file(Consts::luaScriptsPath + "game_autoexec.lua");
257+
}
258+
catch (sol::error& err)
236259
{
237-
sv.do_file("plugins/DriverNGHook/scripts/game_autoexec.lua");
260+
spdlog::warn("game_autoexec.lua failed to load");
238261
}
239262
}
240263
}
@@ -369,7 +392,7 @@ namespace DriverNG
369392
if (!IsValidLuaState())
370393
return;
371394

372-
if (IsOnlineGame() && !m_allowOnlineCheats)
395+
if (IsOnlineGame() && !m_allowCustomGameScripts)
373396
{
374397
g_luaAsyncQueue.Clear();
375398
return;
@@ -416,7 +439,7 @@ namespace DriverNG
416439
if (!IsValidLuaState())
417440
return sol::protected_function_result();
418441

419-
if (IsOnlineGame() && !m_allowOnlineCheats)
442+
if (IsOnlineGame() && !m_allowCustomGameScripts)
420443
return sol::protected_function_result();
421444

422445
sol::state_view state(m_gameState);
@@ -428,7 +451,7 @@ namespace DriverNG
428451
if (!IsValidLuaState())
429452
return sol::protected_function_result();
430453

431-
if (IsOnlineGame() && !m_allowOnlineCheats)
454+
if (IsOnlineGame() && !m_allowCustomGameScripts)
432455
return sol::protected_function_result();
433456

434457
sol::state_view state(m_gameState);

0 commit comments

Comments
 (0)