├── .gitignore ├── CMakeLists.txt ├── main.cpp └── settings.h /.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | Dist 3 | .vscode 4 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required (VERSION 3.8) 2 | project (SampleMod) 3 | 4 | # Change the name 5 | def_mod (SampleMod) 6 | -------------------------------------------------------------------------------- /main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "settings.h" 4 | #include "playerdb.h" 5 | 6 | DEF_LOGGER("SampleMod"); 7 | DEFAULT_SETTINGS(settings); 8 | 9 | // PS: Reserved for compatibility purposes 10 | // If it is not necessary, keep both functions empty 11 | // Initialization can be done in the PreInit function 12 | // Incorrect use of this function may cause a crash 13 | void dllenter() {} 14 | void dllexit() {} 15 | 16 | void PreInit() { 17 | LOGV("pre init"); 18 | // You can use the event system to receive and process events 19 | // The following is an example 20 | Mod::PlayerDatabase::GetInstance().AddListener(SIG("joined"), [](Mod::PlayerEntry const &entry) { 21 | LOGV("joined name: %s, xuid: %d") % entry.name % entry.xuid; 22 | }); 23 | Mod::PlayerDatabase::GetInstance().AddListener( 24 | SIG("left"), [](Mod::PlayerEntry const &entry) { LOGV("left name: %s, xuid: %d") % entry.name % entry.xuid; }); 25 | } 26 | void PostInit() { LOGV("post init"); } 27 | -------------------------------------------------------------------------------- /settings.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | struct Settings { 7 | bool optionA = false; 8 | bool optionB = true; 9 | 10 | struct Nested { 11 | std::string value; 12 | 13 | template static inline bool io(IO f, Nested &nested, YAML::Node &node) { 14 | return f(nested.value, node["value"]); 15 | } 16 | } nested; 17 | 18 | template static inline bool io(IO f, Settings &settings, YAML::Node &node) { 19 | return f(settings.optionA, node["opt-a"]) && f(settings.optionB, node["opt-b"]) && 20 | f(settings.nested, node["nested"]); 21 | } 22 | }; 23 | 24 | inline Settings settings; 25 | --------------------------------------------------------------------------------