A less autistic way of writing this?
Hey so, just been doing nothing in particular recently so I decided to clean some shit up. Therefore, was wondering a better way of doing the following;
void Manager::saving()
{
if (g_Save)
{
if (g_Options.selected_config_index == 0)
{
std::ofstream ofs("hvh_pistol", std::ios::binary);
ofs.write((char*)&g_Options, sizeof(g_Options));
}
else if (g_Options.selected_config_index == 1)
{
std::ofstream ofs("hvh_auto", std::ios::binary);
ofs.write((char*)&g_Options, sizeof(g_Options));
}
else if (g_Options.selected_config_index == 2)
{
std::ofstream ofs("hvh_scout", std::ios::binary);
ofs.write((char*)&g_Options, sizeof(g_Options));
}
else if (g_Options.selected_config_index == 3)
{
std::ofstream ofs("hvh_awp", std::ios::binary);
ofs.write((char*)&g_Options, sizeof(g_Options));
}
else if (g_Options.selected_config_index == 4)
{
std::ofstream ofs("hvh_deagle", std::ios::binary);
ofs.write((char*)&g_Options, sizeof(g_Options));
}
else if (g_Options.selected_config_index == 5)
{
std::ofstream ofs("hvh_revolver", std::ios::binary);
ofs.write((char*)&g_Options, sizeof(g_Options));
}
else if (g_Options.selected_config_index == 6)
{
std::ofstream ofs("hvh_rifle", std::ios::binary);
ofs.write((char*)&g_Options, sizeof(g_Options));
}
g_Save = false;
}
}
void Manager::loading()
{
if (g_Load)
{
if (g_Options.selected_config_index == 0)
{
std::ifstream ifs("hvh_pistol", std::ios::binary);
ifs.read((char*)&g_Options, sizeof(g_Options));
}
else if (g_Options.selected_config_index == 1)
{
std::ifstream ifs("hvh_auto", std::ios::binary);
ifs.read((char*)&g_Options, sizeof(g_Options));
}
else if (g_Options.selected_config_index == 2)
{
std::ifstream ifs("hvh_scout", std::ios::binary);
ifs.read((char*)&g_Options, sizeof(g_Options));
}
else if (g_Options.selected_config_index == 3)
{
std::ifstream ifs("hvh_awp", std::ios::binary);
ifs.read((char*)&g_Options, sizeof(g_Options));
}
else if (g_Options.selected_config_index == 4)
{
std::ifstream ifs("hvh_deagle", std::ios::binary);
ifs.read((char*)&g_Options, sizeof(g_Options));
}
else if (g_Options.selected_config_index == 5)
{
std::ifstream ifs("hvh_revolver", std::ios::binary);
ifs.read((char*)&g_Options, sizeof(g_Options));
}
else if (g_Options.selected_config_index == 6)
{
std::ifstream ifs("hvh_rifle", std::ios::binary);
ifs.read((char*)&g_Options, sizeof(g_Options));
}
g_Load = false;
}
}
Not looking for paste or anything, I would appreciate some links that I can read up on.
I personally made an aimbot override system where every weapon uses global settings unless the user creates an override for it, which are all stored in a map sorted by ItemDefinitionIndex. Then in my config loading/saving I do a for each to store overrides recursively in the json to produce something like this:
"Overrides" : {
"0" : {
"AimKey" : 6,
"AimStep" : true,
"AutoCrouch" : false,
"AutoFire" : true,
"AutoScope" : false,
"AutoSlow" : false,
"Autowall" : true,
"Backtrack" : true,
"BodyBullet" : 0,
"BodyHP" : 0.0,
"DrawFov" : false,
"DrawSpread" : false,
"FOV" : 5.0,
"FriendlyFire" : false,
"HitChance" : false,
"HitChanceAmt" : 0.0,
"Hitboxes" : {
"arms" : false,
"arms_edge" : false,
"chest" : false,
"chest_edge" : false,
"feet" : false,
"feet_edge" : false,
"head" : true,
"head_edge" : false,
"legs" : false,
"legs_edge" : false,
"neck" : true,
"neck_edge" : false,
"pelvis" : true,
"pelvis_edge" : false
},
"MinDamage" : 10.0,
"OnKey" : true,
"Override" : true,
"RCS" : 0,
"SilentAim" : false,
"Speed" : 0.5,
"TargetMethod" : 0,
"VeloPrediction" : false
},
"1" : {
"AimKey" : 6,
"AimStep" : true,
"AutoCrouch" : false,
"AutoFire" : true,
"AutoScope" : false,
"AutoSlow" : false,
"Autowall" : true,
"Backtrack" : true,
"BodyBullet" : 0,
"BodyHP" : 0.0,
"DrawFov" : false,
"DrawSpread" : false,
"FOV" : 5.0,
"FriendlyFire" : false,
"HitChance" : false,
"HitChanceAmt" : 33.478000640869141,
"Hitboxes" : {
"arms" : false,
"arms_edge" : false,
"chest" : false,
"chest_edge" : false,
"feet" : false,
"feet_edge" : false,
"head" : true,
"head_edge" : false,
"legs" : false,
"legs_edge" : false,
"neck" : false,
"neck_edge" : false,
"pelvis" : false,
"pelvis_edge" : false
},
"MinDamage" : 10.0,
"OnKey" : true,
"Override" : true,
"RCS" : 0,
"SilentAim" : false,
"Speed" : 1.0,
"TargetMethod" : 0,
"VeloPrediction" : false
},
"10" : {
"AimKey" : 6,
"AimStep" : true,
"AutoCrouch" : false,
"AutoFire" : true,
"AutoScope" : false,
"AutoSlow" : false,
"Autowall" : true,
"Backtrack" : true,
"BodyBullet" : 0,
"BodyHP" : 0.0,
"DrawFov" : false,
"DrawSpread" : false,
"FOV" : 5.0,
"FriendlyFire" : false,
"HitChance" : false,
"HitChanceAmt" : 0.0,
"Hitboxes" : {
"arms" : false,
"arms_edge" : false,
"chest" : false,
"chest_edge" : false,
"feet" : false,
"feet_edge" : false,
"head" : true,
"head_edge" : false,
"legs" : false,
"legs_edge" : false,
"neck" : true,
"neck_edge" : false,
"pelvis" : true,
"pelvis_edge" : false
},
"MinDamage" : 10.0,
"OnKey" : true,
"Override" : true,
"RCS" : 1,
"SilentAim" : false,
"Speed" : 0.5,
"TargetMethod" : 0,
"VeloPrediction" : false
},
"11" : {
"AimKey" : 6,
"AimStep" : true,
"AutoCrouch" : false,
"AutoFire" : true,
"AutoScope" : false,
"AutoSlow" : false,
"Autowall" : true,
"Backtrack" : true,
"BodyBullet" : 0,
"BodyHP" : 0.0,
"DrawFov" : false,
"DrawSpread" : false,
"FOV" : 5.0,
"FriendlyFire" : false,
"HitChance" : false,
"HitChanceAmt" : 0.0,
"Hitboxes" : {
"arms" : false,
"arms_edge" : false,
"chest" : false,
"chest_edge" : false,
"feet" : false,
"feet_edge" : false,
"head" : true,
"head_edge" : false,
"legs" : false,
"legs_edge" : false,
"neck" : true,
"neck_edge" : false,
"pelvis" : true,
"pelvis_edge" : false
},
"MinDamage" : 10.0,
"OnKey" : true,
"Override" : true,
"RCS" : 1,
"SilentAim" : false,
"Speed" : 0.5,
"TargetMethod" : 0,
"VeloPrediction" : false
},
"13" : {
"AimKey" : 6,
"AimStep" : true,
"AutoCrouch" : false,
"AutoFire" : true,
"AutoScope" : false,
"AutoSlow" : false,
"Autowall" : true,
"Backtrack" : true,
"BodyBullet" : 0,
"BodyHP" : 0.0,
"DrawFov" : false,
"DrawSpread" : false,
"FOV" : 5.0,
"FriendlyFire" : false,
"HitChance" : false,
"HitChanceAmt" : 0.0,
"Hitboxes" : {
"arms" : false,
"arms_edge" : false,
"chest" : false,
"chest_edge" : false,
"feet" : false,
"feet_edge" : false,
"head" : true,
"head_edge" : false,
"legs" : false,
"legs_edge" : false,
"neck" : true,
"neck_edge" : false,
"pelvis" : true,
"pelvis_edge" : false
},
"MinDamage" : 10.0,
"OnKey" : true,
"Override" : true,
"RCS" : 1,
"SilentAim" : false,
"Speed" : 0.5,
"TargetMethod" : 0,
"VeloPrediction" : false
},
"16" : {
"AimKey" : 6,
"AimStep" : true,
"AutoCrouch" : false,
"AutoFire" : true,
"AutoScope" : false,
"AutoSlow" : false,
"Autowall" : true,
"Backtrack" : true,
"BodyBullet" : 0,
"BodyHP" : 0.0,
"DrawFov" : false,
"DrawSpread" : false,
"FOV" : 5.0,
"FriendlyFire" : false,
"HitChance" : false,
"HitChanceAmt" : 0.0,
"Hitboxes" : {
"arms" : false,
"arms_edge" : false,
"chest" : false,
"chest_edge" : false,
"feet" : false,
"feet_edge" : false,
"head" : true,
"head_edge" : false,
"legs" : false,
"legs_edge" : false,
"neck" : true,
"neck_edge" : false,
"pelvis" : true,
"pelvis_edge" : false
},
"MinDamage" : 10.0,
"OnKey" : true,
"Override" : true,
"RCS" : 1,
"SilentAim" : false,
"Speed" : 0.5,
"TargetMethod" : 0,
"VeloPrediction" : false
},
"38" : {
"AimKey" : 6,
"AimStep" : true,
"AutoCrouch" : false,
"AutoFire" : true,
"AutoScope" : false,
"AutoSlow" : false,
"Autowall" : true,
"Backtrack" : true,
"BodyBullet" : 0,
"BodyHP" : 0.0,
"DrawFov" : false,
"DrawSpread" : false,
"FOV" : 5.0,
"FriendlyFire" : false,
"HitChance" : false,
"HitChanceAmt" : 0.0,
"Hitboxes" : {
"arms" : false,
"arms_edge" : false,
"chest" : false,
"chest_edge" : false,
"feet" : false,
"feet_edge" : false,
"head" : true,
"head_edge" : false,
"legs" : false,
"legs_edge" : false,
"neck" : true,
"neck_edge" : false,
"pelvis" : true,
"pelvis_edge" : false
},
"MinDamage" : 10.0,
"OnKey" : true,
"Override" : true,
"RCS" : 1,
"SilentAim" : false,
"Speed" : 0.5,
"TargetMethod" : 0,
"VeloPrediction" : false
},
"39" : {
"AimKey" : 6,
"AimStep" : true,
"AutoCrouch" : false,
"AutoFire" : true,
"AutoScope" : false,
"AutoSlow" : false,
"Autowall" : true,
"Backtrack" : true,
"BodyBullet" : 0,
"BodyHP" : 0.0,
"DrawFov" : false,
"DrawSpread" : false,
"FOV" : 5.0,
"FriendlyFire" : false,
"HitChance" : false,
"HitChanceAmt" : 0.0,
"Hitboxes" : {
"arms" : false,
"arms_edge" : false,
"chest" : false,
"chest_edge" : false,
"feet" : false,
"feet_edge" : false,
"head" : true,
"head_edge" : false,
"legs" : false,
"legs_edge" : false,
"neck" : true,
"neck_edge" : false,
"pelvis" : true,
"pelvis_edge" : false
},
"MinDamage" : 10.0,
"OnKey" : true,
"Override" : true,
"RCS" : 1,
"SilentAim" : false,
"Speed" : 0.5,
"TargetMethod" : 0,
"VeloPrediction" : false
},
etc
It’s not the most optimised system, but it’s pretty cute tbh
|
|
|