From bb4399b69e4e9fb27bcbec0430fca7bf35e90cb7 Mon Sep 17 00:00:00 2001 From: tombohar Date: Sat, 11 Apr 2026 01:06:27 -0400 Subject: [PATCH] Remove HelloBox plugin, disable desktop log file, update ImGui theme MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Delete HelloBox plugin and its panel (RynthCore.sln updated accordingly) - Remove File.AppendAllText from EntryPoint.Log() — no longer writes to Desktop\RynthCore.log; in-memory buffer (RecentLogLines) retained - Tune RynthCoreShell ImGui color theme (darker blues, frame borders, unified slider/tab palette) - Add AGENTS.md, find_bytes.cs, loot-port-plan.txt Co-Authored-By: Claude Sonnet 4.6 --- AGENTS.md | 133 +++ .../HelloBoxPlugin.cs | 797 ------------------ .../PluginExports.cs | 82 -- .../RynthCore.Plugin.HelloBox.csproj | 57 -- RynthCore.sln | 14 - find_bytes.cs | 20 + loot-port-plan.txt | 204 +++++ src/RynthCore.Engine/EntryPoint.cs | 6 - src/RynthCore.Engine/ImGui/RynthCoreShell.cs | 161 +--- .../UI/Panels/HelloBoxPanel.cs | 102 --- 10 files changed, 392 insertions(+), 1184 deletions(-) create mode 100644 AGENTS.md delete mode 100644 Plugins/RynthCore.Plugin.HelloBox/HelloBoxPlugin.cs delete mode 100644 Plugins/RynthCore.Plugin.HelloBox/PluginExports.cs delete mode 100644 Plugins/RynthCore.Plugin.HelloBox/RynthCore.Plugin.HelloBox.csproj create mode 100644 find_bytes.cs create mode 100644 loot-port-plan.txt delete mode 100644 src/RynthCore.Engine/UI/Panels/HelloBoxPanel.cs diff --git a/AGENTS.md b/AGENTS.md new file mode 100644 index 0000000..37f53e3 --- /dev/null +++ b/AGENTS.md @@ -0,0 +1,133 @@ +# RynthCore — Codex Context + +A modern .NET 9 NativeAOT framework for Asheron's Call client modding. Replaces Decal + UBService with a self-contained injection system. Hooks D3D9 EndScene to render an ImGui overlay inside the AC client process. + +--- + +## ⚠ Active Focus: RynthAi ImGui Plugin + +**Do NOT work on `src/RynthCore.Engine/UI/Panels/RynthAiPanel.cs` (the Avalonia version of RynthAi).** +The Avalonia RynthAi panel is disabled (`EntryPoint.cs` registration is commented out) and parked until the ImGui plugin is feature-complete. All RynthAi work goes in `Plugins/RynthCore.Plugin.RynthAi/` which uses ImGui via `RynthCore.PluginCore`. + +--- + +## Project Layout + +``` +C:\Projects\RynthCore\ +└── src\ + ├── RynthCore.Injector\ Console app — injects Engine into acclient.exe + │ └── Program.cs LoadLibrary + CreateRemoteThread injection + └── RynthCore.Engine\ NativeAOT x86 DLL — lives inside acclient.exe + ├── EntryPoint.cs Exported RynthCoreInit, preloads native DLLs, spawns init thread + ├── D3D9\ + │ ├── D3D9VTable.cs Temp device to harvest vtable pointers + │ ├── EndSceneHook.cs MinHook detour on EndScene + │ └── TestRenderer.cs v0.1 proof-of-life, kept for reference + └── ImGui\ + ├── ImGuiController.cs Context creation, frame loop orchestration + ├── DX9Backend.cs Renders ImGui draw data via raw D3D9 vtable calls + └── Win32Backend.cs WndProc subclass for mouse/keyboard input +``` + +Deploy folder: `C:\Games\RynthCore\` + +--- + +## Build + +```bash +# Engine (NativeAOT — slow first build, ~2 min) +cd src\RynthCore.Engine +dotnet publish -c Release + +# Injector +cd src\RynthCore.Injector +dotnet publish -c Release +``` + +Both projects target **x86** only. The Engine is NativeAOT (`PublishAot=true`) — it has no .NET runtime dependency and injects as a plain native DLL. + +Deploy output: +``` +C:\Games\RynthCore\ +├── RynthCore.Engine.dll ← Engine publish output +├── RynthCore.Injector.exe ← Injector publish output +├── minhook.x86.dll ← MinHook (x86), preloaded by EntryPoint +└── cimgui.dll ← ImGui C bindings (x86, docking branch) +``` + +Log file: `%USERPROFILE%\Desktop\RynthCore.log` + +--- + +## Key Technical Facts + +### NativeAOT / x86 +- .NET 9, `net9.0-windows`, `PlatformTarget=x86`, `RuntimeIdentifier=win-x86` +- `AllowUnsafeBlocks=true`, `PublishAot=true`, `TrimMode=link` +- `ImGui.NET` assembly is trim-rooted to preserve P/Invoke bindings +- `SetWindowLongA` not `SetWindowLongPtrA` — the Ptr variant doesn't exist on x86 + +### Injection flow +1. `RynthCore.Injector.exe` calls `CreateRemoteThread(LoadLibrary, "RynthCore.Engine.dll")` +2. `RynthCoreInit` export fires under loader lock — immediately spawns background thread +3. Init thread sleeps 2s (lets AC finish D3D9 init), preloads minhook + cimgui, then installs EndScene hook + +### D3D9 hook +- Vtable discovery: creates a throwaway device via `D3D9VTable.cs`, captures 119 vtable entries +- Hook installed via MinHook on `EndScene` (vtable index 42) +- All D3D9 calls go through cached delegates (stdcall, `this` as first param) — never via COM wrappers +- State save/restore is manual (get/set each render state) — D3D9 state blocks don't work reliably inside EndScene + +### ImGui / cimgui version situation +- ImGui.NET NuGet: **1.91.6.1** +- cimgui.dll must match: use `%USERPROFILE%\.nuget\packages\imgui.net\1.91.6.1\runtimes\win-x86\native\cimgui.dll` +- Post-1.90 struct layout: `ImDrawData.CmdLists` is an **ImVector (12 bytes)**, not a raw pointer (4 bytes) +- `DX9Backend.cs` reads `ImDrawData` fields from native memory at confirmed offsets as a safety fallback: + - `+4` = CmdListsCount + - `+16` = CmdLists array pointer + - `+20/24` = DisplayPos (X, Y) + - `+28/32` = DisplaySize (X, Y) + +### ImGui input API +- Uses the **modern** API: `AddKeyEvent` / `AddMouseButtonEvent` / `AddMousePosEvent` +- `KeyMap` / `KeysDown` / `MouseDown` arrays were removed in ImGui 1.87 — do not use them +- WndProc subclass via `SetWindowLongA` (not Ptr) in `Win32Backend.cs` + +### DX9Backend render notes +- `DrawIndexedPrimitiveUP` takes user-memory pointers directly — **do not** call `SetStreamSource(null)` before it, this crashes the driver +- Vertex format: `D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX1` — xyz (3 floats) + BGRA color (uint) + uv (2 floats) +- ImGui gives RGBA pixel data; D3D9 `A8R8G8B8` is BGRA in memory — swizzle R↔B on upload +- Color conversion per vertex: `(c & 0xFF00FF00) | ((c & 0x00FF0000) >> 16) | ((c & 0x000000FF) << 16)` +- Font texture: `POOL_MANAGED`, created once in `Init`, `TexID` set via `io.Fonts.SetTexID` + +### Multi-viewport (docking/undocking outside AC window) +- `DockingEnable` is on +- `ViewportsEnable` is commented out — requires cimgui built with `IMGUI_ENABLE_VIEWPORTS` + +--- + +## Common Pitfalls + +| Symptom | Cause | +|---------|-------| +| `DisplaySize = <1, 1>` | cimgui.dll version mismatch (pre/post 1.90 layout) | +| Font cache crash on frame 2 | `io.Fonts.TexID` was zero after init (usually fixed by matching cimgui) | +| Crash in `SetupRenderStateNative` | Do not call `SetStreamSource(null, 0)` — invalid for UP drawing | +| Duplicate `vtxCount` compile error | Was present in early source — remove the second declaration | +| Hook not firing | acclient.exe must be running and past login before injection | +| `ChangePortalMode` event (future) | Crashes Decal — never use (RynthCore note carried from NexTank) | + +--- + +## Current Status (v0.2) + +- [x] D3D9 EndScene hook stable +- [x] ImGui context, font texture, WndProc subclass working +- [x] ImGui demo window + RynthCore info panel rendering +- [x] Mouse/keyboard input forwarded; ImGui captures input when hovered +- [ ] Multi-viewport (needs IMGUI_ENABLE_VIEWPORTS cimgui build) +- [ ] NexTank UI panels ported to RynthCore +- [ ] Network message hooks +- [ ] World state / actions API diff --git a/Plugins/RynthCore.Plugin.HelloBox/HelloBoxPlugin.cs b/Plugins/RynthCore.Plugin.HelloBox/HelloBoxPlugin.cs deleted file mode 100644 index 264662f..0000000 --- a/Plugins/RynthCore.Plugin.HelloBox/HelloBoxPlugin.cs +++ /dev/null @@ -1,797 +0,0 @@ -using System; -using System.Runtime.InteropServices; -using RynthCore.PluginCore; -using RynthCore.PluginSdk; - -namespace RynthCore.Plugin.HelloBox; - -public sealed unsafe class HelloBoxPlugin : RynthPluginBase -{ - private const int UiSnapshotIntervalMs = 250; - private const int ImGuiCondFirstUseEver = 1 << 2; - private const int ImGuiWindowFlagsNone = 0; - private const int ChatTypeWorldBroadcast = 1; - private const uint HookCombatInitialized = 1u << 0; - private const uint HookMovementInitialized = 1u << 1; - private const uint HookMeleeAttack = 1u << 2; - private const uint HookMissileAttack = 1u << 3; - private const uint HookChangeCombatMode = 1u << 4; - private const uint HookCancelAttack = 1u << 5; - private const uint HookQueryHealth = 1u << 6; - private const uint HookDoMovement = 1u << 7; - private const uint HookStopMovement = 1u << 8; - private const uint HookJumpNonAutonomous = 1u << 9; - private const uint HookSetAutonomyLevel = 1u << 10; - private const uint HookSetAutoRun = 1u << 11; - private const uint HookTapJump = 1u << 12; - - internal static readonly IntPtr NamePointer = Marshal.StringToHGlobalAnsi("RynthCore Hello Box"); - internal static readonly IntPtr VersionPointer = Marshal.StringToHGlobalAnsi("0.8.32"); - - private static readonly IntPtr WindowTitlePtr = Marshal.StringToHGlobalAnsi("RynthCore Hello Box##Plugin"); - private static readonly IntPtr GreetingPtr = Marshal.StringToHGlobalAnsi("Hello from the RynthCore test plugin."); - private static readonly IntPtr StatusPtr = Marshal.StringToHGlobalAnsi("PluginCore is active. Hello Box now runs through RynthPluginRuntime while keeping the current compatibility and helper validation surface."); - private static readonly IntPtr ProbeHooksButtonPtr = Marshal.StringToHGlobalAnsi("Probe Hooks"); - private static readonly IntPtr JumpButtonPtr = Marshal.StringToHGlobalAnsi("Jump"); - private static readonly IntPtr StartForwardButtonPtr = Marshal.StringToHGlobalAnsi("Start Forward"); - private static readonly IntPtr StopForwardButtonPtr = Marshal.StringToHGlobalAnsi("Stop Forward"); - private static readonly IntPtr ToggleIncomingEatButtonPtr = Marshal.StringToHGlobalAnsi("Toggle Eat Incoming"); - private static readonly IntPtr ToggleOutgoingEatButtonPtr = Marshal.StringToHGlobalAnsi("Toggle Eat Outgoing"); - private static readonly IntPtr GetPlayerIdButtonPtr = Marshal.StringToHGlobalAnsi("Get Player ID"); - private static readonly IntPtr GetSelectedIdButtonPtr = Marshal.StringToHGlobalAnsi("Get Selected ID"); - private static readonly IntPtr GetPreviousSelectedIdButtonPtr = Marshal.StringToHGlobalAnsi("Get Previous Selected"); - private static readonly IntPtr GetCoordsButtonPtr = Marshal.StringToHGlobalAnsi("Get Coords"); - private static readonly IntPtr GetGroundContainerButtonPtr = Marshal.StringToHGlobalAnsi("Get Ground Container"); - private static readonly IntPtr SelectSelfButtonPtr = Marshal.StringToHGlobalAnsi("Select Self"); - private static readonly IntPtr UseSelectedButtonPtr = Marshal.StringToHGlobalAnsi("Use Selected"); - private static readonly IntPtr WriteChatPingButtonPtr = Marshal.StringToHGlobalAnsi("Write Chat Ping"); - - private static RynthCoreApiNative _api; - private static RynthCoreHost _host; - private static bool _initialized; - private static bool _uiInitialized; - private static bool _loginComplete; - private static bool _windowVisible; - private static bool _imguiBound; - private static bool _eatIncomingChat; - private static bool _eatOutgoingChat; - private static int _busyCountIncrementedCount; - private static int _busyCountDecrementedCount; - private static int _incomingChatCount; - private static int _outgoingChatCount; - private static int _targetChangeCount; - private static int _combatModeChangeCount; - private static int _smartBoxEventCount; - private static int _createObjectCount; - private static int _deleteObjectCount; - private static int _updateObjectCount; - private static int _inventoryUpdateCount; - private static int _viewContentsCount; - private static int _stopViewContentsCount; - private static string _lastAction = "Waiting for OnLoginComplete."; - private static string _lastIncomingChat = "(none)"; - private static string _lastOutgoingChat = "(none)"; - private static string _lastBusyCountEvent = "(none)"; - private static string _lastTargetChange = "(none)"; - private static string _lastCombatModeChange = "(none)"; - private static bool _hasSmartBoxEvent; - private static uint _lastSmartBoxOpcode; - private static uint _lastSmartBoxBlobSize; - private static uint _lastSmartBoxStatus; - private static string _lastCreatedObject = "(none)"; - private static string _lastDeletedObject = "(none)"; - private static bool _hasUpdatedObject; - private static uint _lastUpdatedObjectId; - private static string _lastInventoryUpdate = "(none)"; - private static string _lastViewedContents = "(none)"; - private static string _lastClosedContents = "(none)"; - private static uint _currentTargetId; - private static IntPtr[] _uiSnapshotBuffers = Array.Empty(); - private static long _nextUiSnapshotTick; - - private static delegate* unmanaged[Cdecl] _igSetCurrentContext; - private static delegate* unmanaged[Cdecl] _igSetNextWindowPos; - private static delegate* unmanaged[Cdecl] _igSetNextWindowSize; - private static delegate* unmanaged[Cdecl] _igBegin; - private static delegate* unmanaged[Cdecl] _igButton; - private static delegate* unmanaged[Cdecl] _igTextUnformatted; - private static delegate* unmanaged[Cdecl] _igSeparator; - private static delegate* unmanaged[Cdecl] _igEnd; - - public override int Initialize() - { - _api = Api; - _host = Host; - - if (_api.ImGuiContext == IntPtr.Zero) - return 11; - - if (!TryBindImGui(out string error)) - { - Log($"Hello Box: failed to bind cimgui exports ({error})."); - return 12; - } - - _initialized = true; - _uiInitialized = false; - _loginComplete = false; - _windowVisible = false; - _eatIncomingChat = false; - _eatOutgoingChat = false; - _host.SetIncomingChatSuppression(false); - _busyCountIncrementedCount = 0; - _busyCountDecrementedCount = 0; - _incomingChatCount = 0; - _outgoingChatCount = 0; - _targetChangeCount = 0; - _combatModeChangeCount = 0; - _smartBoxEventCount = 0; - _createObjectCount = 0; - _deleteObjectCount = 0; - _updateObjectCount = 0; - _inventoryUpdateCount = 0; - _viewContentsCount = 0; - _stopViewContentsCount = 0; - _lastIncomingChat = "(none)"; - _lastOutgoingChat = "(none)"; - _lastBusyCountEvent = "(none)"; - _lastTargetChange = "(none)"; - _lastCombatModeChange = "(none)"; - _hasSmartBoxEvent = false; - _lastSmartBoxOpcode = 0; - _lastSmartBoxBlobSize = 0; - _lastSmartBoxStatus = 0; - _lastCreatedObject = "(none)"; - _lastDeletedObject = "(none)"; - _hasUpdatedObject = false; - _lastUpdatedObjectId = 0; - _lastInventoryUpdate = "(none)"; - _lastViewedContents = "(none)"; - _lastClosedContents = "(none)"; - ClearUiSnapshotBuffers(); - _nextUiSnapshotTick = 0; - _lastAction = "Waiting for OnLoginComplete."; - Log($"Hello Box: initialized via PluginCore. hookFlags=0x{_host.GetClientHookFlags():X8}"); - return 0; - } - - public override void Shutdown() - { - Log("Hello Box: shutting down."); - _initialized = false; - _uiInitialized = false; - _loginComplete = false; - _windowVisible = false; - ClearUiSnapshotBuffers(); - _host.SetIncomingChatSuppression(false); - } - - public override void OnUIInitialized() - { - if (!_initialized) - return; - - _uiInitialized = true; - SetLastAction("OnUIInitialized received."); - } - - public override void OnBusyCountIncremented() - { - if (!_initialized) - return; - - _busyCountIncrementedCount++; - _lastBusyCountEvent = "incremented"; - } - - public override void OnBusyCountDecremented() - { - if (!_initialized) - return; - - _busyCountDecrementedCount++; - _lastBusyCountEvent = "decremented"; - } - - public override void OnLoginComplete() - { - if (!_initialized) - return; - - _loginComplete = true; - SetLastAction("OnLoginComplete received. Open from the bar when needed."); - } - - public override void OnBarAction() - { - if (!_initialized || !_loginComplete) - return; - - _windowVisible = !_windowVisible; - SetLastAction(_windowVisible ? "Window opened from bar." : "Window hidden from bar."); - } - - public override void OnChatWindowText(string? text, int chatType, ref int eat) - { - if (!_initialized) - return; - - _incomingChatCount++; - _lastIncomingChat = text is not null - ? $"[{chatType}] {TrimForUi(text)}" - : $"[{chatType}] (queued stability path)"; - } - - public override void OnChatBarEnter(string? text, ref int eat) - { - if (!_initialized) - return; - - _outgoingChatCount++; - _lastOutgoingChat = TrimForUi(text ?? string.Empty); - if (_eatOutgoingChat) - eat = 1; - } - - public override void OnSelectedTargetChange(uint currentTargetId, uint previousTargetId) - { - if (!_initialized) - return; - - _targetChangeCount++; - _currentTargetId = currentTargetId; - _lastTargetChange = $"0x{previousTargetId:X8} -> 0x{currentTargetId:X8}"; - } - - public override void OnCombatModeChange(int currentCombatMode, int previousCombatMode) - { - if (!_initialized) - return; - - _combatModeChangeCount++; - _lastCombatModeChange = $"{FormatCombatMode(previousCombatMode)} -> {FormatCombatMode(currentCombatMode)}"; - } - - public override void OnSmartBoxEvent(uint opcode, uint blobSize, uint status) - { - if (!_initialized) - return; - - _smartBoxEventCount++; - _hasSmartBoxEvent = true; - _lastSmartBoxOpcode = opcode; - _lastSmartBoxBlobSize = blobSize; - _lastSmartBoxStatus = status; - } - - public override void OnDeleteObject(uint objectId) - { - if (!_initialized) - return; - - _deleteObjectCount++; - _lastDeletedObject = $"0x{objectId:X8}"; - } - - public override void OnCreateObject(uint objectId) - { - if (!_initialized) - return; - - _createObjectCount++; - _lastCreatedObject = $"0x{objectId:X8}"; - } - - public override void OnUpdateObject(uint objectId) - { - if (!_initialized) - return; - - _updateObjectCount++; - _hasUpdatedObject = true; - _lastUpdatedObjectId = objectId; - } - - public override void OnUpdateObjectInventory(uint objectId) - { - if (!_initialized) - return; - - _inventoryUpdateCount++; - _lastInventoryUpdate = $"0x{objectId:X8}"; - } - - public override void OnViewObjectContents(uint objectId) - { - if (!_initialized) - return; - - _viewContentsCount++; - _lastViewedContents = $"0x{objectId:X8}"; - } - - public override void OnStopViewingObjectContents(uint objectId) - { - if (!_initialized) - return; - - _stopViewContentsCount++; - _lastClosedContents = $"0x{objectId:X8}"; - } - - public override void OnRender() - { - if (!_initialized || !_loginComplete || !_windowVisible || !_imguiBound || _api.ImGuiContext == IntPtr.Zero) - return; - - uint hookFlags = _host.GetClientHookFlags(); - RefreshUiSnapshot(hookFlags); - - _igSetCurrentContext(_api.ImGuiContext); - _igSetNextWindowPos(new ImVec2(48f, 140f), ImGuiCondFirstUseEver, default); - _igSetNextWindowSize(new ImVec2(448f, 360f), ImGuiCondFirstUseEver); - - bool open = _igBegin(WindowTitlePtr, IntPtr.Zero, ImGuiWindowFlagsNone) != 0; - if (open) - { - _igTextUnformatted(GreetingPtr, IntPtr.Zero); - _igSeparator(); - _igTextUnformatted(StatusPtr, IntPtr.Zero); - foreach (IntPtr line in _uiSnapshotBuffers) - _igTextUnformatted(line, IntPtr.Zero); - - if (_igButton(ToggleIncomingEatButtonPtr, default) != 0) - { - _eatIncomingChat = !_eatIncomingChat; - _host.SetIncomingChatSuppression(_eatIncomingChat); - SetLastAction(_eatIncomingChat - ? "Incoming chat suppression enabled." - : "Incoming chat suppression disabled."); - } - - if (_igButton(ToggleOutgoingEatButtonPtr, default) != 0) - { - _eatOutgoingChat = !_eatOutgoingChat; - SetLastAction(_eatOutgoingChat ? "Outgoing chat suppression enabled." : "Outgoing chat suppression disabled."); - } - - _igSeparator(); - - if (_host.HasProbeClientHooks && _igButton(ProbeHooksButtonPtr, default) != 0) - { - _host.ProbeClientHooks(); - SetLastAction($"Probe requested. hookFlags=0x{_host.GetClientHookFlags():X8}"); - } - - if (_host.HasTapJump && _igButton(JumpButtonPtr, default) != 0) - { - bool ok = _host.TapJump(); - SetLastAction(ok ? "Jump requested." : "Jump request failed."); - } - - if (_host.HasSetAutoRun && _igButton(StartForwardButtonPtr, default) != 0) - { - bool ok = _host.SetAutoRun(true); - SetLastAction(ok ? "Forward movement started." : "Forward start failed."); - } - - if (_host.HasSetAutoRun && _igButton(StopForwardButtonPtr, default) != 0) - { - bool ok = _host.SetAutoRun(false); - SetLastAction(ok ? "Forward movement stop requested." : "Forward stop failed."); - } - - if (_host.HasGetPlayerId && _igButton(GetPlayerIdButtonPtr, default) != 0) - { - uint playerId = _host.GetPlayerId(); - SetLastAction(playerId != 0 - ? $"GetPlayerId -> 0x{playerId:X8}" - : "GetPlayerId returned 0."); - } - - if (_host.HasGetSelectedItemId && _igButton(GetSelectedIdButtonPtr, default) != 0) - { - uint selectedId = _host.GetSelectedItemId(); - SetLastAction(selectedId != 0 - ? $"GetSelectedItemId -> 0x{selectedId:X8}" - : "GetSelectedItemId returned 0."); - } - - if (_host.HasGetPreviousSelectedItemId && _igButton(GetPreviousSelectedIdButtonPtr, default) != 0) - { - uint previousSelectedId = _host.GetPreviousSelectedItemId(); - SetLastAction(previousSelectedId != 0 - ? $"GetPreviousSelectedItemId -> 0x{previousSelectedId:X8}" - : "GetPreviousSelectedItemId returned 0."); - } - - if (_host.HasGetCurCoords && _igButton(GetCoordsButtonPtr, default) != 0) - { - bool ok = _host.TryGetCurCoords(out double northSouth, out double eastWest); - SetLastAction(ok - ? $"GetCurCoords -> NS={northSouth:F3} EW={eastWest:F3}" - : "GetCurCoords failed."); - } - - if (_host.HasGetGroundContainerId && _igButton(GetGroundContainerButtonPtr, default) != 0) - { - uint groundContainerId = _host.GetGroundContainerId(); - SetLastAction(groundContainerId != 0 - ? $"GetGroundContainerId -> 0x{groundContainerId:X8}" - : "GetGroundContainerId returned 0."); - } - - if (_host.HasSelectItem && _host.HasGetPlayerId && _igButton(SelectSelfButtonPtr, default) != 0) - { - uint playerId = _host.GetPlayerId(); - if (playerId == 0) - { - SetLastAction("SelectSelf aborted: GetPlayerId returned 0."); - } - else - { - bool ok = _host.SelectItem(playerId); - SetLastAction(ok - ? $"SelectItem(self) -> 0x{playerId:X8}" - : $"SelectItem(self) failed for 0x{playerId:X8}."); - } - } - - if (_host.HasUseObject && _host.HasGetSelectedItemId && _igButton(UseSelectedButtonPtr, default) != 0) - { - uint selectedId = _host.GetSelectedItemId(); - if (selectedId == 0) - { - SetLastAction("UseSelected aborted: no selected object."); - } - else - { - bool ok = _host.UseObject(selectedId); - SetLastAction(ok - ? $"UseObject(selected) -> 0x{selectedId:X8}" - : $"UseObject(selected) failed for 0x{selectedId:X8}."); - } - } - - if (_host.HasWriteToChat && _igButton(WriteChatPingButtonPtr, default) != 0) - { - bool ok = _host.WriteToChat("RynthCore helper ping", ChatTypeWorldBroadcast); - SetLastAction(ok - ? "WriteToChat sent helper ping." - : "WriteToChat failed."); - } - - _igSeparator(); - TextOneOff($"Last action: {_lastAction}"); - } - - _igEnd(); - } - - // ─── Avalonia status text export ────────────────────────────────────── - private static IntPtr _statusTextPtr = IntPtr.Zero; - - /// - /// Called by the engine's HelloBoxPanel every 250 ms to get a snapshot of - /// current plugin state as a newline-delimited ANSI string. The returned - /// pointer is valid until the next call to this method. - /// - internal static IntPtr GetStatusTextPtr() - { - if (_statusTextPtr != IntPtr.Zero) - { - Marshal.FreeHGlobal(_statusTextPtr); - _statusTextPtr = IntPtr.Zero; - } - - if (!_initialized) - { - _statusTextPtr = Marshal.StringToHGlobalAnsi("Hello Box: not initialized.\nWaiting for OnLoginComplete..."); - return _statusTextPtr; - } - - uint hookFlags = _host.GetClientHookFlags(); - - string text = string.Join("\n", new[] - { - $"Hello Box v{Marshal.PtrToStringAnsi(VersionPointer)} — RynthPluginRuntime", - $"Lifecycle: UI={OnOff(_uiInitialized)} Login={OnOff(_loginComplete)}", - $"Hook flags: 0x{hookFlags:X8}", - $" combat {OnOff(hookFlags, HookCombatInitialized)} movement {OnOff(hookFlags, HookMovementInitialized)}", - $" melee {OnOff(hookFlags, HookMeleeAttack)} missile {OnOff(hookFlags, HookMissileAttack)} mode {OnOff(hookFlags, HookChangeCombatMode)} cancel {OnOff(hookFlags, HookCancelAttack)}", - $" move {OnOff(hookFlags, HookDoMovement)} stop {OnOff(hookFlags, HookStopMovement)} jump {OnOff(hookFlags, HookTapJump)} autorun {OnOff(hookFlags, HookSetAutoRun)}", - string.Empty, - $"Chat in: {_incomingChatCount:D6} eat={OnOff(_eatIncomingChat)}", - $"Chat out: {_outgoingChatCount:D6} eat={OnOff(_eatOutgoingChat)}", - $"Busy: +{_busyCountIncrementedCount:D6} / -{_busyCountDecrementedCount:D6}", - $"Target changes: {_targetChangeCount:D6}", - $"Combat changes: {_combatModeChangeCount:D6}", - $"SmartBox events: {_smartBoxEventCount:D6}", - $"Create/Delete/Update: {_createObjectCount}/{_deleteObjectCount}/{_updateObjectCount}", - $"Inventory updates: {_inventoryUpdateCount:D6}", - $"View/Close contents: {_viewContentsCount}/{_stopViewContentsCount}", - string.Empty, - $"Last incoming: {_lastIncomingChat}", - $"Last outgoing: {_lastOutgoingChat}", - $"Last busy event: {_lastBusyCountEvent}", - $"Last target: {_lastTargetChange}", - $"Last combat: {_lastCombatModeChange}", - _hasSmartBoxEvent - ? $"Last SmartBox: op=0x{_lastSmartBoxOpcode:X8} size={_lastSmartBoxBlobSize} status={_lastSmartBoxStatus}" - : "Last SmartBox: (none)", - $"Last created: {_lastCreatedObject}", - $"Last deleted: {_lastDeletedObject}", - _hasUpdatedObject ? $"Last updated: 0x{_lastUpdatedObjectId:X8}" : "Last updated: (none)", - $"Last inventory: {_lastInventoryUpdate}", - $"Last viewed: {_lastViewedContents}", - $"Last closed: {_lastClosedContents}", - string.Empty, - $"Status: {_lastAction}" - }); - - _statusTextPtr = Marshal.StringToHGlobalAnsi(text); - return _statusTextPtr; - } - - private static bool TryBindImGui(out string error) - { - if (_imguiBound) - { - error = string.Empty; - return true; - } - - IntPtr module = GetModuleHandleA("RynthCore.cimgui.dll"); - if (module == IntPtr.Zero) - module = GetModuleHandleA("cimgui.dll"); - - if (module == IntPtr.Zero) - { - error = "no loaded cimgui module"; - return false; - } - - if (!TryGetProc(module, "igSetCurrentContext", out IntPtr setCurrentContext)) - { - error = "missing igSetCurrentContext"; - return false; - } - - if (!TryGetProc(module, "igSetNextWindowPos", out IntPtr setNextWindowPos)) - { - error = "missing igSetNextWindowPos"; - return false; - } - - if (!TryGetProc(module, "igSetNextWindowSize", out IntPtr setNextWindowSize)) - { - error = "missing igSetNextWindowSize"; - return false; - } - - if (!TryGetProc(module, "igBegin", out IntPtr begin)) - { - error = "missing igBegin"; - return false; - } - - if (!TryGetProc(module, "igButton", out IntPtr button)) - { - error = "missing igButton"; - return false; - } - - if (!TryGetProc(module, "igTextUnformatted", out IntPtr textUnformatted)) - { - error = "missing igTextUnformatted"; - return false; - } - - if (!TryGetProc(module, "igSeparator", out IntPtr separator)) - { - error = "missing igSeparator"; - return false; - } - - if (!TryGetProc(module, "igEnd", out IntPtr end)) - { - error = "missing igEnd"; - return false; - } - - _igSetCurrentContext = (delegate* unmanaged[Cdecl])setCurrentContext; - _igSetNextWindowPos = (delegate* unmanaged[Cdecl])setNextWindowPos; - _igSetNextWindowSize = (delegate* unmanaged[Cdecl])setNextWindowSize; - _igBegin = (delegate* unmanaged[Cdecl])begin; - _igButton = (delegate* unmanaged[Cdecl])button; - _igTextUnformatted = (delegate* unmanaged[Cdecl])textUnformatted; - _igSeparator = (delegate* unmanaged[Cdecl])separator; - _igEnd = (delegate* unmanaged[Cdecl])end; - - _imguiBound = true; - error = string.Empty; - return true; - } - - private static bool TryGetProc(IntPtr module, string exportName, out IntPtr address) - { - address = GetProcAddress(module, exportName); - return address != IntPtr.Zero; - } - - private static string OnOff(bool value) => value ? "ON" : "OFF"; - - private static string OnOff(uint flags, uint flag) => (flags & flag) != 0 ? "ON" : "OFF"; - - private static string TrimForUi(string value) - { - if (string.IsNullOrWhiteSpace(value)) - return "(empty)"; - - string singleLine = value.Replace('\r', ' ').Replace('\n', ' ').Trim(); - return singleLine.Length <= 96 ? singleLine : singleLine[..96] + "..."; - } - - private static string FormatCombatMode(int combatMode) - { - return combatMode switch - { - 1 => "noncombat(1)", - 2 => "melee(2)", - 4 => "missile(4)", - 8 => "magic(8)", - _ => combatMode.ToString() - }; - } - - private static void RefreshUiSnapshot(uint hookFlags) - { - long now = Environment.TickCount64; - if (_uiSnapshotBuffers.Length != 0 && now < _nextUiSnapshotTick) - return; - - string[] lines = - [ - $"Host API version: {_api.Version}", - $"Lifecycle: UI {OnOff(_uiInitialized)} Login {OnOff(_loginComplete)}", - $"Hook flags: 0x{hookFlags:X8}", - $"Surfaces: combat {OnOff(hookFlags, HookCombatInitialized)}, movement {OnOff(hookFlags, HookMovementInitialized)}", - $"Combat actions: melee {OnOff(hookFlags, HookMeleeAttack)}, missile {OnOff(hookFlags, HookMissileAttack)}, mode {OnOff(hookFlags, HookChangeCombatMode)}, cancel {OnOff(hookFlags, HookCancelAttack)}, health {OnOff(hookFlags, HookQueryHealth)}", - $"Movement actions: move {OnOff(hookFlags, HookDoMovement)}, stop {OnOff(hookFlags, HookStopMovement)}, jump {OnOff(hookFlags, HookJumpNonAutonomous)}, autonomy {OnOff(hookFlags, HookSetAutonomyLevel)}", - $"Local actions: autorun {OnOff(hookFlags, HookSetAutoRun)}, tap-jump {OnOff(hookFlags, HookTapJump)}", - $"Helpers: player {OnOff(_host.HasGetPlayerId)}, selection {OnOff(_host.HasGetSelectedItemId && _host.HasSetSelectedObjectId)}, coords {OnOff(_host.HasGetCurCoords)}, chat {OnOff(_host.HasWriteToChat)}", - $"Helpers 2: ground {OnOff(_host.HasGetGroundContainerId)}, use-on {OnOff(_host.HasUseObjectOn)}, equipped {OnOff(_host.HasUseEquippedItem)}, move ext/int {OnOff(_host.HasMoveItemExternal && _host.HasMoveItemInternal)}", - string.Empty, - FormatPositionDebug(), - string.Empty, - $"Incoming chat callbacks: {_incomingChatCount:D6} Suppress {OnOff(_eatIncomingChat)} (host-side stable suppression)", - $"Outgoing chat callbacks: {_outgoingChatCount:D6} Eat {OnOff(_eatOutgoingChat)}", - $"Busy callbacks: +{_busyCountIncrementedCount:D6} -{_busyCountDecrementedCount:D6}", - $"Target change callbacks: {_targetChangeCount:D6}", - $"Combat mode callbacks: {_combatModeChangeCount:D6}", - $"SmartBox callbacks: {_smartBoxEventCount:D6}", - $"Create object callbacks: {_createObjectCount:D6}", - $"Delete object callbacks: {_deleteObjectCount:D6}", - $"Update object callbacks: {_updateObjectCount:D6}", - $"Inventory update callbacks: {_inventoryUpdateCount:D6}", - $"View contents callbacks: {_viewContentsCount:D6}", - $"Close contents callbacks: {_stopViewContentsCount:D6}", - $"Last incoming: {_lastIncomingChat}", - $"Last outgoing: {_lastOutgoingChat}", - $"Last busy event: {_lastBusyCountEvent}", - $"Last target: {_lastTargetChange}", - $"Last combat mode: {_lastCombatModeChange}", - _hasSmartBoxEvent - ? $"Last SmartBox: op=0x{_lastSmartBoxOpcode:X8} size={_lastSmartBoxBlobSize} status={_lastSmartBoxStatus}" - : "Last SmartBox: (none)", - $"Last created: {_lastCreatedObject}", - $"Last deleted: {_lastDeletedObject}", - _hasUpdatedObject ? $"Last updated: 0x{_lastUpdatedObjectId:X8}" : "Last updated: (none)", - $"Last inventory update: {_lastInventoryUpdate}", - $"Last viewed contents: {_lastViewedContents}", - $"Last closed contents: {_lastClosedContents}" - ]; - - ClearUiSnapshotBuffers(); - _uiSnapshotBuffers = new IntPtr[lines.Length]; - for (int i = 0; i < lines.Length; i++) - _uiSnapshotBuffers[i] = Marshal.StringToHGlobalAnsi(lines[i]); - - _nextUiSnapshotTick = now + UiSnapshotIntervalMs; - } - - private static void ClearUiSnapshotBuffers() - { - for (int i = 0; i < _uiSnapshotBuffers.Length; i++) - { - if (_uiSnapshotBuffers[i] != IntPtr.Zero) - Marshal.FreeHGlobal(_uiSnapshotBuffers[i]); - } - - _uiSnapshotBuffers = Array.Empty(); - } - - private static void TextOneOff(string message) - { - IntPtr buffer = Marshal.StringToHGlobalAnsi(message); - try - { - _igTextUnformatted(buffer, IntPtr.Zero); - } - finally - { - Marshal.FreeHGlobal(buffer); - } - } - - private static string FormatPositionDebug() - { - string playerLine; - float px = 0, py = 0, pz = 0; - uint pCell = 0; - bool hasPlayer = false; - - if (_host.HasGetPlayerPose && - _host.TryGetPlayerPose(out pCell, out px, out py, out pz, out _, out _, out _, out _)) - { - hasPlayer = true; - playerLine = $"Player pos: cell=0x{pCell:X8} x={px:F2} y={py:F2} z={pz:F2}"; - } - else - { - playerLine = "Player pos: unavailable"; - } - - string targetLine; - if (_currentTargetId != 0 && _host.HasGetObjectPosition && - _host.TryGetObjectPosition(_currentTargetId, out uint tCell, out float tx, out float ty, out float tz)) - { - _host.TryGetObjectName(_currentTargetId, out string name); - targetLine = $"Target pos: cell=0x{tCell:X8} x={tx:F2} y={ty:F2} z={tz:F2} [{name}]"; - - if (hasPlayer) - { - float dx = tx - px; - float dy = ty - py; - float dz = tz - pz; - float dist = (float)Math.Sqrt(dx * dx + dy * dy + dz * dz); - targetLine += $" dist={dist:F1}m"; - } - } - else if (_currentTargetId != 0) - { - targetLine = $"Target pos: FAILED for 0x{_currentTargetId:X8} (HasAPI={_host.HasGetObjectPosition})"; - } - else - { - targetLine = "Target pos: no target selected"; - } - - return $"{playerLine}\n{targetLine}"; - } - - private static void SetLastAction(string message) - { - _lastAction = message; - _host.Log($"Hello Box: {message}"); - } - - [DllImport("kernel32.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)] - private static extern IntPtr GetModuleHandleA(string lpModuleName); - - [DllImport("kernel32.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)] - private static extern IntPtr GetProcAddress(IntPtr hModule, string lpProcName); - - [StructLayout(LayoutKind.Sequential)] - private readonly struct ImVec2 - { - public readonly float X; - public readonly float Y; - - public ImVec2(float x, float y) - { - X = x; - Y = y; - } - } -} diff --git a/Plugins/RynthCore.Plugin.HelloBox/PluginExports.cs b/Plugins/RynthCore.Plugin.HelloBox/PluginExports.cs deleted file mode 100644 index 9037632..0000000 --- a/Plugins/RynthCore.Plugin.HelloBox/PluginExports.cs +++ /dev/null @@ -1,82 +0,0 @@ -using System; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; -using RynthCore.PluginCore; -using RynthCore.PluginSdk; - -namespace RynthCore.Plugin.HelloBox; - -public static unsafe class PluginExports -{ - private static readonly RynthPluginRuntime Runtime = new(); - - [UnmanagedCallersOnly(EntryPoint = "RynthPluginInit", CallConvs = new[] { typeof(CallConvCdecl) })] - private static int Init(RynthCoreApiNative* api) => Runtime.Init(api); - - [UnmanagedCallersOnly(EntryPoint = "RynthPluginShutdown", CallConvs = new[] { typeof(CallConvCdecl) })] - public static void Shutdown() => Runtime.Shutdown(); - - [UnmanagedCallersOnly(EntryPoint = "RynthPluginOnUIInitialized", CallConvs = new[] { typeof(CallConvCdecl) })] - public static void OnUIInitialized() => Runtime.OnUIInitialized(); - - [UnmanagedCallersOnly(EntryPoint = "RynthPluginOnBusyCountIncremented", CallConvs = new[] { typeof(CallConvCdecl) })] - public static void OnBusyCountIncremented() => Runtime.OnBusyCountIncremented(); - - [UnmanagedCallersOnly(EntryPoint = "RynthPluginOnBusyCountDecremented", CallConvs = new[] { typeof(CallConvCdecl) })] - public static void OnBusyCountDecremented() => Runtime.OnBusyCountDecremented(); - - [UnmanagedCallersOnly(EntryPoint = "RynthPluginOnLoginComplete", CallConvs = new[] { typeof(CallConvCdecl) })] - public static void OnLoginComplete() => Runtime.OnLoginComplete(); - - [UnmanagedCallersOnly(EntryPoint = "RynthPluginOnBarAction", CallConvs = new[] { typeof(CallConvCdecl) })] - public static void OnBarAction() => Runtime.OnBarAction(); - - [UnmanagedCallersOnly(EntryPoint = "RynthPluginOnChatWindowText", CallConvs = new[] { typeof(CallConvCdecl) })] - public static void OnChatWindowText(IntPtr textUtf16, int chatType, IntPtr eatFlag) => Runtime.OnChatWindowText(textUtf16, chatType, eatFlag); - - [UnmanagedCallersOnly(EntryPoint = "RynthPluginOnChatBarEnter", CallConvs = new[] { typeof(CallConvCdecl) })] - public static void OnChatBarEnter(IntPtr textUtf16, IntPtr eatFlag) => Runtime.OnChatBarEnter(textUtf16, eatFlag); - - [UnmanagedCallersOnly(EntryPoint = "RynthPluginOnSelectedTargetChange", CallConvs = new[] { typeof(CallConvCdecl) })] - public static void OnSelectedTargetChange(uint currentTargetId, uint previousTargetId) => Runtime.OnSelectedTargetChange(currentTargetId, previousTargetId); - - [UnmanagedCallersOnly(EntryPoint = "RynthPluginOnCombatModeChange", CallConvs = new[] { typeof(CallConvCdecl) })] - public static void OnCombatModeChange(int currentCombatMode, int previousCombatMode) => Runtime.OnCombatModeChange(currentCombatMode, previousCombatMode); - - [UnmanagedCallersOnly(EntryPoint = "RynthPluginOnSmartBoxEvent", CallConvs = new[] { typeof(CallConvCdecl) })] - public static void OnSmartBoxEvent(uint opcode, uint blobSize, uint status) => Runtime.OnSmartBoxEvent(opcode, blobSize, status); - - [UnmanagedCallersOnly(EntryPoint = "RynthPluginOnDeleteObject", CallConvs = new[] { typeof(CallConvCdecl) })] - public static void OnDeleteObject(uint objectId) => Runtime.OnDeleteObject(objectId); - - [UnmanagedCallersOnly(EntryPoint = "RynthPluginOnCreateObject", CallConvs = new[] { typeof(CallConvCdecl) })] - public static void OnCreateObject(uint objectId) => Runtime.OnCreateObject(objectId); - - [UnmanagedCallersOnly(EntryPoint = "RynthPluginOnUpdateObject", CallConvs = new[] { typeof(CallConvCdecl) })] - public static void OnUpdateObject(uint objectId) => Runtime.OnUpdateObject(objectId); - - [UnmanagedCallersOnly(EntryPoint = "RynthPluginOnUpdateObjectInventory", CallConvs = new[] { typeof(CallConvCdecl) })] - public static void OnUpdateObjectInventory(uint objectId) => Runtime.OnUpdateObjectInventory(objectId); - - [UnmanagedCallersOnly(EntryPoint = "RynthPluginOnViewObjectContents", CallConvs = new[] { typeof(CallConvCdecl) })] - public static void OnViewObjectContents(uint objectId) => Runtime.OnViewObjectContents(objectId); - - [UnmanagedCallersOnly(EntryPoint = "RynthPluginOnStopViewingObjectContents", CallConvs = new[] { typeof(CallConvCdecl) })] - public static void OnStopViewingObjectContents(uint objectId) => Runtime.OnStopViewingObjectContents(objectId); - - [UnmanagedCallersOnly(EntryPoint = "RynthPluginName", CallConvs = new[] { typeof(CallConvCdecl) })] - public static IntPtr GetName() => HelloBoxPlugin.NamePointer; - - [UnmanagedCallersOnly(EntryPoint = "RynthPluginVersion", CallConvs = new[] { typeof(CallConvCdecl) })] - public static IntPtr GetVersion() => HelloBoxPlugin.VersionPointer; - - [UnmanagedCallersOnly(EntryPoint = "RynthPluginRender", CallConvs = new[] { typeof(CallConvCdecl) })] - public static void Render() => Runtime.OnRender(); - - /// - /// Returns a pointer to a newline-delimited ANSI status string. - /// Valid until the next call. Called by the engine's Avalonia HelloBoxPanel. - /// - [UnmanagedCallersOnly(EntryPoint = "RynthPluginGetStatusText", CallConvs = new[] { typeof(CallConvCdecl) })] - public static IntPtr GetStatusText() => HelloBoxPlugin.GetStatusTextPtr(); -} diff --git a/Plugins/RynthCore.Plugin.HelloBox/RynthCore.Plugin.HelloBox.csproj b/Plugins/RynthCore.Plugin.HelloBox/RynthCore.Plugin.HelloBox.csproj deleted file mode 100644 index 5711d3d..0000000 --- a/Plugins/RynthCore.Plugin.HelloBox/RynthCore.Plugin.HelloBox.csproj +++ /dev/null @@ -1,57 +0,0 @@ - - - - net9.0-windows - x86 - win-x86 - Library - true - enable - true - Shared - true - Size - false - RynthCore.Plugin.HelloBox - RynthCore.Plugin.HelloBox - x86 - - - - - - - - - - <_EnginePluginDir Include="$(MSBuildThisFileDirectory)..\..\src\RynthCore.Engine\bin\$(Configuration)\net9.0-windows\win-x86\Plugins\" /> - <_EnginePluginDir Include="$(MSBuildThisFileDirectory)..\..\src\RynthCore.Engine\bin\$(PlatformTarget)\$(Configuration)\net9.0-windows\win-x86\Plugins\" /> - <_EnginePluginPublishDir Include="$(MSBuildThisFileDirectory)..\..\src\RynthCore.Engine\bin\$(Configuration)\net9.0-windows\win-x86\publish\Plugins\" /> - <_EnginePluginPublishDir Include="$(MSBuildThisFileDirectory)..\..\src\RynthCore.Engine\bin\$(PlatformTarget)\$(Configuration)\net9.0-windows\win-x86\publish\Plugins\" /> - - - - - - - - - - - diff --git a/RynthCore.sln b/RynthCore.sln index a33403b..de2c66e 100644 --- a/RynthCore.sln +++ b/RynthCore.sln @@ -9,8 +9,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RynthCore.Injector", "src\R EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RynthCore.App", "src\RynthCore.App\RynthCore.App.csproj", "{A1B2C3D4-0003-0003-0003-000000000003}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RynthCore.Plugin.HelloBox", "Plugins\RynthCore.Plugin.HelloBox\RynthCore.Plugin.HelloBox.csproj", "{A1B2C3D4-0004-0004-0004-000000000004}" -EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RynthCore.Plugin.RynthAi", "Plugins\RynthCore.Plugin.RynthAi\RynthCore.Plugin.RynthAi.csproj", "{A1B2C3D4-0005-0005-0005-000000000005}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{827E0CD3-B72D-47B6-A68D-7590B98EB39B}" @@ -67,18 +65,6 @@ Global {A1B2C3D4-0003-0003-0003-000000000003}.Release|Any CPU.Build.0 = Release|Any CPU {A1B2C3D4-0003-0003-0003-000000000003}.Release|x64.ActiveCfg = Release|Any CPU {A1B2C3D4-0003-0003-0003-000000000003}.Release|x64.Build.0 = Release|Any CPU - {A1B2C3D4-0004-0004-0004-000000000004}.Debug|x86.ActiveCfg = Debug|x86 - {A1B2C3D4-0004-0004-0004-000000000004}.Debug|x86.Build.0 = Debug|x86 - {A1B2C3D4-0004-0004-0004-000000000004}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {A1B2C3D4-0004-0004-0004-000000000004}.Debug|Any CPU.Build.0 = Debug|Any CPU - {A1B2C3D4-0004-0004-0004-000000000004}.Debug|x64.ActiveCfg = Debug|Any CPU - {A1B2C3D4-0004-0004-0004-000000000004}.Debug|x64.Build.0 = Debug|Any CPU - {A1B2C3D4-0004-0004-0004-000000000004}.Release|x86.ActiveCfg = Release|x86 - {A1B2C3D4-0004-0004-0004-000000000004}.Release|x86.Build.0 = Release|x86 - {A1B2C3D4-0004-0004-0004-000000000004}.Release|Any CPU.ActiveCfg = Release|Any CPU - {A1B2C3D4-0004-0004-0004-000000000004}.Release|Any CPU.Build.0 = Release|Any CPU - {A1B2C3D4-0004-0004-0004-000000000004}.Release|x64.ActiveCfg = Release|Any CPU - {A1B2C3D4-0004-0004-0004-000000000004}.Release|x64.Build.0 = Release|Any CPU {A1B2C3D4-0005-0005-0005-000000000005}.Debug|x86.ActiveCfg = Debug|x86 {A1B2C3D4-0005-0005-0005-000000000005}.Debug|x86.Build.0 = Debug|x86 {A1B2C3D4-0005-0005-0005-000000000005}.Debug|Any CPU.ActiveCfg = Debug|Any CPU diff --git a/find_bytes.cs b/find_bytes.cs new file mode 100644 index 0000000..a60420b --- /dev/null +++ b/find_bytes.cs @@ -0,0 +1,20 @@ +using System; +using System.IO; +using System.Runtime.InteropServices; +public class Program { + public static void Main() { + byte[] pe = File.ReadAllBytes(@"C:\Games\NexCore\acclient.exe"); + int peOffset = BitConverter.ToInt32(pe, 0x3C); + int numSections = BitConverter.ToInt16(pe, peOffset + 6); + int sectionHeaders = peOffset + 24 + BitConverter.ToInt16(pe, peOffset + 20); + for (int i = 0; i < numSections; i++) { + int rva = BitConverter.ToInt32(pe, sectionHeaders + i * 40 + 12); + int size = BitConverter.ToInt32(pe, sectionHeaders + i * 40 + 16); + int ptr = BitConverter.ToInt32(pe, sectionHeaders + i * 40 + 20); + if (rva <= 0x1583F0 && rva + size > 0x1583F0) { + int fileOffset = ptr + (0x1583F0 - rva); + Console.WriteLine("Bytes at GetWeenieObject: " + BitConverter.ToString(pe, fileOffset, 32)); + } + } + } +} diff --git a/loot-port-plan.txt b/loot-port-plan.txt new file mode 100644 index 0000000..9c2ab1c --- /dev/null +++ b/loot-port-plan.txt @@ -0,0 +1,204 @@ +# Plan: Port Loot System from NexSuite2 NexAi to NexCore NexAi + +## Context + +Porting the Loot subsystem (LootManager + VTankLootParser) from the old Decal-dependent NexAi at C:\Projects\NexSuite2\Plugins\NexAi\Loot\ to the new NexCore-based NexAi at C:\Projects\NexSuite\Plugins\NexCore.Plugin.NexAi\. The goal is to copy the files and adapt them to use NexCore's API instead of Decal's. + +### Decisions +- Salvage: Implement now — find VAs for SalvagePanelAdd/SalvagePanelSalvage in acclient.exe +- Loot evaluation: VTankLootParser IS the reimplemented VTank loot engine (handles UTL rule trees). Remove VTClassic/uTank2 code — our parser is the sole evaluator. Can add more VTank node types later if profiles need them. +- NeedsID: Always call RequestId on corpse items, wait up to assess window + +--- + +## Files to Copy + +Source (NexSuite2) -> Destination (NexSuite) +Plugins\NexAi\Loot\VTankLootParser.cs (284 ln) -> Plugins\NexCore.Plugin.NexAi\Loot\VTankLootParser.cs +Plugins\NexAi\Loot\LootManager.cs (1149 ln) -> Plugins\NexCore.Plugin.NexAi\Loot\LootManager.cs + +--- + +## Gap Analysis: What NexCore Has vs. What Loot Needs + +### Already Available (no engine work needed) + +Loot Requirement -> NexCore Equivalent +WorldObject.Id, .Name, .ObjectClass -> WorldObjectCache[id] returns WorldObject +WorldObject.Values(LongValueKey, default) -> WorldObject.Values() -> WorldObjectCache.GetIntProperty() -> TryGetObjectIntProperty() +WorldFilter.GetInventory() -> WorldObjectCache.GetInventory() +WorldFilter.GetLandscape() -> WorldObjectCache.GetLandscape() +WorldFilter.Distance(id1, id2) -> WorldObjectCache.Distance(id1, id2) +Actions.SelectItem(id) -> Host.SelectItem(uint) +Actions.UseItem(id, param) -> Host.UseObject(uint) +Actions.RequestId(id) -> Host.RequestId(uint) +Actions.MoveItem(...) -> Host.MoveItemExternal() + Host.MoveItemInternal() +CharacterFilter.Id -> Host.GetPlayerId() +AddChatText(text, color) -> Host.WriteToChat(text, chatType) +OnCreateObject / OnDeleteObject -> NexPluginBase virtual methods +OnUpdateObjectInventory -> NexPluginBase virtual method +OnViewObjectContents / OnStopViewing -> NexPluginBase virtual methods +OnBusyCountIncremented/Decremented -> NexPluginBase virtual methods +FellowshipTracker -> Already in NexCore.Plugin.NexAi/Combat/FellowshipTracker.cs + +### Plugin-Side Tracking (no engine changes) + +BusyState (is player idle?) -> Track _busyCount via OnBusyCountIncremented/Decremented events +OpenedContainer (which corpse is open?) -> Track _openedContainerId via OnViewObjectContents/OnStopViewing events + +--- + +## Must Add to NexCore Engine + SDK + +### 1. InqString — String Property Reading +File: src/NexCore.Engine/Compatibility/ClientObjectHooks.cs + +Why: VTank rule type 1 (StringValueMatch) reads string properties. Corpse ownership reads StringValueKey 16 (LongDesc = "Killed by {name}."). + +- Find VA for CBaseQualities::InqString (near InqInt 0x00590C20 / InqBool 0x00590CA0) +- Add delegate: int InqString(IntPtr qualitiesPtr, uint stype, IntPtr* retval) (ThisCall) +- Add method: TryGetObjectStringProperty(uint objectId, uint stype, out string value) +- Wire through NexCoreApiNative.GetObjectStringPropertyFn -> NexCoreHost.TryGetObjectStringProperty() + +### 2. InqFloat — Float/Double Property Reading +File: src/NexCore.Engine/Compatibility/ClientObjectHooks.cs + +Why: VTank rule types 4 & 5 (DoubleValKeyLE/GE) compare double properties (weapon damage variance, attack mod, etc.). + +- Find VA for CBaseQualities::InqFloat (near InqInt/InqBool) +- Add delegate + method: TryGetObjectFloatProperty(uint objectId, uint stype, out double value) +- Wire through SDK + +### 3. Container Contents API +File: src/NexCore.Engine/Compatibility/ClientObjectHooks.cs or UpdateObjectInventoryHooks.cs + +Why: After opening a corpse, need to enumerate items inside via GetByContainer(corpseId). + +- Expose existing GetExhaustiveContainedItemsList as SDK function: GetContainerContents(uint containerId, uint* outIds, int maxCount) -> int +- Wire through NexCoreApiNative.GetContainerContentsFn -> NexCoreHost.GetContainerContents() + +### 4. Salvage Panel APIs +File: New src/NexCore.Engine/Compatibility/SalvagePanelHooks.cs (or add to ClientHelperHooks) + +Why: Auto-salvage system needs SalvagePanelAdd(itemId) and SalvagePanelSalvage(). + +- Find VAs in acclient.exe APIManager__IAsheronsCallImpl_vtbl (documented as "declared but not yet validated") +- Implement as direct function calls via delegates +- Wire through SDK + +### 5. ObjectClass Expansion +File: Plugins/NexCore.Plugin.NexAi/Combat/AcStubs.cs + WorldObjectCache.cs + +Why: Loot system checks ObjectClass.Corpse, .Salvage, .Container, .Foci. + +- Expand AcObjectClass enum with Corpse, Container, Salvage, Foci values +- Add ITEM_TYPE constants: TYPE_CORPSE=0x00000020, TYPE_CONTAINER=0x00000040 +- Update WorldObjectCache.ClassifyByItemType() to detect these types + +### 6. String + Double Property Access on WorldObject +File: Plugins/NexCore.Plugin.NexAi/Combat/AcStubs.cs + +- Add StringValueKey enum (at minimum key 16 = LongDesc) +- Add DoubleValueKey enum +- Add WorldObject.Values(StringValueKey, default) -> delegates to cache -> SDK +- Add WorldObject.Values(DoubleValueKey, default) -> delegates to cache -> SDK +- Add WorldObjectCache.GetStringProperty() and WorldObjectCache.GetFloatProperty() methods + +--- + +## LootManager Adaptation Summary + +When copying LootManager.cs, these are the specific changes: + +Old (Decal) -> New (NexCore) +CoreManager _core + PluginHost _host -> NexCoreHost _host + WorldObjectCache _cache +_core.Actions.BusyState -> _busyCount > 0 (tracked via events) +_core.Actions.OpenedContainer -> _openedContainerId (tracked via events) +_core.Actions.SelectItem(id) -> _host.SelectItem((uint)id) +_core.Actions.UseItem(id, 0) -> _host.UseObject((uint)id) +_core.Actions.RequestId(id) -> _host.RequestId((uint)id) +_core.Actions.MoveItem(id, dest, slot, true) -> _host.MoveItemInternal((uint)id, (uint)dest, slot, 0) for stacking +_host.Actions.AddChatText(text, color) -> _host.WriteToChat(text, color) +_host.Actions.SalvagePanelAdd(id) -> _host.SalvagePanelAdd((uint)id) (new SDK method) +_host.Actions.SalvagePanelSalvage() -> _host.SalvagePanelSalvage() (new SDK method) +_core.WorldFilter[id] -> _cache[id] +_core.WorldFilter.GetByContainer(id) -> _host.GetContainerContents(id, ...) (new SDK method) +_core.WorldFilter.GetInventory() -> _cache.GetInventory() +_core.WorldFilter.GetLandscape() -> _cache.GetLandscape() +_core.WorldFilter.Distance(a, b) -> _cache.Distance(a, b) +_core.CharacterFilter.Id -> (int)_host.GetPlayerId() +_core.CharacterFilter.Name -> _host.TryGetObjectName(_host.GetPlayerId(), out name) +VTClassic.LootCore (Path 1) -> REMOVED — VTankLootParser handles all UTL evaluation +uTank2.PluginCore.PC.* (Path 3) -> REMOVED — single evaluation path +FLootPluginQueryNeedsID(id) -> Always true — always RequestId +WorldObject.Values((StringValueKey)k, "") -> wo.Values((StringValueKey)k, "") (new method on WorldObject) +WorldObject.Values((DoubleValueKey)k, 0.0) -> wo.Values((DoubleValueKey)k, 0.0) (new method on WorldObject) + +--- + +## Implementation Order + +### Phase 1: Engine — Property APIs +1. Find VAs for CBaseQualities::InqString and CBaseQualities::InqFloat +2. Add to ClientObjectHooks.cs: delegates, TryGetObjectStringProperty(), TryGetObjectFloatProperty() +3. Add to NexCoreApiNative.cs: GetObjectStringPropertyFn, GetObjectFloatPropertyFn +4. Add to NexCoreHost.cs: wrapper methods +5. Wire function pointers in EntryPoint.cs + +### Phase 2: Engine — Container Contents API +1. Add GetContainerContents() wrapper around existing GetExhaustiveContainedItemsList +2. Wire through SDK + +### Phase 3: Engine — Salvage Panel APIs +1. Find VAs for salvage panel functions in acclient.exe vtable +2. Implement + wire through SDK + +### Phase 4: Plugin — Expand Type System +1. AcStubs.cs: Add StringValueKey, DoubleValueKey enums +2. AcStubs.cs: Expand AcObjectClass (Corpse, Container, Salvage, Foci) +3. WorldObject: Add Values(StringValueKey), Values(DoubleValueKey) methods +4. WorldObjectCache: Add GetStringProperty(), GetFloatProperty(), expand classification + +### Phase 5: Plugin — Copy & Adapt Loot Files +1. Copy VTankLootParser.cs -> update namespace, replace Decal types with local types +2. Copy LootManager.cs -> apply all substitutions from table above +3. Simplify to single loot evaluation path (VTankLootParser only) +4. Always-RequestId for NeedsID + +### Phase 6: Plugin — Integration +1. Wire LootManager into NexAiPlugin.cs +2. Add settings to LegacyUiSettings.cs +3. Add chat commands for profile loading + +--- + +## Key Files to Modify + +### Engine (C:\Projects\nexcore\src\NexCore.Engine\) +- Compatibility/ClientObjectHooks.cs — InqString, InqFloat +- Compatibility/UpdateObjectInventoryHooks.cs — GetContainerContents export +- Compatibility/SalvagePanelHooks.cs — NEW: salvage APIs +- EntryPoint.cs — Wire new API function pointers + +### SDK (C:\Projects\nexcore\src\NexCore.PluginSdk\) +- NexCoreApiNative.cs — New function pointer fields +- NexCoreHost.cs — New wrapper methods + +### Plugin (C:\Projects\NexSuite\Plugins\NexCore.Plugin.NexAi\) +- Combat/AcStubs.cs — StringValueKey, DoubleValueKey, expanded ObjectClass +- Combat/WorldObjectCache.cs — Classification expansion, container tracking, new property methods +- Loot/VTankLootParser.cs — NEW (copy + adapt) +- Loot/LootManager.cs — NEW (copy + adapt) +- NexAiPlugin.cs — Wire LootManager +- LegacyUi/LegacyUiSettings.cs — Loot settings + +--- + +## Verification +1. cd src\NexCore.Engine && dotnet publish -c Release — engine builds +2. cd Plugins\NexCore.Plugin.NexAi && dotnet publish -c Release — plugin builds +3. Deploy to C:\Games\NexCore\ + inject into AC client +4. Load a VTank UTL profile via /na lootprofile +5. Verify: corpse detection -> item scanning -> RequestId -> loot evaluation -> pickup +6. Verify: salvage queue processes items correctly +7. Check %USERPROFILE%\Desktop\NexCore.log for errors diff --git a/src/RynthCore.Engine/EntryPoint.cs b/src/RynthCore.Engine/EntryPoint.cs index f3e82cb..22c2b66 100644 --- a/src/RynthCore.Engine/EntryPoint.cs +++ b/src/RynthCore.Engine/EntryPoint.cs @@ -325,10 +325,6 @@ public static class EntryPoint } } - private static readonly string LogPath = Path.Combine( - Environment.GetFolderPath(Environment.SpecialFolder.Desktop), - "RynthCore.log"); - internal static void Log(string message) { try @@ -341,8 +337,6 @@ public static class EntryPoint while (RecentLogLines.Count > MaxRecentLogLines) RecentLogLines.Dequeue(); } - - File.AppendAllText(LogPath, line + Environment.NewLine); } catch { diff --git a/src/RynthCore.Engine/ImGui/RynthCoreShell.cs b/src/RynthCore.Engine/ImGui/RynthCoreShell.cs index 7542963..5e5b2ac 100644 --- a/src/RynthCore.Engine/ImGui/RynthCoreShell.cs +++ b/src/RynthCore.Engine/ImGui/RynthCoreShell.cs @@ -104,7 +104,7 @@ internal static class RynthCoreShell style.GrabRounding = 8f; style.TabRounding = 8f; style.WindowBorderSize = 1f; - style.FrameBorderSize = 0f; + style.FrameBorderSize = 1f; style.ItemSpacing = new Vector2(10f, 10f); style.ItemInnerSpacing = new Vector2(8f, 6f); style.WindowPadding = new Vector2(14f, 14f); @@ -112,29 +112,30 @@ internal static class RynthCoreShell var colors = style.Colors; colors[(int)ImGuiCol.WindowBg] = new Vector4(0.04f, 0.06f, 0.08f, 0.97f); colors[(int)ImGuiCol.ChildBg] = Panel; - colors[(int)ImGuiCol.PopupBg] = new Vector4(0.05f, 0.07f, 0.10f, 0.98f); + colors[(int)ImGuiCol.PopupBg] = new Vector4(0.06f, 0.12f, 0.18f, 1.00f); colors[(int)ImGuiCol.Border] = new Vector4(0.16f, 0.23f, 0.28f, 1.00f); colors[(int)ImGuiCol.FrameBg] = new Vector4(0.08f, 0.11f, 0.15f, 1.00f); colors[(int)ImGuiCol.FrameBgHovered] = new Vector4(0.11f, 0.16f, 0.22f, 1.00f); colors[(int)ImGuiCol.FrameBgActive] = new Vector4(0.14f, 0.20f, 0.26f, 1.00f); colors[(int)ImGuiCol.TitleBg] = new Vector4(0.05f, 0.07f, 0.10f, 1.00f); colors[(int)ImGuiCol.TitleBgActive] = new Vector4(0.07f, 0.10f, 0.14f, 1.00f); - colors[(int)ImGuiCol.Button] = new Vector4(0.10f, 0.14f, 0.18f, 1.00f); - colors[(int)ImGuiCol.ButtonHovered] = new Vector4(0.14f, 0.21f, 0.27f, 1.00f); - colors[(int)ImGuiCol.ButtonActive] = new Vector4(0.11f, 0.26f, 0.24f, 1.00f); - colors[(int)ImGuiCol.Header] = new Vector4(0.10f, 0.14f, 0.18f, 1.00f); - colors[(int)ImGuiCol.HeaderHovered] = new Vector4(0.13f, 0.20f, 0.26f, 1.00f); - colors[(int)ImGuiCol.HeaderActive] = new Vector4(0.12f, 0.24f, 0.22f, 1.00f); + colors[(int)ImGuiCol.Button] = new Vector4(0.06f, 0.12f, 0.18f, 1.00f); + colors[(int)ImGuiCol.ButtonHovered] = new Vector4(0.10f, 0.18f, 0.25f, 1.00f); + colors[(int)ImGuiCol.ButtonActive] = new Vector4(0.08f, 0.15f, 0.22f, 1.00f); + colors[(int)ImGuiCol.Header] = new Vector4(0.06f, 0.12f, 0.18f, 1.00f); + colors[(int)ImGuiCol.HeaderHovered] = new Vector4(0.10f, 0.18f, 0.25f, 1.00f); + colors[(int)ImGuiCol.HeaderActive] = new Vector4(0.08f, 0.15f, 0.22f, 1.00f); + colors[(int)ImGuiCol.Border] = new Vector4(0.15f, 0.25f, 0.35f, 1.00f); colors[(int)ImGuiCol.CheckMark] = Accent; - colors[(int)ImGuiCol.SliderGrab] = Accent; - colors[(int)ImGuiCol.SliderGrabActive] = Gold; - colors[(int)ImGuiCol.Tab] = new Vector4(0.08f, 0.11f, 0.15f, 1.00f); - colors[(int)ImGuiCol.TabHovered] = new Vector4(0.13f, 0.20f, 0.26f, 1.00f); - colors[(int)ImGuiCol.TabSelected] = new Vector4(0.11f, 0.25f, 0.22f, 1.00f); - colors[(int)ImGuiCol.Separator] = new Vector4(0.16f, 0.23f, 0.28f, 1.00f); - colors[(int)ImGuiCol.ResizeGrip] = AccentSoft; - colors[(int)ImGuiCol.ResizeGripHovered] = Accent; - colors[(int)ImGuiCol.ResizeGripActive] = Gold; + colors[(int)ImGuiCol.SliderGrab] = new Vector4(0.15f, 0.30f, 0.45f, 1.00f); + colors[(int)ImGuiCol.SliderGrabActive] = new Vector4(0.20f, 0.40f, 0.60f, 1.00f); + colors[(int)ImGuiCol.Tab] = new Vector4(0.06f, 0.12f, 0.18f, 1.00f); + colors[(int)ImGuiCol.TabHovered] = new Vector4(0.10f, 0.18f, 0.25f, 1.00f); + colors[(int)ImGuiCol.TabSelected] = new Vector4(0.15f, 0.25f, 0.35f, 1.00f); + colors[(int)ImGuiCol.Separator] = new Vector4(0.15f, 0.25f, 0.35f, 1.00f); + colors[(int)ImGuiCol.ResizeGrip] = new Vector4(0.06f, 0.12f, 0.18f, 0.40f); + colors[(int)ImGuiCol.ResizeGripHovered] = new Vector4(0.10f, 0.18f, 0.25f, 1.00f); + colors[(int)ImGuiCol.ResizeGripActive] = new Vector4(0.15f, 0.25f, 0.35f, 1.00f); colors[(int)ImGuiCol.ModalWindowDimBg] = new Vector4(0, 0, 0, 0); } @@ -157,7 +158,7 @@ internal static class RynthCoreShell ImGui.SetNextWindowPos(_barPosition, ImGuiCond.FirstUseEver); } - ImGui.SetNextWindowBgAlpha(0.96f); + ImGui.SetNextWindowBgAlpha(1.0f); ImGui.PushStyleVar(ImGuiStyleVar.WindowPadding, new Vector2(6f, 4f)); ImGui.PushStyleVar(ImGuiStyleVar.ItemSpacing, new Vector2(4f, 3f)); ImGui.PushStyleVar(ImGuiStyleVar.FramePadding, new Vector2(5f, 2f)); @@ -182,15 +183,6 @@ internal static class RynthCoreShell ImGui.TextColored(Win32Backend.IsUiCaptureEnabled() ? Good : TextMute, Win32Backend.IsUiCaptureEnabled() ? "UI" : "GAME"); ShowTooltip("Press Insert to toggle UI capture."); - ImGui.SameLine(); - ImGui.BeginDisabled(!auxReady); - if (ImGui.SmallButton(_showShellWindow ? "Hd" : "Op")) - _showShellWindow = !_showShellWindow; - ShowTooltip(auxReady - ? (_showShellWindow ? "Hide RynthCore shell." : "Open RynthCore shell.") - : "Shell unlocks after the client render pipeline has stabilized."); - ImGui.EndDisabled(); - ImGui.SameLine(); ImGui.BeginDisabled(!auxReady); DrawCompactToggle("Lg", ref _showLogWindow); @@ -199,22 +191,6 @@ internal static class RynthCoreShell : "Diagnostics unlock after the client render pipeline has stabilized."); ImGui.EndDisabled(); - ImGui.SameLine(); - ImGui.BeginDisabled(!auxReady); - DrawCompactToggle("Mp", ref _showRoadmapWindow); - ShowTooltip(auxReady - ? "Open or close the roadmap window." - : "Roadmap unlocks after the client render pipeline has stabilized."); - ImGui.EndDisabled(); - - ImGui.SameLine(); - ImGui.BeginDisabled(!auxReady); - DrawCompactToggle("Dm", ref _showDemoWindow); - ShowTooltip(auxReady - ? "Open or close the ImGui demo window." - : "Demo unlocks after the client render pipeline has stabilized."); - ImGui.EndDisabled(); - ImGui.SameLine(); ImGui.BeginDisabled(!auxReady); DrawCompactToggle("Pk", ref _showPacketSnifferWindow); @@ -223,80 +199,6 @@ internal static class RynthCoreShell : "Packet sniffer unlocks after the client render pipeline has stabilized."); ImGui.EndDisabled(); - ImGui.SameLine(); - ImGui.BeginDisabled(!auxReady); - if (ImGui.SmallButton("+")) - OpenAllWindows(); - ShowTooltip(auxReady - ? "Open the shell, logs, roadmap, and demo windows." - : "Bulk window controls unlock after the client render pipeline has stabilized."); - ImGui.EndDisabled(); - - ImGui.SameLine(); - ImGui.BeginDisabled(!auxReady); - if (ImGui.SmallButton("-")) - CloseAllWindows(); - ShowTooltip(auxReady - ? "Close the shell, logs, roadmap, and demo windows." - : "Bulk window controls unlock after the client render pipeline has stabilized."); - ImGui.EndDisabled(); - - ImGui.SameLine(); - ImGui.BeginDisabled(!auxReady); - if (ImGui.SmallButton("Plg")) - ImGui.OpenPopup("PluginBarPopup"); - ShowTooltip(auxReady - ? "Choose which plugin shortcuts appear on the bar." - : "Plugin shortcuts unlock after the client render pipeline has stabilized."); - ImGui.EndDisabled(); - - if (ImGui.BeginPopup("PluginBarPopup")) - { - ImGui.TextColored(TextDim, "Plugin Shortcuts"); - ImGui.Separator(); - - for (int i = 0; i < PluginNames.Length; i++) - { - bool visible = PluginBarButtonsVisible[i]; - if (ImGui.Checkbox(PluginNames[i], ref visible)) - PluginBarButtonsVisible[i] = visible; - - ImGui.SameLine(220f); - ImGui.TextColored(TextMute, PluginStatuses[i]); - } - - ImGui.EndPopup(); - } - - bool anyPluginShortcut = false; - for (int i = 0; i < PluginNames.Length; i++) - { - if (!PluginBarButtonsVisible[i]) - continue; - - if (!anyPluginShortcut) - { - ImGui.SameLine(); - ImGui.TextColored(TextMute, "|"); - anyPluginShortcut = true; - } - else - { - ImGui.SameLine(); - } - - ImGui.BeginDisabled(!auxReady); - if (ImGui.SmallButton(PluginNames[i])) - { - _selectedPlugin = i; - _showShellWindow = true; - } - ShowTooltip(auxReady - ? $"{PluginNames[i]}: focus this plugin in the RynthCore shell." - : "Plugin shortcuts unlock after the client render pipeline has stabilized."); - ImGui.EndDisabled(); - } - var loadedPlugins = PluginManager.Plugins; bool anyLoadedPluginShortcut = false; for (int i = 0; i < loadedPlugins.Count; i++) @@ -347,6 +249,15 @@ internal static class RynthCoreShell ImGui.EndDisabled(); } + ImGui.SameLine(); + ImGui.BeginDisabled(!auxReady); + if (ImGui.SmallButton("RL")) + PluginManager.RequestRescan(); + ShowTooltip(auxReady + ? "Hot-reload all plugins: unloads, copies new DLLs, reloads." + : "Hot-reload unlocks after the client render pipeline has stabilized."); + ImGui.EndDisabled(); + ImGui.SameLine(); if (ImGui.SmallButton("Rs")) ResetBarPosition(); @@ -440,9 +351,9 @@ internal static class RynthCoreShell bool wasActive = value; if (wasActive) { - ImGui.PushStyleColor(ImGuiCol.Button, new Vector4(0.12f, 0.32f, 0.28f, 1.00f)); - ImGui.PushStyleColor(ImGuiCol.ButtonHovered, new Vector4(0.15f, 0.40f, 0.34f, 1.00f)); - ImGui.PushStyleColor(ImGuiCol.ButtonActive, new Vector4(0.18f, 0.46f, 0.39f, 1.00f)); + ImGui.PushStyleColor(ImGuiCol.Button, new Vector4(0.15f, 0.30f, 0.35f, 1.00f)); + ImGui.PushStyleColor(ImGuiCol.ButtonHovered, new Vector4(0.18f, 0.36f, 0.42f, 1.00f)); + ImGui.PushStyleColor(ImGuiCol.ButtonActive, new Vector4(0.20f, 0.40f, 0.46f, 1.00f)); } if (ImGui.SmallButton(label)) @@ -452,14 +363,18 @@ internal static class RynthCoreShell ImGui.PopStyleColor(3); } + private static readonly Vector4 TooltipBg = new(0.06f, 0.12f, 0.18f, 1.0f); + private static void ShowTooltip(string text) { if (!ImGui.IsItemHovered(ImGuiHoveredFlags.AllowWhenDisabled)) return; + ImGui.PushStyleColor(ImGuiCol.PopupBg, TooltipBg); ImGui.BeginTooltip(); ImGui.TextUnformatted(text); ImGui.EndTooltip(); + ImGui.PopStyleColor(); } private static void RenderHostWindow(int frameCount) @@ -1021,17 +936,11 @@ internal static class RynthCoreShell private static void OpenAllWindows() { - _showShellWindow = true; _showLogWindow = true; - _showRoadmapWindow = true; - _showDemoWindow = true; } private static void CloseAllWindows() { - _showShellWindow = false; _showLogWindow = false; - _showRoadmapWindow = false; - _showDemoWindow = false; } } diff --git a/src/RynthCore.Engine/UI/Panels/HelloBoxPanel.cs b/src/RynthCore.Engine/UI/Panels/HelloBoxPanel.cs deleted file mode 100644 index c932219..0000000 --- a/src/RynthCore.Engine/UI/Panels/HelloBoxPanel.cs +++ /dev/null @@ -1,102 +0,0 @@ -// ============================================================================ -// RynthCore.Engine - UI/Panels/HelloBoxPanel.cs -// Shows live status from the HelloBox plugin. Resolves the plugin's -// RynthPluginGetStatusText export via GetProcAddress on the module handle — -// no changes to the plugin contract needed. -// ============================================================================ - -using System; -using System.Linq; -using System.Runtime.InteropServices; -using Avalonia.Controls; -using Avalonia.Controls.Primitives; -using Avalonia.Media; -using Avalonia.Threading; -using Avalonia.VisualTree; -using RynthCore.Engine.Plugins; - -namespace RynthCore.Engine.UI.Panels; - -internal static class HelloBoxPanel -{ - [DllImport("kernel32.dll", CharSet = CharSet.Ansi, ExactSpelling = true)] - private static extern IntPtr GetProcAddress(IntPtr hModule, string lpProcName); - - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - private delegate IntPtr GetStatusTextFn(); - - private static GetStatusTextFn? _getStatusText; - - internal static Control Create() - { - TryBindDelegate(); - - var textBlock = new TextBlock - { - FontFamily = new FontFamily("Consolas,Courier New,monospace"), - FontSize = 10, - Foreground = new SolidColorBrush(Color.FromArgb(200, 210, 210, 210)), - TextWrapping = TextWrapping.Wrap, - Margin = new Avalonia.Thickness(8, 6) - }; - - var scroll = new ScrollViewer - { - VerticalScrollBarVisibility = ScrollBarVisibility.Auto, - HorizontalScrollBarVisibility = ScrollBarVisibility.Disabled, - Content = textBlock - }; - - var timer = new DispatcherTimer { Interval = TimeSpan.FromMilliseconds(250) }; - timer.Tick += (_, _) => - { - if (_getStatusText == null) - TryBindDelegate(); - - string text; - if (_getStatusText != null) - { - try - { - IntPtr ptr = _getStatusText(); - text = Marshal.PtrToStringAnsi(ptr) ?? "(empty)"; - } - catch (Exception ex) - { - text = $"Error reading status: {ex.Message}"; - } - } - else - { - var plugin = PluginManager.Plugins.FirstOrDefault(p => p.DisplayName.Contains("Hello")); - text = plugin == null - ? "Hello Box plugin not loaded." - : $"Hello Box loaded ({plugin.DisplayName}) but RynthPluginGetStatusText not found."; - } - - if (textBlock.Text != text) - textBlock.Text = text; - }; - scroll.DetachedFromVisualTree += (_, _) => timer.Stop(); - timer.Start(); - - return scroll; - } - - private static void TryBindDelegate() - { - var plugin = PluginManager.Plugins.FirstOrDefault(p => p.DisplayName.Contains("Hello")); - if (plugin == null) - return; - - IntPtr fn = GetProcAddress(plugin.ModuleHandle, "RynthPluginGetStatusText"); - if (fn == IntPtr.Zero) - return; - - if (_getStatusText != null) - return; - - _getStatusText = Marshal.GetDelegateForFunctionPointer(fn); - RynthLog.UI($"HelloBoxPanel: bound RynthPluginGetStatusText for '{plugin.DisplayName}'."); - } -}