diff --git a/DDrawCompat/CompatVtable.h b/DDrawCompat/CompatVtable.h index c81e2de..f34de6b 100644 --- a/DDrawCompat/CompatVtable.h +++ b/DDrawCompat/CompatVtable.h @@ -59,18 +59,11 @@ private: { public: template - void visit(const std::string& vtableTypeName, const std::string& funcName) + void visit() { - s_funcNames[getKey()] = vtableTypeName + "::" + funcName; - if (!(s_compatVtable.*ptr)) { -#ifdef _DEBUG - s_threadSafeVtable.*ptr = getThreadSafeFuncPtr(s_compatVtable.*ptr); - hookMethod(reinterpret_cast(s_origVtable.*ptr), s_threadSafeVtable.*ptr); -#else s_threadSafeVtable.*ptr = s_origVtable.*ptr; -#endif s_compatVtable.*ptr = s_origVtable.*ptr; } else @@ -80,6 +73,20 @@ private: } } + template + void visitDebug(const std::string& vtableTypeName, const std::string& funcName) + { + s_funcNames[getKey()] = vtableTypeName + "::" + funcName; + + s_threadSafeVtable.*ptr = getThreadSafeFuncPtr(s_compatVtable.*ptr); + hookMethod(reinterpret_cast(s_origVtable.*ptr), s_threadSafeVtable.*ptr); + + if (!(s_compatVtable.*ptr)) + { + s_compatVtable.*ptr = s_origVtable.*ptr; + } + } + private: template using FuncPtr = Result(STDMETHODCALLTYPE *)(Params...); @@ -121,7 +128,9 @@ private: static Result STDMETHODCALLTYPE threadSafeFunc(IntfPtr This, Params... params) { Compat::origProcs.AcquireDDThreadLock(); +#ifdef _DEBUG Compat::LogEnter(s_funcNames[getKey()].c_str(), This, params...); +#endif Result result; auto it = s_vtablePtrToCompatVtable.find(This->lpVtbl); @@ -135,7 +144,9 @@ private: result = (s_origVtable.*ptr)(This, params...); } +#ifdef _DEBUG Compat::LogLeave(s_funcNames[getKey()].c_str(), This, params...) << result; +#endif Compat::origProcs.ReleaseDDThreadLock(); return result; } diff --git a/DDrawCompat/DDrawVtableVisitor.h b/DDrawCompat/DDrawVtableVisitor.h index 8822d5c..485eb4a 100644 --- a/DDrawCompat/DDrawVtableVisitor.h +++ b/DDrawCompat/DDrawVtableVisitor.h @@ -25,8 +25,13 @@ std::string getTypeName() return typeName; } +#ifdef _DEBUG #define DD_VISIT(member) \ - visitor.visit(getTypeName(), #member) + visitor.visitDebug(getTypeName(), #member) +#else +#define DD_VISIT(member) \ + visitor.visit() +#endif template <> struct DDrawVtableForEach