Revert some changes and use const char pointer where it's appropriate

This commit is contained in:
FutureRave 2022-01-17 17:21:51 +00:00
parent 62bca7f3b2
commit c0670ba0a3
No known key found for this signature in database
GPG Key ID: E883E2BC9657D955
8 changed files with 31 additions and 36 deletions

View File

@ -18,14 +18,14 @@ namespace Components
return result; return result;
} }
char* Command::Params::operator[](size_t index) const char* Command::Params::operator[](size_t index)
{ {
return this->get(index); return this->get(index);
} }
char* Command::ClientParams::get(size_t index) const char* Command::ClientParams::get(size_t index)
{ {
if (index >= this->length()) return const_cast<char*>(""); if (index >= this->length()) return "";
return Game::cmd_argv[this->commandId][index]; return Game::cmd_argv[this->commandId][index];
} }
@ -34,9 +34,9 @@ namespace Components
return Game::cmd_argc[this->commandId]; return Game::cmd_argc[this->commandId];
} }
char* Command::ServerParams::get(size_t index) const char* Command::ServerParams::get(size_t index)
{ {
if (index >= this->length()) return const_cast<char*>(""); if (index >= this->length()) return "";
return Game::cmd_argv_sv[this->commandId][index]; return Game::cmd_argv_sv[this->commandId][index];
} }

View File

@ -10,11 +10,11 @@ namespace Components
public: public:
Params() {}; Params() {};
virtual ~Params() {}; virtual ~Params() {};
virtual char* get(size_t index) = 0; virtual const char* get(size_t index) = 0;
virtual size_t length() = 0; virtual size_t length() = 0;
virtual std::string join(size_t startIndex); virtual std::string join(size_t startIndex);
virtual char* operator[](size_t index); virtual const char* operator[](size_t index);
}; };
class ClientParams : public Params class ClientParams : public Params
@ -24,7 +24,7 @@ namespace Components
ClientParams(const ClientParams &obj) : commandId(obj.commandId) {}; ClientParams(const ClientParams &obj) : commandId(obj.commandId) {};
ClientParams() : ClientParams(*Game::cmd_id) {}; ClientParams() : ClientParams(*Game::cmd_id) {};
char* get(size_t index) override; const char* get(size_t index) override;
size_t length() override; size_t length() override;
private: private:
@ -38,7 +38,7 @@ namespace Components
ServerParams(const ServerParams &obj) : commandId(obj.commandId) {}; ServerParams(const ServerParams &obj) : commandId(obj.commandId) {};
ServerParams() : ServerParams(*Game::cmd_id_sv) {}; ServerParams() : ServerParams(*Game::cmd_id_sv) {};
char* get(size_t index) override; const char* get(size_t index) override;
size_t length() override; size_t length() override;
private: private:

View File

@ -21,19 +21,19 @@ namespace Components
return this->dvar; return this->dvar;
} }
template <> char* Dvar::Var::get()
{
if (this->dvar && this->dvar->type == Game::dvar_type::DVAR_TYPE_STRING && this->dvar->current.string)
{
return const_cast<char*>(this->dvar->current.string);
}
return const_cast<char*>("");
}
template <> const char* Dvar::Var::get() template <> const char* Dvar::Var::get()
{ {
return this->get<char*>(); if (this->dvar == nullptr)
return "";
if (this->dvar->type == Game::dvar_type::DVAR_TYPE_STRING
|| this->dvar->type == Game::dvar_type::DVAR_TYPE_ENUM)
{
if (this->dvar->current.string != nullptr)
return this->dvar->current.string;
}
return "";
} }
template <> int Dvar::Var::get() template <> int Dvar::Var::get()
@ -198,7 +198,7 @@ namespace Components
Scheduler::OnFrame([]() Scheduler::OnFrame([]()
{ {
static std::string lastValidName = "Unknown Soldier"; static std::string lastValidName = "Unknown Soldier";
std::string name = Dvar::Var("name").get<char*>(); std::string name = Dvar::Var("name").get<const char*>();
// Don't perform any checks if name didn't change // Don't perform any checks if name didn't change
if (name == lastValidName) return; if (name == lastValidName) return;

View File

@ -186,7 +186,7 @@ namespace Components
{ {
std::lock_guard<std::recursive_mutex> _(Friends::Mutex); std::lock_guard<std::recursive_mutex> _(Friends::Mutex);
const unsigned int modId = *reinterpret_cast<unsigned int*>(const_cast<char*>("IW4x")) | 0x80000000; const unsigned int modId = *reinterpret_cast<unsigned int*>("IW4x") | 0x80000000;
// Split up the list // Split up the list
for (auto entry : Friends::FriendsList) for (auto entry : Friends::FriendsList)

View File

@ -21,7 +21,7 @@ namespace Components
Dvar::Var("xblive_privateserver").set(false); Dvar::Var("xblive_privateserver").set(false);
std::string playlistFilename = Dvar::Var("playlistFilename").get<char*>(); std::string playlistFilename = Dvar::Var("playlistFilename").get<const char*>();
FileSystem::File playlist(playlistFilename); FileSystem::File playlist(playlistFilename);
if (playlist.exists()) if (playlist.exists())

View File

@ -15,19 +15,14 @@ namespace Components
return 0; return 0;
} }
template<> char* UIScript::Token::get() template<> const char* UIScript::Token::get()
{ {
if (this->isValid()) if (this->isValid())
{ {
return this->token; return this->token;
} }
return const_cast<char*>(""); return "";
}
template<> const char* UIScript::Token::get()
{
return this->get<char*>();
} }
template<> std::string UIScript::Token::get() template<> std::string UIScript::Token::get()

View File

@ -1300,7 +1300,7 @@ namespace Components
}, nullptr, false); }, nullptr, false);
// HACK: set language to 'techsets' to load from that dir // HACK: set language to 'techsets' to load from that dir
char* language = Utils::Hook::Get<char*>(0x649E740); const char* language = Utils::Hook::Get<const char*>(0x649E740);
Utils::Hook::Set<const char*>(0x649E740, "techsets"); Utils::Hook::Set<const char*>(0x649E740, "techsets");
// load generated techset fastfiles // load generated techset fastfiles
@ -1447,7 +1447,7 @@ namespace Components
Utils::IO::WriteFile("zone_source/techsets/techsets.csv", csvStr.data()); Utils::IO::WriteFile("zone_source/techsets/techsets.csv", csvStr.data());
// set language back // set language back
Utils::Hook::Set<char*>(0x649E740, language); Utils::Hook::Set<const char*>(0x649E740, language);
Logger::Print("Building zone 'techsets/techsets'...\n"); Logger::Print("Building zone 'techsets/techsets'...\n");
Zone("techsets/techsets").build(); Zone("techsets/techsets").build();

View File

@ -773,9 +773,9 @@ namespace Game
float Vec2Normalize(vec2_t& vec) float Vec2Normalize(vec2_t& vec)
{ {
const float length = std::sqrt((vec[0] * vec[0]) + (vec[1] * vec[1])); const auto length = std::sqrt(vec[0] * vec[0] + vec[1] * vec[1]);
if(length > 0.0f) if (length > 0.0f)
{ {
vec[0] /= length; vec[0] /= length;
vec[1] /= length; vec[1] /= length;
@ -786,9 +786,9 @@ namespace Game
float Vec3Normalize(vec3_t& vec) float Vec3Normalize(vec3_t& vec)
{ {
const float length = std::sqrt(std::pow(vec[0], 2.0f) + std::pow(vec[1], 2.0f) + std::pow(vec[2], 2.0f)); const auto length = std::sqrt(vec[0] * vec[0] + vec[1] * vec[1] + vec[2] * vec[2]);
if(length > 0.0f) if (length > 0.0f)
{ {
vec[0] /= length; vec[0] /= length;
vec[1] /= length; vec[1] /= length;