[General] Upgrade to C++17 features
This commit is contained in:
parent
a1c14cd03f
commit
110aeb02f7
@ -232,7 +232,7 @@ namespace Components
|
|||||||
void AntiCheat::QuickCodeScanner_1()
|
void AntiCheat::QuickCodeScanner_1()
|
||||||
{
|
{
|
||||||
static Utils::Time::Interval interval;
|
static Utils::Time::Interval interval;
|
||||||
static Utils::Value<std::string> hashVal;
|
static std::optional<std::string> hashVal;
|
||||||
|
|
||||||
if (!interval.elapsed(11s)) return;
|
if (!interval.elapsed(11s)) return;
|
||||||
interval.update();
|
interval.update();
|
||||||
@ -243,30 +243,30 @@ namespace Components
|
|||||||
uint8_t* textBase = reinterpret_cast<uint8_t*>(0x400FFF);
|
uint8_t* textBase = reinterpret_cast<uint8_t*>(0x400FFF);
|
||||||
std::string hash = Utils::Cryptography::SHA256::Compute(textBase + 1, textSize + 1, false);
|
std::string hash = Utils::Cryptography::SHA256::Compute(textBase + 1, textSize + 1, false);
|
||||||
|
|
||||||
if (hashVal.isValid() && hash != hashVal.get())
|
if (hashVal.has_value() && hash != hashVal.value())
|
||||||
{
|
{
|
||||||
Utils::Hook::Set<BYTE>(0x42A667, 0x90); // Crash
|
Utils::Hook::Set<BYTE>(0x42A667, 0x90); // Crash
|
||||||
}
|
}
|
||||||
|
|
||||||
hashVal.set(hash);
|
hashVal.emplace(hash);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AntiCheat::QuickCodeScanner_2()
|
void AntiCheat::QuickCodeScanner_2()
|
||||||
{
|
{
|
||||||
static Utils::Time::Interval interval;
|
static Utils::Time::Interval interval;
|
||||||
static Utils::Value<std::string> hashVal;
|
static std::optional<std::string> hashVal;
|
||||||
|
|
||||||
if (!interval.elapsed(12s)) return;
|
if (!interval.elapsed(12s)) return;
|
||||||
interval.update();
|
interval.update();
|
||||||
|
|
||||||
// Hash .text segment
|
// Hash .text segment
|
||||||
std::string hash = Utils::Cryptography::SHA1::Compute(reinterpret_cast<uint8_t*>(0x401000), 0x2D6000, false);
|
std::string hash = Utils::Cryptography::SHA1::Compute(reinterpret_cast<uint8_t*>(0x401000), 0x2D6000, false);
|
||||||
if (hashVal.isValid() && hash != hashVal.get())
|
if (hashVal.has_value() && hash != hashVal.value())
|
||||||
{
|
{
|
||||||
Utils::Hook::Set<BYTE>(0x40797C, 0x90); // Crash
|
Utils::Hook::Set<BYTE>(0x40797C, 0x90); // Crash
|
||||||
}
|
}
|
||||||
|
|
||||||
hashVal.set(hash);
|
hashVal.emplace(hash);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef DEBUG_LOAD_LIBRARY
|
#ifdef DEBUG_LOAD_LIBRARY
|
||||||
|
@ -8,14 +8,14 @@ namespace Components
|
|||||||
|
|
||||||
bool Dedicated::IsEnabled()
|
bool Dedicated::IsEnabled()
|
||||||
{
|
{
|
||||||
static Utils::Value<bool> flag;
|
static std::optional<bool> flag;
|
||||||
|
|
||||||
if (!flag.isValid())
|
if (!flag.has_value())
|
||||||
{
|
{
|
||||||
flag.set(Flags::HasFlag("dedicated"));
|
flag.emplace(Flags::HasFlag("dedicated"));
|
||||||
}
|
}
|
||||||
|
|
||||||
return flag.get();
|
return flag.value();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Dedicated::InitDedicatedServer()
|
void Dedicated::InitDedicatedServer()
|
||||||
|
@ -283,15 +283,15 @@ namespace Components
|
|||||||
|
|
||||||
void Friends::UpdateRank()
|
void Friends::UpdateRank()
|
||||||
{
|
{
|
||||||
static Utils::Value<int> levelVal;
|
static std::optional<int> levelVal;
|
||||||
|
|
||||||
int experience = Game::Live_GetXp(0);
|
int experience = Game::Live_GetXp(0);
|
||||||
int prestige = Game::Live_GetPrestige(0);
|
int prestige = Game::Live_GetPrestige(0);
|
||||||
int level = (experience & 0xFFFFFF) | ((prestige & 0xFF) << 24);
|
int level = (experience & 0xFFFFFF) | ((prestige & 0xFF) << 24);
|
||||||
|
|
||||||
if(!levelVal.isValid() || levelVal.get() != level)
|
if(!levelVal.has_value() || levelVal.value() != level)
|
||||||
{
|
{
|
||||||
levelVal.set(level);
|
levelVal.emplace(level);
|
||||||
|
|
||||||
Friends::SetPresence("iw4x_experience", Utils::String::VA("%d", experience));
|
Friends::SetPresence("iw4x_experience", Utils::String::VA("%d", experience));
|
||||||
Friends::SetPresence("iw4x_prestige", Utils::String::VA("%d", prestige));
|
Friends::SetPresence("iw4x_prestige", Utils::String::VA("%d", prestige));
|
||||||
|
@ -7,14 +7,14 @@ namespace Components
|
|||||||
{
|
{
|
||||||
bool Monitor::IsEnabled()
|
bool Monitor::IsEnabled()
|
||||||
{
|
{
|
||||||
static Utils::Value<bool> flag;
|
static std::optional<bool> flag;
|
||||||
|
|
||||||
if (!flag.isValid())
|
if (!flag.has_value())
|
||||||
{
|
{
|
||||||
flag.set(Flags::HasFlag("monitor"));
|
flag.emplace(Flags::HasFlag("monitor"));
|
||||||
}
|
}
|
||||||
|
|
||||||
return flag.get();
|
return flag.value();
|
||||||
}
|
}
|
||||||
|
|
||||||
int __stdcall Monitor::EntryPoint(HINSTANCE /*hInstance*/, HINSTANCE /*hPrevInstance*/, LPSTR /*lpCmdLine*/, int /*nShowCmd*/)
|
int __stdcall Monitor::EntryPoint(HINSTANCE /*hInstance*/, HINSTANCE /*hPrevInstance*/, LPSTR /*lpCmdLine*/, int /*nShowCmd*/)
|
||||||
|
@ -735,6 +735,21 @@ namespace Components
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
printf("Success\n");
|
||||||
|
|
||||||
|
printf("Testing trimming...");
|
||||||
|
std::string trim1 = " 1 ";
|
||||||
|
std::string trim2 = " 1";
|
||||||
|
std::string trim3 = "1 ";
|
||||||
|
|
||||||
|
Utils::String::Trim(trim1);
|
||||||
|
Utils::String::LTrim(trim2);
|
||||||
|
Utils::String::RTrim(trim3);
|
||||||
|
|
||||||
|
if (trim1 != "1") return false;
|
||||||
|
if (trim2 != "1") return false;
|
||||||
|
if (trim3 != "1") return false;
|
||||||
|
|
||||||
printf("Success\n");
|
printf("Success\n");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -664,14 +664,14 @@ namespace Components
|
|||||||
|
|
||||||
bool ZoneBuilder::IsEnabled()
|
bool ZoneBuilder::IsEnabled()
|
||||||
{
|
{
|
||||||
static Utils::Value<bool> flag;
|
static std::optional<bool> flag;
|
||||||
|
|
||||||
if (!flag.isValid())
|
if (!flag.has_value())
|
||||||
{
|
{
|
||||||
flag.set(Flags::HasFlag("zonebuilder"));
|
flag.emplace(Flags::HasFlag("zonebuilder"));
|
||||||
}
|
}
|
||||||
|
|
||||||
return (flag.get() && !Dedicated::IsEnabled());
|
return (flag.value() && !Dedicated::IsEnabled());
|
||||||
}
|
}
|
||||||
|
|
||||||
void ZoneBuilder::BeginAssetTrace(std::string zone)
|
void ZoneBuilder::BeginAssetTrace(std::string zone)
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
#ifndef RC_INVOKED
|
#ifndef RC_INVOKED
|
||||||
|
|
||||||
|
#define _HAS_CXX17 1
|
||||||
#define VC_EXTRALEAN
|
#define VC_EXTRALEAN
|
||||||
#define WIN32_LEAN_AND_MEAN
|
#define WIN32_LEAN_AND_MEAN
|
||||||
|
|
||||||
@ -39,6 +40,7 @@
|
|||||||
|
|
||||||
// Experimental C++17 features
|
// Experimental C++17 features
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
|
#include <optional>
|
||||||
|
|
||||||
#pragma warning(pop)
|
#pragma warning(pop)
|
||||||
|
|
||||||
|
@ -21,9 +21,9 @@ namespace Steam
|
|||||||
|
|
||||||
unsigned int Utils::GetServerRealTime()
|
unsigned int Utils::GetServerRealTime()
|
||||||
{
|
{
|
||||||
static ::Utils::Value<unsigned int> timeDelta;
|
static ::std::optional<unsigned int> timeDelta;
|
||||||
|
|
||||||
if(!timeDelta.isValid())
|
if(!timeDelta.has_value())
|
||||||
{
|
{
|
||||||
unsigned int steamTime = static_cast<unsigned int>(time(nullptr));
|
unsigned int steamTime = static_cast<unsigned int>(time(nullptr));
|
||||||
|
|
||||||
@ -32,10 +32,10 @@ namespace Steam
|
|||||||
steamTime = Steam::Proxy::SteamUtils->GetServerRealTime();
|
steamTime = Steam::Proxy::SteamUtils->GetServerRealTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
timeDelta.set(steamTime - (Game::Sys_Milliseconds() / 1000));
|
timeDelta.emplace(steamTime - (Game::Sys_Milliseconds() / 1000));
|
||||||
}
|
}
|
||||||
|
|
||||||
return timeDelta.get() + (Game::Sys_Milliseconds() / 1000);
|
return timeDelta.value() + (Game::Sys_Milliseconds() / 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* Utils::GetIPCountry()
|
const char* Utils::GetIPCountry()
|
||||||
|
@ -113,14 +113,20 @@ namespace Utils
|
|||||||
// trim from start
|
// trim from start
|
||||||
std::string <rim(std::string &s)
|
std::string <rim(std::string &s)
|
||||||
{
|
{
|
||||||
s.erase(s.begin(), std::find_if(s.begin(), s.end(), std::not1(std::ptr_fun<int, int>(IsSpace))));
|
s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](int val)
|
||||||
|
{
|
||||||
|
return !IsSpace(val);
|
||||||
|
}));
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
// trim from end
|
// trim from end
|
||||||
std::string &RTrim(std::string &s)
|
std::string &RTrim(std::string &s)
|
||||||
{
|
{
|
||||||
s.erase(std::find_if(s.rbegin(), s.rend(), std::not1(std::ptr_fun<int, int>(IsSpace))).base(), s.end());
|
s.erase(std::find_if(s.rbegin(), s.rend(), [](int val)
|
||||||
|
{
|
||||||
|
return !IsSpace(val);
|
||||||
|
}).base(), s.end());
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -112,33 +112,4 @@ namespace Utils
|
|||||||
private:
|
private:
|
||||||
std::vector<Slot<T>> slots;
|
std::vector<Slot<T>> slots;
|
||||||
};
|
};
|
||||||
|
|
||||||
// TODO: Replace with std::optional, once C++17 is fully available!
|
|
||||||
template <typename T>
|
|
||||||
class Value
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
Value() : hasValue(false) {}
|
|
||||||
Value(T _value) { this->set(_value); }
|
|
||||||
|
|
||||||
void set(T _value)
|
|
||||||
{
|
|
||||||
this->value = _value;
|
|
||||||
this->hasValue = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool isValid()
|
|
||||||
{
|
|
||||||
return this->hasValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
T get()
|
|
||||||
{
|
|
||||||
return this->value;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
bool hasValue;
|
|
||||||
T value;
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user