Merge branch 'develop' into refactor-scripts-stuff

This commit is contained in:
Edo 2022-02-26 23:30:58 +00:00 committed by GitHub
commit cbfd650f78
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
19 changed files with 98 additions and 87 deletions

2
deps/libtommath vendored

@ -1 +1 @@
Subproject commit bea9270646303baf683f4ba2ddf0d70721f0e55d
Subproject commit 04e9d1e7a0493910b2eb5e757d623870692ada04

View File

@ -8,7 +8,8 @@ namespace Components
Utils::Cryptography::Token Auth::ComputeToken;
Utils::Cryptography::ECC::Key Auth::GuidKey;
std::vector<std::uint64_t> Auth::BannedUids = {
std::vector<std::uint64_t> Auth::BannedUids =
{
0xf4d2c30b712ac6e3,
0xf7e33c4081337fa3,
0x6f5597f103cc50e9
@ -179,8 +180,8 @@ namespace Components
Utils::InfoString infostr(params[2]);
// Read the required data
std::string steamId = infostr.get("xuid");
std::string challenge = infostr.get("challenge");
const auto& steamId = infostr.get("xuid");
const auto& challenge = infostr.get("challenge");
if (steamId.empty() || challenge.empty())
{
@ -189,12 +190,12 @@ namespace Components
}
// Parse the id
unsigned __int64 xuid = strtoull(steamId.data(), nullptr, 16);
const auto xuid = std::strtoull(steamId.data(), nullptr, 16);
SteamID guid;
guid.bits = xuid;
if (Bans::IsBanned({ guid, address.getIP() }))
if (Bans::IsBanned({guid, address.getIP()}))
{
Network::Send(address, "error\nEXE_ERR_BANNED_PERM");
return;
@ -223,8 +224,8 @@ namespace Components
}
// Verify the security level
uint32_t ourLevel = static_cast<uint32_t>(Dvar::Var("sv_securityLevel").get<int>());
uint32_t userLevel = Auth::GetZeroBits(connectData.token(), connectData.publickey());
auto ourLevel = Dvar::Var("sv_securityLevel").get<unsigned int>();
auto userLevel = Auth::GetZeroBits(connectData.token(), connectData.publickey());
if (userLevel < ourLevel)
{

View File

@ -60,7 +60,7 @@ namespace Components
if (bots.exists())
{
auto names = Utils::String::Explode(bots.getBuffer(), '\n');
auto names = Utils::String::Split(bots.getBuffer(), '\n');
for (auto& name : names)
{

View File

@ -19,7 +19,7 @@ namespace Components
data = "^1Unable to get changelog.";
}
Changelog::Lines = Utils::String::Explode(data, '\n');
Changelog::Lines = Utils::String::Split(data, '\n');
for (auto& line : Changelog::Lines)
{

View File

@ -124,7 +124,7 @@ namespace Components
{
auto rotation = Dvar::Var("sv_mapRotation").get<std::string>();
const auto tokens = Utils::String::Explode(rotation, ' ');
const auto tokens = Utils::String::Split(rotation, ' ');
std::vector<std::pair<std::string, std::string>> mapRotationPair;
for (auto i = 0u; i < (tokens.size() - 1); i += 2)
@ -207,7 +207,7 @@ namespace Components
auto rotation = Dvar::Var("sv_mapRotationCurrent").get<std::string>();
auto tokens = Utils::String::Explode(rotation, ' ');
auto tokens = Utils::String::Split(rotation, ' ');
for (unsigned int i = 0; i < (tokens.size() - 1); i += 2)
{

View File

@ -9,11 +9,11 @@ namespace Components
{
this->dvar = Game::Dvar_FindVar(dvarName.data());
if (!this->dvar)
// If the dvar can't be found it will be registered as an empty string dvar
if (this->dvar == nullptr)
{
// Quick-register the dvar
Game::Dvar_SetStringByName(dvarName.data(), "");
this->dvar = Game::Dvar_FindVar(dvarName.data());
this->dvar = const_cast<Game::dvar_t*>(Game::Dvar_SetFromStringByNameFromSource(dvarName.data(), "",
Game::DvarSetSource::DVAR_SOURCE_INTERNAL));
}
}
@ -39,7 +39,10 @@ namespace Components
template <> int Dvar::Var::get()
{
if (this->dvar && this->dvar->type == Game::dvar_type::DVAR_TYPE_INT || this->dvar->type == Game::dvar_type::DVAR_TYPE_ENUM)
if (this->dvar == nullptr)
return 0;
if (this->dvar->type == Game::dvar_type::DVAR_TYPE_INT || this->dvar->type == Game::dvar_type::DVAR_TYPE_ENUM)
{
return this->dvar->current.integer;
}
@ -49,34 +52,52 @@ namespace Components
template <> unsigned int Dvar::Var::get()
{
return static_cast<unsigned int>(this->get<int>());
if (this->dvar == nullptr)
return 0u;
if (this->dvar->type == Game::dvar_type::DVAR_TYPE_INT)
{
return this->dvar->current.unsignedInt;
}
return 0u;
}
template <> float Dvar::Var::get()
{
if (this->dvar && this->dvar->type == Game::dvar_type::DVAR_TYPE_FLOAT)
if (this->dvar == nullptr)
return 0.f;
if (this->dvar->type == Game::dvar_type::DVAR_TYPE_FLOAT)
{
return this->dvar->current.value;
}
return 0;
return 0.f;
}
template <> float* Dvar::Var::get()
{
static float val[4] = { 0 };
static Game::vec4_t vector{ 0.f, 0.f, 0.f, 0.f };
if (this->dvar && (this->dvar->type == Game::dvar_type::DVAR_TYPE_FLOAT_2 || this->dvar->type == Game::dvar_type::DVAR_TYPE_FLOAT_3 || this->dvar->type == Game::dvar_type::DVAR_TYPE_FLOAT_4))
if (this->dvar == nullptr)
return vector;
if (this->dvar->type == Game::dvar_type::DVAR_TYPE_FLOAT_2 || this->dvar->type == Game::dvar_type::DVAR_TYPE_FLOAT_3
|| this->dvar->type == Game::dvar_type::DVAR_TYPE_FLOAT_4)
{
return this->dvar->current.vector;
}
return val;
return vector;
}
template <> bool Dvar::Var::get()
{
if (this->dvar && this->dvar->type == Game::dvar_type::DVAR_TYPE_BOOL)
if (this->dvar == nullptr)
return false;
if (this->dvar->type == Game::dvar_type::DVAR_TYPE_BOOL)
{
return this->dvar->current.enabled;
}
@ -89,11 +110,6 @@ namespace Components
return this->get<const char*>();
}
void Dvar::Var::set(char* string)
{
this->set(const_cast<const char*>(string));
}
void Dvar::Var::set(const char* string)
{
assert(this->dvar->type == Game::DVAR_TYPE_STRING);
@ -242,7 +258,7 @@ namespace Components
return Dvar::Register<const char*>(name, username.data(), Dvar::Flag(flag | Game::dvar_flag::DVAR_FLAG_SAVED).val, description).get<Game::dvar_t*>();
}
Game::dvar_t* Dvar::SetFromStringByNameSafeExternal(const char* dvar, const char* value)
void Dvar::SetFromStringByNameSafeExternal(const char* dvarName, const char* string)
{
static const char* exceptions[] =
{
@ -258,18 +274,19 @@ namespace Components
for (int i = 0; i < ARRAYSIZE(exceptions); ++i)
{
if (Utils::String::ToLower(dvar) == Utils::String::ToLower(exceptions[i]))
if (Utils::String::ToLower(dvarName) == Utils::String::ToLower(exceptions[i]))
{
return Game::Dvar_SetFromStringByName(dvar, value);
Game::Dvar_SetFromStringByNameFromSource(dvarName, string, Game::DvarSetSource::DVAR_SOURCE_INTERNAL);
return;
}
}
return Dvar::SetFromStringByNameExternal(dvar, value);
Dvar::SetFromStringByNameExternal(dvarName, string);
}
Game::dvar_t* Dvar::SetFromStringByNameExternal(const char* dvar, const char* value)
void Dvar::SetFromStringByNameExternal(const char* dvarName, const char* string)
{
return Game::Dvar_SetFromStringByNameFromSource(dvar, value, Game::DvarSetSource::DVAR_SOURCE_EXTERNAL);
Game::Dvar_SetFromStringByNameFromSource(dvarName, string, Game::DvarSetSource::DVAR_SOURCE_EXTERNAL);
}
void Dvar::SaveArchiveDvar(const Game::dvar_t* var)
@ -349,7 +366,7 @@ namespace Components
Utils::Hook(0x63CDB5, Dvar::SetFromStringByNameExternal, HOOK_CALL).install()->quick();
Utils::Hook(0x635E47, Dvar::SetFromStringByNameExternal, HOOK_CALL).install()->quick();
// SetDvar
// Script_SetDvar
Utils::Hook(0x63444C, Dvar::SetFromStringByNameSafeExternal, HOOK_CALL).install()->quick();
// Slider

View File

@ -18,14 +18,13 @@ namespace Components
{
public:
Var() : dvar(nullptr) {};
Var(const Var &obj) { this->dvar = obj.dvar; };
Var(const Var& obj) { this->dvar = obj.dvar; };
Var(Game::dvar_t* _dvar) : dvar(_dvar) {};
Var(DWORD ppdvar) : Var(*reinterpret_cast<Game::dvar_t**>(ppdvar)) {};
Var(const std::string& dvarName);
template<typename T> T get();
void set(char* string);
void set(const char* string);
void set(const std::string& string);
@ -58,8 +57,8 @@ namespace Components
static Game::dvar_t* RegisterName(const char* name, const char* defaultVal, Game::dvar_flag flag, const char* description);
static Game::dvar_t* SetFromStringByNameExternal(const char* dvar, const char* value);
static Game::dvar_t* SetFromStringByNameSafeExternal(const char* dvar, const char* value);
static void SetFromStringByNameExternal(const char* dvar, const char* value);
static void SetFromStringByNameSafeExternal(const char* dvar, const char* value);
static void SaveArchiveDvar(const Game::dvar_t* var);
static void DvarSetFromStringByNameStub(const char* dvarName, const char* value);

View File

@ -1730,7 +1730,7 @@ namespace Components
gpad_button_deadzone = Dvar::Register<float>("gpad_button_deadzone", 0.13f, 0.0f, 1.0f, Game::DVAR_FLAG_NONE, "Game pad button deadzone threshhold");
gpad_button_lstick_deflect_max = Dvar::Register<float>("gpad_button_lstick_deflect_max", 1.0f, 0.0f, 1.0f, Game::DVAR_FLAG_NONE, "Game pad maximum pad stick pressed value");
gpad_button_rstick_deflect_max = Dvar::Register<float>("gpad_button_rstick_deflect_max", 1.0f, 0.0f, 1.0f, Game::DVAR_FLAG_NONE, "Game pad maximum pad stick pressed value");
gpad_use_hold_time = Dvar::Register<int>("gpad_use_hold_time", 250, 0, INT32_MAX, Game::DVAR_FLAG_NONE, "Time to hold the 'use' button on gamepads to activate use");
gpad_use_hold_time = Dvar::Register<int>("gpad_use_hold_time", 250, 0, std::numeric_limits<int>::max(), Game::DVAR_FLAG_NONE, "Time to hold the 'use' button on gamepads to activate use");
gpad_lockon_enabled = Dvar::Register<bool>("gpad_lockon_enabled", true, Game::DVAR_FLAG_SAVED, "Game pad lockon aim assist enabled");
gpad_slowdown_enabled = Dvar::Register<bool>("gpad_slowdown_enabled", true, Game::DVAR_FLAG_SAVED, "Game pad slowdown aim assist enabled");
@ -1761,10 +1761,10 @@ namespace Components
aim_lockon_strength = Dvar::Var("aim_lockon_strength");
}
void Gamepad::IN_Init_Hk()
void Gamepad::CG_RegisterDvars_Hk()
{
// Call original method
Utils::Hook::Call<void()>(0x45D620)();
Utils::Hook::Call<void()>(0x4F8DC0)();
InitDvars();
}
@ -1907,7 +1907,7 @@ namespace Components
return;
// Initialize gamepad environment
Utils::Hook(0x467C03, IN_Init_Hk, HOOK_CALL).install()->quick();
Utils::Hook(0x4059FE, CG_RegisterDvars_Hk, HOOK_CALL).install()->quick();
// package the forward and right move components in the move buttons
Utils::Hook(0x60E38D, MSG_WriteDeltaUsercmdKeyStub, HOOK_JUMP).install()->quick();

View File

@ -187,7 +187,7 @@ namespace Components
static void Scores_Toggle_f(Command::Params* params);
static void InitDvars();
static void IN_Init_Hk();
static void CG_RegisterDvars_Hk();
static const char* GetGamePadCommand(const char* command);
static int Key_GetCommandAssignmentInternal_Hk(const char* cmd, int(*keys)[2]);

View File

@ -366,7 +366,7 @@ namespace Components
{
if (arena->keys[j] == "dependency"s)
{
return Utils::String::Explode(arena->values[j], ' ');
return Utils::String::Split(arena->values[j], ' ');
}
}
}

View File

@ -60,7 +60,7 @@ namespace Components
std::string nodes = Utils::Cache::GetFile("/iw4/nodes.txt");
if (nodes.empty()) return;
auto nodeList = Utils::String::Explode(nodes, '\n');
auto nodeList = Utils::String::Split(nodes, '\n');
for (auto& node : nodeList)
{
Utils::String::Replace(node, "\r", "");

View File

@ -264,7 +264,7 @@ namespace Components
Dvar::Var("uiSi_ModName").set(info.get("fs_game").data() + 5);
}
auto lines = Utils::String::Explode(data, '\n');
auto lines = Utils::String::Split(data, '\n');
if (lines.size() <= 1) return;

View File

@ -539,8 +539,8 @@ namespace Components
bool ServerList::CompareVersion(const std::string& version1, const std::string& version2)
{
std::vector<std::string> subVersions1 = Utils::String::Explode(version1, '.');
std::vector<std::string> subVersions2 = Utils::String::Explode(version2, '.');
auto subVersions1 = Utils::String::Split(version1, '.');
auto subVersions2 = Utils::String::Split(version2, '.');
while (subVersions1.size() >= 3) subVersions1.pop_back();
while (subVersions2.size() >= 3) subVersions2.pop_back();

View File

@ -262,25 +262,25 @@ namespace Game
typedef dvar_t* (__cdecl * Dvar_RegisterColor_t)(const char* name, float r, float g, float b, float a, int flags, const char* description);
extern Dvar_RegisterColor_t Dvar_RegisterColor;
typedef dvar_t* (__cdecl * Dvar_SetFromStringByName_t)(const char* cvar, const char* value);
typedef void(__cdecl * Dvar_SetFromStringByName_t)(const char* dvarName, const char* string);
extern Dvar_SetFromStringByName_t Dvar_SetFromStringByName;
typedef dvar_t* (__cdecl * Dvar_SetFromStringByNameFromSource_t)(const char* cvar, const char* value, DvarSetSource source);
typedef const dvar_t* (__cdecl * Dvar_SetFromStringByNameFromSource_t)(const char* dvarName, const char* string, DvarSetSource source);
extern Dvar_SetFromStringByNameFromSource_t Dvar_SetFromStringByNameFromSource;
typedef void (__cdecl * Dvar_SetStringByName_t)(const char* cvar, const char* value);
extern Dvar_SetStringByName_t Dvar_SetStringByName;
typedef void (__cdecl * Dvar_SetString_t)(dvar_t* cvar, const char* value);
typedef void (__cdecl * Dvar_SetString_t)(const dvar_t* cvar, const char* value);
extern Dvar_SetString_t Dvar_SetString;
typedef void (__cdecl * Dvar_SetBool_t)(dvar_t* cvar, bool enabled);
typedef void (__cdecl * Dvar_SetBool_t)(const dvar_t* cvar, bool enabled);
extern Dvar_SetBool_t Dvar_SetBool;
typedef void (__cdecl * Dvar_SetFloat_t)(dvar_t* cvar, float value);
typedef void (__cdecl * Dvar_SetFloat_t)(const dvar_t* cvar, float value);
extern Dvar_SetFloat_t Dvar_SetFloat;
typedef void (__cdecl * Dvar_SetInt_t)(dvar_t* cvar, int integer);
typedef void (__cdecl * Dvar_SetInt_t)(const dvar_t* cvar, int integer);
extern Dvar_SetInt_t Dvar_SetInt;
typedef void(__cdecl * Dvar_GetUnpackedColorByName_t)(const char* name, float* color);
@ -289,10 +289,10 @@ namespace Game
typedef dvar_t* (__cdecl * Dvar_FindVar_t)(const char *dvarName);
extern Dvar_FindVar_t Dvar_FindVar;
typedef char* (__cdecl* Dvar_InfoString_Big_t)(int typeMask);
typedef char* (__cdecl * Dvar_InfoString_Big_t)(int bit);
extern Dvar_InfoString_Big_t Dvar_InfoString_Big;
typedef dvar_t* (__cdecl * Dvar_SetCommand_t)(const char* name, const char* value);
typedef void(__cdecl * Dvar_SetCommand_t)(const char* dvarName, const char* string);
extern Dvar_SetCommand_t Dvar_SetCommand;
typedef const char* (__cdecl * Dvar_DisplayableValue_t)(const dvar_t* cvar);

View File

@ -71,7 +71,7 @@ namespace Utils
if (!buffer.empty())
{
auto rows = Utils::String::Explode(buffer, '\n');
auto rows = Utils::String::Split(buffer, '\n');
for (auto& row : rows)
{

View File

@ -9,9 +9,10 @@ namespace Utils
std::string InfoString::get(const std::string& key)
{
if (this->keyValuePairs.find(key) != this->keyValuePairs.end())
const auto value = this->keyValuePairs.find(key);
if (value != this->keyValuePairs.end())
{
return this->keyValuePairs[key];
return value->second;
}
return "";
@ -24,11 +25,13 @@ namespace Utils
buffer = buffer.substr(1);
}
std::vector<std::string> KeyValues = Utils::String::Explode(buffer, '\\');
auto KeyValues = Utils::String::Split(buffer, '\\');
for (unsigned int i = 0; i < (KeyValues.size() - 1); i += 2)
for (size_t i = 0; !KeyValues.empty() && i < (KeyValues.size() - 1); i += 2)
{
this->keyValuePairs[KeyValues[i]] = KeyValues[i + 1];
const auto& key = KeyValues[i];
const auto& value = KeyValues[i + 1];
this->keyValuePairs[key] = value;
}
}
@ -36,16 +39,16 @@ namespace Utils
{
std::string infoString;
bool first = true;
auto first = true;
for (auto i = this->keyValuePairs.begin(); i != this->keyValuePairs.end(); ++i)
for (const auto& [key, value] : this->keyValuePairs)
{
if (first) first = false;
else infoString.append("\\");
infoString.append(i->first); // Key
infoString.append(key);
infoString.append("\\");
infoString.append(i->second); // Value
infoString.append(value);
}
return infoString;
@ -53,9 +56,9 @@ namespace Utils
void InfoString::dump()
{
for (auto i = this->keyValuePairs.begin(); i != this->keyValuePairs.end(); ++i)
for (const auto& [key, value] : this->keyValuePairs)
{
OutputDebugStringA(Utils::String::VA("%s: %s", i->first.data(), i->second.data()));
OutputDebugStringA(Utils::String::VA("%s: %s\n", key.data(), value.data()));
}
}

View File

@ -7,11 +7,9 @@ namespace Utils
public:
InfoString() {};
InfoString(const std::string& buffer) : InfoString() { this->parse(buffer); };
InfoString(const InfoString &obj) : keyValuePairs(obj.keyValuePairs) {};
void set(const std::string& key, const std::string& value);
std::string get(const std::string& key);
std::string build();
void dump();

View File

@ -62,25 +62,18 @@ namespace Utils
return str;
}
std::vector<std::string> Explode(const std::string& str, char delim)
std::vector<std::string> Split(const std::string& str, const char delim)
{
std::vector<std::string> result;
std::istringstream iss(str);
std::stringstream ss(str);
std::string item;
std::vector<std::string> elems;
for (std::string token; std::getline(iss, token, delim);)
while (std::getline(ss, item, delim))
{
std::string _entry = std::move(token);
// Remove trailing 0x0 bytes
while (_entry.size() && !_entry.back())
{
_entry = _entry.substr(0, _entry.size() - 1);
}
result.push_back(_entry);
elems.push_back(item); // elems.push_back(std::move(item)); // if C++11 (based on comment from S1x)
}
return result;
return elems;
}
void Replace(std::string &string, const std::string& find, const std::string& replace)

View File

@ -78,7 +78,7 @@ namespace Utils
std::string ToLower(std::string input);
std::string ToUpper(std::string input);
bool EndsWith(const std::string& haystack, const std::string& needle);
std::vector<std::string> Explode(const std::string& str, char delim);
std::vector<std::string> Split(const std::string& str, const char delim);
void Replace(std::string &string, const std::string& find, const std::string& replace);
bool StartsWith(const std::string& haystack, const std::string& needle);
std::string &LTrim(std::string &s);