mirror of
https://github.com/narzoul/DDrawCompat
synced 2024-12-30 08:55:36 +01:00
Added critical section to all user-mode display driver functions
Fixes crashes and frozen screen issues in Laghaim Online (issue #58)
This commit is contained in:
parent
a49a19c448
commit
6aaf12b0a4
@ -6,6 +6,7 @@
|
|||||||
#include "Common/Log.h"
|
#include "Common/Log.h"
|
||||||
#include "Common/VtableVisitor.h"
|
#include "Common/VtableVisitor.h"
|
||||||
#include "Config/Config.h"
|
#include "Config/Config.h"
|
||||||
|
#include "D3dDdi/ScopedCriticalSection.h"
|
||||||
|
|
||||||
namespace D3dDdi
|
namespace D3dDdi
|
||||||
{
|
{
|
||||||
@ -31,6 +32,35 @@ namespace D3dDdi
|
|||||||
static Vtable*& s_origVtablePtr;
|
static Vtable*& s_origVtablePtr;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
template <int instanceId>
|
||||||
|
class Visitor
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Visitor(Vtable& compatVtable)
|
||||||
|
: m_compatVtable(compatVtable)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename MemberDataPtr, MemberDataPtr ptr>
|
||||||
|
void visit(const char* /*funcName*/)
|
||||||
|
{
|
||||||
|
if (!(m_compatVtable.*ptr))
|
||||||
|
{
|
||||||
|
m_compatVtable.*ptr = &threadSafeFunc<MemberDataPtr, ptr>;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
template <typename MemberDataPtr, MemberDataPtr ptr, typename Result, typename... Params>
|
||||||
|
static Result APIENTRY threadSafeFunc(Params... params)
|
||||||
|
{
|
||||||
|
D3dDdi::ScopedCriticalSection lock;
|
||||||
|
return (CompatVtableInstance<Vtable, instanceId>::s_origVtable.*ptr)(params...);
|
||||||
|
}
|
||||||
|
|
||||||
|
Vtable& m_compatVtable;
|
||||||
|
};
|
||||||
|
|
||||||
template <int instanceId> struct InstanceId {};
|
template <int instanceId> struct InstanceId {};
|
||||||
|
|
||||||
template <int instanceId>
|
template <int instanceId>
|
||||||
@ -45,6 +75,11 @@ namespace D3dDdi
|
|||||||
Vtable compatVtable = {};
|
Vtable compatVtable = {};
|
||||||
Compat::setCompatVtable(compatVtable);
|
Compat::setCompatVtable(compatVtable);
|
||||||
|
|
||||||
|
#ifndef DEBUGLOGS
|
||||||
|
Visitor<instanceId> visitor(compatVtable);
|
||||||
|
forEach<Vtable>(visitor);
|
||||||
|
#endif
|
||||||
|
|
||||||
isHooked = true;
|
isHooked = true;
|
||||||
CompatVtableInstance<Vtable, instanceId>::hookVtable(vtable, compatVtable);
|
CompatVtableInstance<Vtable, instanceId>::hookVtable(vtable, compatVtable);
|
||||||
return CompatVtableInstance<Vtable, instanceId>::s_origVtable;
|
return CompatVtableInstance<Vtable, instanceId>::s_origVtable;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user