-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsample_plugin.cpp
More file actions
86 lines (71 loc) · 3.04 KB
/
Copy pathsample_plugin.cpp
File metadata and controls
86 lines (71 loc) · 3.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include "plugin_helper.h"
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
// Typed config structure
struct Config {
bool EnableFeatureA = true;
float Sensitivity = 0.5f;
char UserAlias[64] = "ProGamer";
int WindowMode = 0; // 0=Windowed, 1=Fullscreen, 2=Borderless
void Load(const char* path) {
std::ifstream file(path);
if (!file.is_open()) return;
std::string line;
while (std::getline(file, line)) {
size_t sep = line.find('=');
if (sep != std::string::npos) {
std::string key = line.substr(0, sep);
std::string val = line.substr(sep + 1);
if (key == "EnableFeatureA") EnableFeatureA = (val == "true");
else if (key == "Sensitivity") Sensitivity = std::stof(val);
else if (key == "WindowMode") WindowMode = std::stoi(val);
else if (key == "UserAlias") {
strncpy(UserAlias, val.c_str(), sizeof(UserAlias)-1);
UserAlias[sizeof(UserAlias)-1] = '\0';
}
}
}
}
void Save(const char* path) {
std::ofstream file(path);
file << "EnableFeatureA=" << (EnableFeatureA ? "true" : "false") << "\n";
file << "Sensitivity=" << Sensitivity << "\n";
file << "UserAlias=" << UserAlias << "\n";
file << "WindowMode=" << WindowMode << "\n";
}
};
class SamplePlugin : public GamePlug::Plugin {
public:
const char* GetName() const override {
return "Sample Config Editor (C++ Base)";
}
void OnInit(ImGuiContext* context, void (*LogFunc)(GamePlugPluginInterface::PluginLogLevel, const char*, void*), void* logContext) override {
// Call base to set up ImGui and Logger
GamePlug::Plugin::OnInit(context, LogFunc, logContext);
m_config.Load("sample.conf");
GamePlug::Logger::info("Sample Plugin: Initialized using C++ Helper Class");
}
void OnImGuiRender() override {
ImGui::TextDisabled("(Configuration is saved automatically)");
}
void OnFieldsChanged() override {
m_config.Save("sample.conf");
}
int GetFields(GamePlugPluginInterface::FieldDescriptor** outFields) override {
static GamePlugPluginInterface::FieldDescriptor fields[] = {
{ "Enable Feature A", "General", GamePlugPluginInterface::TYPE_BOOL, &m_config.EnableFeatureA, 0, nullptr },
{ "Sensitivity", "General", GamePlugPluginInterface::TYPE_FLOAT, &m_config.Sensitivity, 0, nullptr },
{ "Window Mode", "General", GamePlugPluginInterface::TYPE_ENUM, &m_config.WindowMode, 0, "Windowed,Fullscreen,Borderless" },
{ "User Alias", "User Profile", GamePlugPluginInterface::TYPE_STRING, m_config.UserAlias, sizeof(m_config.UserAlias), nullptr }
};
if (outFields) {
*outFields = fields;
}
return sizeof(fields) / sizeof(fields[0]);
}
private:
Config m_config;
};
REGISTER_GAMEPLUG_PLUGIN(SamplePlugin)