From 53950fdd6a3645d1de4210f81b3bbdf9dc5c60ff Mon Sep 17 00:00:00 2001 From: ianpatt Date: Fri, 1 Sep 2023 10:55:29 -0700 Subject: [PATCH] show version in options screen --- sfse/CMakeLists.txt | 2 ++ sfse/Hooks_Version.cpp | 44 ++++++++++++++++++++++++++++++++++++++++++ sfse/Hooks_Version.h | 3 +++ sfse/sfse.cpp | 4 ++++ 4 files changed, 53 insertions(+) create mode 100644 sfse/Hooks_Version.cpp create mode 100644 sfse/Hooks_Version.h diff --git a/sfse/CMakeLists.txt b/sfse/CMakeLists.txt index 9cb87f6..233bac6 100644 --- a/sfse/CMakeLists.txt +++ b/sfse/CMakeLists.txt @@ -55,6 +55,8 @@ source_group( source_group( ${PROJECT_NAME}/hooks FILES + Hooks_Version.cpp + Hooks_Version.h ) source_group( diff --git a/sfse/Hooks_Version.cpp b/sfse/Hooks_Version.cpp new file mode 100644 index 0000000..12baf71 --- /dev/null +++ b/sfse/Hooks_Version.cpp @@ -0,0 +1,44 @@ +#include "Hooks_Version.h" +#include "sfse_common/SafeWrite.h" +#include "sfse_common/sfse_version.h" +#include "sfse_common/Errors.h" +#include "sfse_common/BranchTrampoline.h" +#include "sfse_common/Relocation.h" +#include "xbyak/xbyak.h" +#include + +const char * kHook_ShowVersion_FormatString = + "%08x v%s [SFSE " __PREPRO_TOKEN_STR__(SFSE_VERSION_INTEGER) "." + __PREPRO_TOKEN_STR__(SFSE_VERSION_INTEGER_MINOR) "." + __PREPRO_TOKEN_STR__(SFSE_VERSION_INTEGER_BETA) "]"; +RelocAddr kHook_ShowVersion_Offset(0x02079A7D); + +void Hooks_Version_Apply() +{ + // show SFSE version in menu + { + struct ShowVersion_Code: Xbyak::CodeGenerator { + ShowVersion_Code(void * buf) : Xbyak::CodeGenerator(4096, buf) + { + Xbyak::Label retnLabel; + Xbyak::Label dataLabel; + + mov(rdx, ptr[rip + dataLabel]); + jmp(ptr[rip + retnLabel]); + + L(retnLabel); + dq(kHook_ShowVersion_Offset.getUIntPtr() + 0x7); + + L(dataLabel); + dq(uintptr_t(kHook_ShowVersion_FormatString)); + } + }; + + void * codeBuf = g_localTrampoline.startAlloc(); + ShowVersion_Code code(codeBuf); + g_localTrampoline.endAlloc(code.getCurr()); + + g_branchTrampoline.write6Branch(kHook_ShowVersion_Offset.getUIntPtr(), uintptr_t(code.getCode())); + safeWrite8(kHook_ShowVersion_Offset.getUIntPtr() + 6, 0x90); + } +} diff --git a/sfse/Hooks_Version.h b/sfse/Hooks_Version.h new file mode 100644 index 0000000..96e0868 --- /dev/null +++ b/sfse/Hooks_Version.h @@ -0,0 +1,3 @@ +#pragma once + +void Hooks_Version_Apply(); diff --git a/sfse/sfse.cpp b/sfse/sfse.cpp index 0cab554..62c88e9 100644 --- a/sfse/sfse.cpp +++ b/sfse/sfse.cpp @@ -8,6 +8,8 @@ #include "sfse_common/BranchTrampoline.h" #include "PluginManager.h" +#include "Hooks_Version.h" + HINSTANCE g_moduleHandle = nullptr; void SFSE_Preinit(); @@ -136,6 +138,8 @@ void SFSE_Initialize() g_pluginManager.installPlugins(PluginManager::kPhase_Preload); g_pluginManager.loadComplete(); + Hooks_Version_Apply(); + FlushInstructionCache(GetCurrentProcess(), NULL, 0); _MESSAGE("init complete");