aboutsummaryrefslogtreecommitdiff
path: root/NorthstarDLL/plugins/pluginbackend.cpp
blob: b442d702d488217298d96c6b2facaa0dc7b99b22 (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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#include "pch.h"
#include "pluginbackend.h"
#include "plugin_abi.h"
#include "server/serverpresence.h"
#include "masterserver/masterserver.h"
#include "squirrel/squirrel.h"
#include "plugins.h"

#include "core/convar/concommand.h"

#define EXPORT extern "C" __declspec(dllexport)

AUTOHOOK_INIT()

PluginCommunicationHandler* g_pPluginCommunicationhandler;

static PluginDataRequest storedRequest {PluginDataRequestType::END, (PluginRespondDataCallable) nullptr};

void init_plugincommunicationhandler()
{
	g_pPluginCommunicationhandler = new PluginCommunicationHandler;
	g_pPluginCommunicationhandler->requestQueue = {};
}

void PluginCommunicationHandler::RunFrame()
{
	std::lock_guard<std::mutex> lock(requestMutex);
	if (!requestQueue.empty())
	{
		storedRequest = requestQueue.front();
		switch (storedRequest.type)
		{
		default:
			spdlog::error("{} was called with invalid request type '{}'", __FUNCTION__, static_cast<int>(storedRequest.type));
		}
		requestQueue.pop();
	}
}

void PluginCommunicationHandler::PushRequest(PluginDataRequestType type, PluginRespondDataCallable func)
{
	std::lock_guard<std::mutex> lock(requestMutex);
	requestQueue.push(PluginDataRequest {type, func});
}

void PluginCommunicationHandler::GeneratePresenceObjects()
{
	PluginGameStatePresence presence {};

	presence.id = g_pGameStatePresence->id.c_str();
	presence.name = g_pGameStatePresence->name.c_str();
	presence.description = g_pGameStatePresence->description.c_str();
	presence.password = g_pGameStatePresence->password.c_str();

	presence.isServer = g_pGameStatePresence->isServer;
	presence.isLocal = g_pGameStatePresence->isLocal;

	if (g_pGameStatePresence->isLoading)
		presence.state = GameState::LOADING;
	else if (g_pGameStatePresence->uiMap == "")
		presence.state = GameState::MAINMENU;
	else if (g_pGameStatePresence->map == "mp_lobby" && g_pGameStatePresence->isLocal && g_pGameStatePresence->isLobby)
		presence.state = GameState::LOBBY;
	else
		presence.state = GameState::INGAME;

	presence.map = g_pGameStatePresence->map.c_str();
	presence.mapDisplayname = g_pGameStatePresence->mapDisplayname.c_str();
	presence.playlist = g_pGameStatePresence->playlist.c_str();
	presence.playlistDisplayname = g_pGameStatePresence->playlistDisplayname.c_str();

	presence.currentPlayers = g_pGameStatePresence->currentPlayers;
	presence.maxPlayers = g_pGameStatePresence->maxPlayers;
	presence.ownScore = g_pGameStatePresence->ownScore;
	presence.otherHighestScore = g_pGameStatePresence->otherHighestScore;
	presence.maxScore = g_pGameStatePresence->maxScore;
	presence.timestampEnd = g_pGameStatePresence->timestampEnd;
	g_pPluginManager->PushPresence(&presence);
}

ON_DLL_LOAD_RELIESON("engine.dll", PluginBackendEngine, ConCommand, (CModule module))
{
	g_pPluginManager->InformDLLLoad(PluginLoadDLL::ENGINE, &g_pPluginCommunicationhandler->m_sEngineData);
}

ON_DLL_LOAD_RELIESON("client.dll", PluginBackendClient, ConCommand, (CModule module))
{
	g_pPluginManager->InformDLLLoad(PluginLoadDLL::CLIENT, nullptr);
}

ON_DLL_LOAD_RELIESON("server.dll", PluginBackendServer, ConCommand, (CModule module))
{
	g_pPluginManager->InformDLLLoad(PluginLoadDLL::SERVER, nullptr);
}