aboutsummaryrefslogtreecommitdiff
path: root/NorthstarDLL/core/tier0.cpp
blob: 167093842b56d64ac0b61992e6dac8655983cf5d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include "tier0.h"

// use the Tier0 namespace for tier0 funcs
namespace Tier0
{
	IMemAlloc* g_pMemAllocSingleton = nullptr;

	ErrorType Error;
	CommandLineType CommandLine;
	Plat_FloatTimeType Plat_FloatTime;
	ThreadInServerFrameThreadType ThreadInServerFrameThread;
} // namespace Tier0

typedef Tier0::IMemAlloc* (*CreateGlobalMemAllocType)();
CreateGlobalMemAllocType CreateGlobalMemAlloc;

// needs to be a seperate function, since memalloc.cpp calls it
void TryCreateGlobalMemAlloc()
{
	// init memalloc stuff
	CreateGlobalMemAlloc =
		reinterpret_cast<CreateGlobalMemAllocType>(GetProcAddress(GetModuleHandleA("tier0.dll"), "CreateGlobalMemAlloc"));
	Tier0::g_pMemAllocSingleton = CreateGlobalMemAlloc(); // if it already exists, this returns the preexisting IMemAlloc instance
}

ON_DLL_LOAD("tier0.dll", Tier0GameFuncs, (CModule module))
{
	// shouldn't be necessary, but do this just in case
	TryCreateGlobalMemAlloc();

	// setup tier0 funcs
	Tier0::Error = module.GetExport("Error").RCast<Tier0::ErrorType>();
	Tier0::CommandLine = module.GetExport("CommandLine").RCast<Tier0::CommandLineType>();
	Tier0::Plat_FloatTime = module.GetExport("Plat_FloatTime").RCast<Tier0::Plat_FloatTimeType>();
	Tier0::ThreadInServerFrameThread = module.GetExport("ThreadInServerFrameThread").RCast<Tier0::ThreadInServerFrameThreadType>();
}