Merge pull request #169 from diamante0018/revert-Fixed-compile-errors-on-Cpp20

Partially revert some changes from "fix compile errors on c++20"
This commit is contained in:
Dss0 2022-01-17 19:24:10 +01:00 committed by GitHub
commit 9da6abd11d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 31 additions and 36 deletions

View File

@ -18,14 +18,14 @@ namespace Components
return result;
}
char* Command::Params::operator[](size_t index)
const char* Command::Params::operator[](size_t 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];
}
@ -34,9 +34,9 @@ namespace Components
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];
}

View File

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

View File

@ -22,19 +22,19 @@ namespace Components
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()
{
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()
@ -209,7 +209,7 @@ namespace Components
Scheduler::OnFrame([]()
{
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
if (name == lastValidName) return;

View File

@ -186,7 +186,7 @@ namespace Components
{
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
for (auto entry : Friends::FriendsList)

View File

@ -21,7 +21,7 @@ namespace Components
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);
if (playlist.exists())

View File

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

View File

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

View File

@ -782,9 +782,9 @@ namespace Game
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[1] /= length;
@ -795,9 +795,9 @@ namespace Game
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[1] /= length;