#pragma once #include #include #include #include #include #include #include #include namespace hex { class SharedData; } namespace hex::plugin::internal { void initializePlugin(SharedData &sharedData); } namespace hex { namespace prv { class Provider; } class SharedData { SharedData() = default; public: SharedData(const SharedData&) = delete; SharedData(SharedData&&) = delete; static auto& get() { static SharedData instance; return instance; } friend void hex::plugin::internal::initializePlugin(SharedData &sharedData); friend class Window; template T& getVariable(std::string variableName) { return std::any_cast((*this->sharedVariables)[variableName]); } template void setVariable(std::string variableName, T value) { (*this->sharedVariables)[variableName] = value; } private: void initializeData() { static std::vector eventHandlersStorage; static std::vector> deferredCallsStorage; static prv::Provider *currentProviderStorage; static std::map> settingsEntriesStorage; static std::map sharedVariablesStorage; static ImVec2 windowPosStorage, windowSizeStorage; static nlohmann::json settingsJsonStorage; static std::map customEventsStorage; static u32 customEventsLastIdStorage = u32(Events::Events_BuiltinEnd) + 1; static std::vector commandPaletteCommandsStorage; static std::map patternLanguageFunctionsStorage; this->imguiContext = ImGui::GetCurrentContext(); this->eventHandlers = &eventHandlersStorage; this->deferredCalls = &deferredCallsStorage; this->currentProvider = ¤tProviderStorage; this->settingsEntries = &settingsEntriesStorage; this->sharedVariables = &sharedVariablesStorage; this->windowPos = &windowPosStorage; this->windowSize = &windowSizeStorage; this->settingsJson = &settingsJsonStorage; this->customEvents = &customEventsStorage; this->customEventsLastId = &customEventsLastIdStorage; this->commandPaletteCommands = &commandPaletteCommandsStorage; this->patternLanguageFunctions = &patternLanguageFunctionsStorage; } void initializeData(const SharedData &other) { this->imguiContext = other.imguiContext; this->eventHandlers = other.eventHandlers; this->deferredCalls = other.deferredCalls; this->currentProvider = other.currentProvider; this->settingsEntries = other.settingsEntries; this->sharedVariables = other.sharedVariables; this->windowPos = other.windowPos; this->windowSize = other.windowSize; this->settingsJson = other.settingsJson; this->customEvents = other.customEvents; this->customEventsLastId = other.customEventsLastId; this->commandPaletteCommands = other.commandPaletteCommands; this->patternLanguageFunctions = other.patternLanguageFunctions; } public: ImGuiContext *imguiContext; std::vector *eventHandlers; std::vector> *deferredCalls; prv::Provider **currentProvider; std::map> *settingsEntries; nlohmann::json *settingsJson; std::map *customEvents; u32 *customEventsLastId; std::vector *commandPaletteCommands; std::map *patternLanguageFunctions; ImVec2 *windowPos; ImVec2 *windowSize; private: std::map *sharedVariables; }; }