2021-05-19 14:32:30 +02:00
|
|
|
#pragma once
|
2021-05-19 16:05:21 +02:00
|
|
|
#include "enums.hpp"
|
2021-05-19 14:32:30 +02:00
|
|
|
|
|
|
|
#ifndef GLOBALS_H
|
|
|
|
#define GLOBALS_H
|
|
|
|
|
2021-05-19 18:09:13 +02:00
|
|
|
using namespace big;
|
2021-05-19 14:32:30 +02:00
|
|
|
struct globals {
|
2021-05-20 18:00:03 +02:00
|
|
|
nlohmann::json default_options;
|
|
|
|
nlohmann::json options;
|
|
|
|
|
2022-01-06 08:47:00 +01:00
|
|
|
struct debug {
|
|
|
|
bool script_event_logging = false;
|
|
|
|
};
|
|
|
|
|
2021-07-24 00:16:04 +02:00
|
|
|
struct tunables {
|
|
|
|
bool disable_phone = false;
|
2021-07-24 14:39:13 +02:00
|
|
|
bool no_idle_kick = false;
|
2021-07-24 00:16:04 +02:00
|
|
|
};
|
|
|
|
|
2021-05-26 13:17:19 +02:00
|
|
|
struct player {
|
2021-07-23 12:28:17 +02:00
|
|
|
int character_slot = 1;
|
|
|
|
int set_level = 130;
|
2021-05-26 13:17:19 +02:00
|
|
|
bool spectating = false;
|
|
|
|
};
|
|
|
|
|
2021-07-26 00:38:03 +02:00
|
|
|
struct protections {
|
2021-08-05 23:06:47 +02:00
|
|
|
struct script_events {
|
|
|
|
bool bounty = true;
|
|
|
|
bool ceo_ban = true;
|
|
|
|
bool ceo_kick = true;
|
|
|
|
bool ceo_money = true;
|
|
|
|
bool clear_wanted_level = true;
|
|
|
|
bool fake_deposit = true;
|
|
|
|
bool force_mission = true;
|
|
|
|
bool force_teleport = true;
|
|
|
|
bool gta_banner = true;
|
2022-01-26 15:23:57 +01:00
|
|
|
bool network_bail = true;
|
2021-08-05 23:06:47 +02:00
|
|
|
bool personal_vehicle_destroyed = true;
|
|
|
|
bool remote_off_radar = true;
|
2022-01-26 21:37:08 +01:00
|
|
|
bool rotate_cam = true;
|
2021-08-05 23:06:47 +02:00
|
|
|
bool send_to_cutscene = true;
|
|
|
|
bool send_to_island = true;
|
|
|
|
bool sound_spam = true;
|
|
|
|
bool spectate = true;
|
|
|
|
bool transaction_error = true;
|
|
|
|
bool vehicle_kick = true;
|
|
|
|
};
|
|
|
|
|
2022-01-21 23:13:10 +01:00
|
|
|
bool freemode_terminated = false;
|
|
|
|
|
2021-08-05 23:06:47 +02:00
|
|
|
script_events script_events{};
|
2021-07-26 00:38:03 +02:00
|
|
|
};
|
|
|
|
|
2021-05-19 14:32:30 +02:00
|
|
|
struct self {
|
2021-07-26 21:18:19 +02:00
|
|
|
struct frame_flags {
|
|
|
|
bool explosive_ammo = false;
|
|
|
|
bool explosive_melee = false;
|
|
|
|
bool fire_ammo = false;
|
|
|
|
bool super_jump = false;
|
|
|
|
};
|
|
|
|
|
2021-05-19 18:09:13 +02:00
|
|
|
bool godmode = false;
|
2021-09-21 01:44:24 +02:00
|
|
|
bool free_cam = false;
|
2021-05-21 01:16:33 +02:00
|
|
|
bool off_radar = false;
|
2021-07-28 00:46:00 +02:00
|
|
|
bool never_wanted = false;
|
2021-05-19 14:32:30 +02:00
|
|
|
bool noclip = false;
|
2021-05-21 00:52:59 +02:00
|
|
|
bool no_ragdoll = false;
|
2021-12-19 00:25:54 +01:00
|
|
|
bool super_run = false;
|
2022-01-05 18:30:16 +01:00
|
|
|
bool force_wanted_level = false;
|
2021-07-28 00:46:00 +02:00
|
|
|
int wanted_level = 0;
|
2021-07-26 21:18:19 +02:00
|
|
|
|
|
|
|
frame_flags frame_flags{};
|
2021-05-19 14:32:30 +02:00
|
|
|
};
|
|
|
|
|
2022-01-18 02:38:51 +01:00
|
|
|
struct settings {
|
|
|
|
struct hotkeys
|
|
|
|
{
|
|
|
|
bool editing_menu_toggle = false;
|
|
|
|
int menu_toggle = VK_INSERT;
|
|
|
|
int teleport_waypoint = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
hotkeys hotkeys{};
|
|
|
|
};
|
|
|
|
|
2021-12-18 19:24:30 +01:00
|
|
|
struct spoofing
|
|
|
|
{
|
|
|
|
bool spoof_username = false;
|
|
|
|
std::string username = "";
|
|
|
|
|
|
|
|
bool spoof_ip = true;
|
|
|
|
int ip_address[4] = { 42, 42, 42, 42};
|
|
|
|
|
|
|
|
bool spoof_rockstar_id = false;
|
|
|
|
uint64_t rockstar_id = 0;
|
|
|
|
};
|
|
|
|
|
2021-05-19 18:09:13 +02:00
|
|
|
struct vehicle {
|
2021-08-03 20:29:54 +02:00
|
|
|
struct speedo_meter {
|
|
|
|
SpeedoMeter type = SpeedoMeter::DISABLED;
|
|
|
|
|
|
|
|
float x = .9f;
|
|
|
|
float y = .72f;
|
|
|
|
|
|
|
|
bool left_side = false;
|
|
|
|
};
|
|
|
|
|
2021-08-16 23:11:08 +02:00
|
|
|
bool god_mode = false;
|
2021-05-20 23:18:44 +02:00
|
|
|
bool horn_boost = false;
|
2022-01-14 16:12:30 +01:00
|
|
|
bool ls_customs = false; // don't save this to disk
|
2022-01-18 02:06:28 +01:00
|
|
|
bool pv_teleport_into = false;
|
2021-08-03 20:29:54 +02:00
|
|
|
speedo_meter speedo_meter{};
|
2021-05-19 18:09:13 +02:00
|
|
|
};
|
|
|
|
|
2021-05-19 15:32:51 +02:00
|
|
|
struct weapons {
|
2021-05-19 18:09:13 +02:00
|
|
|
CustomWeapon custom_weapon = CustomWeapon::NONE;
|
2021-05-20 22:39:56 +02:00
|
|
|
char vehicle_gun_model[12] = "bus";
|
2022-02-13 23:52:33 +01:00
|
|
|
bool infinite_ammo = false;
|
|
|
|
bool infinite_mag = false;
|
2021-05-19 15:32:51 +02:00
|
|
|
};
|
|
|
|
|
2021-05-21 02:28:14 +02:00
|
|
|
struct window {
|
2021-12-22 21:26:26 +01:00
|
|
|
bool debug = false;
|
2021-07-25 21:06:49 +02:00
|
|
|
bool handling = false;
|
2021-05-21 12:44:43 +02:00
|
|
|
bool log = false;
|
2021-07-25 21:06:49 +02:00
|
|
|
bool main = true;
|
2021-07-23 21:15:32 +02:00
|
|
|
bool users = true;
|
2021-05-26 13:17:19 +02:00
|
|
|
bool player = false;
|
|
|
|
|
|
|
|
int x;
|
|
|
|
int y;
|
2021-05-21 02:28:14 +02:00
|
|
|
};
|
|
|
|
|
2021-07-23 18:06:33 +02:00
|
|
|
int friend_count = 0;
|
|
|
|
int player_count = 0;
|
2021-05-26 13:17:19 +02:00
|
|
|
|
2022-01-06 08:47:00 +01:00
|
|
|
debug debug{};
|
2021-07-24 00:16:04 +02:00
|
|
|
tunables tunables{};
|
2021-05-26 13:17:19 +02:00
|
|
|
player player{};
|
2021-07-26 00:38:03 +02:00
|
|
|
protections protections{};
|
2021-05-19 14:32:30 +02:00
|
|
|
self self{};
|
2022-01-18 02:38:51 +01:00
|
|
|
settings settings{};
|
2021-12-18 19:24:30 +01:00
|
|
|
spoofing spoofing{};
|
2021-05-19 18:09:13 +02:00
|
|
|
vehicle vehicle{};
|
2021-05-19 15:32:51 +02:00
|
|
|
weapons weapons{};
|
2021-05-21 02:28:14 +02:00
|
|
|
window window{};
|
2021-05-20 15:51:42 +02:00
|
|
|
|
|
|
|
void from_json(const nlohmann::json& j)
|
|
|
|
{
|
2022-01-06 08:47:00 +01:00
|
|
|
this->debug.script_event_logging = j["debug"]["script_event_logging"];
|
|
|
|
|
2021-08-05 23:06:47 +02:00
|
|
|
this->protections.script_events.bounty = j["protections"]["script_events"]["bounty"];
|
|
|
|
this->protections.script_events.ceo_ban = j["protections"]["script_events"]["ceo_ban"];
|
|
|
|
this->protections.script_events.ceo_kick = j["protections"]["script_events"]["ceo_kick"];
|
|
|
|
this->protections.script_events.ceo_money = j["protections"]["script_events"]["ceo_money"];
|
|
|
|
this->protections.script_events.clear_wanted_level = j["protections"]["script_events"]["clear_wanted_level"];
|
|
|
|
this->protections.script_events.fake_deposit = j["protections"]["script_events"]["fake_deposit"];
|
|
|
|
this->protections.script_events.force_mission = j["protections"]["script_events"]["force_mission"];
|
|
|
|
this->protections.script_events.force_teleport = j["protections"]["script_events"]["force_teleport"];
|
|
|
|
this->protections.script_events.gta_banner = j["protections"]["script_events"]["gta_banner"];
|
2022-01-26 15:23:57 +01:00
|
|
|
this->protections.script_events.network_bail = j["protections"]["script_events"]["network_bail"];
|
2021-08-05 23:06:47 +02:00
|
|
|
this->protections.script_events.personal_vehicle_destroyed = j["protections"]["script_events"]["personal_vehicle_destroyed"];
|
|
|
|
this->protections.script_events.remote_off_radar = j["protections"]["script_events"]["remote_off_radar"];
|
2022-01-26 21:37:08 +01:00
|
|
|
this->protections.script_events.rotate_cam = j["protections"]["script_events"]["rotate_cam"];
|
2021-08-05 23:06:47 +02:00
|
|
|
this->protections.script_events.send_to_cutscene = j["protections"]["script_events"]["send_to_cutscene"];
|
|
|
|
this->protections.script_events.send_to_island = j["protections"]["script_events"]["send_to_island"];
|
|
|
|
this->protections.script_events.sound_spam = j["protections"]["script_events"]["sound_spam"];
|
|
|
|
this->protections.script_events.spectate = j["protections"]["script_events"]["spectate"];
|
|
|
|
this->protections.script_events.transaction_error = j["protections"]["script_events"]["transaction_error"];
|
|
|
|
this->protections.script_events.vehicle_kick = j["protections"]["script_events"]["vehicle_kick"];
|
2021-07-26 00:38:03 +02:00
|
|
|
|
2021-07-24 00:16:04 +02:00
|
|
|
this->tunables.disable_phone = j["tunables"]["disable_phone"];
|
2021-07-24 14:39:13 +02:00
|
|
|
this->tunables.no_idle_kick = j["tunables"]["no_idle_kick"];
|
2021-07-24 00:16:04 +02:00
|
|
|
|
2021-05-20 15:51:42 +02:00
|
|
|
this->self.godmode = j["self"]["godmode"];
|
2021-05-21 01:16:33 +02:00
|
|
|
this->self.off_radar = j["self"]["off_radar"];
|
2021-07-28 00:46:00 +02:00
|
|
|
this->self.never_wanted = j["self"]["never_wanted"];
|
2021-05-21 00:52:59 +02:00
|
|
|
this->self.no_ragdoll = j["self"]["no_ragdoll"];
|
2021-12-19 00:25:54 +01:00
|
|
|
this->self.super_run = j["self"]["super_run"];
|
2021-05-20 15:51:42 +02:00
|
|
|
|
2021-07-26 21:18:19 +02:00
|
|
|
this->self.frame_flags.explosive_ammo = j["self"]["frame_flags"]["explosive_ammo"];
|
|
|
|
this->self.frame_flags.explosive_melee = j["self"]["frame_flags"]["explosive_melee"];
|
|
|
|
this->self.frame_flags.fire_ammo = j["self"]["frame_flags"]["fire_ammo"];
|
|
|
|
this->self.frame_flags.super_jump = j["self"]["frame_flags"]["super_jump"];
|
|
|
|
|
2022-01-18 02:38:51 +01:00
|
|
|
this->settings.hotkeys.menu_toggle = j["settings"]["hotkeys"]["menu_toggle"];
|
|
|
|
|
2021-12-18 19:24:30 +01:00
|
|
|
this->spoofing.spoof_ip = j["spoofing"]["spoof_ip"];
|
|
|
|
this->spoofing.spoof_rockstar_id = j["spoofing"]["spoof_rockstar_id"];
|
|
|
|
this->spoofing.spoof_username = j["spoofing"]["spoof_username"];
|
|
|
|
|
|
|
|
for (int i = 0; i < 4; i++)
|
|
|
|
this->spoofing.ip_address[i] = j["spoofing"]["ip_address"].at(i);
|
|
|
|
this->spoofing.rockstar_id = j["spoofing"]["rockstar_id"];
|
|
|
|
this->spoofing.username = j["spoofing"]["username"];
|
|
|
|
|
2021-08-16 23:11:08 +02:00
|
|
|
this->vehicle.god_mode = j["vehicle"]["god_mode"];
|
2021-05-20 23:18:44 +02:00
|
|
|
this->vehicle.horn_boost = j["vehicle"]["horn_boost"];
|
2022-01-18 02:06:28 +01:00
|
|
|
this->vehicle.pv_teleport_into = j["vehicle"]["pv_teleport_into"];
|
2021-08-03 20:29:54 +02:00
|
|
|
|
|
|
|
this->vehicle.speedo_meter.type = (SpeedoMeter)j["vehicle"]["speedo_meter"]["type"];
|
|
|
|
this->vehicle.speedo_meter.left_side = j["vehicle"]["speedo_meter"]["left_side"];
|
|
|
|
this->vehicle.speedo_meter.x = j["vehicle"]["speedo_meter"]["position_x"];
|
|
|
|
this->vehicle.speedo_meter.y = j["vehicle"]["speedo_meter"]["position_y"];
|
2021-05-20 15:51:42 +02:00
|
|
|
|
|
|
|
this->weapons.custom_weapon = (CustomWeapon)j["weapons"]["custom_weapon"];
|
2022-02-13 23:52:33 +01:00
|
|
|
this->weapons.infinite_ammo = j["weapons"]["infinite_ammo"];
|
|
|
|
this->weapons.infinite_mag = j["weapons"]["infinite_mag"];
|
2021-05-21 14:13:00 +02:00
|
|
|
|
2021-12-22 21:26:26 +01:00
|
|
|
this->window.debug = j["window"]["debug"];
|
2021-07-25 21:06:49 +02:00
|
|
|
this->window.handling = j["window"]["handling"];
|
2021-05-21 14:13:00 +02:00
|
|
|
this->window.log = j["window"]["log"];
|
|
|
|
this->window.main = j["window"]["main"];
|
2021-07-23 21:15:32 +02:00
|
|
|
this->window.users = j["window"]["users"];
|
2021-05-20 15:51:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
nlohmann::json to_json()
|
|
|
|
{
|
|
|
|
return nlohmann::json{
|
2022-01-06 08:47:00 +01:00
|
|
|
{
|
|
|
|
"debug",
|
|
|
|
{
|
|
|
|
{ "script_event_logging", this->debug.script_event_logging }
|
|
|
|
}
|
|
|
|
},
|
2021-07-26 00:38:03 +02:00
|
|
|
{
|
2021-08-05 23:06:47 +02:00
|
|
|
"protections",
|
|
|
|
{
|
|
|
|
{
|
|
|
|
"script_events", {
|
|
|
|
{ "bounty", this->protections.script_events.bounty },
|
|
|
|
{ "ceo_ban", this->protections.script_events.ceo_ban },
|
|
|
|
{ "ceo_kick", this->protections.script_events.ceo_kick },
|
|
|
|
{ "ceo_money", this->protections.script_events.ceo_money },
|
|
|
|
{ "clear_wanted_level", this->protections.script_events.clear_wanted_level },
|
|
|
|
{ "fake_deposit", this->protections.script_events.fake_deposit },
|
|
|
|
{ "force_mission", this->protections.script_events.force_mission },
|
|
|
|
{ "force_teleport", this->protections.script_events.force_teleport },
|
|
|
|
{ "gta_banner", this->protections.script_events.gta_banner },
|
2022-01-26 15:23:57 +01:00
|
|
|
{ "network_bail", this->protections.script_events.network_bail },
|
2021-08-05 23:06:47 +02:00
|
|
|
{ "personal_vehicle_destroyed", this->protections.script_events.personal_vehicle_destroyed },
|
|
|
|
{ "remote_off_radar", this->protections.script_events.remote_off_radar },
|
2022-01-26 21:37:08 +01:00
|
|
|
{ "rotate_cam", this->protections.script_events.rotate_cam },
|
2021-08-05 23:06:47 +02:00
|
|
|
{ "send_to_cutscene", this->protections.script_events.send_to_cutscene },
|
|
|
|
{ "send_to_island", this->protections.script_events.send_to_island },
|
|
|
|
{ "sound_spam", this->protections.script_events.sound_spam },
|
|
|
|
{ "spectate", this->protections.script_events.spectate },
|
|
|
|
{ "transaction_error", this->protections.script_events.transaction_error },
|
|
|
|
{ "vehicle_kick", this->protections.script_events.vehicle_kick }
|
|
|
|
}
|
|
|
|
}
|
2021-07-26 00:38:03 +02:00
|
|
|
}
|
|
|
|
},
|
2021-07-24 00:16:04 +02:00
|
|
|
{
|
|
|
|
"tunables", {
|
2021-07-24 14:39:13 +02:00
|
|
|
{ "disable_phone", this->tunables.disable_phone },
|
|
|
|
{ "no_idle_kick", this->tunables.no_idle_kick }
|
2021-07-24 00:16:04 +02:00
|
|
|
}
|
|
|
|
},
|
2021-05-20 15:51:42 +02:00
|
|
|
{
|
|
|
|
"self", {
|
2021-05-21 00:52:59 +02:00
|
|
|
{ "godmode", this->self.godmode },
|
2021-05-21 01:16:33 +02:00
|
|
|
{ "off_radar", this->self.off_radar },
|
2021-07-28 00:46:00 +02:00
|
|
|
{ "never_wanted", this->self.never_wanted },
|
2021-07-26 21:18:19 +02:00
|
|
|
{ "no_ragdoll", this->self.no_ragdoll },
|
2021-12-19 00:25:54 +01:00
|
|
|
{ "super_run", this->self.super_run },
|
2021-07-26 21:18:19 +02:00
|
|
|
|
|
|
|
{
|
|
|
|
"frame_flags", {
|
|
|
|
{ "explosive_ammo", this->self.frame_flags.explosive_ammo },
|
|
|
|
{ "explosive_melee", this->self.frame_flags.explosive_melee },
|
|
|
|
{ "fire_ammo", this->self.frame_flags.fire_ammo },
|
|
|
|
{ "super_jump", this->self.frame_flags.super_jump }
|
|
|
|
}
|
|
|
|
}
|
2021-05-20 15:51:42 +02:00
|
|
|
}
|
|
|
|
},
|
2022-01-18 02:38:51 +01:00
|
|
|
{
|
|
|
|
"settings", {
|
|
|
|
{ "hotkeys", {
|
|
|
|
{ "menu_toggle", this->settings.hotkeys.menu_toggle }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2021-12-18 19:24:30 +01:00
|
|
|
{
|
|
|
|
"spoofing", {
|
|
|
|
{ "spoof_ip", this->spoofing.spoof_ip },
|
|
|
|
{ "spoof_rockstar_id", this->spoofing.spoof_rockstar_id },
|
|
|
|
{ "spoof_username", this->spoofing.spoof_username },
|
|
|
|
{ "ip_address", nlohmann::json::array({
|
|
|
|
this->spoofing.ip_address[0],
|
|
|
|
this->spoofing.ip_address[1],
|
|
|
|
this->spoofing.ip_address[2],
|
|
|
|
this->spoofing.ip_address[3] })
|
|
|
|
},
|
|
|
|
{ "rockstar_id", this->spoofing.rockstar_id },
|
|
|
|
{ "username", this->spoofing.username }
|
|
|
|
}
|
|
|
|
},
|
2021-05-20 15:51:42 +02:00
|
|
|
{
|
|
|
|
"vehicle", {
|
2021-08-16 23:11:08 +02:00
|
|
|
{ "god_mode", this->vehicle.god_mode },
|
2021-05-20 23:18:44 +02:00
|
|
|
{ "horn_boost", this->vehicle.horn_boost },
|
2022-01-18 02:06:28 +01:00
|
|
|
{ "pv_teleport_into", this->vehicle.pv_teleport_into },
|
2021-08-03 20:29:54 +02:00
|
|
|
{
|
|
|
|
"speedo_meter", {
|
|
|
|
{ "type", (int)this->vehicle.speedo_meter.type },
|
|
|
|
{ "left_side", this->vehicle.speedo_meter.left_side },
|
|
|
|
{ "position_x", this->vehicle.speedo_meter.x },
|
|
|
|
{ "position_y", this->vehicle.speedo_meter.y }
|
|
|
|
}
|
|
|
|
}
|
2021-05-20 15:51:42 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"weapons", {
|
2022-02-08 23:06:33 -05:00
|
|
|
{ "custom_weapon", (int)this->weapons.custom_weapon },
|
2022-02-13 23:52:33 +01:00
|
|
|
{ "infinite_ammo", this->weapons.infinite_ammo },
|
|
|
|
{ "infinite_mag", this->weapons.infinite_mag }
|
2021-05-20 15:51:42 +02:00
|
|
|
}
|
2021-05-21 14:13:00 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"window", {
|
2021-12-22 21:26:26 +01:00
|
|
|
{ "debug", this->window.debug },
|
2021-07-25 21:06:49 +02:00
|
|
|
{ "handling", this->window.handling },
|
2021-05-21 14:13:00 +02:00
|
|
|
{ "log", this->window.log },
|
2021-07-23 21:15:32 +02:00
|
|
|
{ "main", this->window.main },
|
|
|
|
{ "users", this->window.users }
|
2021-05-21 14:13:00 +02:00
|
|
|
}
|
2021-05-20 15:51:42 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-05-20 18:00:03 +02:00
|
|
|
void attempt_save()
|
|
|
|
{
|
|
|
|
nlohmann::json& j = this->to_json();
|
|
|
|
|
2021-07-24 17:15:31 +02:00
|
|
|
if (deep_compare(this->options, j, true))
|
2021-07-24 15:27:41 +02:00
|
|
|
this->save();
|
2021-05-20 18:00:03 +02:00
|
|
|
}
|
|
|
|
|
2021-05-20 15:51:42 +02:00
|
|
|
bool load()
|
|
|
|
{
|
2021-05-20 18:00:03 +02:00
|
|
|
this->default_options = this->to_json();
|
|
|
|
|
2021-05-20 15:51:42 +02:00
|
|
|
std::string settings_file = std::getenv("appdata");
|
2021-07-24 15:27:41 +02:00
|
|
|
settings_file += this->settings_location;
|
2021-05-20 15:51:42 +02:00
|
|
|
|
|
|
|
std::ifstream file(settings_file);
|
|
|
|
|
|
|
|
if (!file.is_open())
|
|
|
|
{
|
|
|
|
this->write_default_config();
|
|
|
|
|
|
|
|
file.open(settings_file);
|
|
|
|
}
|
|
|
|
|
2021-07-24 17:15:31 +02:00
|
|
|
try
|
|
|
|
{
|
|
|
|
file >> this->options;
|
2021-12-24 01:58:56 +01:00
|
|
|
|
|
|
|
file.close();
|
2021-07-24 17:15:31 +02:00
|
|
|
}
|
|
|
|
catch (const std::exception&)
|
2021-07-24 15:27:41 +02:00
|
|
|
{
|
2021-12-24 01:58:56 +01:00
|
|
|
file.close();
|
|
|
|
|
2021-07-24 17:15:31 +02:00
|
|
|
LOG(WARNING) << "Detected corrupt settings, writing default config...";
|
|
|
|
|
|
|
|
this->write_default_config();
|
|
|
|
|
|
|
|
return this->load();
|
2021-07-24 15:27:41 +02:00
|
|
|
}
|
2021-05-20 15:51:42 +02:00
|
|
|
|
2021-07-23 21:15:32 +02:00
|
|
|
bool should_save = this->deep_compare(this->options, this->default_options);
|
2021-05-20 15:51:42 +02:00
|
|
|
|
2021-05-20 18:00:03 +02:00
|
|
|
this->from_json(this->options);
|
|
|
|
|
2021-05-20 15:51:42 +02:00
|
|
|
if (should_save)
|
|
|
|
{
|
|
|
|
LOG(INFO) << "Updating settings.";
|
|
|
|
save();
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-05-21 00:52:59 +02:00
|
|
|
private:
|
2021-07-24 15:27:41 +02:00
|
|
|
const char* settings_location = "\\BigBaseV2\\settings.json";
|
|
|
|
|
2021-07-24 17:15:31 +02:00
|
|
|
bool deep_compare(nlohmann::json& current_settings, const nlohmann::json& default_settings, bool compare_value = false)
|
2021-07-23 21:15:32 +02:00
|
|
|
{
|
|
|
|
bool should_save = false;
|
|
|
|
|
|
|
|
for (auto& e : default_settings.items())
|
|
|
|
{
|
|
|
|
const std::string &key = e.key();
|
|
|
|
|
2021-07-24 17:15:31 +02:00
|
|
|
if (current_settings.count(key) == 0 || (compare_value && current_settings[key] != e.value()))
|
2021-07-23 21:15:32 +02:00
|
|
|
{
|
|
|
|
current_settings[key] = e.value();
|
|
|
|
|
|
|
|
should_save = true;
|
|
|
|
}
|
2021-12-18 19:24:30 +01:00
|
|
|
else if (current_settings[key].is_object() && e.value().is_object())
|
2021-07-23 21:15:32 +02:00
|
|
|
{
|
2021-07-24 17:15:31 +02:00
|
|
|
if (deep_compare(current_settings[key], e.value(), compare_value))
|
2021-07-23 21:15:32 +02:00
|
|
|
should_save = true;
|
|
|
|
}
|
2021-12-18 19:24:30 +01:00
|
|
|
else if (!current_settings[key].is_object() && e.value().is_object()) {
|
2021-07-23 21:15:32 +02:00
|
|
|
current_settings[key] = e.value();
|
|
|
|
|
|
|
|
should_save = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return should_save;
|
|
|
|
}
|
|
|
|
|
2021-05-20 15:51:42 +02:00
|
|
|
bool save()
|
|
|
|
{
|
|
|
|
std::string settings_file = std::getenv("appdata");
|
2021-07-24 15:27:41 +02:00
|
|
|
settings_file += this->settings_location;
|
2021-05-20 15:51:42 +02:00
|
|
|
|
|
|
|
std::ofstream file(settings_file, std::ios::out | std::ios::trunc);
|
|
|
|
file << this->to_json().dump(4);
|
|
|
|
file.close();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool write_default_config()
|
|
|
|
{
|
|
|
|
std::string settings_file = std::getenv("appdata");
|
2021-07-24 15:27:41 +02:00
|
|
|
settings_file += this->settings_location;
|
2021-05-20 15:51:42 +02:00
|
|
|
|
|
|
|
std::ofstream file(settings_file, std::ios::out);
|
|
|
|
file << this->to_json().dump(4);
|
|
|
|
file.close();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2021-05-19 14:32:30 +02:00
|
|
|
};
|
|
|
|
|
2021-05-20 15:51:42 +02:00
|
|
|
inline struct globals g;
|
|
|
|
#endif // !GLOBALS_H
|