Skip to content

Commit

Permalink
Remove owner mutex
Browse files Browse the repository at this point in the history
  • Loading branch information
psiberx committed Jan 18, 2024
1 parent 91bf2ba commit b7c2dd4
Showing 1 changed file with 9 additions and 30 deletions.
39 changes: 9 additions & 30 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@
#include "App/Project.hpp"
#include "Core/Facades/Hook.hpp"
#include "Core/Facades/Runtime.hpp"
#include "Core/Runtime/OwnerMutex.hpp"
#include "Red/Addresses.hpp"

namespace
{
Core::UniquePtr<App::Application> g_app;
Core::UniquePtr<Core::OwnerMutex> g_mutex;
}

// RED4ext
Expand All @@ -20,25 +18,14 @@ RED4EXT_C_EXPORT bool RED4EXT_CALL Main(RED4ext::PluginHandle aHandle, RED4ext::
{
case RED4ext::EMainReason::Load:
{
g_mutex = Core::MakeUnique<Core::OwnerMutex>(App::Project::Name);

if (g_mutex->Obtain())
{
g_app = Core::MakeUnique<App::Application>(aHandle, aSdk);
g_app->Bootstrap();
}
g_app = Core::MakeUnique<App::Application>(aHandle, aSdk);
g_app->Bootstrap();
break;
}
case RED4ext::EMainReason::Unload:
{
if (g_mutex->IsOwner())
{
g_app->Shutdown();
g_app = nullptr;

g_mutex->Release();
g_mutex = nullptr;
}
g_app->Shutdown();
g_app = nullptr;
break;
}
}
Expand Down Expand Up @@ -80,28 +67,20 @@ BOOL APIENTRY DllMain(HMODULE aHandle, DWORD aReason, LPVOID)

if (s_isGame && s_isASI)
{
g_mutex = Core::MakeUnique<Core::OwnerMutex>(App::Project::Name);

if (g_mutex->Obtain())
{
g_app = Core::MakeUnique<App::Application>(aHandle);
g_app = Core::MakeUnique<App::Application>(aHandle);

Core::Hook::Before<GameMain>(+[]() {
g_app->Bootstrap();
});
}
Core::Hook::Before<GameMain>(+[]() {
g_app->Bootstrap();
});
}
break;
}
case DLL_PROCESS_DETACH:
{
if (s_isGame && s_isASI && g_mutex->IsOwner())
if (s_isGame && s_isASI)
{
g_app->Shutdown();
g_app = nullptr;

g_mutex->Release();
g_mutex = nullptr;
}
break;
}
Expand Down

0 comments on commit b7c2dd4

Please sign in to comment.