From ba1035ec10117e4996487750265141e2fd924677 Mon Sep 17 00:00:00 2001 From: Patrick Mollohan <14967142+patrickmollohan@users.noreply.github.com> Date: Mon, 30 Dec 2024 14:07:58 -0500 Subject: [PATCH] Support both Avatar and Outlaws modding --- src/mod_loader.cpp | 18 ++++++++++++++---- src/mod_loader.hpp | 5 +++-- src/utilities.cpp | 12 ++++++++++++ src/utilities.hpp | 2 ++ 4 files changed, 31 insertions(+), 6 deletions(-) diff --git a/src/mod_loader.cpp b/src/mod_loader.cpp index a893659..6589827 100644 --- a/src/mod_loader.cpp +++ b/src/mod_loader.cpp @@ -1,10 +1,11 @@ #include "mod_loader.hpp" -const unsigned char ModLoader::pattern[] = { 0x4C, 0x8B, 0xDC, 0x53, 0x57, 0x41, 0x54, 0x48, 0x81, 0xEC, 0x00, 0x00, 0x00, 0x00, 0x41, 0x8B, 0xD8 }; -const unsigned char ModLoader::mask[] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF }; - ModLoader::open_file_stream_proc oldOpenFileStream = nullptr; +int ModLoader::pattern_size; +unsigned char* ModLoader::pattern; +unsigned char* ModLoader::mask; + bool __fastcall ModLoader::HookOpenFileStream(uintptr_t stream, LPCSTR file_path, unsigned int flags) { if (Utilities::Files::LocalFileExists(file_path)) { flags |= (1 << 0xA); @@ -14,7 +15,16 @@ bool __fastcall ModLoader::HookOpenFileStream(uintptr_t stream, LPCSTR file_path bool ModLoader::Enable() { if (Settings::EnableMods) { - uintptr_t openFileStreamAddress = Utilities::Processes::FindPatternAddressMask(pattern, mask, (sizeof(pattern) / sizeof(pattern[0]))); + if (Utilities::Processes::IsGameAvatar()) { + pattern_size = 26; + pattern = new unsigned char[pattern_size] { 0x48, 0x89, 0x5C, 0x24, 0x00, 0x55, 0x56, 0x57, 0x41, 0x54, 0x41, 0x55, 0x41, 0x56, 0x41, 0x57, 0x48, 0x81, 0xEC, 0x00, 0x00, 0x00, 0x00, 0x41, 0x8B, 0xF8 }; + mask = new unsigned char[pattern_size] { 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF }; + } else if (Utilities::Processes::IsGameOutlaws()) { + pattern_size = 17; + pattern = new unsigned char[pattern_size] { 0x4C, 0x8B, 0xDC, 0x53, 0x57, 0x41, 0x54, 0x48, 0x81, 0xEC, 0x00, 0x00, 0x00, 0x00, 0x41, 0x8B, 0xD8 }; + mask = new unsigned char[pattern_size] { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF }; + } + uintptr_t openFileStreamAddress = Utilities::Processes::FindPatternAddressMask(pattern, mask, pattern_size); if (!openFileStreamAddress) { MessageBoxA(NULL, "OpenFileStream pattern not found. Mod loading disabled.", "Dank farrik!", MB_OK | MB_ICONERROR); return false; diff --git a/src/mod_loader.hpp b/src/mod_loader.hpp index d5cc6db..3474404 100644 --- a/src/mod_loader.hpp +++ b/src/mod_loader.hpp @@ -17,6 +17,7 @@ class ModLoader { private: static bool __fastcall HookOpenFileStream(uintptr_t stream, LPCSTR file_path, unsigned int flags); - static const unsigned char pattern[]; - static const unsigned char mask[]; + static int pattern_size; + static unsigned char* pattern; + static unsigned char* mask; }; \ No newline at end of file diff --git a/src/utilities.cpp b/src/utilities.cpp index 14bc7b2..f34fe9b 100644 --- a/src/utilities.cpp +++ b/src/utilities.cpp @@ -110,6 +110,18 @@ bool Utilities::Processes::IsCompatibleExe() { return false; } +bool Utilities::Processes::IsGameAvatar() { + std::string exeName = Utilities::Processes::GetExeName(); + return (Utilities::String::EqualsIgnoreCase(exeName, "AFOP.exe") || + Utilities::String::EqualsIgnoreCase(exeName, "AFOP_Plus.exe")); +} + +bool Utilities::Processes::IsGameOutlaws() { + std::string exeName = Utilities::Processes::GetExeName(); + return (Utilities::String::EqualsIgnoreCase(exeName, "Outlaws.exe") || + Utilities::String::EqualsIgnoreCase(exeName, "Outlaws_Plus.exe")); +} + void Utilities::Processes::SetPriorityLevels() { HANDLE hProcess = GetCurrentProcess(); HANDLE hThread = GetCurrentThread(); diff --git a/src/utilities.hpp b/src/utilities.hpp index dc589b4..571ae6f 100644 --- a/src/utilities.hpp +++ b/src/utilities.hpp @@ -56,6 +56,8 @@ class Utilities { static uintptr_t FindPatternAddressMask(const unsigned char* pattern, const unsigned char* mask, size_t patternLength); static std::string GetExeName(); static bool IsCompatibleExe(); + static bool IsGameAvatar(); + static bool IsGameOutlaws(); static void SetPriorityLevels(); private: