mirror of
https://github.com/WerWolv/ImHex.git
synced 2026-03-30 05:05:19 -05:00
impr: Get rid of cimgui shared library by hooking pinvoke handler
This commit is contained in:
@@ -6,10 +6,10 @@ using System.Text;
|
||||
|
||||
namespace ImHex
|
||||
{
|
||||
public class Bookmarks
|
||||
public partial class Bookmarks
|
||||
{
|
||||
[DllImport(Library.Name)]
|
||||
private static extern void createBookmarkV1(UInt64 address, UInt64 size, UInt32 color, byte[] name, byte[] description);
|
||||
[LibraryImport("ImHex")]
|
||||
private static partial void createBookmarkV1(UInt64 address, UInt64 size, UInt32 color, byte[] name, byte[] description);
|
||||
|
||||
public static void CreateBookmark(long address, long size, Color color, string name = "", string description = "")
|
||||
{
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
namespace ImHex
|
||||
{
|
||||
public static class Library
|
||||
{
|
||||
public const string Name = "script_loader.hexplug";
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
#pragma warning disable SYSLIB1054
|
||||
|
||||
using System.Drawing;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
@@ -34,7 +33,7 @@ namespace ImHex
|
||||
string getTypeName();
|
||||
string getName();
|
||||
}
|
||||
public class Memory
|
||||
public partial class Memory
|
||||
{
|
||||
private static List<IProvider> _registeredProviders = new();
|
||||
private static List<Delegate> _registeredDelegates = new();
|
||||
@@ -42,17 +41,17 @@ namespace ImHex
|
||||
private delegate void DataAccessDelegate(UInt64 address, IntPtr buffer, UInt64 size);
|
||||
private delegate UInt64 GetSizeDelegate();
|
||||
|
||||
[DllImport(Library.Name)]
|
||||
private static extern void readMemoryV1(UInt64 address, UInt64 size, IntPtr buffer);
|
||||
[LibraryImport("ImHex")]
|
||||
private static partial void readMemoryV1(UInt64 address, UInt64 size, IntPtr buffer);
|
||||
|
||||
[DllImport(Library.Name)]
|
||||
private static extern void writeMemoryV1(UInt64 address, UInt64 size, IntPtr buffer);
|
||||
[LibraryImport("ImHex")]
|
||||
private static partial void writeMemoryV1(UInt64 address, UInt64 size, IntPtr buffer);
|
||||
|
||||
[DllImport(Library.Name)]
|
||||
private static extern bool getSelectionV1(IntPtr start, IntPtr end);
|
||||
[LibraryImport("ImHex")]
|
||||
private static partial int getSelectionV1(IntPtr start, IntPtr end);
|
||||
|
||||
[DllImport(Library.Name)]
|
||||
private static extern void registerProviderV1(byte[] typeName, byte[] name, IntPtr readFunction, IntPtr writeFunction, IntPtr getSizeFunction);
|
||||
[LibraryImport("ImHex")]
|
||||
private static partial void registerProviderV1(byte[] typeName, byte[] name, IntPtr readFunction, IntPtr writeFunction, IntPtr getSizeFunction);
|
||||
|
||||
|
||||
public static byte[] Read(ulong address, ulong size)
|
||||
@@ -87,7 +86,7 @@ namespace ImHex
|
||||
unsafe
|
||||
{
|
||||
UInt64 start = 0, end = 0;
|
||||
if (!getSelectionV1((nint)(&start), (nint)(&end)))
|
||||
if (getSelectionV1((nint)(&start), (nint)(&end)) == 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -1,33 +1,31 @@
|
||||
#pragma warning disable SYSLIB1054
|
||||
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
namespace ImHex
|
||||
{
|
||||
public class UI
|
||||
public partial class UI
|
||||
{
|
||||
private delegate void DrawContentDelegate();
|
||||
|
||||
private static List<Delegate> _registeredDelegates = new();
|
||||
|
||||
[DllImport(Library.Name)]
|
||||
private static extern void showMessageBoxV1(byte[] message);
|
||||
[LibraryImport("ImHex")]
|
||||
private static partial void showMessageBoxV1(byte[] message);
|
||||
|
||||
[DllImport(Library.Name)]
|
||||
private static extern void showInputTextBoxV1(byte[] title, byte[] message, StringBuilder buffer, int bufferSize);
|
||||
[LibraryImport("ImHex")]
|
||||
private static unsafe partial void showInputTextBoxV1(byte[] title, byte[] message, IntPtr buffer, int bufferSize);
|
||||
|
||||
[DllImport(Library.Name)]
|
||||
private static extern unsafe void showYesNoQuestionBoxV1(byte[] title, byte[] message, bool* result);
|
||||
[LibraryImport("ImHex")]
|
||||
private static unsafe partial void showYesNoQuestionBoxV1(byte[] title, byte[] message, bool* result);
|
||||
|
||||
[DllImport(Library.Name)]
|
||||
private static extern void showToastV1(byte[] message, UInt32 type);
|
||||
[LibraryImport("ImHex")]
|
||||
private static partial void showToastV1(byte[] message, UInt32 type);
|
||||
|
||||
[DllImport(Library.Name)]
|
||||
private static extern IntPtr getImGuiContextV1();
|
||||
[LibraryImport("ImHex")]
|
||||
private static partial IntPtr getImGuiContextV1();
|
||||
|
||||
[DllImport(Library.Name)]
|
||||
private static extern void registerViewV1(byte[] icon, byte[] name, IntPtr drawFunction);
|
||||
[LibraryImport("ImHex")]
|
||||
private static partial void registerViewV1(byte[] icon, byte[] name, IntPtr drawFunction);
|
||||
|
||||
public static void ShowMessageBox(string message)
|
||||
{
|
||||
@@ -46,13 +44,22 @@ namespace ImHex
|
||||
|
||||
public static string? ShowInputTextBox(string title, string message, int maxSize)
|
||||
{
|
||||
StringBuilder buffer = new(maxSize);
|
||||
showInputTextBoxV1(Encoding.UTF8.GetBytes(title), Encoding.UTF8.GetBytes(message), buffer, buffer.Capacity);
|
||||
unsafe
|
||||
{
|
||||
var buffer = new byte[maxSize];
|
||||
GCHandle pinnedArray = GCHandle.Alloc(buffer, GCHandleType.Pinned);
|
||||
showInputTextBoxV1(Encoding.UTF8.GetBytes(title), Encoding.UTF8.GetBytes(message), pinnedArray.AddrOfPinnedObject(), maxSize);
|
||||
pinnedArray.Free();
|
||||
|
||||
if (buffer.Length == 0 || buffer[0] == '\x00')
|
||||
return null;
|
||||
else
|
||||
return buffer.ToString();
|
||||
if (buffer.Length == 0 || buffer[0] == '\x00')
|
||||
{
|
||||
return null;
|
||||
}
|
||||
else
|
||||
{
|
||||
return Encoding.UTF8.GetString(buffer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public enum ToastType
|
||||
|
||||
@@ -1,8 +1,18 @@
|
||||
using ImHex;
|
||||
using ImGuiNET;
|
||||
class Script {
|
||||
|
||||
public static void OnLoad() {
|
||||
// This function is executed the first time the Plugin is loaded
|
||||
UI.RegisterView(new byte[]{ 0xEE, 0xAC, 0x89 }, "Test View", () =>
|
||||
{
|
||||
ImGui.SetCurrentContext(UI.GetImGuiContext());
|
||||
ImGui.TextUnformatted("Test Text");
|
||||
if (ImGui.Button("Hello World"))
|
||||
{
|
||||
UI.ShowToast("Hello World");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static void Main()
|
||||
|
||||
Reference in New Issue
Block a user