Don't rely on DIEmWin window anymore

This commit is contained in:
rebtd7 2020-02-08 17:55:23 -03:00 committed by GitHub
parent 2e08f145fc
commit 2ac408687f
4 changed files with 165 additions and 145 deletions

View file

@ -1,137 +1,139 @@
#pragma once #pragma once
#include <io.h> #include <io.h>
#include <fcntl.h> #include <fcntl.h>
#include <memory> #include <memory>
#include <string> #include <string>
#include "StringUtil.h" #include "StringUtil.h"
#include "WinUtil.h" #include "WinUtil.h"
#ifndef LOGGER_DISABLE #ifndef LOGGER_DISABLE
class Logger class Logger
{ {
public: public:
Logger(const Logger&) = delete; std::mutex printLogMutex;
const Logger& operator=(Logger& other) = delete; Logger(const Logger&) = delete;
const Logger& operator=(Logger& other) = delete;
Logger() : m_systime(), m_console(INVALID_HANDLE_VALUE), m_file(INVALID_HANDLE_VALUE) {}
Logger() : m_systime(), m_console(INVALID_HANDLE_VALUE), m_file(INVALID_HANDLE_VALUE) {}
Logger::~Logger()
{ Logger::~Logger()
if (m_console) {
FreeConsole(); if (m_console)
FreeConsole();
if (m_file)
CloseHandle(m_file); if (m_file)
} CloseHandle(m_file);
}
static Logger& Logger::Get()
{ static Logger& Logger::Get()
static Logger instance; {
return instance; static Logger instance;
}; return instance;
};
bool File(const std::string& filename)
{ bool File(const std::string& filename)
std::string logpath = FullPathFromPath(filename); {
m_file = CreateFileA(logpath.c_str(), GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); std::string logpath = FullPathFromPath(filename);
OutputDebugStringA(logpath.c_str()); m_file = CreateFileA(logpath.c_str(), GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
OutputDebugStringA(logpath.c_str());
if (m_file != INVALID_HANDLE_VALUE)
PrintStamp(false); if (m_file != INVALID_HANDLE_VALUE)
PrintStamp(false);
return m_file != INVALID_HANDLE_VALUE;
} return m_file != INVALID_HANDLE_VALUE;
}
bool Console(const char* title)
{ bool Console(const char* title)
AllocConsole(); {
AllocConsole();
m_console = GetStdHandle(STD_OUTPUT_HANDLE);
if (m_console != INVALID_HANDLE_VALUE) m_console = GetStdHandle(STD_OUTPUT_HANDLE);
{ if (m_console != INVALID_HANDLE_VALUE)
ShowWindow(GetConsoleWindow(), SW_MAXIMIZE); {
if (title) SetConsoleTitleA(title); ShowWindow(GetConsoleWindow(), SW_MAXIMIZE);
} if (title) SetConsoleTitleA(title);
}
if (m_console != INVALID_HANDLE_VALUE)
PrintStamp(true); if (m_console != INVALID_HANDLE_VALUE)
PrintStamp(true);
return m_console != INVALID_HANDLE_VALUE;
} return m_console != INVALID_HANDLE_VALUE;
}
void Print(const char* format, va_list args)
{ void Print(const char* format, va_list args)
bool to_console = m_console != INVALID_HANDLE_VALUE; {
bool to_file = m_file != INVALID_HANDLE_VALUE; bool to_console = m_console != INVALID_HANDLE_VALUE;
bool to_file = m_file != INVALID_HANDLE_VALUE;
if ((to_console || to_file) && format)
{ if ((to_console || to_file) && format)
int outsize = _vscprintf(format, args) + 1; {
std::unique_ptr<char[]> buffer(new char[outsize]); int outsize = _vscprintf(format, args) + 1;
CharArrayFromFormatV(buffer.get(), outsize, format, args); std::unique_ptr<char[]> buffer(new char[outsize]);
CharArrayFromFormatV(buffer.get(), outsize, format, args);
#ifdef LOGGER_DISABLE_TIME
std::string to_print(buffer.get(), outsize - 1); #ifdef LOGGER_DISABLE_TIME
#else std::string to_print(buffer.get(), outsize - 1);
std::string to_print; #else
GetTime(&to_print); std::string to_print;
to_print.append(buffer.get(), outsize - 1); GetTime(&to_print);
#endif to_print.append(buffer.get(), outsize - 1);
#endif
to_print.append("\r\n");
to_print.append("\r\n");
DWORD lenout = 0;
if (to_console) WriteConsoleA(m_console, to_print.c_str(), (DWORD)to_print.size(), &lenout, NULL); DWORD lenout = 0;
if (to_file) WriteFile(m_file, to_print.c_str(), (DWORD)to_print.size(), &lenout, NULL); if (to_console) WriteConsoleA(m_console, to_print.c_str(), (DWORD)to_print.size(), &lenout, NULL);
} if (to_file) WriteFile(m_file, to_print.c_str(), (DWORD)to_print.size(), &lenout, NULL);
} }
}
private:
void PrintStamp(bool console) private:
{ void PrintStamp(bool console)
static char stamp[] = "[TIME]\t\t[THREAD]\t[LOG]\r\n"; {
DWORD lenout = 0; static char stamp[] = "[TIME]\t\t[THREAD]\t[LOG]\r\n";
DWORD lenout = 0;
if (console) WriteConsoleA(m_console, stamp, _countof(stamp) - 1, &lenout, NULL);
else WriteFile(m_file, stamp, _countof(stamp) - 1, &lenout, NULL); if (console) WriteConsoleA(m_console, stamp, _countof(stamp) - 1, &lenout, NULL);
} else WriteFile(m_file, stamp, _countof(stamp) - 1, &lenout, NULL);
}
void GetTime(std::string* out)
{ void GetTime(std::string* out)
GetLocalTime(&m_systime); {
*out = StringFromFormat("%02u:%02u:%02u.%03u\t%08u\t", m_systime.wHour, m_systime.wMinute, GetLocalTime(&m_systime);
m_systime.wSecond, m_systime.wMilliseconds, GetCurrentThreadId()); *out = StringFromFormat("%02u:%02u:%02u.%03u\t%08u\t", m_systime.wHour, m_systime.wMinute,
m_systime.wSecond, m_systime.wMilliseconds, GetCurrentThreadId());
}
}
SYSTEMTIME m_systime;
HANDLE m_console; SYSTEMTIME m_systime;
HANDLE m_file; HANDLE m_console;
}; HANDLE m_file;
};
inline void LogFile(const std::string& logname)
{ inline void LogFile(const std::string& logname)
Logger::Get().File(logname); {
} Logger::Get().File(logname);
}
inline void LogConsole(const char* title = nullptr)
{ inline void LogConsole(const char* title = nullptr)
Logger::Get().Console(title); {
} Logger::Get().Console(title);
}
inline void PrintLog(const char* format, ...)
{ inline void PrintLog(const char* format, ...)
va_list args; {
va_start(args, format); const std::lock_guard<std::mutex> lock(Logger::Get().printLogMutex);
Logger::Get().Print(format, args); va_list args;
va_end(args); va_start(args, format);
} Logger::Get().Print(format, args);
va_end(args);
#else }
#define LogFile(logname) (logname)
#define LogConsole(title, notice) (title) #else
#define PrintLog(format, ...) (format) #define LogFile(logname) (logname)
#define LogConsole(title, notice) (title)
#define PrintLog(format, ...) (format)
#endif #endif

View file

@ -103,6 +103,13 @@ HRESULT APIENTRY MainContext::ApplyVertexBufferFix(IDirect3DDevice9* pIDirect3DD
return pIDirect3DDevice9->CreateVertexBuffer(Length, Usage, FVF, Pool, ppVertexBuffer, pSharedHandle); return pIDirect3DDevice9->CreateVertexBuffer(Length, Usage, FVF, Pool, ppVertexBuffer, pSharedHandle);
} }
void MainContext::FF13_AsyncPatchingLoop() {
std::this_thread::sleep_for(std::chrono::milliseconds(2000));
if (*context.ff13_frame_pacer_ptr) {
context.FF13_OneTimeFixes();
}
}
void MainContext::FF13_InitializeGameAddresses() void MainContext::FF13_InitializeGameAddresses()
{ {
// FF13 always seem to use the same addresses (even if you force ASLR on the OS), but we are calculating the addresses just in case... // FF13 always seem to use the same addresses (even if you force ASLR on the OS), but we are calculating the addresses just in case...
@ -122,13 +129,13 @@ void MainContext::FF13_InitializeGameAddresses()
void MainContext::FF13_OneTimeFixes() { void MainContext::FF13_OneTimeFixes() {
MainContext::FF13_NOPIngameFrameRateLimitSetter(); MainContext::FF13_NOPIngameFrameRateLimitSetter();
MainContext::FF13_SetFrameRateVariables();
MainContext::FF13_RemoveContinuousControllerScan(); MainContext::FF13_RemoveContinuousControllerScan();
MainContext::FF13_FixMissingEnemyScan(); MainContext::FF13_FixMissingEnemyScan();
MainContext::FF13_EnableControllerVibration(); MainContext::FF13_EnableControllerVibration();
MainContext::FF13_SetFrameRateVariables();
PrintLog("Finished FF13 One Time Fixes"); PrintLog("Finished FF13 One Time Fixes");
MainContext::didOneTimeFixes = true; context.didOneTimeFixes = true;
} }
void MainContext::FF13_EnableControllerVibration() void MainContext::FF13_EnableControllerVibration()
@ -250,6 +257,11 @@ void MainContext::FF13_SetFrameRateVariables() {
} }
} }
void MainContext::FF13_2_AsyncPatchingLoop() {
std::this_thread::sleep_for(std::chrono::milliseconds(2000));
context.FF13_2_OneTimeFixes();
}
void MainContext::FF13_2_OneTimeFixes() { void MainContext::FF13_2_OneTimeFixes() {
if (*ff13_2_frame_pacer_ptr_address) { if (*ff13_2_frame_pacer_ptr_address) {
@ -262,6 +274,9 @@ void MainContext::FF13_2_OneTimeFixes() {
PrintLog("Finished FF13-2 One Time Fixes"); PrintLog("Finished FF13-2 One Time Fixes");
context.didOneTimeFixes = true; context.didOneTimeFixes = true;
} }
else {
PrintLog("Unable to apply FF13-2 One Time Fixes. Report this!");
}
} }
void MainContext::FF13_2_EnableControllerVibration() void MainContext::FF13_2_EnableControllerVibration()
@ -389,7 +404,7 @@ void MainContext::ChangeMemoryProtectionToReadWriteExecute(void* address, const
} }
void MainContext::PrintVersionInfo() { void MainContext::PrintVersionInfo() {
PrintLog("FF13Fix 1.4.2 https://github.com/rebtd7/FF13Fix"); PrintLog("FF13Fix 1.4.3 https://github.com/rebtd7/FF13Fix");
} }
bool MainContext::AreAlmostTheSame(float a, float b) { bool MainContext::AreAlmostTheSame(float a, float b) {

View file

@ -192,18 +192,18 @@ bool MainContext::CheckWindow(HWND hWnd)
PrintLog("HWND 0x%p: ClassName \"%ls\", WindowName: \"%ls\"", hWnd, className.get(), windowName.get()); PrintLog("HWND 0x%p: ClassName \"%ls\", WindowName: \"%ls\"", hWnd, className.get(), windowName.get());
if (!context.didOneTimeFixes) { if (!context.didOneTimeFixes) {
if (context.autofix == FINAL_FANTASY_XIII && wcscmp(windowName.get(), L"DIEmWin") == 0) { if (context.autofix == FINAL_FANTASY_XIII && wcscmp(className.get(), L"SQEX.CDev.Engine.Framework.MainWindow") == 0) {
const std::lock_guard<std::mutex> lock(context.oneTimeFixesMutex); const std::lock_guard<std::mutex> lock(context.oneTimeFixesMutex);
if(!context.didOneTimeFixes){ if(!context.didOneTimeFixes){
PrintLog("Starting FFXIII one time RAM patches."); PrintLog("Starting FFXIII one time RAM patches.");
context.FF13_OneTimeFixes(); patchingThread = new std::thread(&context.FF13_AsyncPatchingLoop);
} }
} }
else if (context.autofix == FINAL_FANTASY_XIII2 && wcscmp(windowName.get(), L"DIEmWin") == 0) { else if (context.autofix == FINAL_FANTASY_XIII2 && wcscmp(className.get(), L"SQEX.CDev.Engine.Framework.MainWindow") == 0) {
const std::lock_guard<std::mutex> lock(context.oneTimeFixesMutex); const std::lock_guard<std::mutex> lock(context.oneTimeFixesMutex);
if (!context.didOneTimeFixes) { if (!context.didOneTimeFixes) {
PrintLog("Starting FFXIII-2 one time RAM patches."); PrintLog("Starting FFXIII-2 one time RAM patches.");
context.FF13_2_OneTimeFixes(); patchingThread = new std::thread(&context.FF13_2_AsyncPatchingLoop);
} }
} }
} }

View file

@ -45,7 +45,6 @@ class MainContext
public: public:
MainContext(); MainContext();
void Foo();
~MainContext(); ~MainContext();
bool ApplyPresentationParameters(D3DPRESENT_PARAMETERS* pPresentationParameters); bool ApplyPresentationParameters(D3DPRESENT_PARAMETERS* pPresentationParameters);
@ -100,6 +99,7 @@ private:
const float FF13_2_30_FPS = 30.0F; const float FF13_2_30_FPS = 30.0F;
const float FF13_2_MAX_FRAME_CAP = 1000.0F; const float FF13_2_MAX_FRAME_CAP = 1000.0F;
XInputManager* xinputManager; XInputManager* xinputManager;
std::thread * patchingThread;
void FixBehaviorFlagConflict(const DWORD flags_in, DWORD* flags_out); void FixBehaviorFlagConflict(const DWORD flags_in, DWORD* flags_out);
static const std::map<const AutoFixes, const uint32_t> behaviorflags_fixes; static const std::map<const AutoFixes, const uint32_t> behaviorflags_fixes;
@ -111,6 +111,8 @@ private:
bool AreAlmostTheSame(float a, float b); bool AreAlmostTheSame(float a, float b);
void PrintVersionInfo(); void PrintVersionInfo();
static void FF13_AsyncPatchingLoop();
void FF13_InitializeGameAddresses(); void FF13_InitializeGameAddresses();
void FF13_OneTimeFixes(); void FF13_OneTimeFixes();
void FF13_EnableControllerVibration(); void FF13_EnableControllerVibration();
@ -119,6 +121,7 @@ private:
void FF13_FixMissingEnemyScan(); void FF13_FixMissingEnemyScan();
void FF13_RemoveContinuousControllerScan(); void FF13_RemoveContinuousControllerScan();
static void FF13_2_AsyncPatchingLoop();
void FF13_2_CreateSetFrameRateCodeBlock(); void FF13_2_CreateSetFrameRateCodeBlock();
void FF13_2_InitializeGameAddresses(); void FF13_2_InitializeGameAddresses();
void FF13_2_RemoveContinuousControllerScan(); void FF13_2_RemoveContinuousControllerScan();