aboutsummaryrefslogtreecommitdiff
path: root/NorthstarDedicatedTest/host.cpp
blob: 624809b5da2e86b6e52c502ba422629d7a89be95 (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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include "pch.h"
#include "host.h"
#include "convar.h"
#include "modmanager.h"
#include "gameutils.h"
#include "commandprint.h"
#include "mapsprint.h"

typedef void (*Host_InitType)(bool bDedicated);
Host_InitType Host_Init;
void Host_InitHook(bool bDedicated) 
{
	Host_Init(bDedicated);

	// get all mod convars
	std::vector<std::string> vModConvarNames;
	for (auto& mod : g_pModManager->m_loadedMods)
		for (auto& cvar : mod.ConVars)
			vModConvarNames.push_back(cvar->Name);

	// strip hidden and devonly cvar flags
	int iCvarsAltered = 0;
	for (auto& pair : g_pCVar->DumpToMap())
	{
		// don't remove from mod cvars
		if (std::find(vModConvarNames.begin(), vModConvarNames.end(), pair.second->m_pszName) != vModConvarNames.end())
			continue;

		// strip flags
		int flags = pair.second->GetFlags();
		if (flags & FCVAR_DEVELOPMENTONLY)
		{
			flags &= ~FCVAR_DEVELOPMENTONLY;
			iCvarsAltered++;
		}

		if (flags & FCVAR_HIDDEN)
		{
			flags &= ~FCVAR_HIDDEN;
			iCvarsAltered++;
		}

		pair.second->m_nFlags = flags;
	}

	spdlog::info("Removed {} hidden/devonly cvar flags", iCvarsAltered);

	// make servers able to run disconnect on clients
	g_pCVar->FindCommand("disconnect")->m_nFlags |= FCVAR_SERVER_CAN_EXECUTE;

	// need to initialise these after host_init since they do stuff to preexisting concommands/convars
	InitialiseCommandPrint();
	InitialiseMapsPrint();

	// run client autoexec if on client
	if (!bDedicated)
		Cbuf_AddText(Cbuf_GetCurrentPlayer(), "exec autoexec_ns_client", cmd_source_t::kCommandSrcCode);
}

ON_DLL_LOAD("engine.dll", Host_Init, [](HMODULE baseAddress)
{ 
	HookEnabler hook;
	ENABLER_CREATEHOOK(hook, (char*)baseAddress + 0x155EA0, &Host_InitHook, reinterpret_cast<LPVOID*>(&Host_Init));
})