From b97610facb8ad26874ca3aab667c452070f3d2d6 Mon Sep 17 00:00:00 2001 From: RektInator Date: Tue, 1 Oct 2019 15:06:40 +0200 Subject: [PATCH 1/2] [Stats] Add support for mod-specific stat files --- src/Components/Modules/Stats.cpp | 14 ++++++++++++++ src/Components/Modules/Stats.hpp | 1 + 2 files changed, 15 insertions(+) diff --git a/src/Components/Modules/Stats.cpp b/src/Components/Modules/Stats.cpp index 36f28419..9f9260ff 100644 --- a/src/Components/Modules/Stats.cpp +++ b/src/Components/Modules/Stats.cpp @@ -63,6 +63,17 @@ namespace Components Stats::SendStats(); } + int Stats::SaveStats(char* dest, const char* folder, const char* buffer, size_t length) + { + const auto fs_game = Game::Dvar_FindVar("fs_game"); + if (fs_game && fs_game->current.string && strlen(fs_game->current.string) && !strncmp(fs_game->current.string, "mods/", 5)) + { + folder = fs_game->current.string; + } + + return Utils::Hook::Call(0x426450)(dest, folder, buffer, length); + } + Stats::Stats() { // This UIScript should be added in the onClose code of the cac_popup menu, @@ -91,6 +102,9 @@ namespace Components // Don't create stat backup Utils::Hook::Nop(0x402CE6, 2); + + // Write stats to mod folder if a mod is loaded + Utils::Hook(0x682F7B, Stats::SaveStats, HOOK_CALL).install()->quick(); } Stats::~Stats() diff --git a/src/Components/Modules/Stats.hpp b/src/Components/Modules/Stats.hpp index 81f4d6a7..6fa5be2c 100644 --- a/src/Components/Modules/Stats.hpp +++ b/src/Components/Modules/Stats.hpp @@ -13,6 +13,7 @@ namespace Components private: static void UpdateClasses(UIScript::Token token); static void SendStats(); + static int SaveStats(char* dest, const char* folder, const char* buffer, size_t length); static int64_t* GetStatsID(); }; From f9064ab1c4f5e6aeb8974e70c715736cbf581291 Mon Sep 17 00:00:00 2001 From: /dev/urandom Date: Wed, 2 Oct 2019 11:15:44 +0200 Subject: [PATCH 2/2] [Changelog] Mention pull request in change log. --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index bd2732bc..ac7e3f2d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,10 @@ The format is based on [Keep a Changelog v0.3.0](http://keepachangelog.com/en/0. - Add host information to /info endpoint (request) +### Changed + +- Stats are now separate for each mod (#6). Player stats are copied to `fs_game` folder if no stats exist for this mod yet. Keep in mind this also means that level, XP and classes will not be synchronized with the main stats file after this point. + ## [0.6.0] - 2018-12-30 ### Added