Singleton checks and guid adaptation.

This commit is contained in:
momo5502 2015-12-27 20:05:43 +01:00
parent 044e937781
commit 55c9ddb63b
7 changed files with 65 additions and 6 deletions

View File

@ -6,6 +6,8 @@ namespace Components
void Loader::Initialize()
{
Loader::Register(new Dedicated());
Loader::Register(new Dvar());
Loader::Register(new Maps());
Loader::Register(new Menus());
@ -18,9 +20,9 @@ namespace Components
Loader::Register(new Network());
Loader::Register(new RawFiles());
Loader::Register(new Renderer());
Loader::Register(new Dedicated());
Loader::Register(new FastFiles());
Loader::Register(new Materials());
Loader::Register(new Singleton());
Loader::Register(new FileSystem());
Loader::Register(new QuickPatch());
Loader::Register(new AssetHandler());

View File

@ -35,6 +35,7 @@ namespace Components
#include "Dedicated.hpp"
#include "FastFiles.hpp"
#include "Materials.hpp"
#include "Singleton.hpp"
#include "FileSystem.hpp"
#include "QuickPatch.hpp"
#include "AssetHandler.hpp"

View File

@ -0,0 +1,23 @@
#include "..\STDInclude.hpp"
namespace Components
{
bool Singleton::FirstInstance = true;
bool Singleton::IsFirstInstance()
{
return Singleton::FirstInstance;
}
Singleton::Singleton()
{
if (Dedicated::IsDedicated()) return;
Singleton::FirstInstance = !(CreateMutex(NULL, FALSE, "iw4x_mutex") && GetLastError() == ERROR_ALREADY_EXISTS);
if (!Singleton::FirstInstance && MessageBoxA(0, "Do you want to start a second instance?", "Game already running", MB_ICONEXCLAMATION | MB_YESNO) == IDNO)
{
ExitProcess(0);
}
}
}

View File

@ -0,0 +1,14 @@
namespace Components
{
class Singleton : public Component
{
public:
Singleton();
const char* GetName() { return "Singleton"; };
static bool IsFirstInstance();
private:
static bool FirstInstance;
};
}

View File

@ -20,13 +20,24 @@ namespace Steam
if (!subId)
{
DATA_BLOB Data[2];
Data[0].pbData = (BYTE *)"AAAAAAAAAA";
Data[0].cbData = 10;
if (Components::Dedicated::IsDedicated())
{
subId = 0xDED1CADE;
}
else if (Components::Singleton::IsFirstInstance())
{
DATA_BLOB Data[2];
Data[0].pbData = (BYTE *)"AAAAAAAAAA";
Data[0].cbData = 10;
CryptProtectData(&Data[0], NULL, NULL, NULL, NULL, CRYPTPROTECT_LOCAL_MACHINE, &Data[1]);
CryptProtectData(&Data[0], NULL, NULL, NULL, NULL, CRYPTPROTECT_LOCAL_MACHINE, &Data[1]);
subId = /*::Utils::OneAtATime((char*)Data[1].pbData, 52); */(Game::Com_Milliseconds() + timeGetTime());
subId = ::Utils::OneAtATime((char*)Data[1].pbData, 52);
}
else
{
subId = (Game::Com_Milliseconds() + timeGetTime());
}
}
id.Bits = 0x110000100000000 | subId;

View File

@ -72,6 +72,7 @@
<ClInclude Include="Components\QuickPatch.hpp" />
<ClInclude Include="Components\RawFiles.hpp" />
<ClInclude Include="Components\Renderer.hpp" />
<ClInclude Include="Components\Singleton.hpp" />
<ClInclude Include="Components\Window.hpp" />
<ClInclude Include="Game\Functions.hpp" />
<ClInclude Include="Game\Structs.hpp" />
@ -109,6 +110,7 @@
<ClCompile Include="Components\QuickPatch.cpp" />
<ClCompile Include="Components\RawFiles.cpp" />
<ClCompile Include="Components\Renderer.cpp" />
<ClCompile Include="Components\Singleton.cpp" />
<ClCompile Include="Components\Window.cpp" />
<ClCompile Include="Game\Functions.cpp" />
<ClCompile Include="Steam\Interfaces\SteamFriends.cpp" />

View File

@ -131,6 +131,9 @@
<ClCompile Include="Components\Dedicated.cpp">
<Filter>Source\Components\Modules</Filter>
</ClCompile>
<ClCompile Include="Components\Singleton.cpp">
<Filter>Source\Components\Modules</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="Steam\Interfaces\SteamUser.hpp">
@ -238,5 +241,8 @@
<ClInclude Include="Components\Dedicated.hpp">
<Filter>Source\Components\Modules</Filter>
</ClInclude>
<ClInclude Include="Components\Singleton.hpp">
<Filter>Source\Components\Modules</Filter>
</ClInclude>
</ItemGroup>
</Project>