mirror of
https://github.com/narzoul/DDrawCompat
synced 2024-12-30 08:55:36 +01:00
Separate log files per process name and instance number
This commit is contained in:
parent
757f648385
commit
c67437d5bf
@ -144,14 +144,14 @@ namespace
|
|||||||
GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS,
|
GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS,
|
||||||
static_cast<char*>(hookedFuncPtr), &module);
|
static_cast<char*>(hookedFuncPtr), &module);
|
||||||
|
|
||||||
Compat::LogDebug() << "Hooking function: " << funcName << " (" << funcAddrToStr(hookedFuncPtr) << ')';
|
LOG_DEBUG << "Hooking function: " << funcName << " (" << funcAddrToStr(hookedFuncPtr) << ')';
|
||||||
|
|
||||||
DetourTransactionBegin();
|
DetourTransactionBegin();
|
||||||
const bool attachSuccessful = NO_ERROR == DetourAttach(&origFuncPtr, newFuncPtr);
|
const bool attachSuccessful = NO_ERROR == DetourAttach(&origFuncPtr, newFuncPtr);
|
||||||
const bool commitSuccessful = NO_ERROR == DetourTransactionCommit();
|
const bool commitSuccessful = NO_ERROR == DetourTransactionCommit();
|
||||||
if (!attachSuccessful || !commitSuccessful)
|
if (!attachSuccessful || !commitSuccessful)
|
||||||
{
|
{
|
||||||
Compat::LogDebug() << "ERROR: Failed to hook a function: " << funcName;
|
LOG_DEBUG << "ERROR: Failed to hook a function: " << funcName;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -270,7 +270,7 @@ namespace Compat
|
|||||||
FARPROC procAddr = getProcAddress(module, funcName);
|
FARPROC procAddr = getProcAddress(module, funcName);
|
||||||
if (!procAddr)
|
if (!procAddr)
|
||||||
{
|
{
|
||||||
Compat::LogDebug() << "ERROR: Failed to load the address of a function: " << funcName;
|
LOG_DEBUG << "ERROR: Failed to load the address of a function: " << funcName;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -294,7 +294,7 @@ namespace Compat
|
|||||||
FARPROC* func = findProcAddressInIat(module, importedModuleName, funcName);
|
FARPROC* func = findProcAddressInIat(module, importedModuleName, funcName);
|
||||||
if (func)
|
if (func)
|
||||||
{
|
{
|
||||||
Compat::LogDebug() << "Hooking function via IAT: " << funcName << " (" << funcAddrToStr(*func) << ')';
|
LOG_DEBUG << "Hooking function via IAT: " << funcName << " (" << funcAddrToStr(*func) << ')';
|
||||||
DWORD oldProtect = 0;
|
DWORD oldProtect = 0;
|
||||||
VirtualProtect(func, sizeof(func), PAGE_READWRITE, &oldProtect);
|
VirtualProtect(func, sizeof(func), PAGE_READWRITE, &oldProtect);
|
||||||
*func = static_cast<FARPROC>(newFuncPtr);
|
*func = static_cast<FARPROC>(newFuncPtr);
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
#include <sstream>
|
||||||
|
|
||||||
#include <Common/Log.h>
|
#include <Common/Log.h>
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
@ -74,9 +76,30 @@ namespace Compat
|
|||||||
s_logFile << std::endl;
|
s_logFile << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Log::initLogging()
|
void Log::initLogging(std::string processName)
|
||||||
{
|
{
|
||||||
s_logFile.open("ddraw.log");
|
if (processName.length() >= 4 &&
|
||||||
|
0 == _strcmpi(processName.substr(processName.length() - 4).c_str(), ".exe"))
|
||||||
|
{
|
||||||
|
processName.resize(processName.length() - 4);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 1; i < 100; ++i)
|
||||||
|
{
|
||||||
|
std::ostringstream logFileName;
|
||||||
|
logFileName << "DDrawCompat-" << processName;
|
||||||
|
if (i > 1)
|
||||||
|
{
|
||||||
|
logFileName << '[' << i << ']';
|
||||||
|
}
|
||||||
|
logFileName << ".log";
|
||||||
|
|
||||||
|
s_logFile.open(logFileName.str(), std::ios_base::out, SH_DENYWR);
|
||||||
|
if (!s_logFile.fail())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
thread_local DWORD Log::s_indent = 0;
|
thread_local DWORD Log::s_indent = 0;
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <ostream>
|
#include <ostream>
|
||||||
|
#include <string>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
|
||||||
#include <Windows.h>
|
#include <Windows.h>
|
||||||
@ -11,8 +12,15 @@
|
|||||||
#include <DDraw/Log.h>
|
#include <DDraw/Log.h>
|
||||||
#include <Win32/Log.h>
|
#include <Win32/Log.h>
|
||||||
|
|
||||||
|
#ifdef DEBUGLOGS
|
||||||
|
#define LOG_DEBUG Compat::Log()
|
||||||
#define LOG_FUNC(...) Compat::LogFunc logFunc(__VA_ARGS__)
|
#define LOG_FUNC(...) Compat::LogFunc logFunc(__VA_ARGS__)
|
||||||
#define LOG_RESULT(...) logFunc.setResult(__VA_ARGS__)
|
#define LOG_RESULT(...) logFunc.setResult(__VA_ARGS__)
|
||||||
|
#else
|
||||||
|
#define LOG_DEBUG if (false) Compat::Log()
|
||||||
|
#define LOG_FUNC(...)
|
||||||
|
#define LOG_RESULT(...) __VA_ARGS__
|
||||||
|
#endif
|
||||||
|
|
||||||
#define LOG_ONCE(msg) \
|
#define LOG_ONCE(msg) \
|
||||||
{ \
|
{ \
|
||||||
@ -145,7 +153,7 @@ namespace Compat
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void initLogging();
|
static void initLogging(std::string processName);
|
||||||
static bool isPointerDereferencingAllowed() { return s_isLeaveLog || 0 == s_outParamDepth; }
|
static bool isPointerDereferencingAllowed() { return s_isLeaveLog || 0 == s_outParamDepth; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
@ -187,16 +195,6 @@ namespace Compat
|
|||||||
static std::ofstream s_logFile;
|
static std::ofstream s_logFile;
|
||||||
};
|
};
|
||||||
|
|
||||||
class LogStruct : public detail::LogFirstParam
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
LogStruct(std::ostream& os) : detail::LogFirstParam(os) { m_os << '{'; }
|
|
||||||
~LogStruct() { m_os << '}'; }
|
|
||||||
};
|
|
||||||
|
|
||||||
#ifdef DEBUGLOGS
|
|
||||||
typedef Log LogDebug;
|
|
||||||
|
|
||||||
class LogFunc
|
class LogFunc
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -237,28 +235,13 @@ namespace Compat
|
|||||||
std::function<void(Log&)> m_printCall;
|
std::function<void(Log&)> m_printCall;
|
||||||
std::function<void(Log&)> m_printResult;
|
std::function<void(Log&)> m_printResult;
|
||||||
};
|
};
|
||||||
#else
|
|
||||||
class LogDebug
|
class LogStruct : public detail::LogFirstParam
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
template <typename T> LogDebug& operator<<(const T&) { return *this; }
|
LogStruct(std::ostream& os) : detail::LogFirstParam(os) { m_os << '{'; }
|
||||||
|
~LogStruct() { m_os << '}'; }
|
||||||
};
|
};
|
||||||
|
|
||||||
class LogFunc
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
template <typename... Params>
|
|
||||||
LogFunc(const char* /*funcName*/, Params...)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
T setResult(T result)
|
|
||||||
{
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
|
@ -464,7 +464,9 @@ namespace D3dDdi
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef DEBUGLOGS
|
||||||
LOG_RESULT(m_lockResource.get());
|
LOG_RESULT(m_lockResource.get());
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void Resource::endGdiAccess(bool isReadOnly)
|
void Resource::endGdiAccess(bool isReadOnly)
|
||||||
|
@ -214,8 +214,10 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
Compat::Log::initLogging();
|
auto processPath = getModulePath(nullptr);
|
||||||
Compat::Log() << "Process path: " << getModulePath(nullptr);
|
Compat::Log::initLogging(getFileName(processPath));
|
||||||
|
|
||||||
|
Compat::Log() << "Process path: " << processPath;
|
||||||
printEnvironmentVariable("__COMPAT_LAYER");
|
printEnvironmentVariable("__COMPAT_LAYER");
|
||||||
auto currentDllPath = getModulePath(hinstDLL);
|
auto currentDllPath = getModulePath(hinstDLL);
|
||||||
Compat::Log() << "Loading DDrawCompat " << (lpvReserved ? "statically" : "dynamically") << " from " << currentDllPath;
|
Compat::Log() << "Loading DDrawCompat " << (lpvReserved ? "statically" : "dynamically") << " from " << currentDllPath;
|
||||||
|
@ -7,7 +7,7 @@ namespace
|
|||||||
BOOL g_isFontSmoothingEnabled = FALSE;
|
BOOL g_isFontSmoothingEnabled = FALSE;
|
||||||
|
|
||||||
BOOL WINAPI systemParametersInfo(UINT uiAction, UINT uiParam, PVOID pvParam, UINT fWinIni,
|
BOOL WINAPI systemParametersInfo(UINT uiAction, UINT uiParam, PVOID pvParam, UINT fWinIni,
|
||||||
decltype(&SystemParametersInfoA) origSystemParametersInfo, const char* origFuncName)
|
decltype(&SystemParametersInfoA) origSystemParametersInfo, [[maybe_unused]] const char* origFuncName)
|
||||||
{
|
{
|
||||||
LOG_FUNC(origFuncName, Compat::hex(uiAction), uiParam, pvParam, fWinIni);
|
LOG_FUNC(origFuncName, Compat::hex(uiAction), uiParam, pvParam, fWinIni);
|
||||||
switch (uiAction)
|
switch (uiAction)
|
||||||
|
@ -160,7 +160,7 @@ namespace
|
|||||||
}
|
}
|
||||||
|
|
||||||
LRESULT defPaintProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam, WNDPROC origWndProc,
|
LRESULT defPaintProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam, WNDPROC origWndProc,
|
||||||
const char* origWndProcName)
|
[[maybe_unused]] const char* origWndProcName)
|
||||||
{
|
{
|
||||||
LOG_FUNC(origWndProcName, hwnd, Compat::logWm(msg), Compat::hex(wParam), Compat::hex(lParam));
|
LOG_FUNC(origWndProcName, hwnd, Compat::logWm(msg), Compat::hex(wParam), Compat::hex(lParam));
|
||||||
return LOG_RESULT(defPaintProc(hwnd, msg, wParam, lParam, origWndProc));
|
return LOG_RESULT(defPaintProc(hwnd, msg, wParam, lParam, origWndProc));
|
||||||
@ -431,7 +431,7 @@ namespace
|
|||||||
}
|
}
|
||||||
|
|
||||||
LRESULT CALLBACK user32WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam,
|
LRESULT CALLBACK user32WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam,
|
||||||
const std::string& procName, WndProcHook wndProcHook, WNDPROC oldWndProcTrampoline)
|
[[maybe_unused]] const std::string& procName, WndProcHook wndProcHook, WNDPROC oldWndProcTrampoline)
|
||||||
{
|
{
|
||||||
LOG_FUNC(procName.c_str(), hwnd, Compat::logWm(uMsg), Compat::hex(wParam), Compat::hex(lParam));
|
LOG_FUNC(procName.c_str(), hwnd, Compat::logWm(uMsg), Compat::hex(wParam), Compat::hex(lParam));
|
||||||
return LOG_RESULT(wndProcHook(hwnd, uMsg, wParam, lParam, oldWndProcTrampoline));
|
return LOG_RESULT(wndProcHook(hwnd, uMsg, wParam, lParam, oldWndProcTrampoline));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user