From 87c2af5049d89912487c1c84c917e8c0d26c5d9f Mon Sep 17 00:00:00 2001 From: narzoul Date: Sun, 22 May 2022 18:39:04 +0200 Subject: [PATCH] Added LogLevel setting --- DDrawCompat.sln | 7 +- DDrawCompat/Common/Hook.cpp | 21 ++--- DDrawCompat/Common/Log.cpp | 91 ++++++++++++++++--- DDrawCompat/Common/Log.h | 62 ++++++------- DDrawCompat/Common/VtableHookVisitor.h | 23 +++-- DDrawCompat/Config/Config.cpp | 1 + DDrawCompat/Config/Config.h | 2 + DDrawCompat/Config/Parser.cpp | 10 +- DDrawCompat/Config/Settings/LogLevel.h | 29 ++++++ DDrawCompat/D3dDdi/Adapter.cpp | 8 +- DDrawCompat/D3dDdi/Hooks.cpp | 2 +- DDrawCompat/D3dDdi/Resource.cpp | 2 - DDrawCompat/DDraw/Hooks.cpp | 6 +- DDrawCompat/DDraw/RealPrimarySurface.cpp | 2 +- DDrawCompat/DDraw/Surfaces/PrimarySurface.cpp | 2 +- DDrawCompat/DDrawCompat.vcxproj | 70 +------------- DDrawCompat/DDrawCompat.vcxproj.filters | 3 + DDrawCompat/Direct3d/Hooks.cpp | 18 ++-- DDrawCompat/Dll/DllMain.cpp | 36 ++++---- DDrawCompat/Gdi/DcFunctions.cpp | 6 -- DDrawCompat/Gdi/GuiThread.cpp | 2 +- DDrawCompat/Gdi/Icon.cpp | 3 - DDrawCompat/Gdi/User32WndProcs.cpp | 2 +- DDrawCompat/Win32/Thread.cpp | 2 +- 24 files changed, 212 insertions(+), 198 deletions(-) create mode 100644 DDrawCompat/Config/Settings/LogLevel.h diff --git a/DDrawCompat.sln b/DDrawCompat.sln index 396cf5b..e630767 100644 --- a/DDrawCompat.sln +++ b/DDrawCompat.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 16 -VisualStudioVersion = 16.0.29001.49 +# Visual Studio Version 17 +VisualStudioVersion = 17.2.32516.85 MinimumVisualStudioVersion = 10.0.40219.1 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DDrawCompat", "DDrawCompat\DDrawCompat.vcxproj", "{1146187A-17DE-4350-B9D1-9F9EAA934908}" EndProject @@ -9,15 +9,12 @@ Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|x86 = Debug|x86 Release|x86 = Release|x86 - ReleaseWithDebugLogs|x86 = ReleaseWithDebugLogs|x86 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {1146187A-17DE-4350-B9D1-9F9EAA934908}.Debug|x86.ActiveCfg = Debug|Win32 {1146187A-17DE-4350-B9D1-9F9EAA934908}.Debug|x86.Build.0 = Debug|Win32 {1146187A-17DE-4350-B9D1-9F9EAA934908}.Release|x86.ActiveCfg = Release|Win32 {1146187A-17DE-4350-B9D1-9F9EAA934908}.Release|x86.Build.0 = Release|Win32 - {1146187A-17DE-4350-B9D1-9F9EAA934908}.ReleaseWithDebugLogs|x86.ActiveCfg = ReleaseWithDebugLogs|Win32 - {1146187A-17DE-4350-B9D1-9F9EAA934908}.ReleaseWithDebugLogs|x86.Build.0 = ReleaseWithDebugLogs|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/DDrawCompat/Common/Hook.cpp b/DDrawCompat/Common/Hook.cpp index 3700e28..67d4ac0 100644 --- a/DDrawCompat/Common/Hook.cpp +++ b/DDrawCompat/Common/Hook.cpp @@ -131,9 +131,7 @@ namespace BYTE* targetFunc = static_cast(origFuncPtr); std::ostringstream oss; -#ifdef DEBUGLOGS oss << Compat::funcPtrToStr(targetFunc) << ' '; -#endif char origFuncPtrStr[20] = {}; if (!funcName) @@ -170,16 +168,15 @@ namespace { break; } -#ifdef DEBUGLOGS + Compat::LogStream(oss) << Compat::hexDump(prevTargetFunc, instructionSize) << " -> " << Compat::funcPtrToStr(targetFunc) << ' '; -#endif prevTargetFunc = targetFunc; } if (Compat::getModuleHandleFromAddress(targetFunc) == Dll::g_currentModule) { - Compat::Log() << "ERROR: Target function is already hooked: " << funcName; + LOG_INFO << "ERROR: Target function is already hooked: " << funcName; return; } @@ -241,7 +238,7 @@ namespace auto dbgEng = LoadLibraryW((Compat::getSystemPath() / "dbgeng.dll").c_str()); if (!dbgEng) { - Compat::Log() << "ERROR: DbgEng: failed to load library"; + LOG_INFO << "ERROR: DbgEng: failed to load library"; return false; } @@ -250,7 +247,7 @@ namespace auto debugCreate = reinterpret_cast(Compat::getProcAddress(dbgEng, "DebugCreate")); if (!debugCreate) { - Compat::Log() << "ERROR: DbgEng: DebugCreate not found"; + LOG_INFO << "ERROR: DbgEng: DebugCreate not found"; return false; } @@ -260,14 +257,14 @@ namespace FAILED(result = g_debugClient->QueryInterface(IID_IDebugSymbols, reinterpret_cast(&g_debugSymbols))) || FAILED(result = g_debugClient->QueryInterface(IID_IDebugDataSpaces4, reinterpret_cast(&g_debugDataSpaces)))) { - Compat::Log() << "ERROR: DbgEng: object creation failed: " << Compat::hex(result); + LOG_INFO << "ERROR: DbgEng: object creation failed: " << Compat::hex(result); return false; } result = g_debugClient->OpenDumpFileWide(Compat::getModulePath(Dll::g_currentModule).c_str(), 0); if (FAILED(result)) { - Compat::Log() << "ERROR: DbgEng: OpenDumpFile failed: " << Compat::hex(result); + LOG_INFO << "ERROR: DbgEng: OpenDumpFile failed: " << Compat::hex(result); return false; } @@ -275,7 +272,7 @@ namespace result = g_debugControl->WaitForEvent(0, INFINITE); if (FAILED(result)) { - Compat::Log() << "ERROR: DbgEng: WaitForEvent failed: " << Compat::hex(result); + LOG_INFO << "ERROR: DbgEng: WaitForEvent failed: " << Compat::hex(result); return false; } @@ -283,7 +280,7 @@ namespace result = g_debugSymbols->GetModuleParameters(1, 0, 0, &dmp); if (FAILED(result)) { - Compat::Log() << "ERROR: DbgEng: GetModuleParameters failed: " << Compat::hex(result); + LOG_INFO << "ERROR: DbgEng: GetModuleParameters failed: " << Compat::hex(result); return false; } @@ -291,7 +288,7 @@ namespace result = g_debugDataSpaces->GetValidRegionVirtual(dmp.Base, dmp.Size, &g_debugBase, &size); if (FAILED(result) || 0 == g_debugBase) { - Compat::Log() << "ERROR: DbgEng: GetValidRegionVirtual failed: " << Compat::hex(result); + LOG_INFO << "ERROR: DbgEng: GetValidRegionVirtual failed: " << Compat::hex(result); return false; } diff --git a/DDrawCompat/Common/Log.cpp b/DDrawCompat/Common/Log.cpp index a1db4c3..844bc59 100644 --- a/DDrawCompat/Common/Log.cpp +++ b/DDrawCompat/Common/Log.cpp @@ -1,11 +1,17 @@ +#include +#include #include #include #include +#include namespace { Compat::CriticalSection g_logCs; + std::ofstream g_logFile; + static std::ostringstream g_initialLogStream; + } namespace Compat @@ -23,33 +29,60 @@ namespace Compat return os; } - Log::Log() : m_lock(g_logCs) + Log::Log(bool isEnabled) : m_isEnabled(isEnabled) { + if (!m_isEnabled) + { + return; + } + + EnterCriticalSection(&g_logCs); SYSTEMTIME st = {}; GetLocalTime(&st); char header[20]; -#ifdef DEBUGLOGS - sprintf_s(header, "%04hx %02hu:%02hu:%02hu.%03hu ", - GetCurrentThreadId(), st.wHour, st.wMinute, st.wSecond, st.wMilliseconds); -#else - sprintf_s(header, "%02hu:%02hu:%02hu.%03hu ", st.wHour, st.wMinute, st.wSecond, st.wMilliseconds); -#endif - s_logFile << header; + if (s_logLevel >= Config::Settings::LogLevel::DEBUG) + { + sprintf_s(header, "%04hx %02hu:%02hu:%02hu.%03hu ", + GetCurrentThreadId(), st.wHour, st.wMinute, st.wSecond, st.wMilliseconds); + } + else + { + sprintf_s(header, "%02hu:%02hu:%02hu.%03hu ", + st.wHour, st.wMinute, st.wSecond, st.wMilliseconds); + } + *s_logStream << header; if (0 != s_indent) { - std::fill_n(std::ostreambuf_iterator(s_logFile), s_indent, ' '); + std::fill_n(std::ostreambuf_iterator(*s_logStream), s_indent, ' '); } } + Log::Log(unsigned logLevel) : Log(logLevel <= s_logLevel) + { + } + Log::~Log() { - s_logFile << std::endl; + if (m_isEnabled) + { + *s_logStream << std::endl; + LeaveCriticalSection(&g_logCs); + } } - void Log::initLogging(std::filesystem::path processPath) + void Log::initLogging(std::filesystem::path processPath, unsigned logLevel) { + s_logLevel = logLevel; + s_logStream = &g_logFile; + + if (Config::Settings::LogLevel::NONE == logLevel) + { + g_initialLogStream = {}; + return; + } + if (Compat::isEqual(processPath.extension(), ".exe")) { processPath.replace_extension(); @@ -65,16 +98,46 @@ namespace Compat } logFilePath += ".log"; - s_logFile.open(logFilePath, std::ios_base::out, SH_DENYWR); - if (!s_logFile.fail()) + g_logFile.open(logFilePath, std::ios_base::out, SH_DENYWR); + if (!g_logFile.fail()) { + std::string initialLogs(g_initialLogStream.str()); + if (logLevel < Config::Settings::LogLevel::DEBUG) + { + initialLogs = std::regex_replace(initialLogs, std::regex("^....."), ""); + } + + g_logFile.write(initialLogs.c_str(), initialLogs.size()); + g_initialLogStream = {}; return; } } + + s_logLevel = Config::Settings::LogLevel::NONE; + } + + LogFuncBase::~LogFuncBase() + { + if (m_isEnabled) + { + Log::s_isLeaveLog = true; + Log::s_indent -= 2; + Log log(Config::Settings::LogLevel::DEBUG); + log << "< "; + logCall(log); + + if (m_logResult) + { + log << " = "; + m_logResult(log); + } + Log::s_isLeaveLog = false; + } } thread_local DWORD Log::s_indent = 0; bool Log::s_isLeaveLog = false; - std::ofstream Log::s_logFile; + unsigned Log::s_logLevel = Config::Settings::LogLevel::INITIAL; + std::ostream* Log::s_logStream = &g_initialLogStream; } diff --git a/DDrawCompat/Common/Log.h b/DDrawCompat/Common/Log.h index afbd1f8..260ad7a 100644 --- a/DDrawCompat/Common/Log.h +++ b/DDrawCompat/Common/Log.h @@ -10,28 +10,22 @@ #include -#include +#include #include #include -#ifdef DEBUGLOGS -#define LOG_DEBUG Compat::Log() +#define LOG_INFO Compat::Log(Config::Settings::LogLevel::INFO) +#define LOG_DEBUG Compat::Log(Config::Settings::LogLevel::DEBUG) #define LOG_FUNC(...) Compat::LogFunc logFunc(__VA_ARGS__) #define LOG_FUNC_CUSTOM(funcPtr, ...) Compat::LogFunc logFunc(__VA_ARGS__) #define LOG_RESULT(...) logFunc.setResult(__VA_ARGS__) -#else -#define LOG_DEBUG if constexpr (false) Compat::Log() -#define LOG_FUNC(...) -#define LOG_FUNC_CUSTOM(funcPtr, ...) -#define LOG_RESULT(...) __VA_ARGS__ -#endif #define LOG_ONCE(msg) \ { \ static bool isAlreadyLogged = false; \ if (!isAlreadyLogged) \ { \ - Compat::Log() << msg; \ + LOG_INFO << msg; \ isAlreadyLogged = true; \ } \ } @@ -245,28 +239,34 @@ namespace Compat class Log { public: - Log(); + Log(bool isEnabled); + Log(unsigned logLevel); ~Log(); template Log& operator<<(const T& t) { - LogStream(s_logFile) << t; + if (m_isEnabled) + { + LogStream(*s_logStream) << t; + } return *this; } - static void initLogging(std::filesystem::path processPath); + static unsigned getLogLevel() { return s_logLevel; } + static void initLogging(std::filesystem::path processPath, unsigned logLevel); static bool isLeaveLog() { return s_isLeaveLog; } private: friend class LogFuncBase; - ScopedCriticalSection m_lock; + bool m_isEnabled; static thread_local DWORD s_indent; static bool s_isLeaveLog; - static std::ofstream s_logFile; + static unsigned s_logLevel; + static std::ostream* s_logStream; }; template @@ -315,7 +315,10 @@ namespace Compat template T setResult(T result) { - m_logResult = [=](Log& log) { log << std::hex << result << std::dec; }; + if (m_isEnabled) + { + m_logResult = [=](Log& log) { log << std::hex << result << std::dec; }; + } return result; } @@ -324,29 +327,19 @@ namespace Compat LogFuncBase(const char* funcName, std::function logParams) : m_funcName(funcName) , m_logParams(logParams) + , m_isEnabled(Log::s_logLevel >= Config::Settings::LogLevel::DEBUG) { - Log log; - log << "> "; - logCall(log); - Log::s_indent += 2; - } - - ~LogFuncBase() - { - Log::s_isLeaveLog = true; - Log::s_indent -= 2; - Log log; - log << "< "; - logCall(log); - - if (m_logResult) + if (m_isEnabled) { - log << " = "; - m_logResult(log); + Log log(Config::Settings::LogLevel::DEBUG); + log << "> "; + logCall(log); + Log::s_indent += 2; } - Log::s_isLeaveLog = false; } + ~LogFuncBase(); + template auto packParam(Param&& param) { @@ -377,6 +370,7 @@ namespace Compat const char* m_funcName; std::function m_logParams; std::function m_logResult; + bool m_isEnabled; }; template diff --git a/DDrawCompat/Common/VtableHookVisitor.h b/DDrawCompat/Common/VtableHookVisitor.h index f77b66f..4fa8ef1 100644 --- a/DDrawCompat/Common/VtableHookVisitor.h +++ b/DDrawCompat/Common/VtableHookVisitor.h @@ -17,12 +17,10 @@ template constexpr auto getCompatFunc(Vtable*) { auto func = getCompatVtable().*memberPtr; -#ifdef DEBUGLOGS if (!func) { func = &callOrigFunc; } -#endif return func; } @@ -52,18 +50,21 @@ public: template void visit([[maybe_unused]] const char* funcName) { - if constexpr (getCompatFunc()) + if constexpr (!(getCompatVtable().*memberPtr)) { - if (m_vtable.*memberPtr) + if (Compat::Log::getLogLevel() < Config::Settings::LogLevel::DEBUG) { -#ifdef DEBUGLOGS - s_funcName = s_vtableTypeName + "::" + funcName; - Compat::Log() << "Hooking function: " << s_funcName - << " (" << Compat::funcPtrToStr(m_vtable.*memberPtr) << ')'; -#endif - m_vtable.*memberPtr = &hookFunc; + return; } } + + if (m_vtable.*memberPtr) + { + s_funcName = s_vtableTypeName + "::" + funcName; + LOG_DEBUG << "Hooking function: " << s_funcName + << " (" << Compat::funcPtrToStr(m_vtable.*memberPtr) << ')'; + m_vtable.*memberPtr = &hookFunc; + } } private: @@ -101,11 +102,9 @@ private: static std::string s_vtableTypeName; }; -#ifdef DEBUGLOGS template template std::string VtableHookVisitor::s_funcName; template std::string VtableHookVisitor::s_vtableTypeName(getVtableTypeName()); -#endif diff --git a/DDrawCompat/Config/Config.cpp b/DDrawCompat/Config/Config.cpp index 48bc7c4..668c20b 100644 --- a/DDrawCompat/Config/Config.cpp +++ b/DDrawCompat/Config/Config.cpp @@ -14,6 +14,7 @@ namespace Config Settings::DisplayResolution displayResolution; Settings::ForceD3D9On12 forceD3D9On12; Settings::FullscreenMode fullscreenMode; + Settings::LogLevel logLevel; Settings::RemoveBorders removeBorders; Settings::RenderColorDepth renderColorDepth; Settings::ResolutionScale resolutionScale; diff --git a/DDrawCompat/Config/Config.h b/DDrawCompat/Config/Config.h index e26b72f..fce5de8 100644 --- a/DDrawCompat/Config/Config.h +++ b/DDrawCompat/Config/Config.h @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -38,6 +39,7 @@ namespace Config extern Settings::DisplayResolution displayResolution; extern Settings::ForceD3D9On12 forceD3D9On12; extern Settings::FullscreenMode fullscreenMode; + extern Settings::LogLevel logLevel; extern Settings::RemoveBorders removeBorders; extern Settings::RenderColorDepth renderColorDepth; extern Settings::ResolutionScale resolutionScale; diff --git a/DDrawCompat/Config/Parser.cpp b/DDrawCompat/Config/Parser.cpp index 48652b7..7c6ba37 100644 --- a/DDrawCompat/Config/Parser.cpp +++ b/DDrawCompat/Config/Parser.cpp @@ -19,11 +19,11 @@ namespace void loadConfigFile(const std::string& source, const std::filesystem::path& path) { - Compat::Log() << "Loading " << source << " config file: " << path.u8string(); + LOG_INFO << "Loading " << source << " config file: " << path.u8string(); std::ifstream f(path); if (!f.is_open()) { - Compat::Log() << " File not found, skipping"; + LOG_INFO << " File not found, skipping"; return; } @@ -54,7 +54,7 @@ namespace } catch (const Config::ParsingError& error) { - Compat::Log() << " Line #" << lineNumber << ": " << error.what(); + LOG_INFO << " Line #" << lineNumber << ": " << error.what(); } } } @@ -120,14 +120,14 @@ namespace Config } } - Compat::Log() << "Final configuration:"; + LOG_INFO << "Final configuration:"; for (const auto& setting : getSettings()) { std::string name(setting.second.getName()); name.insert(name.end(), maxNameLength - name.length(), ' '); std::string source(setting.second.getSource()); source.insert(source.end(), maxSourceLength - source.length(), ' '); - Compat::Log() << " [" << source << "] " << name << " = " << setting.second.getValueStr(); + LOG_INFO << " [" << source << "] " << name << " = " << setting.second.getValueStr(); } } diff --git a/DDrawCompat/Config/Settings/LogLevel.h b/DDrawCompat/Config/Settings/LogLevel.h new file mode 100644 index 0000000..5f32b93 --- /dev/null +++ b/DDrawCompat/Config/Settings/LogLevel.h @@ -0,0 +1,29 @@ +#pragma once + +#include + +namespace Config +{ + namespace Settings + { + class LogLevel : public MappedSetting + { + public: + static const UINT NONE = 0; + static const UINT INFO = 1; + static const UINT DEBUG = 2; + static const UINT INITIAL = MAXUINT; + + LogLevel::LogLevel() + : MappedSetting("LogLevel", +#ifdef _DEBUG + "debug", +#else + "info", +#endif + { {"none", NONE}, {"info", INFO}, {"debug", DEBUG} }) + { + } + }; + } +} diff --git a/DDrawCompat/D3dDdi/Adapter.cpp b/DDrawCompat/D3dDdi/Adapter.cpp index e0b89d1..4c710b8 100644 --- a/DDrawCompat/D3dDdi/Adapter.cpp +++ b/DDrawCompat/D3dDdi/Adapter.cpp @@ -23,9 +23,9 @@ namespace if (result.empty()) { - return "\"\""; + return "none"; } - return '"' + result.substr(2) + '"'; + return result.substr(2); } } @@ -55,8 +55,8 @@ namespace D3dDdi info.formatOps = getFormatOps(); info.supportedZBufferBitDepths = getSupportedZBufferBitDepths(info.formatOps); - Compat::Log() << "Supported z-buffer bit depths: " << bitDepthsToString(info.supportedZBufferBitDepths); - Compat::Log() << "Supported MSAA modes: " << getSupportedMsaaModes(info.formatOps); + LOG_INFO << "Supported z-buffer bit depths: " << bitDepthsToString(info.supportedZBufferBitDepths); + LOG_INFO << "Supported MSAA modes: " << getSupportedMsaaModes(info.formatOps); LOG_DEBUG << "Supported resource formats:"; for (const auto& formatOp : info.formatOps) { diff --git a/DDrawCompat/D3dDdi/Hooks.cpp b/DDrawCompat/D3dDdi/Hooks.cpp index b784f73..c0ad909 100644 --- a/DDrawCompat/D3dDdi/Hooks.cpp +++ b/DDrawCompat/D3dDdi/Hooks.cpp @@ -79,7 +79,7 @@ namespace static std::set hookedModules; if (hookedModules.find(hModule) == hookedModules.end()) { - Compat::Log() << "Hooking user mode display driver: " << Compat::funcPtrToStr(g_origOpenAdapter); + LOG_INFO << "Hooking user mode display driver: " << Compat::funcPtrToStr(g_origOpenAdapter); Dll::pinModule(hModule); hookedModules.insert(hModule); } diff --git a/DDrawCompat/D3dDdi/Resource.cpp b/DDrawCompat/D3dDdi/Resource.cpp index 0c84f75..ab171de 100644 --- a/DDrawCompat/D3dDdi/Resource.cpp +++ b/DDrawCompat/D3dDdi/Resource.cpp @@ -599,9 +599,7 @@ namespace D3dDdi } } -#ifdef DEBUGLOGS LOG_RESULT(m_lockResource.get()); -#endif } void Resource::disableClamp() diff --git a/DDrawCompat/DDraw/Hooks.cpp b/DDrawCompat/DDraw/Hooks.cpp index e7ed633..8907645 100644 --- a/DDrawCompat/DDraw/Hooks.cpp +++ b/DDrawCompat/DDraw/Hooks.cpp @@ -32,7 +32,7 @@ namespace } else { - Compat::Log() << "ERROR: Failed to create a DirectDraw clipper for hooking: " << result; + LOG_INFO << "ERROR: Failed to create a DirectDraw clipper for hooking: " << result; } } @@ -47,7 +47,7 @@ namespace } else { - Compat::Log() << "ERROR: Failed to create a DirectDraw palette for hooking: " << result; + LOG_INFO << "ERROR: Failed to create a DirectDraw palette for hooking: " << result; } } @@ -76,7 +76,7 @@ namespace } else { - Compat::Log() << "ERROR: Failed to create a DirectDraw surface for hooking: " << result; + LOG_INFO << "ERROR: Failed to create a DirectDraw surface for hooking: " << result; } } diff --git a/DDrawCompat/DDraw/RealPrimarySurface.cpp b/DDrawCompat/DDraw/RealPrimarySurface.cpp index 4138915..5786482 100644 --- a/DDrawCompat/DDraw/RealPrimarySurface.cpp +++ b/DDrawCompat/DDraw/RealPrimarySurface.cpp @@ -277,7 +277,7 @@ namespace DDraw if (FAILED(result)) { - Compat::Log() << "ERROR: Failed to create the real primary surface: " << Compat::hex(result); + LOG_INFO << "ERROR: Failed to create the real primary surface: " << Compat::hex(result); g_monitorRect = {}; return result; } diff --git a/DDrawCompat/DDraw/Surfaces/PrimarySurface.cpp b/DDrawCompat/DDraw/Surfaces/PrimarySurface.cpp index 4da6246..dcb0852 100644 --- a/DDrawCompat/DDraw/Surfaces/PrimarySurface.cpp +++ b/DDrawCompat/DDraw/Surfaces/PrimarySurface.cpp @@ -76,7 +76,7 @@ namespace DDraw result = Surface::create(dd, desc, surface, std::move(privateData)); if (FAILED(result)) { - Compat::Log() << "ERROR: Failed to create the compat primary surface: " << Compat::hex(result); + LOG_INFO << "ERROR: Failed to create the compat primary surface: " << Compat::hex(result); g_monitorRect = {}; RealPrimarySurface::release(); return result; diff --git a/DDrawCompat/DDrawCompat.vcxproj b/DDrawCompat/DDrawCompat.vcxproj index a9de31b..3c72da4 100644 --- a/DDrawCompat/DDrawCompat.vcxproj +++ b/DDrawCompat/DDrawCompat.vcxproj @@ -5,10 +5,6 @@ Debug Win32 - - ReleaseWithDebugLogs - Win32 - Release Win32 @@ -36,13 +32,6 @@ NotSet false - - DynamicLibrary - false - v143 - NotSet - false - @@ -54,9 +43,6 @@ - - - ddraw @@ -72,22 +58,14 @@ $(SolutionDir)Build\$(Configuration)\ true - - ddraw - false - false - $(SolutionDir)Build\$(Configuration)\ - true - Level4 - DEBUGLOGS;WIN32_LEAN_AND_MEAN;CINTERFACE;_NO_DDRAWINT_NO_COM;PSAPI_VERSION=1;WIN32;_DEBUG;_WINDOWS;_USRDLL;DDRAWCOMPAT_EXPORTS;%(PreprocessorDefinitions) + WIN32_LEAN_AND_MEAN;CINTERFACE;_NO_DDRAWINT_NO_COM;PSAPI_VERSION=1;WIN32;_DEBUG;_WINDOWS;_USRDLL;DDRAWCOMPAT_EXPORTS;%(PreprocessorDefinitions) MultiThreadedDebug true - false $(IntDir)%(RelativeDir) ProgramDatabase stdcpp17 @@ -111,9 +89,9 @@ g_ps%(Filename) + $(IntDir)%(RelativeDir)%(Filename).h 2.0 - $(IntDir)%(RelativeDir)%(Filename).h Pixel false @@ -127,6 +105,7 @@ MultiThreaded true $(IntDir)%(RelativeDir) + ProgramDatabase stdcpp17 $(ProjectDir);$(IntDir) @@ -148,49 +127,11 @@ $(IntDir)%(RelativeDir)%(Filename).h - - 2.0 Pixel - - - - - Level4 - DEBUGLOGS;WIN32_LEAN_AND_MEAN;CINTERFACE;_NO_DDRAWINT_NO_COM;PSAPI_VERSION=1;WIN32;NDEBUG;_WINDOWS;_USRDLL;DDRAWCOMPAT_EXPORTS;%(PreprocessorDefinitions) - MultiThreaded - true - $(IntDir)%(RelativeDir) - stdcpp17 - $(ProjectDir);$(IntDir) - - - dwmapi.lib;dxguid.lib;imm32.lib;msimg32.lib;oleacc.lib;uxtheme.lib;winmm.lib;%(AdditionalDependencies) - DebugFull - true - $(IntDir)$(TargetName).lib - - - powershell.exe -NonInteractive -NoProfile -ExecutionPolicy Unrestricted -File genversion.ps1 "$(IntDir)version.h" - Generating version information - - - $(IntDir) - SPECIALBUILD=\"$(Configuration)\" - - - g_ps%(Filename) - - - - 2.0 - $(IntDir)%(RelativeDir)%(Filename).h - Pixel - - @@ -229,6 +170,7 @@ + @@ -471,11 +413,9 @@ Vertex - Vertex Vertex g_vs%(Filename) g_vs%(Filename) - g_vs%(Filename) @@ -484,4 +424,4 @@ - \ No newline at end of file + diff --git a/DDrawCompat/DDrawCompat.vcxproj.filters b/DDrawCompat/DDrawCompat.vcxproj.filters index 183d809..cdd92e1 100644 --- a/DDrawCompat/DDrawCompat.vcxproj.filters +++ b/DDrawCompat/DDrawCompat.vcxproj.filters @@ -564,6 +564,9 @@ Header Files\Config\Settings + + Header Files\Config\Settings + diff --git a/DDrawCompat/Direct3d/Hooks.cpp b/DDrawCompat/Direct3d/Hooks.cpp index 3ca8965..0a74540 100644 --- a/DDrawCompat/Direct3d/Hooks.cpp +++ b/DDrawCompat/Direct3d/Hooks.cpp @@ -34,7 +34,7 @@ namespace } else { - Compat::Log() << "ERROR: Failed to create a Direct3D object for hooking: " << Compat::hex(result); + LOG_INFO << "ERROR: Failed to create a Direct3D object for hooking: " << Compat::hex(result); } return d3d; } @@ -58,7 +58,7 @@ namespace HRESULT result = dd->CreateSurface(&dd, &desc, &renderTarget.getRef(), nullptr); if (FAILED(result)) { - Compat::Log() << "ERROR: Failed to create a render target for hooking: " << Compat::hex(result); + LOG_INFO << "ERROR: Failed to create a render target for hooking: " << Compat::hex(result); } return renderTarget; } @@ -103,7 +103,7 @@ namespace &d3d, IID_IDirect3DRGBDevice, &renderTarget, &d3dDevice.getRef(), nullptr); if (FAILED(result)) { - Compat::Log() << "ERROR: Failed to create a Direct3D device for hooking: " << Compat::hex(result); + LOG_INFO << "ERROR: Failed to create a Direct3D device for hooking: " << Compat::hex(result); return; } @@ -130,7 +130,7 @@ namespace HRESULT result = dev->CreateExecuteBuffer(&dev, &desc, &buffer.getRef(), nullptr); if (FAILED(result)) { - Compat::Log() << "ERROR: Failed to create an execute buffer for hooking: " << Compat::hex(result); + LOG_INFO << "ERROR: Failed to create an execute buffer for hooking: " << Compat::hex(result); return; } @@ -143,7 +143,7 @@ namespace HRESULT result = d3d->CreateLight(&d3d, &light.getRef(), nullptr); if (FAILED(result)) { - Compat::Log() << "ERROR: Failed to create a light for hooking: " << Compat::hex(result); + LOG_INFO << "ERROR: Failed to create a light for hooking: " << Compat::hex(result); return; } @@ -156,7 +156,7 @@ namespace HRESULT result = d3d->CreateMaterial(&d3d, &material.getRef(), nullptr); if (FAILED(result)) { - Compat::Log() << "ERROR: Failed to create a material for hooking: " << Compat::hex(result); + LOG_INFO << "ERROR: Failed to create a material for hooking: " << Compat::hex(result); return; } @@ -179,7 +179,7 @@ namespace HRESULT result = dd->CreateSurface(&dd, &desc, &texture.getRef(), nullptr); if (FAILED(result)) { - Compat::Log() << "ERROR: Failed to create a texture for hooking: " << Compat::hex(result); + LOG_INFO << "ERROR: Failed to create a texture for hooking: " << Compat::hex(result); return; } @@ -199,7 +199,7 @@ namespace HRESULT result = d3d->CreateVertexBuffer(&d3d, &desc, &vertexBuffer.getRef(), 0, nullptr); if (FAILED(result)) { - Compat::Log() << "ERROR: Failed to create a vertex buffer for hooking: " << Compat::hex(result); + LOG_INFO << "ERROR: Failed to create a vertex buffer for hooking: " << Compat::hex(result); } Direct3d::Direct3dVertexBuffer::hookVtable(*vertexBuffer.get()->lpVtbl); @@ -211,7 +211,7 @@ namespace HRESULT result = d3d->CreateViewport(&d3d, &viewport.getRef(), nullptr); if (FAILED(result)) { - Compat::Log() << "ERROR: Failed to create a Direct3D viewport for hooking: " << Compat::hex(result); + LOG_INFO << "ERROR: Failed to create a Direct3D viewport for hooking: " << Compat::hex(result); return; } diff --git a/DDrawCompat/Dll/DllMain.cpp b/DDrawCompat/Dll/DllMain.cpp index 2b4376f..e9876de 100644 --- a/DDrawCompat/Dll/DllMain.cpp +++ b/DDrawCompat/Dll/DllMain.cpp @@ -70,11 +70,11 @@ namespace static bool isAlreadyInstalled = false; if (!isAlreadyInstalled) { - Compat::Log() << "Installing display mode hooks"; + LOG_INFO << "Installing display mode hooks"; Win32::DisplayMode::installHooks(); - Compat::Log() << "Installing registry hooks"; + LOG_INFO << "Installing registry hooks"; Win32::Registry::installHooks(); - Compat::Log() << "Installing Direct3D driver hooks"; + LOG_INFO << "Installing Direct3D driver hooks"; D3dDdi::installHooks(); Gdi::VirtualScreen::init(); @@ -82,7 +82,7 @@ namespace HRESULT result = CALL_ORIG_PROC(DirectDrawCreate)(nullptr, &dd.getRef(), nullptr); if (FAILED(result)) { - Compat::Log() << "ERROR: Failed to create a DirectDraw object for hooking: " << Compat::hex(result); + LOG_INFO << "ERROR: Failed to create a DirectDraw object for hooking: " << Compat::hex(result); return; } @@ -91,7 +91,7 @@ namespace nullptr, reinterpret_cast(&dd7.getRef()), IID_IDirectDraw7, nullptr); if (FAILED(result)) { - Compat::Log() << "ERROR: Failed to create a DirectDraw object for hooking: " << Compat::hex(result); + LOG_INFO << "ERROR: Failed to create a DirectDraw object for hooking: " << Compat::hex(result); return; } @@ -104,19 +104,19 @@ namespace } if (FAILED(result)) { - Compat::Log() << "ERROR: Failed to set the cooperative level for hooking: " << Compat::hex(result); + LOG_INFO << "ERROR: Failed to set the cooperative level for hooking: " << Compat::hex(result); return; } - Compat::Log() << "Installing DirectDraw hooks"; + LOG_INFO << "Installing DirectDraw hooks"; DDraw::installHooks(dd7); - Compat::Log() << "Installing Direct3D hooks"; + LOG_INFO << "Installing Direct3D hooks"; Direct3d::installHooks(dd, dd7); - Compat::Log() << "Installing GDI hooks"; + LOG_INFO << "Installing GDI hooks"; Gdi::installHooks(); Compat::closeDbgEng(); Gdi::GuiThread::start(); - Compat::Log() << "Finished installing hooks"; + LOG_INFO << "Finished installing hooks"; isAlreadyInstalled = true; } } @@ -143,7 +143,7 @@ namespace void printEnvironmentVariable(const char* var) { - Compat::Log() << "Environment variable " << var << " = \"" << Dll::getEnvVar(var) << '"'; + LOG_INFO << "Environment variable " << var << " = \"" << Dll::getEnvVar(var) << '"'; } void setDpiAwareness() @@ -189,26 +189,26 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) } auto processPath(Compat::getModulePath(nullptr)); - Compat::Log::initLogging(processPath); - Compat::Log() << "Process path: " << processPath.u8string(); + LOG_INFO << "Process path: " << processPath.u8string(); auto currentDllPath(Compat::getModulePath(hinstDLL)); - Compat::Log() << "Loading DDrawCompat " << (lpvReserved ? "statically" : "dynamically") << " from " << currentDllPath.u8string(); + LOG_INFO << "Loading DDrawCompat " << (lpvReserved ? "statically" : "dynamically") << " from " << currentDllPath.u8string(); printEnvironmentVariable("__COMPAT_LAYER"); Config::Parser::loadAllConfigFiles(processPath); + Compat::Log::initLogging(processPath, Config::logLevel.get()); auto systemPath(Compat::getSystemPath()); if (Compat::isEqual(currentDllPath.parent_path(), systemPath)) { - Compat::Log() << "DDrawCompat cannot be installed in the Windows system directory"; + LOG_INFO << "DDrawCompat cannot be installed in the Windows system directory"; return FALSE; } Dll::g_origDDrawModule = LoadLibraryW((systemPath / "ddraw.dll").c_str()); if (!Dll::g_origDDrawModule) { - Compat::Log() << "ERROR: Failed to load system ddraw.dll from " << systemPath.u8string(); + LOG_INFO << "ERROR: Failed to load system ddraw.dll from " << systemPath.u8string(); return FALSE; } @@ -247,11 +247,11 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) CALL_ORIG_PROC(SetAppCompatData)(disableMaxWindowedMode, 0); } - Compat::Log() << "DDrawCompat loaded successfully"; + LOG_INFO << "DDrawCompat loaded successfully"; } else if (fdwReason == DLL_PROCESS_DETACH) { - Compat::Log() << "DDrawCompat detached successfully"; + LOG_INFO << "DDrawCompat detached successfully"; } else if (fdwReason == DLL_THREAD_DETACH) { diff --git a/DDrawCompat/Gdi/DcFunctions.cpp b/DDrawCompat/Gdi/DcFunctions.cpp index 39f22df..0664cf9 100644 --- a/DDrawCompat/Gdi/DcFunctions.cpp +++ b/DDrawCompat/Gdi/DcFunctions.cpp @@ -323,20 +323,14 @@ namespace template void hookGdiDcFunction(const char* moduleName, const char* funcName) { -#ifdef DEBUGLOGS g_funcName = funcName; -#endif - Compat::hookFunction(moduleName, funcName, &compatGdiDcFunc); } template void hookGdiTextDcFunction(const char* moduleName, const char* funcName) { -#ifdef DEBUGLOGS g_funcName = funcName; -#endif - Compat::hookFunction(moduleName, funcName, &compatGdiTextDcFunc); } diff --git a/DDrawCompat/Gdi/GuiThread.cpp b/DDrawCompat/Gdi/GuiThread.cpp index a024389..ef42928 100644 --- a/DDrawCompat/Gdi/GuiThread.cpp +++ b/DDrawCompat/Gdi/GuiThread.cpp @@ -72,7 +72,7 @@ namespace "DDrawCompatMessageWindow", nullptr, 0, 0, 0, 0, 0, HWND_MESSAGE, nullptr, nullptr, nullptr); if (!g_messageWindow) { - Compat::Log() << "ERROR: Failed to create a message-only window"; + LOG_INFO << "ERROR: Failed to create a message-only window"; return 0; } diff --git a/DDrawCompat/Gdi/Icon.cpp b/DDrawCompat/Gdi/Icon.cpp index e8adbd8..a22cb96 100644 --- a/DDrawCompat/Gdi/Icon.cpp +++ b/DDrawCompat/Gdi/Icon.cpp @@ -51,10 +51,7 @@ namespace template void hookIconFunc(const char* moduleName, const char* funcName) { -#ifdef DEBUGLOGS g_funcName = funcName; -#endif - Compat::hookFunction(moduleName, funcName, &iconFunc); } diff --git a/DDrawCompat/Gdi/User32WndProcs.cpp b/DDrawCompat/Gdi/User32WndProcs.cpp index 02d7cfd..5988286 100644 --- a/DDrawCompat/Gdi/User32WndProcs.cpp +++ b/DDrawCompat/Gdi/User32WndProcs.cpp @@ -378,7 +378,7 @@ namespace HMODULE module = Compat::getModuleHandleFromAddress(wndProc); if (module != GetModuleHandle("ntdll") && module != GetModuleHandle("user32")) { - Compat::Log() << "Failed to hook a user32 window procedure: " << className; + LOG_INFO << "Failed to hook a user32 window procedure: " << className; return; } diff --git a/DDrawCompat/Win32/Thread.cpp b/DDrawCompat/Win32/Thread.cpp index d931cb4..38c6d7f 100644 --- a/DDrawCompat/Win32/Thread.cpp +++ b/DDrawCompat/Win32/Thread.cpp @@ -54,7 +54,7 @@ namespace Win32 if (0 == cpuAffinity || !CALL_ORIG_FUNC(SetProcessAffinityMask)(GetCurrentProcess(), cpuAffinity)) { - Compat::Log() << (0 == cpuAffinity ? "Invalid" : "Failed to set") << " CPU affinity, falling back to default"; + LOG_INFO << (0 == cpuAffinity ? "Invalid" : "Failed to set") << " CPU affinity, falling back to default"; Config::cpuAffinity.reset(); CALL_ORIG_FUNC(SetProcessAffinityMask)(GetCurrentProcess(), Config::cpuAffinity.get()); }