#pragma once #include #include #include namespace PalUIExtension::Static { using namespace RC; using namespace RC::Unreal; class ClassCache { public: // Registers a slot to be nulled on Flush. The pointer must outlive the process -- every caller is a static, so this holds. static auto RegisterSlot(UObject** Slot) -> void { if (!Slot) return; s_slots.push_back(Slot); } static auto RegisterSlot(UClass** Slot) -> void { if (!Slot) return; s_class_slots.push_back(Slot); } // Called on EVERY world teardown, before anything else runs. static auto Flush() -> void { for (UObject** Slot : s_slots) { if (Slot) *Slot = nullptr; } for (UClass** Slot : s_class_slots){ if (Slot) *Slot = nullptr; } Output::send( STR("[ClassCache] flushed {} object slots and {} class slots\n"), static_cast(s_slots.size()), static_cast(s_class_slots.size())); } static auto SlotCount() -> size_t { return s_slots.size() + s_class_slots.size(); } private: inline static std::vector s_slots{}; inline static std::vector s_class_slots{}; }; }