diff --git a/src/Components/Modules/Bots.cpp b/src/Components/Modules/Bots.cpp index 77d041d8..72c3836b 100644 --- a/src/Components/Modules/Bots.cpp +++ b/src/Components/Modules/Bots.cpp @@ -119,10 +119,10 @@ namespace Components void Bots::AddMethods() { - Script::AddMethod("IsBot", Bots::GScr_isTestClient); // Usage: self iw4x_IsBot(); - Script::AddMethod("IsTestClient", Bots::GScr_isTestClient); // Usage: self iw4x_IsTestClient(); + Script::AddMethod("IsBot", Bots::GScr_isTestClient); // Usage: self IsBot(); + Script::AddMethod("IsTestClient", Bots::GScr_isTestClient); // Usage: self IsTestClient(); - Script::AddMethod("BotStop", [](Game::scr_entref_t entref) // Usage: iw4x_BotStop(); + Script::AddMethod("BotStop", [](Game::scr_entref_t entref) // Usage: BotStop(); { const auto* ent = Game::GetPlayerEntity(entref); @@ -137,7 +137,7 @@ namespace Components g_botai[entref.entnum].active = true; }); - Script::AddMethod("BotWeapon", [](Game::scr_entref_t entref) // Usage: iw4x_BotWeapon(); + Script::AddMethod("BotWeapon", [](Game::scr_entref_t entref) // Usage: BotWeapon(); { const auto* ent = Game::GetPlayerEntity(entref); @@ -160,7 +160,7 @@ namespace Components g_botai[entref.entnum].active = true; }); - Script::AddMethod("BotAction", [](Game::scr_entref_t entref) // Usage: iw4x_BotAction(); + Script::AddMethod("BotAction", [](Game::scr_entref_t entref) // Usage: BotAction(); { const auto* ent = Game::GetPlayerEntity(entref); @@ -201,7 +201,7 @@ namespace Components Game::Scr_ParamError(0, "^1BotAction: Unknown action.\n"); }); - Script::AddMethod("BotMovement", [](Game::scr_entref_t entref) // Usage: iw4x_BotMovement(, ); + Script::AddMethod("BotMovement", [](Game::scr_entref_t entref) // Usage: BotMovement(, ); { const auto* ent = Game::GetPlayerEntity(entref); diff --git a/src/Components/Modules/Chat.cpp b/src/Components/Modules/Chat.cpp index b2f105e6..37c55e37 100644 --- a/src/Components/Modules/Chat.cpp +++ b/src/Components/Modules/Chat.cpp @@ -389,7 +389,7 @@ namespace Components void Chat::AddScriptFunctions() { - Script::AddFunction("OnPlayerSay", [] // gsc: iw4x_OnPlayerSay() + Script::AddFunction("OnPlayerSay", [] // gsc: OnPlayerSay() { if (Game::Scr_GetNumParam() != 1) { diff --git a/src/Components/Modules/ClientCommand.cpp b/src/Components/Modules/ClientCommand.cpp index cc552799..48077a44 100644 --- a/src/Components/Modules/ClientCommand.cpp +++ b/src/Components/Modules/ClientCommand.cpp @@ -351,49 +351,7 @@ namespace Components void ClientCommand::AddScriptFunctions() { - Script::AddMethod("Noclip", [](Game::scr_entref_t entref) // gsc: iw4x_Noclip(); - { - const auto* ent = Game::GetPlayerEntity(entref); - - if (Game::Scr_GetNumParam() >= 1) - { - if (Game::Scr_GetInt(0)) - { - ent->client->flags |= Game::PLAYER_FLAG_NOCLIP; - } - else - { - ent->client->flags &= ~Game::PLAYER_FLAG_NOCLIP; - } - } - else - { - ent->client->flags ^= Game::PLAYER_FLAG_NOCLIP; - } - }); - - Script::AddMethod("Ufo", [](Game::scr_entref_t entref) // gsc: iw4x_Ufo(); - { - const auto* ent = Game::GetPlayerEntity(entref); - - if (Game::Scr_GetNumParam() >= 1) - { - if (Game::Scr_GetInt(0)) - { - ent->client->flags |= Game::PLAYER_FLAG_UFO; - } - else - { - ent->client->flags &= ~Game::PLAYER_FLAG_UFO; - } - } - else - { - ent->client->flags ^= Game::PLAYER_FLAG_UFO; - } - }); - - Script::AddMethod("God", [](Game::scr_entref_t entref) // gsc: iw4x_God(); + Script::AddMethod("God", [](Game::scr_entref_t entref) // gsc: God(); { auto* ent = Game::GetEntity(entref); @@ -414,7 +372,7 @@ namespace Components } }); - Script::AddMethod("Demigod", [](Game::scr_entref_t entref) // gsc: iw4x_Demigod(); + Script::AddMethod("Demigod", [](Game::scr_entref_t entref) // gsc: Demigod(); { auto* ent = Game::GetEntity(entref); @@ -435,7 +393,7 @@ namespace Components } }); - Script::AddMethod("Notarget", [](Game::scr_entref_t entref) // gsc: iw4x_Notarget(); + Script::AddMethod("Notarget", [](Game::scr_entref_t entref) // gsc: Notarget(); { auto* ent = Game::GetEntity(entref); @@ -456,7 +414,7 @@ namespace Components } }); - Script::AddFunction("DropAllBots", [] // gsc: iw4x_DropAllBots(); + Script::AddFunction("DropAllBots", [] // gsc: DropAllBots(); { Game::SV_DropAllBots(); }); diff --git a/src/Components/Modules/GSC/IO.cpp b/src/Components/Modules/GSC/IO.cpp index 2eaa1203..159944eb 100644 --- a/src/Components/Modules/GSC/IO.cpp +++ b/src/Components/Modules/GSC/IO.cpp @@ -8,7 +8,7 @@ namespace Components void IO::AddScriptFunctions() { - Script::AddFunction("FileWrite", [] // gsc: iw4x_FileWrite(, , ) + Script::AddFunction("FileWrite", [] // gsc: FileWrite(, , ) { const auto* path = Game::Scr_GetString(0); auto* text = Game::Scr_GetString(1); @@ -53,7 +53,7 @@ namespace Components } }); - Script::AddFunction("FileRead", [] // gsc: iw4x_FileRead() + Script::AddFunction("FileRead", [] // gsc: FileRead() { const auto* path = Game::Scr_GetString(0); @@ -83,7 +83,7 @@ namespace Components Game::Scr_AddString(FileSystem::FileReader(scriptData).getBuffer().data()); }); - Script::AddFunction("FileExists", [] // gsc: iw4x_FileExists() + Script::AddFunction("FileExists", [] // gsc: FileExists() { const auto* path = Game::Scr_GetString(0); diff --git a/src/Components/Modules/GSC/Script.cpp b/src/Components/Modules/GSC/Script.cpp index 1ca8c235..683e1ede 100644 --- a/src/Components/Modules/GSC/Script.cpp +++ b/src/Components/Modules/GSC/Script.cpp @@ -6,33 +6,6 @@ namespace Components std::unordered_map Script::CustomScrFunctions; std::unordered_map Script::CustomScrMethods; - // This was added on the 17th of July 2022 to help transition current mods to - // the new prefixed functions. Look at the clock! If it's more than three months - // later than this date... remove this! - std::unordered_set Script::DeprecatedFunctionsAndMethods = - { - "isbot", - "istestclient", - "botstop", - "botweapon", - "botmovement", - "botaction", - "onplayersay", - "fileread", - "filewrite", - "fileexists", - "getsystemmilliseconds", - "exec", - "printconsole", - "arecontrolsfrozen", - "setping", - "setname", - "resetname", - "dropallbots", - "httpget", - "httpcancel" - }; - std::string Script::ScriptName; std::vector Script::ScriptNameStack; unsigned short Script::FunctionName; @@ -303,48 +276,28 @@ namespace Components void Script::AddFunction(const std::string& name, Game::BuiltinFunction func, bool type) { - const auto functionName = Script::ClientPrefix + name; - Script::ScriptFunction toAdd; toAdd.actionFunc = func; toAdd.type = type; - CustomScrFunctions.insert_or_assign(Utils::String::ToLower(functionName), toAdd); + CustomScrFunctions.insert_or_assign(Utils::String::ToLower(name), toAdd); } void Script::AddMethod(const std::string& name, Game::BuiltinMethod func, bool type) { - const auto functionName = Script::ClientPrefix + name; - Script::ScriptMethod toAdd; toAdd.actionFunc = func; toAdd.type = type; - CustomScrMethods.insert_or_assign(Utils::String::ToLower(functionName), toAdd); - } - - bool Script::IsDeprecated(const std::string& name) - { - return Script::DeprecatedFunctionsAndMethods.contains(name); + CustomScrMethods.insert_or_assign(Utils::String::ToLower(name), toAdd); } Game::BuiltinFunction Script::BuiltIn_GetFunctionStub(const char** pName, int* type) { if (pName != nullptr) { - auto name = Utils::String::ToLower(*pName); + const auto got = Script::CustomScrFunctions.find(Utils::String::ToLower(*pName)); - if (IsDeprecated(name)) - { - Toast::Show("cardicon_gumby", "WARNING!", std::format("{} uses the deprecated function {}", Script::ScriptName, name), 2048); - Logger::Print(Game::CON_CHANNEL_PARSERSCRIPT, "*** DEPRECATION WARNING ***\n"); - Logger::PrintError(Game::CON_CHANNEL_ERROR, "Attempted to execute deprecated builtin {} from {}! This method or function should be prefixed with '{}'. Please update your mod!\n", name, Script::ScriptName, Script::ClientPrefix); - Logger::Print(Game::CON_CHANNEL_PARSERSCRIPT, "***************************\n"); - - name = Script::ClientPrefix + name; // Fixes it automatically - } - - const auto got = Script::CustomScrFunctions.find(name); // If no function was found let's call game's function if (got != Script::CustomScrFunctions.end()) { @@ -367,20 +320,8 @@ namespace Components { if (pName != nullptr) { - auto name = Utils::String::ToLower(*pName); + const auto got = Script::CustomScrMethods.find(Utils::String::ToLower(*pName)); - if (IsDeprecated(name)) - { - Toast::Show("cardicon_gumby", "WARNING!", std::format("{} uses the deprecated method {}", Script::ScriptName, name), 2048); - Logger::Print(Game::CON_CHANNEL_PARSERSCRIPT, "*** DEPRECATION WARNING ***\n"); - Logger::PrintError(Game::CON_CHANNEL_ERROR, "Attempted to execute deprecated builtin {} from {}! This function or method should be prefixed with '{}'. Please update your mod!\n", name, Script::ScriptName, Script::ClientPrefix); - Logger::Print(Game::CON_CHANNEL_PARSERSCRIPT, "***************************\n"); - - name = Script::ClientPrefix + name; // Fixes it automatically - - } - - const auto got = Script::CustomScrMethods.find(name); // If no method was found let's call game's function if (got != Script::CustomScrMethods.end()) { @@ -596,7 +537,7 @@ namespace Components void Script::AddFunctions() { - Script::AddFunction("ReplaceFunc", [] // gsc: iw4x_ReplaceFunc(, ) + Script::AddFunction("ReplaceFunc", [] // gsc: ReplaceFunc(, ) { if (Game::Scr_GetNumParam() != 2) { @@ -611,7 +552,7 @@ namespace Components }); // System time - Script::AddFunction("GetSystemMilliseconds", [] // gsc: iw4x_GetSystemMilliseconds() + Script::AddFunction("GetSystemMilliseconds", [] // gsc: GetSystemMilliseconds() { SYSTEMTIME time; GetSystemTime(&time); @@ -620,7 +561,7 @@ namespace Components }); // Executes command to the console - Script::AddFunction("Exec", [] // gsc: iw4x_Exec() + Script::AddFunction("Exec", [] // gsc: Exec() { const auto str = Game::Scr_GetString(0); @@ -634,7 +575,7 @@ namespace Components }); // Allow printing to the console even when developer is 0 - Script::AddFunction("PrintConsole", [] // gsc: iw4x_PrintConsole() + Script::AddFunction("PrintConsole", [] // gsc: PrintConsole() { for (std::size_t i = 0; i < Game::Scr_GetNumParam(); ++i) { @@ -651,7 +592,7 @@ namespace Components }); // PlayerCmd_AreControlsFrozen GSC function from Black Ops 2 - Script::AddMethod("AreControlsFrozen", [](Game::scr_entref_t entref) // Usage: self iw4x_AreControlsFrozen(); + Script::AddMethod("AreControlsFrozen", [](Game::scr_entref_t entref) // Usage: self AreControlsFrozen(); { const auto* ent = Game::GetPlayerEntity(entref); diff --git a/src/Components/Modules/GSC/Script.hpp b/src/Components/Modules/GSC/Script.hpp index f92d9f3a..0b585d94 100644 --- a/src/Components/Modules/GSC/Script.hpp +++ b/src/Components/Modules/GSC/Script.hpp @@ -27,10 +27,8 @@ namespace Components bool type; }; - static constexpr auto* ClientPrefix = "iw4x_"; static std::unordered_map CustomScrFunctions; static std::unordered_map CustomScrMethods; - static std::unordered_set DeprecatedFunctionsAndMethods; static std::string ScriptName; static std::vector ScriptNameStack; diff --git a/src/Components/Modules/GSC/ScriptExtension.cpp b/src/Components/Modules/GSC/ScriptExtension.cpp index 411282dc..fbcc8f06 100644 --- a/src/Components/Modules/GSC/ScriptExtension.cpp +++ b/src/Components/Modules/GSC/ScriptExtension.cpp @@ -116,7 +116,7 @@ namespace Components void ScriptExtension::AddFunctions() { // Misc functions - Script::AddFunction("ToUpper", [] // gsc: iw4x_ToUpper() + Script::AddFunction("ToUpper", [] // gsc: ToUpper() { const auto scriptValue = Game::Scr_GetConstString(0); const auto* string = Game::SL_ConvertToString(scriptValue); @@ -161,7 +161,7 @@ namespace Components }); // Func present on IW5 - Script::AddFunction("StrICmp", [] // gsc: iw4x_StrICmp(, ) + Script::AddFunction("StrICmp", [] // gsc: StrICmp(, ) { const auto value1 = Game::Scr_GetConstString(0); const auto value2 = Game::Scr_GetConstString(1); @@ -173,7 +173,7 @@ namespace Components }); // Func present on IW5 - Script::AddFunction("IsEndStr", [] // gsc: iw4x_IsEndStr(, ) + Script::AddFunction("IsEndStr", [] // gsc: IsEndStr(, ) { const auto* s1 = Game::Scr_GetString(0); const auto* s2 = Game::Scr_GetString(1); @@ -187,7 +187,7 @@ namespace Components Game::Scr_AddBool(Utils::String::EndsWith(s1, s2)); }); - Script::AddFunction("IsArray", [] // gsc: iw4x_IsArray() + Script::AddFunction("IsArray", [] // gsc: IsArray() { auto type = Game::Scr_GetType(0); @@ -211,7 +211,7 @@ namespace Components void ScriptExtension::AddMethods() { // ScriptExtension methods - Script::AddMethod("GetIp", [](Game::scr_entref_t entref) // gsc: self iw4x_GetIp() + Script::AddMethod("GetIp", [](Game::scr_entref_t entref) // gsc: self GetIp() { const auto* ent = Game::GetPlayerEntity(entref); const auto* client = Script::GetClient(ent); @@ -224,7 +224,7 @@ namespace Components Game::Scr_AddString(ip.data()); }); - Script::AddMethod("GetPing", [](Game::scr_entref_t entref) // gsc: self iw4x_GetPing() + Script::AddMethod("GetPing", [](Game::scr_entref_t entref) // gsc: self GetPing() { const auto* ent = Game::GetPlayerEntity(entref); const auto* client = Script::GetClient(ent); @@ -232,7 +232,7 @@ namespace Components Game::Scr_AddInt(client->ping); }); - Script::AddMethod("SetPing", [](Game::scr_entref_t entref) // gsc: self iw4x_SetPing() + Script::AddMethod("SetPing", [](Game::scr_entref_t entref) // gsc: self SetPing() { auto ping = Game::Scr_GetInt(0); diff --git a/src/Components/Modules/GSC/ScriptStorage.cpp b/src/Components/Modules/GSC/ScriptStorage.cpp index 8a1c47c1..b169d1ea 100644 --- a/src/Components/Modules/GSC/ScriptStorage.cpp +++ b/src/Components/Modules/GSC/ScriptStorage.cpp @@ -8,7 +8,7 @@ namespace Components void ScriptStorage::AddScriptFunctions() { - Script::AddFunction("StorageSet", [] // gsc: iw4x_StorageSet(, ); + Script::AddFunction("StorageSet", [] // gsc: StorageSet(, ); { const auto* key = Game::Scr_GetString(0); const auto* value = Game::Scr_GetString(1); @@ -22,7 +22,7 @@ namespace Components Data.insert_or_assign(key, value); }); - Script::AddFunction("StorageRemove", [] // gsc: iw4x_StorageRemove(); + Script::AddFunction("StorageRemove", [] // gsc: StorageRemove(); { const auto* key = Game::Scr_GetString(0); @@ -41,7 +41,7 @@ namespace Components Data.erase(key); }); - Script::AddFunction("StorageGet", [] // gsc: iw4x_StorageGet(); + Script::AddFunction("StorageGet", [] // gsc: StorageGet(); { const auto* key = Game::Scr_GetString(0); @@ -61,7 +61,7 @@ namespace Components Game::Scr_AddString(data.data()); }); - Script::AddFunction("StorageHas", [] // gsc: iw4x_StorageHas(); + Script::AddFunction("StorageHas", [] // gsc: StorageHas(); { const auto* key = Game::Scr_GetString(0); @@ -74,7 +74,7 @@ namespace Components Game::Scr_AddBool(Data.contains(key)); }); - Script::AddFunction("StorageDump", [] // gsc: iw4x_StorageDump(); + Script::AddFunction("StorageDump", [] // gsc: StorageDump(); { if (Data.empty()) { @@ -87,7 +87,7 @@ namespace Components FileSystem::FileWriter("scriptdata/scriptstorage.json").write(json.dump()); }); - Script::AddFunction("StorageClear", [] // gsc: iw4x_StorageClear(); + Script::AddFunction("StorageClear", [] // gsc: StorageClear(); { Data.clear(); }); diff --git a/src/Components/Modules/UserInfo.cpp b/src/Components/Modules/UserInfo.cpp index 39b6cd63..ab425dda 100644 --- a/src/Components/Modules/UserInfo.cpp +++ b/src/Components/Modules/UserInfo.cpp @@ -44,7 +44,7 @@ namespace Components void UserInfo::AddScriptMethods() { - Script::AddMethod("SetName", [](Game::scr_entref_t entref) // gsc: self iw4x_SetName() + Script::AddMethod("SetName", [](Game::scr_entref_t entref) // gsc: self SetName() { const auto* ent = Game::GetPlayerEntity(entref); const auto* name = Game::Scr_GetString(0); @@ -60,7 +60,7 @@ namespace Components Game::ClientUserinfoChanged(ent->s.number); }); - Script::AddMethod("ResetName", [](Game::scr_entref_t entref) // gsc: self iw4x_ResetName() + Script::AddMethod("ResetName", [](Game::scr_entref_t entref) // gsc: self ResetName() { const auto* ent = Game::GetPlayerEntity(entref); @@ -69,7 +69,7 @@ namespace Components Game::ClientUserinfoChanged(ent->s.number); }); - Script::AddMethod("SetClanTag", [](Game::scr_entref_t entref) // gsc: self iw4x_setClanTag() + Script::AddMethod("SetClanTag", [](Game::scr_entref_t entref) // gsc: self SetClanTag() { const auto* ent = Game::GetPlayerEntity(entref); const auto* clanName = Game::Scr_GetString(0); @@ -85,7 +85,7 @@ namespace Components Game::ClientUserinfoChanged(ent->s.number); }); - Script::AddMethod("ResetClanTag", [](Game::scr_entref_t entref) // gsc: self iw4x_ResetClanTag() + Script::AddMethod("ResetClanTag", [](Game::scr_entref_t entref) // gsc: self ResetClanTag() { const auto* ent = Game::GetPlayerEntity(entref); diff --git a/src/Game/Structs.hpp b/src/Game/Structs.hpp index c57e84f6..0d6b250b 100644 --- a/src/Game/Structs.hpp +++ b/src/Game/Structs.hpp @@ -6246,7 +6246,7 @@ namespace Game static_assert(sizeof(gentity_s) == 0x274); - enum $1C4253065710F064DA9E4D59ED6EC544 + enum { ENTFIELD_ENTITY = 0x0, ENTFIELD_SENTIENT = 0x2000,