diff --git a/scripts/TweakDBBatch.reds b/scripts/TweakDBBatch.reds index ae1233e..3b4ce94 100644 --- a/scripts/TweakDBBatch.reds +++ b/scripts/TweakDBBatch.reds @@ -3,6 +3,7 @@ public native class TweakDBBatch { public native func CreateRecord(id: TweakDBID, type: CName) -> Bool public native func CloneRecord(id: TweakDBID, base: TweakDBID) -> Bool public native func UpdateRecord(id: TweakDBID) -> Bool + public native func RegisterEnum(id: TweakDBID) public native func RegisterName(name: CName) -> Bool public native func Commit() diff --git a/scripts/TweakDBManager.reds b/scripts/TweakDBManager.reds index d327e65..5414d55 100644 --- a/scripts/TweakDBManager.reds +++ b/scripts/TweakDBManager.reds @@ -3,6 +3,7 @@ public abstract native class TweakDBManager { public final static native func CreateRecord(id: TweakDBID, type: CName) -> Bool public final static native func CloneRecord(id: TweakDBID, base: TweakDBID) -> Bool public final static native func UpdateRecord(id: TweakDBID) -> Bool + public final static native func RegisterEnum(id: TweakDBID) public final static native func RegisterName(name: CName) -> Bool public final static native func StartBatch() -> ref diff --git a/src/App/Stats/StatService.cpp b/src/App/Stats/StatService.cpp index e9004d6..41dba84 100644 --- a/src/App/Stats/StatService.cpp +++ b/src/App/Stats/StatService.cpp @@ -19,20 +19,25 @@ void App::StatService::OnBootstrap() void App::StatService::OnInitializeStats(void* aSystem) { - auto statRecords = Raw::StatsDataSystem::StatRecords::Ptr(aSystem); + RegisterStats(aSystem, Core::Resolve()->GetChangelog().GetAffectedRecords()); + RegisterStats(aSystem, Core::Resolve()->GetManager().GetEnums()); +} + +void App::StatService::RegisterStats(void* aStatSystem, const Core::Set& aRecordIDs) +{ + auto statRecords = Raw::StatsDataSystem::StatRecords::Ptr(aStatSystem); auto statTypeEnum = Red::GetDescriptor(); auto& tweakManager = Core::Resolve()->GetManager(); - auto& tweakChangelog = Core::Resolve()->GetChangelog(); - for (const auto& recordId : tweakChangelog.GetAffectedRecords()) + for (const auto& recordID : aRecordIDs) { - const auto& recordName = tweakManager.GetName(recordId); + const auto& recordName = tweakManager.GetName(recordID); if (!recordName.starts_with(BaseStatPrefix)) continue; - auto enumNameProp = tweakManager.GetFlat({recordId, ".enumName"}); + auto enumNameProp = tweakManager.GetFlat({recordID, ".enumName"}); if (!enumNameProp) continue; @@ -58,7 +63,7 @@ void App::StatService::OnInitializeStats(void* aSystem) const auto enumValue = statRecords->size; statTypeEnum->AddOption(enumValue, enumName); - statRecords->PushBack(recordId); + statRecords->PushBack(recordID); if (!s_statTypesModified) { @@ -69,7 +74,7 @@ void App::StatService::OnInitializeStats(void* aSystem) } { - const auto record = tweakManager.GetRecord(recordId); + const auto record = tweakManager.GetRecord(recordID); Raw::StatRecord::EnumValue::Ref(record) = enumValue; } } diff --git a/src/App/Stats/StatService.hpp b/src/App/Stats/StatService.hpp index bfd0d9e..d729e9d 100644 --- a/src/App/Stats/StatService.hpp +++ b/src/App/Stats/StatService.hpp @@ -19,5 +19,7 @@ class StatService static uint64_t* OnGetStatRange(void* aSystem, uint64_t* aRange, uint32_t aStat); static uint32_t OnGetStatFlags(void* aSystem, uint32_t aStat); static bool OnCheckStatFlag(void* aSystem, uint32_t aStat, uint32_t aFlag); + + static void RegisterStats(void* aStatSystem, const Core::Set& aRecordIDs); }; } diff --git a/src/App/Tweaks/Executable/Scriptable/ScriptBatch.cpp b/src/App/Tweaks/Executable/Scriptable/ScriptBatch.cpp index 3a74e0c..cc4e285 100644 --- a/src/App/Tweaks/Executable/Scriptable/ScriptBatch.cpp +++ b/src/App/Tweaks/Executable/Scriptable/ScriptBatch.cpp @@ -49,6 +49,17 @@ bool App::ScriptBatch::UpdateRecord(Red::TweakDBID aRecordID) const return false; } +bool App::ScriptBatch::RegisterEnum(Red::TweakDBID aRecordID) const +{ + if (m_batch && aRecordID) + { + m_manager->RegisterEnum(m_batch, aRecordID); + return true; + } + + return false; +} + bool App::ScriptBatch::RegisterName(Red::CName aName) const { if (m_batch && aName) diff --git a/src/App/Tweaks/Executable/Scriptable/ScriptBatch.hpp b/src/App/Tweaks/Executable/Scriptable/ScriptBatch.hpp index 2cdcc32..7f407d5 100644 --- a/src/App/Tweaks/Executable/Scriptable/ScriptBatch.hpp +++ b/src/App/Tweaks/Executable/Scriptable/ScriptBatch.hpp @@ -13,6 +13,7 @@ struct ScriptBatch : Red::IScriptable bool CreateRecord(Red::TweakDBID aRecordID, Red::CName aTypeName) const; bool CloneRecord(Red::TweakDBID aRecordID, Red::TweakDBID aSourceID) const; bool UpdateRecord(Red::TweakDBID aRecordID) const; + bool RegisterEnum(Red::TweakDBID aRecordID) const; bool RegisterName(Red::CName aName) const; void Commit() const; @@ -30,6 +31,7 @@ RTTI_DEFINE_CLASS(App::ScriptBatch, "TweakDBBatch", { RTTI_METHOD(CreateRecord); RTTI_METHOD(CloneRecord); RTTI_METHOD(UpdateRecord); + RTTI_METHOD(RegisterEnum); RTTI_METHOD(RegisterName); RTTI_METHOD(Commit); }); diff --git a/src/App/Tweaks/Executable/Scriptable/ScriptManager.cpp b/src/App/Tweaks/Executable/Scriptable/ScriptManager.cpp index a1d4780..e2ce5f5 100644 --- a/src/App/Tweaks/Executable/Scriptable/ScriptManager.cpp +++ b/src/App/Tweaks/Executable/Scriptable/ScriptManager.cpp @@ -113,6 +113,14 @@ void App::ScriptManager::RegisterName(Red::IScriptable*, Red::CStackFrame* aFram } } +void App::ScriptManager::RegisterEnum(Red::TweakDBID aRecordID) +{ + if (s_manager) + { + s_manager->RegisterEnum(aRecordID); + } +} + Red::Handle App::ScriptManager::StartBatch() { return Red::MakeHandle(s_manager); diff --git a/src/App/Tweaks/Executable/Scriptable/ScriptManager.hpp b/src/App/Tweaks/Executable/Scriptable/ScriptManager.hpp index 233f7ca..9670380 100644 --- a/src/App/Tweaks/Executable/Scriptable/ScriptManager.hpp +++ b/src/App/Tweaks/Executable/Scriptable/ScriptManager.hpp @@ -10,6 +10,7 @@ class ScriptManager : public Red::IScriptable public: static void SetManager(Core::SharedPtr aManager); + static void RegisterEnum(Red::TweakDBID aRecordID); static Red::Handle StartBatch(); private: diff --git a/src/Red/TweakDB/Manager.cpp b/src/Red/TweakDB/Manager.cpp index 3091715..effd4ce 100644 --- a/src/Red/TweakDB/Manager.cpp +++ b/src/Red/TweakDB/Manager.cpp @@ -190,6 +190,11 @@ bool Red::TweakDBManager::UpdateRecord(Red::TweakDBID aRecordId) return m_tweakDb->UpdateRecord(record); } +void Red::TweakDBManager::RegisterEnum(Red::TweakDBID aRecordId) +{ + m_knownEnums.insert(aRecordId); +} + void Red::TweakDBManager::RegisterName(const std::string& aName, const Red::CClass* aType) { RegisterName(aName.data(), aName); @@ -355,6 +360,11 @@ bool Red::TweakDBManager::UpdateRecord(const Red::TweakDBManager::BatchPtr& aBat return true; } +void Red::TweakDBManager::RegisterEnum(const Red::TweakDBManager::BatchPtr& aBatch, Red::TweakDBID aRecordId) +{ + RegisterEnum(aRecordId); +} + void Red::TweakDBManager::RegisterName(const Red::TweakDBManager::BatchPtr& aBatch, Red::TweakDBID aId, const std::string& aName) { @@ -663,3 +673,8 @@ const std::string& Red::TweakDBManager::GetName(Red::TweakDBID aId) return it->second; } + +const Core::Set& Red::TweakDBManager::GetEnums() +{ + return m_knownEnums; +} diff --git a/src/Red/TweakDB/Manager.hpp b/src/Red/TweakDB/Manager.hpp index c805a54..d9ef390 100644 --- a/src/Red/TweakDB/Manager.hpp +++ b/src/Red/TweakDB/Manager.hpp @@ -39,8 +39,10 @@ class TweakDBManager bool CloneRecord(Red::TweakDBID aRecordId, Red::TweakDBID aSourceId); bool InheritProps(Red::TweakDBID aRecordId, Red::TweakDBID aSourceId); bool UpdateRecord(Red::TweakDBID aRecordId); + void RegisterEnum(Red::TweakDBID aRecordId); void RegisterName(const std::string& aName, const Red::CClass* aType = nullptr); void RegisterName(Red::TweakDBID aId, const std::string& aName, const Red::CClass* aType = nullptr); + const Core::Set& GetEnums(); const std::string& GetName(Red::TweakDBID aId); BatchPtr StartBatch(); @@ -55,6 +57,7 @@ class TweakDBManager bool CloneRecord(const BatchPtr& aBatch, Red::TweakDBID aRecordId, Red::TweakDBID aSourceId); bool InheritProps(const BatchPtr& aBatch, Red::TweakDBID aRecordId, Red::TweakDBID aSourceId); bool UpdateRecord(const BatchPtr& aBatch, Red::TweakDBID aRecordId); + void RegisterEnum(const BatchPtr& aBatch, Red::TweakDBID aRecordId); void RegisterName(const BatchPtr& aBatch, Red::TweakDBID aId, const std::string& aName); void CommitBatch(const BatchPtr& aBatch); @@ -87,5 +90,6 @@ class TweakDBManager Core::SharedPtr m_buffer; Core::SharedPtr m_reflection; Core::Map m_knownNames; + Core::Set m_knownEnums; }; }