Fix Init
Co-Authored-By: Taiga <67109235+Taiga74164@users.noreply.github.com>
This commit is contained in:
parent
8df2e99f8d
commit
30d55679b8
@ -10,9 +10,9 @@
|
||||
#include "shlwapi.h"
|
||||
#pragma comment(lib, "shlwapi.lib")
|
||||
|
||||
namespace cheat::feature
|
||||
namespace cheat::feature
|
||||
{
|
||||
Settings::Settings() : Feature(),
|
||||
Settings::Settings() : Feature(),
|
||||
NF(f_MenuKey, "Show Cheat Menu Key", "General", Hotkey(VK_F1)),
|
||||
NF(f_HotkeysEnabled, "Hotkeys Enabled", "General", true),
|
||||
NF(f_FontSize, "Font size", "General", 16.0f),
|
||||
@ -20,17 +20,17 @@ namespace cheat::feature
|
||||
|
||||
NF(f_StatusMove, "Move Status Window", "General::StatusWindow", true),
|
||||
NF(f_StatusShow, "Show Status Window", "General::StatusWindow", true),
|
||||
|
||||
NF(f_InfoMove, "Move Info Window", "General::InfoWindow", true),
|
||||
NF(f_InfoShow, "Show Info Window", "General::InfoWindow", true),
|
||||
|
||||
|
||||
NF(f_InfoMove, "Move Info Window", "General::InfoWindow", true),
|
||||
NF(f_InfoShow, "Show Info Window", "General::InfoWindow", true),
|
||||
|
||||
NF(f_FpsMove, "Move FPS Indicator", "General::FPS", false),
|
||||
NF(f_FpsShow, "Show FPS Indicator", "General::FPS", true),
|
||||
|
||||
NF(f_NotificationsShow, "Show Notifications", "General::Notify", true),
|
||||
NF(f_NotificationsShow, "Show Notifications", "General::Notify", true),
|
||||
NF(f_NotificationsDelay, "Notifications Delay", "General::Notify", 500),
|
||||
|
||||
NF(f_FileLogging, "File Logging", "General::Logging", false),
|
||||
|
||||
NF(f_FileLogging, "File Logging", "General::Logging", false),
|
||||
NF(f_ConsoleLogging, "Console Logging", "General::Logging", true),
|
||||
|
||||
NF(f_FastExitEnable, "Fast Exit", "General::FastExit", false),
|
||||
@ -38,35 +38,47 @@ namespace cheat::feature
|
||||
NFS(f_DefaultTheme, "Theme", "General::Colors", "Default"),
|
||||
themesDir(util::GetCurrentPath() / "themes")
|
||||
|
||||
{
|
||||
{
|
||||
renderer::SetGlobalFontSize(static_cast<float>(f_FontSize));
|
||||
f_HotkeyExit.value().PressedEvent += MY_METHOD_HANDLER(Settings::OnExitKeyPressed);
|
||||
if (!std::filesystem::exists(themesDir))
|
||||
std::filesystem::create_directory(themesDir);
|
||||
}
|
||||
bool themeLoaded = false;
|
||||
|
||||
const FeatureGUIInfo& Settings::GetGUIInfo() const
|
||||
{
|
||||
static const FeatureGUIInfo info{ "", "Settings", false };
|
||||
return info;
|
||||
}
|
||||
}
|
||||
|
||||
bool inited = false;
|
||||
void Settings::Init() {
|
||||
if (this->f_DefaultTheme.value() != "Default" && !inited)
|
||||
{
|
||||
LOG_INFO("Loading theme: %s", themesDir / (f_DefaultTheme.value() + ".json").c_str());
|
||||
if (!std::filesystem::exists(themesDir / (f_DefaultTheme.value() + ".json")))
|
||||
f_DefaultTheme = "Default";
|
||||
else Colors_Import(f_DefaultTheme.value());
|
||||
inited = true;
|
||||
}
|
||||
}
|
||||
|
||||
const FeatureGUIInfo& Settings::GetGUIInfo() const
|
||||
{
|
||||
static const FeatureGUIInfo info{ "", "Settings", false };
|
||||
return info;
|
||||
}
|
||||
|
||||
void Settings::Colors_Export(std::string name)
|
||||
{
|
||||
ImGuiStyle &style = ImGui::GetStyle();
|
||||
ImGuiStyle& style = ImGui::GetStyle();
|
||||
auto colors = style.Colors;
|
||||
|
||||
nlohmann::json json;
|
||||
for (int i = 0; i < ImGuiCol_COUNT; i++)
|
||||
json[ImGui::GetStyleColorName((ImGuiCol)i)] = {colors[i].x, colors[i].y, colors[i].z, colors[i].w};
|
||||
json[ImGui::GetStyleColorName((ImGuiCol)i)] = { colors[i].x, colors[i].y, colors[i].z, colors[i].w };
|
||||
std::ofstream file(themesDir / (name + ".json"));
|
||||
file << std::setw(4) << json << std::endl;
|
||||
}
|
||||
|
||||
|
||||
void Settings::Colors_Import(std::string name)
|
||||
{
|
||||
ImGuiStyle &style = ImGui::GetStyle();
|
||||
ImGuiStyle& style = ImGui::GetStyle();
|
||||
auto colors = style.Colors;
|
||||
nlohmann::json json;
|
||||
std::ifstream file(themesDir / (name + ".json"));
|
||||
@ -142,7 +154,7 @@ namespace cheat::feature
|
||||
ImGui::BeginGroupPanel("Show Notifications");
|
||||
{
|
||||
ConfigWidget(f_NotificationsShow, "Notifications on the bottom-right corner of the window will be displayed.");
|
||||
ConfigWidget(f_NotificationsDelay, 1,1,10000, "Delay in milliseconds between notifications.");
|
||||
ConfigWidget(f_NotificationsDelay, 1, 1, 10000, "Delay in milliseconds between notifications.");
|
||||
}
|
||||
ImGui::EndGroupPanel();
|
||||
|
||||
@ -150,7 +162,7 @@ namespace cheat::feature
|
||||
{
|
||||
ConfigWidget("Enabled",
|
||||
f_FastExitEnable,
|
||||
"Enable Fast Exit.\n"
|
||||
"Enable Fast Exit.\n"
|
||||
);
|
||||
if (!f_FastExitEnable)
|
||||
ImGui::BeginDisabled();
|
||||
@ -166,24 +178,6 @@ namespace cheat::feature
|
||||
ImGui::BeginGroupPanel("Colors");
|
||||
{
|
||||
static std::string nameBuffer_;
|
||||
|
||||
if (this->f_DefaultTheme.value() != "Default" && !themeLoaded)
|
||||
{
|
||||
LOG_INFO("Loading theme: %s", themesDir / (f_DefaultTheme.value() + ".json").c_str());
|
||||
if (!std::filesystem::exists(themesDir / (f_DefaultTheme.value() + ".json")))
|
||||
{
|
||||
LOG_ERROR("Theme file not found: %s", themesDir / (f_DefaultTheme.value() + ".json").c_str());
|
||||
f_DefaultTheme = "Default";
|
||||
themeLoaded = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
Colors_Import(f_DefaultTheme.value());
|
||||
themeLoaded = true;
|
||||
LOG_INFO("Loaded theme \"%s\"", f_DefaultTheme.value().c_str());
|
||||
}
|
||||
}
|
||||
|
||||
ImGui::InputText("Name", &nameBuffer_);
|
||||
if (std::filesystem::exists(themesDir / (nameBuffer_ + ".json")))
|
||||
{
|
||||
@ -193,7 +187,6 @@ namespace cheat::feature
|
||||
if (ImGui::Button("Load"))
|
||||
{
|
||||
Colors_Import(nameBuffer_);
|
||||
themeLoaded = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -206,11 +199,11 @@ namespace cheat::feature
|
||||
ImGui::EndGroupPanel();
|
||||
}
|
||||
|
||||
Settings& Settings::GetInstance()
|
||||
{
|
||||
static Settings instance;
|
||||
return instance;
|
||||
}
|
||||
Settings& Settings::GetInstance()
|
||||
{
|
||||
static Settings instance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
void Settings::OnExitKeyPressed()
|
||||
{
|
||||
|
@ -2,11 +2,11 @@
|
||||
#include <cheat-base/cheat/Feature.h>
|
||||
#include <cheat-base/config/config.h>
|
||||
|
||||
namespace cheat::feature
|
||||
namespace cheat::feature
|
||||
{
|
||||
|
||||
class Settings : public Feature
|
||||
{
|
||||
{
|
||||
public:
|
||||
config::Field<Hotkey> f_MenuKey;
|
||||
config::Field<bool> f_HotkeysEnabled;
|
||||
@ -18,10 +18,10 @@ namespace cheat::feature
|
||||
|
||||
config::Field<bool> f_InfoMove;
|
||||
config::Field<bool> f_InfoShow;
|
||||
|
||||
|
||||
config::Field<bool> f_FpsShow;
|
||||
config::Field<bool> f_FpsMove;
|
||||
|
||||
|
||||
config::Field<bool> f_NotificationsShow;
|
||||
config::Field<int> f_NotificationsDelay;
|
||||
|
||||
@ -38,9 +38,10 @@ namespace cheat::feature
|
||||
|
||||
const FeatureGUIInfo& GetGUIInfo() const override;
|
||||
void DrawMain() override;
|
||||
void Init();
|
||||
void Colors_Export(std::string name);
|
||||
void Colors_Import(std::string name);
|
||||
|
||||
|
||||
private:
|
||||
|
||||
void OnExitKeyPressed();
|
||||
|
@ -12,6 +12,7 @@
|
||||
#include <cheat-base/render/backend/dx12-hook.h>
|
||||
|
||||
#include <cheat-base/ResourceLoader.h>
|
||||
#include <cheat-base/cheat/misc/Settings.h>
|
||||
|
||||
extern IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
|
||||
|
||||
@ -33,14 +34,14 @@ namespace renderer
|
||||
static constexpr int _fontsCount = _fontSizeMax / _fontSizeStep;
|
||||
static std::array<ImFont*, _fontsCount> _fonts;
|
||||
|
||||
static Data _customFontData {};
|
||||
static Data _customFontData{};
|
||||
|
||||
static WNDPROC OriginalWndProcHandler;
|
||||
static ID3D11RenderTargetView* mainRenderTargetView;
|
||||
|
||||
static void OnRenderDX11(ID3D11DeviceContext* pContext);
|
||||
static void OnInitializeDX11(HWND window, ID3D11Device* pDevice, ID3D11DeviceContext* pContext, IDXGISwapChain* pChain);
|
||||
|
||||
|
||||
static void OnPreRenderDX12();
|
||||
static void OnPostRenderDX12(ID3D12GraphicsCommandList* commandList);
|
||||
static void OnInitializeDX12(HWND window, ID3D12Device* pDevice, UINT buffersCounts, ID3D12DescriptorHeap* pDescriptorHeapImGuiRender);
|
||||
@ -106,7 +107,7 @@ namespace renderer
|
||||
return io.FontDefault;
|
||||
}
|
||||
int fontSizeInt = static_cast<int>(fontSize);
|
||||
int fontIndex = fontSizeInt / _fontSizeStep +
|
||||
int fontIndex = fontSizeInt / _fontSizeStep +
|
||||
(fontSizeInt % _fontSizeStep > (_fontSizeStep / 2) ? 1 : 0) - 1;
|
||||
fontIndex = std::clamp(fontIndex, 0, _fontsCount - 1);
|
||||
return _fonts[fontIndex];
|
||||
@ -122,7 +123,7 @@ namespace renderer
|
||||
|
||||
int fontSizeInt = static_cast<int>(fontSize);
|
||||
int fontIndex = fontSizeInt / _fontSizeStep;
|
||||
int fontAligned = fontIndex * _fontSizeStep +
|
||||
int fontAligned = fontIndex * _fontSizeStep +
|
||||
((fontSizeInt % _fontSizeStep) > _fontSizeStep / 2 ? _fontSizeStep : 0);
|
||||
fontAligned = std::clamp(fontAligned, _fontSizeStep, _fontSizeMax);
|
||||
|
||||
@ -138,7 +139,7 @@ namespace renderer
|
||||
{
|
||||
return _globalFontSize;
|
||||
}
|
||||
|
||||
|
||||
static void LoadCustomFont()
|
||||
{
|
||||
if (_customFontData.data == nullptr)
|
||||
@ -195,7 +196,7 @@ namespace renderer
|
||||
reinterpret_cast<LONG_PTR>(hWndProc)));
|
||||
|
||||
ImGui_ImplWin32_Init(window);
|
||||
ImGui_ImplDX12_Init(pDevice, buffersCounts, DXGI_FORMAT_R8G8B8A8_UNORM,
|
||||
ImGui_ImplDX12_Init(pDevice, buffersCounts, DXGI_FORMAT_R8G8B8A8_UNORM,
|
||||
pDescriptorHeapImGuiRender,
|
||||
pDescriptorHeapImGuiRender->GetCPUDescriptorHandleForHeapStart(),
|
||||
pDescriptorHeapImGuiRender->GetGPUDescriptorHandleForHeapStart());
|
||||
@ -253,6 +254,9 @@ namespace renderer
|
||||
|
||||
pContext->OMSetRenderTargets(1, &mainRenderTargetView, nullptr);
|
||||
ImGui_ImplDX11_RenderDrawData(ImGui::GetDrawData());
|
||||
|
||||
auto& themes = cheat::feature::Settings::GetInstance();
|
||||
themes.Init();
|
||||
}
|
||||
|
||||
static LRESULT CALLBACK hWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
||||
|
Loading…
Reference in New Issue
Block a user