Merge pull request #387 from diamante0018/script-unfix-the-not-fix

[Script] *Update*
This commit is contained in:
Dss0 2022-07-23 23:39:56 +02:00 committed by GitHub
commit 49cd8039c5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 41 additions and 144 deletions

View File

@ -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: <bot> iw4x_BotStop();
Script::AddMethod("BotStop", [](Game::scr_entref_t entref) // Usage: <bot> 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: <bot> iw4x_BotWeapon(<str>);
Script::AddMethod("BotWeapon", [](Game::scr_entref_t entref) // Usage: <bot> BotWeapon(<str>);
{
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: <bot> iw4x_BotAction(<str action>);
Script::AddMethod("BotAction", [](Game::scr_entref_t entref) // Usage: <bot> BotAction(<str action>);
{
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: <bot> iw4x_BotMovement(<int>, <int>);
Script::AddMethod("BotMovement", [](Game::scr_entref_t entref) // Usage: <bot> BotMovement(<int>, <int>);
{
const auto* ent = Game::GetPlayerEntity(entref);

View File

@ -389,7 +389,7 @@ namespace Components
void Chat::AddScriptFunctions()
{
Script::AddFunction("OnPlayerSay", [] // gsc: iw4x_OnPlayerSay(<function>)
Script::AddFunction("OnPlayerSay", [] // gsc: OnPlayerSay(<function>)
{
if (Game::Scr_GetNumParam() != 1)
{

View File

@ -351,49 +351,7 @@ namespace Components
void ClientCommand::AddScriptFunctions()
{
Script::AddMethod("Noclip", [](Game::scr_entref_t entref) // gsc: iw4x_Noclip(<optional int toggle>);
{
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(<optional int toggle>);
{
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(<optional int toggle>);
Script::AddMethod("God", [](Game::scr_entref_t entref) // gsc: God(<optional int toggle>);
{
auto* ent = Game::GetEntity(entref);
@ -414,7 +372,7 @@ namespace Components
}
});
Script::AddMethod("Demigod", [](Game::scr_entref_t entref) // gsc: iw4x_Demigod(<optional int toggle>);
Script::AddMethod("Demigod", [](Game::scr_entref_t entref) // gsc: Demigod(<optional int toggle>);
{
auto* ent = Game::GetEntity(entref);
@ -435,7 +393,7 @@ namespace Components
}
});
Script::AddMethod("Notarget", [](Game::scr_entref_t entref) // gsc: iw4x_Notarget(<optional int toggle>);
Script::AddMethod("Notarget", [](Game::scr_entref_t entref) // gsc: Notarget(<optional int toggle>);
{
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();
});

View File

@ -8,7 +8,7 @@ namespace Components
void IO::AddScriptFunctions()
{
Script::AddFunction("FileWrite", [] // gsc: iw4x_FileWrite(<filepath>, <string>, <mode>)
Script::AddFunction("FileWrite", [] // gsc: FileWrite(<filepath>, <string>, <mode>)
{
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(<filepath>)
Script::AddFunction("FileRead", [] // gsc: FileRead(<filepath>)
{
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(<filepath>)
Script::AddFunction("FileExists", [] // gsc: FileExists(<filepath>)
{
const auto* path = Game::Scr_GetString(0);

View File

@ -6,33 +6,6 @@ namespace Components
std::unordered_map<std::string, Script::ScriptFunction> Script::CustomScrFunctions;
std::unordered_map<std::string, Script::ScriptMethod> 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<std::string_view> 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<std::string> 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(<function>, <function>)
Script::AddFunction("ReplaceFunc", [] // gsc: ReplaceFunc(<function>, <function>)
{
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(<string>)
Script::AddFunction("Exec", [] // gsc: Exec(<string>)
{
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(<string>)
Script::AddFunction("PrintConsole", [] // gsc: PrintConsole(<string>)
{
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);

View File

@ -27,10 +27,8 @@ namespace Components
bool type;
};
static constexpr auto* ClientPrefix = "iw4x_";
static std::unordered_map<std::string, ScriptFunction> CustomScrFunctions;
static std::unordered_map<std::string, ScriptMethod> CustomScrMethods;
static std::unordered_set<std::string_view> DeprecatedFunctionsAndMethods;
static std::string ScriptName;
static std::vector<std::string> ScriptNameStack;

View File

@ -116,7 +116,7 @@ namespace Components
void ScriptExtension::AddFunctions()
{
// Misc functions
Script::AddFunction("ToUpper", [] // gsc: iw4x_ToUpper(<string>)
Script::AddFunction("ToUpper", [] // gsc: ToUpper(<string>)
{
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(<string>, <string>)
Script::AddFunction("StrICmp", [] // gsc: StrICmp(<string>, <string>)
{
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(<string>, <string>)
Script::AddFunction("IsEndStr", [] // gsc: IsEndStr(<string>, <string>)
{
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(<object>)
Script::AddFunction("IsArray", [] // gsc: IsArray(<object>)
{
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(<int>)
Script::AddMethod("SetPing", [](Game::scr_entref_t entref) // gsc: self SetPing(<int>)
{
auto ping = Game::Scr_GetInt(0);

View File

@ -8,7 +8,7 @@ namespace Components
void ScriptStorage::AddScriptFunctions()
{
Script::AddFunction("StorageSet", [] // gsc: iw4x_StorageSet(<str key>, <str data>);
Script::AddFunction("StorageSet", [] // gsc: StorageSet(<str key>, <str data>);
{
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(<str key>);
Script::AddFunction("StorageRemove", [] // gsc: StorageRemove(<str key>);
{
const auto* key = Game::Scr_GetString(0);
@ -41,7 +41,7 @@ namespace Components
Data.erase(key);
});
Script::AddFunction("StorageGet", [] // gsc: iw4x_StorageGet(<str key>);
Script::AddFunction("StorageGet", [] // gsc: StorageGet(<str key>);
{
const auto* key = Game::Scr_GetString(0);
@ -61,7 +61,7 @@ namespace Components
Game::Scr_AddString(data.data());
});
Script::AddFunction("StorageHas", [] // gsc: iw4x_StorageHas(<str key>);
Script::AddFunction("StorageHas", [] // gsc: StorageHas(<str key>);
{
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();
});

View File

@ -44,7 +44,7 @@ namespace Components
void UserInfo::AddScriptMethods()
{
Script::AddMethod("SetName", [](Game::scr_entref_t entref) // gsc: self iw4x_SetName(<string>)
Script::AddMethod("SetName", [](Game::scr_entref_t entref) // gsc: self SetName(<string>)
{
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(<string>)
Script::AddMethod("SetClanTag", [](Game::scr_entref_t entref) // gsc: self SetClanTag(<string>)
{
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);

View File

@ -6246,7 +6246,7 @@ namespace Game
static_assert(sizeof(gentity_s) == 0x274);
enum $1C4253065710F064DA9E4D59ED6EC544
enum
{
ENTFIELD_ENTITY = 0x0,
ENTFIELD_SENTIENT = 0x2000,