Cat_save changes and playerlist color changes
* Removed cat_save and cat_load thread * Made the cat_save system not save variables set to default settings and made cat_load reset all variables to default before loading
This commit is contained in:
parent
6be70d9beb
commit
c039ab5978
@ -38,7 +38,7 @@
|
||||
|
||||
namespace settings
|
||||
{
|
||||
extern std::atomic<bool> RVarLock;
|
||||
extern std::atomic<bool> cathook_disabled;
|
||||
enum class VariableType
|
||||
{
|
||||
BOOL,
|
||||
|
@ -42,7 +42,7 @@ class SettingsWriter
|
||||
public:
|
||||
explicit SettingsWriter(Manager &manager);
|
||||
|
||||
bool saveTo(std::string path, bool only_changed);
|
||||
bool saveTo(std::string path);
|
||||
|
||||
protected:
|
||||
void write(std::string name, IVariable *variable);
|
||||
@ -52,4 +52,4 @@ protected:
|
||||
std::ofstream stream{};
|
||||
Manager &manager;
|
||||
};
|
||||
} // namespace settings
|
||||
} // namespace settings
|
||||
|
@ -45,7 +45,7 @@ CUserCmd *current_user_cmd{ nullptr };
|
||||
|
||||
bool isHackActive()
|
||||
{
|
||||
return !settings::RVarLock.load() && *global_enable;
|
||||
return !settings::cathook_disabled.load() && *global_enable;
|
||||
}
|
||||
|
||||
GlobalSettings g_Settings{};
|
||||
|
@ -409,7 +409,7 @@ void hack::Shutdown()
|
||||
return;
|
||||
hack::shutdown = true;
|
||||
// Stop cathook stuff
|
||||
settings::RVarLock.store(true);
|
||||
settings::cathook_disabled.store(true);
|
||||
playerlist::Save();
|
||||
#if ENABLE_VISUALS
|
||||
sdl_hooks::cleanSdlHooks();
|
||||
|
@ -51,8 +51,7 @@ static CatCommand cat("cat", "", [](const CCommand &args) {
|
||||
}
|
||||
});
|
||||
|
||||
void save_thread(const int ArgC, const std::string ArgS)
|
||||
{
|
||||
static CatCommand save("save", "", [](const CCommand &args) {
|
||||
settings::SettingsWriter writer{ settings::Manager::instance() };
|
||||
|
||||
DIR *config_directory = opendir(DATA_PATH "/configs");
|
||||
@ -62,86 +61,33 @@ void save_thread(const int ArgC, const std::string ArgS)
|
||||
mkdir(DATA_PATH "/configs", S_IRWXU | S_IRWXG);
|
||||
}
|
||||
|
||||
if (ArgC == 1)
|
||||
if (args.ArgC() == 1)
|
||||
{
|
||||
writer.saveTo(DATA_PATH "/configs/default.conf", false);
|
||||
writer.saveTo(DATA_PATH "/configs/default.conf");
|
||||
}
|
||||
else
|
||||
{
|
||||
writer.saveTo(std::string(DATA_PATH "/configs/") + ArgS + ".conf", false);
|
||||
writer.saveTo(std::string(DATA_PATH "/configs/") + args.ArgS() + ".conf");
|
||||
}
|
||||
logging::Info("cat_save: Sorting configs...");
|
||||
getAndSortAllConfigs();
|
||||
logging::Info("cat_save: Closing dir...");
|
||||
closedir(config_directory);
|
||||
logging::Info("cat_save: Enabeling cathook...");
|
||||
settings::RVarLock.store(false);
|
||||
}
|
||||
|
||||
static CatCommand save("save", "", [](const CCommand &args) {
|
||||
if (!settings::RVarLock.load())
|
||||
{
|
||||
settings::RVarLock.store(true);
|
||||
std::thread loader;
|
||||
if (args.ArgC() == 1)
|
||||
{
|
||||
std::string string;
|
||||
loader = std::thread(save_thread, 1, string);
|
||||
}
|
||||
else
|
||||
{
|
||||
loader = std::thread(save_thread, args.ArgC(), args.Arg(1));
|
||||
}
|
||||
loader.detach();
|
||||
}
|
||||
});
|
||||
|
||||
void load_thread(const int ArgC, const std::string ArgS)
|
||||
{
|
||||
static CatCommand load("load", "", [](const CCommand &args) {
|
||||
settings::SettingsReader loader{ settings::Manager::instance() };
|
||||
if (ArgC == 1)
|
||||
if (args.ArgC() == 1)
|
||||
{
|
||||
loader.loadFrom(DATA_PATH "/configs/default.conf");
|
||||
}
|
||||
else
|
||||
{
|
||||
std::string backup = ArgS;
|
||||
std::string backup = args.ArgS();
|
||||
std::string ArgS = backup;
|
||||
ArgS.erase(std::remove(ArgS.begin(), ArgS.end(), '\n'), ArgS.end());
|
||||
ArgS.erase(std::remove(ArgS.begin(), ArgS.end(), '\r'), ArgS.end());
|
||||
#if ENABLE_VISUALS
|
||||
loader.loadFrom(std::string(DATA_PATH "/configs/") + ArgS + ".conf");
|
||||
#else
|
||||
for (int i = 0;; i++)
|
||||
{
|
||||
if (loader.loadFrom(std::string(DATA_PATH "/configs/") + ArgS + ".conf"))
|
||||
break;
|
||||
if (i > 5)
|
||||
{
|
||||
logging::Info("cat_load: Force crash. Couldn't load config!");
|
||||
std::terminate();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
settings::RVarLock.store(false);
|
||||
}
|
||||
|
||||
static CatCommand load("load", "", [](const CCommand &args) {
|
||||
if (!settings::RVarLock.load())
|
||||
{
|
||||
settings::RVarLock.store(true);
|
||||
std::thread saver;
|
||||
if (args.ArgC() == 1)
|
||||
{
|
||||
std::string string;
|
||||
saver = std::thread(load_thread, 1, string);
|
||||
}
|
||||
else
|
||||
{
|
||||
saver = std::thread(load_thread, args.ArgC(), args.Arg(1));
|
||||
}
|
||||
saver.detach();
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -6,5 +6,5 @@
|
||||
|
||||
namespace settings
|
||||
{
|
||||
std::atomic<bool> RVarLock{ false };
|
||||
std::atomic<bool> cathook_disabled{ false };
|
||||
}
|
||||
|
@ -14,10 +14,10 @@ settings::SettingsWriter::SettingsWriter(settings::Manager &manager) : manager(m
|
||||
{
|
||||
}
|
||||
|
||||
bool settings::SettingsWriter::saveTo(std::string path, bool only_changed)
|
||||
bool settings::SettingsWriter::saveTo(std::string path)
|
||||
{
|
||||
logging::Info("cat_save: started");
|
||||
this->only_changed = only_changed;
|
||||
this->only_changed = true;
|
||||
|
||||
stream.open(path, std::ios::out);
|
||||
|
||||
@ -105,6 +105,11 @@ bool settings::SettingsReader::loadFrom(std::string path)
|
||||
return false;
|
||||
}
|
||||
|
||||
for (auto &v : settings::Manager::instance().registered)
|
||||
{
|
||||
v.second.variable.fromString(v.second.defaults);
|
||||
}
|
||||
|
||||
while (!stream.fail())
|
||||
{
|
||||
char c;
|
||||
|
@ -101,7 +101,6 @@ static void initPlayerlist()
|
||||
pl.state = playerlist::k_EState((int) pl.state + 1);
|
||||
if ((int) pl.state > (int) playerlist::k_EState::STATE_LAST)
|
||||
pl.state = playerlist::k_EState(0);
|
||||
logging::Info("%s", std::to_string(steam).c_str());
|
||||
controller->updatePlayerState(userid, playerlist::k_Names[(int) pl.state]);
|
||||
});
|
||||
}
|
||||
|
@ -12,10 +12,10 @@
|
||||
Created on 26.07.18.
|
||||
*/
|
||||
|
||||
static settings::RVariable<rgba_t> color_team_red{ "zk.style.player-list.team.red", "ce1015" };
|
||||
static settings::RVariable<rgba_t> color_team_red{ "zk.style.player-list.team.red", "d10e25" };
|
||||
static settings::RVariable<rgba_t> color_team_red_dead{ "zk.style.player-list.team.red-dead", "660000" };
|
||||
static settings::RVariable<rgba_t> color_team_blue{ "zk.style.player-list.team.blue", "0000ff" };
|
||||
static settings::RVariable<rgba_t> color_team_blue_dead{ "zk.style.player-list.team.blue-dead", "000066" };
|
||||
static settings::RVariable<rgba_t> color_team_blue_dead{ "zk.style.player-list.team.blue-dead", "6f6fce" };
|
||||
static settings::RVariable<rgba_t> color_team_other{ "zk.style.player-list.team.other", "E6E6E6" };
|
||||
static settings::RVariable<rgba_t> color_team_other_dead{ "zk.style.player-list.team.other-dead", "E6E6E6" };
|
||||
|
||||
|
Reference in New Issue
Block a user