Skip to content

Commit

Permalink
Support both Avatar and Outlaws modding
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickmollohan committed Dec 30, 2024
1 parent 0b91ff0 commit ba1035e
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 6 deletions.
18 changes: 14 additions & 4 deletions src/mod_loader.cpp
Original file line number Diff line number Diff line change
@@ -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);
Expand All @@ -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;
Expand Down
5 changes: 3 additions & 2 deletions src/mod_loader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
12 changes: 12 additions & 0 deletions src/utilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 2 additions & 0 deletions src/utilities.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit ba1035e

Please sign in to comment.