Last active
October 18, 2024 22:57
-
-
Save ThomasJClark/a3fa8d151f3a35b414e8a98f04dc551b to your computer and use it in GitHub Desktop.
regbinmeme.dll
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| cmake_minimum_required(VERSION 3.28.1) | |
| set(CMAKE_GENERATOR_PLATFORM x64) | |
| project(regbinmeme | |
| VERSION "0.0.1" | |
| LANGUAGES CXX) | |
| set(CMAKE_CXX_STANDARD 20) | |
| set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE) | |
| include(FetchContent) | |
| FetchContent_Declare(pattern16 | |
| GIT_REPOSITORY https://github.com/Dasaav-dsv/Pattern16.git | |
| GIT_TAG 728eac543cee7e7bf6fda445d7db06e3dc8a61d0 | |
| CONFIGURE_COMMAND "" | |
| BUILD_COMMAND "") | |
| FetchContent_MakeAvailable(pattern16) | |
| add_library(pattern16 INTERFACE) | |
| target_include_directories(pattern16 INTERFACE ${pattern16_SOURCE_DIR}/include) | |
| add_library(regbinmeme SHARED dllmain.cpp) | |
| set_target_properties(regbinmeme PROPERTIES OUTPUT_NAME "regbinmeme") | |
| add_custom_command(TARGET regbinmeme POST_BUILD | |
| COMMAND ${CMAKE_COMMAND} -E copy -t $<TARGET_FILE_DIR:regbinmeme> | |
| COMMAND_EXPAND_LISTS) | |
| target_link_libraries(regbinmeme pattern16) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #define WIN32_LEAN_AND_MEAN | |
| #include <Pattern16.h> | |
| #include <windows.h> | |
| using Pattern16::scan; | |
| bool WINAPI DllMain(HINSTANCE dll_instance, unsigned int fdw_reason, void *lpv_reserved) | |
| { | |
| if (fdw_reason != DLL_PROCESS_ATTACH) | |
| { | |
| return true; | |
| } | |
| HMODULE module_handle = GetModuleHandleA("eldenring.exe"); | |
| if (!module_handle) | |
| { | |
| return false; | |
| } | |
| MEMORY_BASIC_INFORMATION memory_info; | |
| VirtualQuery(module_handle, &memory_info, sizeof(memory_info)); | |
| auto memory = reinterpret_cast<unsigned char *>(memory_info.AllocationBase); | |
| auto dos_header = reinterpret_cast<IMAGE_DOS_HEADER *>(module_handle); | |
| auto nt_headers = reinterpret_cast<IMAGE_NT_HEADERS *>(&memory[dos_header->e_lfanew]); | |
| auto memory_size = nt_headers->OptionalHeader.SizeOfImage; | |
| auto match = reinterpret_cast<unsigned char *>( | |
| scan(memory, memory_size, | |
| "[01001???] 8b 43 08" // mov rax, qword ptr [rbx + 8] | |
| "[01001???] 89 88 c8 00 00 00" // mov [rax + 200], rcx | |
| "38 0d ?? ?? ?? ??" // cmp [???], cl | |
| "75 ??" // jnz [???] | |
| "e8 ?? ?? ?? ??" // call [???] | |
| "88 05 ?? ?? ?? ??" // mov [RegBinFlags + 0], al | |
| "88 05 ?? ?? ?? ??" // mov [RegBinFlags + 1], al | |
| "88 05 ?? ?? ?? ??") // mov [RegBinFlags + 2], al | |
| ); | |
| if (!match) | |
| { | |
| return true; | |
| } | |
| match += 36; | |
| unsigned long old_protect; | |
| VirtualProtect(match, 1, PAGE_EXECUTE_READWRITE, &old_protect); | |
| match[0] = 0x30; // xor | |
| unsigned long old_protect2; | |
| FlushInstructionCache(module_handle, match, 1); | |
| VirtualProtect(match, 1, old_protect, &old_protect2); | |
| return true; | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Approach stolen from Alt Saves, but I needed this in a standalone mod that doesn't change the save file location
https://github.com/vswarte/alt-saves/