From abe569176f794301423d67f1abe4512e2f4bd281 Mon Sep 17 00:00:00 2001 From: maybegreat48 <96936658+maybegreat48@users.noreply.github.com> Date: Wed, 30 Apr 2025 18:49:02 -0400 Subject: [PATCH] fix: work with SHV scripts --- src/core/memory/BytePatches.cpp | 2 +- src/game/backend/NativeHooks.cpp | 2 +- src/game/backend/ScriptPatches.cpp | 2 +- src/game/hooks/Script/InitNativeTables.cpp | 14 ++++++++++++-- 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/core/memory/BytePatches.cpp b/src/core/memory/BytePatches.cpp index ae9d7ac..569bf0b 100644 --- a/src/core/memory/BytePatches.cpp +++ b/src/core/memory/BytePatches.cpp @@ -15,7 +15,7 @@ namespace YimMenu unsigned long temp; VirtualProtect(m_Address, m_Size, PAGE_EXECUTE_READWRITE, &old_protect); memcpy(m_Address, m_Value.get(), m_Size); - VirtualProtect(m_Address, m_Size, old_protect, &temp); + VirtualProtect(m_Address, m_Size, old_protect, &temp); m_Applied = true; } diff --git a/src/game/backend/NativeHooks.cpp b/src/game/backend/NativeHooks.cpp index 5f4b3ad..1aaf189 100644 --- a/src/game/backend/NativeHooks.cpp +++ b/src/game/backend/NativeHooks.cpp @@ -52,7 +52,7 @@ namespace YimMenu { for (int i = 0; i < 176; i++) { - if (Pointers.ScriptPrograms[i] != nullptr) + if (Pointers.ScriptPrograms[i] != nullptr && Pointers.ScriptPrograms[i]->m_CodeSize && Pointers.ScriptPrograms[i]->m_CodeBlocks) RegisterProgram(Pointers.ScriptPrograms[i]); } } diff --git a/src/game/backend/ScriptPatches.cpp b/src/game/backend/ScriptPatches.cpp index e58e63f..adaaa86 100644 --- a/src/game/backend/ScriptPatches.cpp +++ b/src/game/backend/ScriptPatches.cpp @@ -116,7 +116,7 @@ namespace YimMenu // find existing programs to register for (int i = 0; i < 176; i++) { - if (Pointers.ScriptPrograms[i] && Pointers.ScriptPrograms[i]->m_NameHash == script) + if (Pointers.ScriptPrograms[i] && Pointers.ScriptPrograms[i]->m_NameHash == script && Pointers.ScriptPrograms[i]->m_CodeSize && Pointers.ScriptPrograms[i]->m_CodeBlocks) RegisterProgram(Pointers.ScriptPrograms[i]); } diff --git a/src/game/hooks/Script/InitNativeTables.cpp b/src/game/hooks/Script/InitNativeTables.cpp index d7ce7a5..fac1874 100644 --- a/src/game/hooks/Script/InitNativeTables.cpp +++ b/src/game/hooks/Script/InitNativeTables.cpp @@ -3,6 +3,8 @@ #include "game/backend/ScriptPatches.hpp" #include "game/hooks/Hooks.hpp" +#include "types/script/scrProgram.hpp" + namespace YimMenu::Hooks { void Script::InitNativeTables(rage::scrProgram* program) @@ -10,8 +12,16 @@ namespace YimMenu::Hooks BaseHook::Get>()->Original()(program); if (g_Running) { - NativeHooks::RegisterProgram(program); - ScriptPatches::RegisterProgram(program); + if (program->m_CodeBlocks && program->m_CodeSize) + { + NativeHooks::RegisterProgram(program); + ScriptPatches::RegisterProgram(program); + } + else + { + // printing name causes crash + // LOGF(VERBOSE, "InitNativeTables: skipping SHV script {}", program->m_Name); + } } } } \ No newline at end of file