diff --git a/csharp-api/REFrameworkNET/PluginManager.cpp b/csharp-api/REFrameworkNET/PluginManager.cpp index 20b41a037..c1a40a4fa 100644 --- a/csharp-api/REFrameworkNET/PluginManager.cpp +++ b/csharp-api/REFrameworkNET/PluginManager.cpp @@ -188,7 +188,10 @@ namespace REFrameworkNET { // Must be set up before we load anything as it sets up the LoadLibraryExW hook for cimgui auto imgui_callback_c = System::Runtime::InteropServices::Marshal::GetFunctionPointerForDelegate(s_imgui_callback_delegate).ToPointer(); - REFrameworkNET::API::GetNativeImplementation()->param()->functions->on_imgui_frame((::REFOnImGuiFrameCb)imgui_callback_c); + auto imgui_draw_ui_callback_c = System::Runtime::InteropServices::Marshal::GetFunctionPointerForDelegate(s_imgui_draw_ui_callback_delegate).ToPointer(); + auto api_fns = REFrameworkNET::API::GetNativeImplementation()->param()->functions; + api_fns->on_imgui_frame((::REFOnImGuiFrameCb)imgui_callback_c); + api_fns->on_imgui_draw_ui((::REFOnImGuiFrameCb)imgui_draw_ui_callback_c); s_dependencies = LoadDependencies(); // Pre-loads DLLs in the dependencies folder before loading the plugins @@ -575,18 +578,6 @@ namespace REFrameworkNET { ImGuiNET::ImGui::SetCurrentContext(context); ImGuiNET::ImGui::SetAllocatorFunctions(mallocFn, freeFn, user_data);*/ - // Draw our REFramework.NET menu which has buttons like reload scripts - if (ImGuiNET::ImGui::Begin("REFramework.NET")) { - if (ImGuiNET::ImGui::Button("Unload Scripts")) { - PluginManager::UnloadDynamicAssemblies(); - } - - if (ImGuiNET::ImGui::Button("Reload Scripts")) { - PluginManager::UnloadDynamicAssemblies(); - PluginManager::LoadPlugins_FromSourceCode(0, s_dependencies); - } - } - try { Callbacks::ImGuiRender::TriggerPre(); } catch (System::Exception^ e) { @@ -607,4 +598,23 @@ namespace REFrameworkNET { REFrameworkNET::API::LogError("Unknown exception caught while triggering ImGuiRender::Post"); } } + + void PluginManager::ImGuiDrawUICallback(::REFImGuiFrameCbData* data) { + // Draw our REFramework.NET menu which has buttons like reload scripts + ImGuiNET::ImGui::PushID("REFramework.NET"); + if (ImGuiNET::ImGui::CollapsingHeader("REFramework.NET")) { + if (ImGuiNET::ImGui::Button("Reload Scripts")) { + PluginManager::UnloadDynamicAssemblies(); + PluginManager::LoadPlugins_FromSourceCode(0, s_dependencies); + } + + ImGuiNET::ImGui::SameLine(); + + if (ImGuiNET::ImGui::Button("Unload Scripts")) { + PluginManager::UnloadDynamicAssemblies(); + } + } + + ImGuiNET::ImGui::PopID(); + } } \ No newline at end of file diff --git a/csharp-api/REFrameworkNET/PluginManager.hpp b/csharp-api/REFrameworkNET/PluginManager.hpp index ef7ba97e5..9c007d6c2 100644 --- a/csharp-api/REFrameworkNET/PluginManager.hpp +++ b/csharp-api/REFrameworkNET/PluginManager.hpp @@ -37,10 +37,16 @@ private ref class PluginManager static bool LoadPlugins_FromSourceCode(uintptr_t param_raw, System::Collections::Generic::List^ deps); static void UnloadDynamicAssemblies(); + // This one is outside of a window context static void ImGuiCallback(::REFImGuiFrameCbData* data); delegate void ImGuiCallbackDelegate(::REFImGuiFrameCbData* data); + // This one is in the middle of drawing REFramework's UI + static void ImGuiDrawUICallback(::REFImGuiFrameCbData* data); + delegate void ImGuiDrawUICallbackDelegate(::REFImGuiFrameCbData* data); + static ImGuiCallbackDelegate^ s_imgui_callback_delegate{gcnew ImGuiCallbackDelegate(&ImGuiCallback)}; + static ImGuiDrawUICallbackDelegate^ s_imgui_draw_ui_callback_delegate{gcnew ImGuiDrawUICallbackDelegate(&ImGuiDrawUICallback)}; static System::Collections::Generic::List^ s_loaded_assemblies{gcnew System::Collections::Generic::List()}; static System::Collections::Generic::List^ s_dynamic_assemblies{gcnew System::Collections::Generic::List()}; @@ -63,6 +69,7 @@ private ref class PluginManager static void OnSourceScriptsChanged(System::Object^ sender, System::IO::FileSystemEventArgs^ e); static void BeginRendering(); delegate void BeginRenderingDelegate(); + static BeginRenderingDelegate^ s_begin_rendering_delegate{gcnew BeginRenderingDelegate(&BeginRendering)}; }; } \ No newline at end of file