[Events]: User modern concurrency container (#1042)

This commit is contained in:
Edo 2023-05-15 23:27:37 +01:00 committed by GitHub
parent d0bb7840cb
commit 57d04e5a59
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
32 changed files with 323 additions and 216 deletions

2
.gitmodules vendored
View File

@ -17,7 +17,7 @@
[submodule "deps/mongoose"]
path = deps/mongoose
url = https://github.com/cesanta/mongoose.git
branch = 7.8
branch = 7.9
[submodule "deps/protobuf"]
path = deps/protobuf
url = https://github.com/google/protobuf.git

2
deps/mongoose vendored

@ -1 +1 @@
Subproject commit 0a265e79a67d7bfcdca27f2ccb98ccb474677ec6
Subproject commit 4236405b90e051310aadda818e21c811e404b4d8

View File

@ -21,6 +21,7 @@
#include "Modules/Discovery.hpp"
#include "Modules/Download.hpp"
#include "Modules/Elevators.hpp"
#include "Modules/Events.hpp"
#include "Modules/Exception.hpp"
#include "Modules/FastFiles.hpp"
#include "Modules/Friends.hpp"

View File

@ -73,7 +73,6 @@ namespace Components
#include "Modules/AssetHandler.hpp"
#include "Modules/Dedicated.hpp"
#include "Modules/Events.hpp"
#include "Modules/FileSystem.hpp"
#include "Modules/Localization.hpp"
#include "Modules/Maps.hpp"

View File

@ -1,5 +1,6 @@
#include <STDInclude.hpp>
#include "Bans.hpp"
#include "Events.hpp"
namespace Components
{

View File

@ -2,6 +2,7 @@
#include "Bots.hpp"
#include "ClanTags.hpp"
#include "Events.hpp"
#include "GSC/Script.hpp"

View File

@ -1,5 +1,6 @@
#include <STDInclude.hpp>
#include "CardTitles.hpp"
#include "Events.hpp"
#include "ServerCommands.hpp"
namespace Components

View File

@ -1,5 +1,6 @@
#include <STDInclude.hpp>
#include "Chat.hpp"
#include "Events.hpp"
#include "PlayerName.hpp"
#include "TextRenderer.hpp"
#include "Voice.hpp"

View File

@ -1,5 +1,7 @@
#include <STDInclude.hpp>
#include "ClanTags.hpp"
#include "Events.hpp"
#include "PlayerName.hpp"
#include "ServerCommands.hpp"

View File

@ -1,5 +1,6 @@
#include <STDInclude.hpp>
#include "Debug.hpp"
#include "Events.hpp"
#include "TextRenderer.hpp"
#include "Game/Engine/ScopedCriticalSection.hpp"

View File

@ -3,6 +3,7 @@
#include "CardTitles.hpp"
#include "ClanTags.hpp"
#include "Events.hpp"
#include "Party.hpp"
#include "ServerCommands.hpp"

View File

@ -3,6 +3,7 @@
#include <Utils/WebIO.hpp>
#include "Download.hpp"
#include "Events.hpp"
#include "MapRotation.hpp"
#include "Party.hpp"
#include "ServerInfo.hpp"

View File

@ -1,5 +1,7 @@
#include <STDInclude.hpp>
#include "Elevators.hpp"
#include "Events.hpp"
namespace Components
{

View File

@ -1,54 +1,79 @@
#include <STDInclude.hpp>
#include "Events.hpp"
namespace Components
{
Utils::Signal<Events::ClientCallback> Events::ClientDisconnectSignal;
Utils::Signal<Events::ClientConnectCallback> Events::ClientConnectSignal;
Utils::Signal<Events::Callback> Events::SteamDisconnectSignal;
Utils::Signal<Events::Callback> Events::ShutdownSystemSignal;
Utils::Signal<Events::Callback> Events::ClientInitSignal;
Utils::Signal<Events::Callback> Events::ServerInitSignal;
Utils::Signal<Events::Callback> Events::DvarInitSignal;
Utils::Signal<Events::Callback> Events::NetworkInitSignal;
Utils::Concurrency::Container<Events::ClientCallback> Events::ClientDisconnectTasks_;
Utils::Concurrency::Container<Events::ClientConnectCallback> Events::ClientConnectTasks_;
Utils::Concurrency::Container<Events::Callback> Events::SteamDisconnectTasks_;
Utils::Concurrency::Container<Events::Callback> Events::ShutdownSystemTasks_;
Utils::Concurrency::Container<Events::Callback> Events::ClientInitTasks_;
Utils::Concurrency::Container<Events::Callback> Events::ServerInitTasks_;
Utils::Concurrency::Container<Events::Callback> Events::DvarInitTasks_;
Utils::Concurrency::Container<Events::Callback> Events::NetworkInitTasks_;
void Events::OnClientDisconnect(const Utils::Slot<ClientCallback>& callback)
void Events::OnClientDisconnect(const std::function<void(int clientNum)>& callback)
{
ClientDisconnectSignal.connect(callback);
ClientDisconnectTasks_.access([&callback](ClientCallback& tasks)
{
tasks.emplace_back(callback);
});
}
void Events::OnClientConnect(const Utils::Slot<ClientConnectCallback>& callback)
void Events::OnClientConnect(const std::function<void(Game::client_s* cl)>& callback)
{
ClientConnectSignal.connect(callback);
ClientConnectTasks_.access([&callback](ClientConnectCallback& tasks)
{
tasks.emplace_back(callback);
});
}
void Events::OnSteamDisconnect(const Utils::Slot<Callback>& callback)
void Events::OnSteamDisconnect(const std::function<void()>& callback)
{
SteamDisconnectSignal.connect(callback);
SteamDisconnectTasks_.access([&callback](Callback& tasks)
{
tasks.emplace_back(callback);
});
}
void Events::OnVMShutdown(const Utils::Slot<Callback>& callback)
void Events::OnVMShutdown(const std::function<void()>& callback)
{
ShutdownSystemSignal.connect(callback);
ShutdownSystemTasks_.access([&callback](Callback& tasks)
{
tasks.emplace_back(callback);
});
}
void Events::OnClientInit(const Utils::Slot<Callback>& callback)
void Events::OnClientInit(const std::function<void()>& callback)
{
ClientInitSignal.connect(callback);
ClientInitTasks_.access([&callback](Callback& tasks)
{
tasks.emplace_back(callback);
});
}
void Events::OnSVInit(const Utils::Slot<Callback>& callback)
void Events::OnSVInit(const std::function<void()>& callback)
{
ServerInitSignal.connect(callback);
ServerInitTasks_.access([&callback](Callback& tasks)
{
tasks.emplace_back(callback);
});
}
void Events::OnDvarInit(const Utils::Slot<Callback>& callback)
void Events::OnDvarInit(const std::function<void()>& callback)
{
DvarInitSignal.connect(callback);
DvarInitTasks_.access([&callback](Callback& tasks)
{
tasks.emplace_back(callback);
});
}
void Events::OnNetworkInit(const Utils::Slot<Callback>& callback)
void Events::OnNetworkInit(const std::function<void()>& callback)
{
NetworkInitSignal.connect(callback);
NetworkInitTasks_.access([&callback](Callback& tasks)
{
tasks.emplace_back(callback);
});
}
/*
@ -57,60 +82,112 @@ namespace Components
*/
void Events::ClientDisconnect_Hk(const int clientNum)
{
ClientDisconnectSignal(clientNum);
ClientDisconnectTasks_.access([&clientNum](ClientCallback& tasks)
{
for (const auto& func : tasks)
{
func(clientNum);
}
});
Utils::Hook::Call<void(int)>(0x4AA430)(clientNum); // ClientDisconnect
}
void Events::SV_UserinfoChanged_Hk(Game::client_s* cl)
{
ClientConnectSignal(cl);
ClientConnectTasks_.access([&cl](ClientConnectCallback& tasks)
{
for (const auto& func : tasks)
{
func(cl);
}
});
Utils::Hook::Call<void(Game::client_s*)>(0x401950)(cl); // SV_UserinfoChanged
}
void Events::SteamDisconnect_Hk()
{
SteamDisconnectSignal();
SteamDisconnectTasks_.access([](Callback& tasks)
{
for (const auto& func : tasks)
{
func();
}
});
Utils::Hook::Call<void()>(0x467CC0)(); // LiveSteam_Client_SteamDisconnect
}
void Events::Scr_ShutdownSystem_Hk(unsigned char sys)
{
ShutdownSystemSignal();
ShutdownSystemTasks_.access([](Callback& tasks)
{
for (const auto& func : tasks)
{
func();
}
});
Utils::Hook::Call<void(unsigned char)>(0x421EE0)(sys); // Scr_ShutdownSystem
}
void Events::CL_InitOnceForAllClients_HK()
{
ClientInitSignal();
ClientInitSignal.clear();
ClientInitTasks_.access([](Callback& tasks)
{
for (const auto& func : tasks)
{
func();
}
tasks = {}; // Only called once. Clear
});
Utils::Hook::Call<void()>(0x404CA0)(); // CL_InitOnceForAllClients
}
void Events::SV_Init_Hk()
{
ServerInitSignal();
ServerInitSignal.clear();
ServerInitTasks_.access([](Callback& tasks)
{
for (const auto& func : tasks)
{
func();
}
tasks = {}; // Only called once. Clear
});
Utils::Hook::Call<void()>(0x474320)(); // SV_InitGameMode
}
void Events::Com_InitDvars_Hk()
{
DvarInitSignal();
DvarInitSignal.clear();
DvarInitTasks_.access([](Callback& tasks)
{
for (const auto& func : tasks)
{
func();
}
tasks = {}; // Only called once. Clear
});
Utils::Hook::Call<void()>(0x60AD10)(); // Com_InitDvars
}
void Events::NetworkStart()
{
NetworkInitSignal();
NetworkInitSignal.clear();
NetworkInitTasks_.access([](Callback& tasks)
{
for (const auto& func : tasks)
{
func();
}
tasks = {}; // Only called once. Clear
});
}
__declspec(naked) void Events::NET_OpenSocks_Hk()

View File

@ -5,42 +5,42 @@ namespace Components
class Events : public Component
{
public:
typedef void(ClientCallback)(int clientNum);
typedef void(ClientConnectCallback)(Game::client_s* cl);
typedef void(Callback)();
using Callback = std::vector<std::function<void()>>;
using ClientConnectCallback = std::vector<std::function<void(Game::client_s* cl)>>;
using ClientCallback = std::vector<std::function<void(int clientNum)>>;
Events();
// Server side
static void OnClientDisconnect(const Utils::Slot<ClientCallback>& callback);
static void OnClientDisconnect(const std::function<void(int clientNum)>& callback);
// Server side
static void OnClientConnect(const Utils::Slot<ClientConnectCallback>& callback);
static void OnClientConnect(const std::function<void(Game::client_s* cl)>& callback);
// Client side
static void OnSteamDisconnect(const Utils::Slot<Callback>& callback);
static void OnSteamDisconnect(const std::function<void()>& callback);
static void OnVMShutdown(const Utils::Slot<Callback>& callback);
static void OnVMShutdown(const std::function<void()>& callback);
static void OnClientInit(const Utils::Slot<Callback>& callback);
static void OnClientInit(const std::function<void()>& callback);
// Client & Server (triggered once)
static void OnSVInit(const Utils::Slot<Callback>& callback);
static void OnSVInit(const std::function<void()>& callback);
// Client & Server (triggered once)
static void OnDvarInit(const Utils::Slot<Callback>& callback);
static void OnDvarInit(const std::function<void()>& callback);
static void OnNetworkInit(const Utils::Slot<Callback>& callback);
static void OnNetworkInit(const std::function<void()>& callback);
private:
static Utils::Signal<ClientCallback> ClientDisconnectSignal;
static Utils::Signal<ClientConnectCallback> ClientConnectSignal;
static Utils::Signal<Callback> SteamDisconnectSignal;
static Utils::Signal<Callback> ShutdownSystemSignal;
static Utils::Signal<Callback> ClientInitSignal;
static Utils::Signal<Callback> ServerInitSignal;
static Utils::Signal<Callback> DvarInitSignal;
static Utils::Signal<Callback> NetworkInitSignal;
static Utils::Concurrency::Container<ClientCallback> ClientDisconnectTasks_;
static Utils::Concurrency::Container<ClientConnectCallback> ClientConnectTasks_;
static Utils::Concurrency::Container<Callback> SteamDisconnectTasks_;
static Utils::Concurrency::Container<Callback> ShutdownSystemTasks_;
static Utils::Concurrency::Container<Callback> ClientInitTasks_;
static Utils::Concurrency::Container<Callback> ServerInitTasks_;
static Utils::Concurrency::Container<Callback> DvarInitTasks_;
static Utils::Concurrency::Container<Callback> NetworkInitTasks_;
static void ClientDisconnect_Hk(int clientNum);
static void SV_UserinfoChanged_Hk(Game::client_s* cl);

View File

@ -5,6 +5,7 @@
#include <proto/friends.pb.h>
#pragma warning(pop)
#include "Events.hpp"
#include "Friends.hpp"
#include "Materials.hpp"
#include "Node.hpp"

View File

@ -1,4 +1,7 @@
#include <STDInclude.hpp>
#include <Components/Modules/Events.hpp>
#include "IO.hpp"
#include "Script.hpp"

View File

@ -166,12 +166,12 @@ namespace Components::GSC
if (pName != nullptr)
{
const auto name = Utils::String::ToLower(*pName);
for (const auto& func : CustomScrFunctions)
for (const auto& funcs : CustomScrFunctions)
{
if (Utils::Contains(&func.aliases, name))
if (std::ranges::find(funcs.aliases, name) != funcs.aliases.end())
{
*type = func.type;
return func.actionFunc;
*type = funcs.type;
return funcs.actionFunc;
}
}
}
@ -193,12 +193,12 @@ namespace Components::GSC
if (pName != nullptr)
{
const auto name = Utils::String::ToLower(*pName);
for (const auto& meth : CustomScrMethods)
for (const auto& meths : CustomScrMethods)
{
if (Utils::Contains(&meth.aliases, name))
if (std::ranges::find(meths.aliases, name) != meths.aliases.end())
{
*type = meth.type;
return meth.actionFunc;
*type = meths.type;
return meths.actionFunc;
}
}
}

View File

@ -9,10 +9,10 @@ namespace Components::GSC
{
using namespace Utils::String;
int ScriptError::developer_;
int ScriptError::Developer_;
Game::scrParserGlob_t ScriptError::scrParserGlob;
Game::scrParserPub_t ScriptError::scrParserPub;
Game::scrParserGlob_t ScriptError::ScrParserGlob;
Game::scrParserPub_t ScriptError::ScrParserPub;
int ScriptError::Scr_IsInOpcodeMemory(const char* pos)
{
@ -27,7 +27,7 @@ namespace Components::GSC
Game::OpcodeLookup* opcodeLookup;
Game::SourceLookup* sourcePosLookup;
if (!developer_)
if (!Developer_)
{
return;
}
@ -48,83 +48,83 @@ namespace Components::GSC
type &= ~Game::SOURCE_TYPE_BREAKPOINT;
}
assert(scrParserGlob.opcodeLookup);
assert(scrParserGlob.sourcePosLookup);
assert(ScrParserGlob.opcodeLookup);
assert(ScrParserGlob.sourcePosLookup);
assert(Game::scrCompilePub->opcodePos);
auto size = sizeof(Game::OpcodeLookup) * (scrParserGlob.opcodeLookupLen + 1);
if (size > scrParserGlob.opcodeLookupMaxSize)
auto size = sizeof(Game::OpcodeLookup) * (ScrParserGlob.opcodeLookupLen + 1);
if (size > ScrParserGlob.opcodeLookupMaxSize)
{
if (scrParserGlob.opcodeLookupMaxSize >= Game::MAX_OPCODE_LOOKUP_SIZE)
if (ScrParserGlob.opcodeLookupMaxSize >= Game::MAX_OPCODE_LOOKUP_SIZE)
{
Game::Sys_Error("MAX_OPCODE_LOOKUP_SIZE exceeded");
}
Game::Z_VirtualCommit((char*)scrParserGlob.opcodeLookup + scrParserGlob.opcodeLookupMaxSize, 0x20000);
scrParserGlob.opcodeLookupMaxSize += 0x20000;
assert(size <= scrParserGlob.opcodeLookupMaxSize);
Game::Z_VirtualCommit((char*)ScrParserGlob.opcodeLookup + ScrParserGlob.opcodeLookupMaxSize, 0x20000);
ScrParserGlob.opcodeLookupMaxSize += 0x20000;
assert(size <= ScrParserGlob.opcodeLookupMaxSize);
}
size = sizeof(Game::SourceLookup) * (scrParserGlob.sourcePosLookupLen + 1);
if (size > scrParserGlob.sourcePosLookupMaxSize)
size = sizeof(Game::SourceLookup) * (ScrParserGlob.sourcePosLookupLen + 1);
if (size > ScrParserGlob.sourcePosLookupMaxSize)
{
if (scrParserGlob.sourcePosLookupMaxSize >= Game::MAX_SOURCEPOS_LOOKUP_SIZE)
if (ScrParserGlob.sourcePosLookupMaxSize >= Game::MAX_SOURCEPOS_LOOKUP_SIZE)
{
Game::Sys_Error("MAX_SOURCEPOS_LOOKUP_SIZE exceeded");
}
Game::Z_VirtualCommit((char*)scrParserGlob.sourcePosLookup + scrParserGlob.sourcePosLookupMaxSize, 0x20000);
scrParserGlob.sourcePosLookupMaxSize += 0x20000;
assert(size <= scrParserGlob.sourcePosLookupMaxSize);
Game::Z_VirtualCommit((char*)ScrParserGlob.sourcePosLookup + ScrParserGlob.sourcePosLookupMaxSize, 0x20000);
ScrParserGlob.sourcePosLookupMaxSize += 0x20000;
assert(size <= ScrParserGlob.sourcePosLookupMaxSize);
}
if (scrParserGlob.currentCodePos == Game::scrCompilePub->opcodePos)
if (ScrParserGlob.currentCodePos == Game::scrCompilePub->opcodePos)
{
assert(scrParserGlob.currentSourcePosCount);
--scrParserGlob.opcodeLookupLen;
opcodeLookup = &scrParserGlob.opcodeLookup[scrParserGlob.opcodeLookupLen];
assert(opcodeLookup->sourcePosIndex + scrParserGlob.currentSourcePosCount == scrParserGlob.sourcePosLookupLen);
assert(opcodeLookup->codePos == (char*)scrParserGlob.currentCodePos);
assert(ScrParserGlob.currentSourcePosCount);
--ScrParserGlob.opcodeLookupLen;
opcodeLookup = &ScrParserGlob.opcodeLookup[ScrParserGlob.opcodeLookupLen];
assert(opcodeLookup->sourcePosIndex + ScrParserGlob.currentSourcePosCount == ScrParserGlob.sourcePosLookupLen);
assert(opcodeLookup->codePos == (char*)ScrParserGlob.currentCodePos);
}
else
{
scrParserGlob.currentSourcePosCount = 0;
scrParserGlob.currentCodePos = Game::scrCompilePub->opcodePos;
opcodeLookup = &scrParserGlob.opcodeLookup[scrParserGlob.opcodeLookupLen];
opcodeLookup->sourcePosIndex = scrParserGlob.sourcePosLookupLen;
opcodeLookup->codePos = scrParserGlob.currentCodePos;
ScrParserGlob.currentSourcePosCount = 0;
ScrParserGlob.currentCodePos = Game::scrCompilePub->opcodePos;
opcodeLookup = &ScrParserGlob.opcodeLookup[ScrParserGlob.opcodeLookupLen];
opcodeLookup->sourcePosIndex = ScrParserGlob.sourcePosLookupLen;
opcodeLookup->codePos = ScrParserGlob.currentCodePos;
}
auto sourcePosLookupIndex = scrParserGlob.currentSourcePosCount + opcodeLookup->sourcePosIndex;
sourcePosLookup = &scrParserGlob.sourcePosLookup[sourcePosLookupIndex];
auto sourcePosLookupIndex = ScrParserGlob.currentSourcePosCount + opcodeLookup->sourcePosIndex;
sourcePosLookup = &ScrParserGlob.sourcePosLookup[sourcePosLookupIndex];
sourcePosLookup->sourcePos = sourcePos;
if (sourcePos == static_cast<unsigned int>(-1))
{
assert(scrParserGlob.delayedSourceIndex == -1);
assert(ScrParserGlob.delayedSourceIndex == -1);
assert(type & Game::SOURCE_TYPE_BREAKPOINT);
scrParserGlob.delayedSourceIndex = static_cast<int>(sourcePosLookupIndex);
ScrParserGlob.delayedSourceIndex = static_cast<int>(sourcePosLookupIndex);
}
else if (sourcePos == static_cast<unsigned int>(-2))
{
scrParserGlob.threadStartSourceIndex = static_cast<int>(sourcePosLookupIndex);
ScrParserGlob.threadStartSourceIndex = static_cast<int>(sourcePosLookupIndex);
}
else if (scrParserGlob.delayedSourceIndex >= 0 && (type & Game::SOURCE_TYPE_BREAKPOINT))
else if (ScrParserGlob.delayedSourceIndex >= 0 && (type & Game::SOURCE_TYPE_BREAKPOINT))
{
scrParserGlob.sourcePosLookup[scrParserGlob.delayedSourceIndex].sourcePos = sourcePos;
scrParserGlob.delayedSourceIndex = -1;
ScrParserGlob.sourcePosLookup[ScrParserGlob.delayedSourceIndex].sourcePos = sourcePos;
ScrParserGlob.delayedSourceIndex = -1;
}
sourcePosLookup->type |= type;
++scrParserGlob.currentSourcePosCount;
opcodeLookup->sourcePosCount = static_cast<unsigned short>(scrParserGlob.currentSourcePosCount);
++scrParserGlob.opcodeLookupLen;
++scrParserGlob.sourcePosLookupLen;
++ScrParserGlob.currentSourcePosCount;
opcodeLookup->sourcePosCount = static_cast<unsigned short>(ScrParserGlob.currentSourcePosCount);
++ScrParserGlob.opcodeLookupLen;
++ScrParserGlob.sourcePosLookupLen;
}
void ScriptError::RemoveOpcodePos()
{
if (!developer_)
if (!Developer_)
{
return;
}
@ -135,35 +135,35 @@ namespace Components::GSC
return;
}
assert(scrParserGlob.opcodeLookup);
assert(scrParserGlob.sourcePosLookup);
assert(ScrParserGlob.opcodeLookup);
assert(ScrParserGlob.sourcePosLookup);
assert(Game::scrCompilePub->opcodePos);
assert(scrParserGlob.sourcePosLookupLen);
assert(ScrParserGlob.sourcePosLookupLen);
--scrParserGlob.sourcePosLookupLen;
assert(scrParserGlob.opcodeLookupLen);
--ScrParserGlob.sourcePosLookupLen;
assert(ScrParserGlob.opcodeLookupLen);
--scrParserGlob.opcodeLookupLen;
assert(scrParserGlob.currentSourcePosCount);
--scrParserGlob.currentSourcePosCount;
--ScrParserGlob.opcodeLookupLen;
assert(ScrParserGlob.currentSourcePosCount);
--ScrParserGlob.currentSourcePosCount;
auto* opcodeLookup = &scrParserGlob.opcodeLookup[scrParserGlob.opcodeLookupLen];
auto* opcodeLookup = &ScrParserGlob.opcodeLookup[ScrParserGlob.opcodeLookupLen];
assert(scrParserGlob.currentCodePos == Game::scrCompilePub->opcodePos);
assert(opcodeLookup->sourcePosIndex + scrParserGlob.currentSourcePosCount == scrParserGlob.sourcePosLookupLen);
assert(opcodeLookup->codePos == (char*)scrParserGlob.currentCodePos);
assert(ScrParserGlob.currentCodePos == Game::scrCompilePub->opcodePos);
assert(opcodeLookup->sourcePosIndex + ScrParserGlob.currentSourcePosCount == ScrParserGlob.sourcePosLookupLen);
assert(opcodeLookup->codePos == (char*)ScrParserGlob.currentCodePos);
if (!scrParserGlob.currentSourcePosCount)
if (!ScrParserGlob.currentSourcePosCount)
{
scrParserGlob.currentCodePos = nullptr;
ScrParserGlob.currentCodePos = nullptr;
}
opcodeLookup->sourcePosCount = static_cast<unsigned short>(scrParserGlob.currentSourcePosCount);
opcodeLookup->sourcePosCount = static_cast<unsigned short>(ScrParserGlob.currentSourcePosCount);
}
void ScriptError::AddThreadStartOpcodePos(unsigned int sourcePos)
{
if (!developer_)
if (!Developer_)
{
return;
}
@ -174,12 +174,12 @@ namespace Components::GSC
}
else
{
assert(scrParserGlob.threadStartSourceIndex >= 0);
auto* sourcePosLookup = &scrParserGlob.sourcePosLookup[scrParserGlob.threadStartSourceIndex];
assert(ScrParserGlob.threadStartSourceIndex >= 0);
auto* sourcePosLookup = &ScrParserGlob.sourcePosLookup[ScrParserGlob.threadStartSourceIndex];
sourcePosLookup->sourcePos = sourcePos;
assert(!sourcePosLookup->type);
sourcePosLookup->type = 8;
scrParserGlob.threadStartSourceIndex = -1;
ScrParserGlob.threadStartSourceIndex = -1;
}
}
@ -188,35 +188,35 @@ namespace Components::GSC
const char* startLine;
int col;
assert(developer_);
return Scr_GetLineNumInternal(scrParserPub.sourceBufferLookup[bufferIndex].sourceBuf, sourcePos, &startLine, &col, nullptr);
assert(Developer_);
return Scr_GetLineNumInternal(ScrParserPub.sourceBufferLookup[bufferIndex].sourceBuf, sourcePos, &startLine, &col, nullptr);
}
unsigned int ScriptError::Scr_GetPrevSourcePos(const char* codePos, unsigned int index)
{
return scrParserGlob.sourcePosLookup[index + Scr_GetPrevSourcePosOpcodeLookup(codePos)->sourcePosIndex].sourcePos;
return ScrParserGlob.sourcePosLookup[index + Scr_GetPrevSourcePosOpcodeLookup(codePos)->sourcePosIndex].sourcePos;
}
Game::OpcodeLookup* ScriptError::Scr_GetPrevSourcePosOpcodeLookup(const char* codePos)
{
assert(Scr_IsInOpcodeMemory(codePos));
assert(scrParserGlob.opcodeLookup);
assert(ScrParserGlob.opcodeLookup);
unsigned int low = 0;
unsigned int high = scrParserGlob.opcodeLookupLen - 1;
unsigned int high = ScrParserGlob.opcodeLookupLen - 1;
while (low <= high)
{
unsigned int middle = (high + low) >> 1;
if (codePos < scrParserGlob.opcodeLookup[middle].codePos)
if (codePos < ScrParserGlob.opcodeLookup[middle].codePos)
{
high = middle - 1;
}
else
{
low = middle + 1;
if (low == scrParserGlob.opcodeLookupLen || codePos < scrParserGlob.opcodeLookup[low].codePos)
if (low == ScrParserGlob.opcodeLookupLen || codePos < ScrParserGlob.opcodeLookup[low].codePos)
{
return &scrParserGlob.opcodeLookup[middle];
return &ScrParserGlob.opcodeLookup[middle];
}
}
}
@ -279,16 +279,16 @@ namespace Components::GSC
unsigned int bufferIndex;
assert(Scr_IsInOpcodeMemory(codePos));
assert(scrParserPub.sourceBufferLookupLen > 0);
assert(ScrParserPub.sourceBufferLookupLen > 0);
for (bufferIndex = scrParserPub.sourceBufferLookupLen - 1; bufferIndex; --bufferIndex)
for (bufferIndex = ScrParserPub.sourceBufferLookupLen - 1; bufferIndex; --bufferIndex)
{
if (!scrParserPub.sourceBufferLookup[bufferIndex].codePos)
if (!ScrParserPub.sourceBufferLookup[bufferIndex].codePos)
{
continue;
}
if (scrParserPub.sourceBufferLookup[bufferIndex].codePos > codePos)
if (ScrParserPub.sourceBufferLookup[bufferIndex].codePos > codePos)
{
continue;
}
@ -313,7 +313,7 @@ namespace Components::GSC
return;
}
if (!developer_)
if (!Developer_)
{
if (Scr_IsInOpcodeMemory(codePos - 1))
{
@ -326,7 +326,7 @@ namespace Components::GSC
if (Game::scrVarPub->programBuffer && Scr_IsInOpcodeMemory(codePos))
{
auto bufferIndex = Scr_GetSourceBuffer(codePos - 1);
Scr_PrintSourcePos(channel, scrParserPub.sourceBufferLookup[bufferIndex].buf, scrParserPub.sourceBufferLookup[bufferIndex].sourceBuf, Scr_GetPrevSourcePos(codePos - 1, index));
Scr_PrintSourcePos(channel, ScrParserPub.sourceBufferLookup[bufferIndex].buf, ScrParserPub.sourceBufferLookup[bufferIndex].sourceBuf, Scr_GetPrevSourcePos(codePos - 1, index));
return;
}
}
@ -362,7 +362,7 @@ namespace Components::GSC
assert(filename);
auto lineNum = Scr_GetLineInfo(buf, sourcePos, &col, line, nullptr);
Game::Com_PrintMessage(channel, VA("(file '%s'%s, line %d)\n", filename, scrParserGlob.saveSourceBufferLookup ? " (savegame)" : "", lineNum + 1), 0);
Game::Com_PrintMessage(channel, VA("(file '%s'%s, line %d)\n", filename, ScrParserGlob.saveSourceBufferLookup ? " (savegame)" : "", lineNum + 1), 0);
Game::Com_PrintMessage(channel, VA("%s\n", line), 0);
for (auto i = 0; i < col; ++i)
@ -400,7 +400,7 @@ namespace Components::GSC
bool abort_on_error;
const char* dialogMessageSeparator;
if (!developer_)
if (!Developer_)
{
assert(Scr_IsInOpcodeMemory(codePos));
if (!(*Game::com_developer)->current.enabled)
@ -462,7 +462,7 @@ namespace Components::GSC
Game::Com_PrintError(Game::CON_CHANNEL_PARSERSCRIPT, "\n");
Game::Com_PrintError(Game::CON_CHANNEL_PARSERSCRIPT, "******* script compile error *******\n");
if (!developer_ || !scrParserPub.sourceBuf)
if (!Developer_ || !ScrParserPub.sourceBuf)
{
Game::Com_PrintError(Game::CON_CHANNEL_PARSERSCRIPT, "%s\n", text);
line[0] = '\0';
@ -472,12 +472,12 @@ namespace Components::GSC
}
else
{
assert(scrParserPub.sourceBuf);
assert(ScrParserPub.sourceBuf);
Game::Com_PrintError(Game::CON_CHANNEL_PARSERSCRIPT, "%s: ", text);
Scr_PrintSourcePos(Game::CON_CHANNEL_PARSERSCRIPT, scrParserPub.scriptfilename, scrParserPub.sourceBuf, sourcePos);
auto lineNumber = Scr_GetLineInfo(scrParserPub.sourceBuf, sourcePos, &col, line, nullptr);
Game::Com_Error(Game::ERR_SCRIPT_DROP, "\x15" "script compile error\n%s\n%s(%d):\n %s\n(see console for details)\n", text, scrParserPub.scriptfilename, lineNumber, line);
Scr_PrintSourcePos(Game::CON_CHANNEL_PARSERSCRIPT, ScrParserPub.scriptfilename, ScrParserPub.sourceBuf, sourcePos);
const auto lineNumber = Scr_GetLineInfo(ScrParserPub.sourceBuf, sourcePos, &col, line, nullptr);
Game::Com_Error(Game::ERR_SCRIPT_DROP, "\x15" "script compile error\n%s\n%s(%d):\n %s\n(see console for details)\n", text, ScrParserPub.scriptfilename, lineNumber, line);
}
}
}
@ -504,7 +504,7 @@ namespace Components::GSC
Game::Com_Printf(Game::CON_CHANNEL_PARSERSCRIPT, "************************************\n");
Scr_GetTextSourcePos(scrParserPub.sourceBuf, codePos, line);
Scr_GetTextSourcePos(ScrParserPub.sourceBuf, codePos, line);
Game::Com_Error(Game::ERR_SCRIPT_DROP, "\x15" "script compile error\n%s\n%s\n(see console for details)\n", text, line);
}
@ -513,10 +513,10 @@ namespace Components::GSC
{
int col;
if (developer_ && codePos && codePos != Game::g_EndPos && Game::scrVarPub->programBuffer && Scr_IsInOpcodeMemory(codePos))
if (Developer_ && codePos && codePos != Game::g_EndPos && Game::scrVarPub->programBuffer && Scr_IsInOpcodeMemory(codePos))
{
auto bufferIndex = Scr_GetSourceBuffer(codePos - 1);
Scr_GetLineInfo(scrParserPub.sourceBufferLookup[bufferIndex].sourceBuf, Scr_GetPrevSourcePos(codePos - 1, 0), &col, line, nullptr);
Scr_GetLineInfo(ScrParserPub.sourceBufferLookup[bufferIndex].sourceBuf, Scr_GetPrevSourcePos(codePos - 1, 0), &col, line, nullptr);
}
else
{
@ -526,68 +526,68 @@ namespace Components::GSC
void ScriptError::Scr_InitOpcodeLookup()
{
assert(!scrParserGlob.opcodeLookup);
assert(!scrParserGlob.sourcePosLookup);
assert(!scrParserPub.sourceBufferLookup);
assert(!ScrParserGlob.opcodeLookup);
assert(!ScrParserGlob.sourcePosLookup);
assert(!ScrParserPub.sourceBufferLookup);
if (!developer_)
if (!Developer_)
{
return;
}
scrParserGlob.delayedSourceIndex = -1;
scrParserGlob.opcodeLookupMaxSize = 0;
scrParserGlob.opcodeLookupLen = 0;
scrParserGlob.opcodeLookup = static_cast<Game::OpcodeLookup*>(Game::Z_VirtualReserve(Game::MAX_OPCODE_LOOKUP_SIZE));
ScrParserGlob.delayedSourceIndex = -1;
ScrParserGlob.opcodeLookupMaxSize = 0;
ScrParserGlob.opcodeLookupLen = 0;
ScrParserGlob.opcodeLookup = static_cast<Game::OpcodeLookup*>(Game::Z_VirtualReserve(Game::MAX_OPCODE_LOOKUP_SIZE));
scrParserGlob.sourcePosLookupMaxSize = 0;
scrParserGlob.sourcePosLookupLen = 0;
scrParserGlob.sourcePosLookup = static_cast<Game::SourceLookup*>(Game::Z_VirtualReserve(Game::MAX_SOURCEPOS_LOOKUP_SIZE));
scrParserGlob.currentCodePos = nullptr;
scrParserGlob.currentSourcePosCount = 0;
scrParserGlob.sourceBufferLookupMaxSize = 0;
ScrParserGlob.sourcePosLookupMaxSize = 0;
ScrParserGlob.sourcePosLookupLen = 0;
ScrParserGlob.sourcePosLookup = static_cast<Game::SourceLookup*>(Game::Z_VirtualReserve(Game::MAX_SOURCEPOS_LOOKUP_SIZE));
ScrParserGlob.currentCodePos = nullptr;
ScrParserGlob.currentSourcePosCount = 0;
ScrParserGlob.sourceBufferLookupMaxSize = 0;
scrParserPub.sourceBufferLookupLen = 0;
scrParserPub.sourceBufferLookup = static_cast<Game::SourceBufferInfo*>(Game::Z_VirtualReserve(Game::MAX_SOURCEBUF_LOOKUP_SIZE));
ScrParserPub.sourceBufferLookupLen = 0;
ScrParserPub.sourceBufferLookup = static_cast<Game::SourceBufferInfo*>(Game::Z_VirtualReserve(Game::MAX_SOURCEBUF_LOOKUP_SIZE));
}
void ScriptError::Scr_ShutdownOpcodeLookup()
{
if (scrParserGlob.opcodeLookup)
if (ScrParserGlob.opcodeLookup)
{
Z_VirtualFree(scrParserGlob.opcodeLookup);
scrParserGlob.opcodeLookup = nullptr;
Z_VirtualFree(ScrParserGlob.opcodeLookup);
ScrParserGlob.opcodeLookup = nullptr;
}
if (scrParserGlob.sourcePosLookup)
if (ScrParserGlob.sourcePosLookup)
{
Z_VirtualFree(scrParserGlob.sourcePosLookup);
scrParserGlob.sourcePosLookup = nullptr;
Z_VirtualFree(ScrParserGlob.sourcePosLookup);
ScrParserGlob.sourcePosLookup = nullptr;
}
if (scrParserPub.sourceBufferLookup)
if (ScrParserPub.sourceBufferLookup)
{
for (unsigned int i = 0; i < scrParserPub.sourceBufferLookupLen; ++i)
for (unsigned int i = 0; i < ScrParserPub.sourceBufferLookupLen; ++i)
{
Game::Engine::Hunk_FreeDebugMem(scrParserPub.sourceBufferLookup[i].buf);
Game::Engine::Hunk_FreeDebugMem(ScrParserPub.sourceBufferLookup[i].buf);
}
Z_VirtualFree(scrParserPub.sourceBufferLookup);
scrParserPub.sourceBufferLookup = nullptr;
Z_VirtualFree(ScrParserPub.sourceBufferLookup);
ScrParserPub.sourceBufferLookup = nullptr;
}
if (scrParserGlob.saveSourceBufferLookup)
if (ScrParserGlob.saveSourceBufferLookup)
{
for (unsigned int i = 0; i < scrParserGlob.saveSourceBufferLookupLen; ++i)
for (unsigned int i = 0; i < ScrParserGlob.saveSourceBufferLookupLen; ++i)
{
if (scrParserGlob.saveSourceBufferLookup[i].sourceBuf)
if (ScrParserGlob.saveSourceBufferLookup[i].sourceBuf)
{
Game::Engine::Hunk_FreeDebugMem(scrParserGlob.saveSourceBufferLookup[i].buf);
Game::Engine::Hunk_FreeDebugMem(ScrParserGlob.saveSourceBufferLookup[i].buf);
}
}
Game::Engine::Hunk_FreeDebugMem(scrParserGlob.saveSourceBufferLookup);
scrParserGlob.saveSourceBufferLookup = nullptr;
Game::Engine::Hunk_FreeDebugMem(ScrParserGlob.saveSourceBufferLookup);
ScrParserGlob.saveSourceBufferLookup = nullptr;
}
}
@ -612,39 +612,39 @@ namespace Components::GSC
Game::SourceBufferInfo* ScriptError::Scr_GetNewSourceBuffer()
{
assert(scrParserPub.sourceBufferLookup);
assert(ScrParserPub.sourceBufferLookup);
auto size = sizeof(Game::SourceBufferInfo) * (scrParserPub.sourceBufferLookupLen + 1);
if (size > scrParserGlob.sourceBufferLookupMaxSize)
auto size = sizeof(Game::SourceBufferInfo) * (ScrParserPub.sourceBufferLookupLen + 1);
if (size > ScrParserGlob.sourceBufferLookupMaxSize)
{
if (scrParserGlob.sourceBufferLookupMaxSize >= Game::MAX_SOURCEBUF_LOOKUP_SIZE)
if (ScrParserGlob.sourceBufferLookupMaxSize >= Game::MAX_SOURCEBUF_LOOKUP_SIZE)
{
Game::Sys_Error("MAX_SOURCEBUF_LOOKUP_SIZE exceeded");
}
Game::Z_VirtualCommit((char*)scrParserPub.sourceBufferLookup + scrParserGlob.sourceBufferLookupMaxSize, 0x20000);
scrParserGlob.sourceBufferLookupMaxSize += 0x20000;
assert(size <= scrParserGlob.sourceBufferLookupMaxSize);
Game::Z_VirtualCommit((char*)ScrParserPub.sourceBufferLookup + ScrParserGlob.sourceBufferLookupMaxSize, 0x20000);
ScrParserGlob.sourceBufferLookupMaxSize += 0x20000;
assert(size <= ScrParserGlob.sourceBufferLookupMaxSize);
}
return &scrParserPub.sourceBufferLookup[scrParserPub.sourceBufferLookupLen++];
return &ScrParserPub.sourceBufferLookup[ScrParserPub.sourceBufferLookupLen++];
}
void ScriptError::Scr_AddSourceBufferInternal(const char* extFilename, const char* codePos, char* sourceBuf, int len, bool doEolFixup, bool archive)
{
int i;
if (!scrParserPub.sourceBufferLookup)
if (!ScrParserPub.sourceBufferLookup)
{
scrParserPub.sourceBuf = nullptr;
ScrParserPub.sourceBuf = nullptr;
return;
}
assert((len >= -1));
assert((len >= 0) || !sourceBuf);
auto strLen = std::strlen(extFilename) + 1;
auto newLen = strLen + len + 2;
const auto strLen = std::strlen(extFilename) + 1;
const auto newLen = strLen + len + 2;
auto* buf = static_cast<char*>(Game::Engine::Hunk_AllocDebugMem(static_cast<int>(newLen))); // Scr_AddSourceBufferInternal
strcpy(buf, extFilename);
@ -689,7 +689,7 @@ namespace Components::GSC
if (sourceBuf2)
{
scrParserPub.sourceBuf = sourceBuf2;
ScrParserPub.sourceBuf = sourceBuf2;
}
}
@ -749,12 +749,12 @@ namespace Components::GSC
{
char* sourceBuf;
if (archive && scrParserGlob.saveSourceBufferLookup)
if (archive && ScrParserGlob.saveSourceBufferLookup)
{
assert(scrParserGlob.saveSourceBufferLookupLen > 0);
--scrParserGlob.saveSourceBufferLookupLen;
assert(ScrParserGlob.saveSourceBufferLookupLen > 0);
--ScrParserGlob.saveSourceBufferLookupLen;
const auto* saveSourceBuffer = scrParserGlob.saveSourceBufferLookup + scrParserGlob.saveSourceBufferLookupLen;
const auto* saveSourceBuffer = ScrParserGlob.saveSourceBufferLookup + ScrParserGlob.saveSourceBufferLookupLen;
const auto len = saveSourceBuffer->len;
assert(len >= -1);
@ -808,7 +808,7 @@ namespace Components::GSC
sprintf_s(extFilename, "%s.gsc", Game::SL_ConvertToString(static_cast<unsigned short>(name)));
const auto* oldSourceBuf = scrParserPub.sourceBuf;
const auto* oldSourceBuf = ScrParserPub.sourceBuf;
const auto* sourceBuffer = Scr_AddSourceBuffer(Game::SL_ConvertToString(static_cast<unsigned short>(name)), extFilename, Game::TempMalloc(0), true);
if (!sourceBuffer)
@ -820,8 +820,8 @@ namespace Components::GSC
Game::scrAnimPub->animTreeNames = 0;
Game::scrCompilePub->far_function_count = 0;
const auto* oldFilename = scrParserPub.scriptfilename;
scrParserPub.scriptfilename = extFilename;
const auto* oldFilename = ScrParserPub.scriptfilename;
ScrParserPub.scriptfilename = extFilename;
Game::scrCompilePub->in_ptr = "+";
Game::scrCompilePub->in_ptr_valid = false;
@ -837,8 +837,8 @@ namespace Components::GSC
Game::RemoveVariable(Game::scrCompilePub->scriptsCount, name);
scrParserPub.scriptfilename = oldFilename;
scrParserPub.sourceBuf = oldSourceBuf;
ScrParserPub.scriptfilename = oldFilename;
ScrParserPub.sourceBuf = oldSourceBuf;
Game::scrAnimPub->animTreeNames = oldAnimTreeNames;
@ -848,7 +848,7 @@ namespace Components::GSC
void ScriptError::Scr_Settings_Hk([[maybe_unused]] int developer, int developer_script, int abort_on_error)
{
assert(!abort_on_error || developer);
developer_ = (*Game::com_developer)->current.enabled;
Developer_ = (*Game::com_developer)->current.enabled;
Game::scrVarPub->developer_script = developer_script != 0;
Game::scrVmPub->abort_on_error = abort_on_error != 0;
}

View File

@ -14,10 +14,10 @@ namespace Components::GSC
private:
// Replacement for variables not present in currently available structs
static int developer_;
static int Developer_;
static Game::scrParserGlob_t scrParserGlob;
static Game::scrParserPub_t scrParserPub;
static Game::scrParserGlob_t ScrParserGlob;
static Game::scrParserPub_t ScrParserPub;
static void AddOpcodePos(unsigned int sourcePos, int type);
static void RemoveOpcodePos();

View File

@ -1,4 +1,7 @@
#include <STDInclude.hpp>
#include <Components/Modules/Events.hpp>
#include "ScriptExtension.hpp"
#include "Script.hpp"

View File

@ -1,6 +1,8 @@
#include <STDInclude.hpp>
#include <Utils/InfoString.hpp>
#include <Components/Modules/Events.hpp>
#include "Script.hpp"
#include "UserInfo.hpp"

View File

@ -1,5 +1,7 @@
#include <STDInclude.hpp>
#include "Console.hpp"
#include "Events.hpp"
namespace Components
{

View File

@ -1,4 +1,6 @@
#include <STDInclude.hpp>
#include "Events.hpp"
#include "MapRotation.hpp"
#include "Party.hpp"

View File

@ -1,4 +1,6 @@
#include <STDInclude.hpp>
#include "Events.hpp"
#include "PlayerMovement.hpp"
#include "GSC/Script.hpp"

View File

@ -1,6 +1,7 @@
#include <STDInclude.hpp>
#include <proto/rcon.pb.h>
#include "Events.hpp"
#include "RCon.hpp"
#include "Party.hpp"

View File

@ -1,5 +1,7 @@
#include <STDInclude.hpp>
#include "Events.hpp"
namespace Components
{
Utils::Signal<Renderer::BackendCallback> Renderer::BackendFrameSignal;

View File

@ -2,6 +2,7 @@
#include <Utils/InfoString.hpp>
#include "Discovery.hpp"
#include "Events.hpp"
#include "Node.hpp"
#include "Party.hpp"
#include "ServerList.hpp"

View File

@ -1,4 +1,6 @@
#include <STDInclude.hpp>
#include "Events.hpp"
#include "StartupMessages.hpp"
namespace Components

View File

@ -1,4 +1,6 @@
#include <STDInclude.hpp>
#include "Events.hpp"
#include "UIFeeder.hpp"
namespace Components

View File

@ -1,5 +1,7 @@
#include <STDInclude.hpp>
#include "Chat.hpp"
#include "Events.hpp"
#include "Voice.hpp"
namespace Components

View File

@ -67,12 +67,6 @@ namespace Utils
}
}
template <typename T>
bool Contains(const std::vector<T>* haystack, T needle)
{
return std::ranges::find(*haystack, needle) != haystack->end();
}
template <typename T> using Slot = std::function<T>;
template <typename T>
class Signal