Skip to content

Instantly share code, notes, and snippets.

@iamtis
Created November 20, 2016 05:39
Show Gist options
  • Save iamtis/208ed25c89325f59fd37a3e340882951 to your computer and use it in GitHub Desktop.
Save iamtis/208ed25c89325f59fd37a3e340882951 to your computer and use it in GitHub Desktop.
#pragma once
#include <fstream>
#include <Windows.h>
#include <sstream>
#include <vector>
#include <unordered_map>
#include "Json.h"
#include "SDK.h"
class Settings {
public:
inline void SetSkins();
inline void SetKnives();
inline Settings();
private:
inline void set_skin(std::string weaponID);
inline void set_knife(std::string weaponID, char team);
struct EconomyItemCfg {
int iItemDefinitionIndex = 0;
int nFallbackPaintKit = 0;
int nFallbackSeed = 0;
int nFallbackStatTrak = -1;
int iEntityQuality = 4;
char* szCustomName = nullptr;
float flFallbackWear = 0.1f;
};
std::unordered_map<int, EconomyItemCfg> g_SkinChangerCfg;
std::unordered_map<int, const char*> g_ViewModelCfg;
std::unordered_map<const char*, const char*> g_KillIconCfg;
nlohmann::json SkinJson;
std::fstream settings_file;
std::string current_directory;
};
Settings::Settings() {
LPSTR buffer = "";
std::stringstream convert;
GetCurrentDirectory(MAX_PATH, buffer);
convert << buffer;
convert >> current_directory;
current_directory += current_directory + "\\skins.json";
settings_file.open(current_directory);
if (settings_file.good()) {
SkinJson = nlohmann::json::parse(settings_file);
}
else {
LPCSTR current_directory_LPCSTR = current_directory.c_str();
CreateFile(current_directory_LPCSTR, (GENERIC_READ | GENERIC_WRITE), (FILE_SHARE_DELETE | FILE_SHARE_WRITE | FILE_SHARE_READ), NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
SkinJson = nlohmann::json::parse(settings_file);
}
}
inline void Settings::set_skin(std::string weaponID)
{
std::vector<char*> name = SkinJson[weaponID]["Name"];
std::string float_string = SkinJson[weaponID]["Float"] + "f";
std::stringstream convert;
float skin_float;
convert << float_string;
convert >> skin_float;
g_SkinChangerCfg[SkinJson[weaponID]["WeaponID"]].nFallbackPaintKit = SkinJson[weaponID]["Skin"];
g_SkinChangerCfg[SkinJson[weaponID]["WeaponID"]].nFallbackStatTrak = SkinJson[weaponID]["Stattrak"];
g_SkinChangerCfg[SkinJson[weaponID]["WeaponID"]].flFallbackWear = skin_float;
g_SkinChangerCfg[SkinJson[weaponID]["WeaponID"]].szCustomName = name[0];
}
inline void Settings::set_knife(std::string weaponID, char team)
{
std::vector<char*> name = SkinJson[weaponID]["Name"];
g_SkinChangerCfg[SkinJson[weaponID]["WeaponID"]].nFallbackPaintKit = SkinJson[weaponID]["Skin"];
g_SkinChangerCfg[SkinJson[weaponID]["WeaponID"]].nFallbackStatTrak = SkinJson[weaponID]["Stattrak"];
g_SkinChangerCfg[SkinJson[weaponID]["WeaponID"]].flFallbackWear = SkinJson[weaponID]["Float"];
g_SkinChangerCfg[SkinJson[weaponID]["WeaponID"]].szCustomName = name[0];
int knifeID = SkinJson[weaponID]["WeaponID"];
if (team == 'c')
{
auto original_knife_ct = g_ModelInfo->GetModelIndex("models/weapons/v_knife_default_ct.mdl");
switch (knifeID)
{
case 500:
g_ViewModelCfg[original_knife_ct] = "models/weapons/v_knife_bayonet.mdl";
g_KillIconCfg["knife_default_ct"] = "bayonet";
break;
case 505:
g_ViewModelCfg[original_knife_ct] = "models/weapons/v_knife_flip.mdl";
g_KillIconCfg["knife_default_ct"] = "knife_flip";
break;
case 506:
g_ViewModelCfg[original_knife_ct] = "models/weapons/v_knife_gut.mdl";
g_KillIconCfg["knife_default_ct"] = "knife_gut";
break;
case 507:
g_ViewModelCfg[original_knife_ct] = "models/weapons/v_knife_karam.mdl";
g_KillIconCfg["knife_default_ct"] = "knife_karambit";
break;
case 508:
g_ViewModelCfg[original_knife_ct] = "models/weapons/v_knife_m9_bay.mdl";
g_KillIconCfg["knife_default_ct"] = "knife_m9_bayonet";
break;
case 509:
g_ViewModelCfg[original_knife_ct] = "models/weapons/v_knife_tactical.mdl";
g_KillIconCfg["knife_default_ct"] = "knife_tactical";
break;
case 512:
g_ViewModelCfg[original_knife_ct] = "models/weapons/v_knife_falchion_advanced.mdl";
g_KillIconCfg["knife_default_ct"] = "knife_falchion";
break;
case 514:
g_ViewModelCfg[original_knife_ct] = "models/weapons/v_knife_survival_bowie.mdl";
g_KillIconCfg["knife_default_ct"] = "knife_survival_bowie";
break;
case 515:
g_ViewModelCfg[original_knife_ct] = "models/weapons/v_knife_butterfly.mdl";
g_KillIconCfg["knife_default_ct"] = "knife_butterfly";
break;
case 516:
g_ViewModelCfg[original_knife_ct] = "models/weapons/v_knife_push.mdl";
g_KillIconCfg["knife_default_ct"] = "knife_push";
break;
}
}
else if (team == 't')
{
auto original_knife_t = g_ModelInfo->GetModelIndex("models/weapons/v_knife_default_t.mdl");
switch (knifeID)
{
case 500:
g_ViewModelCfg[original_knife_t] = "models/weapons/v_knife_bayonet.mdl";
g_KillIconCfg["knife_default_t"] = "bayonet";
break;
case 505:
g_ViewModelCfg[original_knife_t] = "models/weapons/v_knife_flip.mdl";
g_KillIconCfg["knife_default_t"] = "knife_flip";
break;
case 506:
g_ViewModelCfg[original_knife_t] = "models/weapons/v_knife_gut.mdl";
g_KillIconCfg["knife_default_t"] = "knife_gut";
break;
case 507:
g_ViewModelCfg[original_knife_t] = "models/weapons/v_knife_karam.mdl";
g_KillIconCfg["knife_default_t"] = "knife_karambit";
break;
case 508:
g_ViewModelCfg[original_knife_t] = "models/weapons/v_knife_m9_bay.mdl";
g_KillIconCfg["knife_default_t"] = "knife_m9_bayonet";
break;
case 509:
g_ViewModelCfg[original_knife_t] = "models/weapons/v_knife_tactical.mdl";
g_KillIconCfg["knife_default_t"] = "knife_tactical";
break;
case 512:
g_ViewModelCfg[original_knife_t] = "models/weapons/v_knife_falchion_advanced.mdl";
g_KillIconCfg["knife_default_t"] = "knife_falchion";
break;
case 514:
g_ViewModelCfg[original_knife_t] = "models/weapons/v_knife_survival_bowie.mdl";
g_KillIconCfg["knife_default_t"] = "knife_survival_bowie";
break;
case 515:
g_ViewModelCfg[original_knife_t] = "models/weapons/v_knife_butterfly.mdl";
g_KillIconCfg["knife_default_t"] = "knife_butterfly";
break;
case 516:
g_ViewModelCfg[original_knife_t] = "models/weapons/v_knife_push.mdl";
g_KillIconCfg["knife_default_t"] = "knife_push";
break;
}
}
}
inline void Settings::SetSkins() {
std::string weaponID[33] = {
"DEAGLE", "ELITES", "FIVESEVEN", "GLOCK", "AK47", "AUG", "AWP", "FAMAS", "G3SG1",
"GALIL", "M249", "M4A4", "MAC10", "P90", "UMP45", "XM1014", "BIZON", "MAG7",
"NEGEV", "SAWEDOFF", "TEC9", "P2000", "MP7", "MP9", "NOVA", "P250", "SCAR20",
"SG556", "SSG08", "M4A1-S", "USP-S", "CZ75-A", "Revolver"
};
for (auto i = 0; i <= 33; i++)
{
set_skin(weaponID[i]);
}
}
inline void Settings::SetKnives() {
set_knife(SkinJson["CT Knife"]["WeaponID"], 'c');
set_knife(SkinJson["T Knife"]["WeaponID"], 't');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment