[GSC]: Add namespace to match folder layout (#808)

This commit is contained in:
Edo 2023-03-05 13:14:47 +00:00 committed by GitHub
parent 6b8eabe513
commit 6e7556b177
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
29 changed files with 190 additions and 152 deletions

View File

@ -48,7 +48,6 @@
#include "Modules/Theatre.hpp"
#include "Modules/Threading.hpp"
#include "Modules/UIFeeder.hpp"
#include "Modules/UserInfo.hpp"
#include "Modules/VisionFile.hpp"
#include "Modules/Voice.hpp"
#include "Modules/Vote.hpp"
@ -162,7 +161,6 @@ namespace Components
Register(new Threading());
Register(new Toast());
Register(new UIFeeder());
Register(new UserInfo());
Register(new VisionFile());
Register(new Voice());
Register(new Vote());
@ -170,9 +168,9 @@ namespace Components
Register(new Window());
Register(new Zones());
Register(new GSC());
Register(new GSC::GSC());
Register(new lPrecomp());
Register(new BotLib::lPrecomp());
Pregame = false;

View File

@ -1,7 +1,7 @@
#include <STDInclude.hpp>
#include "lPrecomp.hpp"
namespace Components
namespace Components::BotLib
{
// Two new directives! Refer to (https://en.cppreference.com/w/cpp/preprocessor/conditional)
Game::directive_s lPrecomp::directives[] =

View File

@ -1,6 +1,6 @@
#pragma once
namespace Components
namespace Components::BotLib
{
class lPrecomp : public Component
{

View File

@ -203,9 +203,9 @@ namespace Components
void Bots::AddMethods()
{
Script::AddMethMultiple(GScr_isTestClient, false, {"IsTestClient", "IsBot"}); // Usage: self IsTestClient();
GSC::Script::AddMethMultiple(GScr_isTestClient, false, {"IsTestClient", "IsBot"}); // Usage: self IsTestClient();
Script::AddMethod("BotStop", [](Game::scr_entref_t entref) // Usage: <bot> BotStop();
GSC::Script::AddMethod("BotStop", [](Game::scr_entref_t entref) // Usage: <bot> BotStop();
{
const auto* ent = Game::GetPlayerEntity(entref);
@ -220,7 +220,7 @@ namespace Components
g_botai[entref.entnum].active = true;
});
Script::AddMethod("BotWeapon", [](Game::scr_entref_t entref) // Usage: <bot> BotWeapon(<str>);
GSC::Script::AddMethod("BotWeapon", [](Game::scr_entref_t entref) // Usage: <bot> BotWeapon(<str>);
{
const auto* ent = Game::GetPlayerEntity(entref);
@ -243,7 +243,7 @@ namespace Components
g_botai[entref.entnum].active = true;
});
Script::AddMethod("BotAction", [](Game::scr_entref_t entref) // Usage: <bot> BotAction(<str action>);
GSC::Script::AddMethod("BotAction", [](Game::scr_entref_t entref) // Usage: <bot> BotAction(<str action>);
{
const auto* ent = Game::GetPlayerEntity(entref);
@ -284,7 +284,7 @@ namespace Components
Game::Scr_ParamError(0, "^1BotAction: Unknown action.\n");
});
Script::AddMethod("BotMovement", [](Game::scr_entref_t entref) // Usage: <bot> BotMovement(<int>, <int>);
GSC::Script::AddMethod("BotMovement", [](Game::scr_entref_t entref) // Usage: <bot> BotMovement(<int>, <int>);
{
const auto* ent = Game::GetPlayerEntity(entref);

View File

@ -586,7 +586,7 @@ namespace Components
void Chat::AddScriptFunctions()
{
Script::AddFunction("OnPlayerSay", [] // gsc: OnPlayerSay(<function>)
GSC::Script::AddFunction("OnPlayerSay", [] // gsc: OnPlayerSay(<function>)
{
if (Game::Scr_GetNumParam() != 1)
{
@ -600,7 +600,7 @@ namespace Components
return;
}
const auto* func = ScriptExtension::GetCodePosForParam(0);
const auto* func = GSC::ScriptExtension::GetCodePosForParam(0);
SayCallbacks.emplace_back(func);
});
}

View File

@ -363,7 +363,7 @@ namespace Components
void ClientCommand::AddScriptFunctions()
{
Script::AddFunction("DropAllBots", [] // gsc: DropAllBots();
GSC::Script::AddFunction("DropAllBots", [] // gsc: DropAllBots();
{
Game::SV_DropAllBots();
});

View File

@ -7,8 +7,10 @@
#include "ScriptExtension.hpp"
#include "ScriptPatches.hpp"
#include "ScriptStorage.hpp"
#include "String.hpp"
#include "UserInfo.hpp"
namespace Components
namespace Components::GSC
{
GSC::GSC()
{
@ -19,5 +21,7 @@ namespace Components
Loader::Register(new ScriptExtension());
Loader::Register(new ScriptPatches());
Loader::Register(new ScriptStorage());
Loader::Register(new String());
Loader::Register(new UserInfo());
}
}

View File

@ -1,6 +1,6 @@
#pragma once
namespace Components
namespace Components::GSC
{
class GSC : public Component
{

View File

@ -2,7 +2,7 @@
#include "IO.hpp"
#include "Script.hpp"
namespace Components
namespace Components::GSC
{
const char* IO::QueryStrings[] = { R"(..)", R"(../)", R"(..\)" };

View File

@ -1,6 +1,6 @@
#pragma once
namespace Components
namespace Components::GSC
{
class IO : public Component
{

View File

@ -4,7 +4,7 @@
#define INT64_OPERATION(expr) [](const std::int64_t a, [[maybe_unused]] const std::int64_t b) { return expr; }
namespace Components
namespace Components::GSC
{
std::unordered_map<std::string, Int64::int64_OP> Int64::Operations =
{

View File

@ -1,6 +1,6 @@
#pragma once
namespace Components
namespace Components::GSC
{
class Int64 : public Component
{

View File

@ -1,7 +1,7 @@
#include <STDInclude.hpp>
#include "Script.hpp"
namespace Components
namespace Components::GSC
{
std::vector<Script::ScriptFunction> Script::CustomScrFunctions;
std::vector<Script::ScriptMethod> Script::CustomScrMethods;

View File

@ -1,6 +1,6 @@
#pragma once
namespace Components
namespace Components::GSC
{
class Script : public Component
{

View File

@ -5,10 +5,10 @@
#define SCRIPT_ERROR_PATCH
using namespace Utils::String;
namespace Components
namespace Components::GSC
{
using namespace Utils::String;
int ScriptError::developer_;
Game::scrParserGlob_t ScriptError::scrParserGlob;

View File

@ -1,6 +1,6 @@
#pragma once
namespace Components
namespace Components::GSC
{
class ScriptError : public Component
{

View File

@ -2,7 +2,7 @@
#include "ScriptExtension.hpp"
#include "Script.hpp"
namespace Components
namespace Components::GSC
{
std::unordered_map<std::uint16_t, Game::ent_field_t> ScriptExtension::CustomEntityFields;
std::unordered_map<std::uint16_t, Game::client_fields_s> ScriptExtension::CustomClientFields;
@ -199,78 +199,6 @@ namespace Components
void ScriptExtension::AddFunctions()
{
// Misc functions
Script::AddFunction("ToUpper", [] // gsc: ToUpper(<string>)
{
const auto scriptValue = Game::Scr_GetConstString(0);
const auto* string = Game::SL_ConvertToString(scriptValue);
char out[1024] = {0}; // 1024 is the max for a string in this SL system
bool changed = false;
size_t i = 0;
while (i < sizeof(out))
{
const auto value = *string;
const auto result = static_cast<char>(std::toupper(static_cast<unsigned char>(value)));
out[i] = result;
if (value != result)
changed = true;
if (result == '\0') // Finished converting string
break;
++string;
++i;
}
// Null terminating character was overwritten
if (i >= sizeof(out))
{
Game::Scr_Error("string too long");
return;
}
if (changed)
{
Game::Scr_AddString(out);
}
else
{
Game::SL_AddRefToString(scriptValue);
Game::Scr_AddConstString(scriptValue);
Game::SL_RemoveRefToString(scriptValue);
}
});
// Func present on IW5
Script::AddFunction("StrICmp", [] // gsc: StrICmp(<string>, <string>)
{
const auto value1 = Game::Scr_GetConstString(0);
const auto value2 = Game::Scr_GetConstString(1);
const auto result = _stricmp(Game::SL_ConvertToString(value1),
Game::SL_ConvertToString(value2));
Game::Scr_AddInt(result);
});
// Func present on IW5
Script::AddFunction("IsEndStr", [] // gsc: IsEndStr(<string>, <string>)
{
const auto* str = Game::Scr_GetString(0);
const auto* suffix = Game::Scr_GetString(1);
if (str == nullptr || suffix == nullptr)
{
Game::Scr_Error("^1IsEndStr: Illegal parameters!\n");
return;
}
Game::Scr_AddBool(Utils::String::EndsWith(str, suffix));
});
Script::AddFunction("IsArray", [] // gsc: IsArray(<object>)
{
auto type = Game::Scr_GetType(0);
@ -291,41 +219,6 @@ namespace Components
Game::Scr_AddBool(result);
});
// Func present on IW5
Script::AddFunction("CastFloat", [] // gsc: CastFloat()
{
switch (Game::Scr_GetType(0))
{
case Game::VAR_STRING:
Game::Scr_AddFloat(static_cast<float>(std::atof(Game::Scr_GetString(0))));
break;
case Game::VAR_FLOAT:
Game::Scr_AddFloat(Game::Scr_GetFloat(0));
break;
case Game::VAR_INTEGER:
Game::Scr_AddFloat(static_cast<float>(Game::Scr_GetInt(0)));
break;
default:
Game::Scr_ParamError(0, Utils::String::VA("cannot cast %s to float", Game::Scr_GetTypeName(0)));
break;
}
});
Script::AddFunction("Strtol", [] // gsc: Strtol(<string>, <int>)
{
const auto* input = Game::Scr_GetString(0);
const auto base = Game::Scr_GetInt(1);
char* end;
const auto result = std::strtol(input, &end, base);
if (input == end)
{
Game::Scr_ParamError(0, "cannot cast string to int");
}
Game::Scr_AddInt(result);
});
Script::AddFunction("ReplaceFunc", [] // gsc: ReplaceFunc(<function>, <function>)
{
if (Game::Scr_GetNumParam() != 2)
@ -388,8 +281,19 @@ namespace Components
std::string ip = Game::NET_AdrToString(client->header.netchan.remoteAddress);
if (const auto pos = ip.find_first_of(":"); pos != std::string::npos)
ip.erase(ip.begin() + pos, ip.end()); // Erase port
const auto extractIPAddress = [](const std::string& input) -> std::string
{
const auto colonPos = input.find(':');
if (colonPos == std::string::npos)
{
return input;
}
auto ipAddress = input.substr(0, colonPos);
return ipAddress;
};
ip = extractIPAddress(ip);
Game::Scr_AddString(ip.data());
});

View File

@ -1,6 +1,6 @@
#pragma once
namespace Components
namespace Components::GSC
{
class ScriptExtension : public Component
{

View File

@ -4,7 +4,7 @@
using namespace Utils::String;
namespace Components
namespace Components::GSC
{
constexpr auto offset = 511;

View File

@ -1,6 +1,6 @@
#pragma once
namespace Components
namespace Components::GSC
{
class ScriptPatches : public Component
{

View File

@ -3,7 +3,7 @@
#include "ScriptStorage.hpp"
#include "Script.hpp"
namespace Components
namespace Components::GSC
{
std::unordered_map<std::string, std::string> ScriptStorage::Data;

View File

@ -1,6 +1,6 @@
#pragma once
namespace Components
namespace Components::GSC
{
class ScriptStorage : public Component
{

View File

@ -0,0 +1,120 @@
#include <STDInclude.hpp>
#include "Script.hpp"
#include "String.hpp"
namespace Components::GSC
{
void String::AddScriptFunctions()
{
Script::AddFunction("ToUpper", [] // gsc: ToUpper(<string>)
{
const auto scriptValue = Game::Scr_GetConstString(0);
const auto* string = Game::SL_ConvertToString(scriptValue);
char out[1024] = {0}; // 1024 is the max for a string in this SL system
bool changed = false;
size_t i = 0;
while (i < sizeof(out))
{
const auto value = *string;
const auto result = static_cast<char>(std::toupper(static_cast<unsigned char>(value)));
out[i] = result;
if (value != result)
changed = true;
if (result == '\0') // Finished converting string
break;
++string;
++i;
}
// Null terminating character was overwritten
if (i >= sizeof(out))
{
Game::Scr_Error("string too long");
return;
}
if (changed)
{
Game::Scr_AddString(out);
}
else
{
Game::SL_AddRefToString(scriptValue);
Game::Scr_AddConstString(scriptValue);
Game::SL_RemoveRefToString(scriptValue);
}
});
// Func present on IW5
Script::AddFunction("StrICmp", [] // gsc: StrICmp(<string>, <string>)
{
const auto value1 = Game::Scr_GetConstString(0);
const auto value2 = Game::Scr_GetConstString(1);
const auto result = _stricmp(Game::SL_ConvertToString(value1), Game::SL_ConvertToString(value2));
Game::Scr_AddInt(result);
});
// Func present on IW5
Script::AddFunction("IsEndStr", [] // gsc: IsEndStr(<string>, <string>)
{
const auto* str = Game::Scr_GetString(0);
const auto* suffix = Game::Scr_GetString(1);
if (!str || !suffix)
{
Game::Scr_Error("^1IsEndStr: Illegal parameters!\n");
return;
}
Game::Scr_AddBool(Utils::String::EndsWith(str, suffix));
});
// Func present on IW5
Script::AddFunction("CastFloat", [] // gsc: CastFloat()
{
switch (Game::Scr_GetType(0))
{
case Game::VAR_STRING:
Game::Scr_AddFloat(static_cast<float>(std::atof(Game::Scr_GetString(0))));
break;
case Game::VAR_FLOAT:
Game::Scr_AddFloat(Game::Scr_GetFloat(0));
break;
case Game::VAR_INTEGER:
Game::Scr_AddFloat(static_cast<float>(Game::Scr_GetInt(0)));
break;
default:
Game::Scr_ParamError(0, Utils::String::VA("cannot cast %s to float", Game::Scr_GetTypeName(0)));
break;
}
});
Script::AddFunction("Strtol", [] // gsc: Strtol(<string>, <int>)
{
const auto* input = Game::Scr_GetString(0);
const auto base = Game::Scr_GetInt(1);
char* end;
const auto result = std::strtol(input, &end, base);
if (input == end)
{
Game::Scr_ParamError(0, "cannot cast string to int");
}
Game::Scr_AddInt(result);
});
}
String::String()
{
AddScriptFunctions();
}
}

View File

@ -0,0 +1,13 @@
#pragma once
namespace Components::GSC
{
class String : public Component
{
public:
String();
private:
static void AddScriptFunctions();
};
}

View File

@ -1,11 +1,10 @@
#include <STDInclude.hpp>
#include <Utils/InfoString.hpp>
#include "Script.hpp"
#include "UserInfo.hpp"
#include "GSC/Script.hpp"
namespace Components
namespace Components::GSC
{
std::unordered_map<int, UserInfo::userInfoMap> UserInfo::UserInfoOverrides;

View File

@ -1,6 +1,6 @@
#pragma once
namespace Components
namespace Components::GSC
{
class UserInfo : public Component
{

View File

@ -330,7 +330,7 @@ namespace Components
Utils::Hook(0x573F39, PM_PlayerTraceStub, HOOK_CALL).install()->quick();
Utils::Hook(0x573E93, PM_PlayerTraceStub, HOOK_CALL).install()->quick();
Script::AddMethod("IsSprinting", GScr_IsSprinting);
GSC::Script::AddMethod("IsSprinting", GScr_IsSprinting);
RegisterMovementDvars();
}

View File

@ -79,7 +79,7 @@ namespace Components
void Stats::AddScriptFunctions()
{
Script::AddMethod("GetStat", [](const Game::scr_entref_t entref)
GSC::Script::AddMethod("GetStat", [](const Game::scr_entref_t entref)
{
const auto* ent = Game::GetPlayerEntity(entref);
const auto index = Game::Scr_GetInt(0);
@ -97,7 +97,7 @@ namespace Components
Game::Scr_AddInt(Game::SV_GetClientStat(ent->s.number, index));
});
Script::AddMethod("SetStat", [](const Game::scr_entref_t entref)
GSC::Script::AddMethod("SetStat", [](const Game::scr_entref_t entref)
{
const auto* ent = Game::GetPlayerEntity(entref);

View File

@ -550,7 +550,7 @@ namespace Components
void Weapon::PlayerCmd_initialWeaponRaise(Game::scr_entref_t entref)
{
auto* ent = Script::Scr_GetPlayerEntity(entref);
auto* ent = GSC::Script::Scr_GetPlayerEntity(entref);
const auto* weapon = Game::Scr_GetString(0);
const auto index = Game::G_GetWeaponIndexForName(weapon);
@ -580,21 +580,21 @@ namespace Components
void Weapon::AddScriptMethods()
{
Script::AddMethod("DisableWeaponPickup", [](Game::scr_entref_t entref)
GSC::Script::AddMethod("DisableWeaponPickup", [](Game::scr_entref_t entref)
{
const auto* ent = Game::GetPlayerEntity(entref);
ent->client->ps.weapCommon.weapFlags |= Game::PWF_DISABLE_WEAPON_PICKUP;
});
Script::AddMethod("EnableWeaponPickup", [](Game::scr_entref_t entref)
GSC::Script::AddMethod("EnableWeaponPickup", [](Game::scr_entref_t entref)
{
const auto* ent = Game::GetPlayerEntity(entref);
ent->client->ps.weapCommon.weapFlags &= ~Game::PWF_DISABLE_WEAPON_PICKUP;
});
Script::AddMethod("InitialWeaponRaise", PlayerCmd_initialWeaponRaise);
GSC::Script::AddMethod("InitialWeaponRaise", PlayerCmd_initialWeaponRaise);
}
Weapon::Weapon()