Fix a typo in stub & clean-up some things
This commit is contained in:
parent
9e207b3c9a
commit
0068b76d98
@ -264,7 +264,7 @@ namespace Components
|
||||
}
|
||||
|
||||
constexpr auto SV_BotUserMove = 0x626E50;
|
||||
__declspec(naked) void Bots::SV_UpdateBots_Hk()
|
||||
__declspec(naked) void Bots::SV_BotUserMove_Hk()
|
||||
{
|
||||
__asm
|
||||
{
|
||||
@ -302,8 +302,8 @@ namespace Components
|
||||
// Intercept sprintf for the connect string
|
||||
Utils::Hook(0x48ADAB, Bots::BuildConnectString, HOOK_CALL).install()->quick();
|
||||
|
||||
Utils::Hook(0x627021, Bots::SV_UpdateBots_Hk, HOOK_CALL).install()->quick();
|
||||
Utils::Hook(0x627241, Bots::SV_UpdateBots_Hk, HOOK_CALL).install()->quick();
|
||||
Utils::Hook(0x627021, Bots::SV_BotUserMove_Hk, HOOK_CALL).install()->quick();
|
||||
Utils::Hook(0x627241, Bots::SV_BotUserMove_Hk, HOOK_CALL).install()->quick();
|
||||
|
||||
// Zero the bot command array
|
||||
for (auto i = 0u; i < std::extent_v<decltype(g_botai)>; i++)
|
||||
|
@ -32,6 +32,6 @@ namespace Components
|
||||
static void AddMethods();
|
||||
|
||||
static void BotAiAction(Game::client_t* cl);
|
||||
static void SV_UpdateBots_Hk();
|
||||
static void SV_BotUserMove_Hk();
|
||||
};
|
||||
}
|
||||
|
@ -28,10 +28,11 @@ namespace Components
|
||||
bool ClientCommand::CallbackHandler(Game::gentity_s* ent, const char* cmd)
|
||||
{
|
||||
const auto command = Utils::String::ToLower(cmd);
|
||||
const auto got = ClientCommand::FunctionMap.find(command);
|
||||
|
||||
if (ClientCommand::FunctionMap.find(command) != ClientCommand::FunctionMap.end())
|
||||
if (got != ClientCommand::FunctionMap.end())
|
||||
{
|
||||
ClientCommand::FunctionMap[command](ent);
|
||||
got->second(ent);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -42,7 +43,7 @@ namespace Components
|
||||
{
|
||||
const auto command = Utils::String::ToLower(name);
|
||||
|
||||
ClientCommand::FunctionMap[command] = callback;
|
||||
ClientCommand::FunctionMap[command] = std::move(callback);
|
||||
}
|
||||
|
||||
void ClientCommand::ClientCommandStub(const int clientNum)
|
||||
|
@ -966,7 +966,7 @@ namespace Components
|
||||
|
||||
Script::AddFunction("HttpGet", [](Game::scr_entref_t)
|
||||
{
|
||||
if (!Dedicated::IsEnabled() && !Flags::HasFlag("scriptablehttp"))
|
||||
if (!Flags::HasFlag("scriptablehttp"))
|
||||
return;
|
||||
|
||||
const auto* url = Game::Scr_GetString(0);
|
||||
@ -987,7 +987,7 @@ namespace Components
|
||||
|
||||
Script::AddFunction("HttpCancel", [](Game::scr_entref_t)
|
||||
{
|
||||
if (!Dedicated::IsEnabled() && !Flags::HasFlag("scriptablehttp"))
|
||||
if (!Flags::HasFlag("scriptablehttp"))
|
||||
return;
|
||||
|
||||
const auto object = Game::Scr_GetObject(0);
|
||||
|
@ -60,18 +60,16 @@ namespace Components
|
||||
if (Game::scrVmPub->debugCode || Game::scrVarPub->developer_script)
|
||||
{
|
||||
Game::RuntimeErrorInternal(23, codePos, index, msg);
|
||||
|
||||
if (!Game::scrVmPub->terminal_error)
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger::Print(23, "%s\n", msg);
|
||||
// Let's not throw error unless we have to
|
||||
if (Game::scrVmPub->abort_on_error && !Game::scrVmPub->terminal_error)
|
||||
return;
|
||||
}
|
||||
|
||||
// Let's not throw error unless we have to
|
||||
if (!Game::scrVmPub->abort_on_error)
|
||||
return;
|
||||
|
||||
if (dialogMessage == nullptr)
|
||||
dialogMessage = "";
|
||||
|
||||
@ -222,7 +220,7 @@ namespace Components
|
||||
}
|
||||
|
||||
Logger::Print("Finding script handle %s::%s...\n", script.data(), label.data());
|
||||
int handle = Game::Scr_GetFunctionHandle(script.data(), label.data());
|
||||
const auto handle = Game::Scr_GetFunctionHandle(script.data(), label.data());
|
||||
if (handle)
|
||||
{
|
||||
Logger::Print("Script handle %s::%s loaded successfully.\n", script.data(), label.data());
|
||||
@ -235,7 +233,7 @@ namespace Components
|
||||
|
||||
void Script::LoadGameType()
|
||||
{
|
||||
for (auto handle : Script::ScriptHandles)
|
||||
for (const auto& handle : Script::ScriptHandles)
|
||||
{
|
||||
Game::Scr_FreeThread(Game::Scr_ExecThread(handle, 0));
|
||||
}
|
||||
@ -247,7 +245,7 @@ namespace Components
|
||||
{
|
||||
Script::ScriptHandles.clear();
|
||||
|
||||
auto list = FileSystem::GetFileList("scripts/", "gsc");
|
||||
const auto list = FileSystem::GetFileList("scripts/", "gsc");
|
||||
|
||||
for (auto file : list)
|
||||
{
|
||||
@ -258,8 +256,12 @@ namespace Components
|
||||
file = file.substr(0, file.size() - 4);
|
||||
}
|
||||
|
||||
int handle = Script::LoadScriptAndLabel(file, "init");
|
||||
if (handle) Script::ScriptHandles.push_back(handle);
|
||||
auto handle = Script::LoadScriptAndLabel(file, "init");
|
||||
|
||||
if (handle)
|
||||
{
|
||||
Script::ScriptHandles.push_back(handle);
|
||||
}
|
||||
else
|
||||
{
|
||||
handle = Script::LoadScriptAndLabel(file, "main");
|
||||
@ -339,7 +341,7 @@ namespace Components
|
||||
|
||||
for (const auto& [key, value] : Script::ScriptBaseProgramNum)
|
||||
{
|
||||
int codePos = key;
|
||||
const auto codePos = key;
|
||||
|
||||
if (codePos > scriptPos)
|
||||
{
|
||||
@ -403,7 +405,7 @@ namespace Components
|
||||
void Script::OnVMShutdown(Utils::Slot<Scheduler::Callback> callback)
|
||||
{
|
||||
Script::ScriptBaseProgramNum.clear();
|
||||
Script::VMShutdownSignal.connect(callback);
|
||||
Script::VMShutdownSignal.connect(std::move(callback));
|
||||
}
|
||||
|
||||
void Script::ScrShutdownSystemStub(int num)
|
||||
@ -460,7 +462,7 @@ namespace Components
|
||||
{
|
||||
if (what[0] == '\0' || with[0] == '\0')
|
||||
{
|
||||
Logger::Print("Warning: Invalid paramters passed to ReplacedFunctions\n");
|
||||
Logger::Print("Warning: Invalid parameters passed to ReplacedFunctions\n");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -600,7 +602,7 @@ namespace Components
|
||||
}
|
||||
});
|
||||
|
||||
// Script Storage Funcs
|
||||
// Script Storage Functions
|
||||
Script::AddFunction("StorageSet", [](Game::scr_entref_t) // gsc: StorageSet(<str key>, <str data>);
|
||||
{
|
||||
const auto* key = Game::Scr_GetString(0);
|
||||
@ -664,7 +666,7 @@ namespace Components
|
||||
return;
|
||||
}
|
||||
|
||||
Game::Scr_AddBool(Script::ScriptStorage.count(key));
|
||||
Game::Scr_AddBool(static_cast<int>(Script::ScriptStorage.count(key))); // Until C++17
|
||||
});
|
||||
|
||||
Script::AddFunction("StorageClear", [](Game::scr_entref_t) // gsc: StorageClear();
|
||||
@ -719,11 +721,12 @@ namespace Components
|
||||
if (!Game::SV_Loaded())
|
||||
return;
|
||||
|
||||
int nowMs = Game::Sys_Milliseconds();
|
||||
const auto nowMs = Game::Sys_Milliseconds();
|
||||
|
||||
if (Script::LastFrameTime != -1)
|
||||
{
|
||||
int timeTaken = static_cast<int>((nowMs - Script::LastFrameTime) * Dvar::Var("timescale").get<float>());
|
||||
const auto timeScale = Dvar::Var("timescale").get<float>();
|
||||
const auto timeTaken = static_cast<int>((nowMs - Script::LastFrameTime) * timeScale);
|
||||
|
||||
if (timeTaken >= 500)
|
||||
Logger::Print(23, "Hitch warning: %i msec frame time\n", timeTaken);
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
namespace Components
|
||||
{
|
||||
static const char* queryStrings[] = { R"(..)", R"(../)", R"(..\)" };
|
||||
const char* ScriptExtension::QueryStrings[] = { R"(..)", R"(../)", R"(..\)" };
|
||||
|
||||
void ScriptExtension::AddFunctions()
|
||||
{
|
||||
@ -26,16 +26,16 @@ namespace Components
|
||||
return;
|
||||
}
|
||||
|
||||
for (auto i = 0u; i < ARRAYSIZE(queryStrings); ++i)
|
||||
for (auto i = 0u; i < ARRAYSIZE(ScriptExtension::QueryStrings); ++i)
|
||||
{
|
||||
if (std::strstr(path, queryStrings[i]) != nullptr)
|
||||
if (std::strstr(path, ScriptExtension::QueryStrings[i]) != nullptr)
|
||||
{
|
||||
Logger::Print("^1FileWrite: directory traversal is not allowed!\n");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (mode != "append"s && mode != "write"s)
|
||||
if (mode != "append" && mode != "write")
|
||||
{
|
||||
Logger::Print("^3FileWrite: mode not defined or was wrong, defaulting to 'write'\n");
|
||||
mode = "write";
|
||||
@ -61,9 +61,9 @@ namespace Components
|
||||
return;
|
||||
}
|
||||
|
||||
for (auto i = 0u; i < ARRAYSIZE(queryStrings); ++i)
|
||||
for (auto i = 0u; i < ARRAYSIZE(ScriptExtension::QueryStrings); ++i)
|
||||
{
|
||||
if (std::strstr(path, queryStrings[i]) != nullptr)
|
||||
if (std::strstr(path, ScriptExtension::QueryStrings[i]) != nullptr)
|
||||
{
|
||||
Logger::Print("^1FileRead: directory traversal is not allowed!\n");
|
||||
return;
|
||||
@ -89,9 +89,9 @@ namespace Components
|
||||
return;
|
||||
}
|
||||
|
||||
for (auto i = 0u; i < ARRAYSIZE(queryStrings); ++i)
|
||||
for (auto i = 0u; i < ARRAYSIZE(ScriptExtension::QueryStrings); ++i)
|
||||
{
|
||||
if (std::strstr(path, queryStrings[i]) != nullptr)
|
||||
if (std::strstr(path, ScriptExtension::QueryStrings[i]) != nullptr)
|
||||
{
|
||||
Logger::Print("^1FileExists: directory traversal is not allowed!\n");
|
||||
return;
|
||||
@ -111,9 +111,9 @@ namespace Components
|
||||
return;
|
||||
}
|
||||
|
||||
for (auto i = 0u; i < ARRAYSIZE(queryStrings); ++i)
|
||||
for (auto i = 0u; i < ARRAYSIZE(ScriptExtension::QueryStrings); ++i)
|
||||
{
|
||||
if (std::strstr(path, queryStrings[i]) != nullptr)
|
||||
if (std::strstr(path, ScriptExtension::QueryStrings[i]) != nullptr)
|
||||
{
|
||||
Logger::Print("^1fileRemove: directory traversal is not allowed!\n");
|
||||
return;
|
||||
@ -137,9 +137,7 @@ namespace Components
|
||||
|
||||
std::string ip = Game::NET_AdrToString(client->netchan.remoteAddress);
|
||||
|
||||
const auto pos = ip.find_first_of(":");
|
||||
|
||||
if (pos != std::string::npos)
|
||||
if (const auto pos = ip.find_first_of(":"); pos != std::string::npos)
|
||||
ip.erase(ip.begin() + pos, ip.end()); // Erase port
|
||||
|
||||
Game::Scr_AddString(ip.data());
|
||||
|
@ -8,6 +8,7 @@ namespace Components
|
||||
ScriptExtension();
|
||||
|
||||
private:
|
||||
static const char* QueryStrings[];
|
||||
|
||||
static void AddFunctions();
|
||||
static void AddMethods();
|
||||
|
@ -681,7 +681,7 @@ namespace Game
|
||||
typedef unsigned int(__cdecl * Scr_GetNumParam_t)();
|
||||
extern Scr_GetNumParam_t Scr_GetNumParam;
|
||||
|
||||
typedef int(__cdecl * Scr_GetFunctionHandle_t)(const char*, const char*);
|
||||
typedef int(__cdecl * Scr_GetFunctionHandle_t)(const char* filename, const char* name);
|
||||
extern Scr_GetFunctionHandle_t Scr_GetFunctionHandle;
|
||||
|
||||
typedef int(__cdecl * Scr_ExecThread_t)(int, int);
|
||||
|
Loading…
x
Reference in New Issue
Block a user