Example #1
0
        /// <summary>
        /// Destroys the current instance of <see cref="ImguiHook"/>.
        /// Use if you don't plan on using the hook again, such as when unloading a mod.
        /// </summary>
        public static void Destroy()
        {
            Disable();
            Shutdown();

            if (Implementations != null)
            {
                foreach (var implementation in Implementations)
                {
                    implementation?.Dispose();
                }
            }

            Debug.WriteLine($"[ImguiHook Destroy] Destroy Context");

            ImGui.DestroyContext(Context);
            Context?.Dispose();

            Render          = null;
            Implementations = null;
            Context         = null;
            WndProcHook     = null;
            WindowHandle    = IntPtr.Zero;

            _created = false;
        }
Example #2
0
 /// <summary>
 /// [Internal] Shuts down the Dear ImGui implementations.
 /// </summary>
 public static void Shutdown()
 {
     if (Initialized)
     {
         Debug.WriteLine($"[ImguiHook Shutdown] Win32 Shutdown");
         ImGui.ImGuiImplWin32Shutdown();
         Initialized = false;
     }
 }
Example #3
0
        /// <summary>
        /// [Internal] Called from renderer implementation, renders a new frame.
        /// </summary>
        public static unsafe void InitializeWithHandle(IntPtr windowHandle)
        {
            if (!Initialized)
            {
                WindowHandle = windowHandle;
                if (WindowHandle == IntPtr.Zero)
                {
                    return;
                }

                Debug.WriteLine($"[ImguiHook] Init with Window Handle {(long)WindowHandle:X}");
                ImGui.ImGuiImplWin32Init(WindowHandle);
                var wndProcHandlerPtr = (IntPtr)SDK.Hooks.Utilities.GetFunctionPointer(typeof(ImguiHook), nameof(WndProcHandler));
                WndProcHook = WndProcHook.Create(WindowHandle, Unsafe.As <IntPtr, WndProcHook.WndProc>(ref wndProcHandlerPtr));
                Initialized = true;
            }
        }