Might have fixed cat_save crashes?
This commit is contained in:
parent
da3c60dacc
commit
603d548198
@ -7,6 +7,7 @@
|
|||||||
#include <config.h>
|
#include <config.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
#include <atomic>
|
||||||
|
|
||||||
#if ENABLE_VISUALS
|
#if ENABLE_VISUALS
|
||||||
#include <glez/color.hpp>
|
#include <glez/color.hpp>
|
||||||
@ -37,7 +38,7 @@
|
|||||||
|
|
||||||
namespace settings
|
namespace settings
|
||||||
{
|
{
|
||||||
|
extern std::atomic<bool> RVarLock;
|
||||||
enum class VariableType
|
enum class VariableType
|
||||||
{
|
{
|
||||||
BOOL,
|
BOOL,
|
||||||
|
@ -40,7 +40,7 @@ CUserCmd *current_user_cmd{ nullptr };
|
|||||||
|
|
||||||
bool isHackActive()
|
bool isHackActive()
|
||||||
{
|
{
|
||||||
return *global_enable;
|
return !settings::RVarLock.load() && *global_enable;
|
||||||
}
|
}
|
||||||
|
|
||||||
GlobalSettings g_Settings{};
|
GlobalSettings g_Settings{};
|
||||||
|
@ -126,13 +126,6 @@ DEFINE_HOOKED_METHOD(CreateMove, bool, void *this_, float input_sample_time,
|
|||||||
float curtime_old, servertime, speed, yaw;
|
float curtime_old, servertime, speed, yaw;
|
||||||
Vector vsilent, ang;
|
Vector vsilent, ang;
|
||||||
|
|
||||||
if (firstcm)
|
|
||||||
{
|
|
||||||
DelayTimer.update();
|
|
||||||
hacks::tf2::NavBot::Init();
|
|
||||||
hacks::tf2::NavBot::initonce();
|
|
||||||
firstcm = false;
|
|
||||||
}
|
|
||||||
tickcount++;
|
tickcount++;
|
||||||
current_user_cmd = cmd;
|
current_user_cmd = cmd;
|
||||||
#if !LAGBOT_MODE
|
#if !LAGBOT_MODE
|
||||||
@ -161,6 +154,14 @@ DEFINE_HOOKED_METHOD(CreateMove, bool, void *this_, float input_sample_time,
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (firstcm)
|
||||||
|
{
|
||||||
|
DelayTimer.update();
|
||||||
|
hacks::tf2::NavBot::Init();
|
||||||
|
hacks::tf2::NavBot::initonce();
|
||||||
|
firstcm = false;
|
||||||
|
}
|
||||||
|
|
||||||
if (!g_IEngine->IsInGame())
|
if (!g_IEngine->IsInGame())
|
||||||
{
|
{
|
||||||
g_Settings.bInvalid = true;
|
g_Settings.bInvalid = true;
|
||||||
|
@ -36,6 +36,8 @@ namespace hooked_methods
|
|||||||
DEFINE_HOOKED_METHOD(DispatchUserMessage, bool, void *this_, int type,
|
DEFINE_HOOKED_METHOD(DispatchUserMessage, bool, void *this_, int type,
|
||||||
bf_read &buf)
|
bf_read &buf)
|
||||||
{
|
{
|
||||||
|
if (!isHackActive())
|
||||||
|
return original::DispatchUserMessage(this_, type, buf);
|
||||||
if (retrun && gitgud.test_and_set(100))
|
if (retrun && gitgud.test_and_set(100))
|
||||||
{
|
{
|
||||||
PrintChat("\x07%06X%s\x01: %s", 0xe05938, lastname.c_str(),
|
PrintChat("\x07%06X%s\x01: %s", 0xe05938, lastname.c_str(),
|
||||||
|
@ -17,6 +17,8 @@ namespace hooked_methods
|
|||||||
DEFINE_HOOKED_METHOD(SendNetMsg, bool, INetChannel *this_, INetMessage &msg,
|
DEFINE_HOOKED_METHOD(SendNetMsg, bool, INetChannel *this_, INetMessage &msg,
|
||||||
bool force_reliable, bool voice)
|
bool force_reliable, bool voice)
|
||||||
{
|
{
|
||||||
|
if (!isHackActive())
|
||||||
|
original::SendNetMsg(this_, msg, force_reliable, voice);
|
||||||
size_t say_idx, say_team_idx;
|
size_t say_idx, say_team_idx;
|
||||||
int offset;
|
int offset;
|
||||||
std::string newlines;
|
std::string newlines;
|
||||||
|
@ -18,7 +18,7 @@ DEFINE_HOOKED_METHOD(DrawModelExecute, void, IVModelRender *this_,
|
|||||||
const ModelRenderInfo_t &info, matrix3x4_t *bone)
|
const ModelRenderInfo_t &info, matrix3x4_t *bone)
|
||||||
{
|
{
|
||||||
if (!isHackActive())
|
if (!isHackActive())
|
||||||
return;
|
return original::DrawModelExecute(this_, state, info, bone);
|
||||||
|
|
||||||
if (!(spectator_target || no_arms || no_hats ||
|
if (!(spectator_target || no_arms || no_hats ||
|
||||||
(clean_screenshots && g_IEngine->IsTakingScreenshot()) ||
|
(clean_screenshots && g_IEngine->IsTakingScreenshot()) ||
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
#include <thread>
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Created on 29.07.18.
|
Created on 29.07.18.
|
||||||
@ -52,7 +53,9 @@ static CatCommand cat("cat", "", [](const CCommand &args) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
static CatCommand save("save", "", [](const CCommand &args) {
|
void save_thread(const CCommand &args)
|
||||||
|
{
|
||||||
|
std::this_thread::sleep_for(std::chrono_literals::operator""s(1));
|
||||||
settings::SettingsWriter writer{ settings::Manager::instance() };
|
settings::SettingsWriter writer{ settings::Manager::instance() };
|
||||||
|
|
||||||
DIR *config_directory = opendir(DATA_PATH "/configs");
|
DIR *config_directory = opendir(DATA_PATH "/configs");
|
||||||
@ -73,9 +76,21 @@ static CatCommand save("save", "", [](const CCommand &args) {
|
|||||||
}
|
}
|
||||||
getAndSortAllConfigs();
|
getAndSortAllConfigs();
|
||||||
closedir(config_directory);
|
closedir(config_directory);
|
||||||
|
settings::RVarLock.store(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
static CatCommand save("save", "", [](const CCommand &args) {
|
||||||
|
if(!settings::RVarLock.load())
|
||||||
|
{
|
||||||
|
settings::RVarLock.store(true);
|
||||||
|
std::thread loader(save_thread, args);
|
||||||
|
loader.detach();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
static CatCommand load("load", "", [](const CCommand &args) {
|
void load_thread(const CCommand &args)
|
||||||
|
{
|
||||||
|
std::this_thread::sleep_for(std::chrono_literals::operator""s(1));
|
||||||
settings::SettingsReader loader{ settings::Manager::instance() };
|
settings::SettingsReader loader{ settings::Manager::instance() };
|
||||||
if (args.ArgC() == 1)
|
if (args.ArgC() == 1)
|
||||||
{
|
{
|
||||||
@ -86,6 +101,13 @@ static CatCommand load("load", "", [](const CCommand &args) {
|
|||||||
loader.loadFrom(std::string(DATA_PATH "/configs/") + args.Arg(1) +
|
loader.loadFrom(std::string(DATA_PATH "/configs/") + args.Arg(1) +
|
||||||
".conf");
|
".conf");
|
||||||
}
|
}
|
||||||
|
settings::RVarLock.store(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
static CatCommand load("load", "", [](const CCommand &args) {
|
||||||
|
settings::RVarLock.store(true);
|
||||||
|
std::thread saver(load_thread, args);
|
||||||
|
saver.detach();
|
||||||
});
|
});
|
||||||
|
|
||||||
static std::vector<std::string> sortedVariables{};
|
static std::vector<std::string> sortedVariables{};
|
||||||
|
@ -6,4 +6,5 @@
|
|||||||
|
|
||||||
namespace settings
|
namespace settings
|
||||||
{
|
{
|
||||||
|
std::atomic<bool> RVarLock{false};
|
||||||
}
|
}
|
@ -5,6 +5,7 @@
|
|||||||
#include <settings/SettingsIO.hpp>
|
#include <settings/SettingsIO.hpp>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
#include "core/logging.hpp"
|
||||||
|
|
||||||
settings::SettingsWriter::SettingsWriter(settings::Manager &manager)
|
settings::SettingsWriter::SettingsWriter(settings::Manager &manager)
|
||||||
: manager(manager)
|
: manager(manager)
|
||||||
@ -13,29 +14,40 @@ settings::SettingsWriter::SettingsWriter(settings::Manager &manager)
|
|||||||
|
|
||||||
bool settings::SettingsWriter::saveTo(std::string path, bool only_changed)
|
bool settings::SettingsWriter::saveTo(std::string path, bool only_changed)
|
||||||
{
|
{
|
||||||
|
logging::Info("cat_save: started");
|
||||||
this->only_changed = only_changed;
|
this->only_changed = only_changed;
|
||||||
|
|
||||||
stream.open(path, std::ios::out);
|
stream.open(path, std::ios::out);
|
||||||
|
|
||||||
if (stream.bad() || !stream.is_open())
|
if (stream.bad() || !stream.is_open() || stream.fail() || !stream)
|
||||||
|
{
|
||||||
|
logging::Info("FATAL: cat_save FAILED!");
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
using pair_type = std::pair<std::string, settings::IVariable *>;
|
using pair_type = std::pair<std::string, settings::IVariable *>;
|
||||||
std::vector<pair_type> all_registered{};
|
std::vector<pair_type> all_registered{};
|
||||||
|
logging::Info("cat_save: Getting variable references...");
|
||||||
for (auto &v : settings::Manager::instance().registered)
|
for (auto &v : settings::Manager::instance().registered)
|
||||||
{
|
{
|
||||||
if (!only_changed || v.second.isChanged())
|
if (!only_changed || v.second.isChanged())
|
||||||
all_registered.emplace_back(
|
all_registered.emplace_back(
|
||||||
std::make_pair(v.first, &v.second.variable));
|
std::make_pair(v.first, &v.second.variable));
|
||||||
}
|
}
|
||||||
|
logging::Info("cat_save: Sorting...");
|
||||||
std::sort(all_registered.begin(), all_registered.end(),
|
std::sort(all_registered.begin(), all_registered.end(),
|
||||||
[](const pair_type &a, const pair_type &b) -> bool {
|
[](const pair_type &a, const pair_type &b) -> bool {
|
||||||
return a.first.compare(b.first) < 0;
|
return a.first.compare(b.first) < 0;
|
||||||
});
|
});
|
||||||
|
logging::Info("cat_save: Writing...");
|
||||||
for (auto &v : all_registered)
|
for (auto &v : all_registered)
|
||||||
if (!v.first.empty())
|
if (!v.first.empty())
|
||||||
|
{
|
||||||
write(v.first, v.second);
|
write(v.first, v.second);
|
||||||
|
stream.flush();
|
||||||
|
}
|
||||||
|
if (stream.bad() || stream.fail() || !stream)
|
||||||
|
logging::Info("cat_save: FATAL! Stream bad!");
|
||||||
stream.close();
|
stream.close();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -75,10 +87,10 @@ bool settings::SettingsReader::loadFrom(std::string path)
|
|||||||
{
|
{
|
||||||
stream.open(path, std::ios::in | std::ios::binary);
|
stream.open(path, std::ios::in | std::ios::binary);
|
||||||
|
|
||||||
if (stream.bad())
|
if (stream.bad() || stream.fail())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
while (stream)
|
while (stream && !stream.bad())
|
||||||
{
|
{
|
||||||
char c;
|
char c;
|
||||||
stream.read(&c, 1);
|
stream.read(&c, 1);
|
||||||
@ -86,6 +98,13 @@ bool settings::SettingsReader::loadFrom(std::string path)
|
|||||||
break;
|
break;
|
||||||
pushChar(c);
|
pushChar(c);
|
||||||
}
|
}
|
||||||
|
if (stream.bad() || stream.fail())
|
||||||
|
{
|
||||||
|
logging::Info("FATAL: Read failed!");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
logging::Info("Read Success!");
|
||||||
finishString(true);
|
finishString(true);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
Reference in New Issue
Block a user