Don't rely on DIEmWin window anymore
This commit is contained in:
parent
2e08f145fc
commit
2ac408687f
274
Common/Logger.h
274
Common/Logger.h
|
@ -1,137 +1,139 @@
|
|||
#pragma once
|
||||
|
||||
#include <io.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "StringUtil.h"
|
||||
#include "WinUtil.h"
|
||||
|
||||
#ifndef LOGGER_DISABLE
|
||||
class Logger
|
||||
{
|
||||
public:
|
||||
Logger(const Logger&) = delete;
|
||||
const Logger& operator=(Logger& other) = delete;
|
||||
|
||||
Logger() : m_systime(), m_console(INVALID_HANDLE_VALUE), m_file(INVALID_HANDLE_VALUE) {}
|
||||
|
||||
Logger::~Logger()
|
||||
{
|
||||
if (m_console)
|
||||
FreeConsole();
|
||||
|
||||
if (m_file)
|
||||
CloseHandle(m_file);
|
||||
}
|
||||
|
||||
static Logger& Logger::Get()
|
||||
{
|
||||
static Logger instance;
|
||||
return instance;
|
||||
};
|
||||
|
||||
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);
|
||||
OutputDebugStringA(logpath.c_str());
|
||||
|
||||
if (m_file != INVALID_HANDLE_VALUE)
|
||||
PrintStamp(false);
|
||||
|
||||
return m_file != INVALID_HANDLE_VALUE;
|
||||
}
|
||||
|
||||
bool Console(const char* title)
|
||||
{
|
||||
AllocConsole();
|
||||
|
||||
m_console = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
if (m_console != INVALID_HANDLE_VALUE)
|
||||
{
|
||||
ShowWindow(GetConsoleWindow(), SW_MAXIMIZE);
|
||||
if (title) SetConsoleTitleA(title);
|
||||
}
|
||||
|
||||
if (m_console != INVALID_HANDLE_VALUE)
|
||||
PrintStamp(true);
|
||||
|
||||
return m_console != INVALID_HANDLE_VALUE;
|
||||
}
|
||||
|
||||
void Print(const char* format, va_list args)
|
||||
{
|
||||
bool to_console = m_console != INVALID_HANDLE_VALUE;
|
||||
bool to_file = m_file != INVALID_HANDLE_VALUE;
|
||||
|
||||
if ((to_console || to_file) && format)
|
||||
{
|
||||
int outsize = _vscprintf(format, args) + 1;
|
||||
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);
|
||||
#else
|
||||
std::string to_print;
|
||||
GetTime(&to_print);
|
||||
to_print.append(buffer.get(), outsize - 1);
|
||||
#endif
|
||||
|
||||
to_print.append("\r\n");
|
||||
|
||||
DWORD lenout = 0;
|
||||
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)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
void GetTime(std::string* out)
|
||||
{
|
||||
GetLocalTime(&m_systime);
|
||||
*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;
|
||||
HANDLE m_file;
|
||||
};
|
||||
|
||||
inline void LogFile(const std::string& logname)
|
||||
{
|
||||
Logger::Get().File(logname);
|
||||
}
|
||||
|
||||
inline void LogConsole(const char* title = nullptr)
|
||||
{
|
||||
Logger::Get().Console(title);
|
||||
}
|
||||
|
||||
inline void PrintLog(const char* format, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
Logger::Get().Print(format, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
#else
|
||||
#define LogFile(logname) (logname)
|
||||
#define LogConsole(title, notice) (title)
|
||||
#define PrintLog(format, ...) (format)
|
||||
#pragma once
|
||||
|
||||
#include <io.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "StringUtil.h"
|
||||
#include "WinUtil.h"
|
||||
|
||||
#ifndef LOGGER_DISABLE
|
||||
class Logger
|
||||
{
|
||||
public:
|
||||
std::mutex printLogMutex;
|
||||
Logger(const Logger&) = delete;
|
||||
const Logger& operator=(Logger& other) = delete;
|
||||
|
||||
Logger() : m_systime(), m_console(INVALID_HANDLE_VALUE), m_file(INVALID_HANDLE_VALUE) {}
|
||||
|
||||
Logger::~Logger()
|
||||
{
|
||||
if (m_console)
|
||||
FreeConsole();
|
||||
|
||||
if (m_file)
|
||||
CloseHandle(m_file);
|
||||
}
|
||||
|
||||
static Logger& Logger::Get()
|
||||
{
|
||||
static Logger instance;
|
||||
return instance;
|
||||
};
|
||||
|
||||
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);
|
||||
OutputDebugStringA(logpath.c_str());
|
||||
|
||||
if (m_file != INVALID_HANDLE_VALUE)
|
||||
PrintStamp(false);
|
||||
|
||||
return m_file != INVALID_HANDLE_VALUE;
|
||||
}
|
||||
|
||||
bool Console(const char* title)
|
||||
{
|
||||
AllocConsole();
|
||||
|
||||
m_console = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
if (m_console != INVALID_HANDLE_VALUE)
|
||||
{
|
||||
ShowWindow(GetConsoleWindow(), SW_MAXIMIZE);
|
||||
if (title) SetConsoleTitleA(title);
|
||||
}
|
||||
|
||||
if (m_console != INVALID_HANDLE_VALUE)
|
||||
PrintStamp(true);
|
||||
|
||||
return m_console != INVALID_HANDLE_VALUE;
|
||||
}
|
||||
|
||||
void Print(const char* format, va_list args)
|
||||
{
|
||||
bool to_console = m_console != INVALID_HANDLE_VALUE;
|
||||
bool to_file = m_file != INVALID_HANDLE_VALUE;
|
||||
|
||||
if ((to_console || to_file) && format)
|
||||
{
|
||||
int outsize = _vscprintf(format, args) + 1;
|
||||
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);
|
||||
#else
|
||||
std::string to_print;
|
||||
GetTime(&to_print);
|
||||
to_print.append(buffer.get(), outsize - 1);
|
||||
#endif
|
||||
|
||||
to_print.append("\r\n");
|
||||
|
||||
DWORD lenout = 0;
|
||||
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)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
void GetTime(std::string* out)
|
||||
{
|
||||
GetLocalTime(&m_systime);
|
||||
*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;
|
||||
HANDLE m_file;
|
||||
};
|
||||
|
||||
inline void LogFile(const std::string& logname)
|
||||
{
|
||||
Logger::Get().File(logname);
|
||||
}
|
||||
|
||||
inline void LogConsole(const char* title = nullptr)
|
||||
{
|
||||
Logger::Get().Console(title);
|
||||
}
|
||||
|
||||
inline void PrintLog(const char* format, ...)
|
||||
{
|
||||
const std::lock_guard<std::mutex> lock(Logger::Get().printLogMutex);
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
Logger::Get().Print(format, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
#else
|
||||
#define LogFile(logname) (logname)
|
||||
#define LogConsole(title, notice) (title)
|
||||
#define PrintLog(format, ...) (format)
|
||||
#endif
|
|
@ -103,6 +103,13 @@ HRESULT APIENTRY MainContext::ApplyVertexBufferFix(IDirect3DDevice9* pIDirect3DD
|
|||
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()
|
||||
{
|
||||
// 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() {
|
||||
MainContext::FF13_NOPIngameFrameRateLimitSetter();
|
||||
MainContext::FF13_SetFrameRateVariables();
|
||||
MainContext::FF13_RemoveContinuousControllerScan();
|
||||
MainContext::FF13_FixMissingEnemyScan();
|
||||
MainContext::FF13_EnableControllerVibration();
|
||||
|
||||
MainContext::FF13_SetFrameRateVariables();
|
||||
|
||||
PrintLog("Finished FF13 One Time Fixes");
|
||||
MainContext::didOneTimeFixes = true;
|
||||
context.didOneTimeFixes = true;
|
||||
}
|
||||
|
||||
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() {
|
||||
|
||||
if (*ff13_2_frame_pacer_ptr_address) {
|
||||
|
@ -262,6 +274,9 @@ void MainContext::FF13_2_OneTimeFixes() {
|
|||
PrintLog("Finished FF13-2 One Time Fixes");
|
||||
context.didOneTimeFixes = true;
|
||||
}
|
||||
else {
|
||||
PrintLog("Unable to apply FF13-2 One Time Fixes. Report this!");
|
||||
}
|
||||
}
|
||||
|
||||
void MainContext::FF13_2_EnableControllerVibration()
|
||||
|
@ -389,7 +404,7 @@ void MainContext::ChangeMemoryProtectionToReadWriteExecute(void* address, const
|
|||
}
|
||||
|
||||
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) {
|
||||
|
|
|
@ -192,18 +192,18 @@ bool MainContext::CheckWindow(HWND hWnd)
|
|||
PrintLog("HWND 0x%p: ClassName \"%ls\", WindowName: \"%ls\"", hWnd, className.get(), windowName.get());
|
||||
|
||||
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);
|
||||
if(!context.didOneTimeFixes){
|
||||
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);
|
||||
if (!context.didOneTimeFixes) {
|
||||
PrintLog("Starting FFXIII-2 one time RAM patches.");
|
||||
context.FF13_2_OneTimeFixes();
|
||||
patchingThread = new std::thread(&context.FF13_2_AsyncPatchingLoop);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -45,7 +45,6 @@ class MainContext
|
|||
|
||||
public:
|
||||
MainContext();
|
||||
void Foo();
|
||||
~MainContext();
|
||||
|
||||
bool ApplyPresentationParameters(D3DPRESENT_PARAMETERS* pPresentationParameters);
|
||||
|
@ -100,6 +99,7 @@ private:
|
|||
const float FF13_2_30_FPS = 30.0F;
|
||||
const float FF13_2_MAX_FRAME_CAP = 1000.0F;
|
||||
XInputManager* xinputManager;
|
||||
std::thread * patchingThread;
|
||||
|
||||
void FixBehaviorFlagConflict(const DWORD flags_in, DWORD* flags_out);
|
||||
static const std::map<const AutoFixes, const uint32_t> behaviorflags_fixes;
|
||||
|
@ -111,6 +111,8 @@ private:
|
|||
bool AreAlmostTheSame(float a, float b);
|
||||
void PrintVersionInfo();
|
||||
|
||||
|
||||
static void FF13_AsyncPatchingLoop();
|
||||
void FF13_InitializeGameAddresses();
|
||||
void FF13_OneTimeFixes();
|
||||
void FF13_EnableControllerVibration();
|
||||
|
@ -119,6 +121,7 @@ private:
|
|||
void FF13_FixMissingEnemyScan();
|
||||
void FF13_RemoveContinuousControllerScan();
|
||||
|
||||
static void FF13_2_AsyncPatchingLoop();
|
||||
void FF13_2_CreateSetFrameRateCodeBlock();
|
||||
void FF13_2_InitializeGameAddresses();
|
||||
void FF13_2_RemoveContinuousControllerScan();
|
||||
|
|
Loading…
Reference in a new issue