Might have fixed cat_save crashes?

This commit is contained in:
TotallyNotElite 2018-09-10 21:45:52 +02:00
parent da3c60dacc
commit 603d548198
9 changed files with 65 additions and 17 deletions

View File

@ -7,6 +7,7 @@
#include <config.h>
#include <string>
#include <functional>
#include <atomic>
#if ENABLE_VISUALS
#include <glez/color.hpp>
@ -37,7 +38,7 @@
namespace settings
{
extern std::atomic<bool> RVarLock;
enum class VariableType
{
BOOL,

View File

@ -40,7 +40,7 @@ CUserCmd *current_user_cmd{ nullptr };
bool isHackActive()
{
return *global_enable;
return !settings::RVarLock.load() && *global_enable;
}
GlobalSettings g_Settings{};

View File

@ -126,13 +126,6 @@ DEFINE_HOOKED_METHOD(CreateMove, bool, void *this_, float input_sample_time,
float curtime_old, servertime, speed, yaw;
Vector vsilent, ang;
if (firstcm)
{
DelayTimer.update();
hacks::tf2::NavBot::Init();
hacks::tf2::NavBot::initonce();
firstcm = false;
}
tickcount++;
current_user_cmd = cmd;
#if !LAGBOT_MODE
@ -161,6 +154,14 @@ DEFINE_HOOKED_METHOD(CreateMove, bool, void *this_, float input_sample_time,
return ret;
}
if (firstcm)
{
DelayTimer.update();
hacks::tf2::NavBot::Init();
hacks::tf2::NavBot::initonce();
firstcm = false;
}
if (!g_IEngine->IsInGame())
{
g_Settings.bInvalid = true;

View File

@ -36,6 +36,8 @@ namespace hooked_methods
DEFINE_HOOKED_METHOD(DispatchUserMessage, bool, void *this_, int type,
bf_read &buf)
{
if (!isHackActive())
return original::DispatchUserMessage(this_, type, buf);
if (retrun && gitgud.test_and_set(100))
{
PrintChat("\x07%06X%s\x01: %s", 0xe05938, lastname.c_str(),

View File

@ -17,6 +17,8 @@ namespace hooked_methods
DEFINE_HOOKED_METHOD(SendNetMsg, bool, INetChannel *this_, INetMessage &msg,
bool force_reliable, bool voice)
{
if (!isHackActive())
original::SendNetMsg(this_, msg, force_reliable, voice);
size_t say_idx, say_team_idx;
int offset;
std::string newlines;

View File

@ -18,7 +18,7 @@ DEFINE_HOOKED_METHOD(DrawModelExecute, void, IVModelRender *this_,
const ModelRenderInfo_t &info, matrix3x4_t *bone)
{
if (!isHackActive())
return;
return original::DrawModelExecute(this_, state, info, bone);
if (!(spectator_target || no_arms || no_hats ||
(clean_screenshots && g_IEngine->IsTakingScreenshot()) ||

View File

@ -6,6 +6,7 @@
#include <dirent.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <thread>
/*
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() };
DIR *config_directory = opendir(DATA_PATH "/configs");
@ -73,9 +76,21 @@ static CatCommand save("save", "", [](const CCommand &args) {
}
getAndSortAllConfigs();
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() };
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) +
".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{};

View File

@ -6,4 +6,5 @@
namespace settings
{
}
std::atomic<bool> RVarLock{false};
}

View File

@ -5,6 +5,7 @@
#include <settings/SettingsIO.hpp>
#include <fstream>
#include <sstream>
#include "core/logging.hpp"
settings::SettingsWriter::SettingsWriter(settings::Manager &manager)
: manager(manager)
@ -13,29 +14,40 @@ settings::SettingsWriter::SettingsWriter(settings::Manager &manager)
bool settings::SettingsWriter::saveTo(std::string path, bool only_changed)
{
logging::Info("cat_save: started");
this->only_changed = only_changed;
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;
}
using pair_type = std::pair<std::string, settings::IVariable *>;
std::vector<pair_type> all_registered{};
logging::Info("cat_save: Getting variable references...");
for (auto &v : settings::Manager::instance().registered)
{
if (!only_changed || v.second.isChanged())
all_registered.emplace_back(
std::make_pair(v.first, &v.second.variable));
}
logging::Info("cat_save: Sorting...");
std::sort(all_registered.begin(), all_registered.end(),
[](const pair_type &a, const pair_type &b) -> bool {
return a.first.compare(b.first) < 0;
});
logging::Info("cat_save: Writing...");
for (auto &v : all_registered)
if (!v.first.empty())
{
write(v.first, v.second);
stream.flush();
}
if (stream.bad() || stream.fail() || !stream)
logging::Info("cat_save: FATAL! Stream bad!");
stream.close();
return true;
}
@ -75,10 +87,10 @@ bool settings::SettingsReader::loadFrom(std::string path)
{
stream.open(path, std::ios::in | std::ios::binary);
if (stream.bad())
if (stream.bad() || stream.fail())
return false;
while (stream)
while (stream && !stream.bad())
{
char c;
stream.read(&c, 1);
@ -86,6 +98,13 @@ bool settings::SettingsReader::loadFrom(std::string path)
break;
pushChar(c);
}
if (stream.bad() || stream.fail())
{
logging::Info("FATAL: Read failed!");
return false;
}
logging::Info("Read Success!");
finishString(true);
return true;