From 5626c52c4336a58c4ad348d7c28550406f8442a4 Mon Sep 17 00:00:00 2001 From: rebtd7 <59185507+rebtd7@users.noreply.github.com> Date: Mon, 22 Mar 2021 09:05:03 -0300 Subject: [PATCH] Fix crashes at startup --- README.md | 2 +- d3d9ex/AutoFix.cpp | 21 ++++++++++++--------- d3d9ex/Context.h | 2 +- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 1b964ed..ccc2337 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,7 @@ This considerably improves the frame rate when 2D elements are being disabled on The game calls [SetScissorRect](https://docs.microsoft.com/en-us/windows/win32/api/d3d9helper/nf-d3d9helper-idirect3ddevice9-setscissorrect) using a rectangle hardcoded with the 720p coordenates. This correct the coordenates and rectangle size in order to fix it. # Usage with the 4GB Large Address Aware patch -You may wish to patch the games to allow them to access more than 4GB of RAM. This seems to avoid crashes in FF13-2 (and may help FF13 under some configurations). +You may wish to patch the games to allow them to access more than 2GB of RAM. This seems to avoid crashes in FF13-2 (and may help FF13 under some configurations). ## FF13: * Create a copy of the unpatched ```ffxiiiimg.exe``` to the folder ```FINAL FANTASY XIII\white_data\prog\win\bin```. Name it ```untouched.exe```. * Patch the original ```ffxiiiimg.exe``` (you can use https://ntcore.com/?page_id=371) diff --git a/d3d9ex/AutoFix.cpp b/d3d9ex/AutoFix.cpp index 6ed73fd..c916396 100644 --- a/d3d9ex/AutoFix.cpp +++ b/d3d9ex/AutoFix.cpp @@ -58,11 +58,12 @@ HANDLE WINAPI MainContext::HookCreateFileA(LPCSTR lpFileName, DWORD dwDesiredAcc MH_STATUS disableHookCreateFileW = MH_DisableHook(CreateFileW); PrintLog("disableHookCreateFileW = %d", disableHookCreateFileW); if (GetFileAttributesA(newFileName) == INVALID_FILE_ATTRIBUTES) { - PrintLog("ERROR: Unable to get attributes of %s. Does the file exist?", newFileName); + PrintLog("ERROR: Unable to get attributes of %s. Does the file exist? Using the regular ffxiiiimg.exe", newFileName); + strcpy_s(newFileName, len + 1, lpFileName); } HANDLE fileHandle = context.TrueCreateFileA(newFileName, dwDesiredAccess, dwShareMode, lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile);; + PrintLog("Returning File Handle for %s", newFileName); delete[] newFileName; - PrintLog("Returning File Handle"); return fileHandle; } else { @@ -89,10 +90,11 @@ HANDLE WINAPI MainContext::HookCreateFileW(LPCWSTR lpFileName, DWORD dwDesiredAc PrintLog("disableHookCreateFileW = %d", disableHookCreateFileW); if (GetFileAttributesW(newFileName) == INVALID_FILE_ATTRIBUTES) { PrintLog("ERROR: Unable to get attributes of %s. Does the file exist?", newFileName); + wcscpy_s(newFileName, len + 1, lpFileName); } HANDLE fileHandle = context.TrueCreateFileW(newFileName, dwDesiredAccess, dwShareMode, lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile);; + PrintLog("Returning File Handle %s", newFileName); delete[] newFileName; - PrintLog("Returning File Handle"); return fileHandle; } else { @@ -262,13 +264,14 @@ void MainContext::FF13_InitializeGameAddresses() ff13_message_box_call_address = baseAddr + 0xA8A98F; ff13_message_box_stack_push_address = baseAddr + 0xA8A982; ff13_exe_large_address_aware_flag_address = baseAddr + 0x126; - ff13_exe_checksum_address = baseAddr + 0x168; + ff13_exe_checksum_address = (uint32_t*)(baseAddr + 0x168); } void MainContext::FF13_HandleLargeAddressAwarePatch() { const uint8_t laaMask = 0x20; - if (*ff13_exe_large_address_aware_flag_address && laaMask) { - PrintLog("LargeAddressAwarePatch found. Make sure untouched.exe is an unmodified copy of ffxiiiimg.exe"); + if (*ff13_exe_large_address_aware_flag_address & laaMask) { + PrintLog("LargeAddressAwarePatch found. ff13_exe_large_address_aware_flag = 0x%02x; ff13_exe_checksum = 0x%08x", *ff13_exe_large_address_aware_flag_address, *ff13_exe_checksum_address); + const MH_STATUS createHookCreateFileA = MH_CreateHook(CreateFileA, HookCreateFileA, reinterpret_cast(&TrueCreateFileA)); PrintLog("createHookCreateFileA = %d", createHookCreateFileA); const MH_STATUS enableHookCreateFileA = MH_EnableHook(CreateFileA); @@ -281,11 +284,11 @@ void MainContext::FF13_HandleLargeAddressAwarePatch() { uint8_t new_ff13_exe_large_address_aware_flag = *ff13_exe_large_address_aware_flag_address & ~laaMask; MemPatch::Patch(ff13_exe_large_address_aware_flag_address, &new_ff13_exe_large_address_aware_flag, 1); - PrintLog("LargeAddressAware patched back = %d", *ff13_exe_large_address_aware_flag_address); + PrintLog("LargeAddressAware patched back. ff13_exe_large_address_aware_flag = 0x%02x;", *ff13_exe_large_address_aware_flag_address); uint32_t new_ff13_exe_checksum = 0; MemPatch::Patch(ff13_exe_checksum_address, &new_ff13_exe_checksum, sizeof(uint32_t)); - PrintLog("Checksum patched back = %d", *ff13_exe_checksum_address); + PrintLog("Checksum patched back. ff13_exe_checksum = 0x%08x", *ff13_exe_checksum_address); PrintLog("LargeAddressAwarePatch handled"); } @@ -602,5 +605,5 @@ void MainContext::FF13_2_CreateSetFrameRateCodeBlock() } void MainContext::PrintVersionInfo() { - PrintLog("FF13Fix 1.6.2 https://github.com/rebtd7/FF13Fix"); + PrintLog("FF13Fix 1.6.3 https://github.com/rebtd7/FF13Fix"); } diff --git a/d3d9ex/Context.h b/d3d9ex/Context.h index ca1b670..b859830 100644 --- a/d3d9ex/Context.h +++ b/d3d9ex/Context.h @@ -98,7 +98,7 @@ private: uint8_t* ff13_message_box_stack_push_address = NULL; uint8_t* ff13_message_box_call_address = NULL; uint8_t* ff13_exe_large_address_aware_flag_address = NULL; - uint8_t* ff13_exe_checksum_address = NULL; + uint32_t* ff13_exe_checksum_address = NULL; uint32_t* ff13_internal_res_w; uint32_t* ff13_internal_res_h;