This commit is contained in:
Quentin E. / iDeath 2022-09-30 20:41:26 +02:00 committed by GitHub
parent b64c57ff40
commit 0e2e142c32
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 18 additions and 13 deletions

View File

@ -118,12 +118,13 @@ namespace big
bool hooks::run_script_threads(std::uint32_t ops_to_execute)
{
TRY_CLAUSE
g_native_invoker.cache_handlers();
if (g_running)
{
if (g_running)
g_script_mgr.tick();
return g_hooking->m_run_script_threads_hook.get_original<functions::run_script_threads>()(ops_to_execute);
} EXCEPT_CLAUSE
return false;
g_script_mgr.tick();
}
return g_hooking->m_run_script_threads_hook.get_original<functions::run_script_threads>()(ops_to_execute);
}
}

View File

@ -16,13 +16,17 @@ namespace big
void native_invoker::cache_handlers()
{
if (m_handlers_cached)
return;
for (const rage::scrNativeMapping& mapping : g_crossmap)
{
rage::scrNativeHandler handler = g_pointers->m_get_native_handler(
g_pointers->m_native_registration_table, mapping.second);
m_handler_cache.emplace(mapping.first, handler);
}
m_handlers_cached = true;
}
void native_invoker::begin_call()

View File

@ -38,6 +38,7 @@ namespace big
private:
native_call_context m_call_context;
std::unordered_map<rage::scrNativeHash, rage::scrNativeHandler> m_handler_cache;
bool m_handlers_cached = false;
};
inline native_invoker g_native_invoker;

View File

@ -87,7 +87,7 @@ BOOL APIENTRY DllMain(HMODULE hmod, DWORD reason, PVOID)
LOG(INFO) << "Registered service instances...";
g_script_mgr.add_script(std::make_unique<script>(&gui::script_func, "GUI", false));
g_script_mgr.add_script(std::make_unique<script>(&backend::loop, "Backend Loop", false));
g_script_mgr.add_script(std::make_unique<script>(&backend::self_loop, "Self"));
g_script_mgr.add_script(std::make_unique<script>(&backend::weapons_loop, "Weapon"));
@ -103,12 +103,12 @@ BOOL APIENTRY DllMain(HMODULE hmod, DWORD reason, PVOID)
g_script_mgr.add_script(std::make_unique<script>(&context_menu_service::context_menu, "Context Menu"));
LOG(INFO) << "Scripts registered.";
auto native_hooks_instance = std::make_unique<native_hooks>();
LOG(INFO) << "Dynamic native hooker initialized.";
g_hooking->enable();
LOG(INFO) << "Hooking enabled.";
auto native_hooks_instance = std::make_unique<native_hooks>();
LOG(INFO) << "Dynamic native hooker initialized.";
g_running = true;
while (g_running)

View File

@ -34,11 +34,10 @@ namespace big
void script_mgr::tick_internal()
{
static bool ensure_main_fiber = (ConvertThreadToFiber(nullptr), true);
static bool ensure_native_handlers = (g_native_invoker.cache_handlers(), true);
std::lock_guard lock(m_mutex);
for (auto const& script : m_scripts)
if (script->is_enabled())
script->tick();
}
}
}