Гайд Custom Config System CSGOSimple

Пользователь
Пользователь
Статус
Оффлайн
Регистрация
28 Апр 2018
Сообщения
134
Реакции
35
1.создаем файл json.hpp и вставляем туда вот это
Пожалуйста, авторизуйтесь для просмотра ссылки.
реклама)
2.создаем файл config.hpp и вставляем туда
Код:
Expand Collapse Copy
#pragma once
#include "singleton.hpp"
#include "json.hpp"
#include "valve_sdk/sdk.hpp"
#include "options.hpp"
#include <fstream>
#include <experimental/filesystem>
class ConfigFile;
class Config : public Singleton<Config>
{
public:
void Init();
void CreateConfigFolder(std::string path);
bool FileExists(std::string file);
void SaveConfig(const std::string path);
void LoadConfig(const std::string path);
std::vector<std::string> GetAllConfigs();
private:
std::vector<ConfigFile> GetFolderConfigs(const std::string path, const std::string ext);
template<typename T>
void Load(T &value, std::string str);
template<typename T>
void Save(T &value, std::string str);
public:
char documents[MAX_PATH];
};
class ConfigFile
{
public:
ConfigFile(const std::string name, const std::string path)
{
this->name = name;
this->path = path;
}
std::string GetName() { return name; };
std::string GetPath() { return path; };
private:
std::string name, path;
};
3.Создаем config.cpp и вставляем туда
Код:
Expand Collapse Copy
#include "Config.hpp"
nlohmann::json config;
void Config::Init()
{
long res = SHGetFolderPath(NULL, CSIDL_PERSONAL, NULL, SHGFP_TYPE_CURRENT,documents);
if (res == S_OK)
{
std::string config_folder = std::string(documents) + "\\CSGOSimple\\";
CreateConfigFolder(config_folder);
std::string default_file_path = config_folder + "config.ini";
if (FileExists(default_file_path))
LoadConfig(default_file_path);
}
}
void Config::CreateConfigFolder(std::string path)
{
if (!std::experimental::filesystem::create_directory(path)) return;
}
bool Config::FileExists(std::string file)
{
return std::experimental::filesystem::exists(file);
}
void Config::SaveConfig(const std::string path)
{
std::ofstream output_file(path);
if (!output_file.good())
return;
Save(g_Options.esp_players_enabled,"esp_players_enabled");
Save(g_Options.esp_players_enemies_only,"esp_players_enemies_only");
Save(g_Options.esp_players_boxes_types,"esp_players_boxes_types");
Save(g_Options.esp_players_boxes,"esp_players_boxes");
//и т.д
output_file << std::setw(4) << config << std::endl;
output_file.close();
}

void Config::LoadConfig(const std::string path)
{
std::ifstream input_file(path);
if (!input_file.good())
return;
try
{
config << input_file;
}
catch (...)
{
input_file.close();
return;
}
Load(g_Options.esp_players_enabled,"esp_players_enabled");
Load(g_Options.esp_players_enemies_only,"esp_players_enemies_only");
Load(g_Options.esp_players_boxes_types,"esp_players_boxes_types");
Load(g_Options.esp_players_boxes,"esp_players_boxes");
//и т.д
input_file.close();
}
std::vector<std::string> Config::GetAllConfigs()
{
namespace fs = std::experimental::filesystem;
std::string fPath = std::string(documents) + "\\CSGOSimple\\";
std::vector<ConfigFile> config_files = GetFolderConfigs(fPath, ".ini");
std::vector<std::string> config_file_names;
for (auto config = config_files.begin(); config != config_files.end(); config++)
config_file_names.emplace_back(config->GetName());
std::sort(config_file_names.begin(), config_file_names.end());
return config_file_names;
}
std::vector<ConfigFile> Config::GetFolderConfigs(const std::string path, const std::string ext)
{
namespace fs = std::experimental::filesystem;
std::vector<ConfigFile> config_files;
if (fs::exists(path) && fs::is_directory(path))
{
for (auto it = fs::recursive_directory_iterator(path); it != fs::recursive_directory_iterator(); it++)
{
if (fs::is_regular_file(*it) && it->path().extension() == ext)
{
std::string fPath = path + it->path().filename().string();
std::string tmp_f_name = it->path().filename().string();
size_t pos = tmp_f_name.find(".");
std::string fName = (std::string::npos == pos) ? tmp_f_name : tmp_f_name.substr(0, pos);
ConfigFile new_config(fName, fPath);
config_files.emplace_back(new_config);
}
}
}
return config_files;
}
template<typename T>
void Config::Load(T &value, std::string str)
{
if (config[str].empty())
return;
value = config[str].get<T>();
}
template<typename T>
void Config::Save(T &value, std::string str)
{
config[str] = value;
}
4.В main.cpp подключаем библиотеку и вставлем код
Код:
Expand Collapse Copy
#define NOMINMAX
#include <Windows.h>
#include "valve_sdk/sdk.hpp"
#include "helpers/utils.hpp"
#include "helpers/input.hpp"
#include "hooks.hpp"
#include "menu.hpp"
#include "options.hpp"
#include "render.hpp"
#include "config.hpp"
DWORD WINAPI OnDllAttach(LPVOID base)
{
 //
 // Wait at most 10s for the main game modules to be loaded.
//
if(Utils::WaitForModules(10000, { L"client.dll", L"engine.dll", L"shaderapidx9.dll" }) == WAIT_TIMEOUT) {
// One or more modules were not loaded in time
return FALSE;
}
#ifdef _DEBUG
    Utils::AttachConsole();
#endif
try {     Utils::ConsolePrint("Initializing...\n");
Interfaces::Initialize();
Interfaces::Dump();
NetvarSys::Get().Initialize();
InputSys::Get().Initialize();
Render::Get().Initialize();
Menu::Get().Initialize();
Hooks::Initialize();
Config::Get().Init();
// Register some hotkeys.
// - Note:  The function that is called when the hotkey is pressed
//          is called from the WndProc thread, not this thread.
//
// Panic button      InputSys::Get().RegisterHotkey(VK_DELETE, [base]() {
            g_Unload = true;
        });
// Menu Toggle InputSys::Get().RegisterHotkey(VK_INSERT, [base]() {
            Menu::Get().Toggle();
        });
Utils::ConsolePrint("Finished.\n");
 while(!g_Unload)
            Sleep(1000);
g_CVar->FindVar("crosshair")->SetValue(true);     FreeLibraryAndExitThread(static_cast<HMODULE>(base), 1);
} catch(const std::exception& ex) {
 Utils::ConsolePrint("An error occured during initialization:\n");
 Utils::ConsolePrint("%s\n", ex.what());
 Utils::ConsolePrint("Press any key to exit.\n");
Utils::ConsoleReadKey();
 Utils::DetachConsole();     FreeLibraryAndExitThread(static_cast<HMODULE>(base), 1);
    }
    // unreachable
    //return TRUE;
}

BOOL WINAPI OnDllDetach()
{
#ifdef _DEBUG
    Utils::DetachConsole();
#endif
    Hooks::Shutdown();
    Menu::Get().Shutdown();
    return TRUE;
}
BOOL WINAPI DllMain(
    _In_      HINSTANCE hinstDll,
    _In_      DWORD     fdwReason,
    _In_opt_  LPVOID    lpvReserved
)
{
switch(fdwReason) {
case DLL_PROCESS_ATTACH:           DisableThreadLibraryCalls(hinstDll);
CreateThread(nullptr, 0, OnDllAttach, hinstDll, 0, nullptr);
return TRUE;
case DLL_PROCESS_DETACH:
if(lpvReserved == nullptr)
return OnDllDetach();
return TRUE;
default:
return TRUE;
}
}
5.в Menu.cpp вставляем вот это
Код:
Expand Collapse Copy
#include "config.hpp"
void RenderConfigTab()
{
static std::vector<std::string> configItems = Config::Get().GetAllConfigs();
static int configItemCurrent = -1;
static char fName[128] = "default";
bool placeholder_true = true;
auto& style = ImGui::GetStyle();
float group_w = ImGui::GetCurrentWindow()->Size.x - style.WindowPadding.x * 2;
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0, 0));
ImGui::ToggleButton("CONFIG", &placeholder_true, ImVec2{ group_w, 25.0f });
ImGui::PopStyleVar();
ImGui::BeginGroupBox("##body_content");
{
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2{ style.WindowPadding.x, style.ItemSpacing.y });
ImGui::Columns(3, nullptr, false);
ImGui::SetColumnOffset(1, group_w / 3.0f);
ImGui::SetColumnOffset(2, 2 * group_w / 3.0f);
ImGui::SetColumnOffset(3, group_w);
if (ImGui::Button("Refresh Config"))
configItems = Config::Get().GetAllConfigs();
ImGui::SameLine();
if (ImGui::Button("Save Config"))
{
if (configItems.size() > 0 && (configItemCurrent >= 0 && configItemCurrent < (int)configItems.size()))
{
std::string fPath = std::string(Config::Get().documents) + "\\CSGOSimple\\" + configItems[configItemCurrent] + ".ini";
Config::Get().SaveConfig(fPath);
}
}
ImGui::SameLine();
if (ImGui::Button("Remove Config"))
{
if (configItems.size() > 0 && (configItemCurrent >= 0 && configItemCurrent < (int)configItems.size()))
{
std::string fPath = std::string(Config::Get().documents) + "\\CSGOSimple\\" + configItems[configItemCurrent] + ".ini";
std::remove(fPath.c_str());
configItems = Config::Get().GetAllConfigs();
configItemCurrent = -1;
}
}
ImGui::PushItemWidth(256);
{
ImGui::InputText("", fName, 128);
}
ImGui::PopItemWidth();
ImGui::SameLine();
if (ImGui::Button("Add Config"))
{
std::string fPath = std::string(Config::Get().documents) + "\\CSGOSimple\\" + fName + ".ini";                        Config::Get().SaveConfig(fPath);
configItems = Config::Get().GetAllConfigs();
configItemCurrent = -1;
}
ImGui::PushItemWidth(256);
{
if (ImGui::ListBox("", &configItemCurrent, configItems, 3))
{
std::string fPath = std::string(Config::Get().documents) + "\\CSGOSimple\\" + configItems[configItemCurrent] + ".ini";
Config::Get().LoadConfig(fPath);
}
}
ImGui::PopItemWidth();
ImGui::Columns(1, nullptr, false);
ImGui::PopStyleVar();
}
ImGui::EndGroupBox();
}
ну вроде и все это другой способ создания кфг системы для ксгосимпл от меня
 
Обратите внимание, пользователь заблокирован на форуме. Не рекомендуется проводить сделки.
No, just no, pasters
 
Обратите внимание, пользователь заблокирован на форуме. Не рекомендуется проводить сделки.
No, just no, pasters
 
Назад
Сверху Снизу