Add salvage, appraisal, account, teleport hooks and expand engine API
New hooks: - AppraisalHooks: hook CM_Examine::SendNotice_SetAppraiseInfo (0x006B05B0) to cache bool properties from server appraisal data; fixes wobjectgetboolprop returning 0 for inventory items whose m_pQualities is null in client memory - SalvageHooks: hook gmSalvageUI::OpenSalvagePanel to capture singleton instance for use by SalvagePanelAddItem and SalvagePanelExecute - AccountHooks: capture account name and world/server name from login flow - TeleportStateHooks: track teleport/portal state via SmartBox ClientObjectHooks: check AppraisalHooks cache before CBaseQualities::InqBool in TryGetObjectBoolProperty so identified inventory items return correct values API v40 additions (PluginContract / PluginManager / PluginSdk): - GetCurrentCombatMode: direct read from ClientCombatSystem without hook - SalvagePanelOpen / SalvagePanelAddItem / SalvagePanelExecute - GetVitae: reads vitae multiplier via CACQualities::GetVitaeValue - GetAccountName / GetWorldName - GetObjectWcid: reads PublicWeenieDesc._wcid fast path Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
bb4399b69e
commit
c2ca425f87
12 changed files with 1161 additions and 12 deletions
271
src/RynthCore.Engine/Compatibility/AccountHooks.cs
Normal file
271
src/RynthCore.Engine/Compatibility/AccountHooks.cs
Normal file
|
|
@ -0,0 +1,271 @@
|
|||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Threading;
|
||||
using RynthCore.Engine.Hooking;
|
||||
|
||||
namespace RynthCore.Engine.Compatibility;
|
||||
|
||||
/// <summary>
|
||||
/// Reads the current account name via Client::GetInstance() + Client::GetAccountName().
|
||||
/// Captures the world/server name by hooking ECM_Login::SendNotice_WorldName (cdecl),
|
||||
/// with a fallback to the launcher's per-process JSON context file.
|
||||
///
|
||||
/// Client::GetInstance() — static cdecl, Map: 000104C0 → live VA: 0x004114C0
|
||||
/// Client::GetAccountName() — thiscall, Map: 00000D90 → live VA: 0x00401D90
|
||||
/// Returns accountID* where first field is PStringBase<char> (4-byte ptr to PSRefBuffer<char>).
|
||||
///
|
||||
/// ECM_Login::SendNotice_WorldName — cdecl, Map: 00292A60 → live VA: 0x00693A60
|
||||
/// Called once during login when the server announces the world name.
|
||||
/// Parameter: AC1Legacy::PStringBase<char> const& — same PSRefBuffer layout as account name.
|
||||
///
|
||||
/// PSRefBuffer<char> layout (confirmed from ClientObjectHooks InqString):
|
||||
/// +0: Turbine_RefCount { vfptr(4), m_cRef(4) } = 8 bytes
|
||||
/// +8: m_len (Int32, includes null terminator)
|
||||
/// +20: m_data[] (ANSI string)
|
||||
/// </summary>
|
||||
internal static class AccountHooks
|
||||
{
|
||||
private const int ReferenceClientGetInstance = 0x004114C0;
|
||||
private const int ReferenceClientGetAccountName = 0x00401D90;
|
||||
private const int SendNoticeWorldNameVa = 0x00693A60;
|
||||
private const int PStringBufferLenOffset = 8;
|
||||
private const int PStringBufferDataOffset = 20;
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||
private delegate IntPtr ClientGetInstanceDelegate();
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.ThisCall)]
|
||||
private delegate IntPtr ClientGetAccountNameDelegate(IntPtr clientPtr);
|
||||
|
||||
// ECM_Login::SendNotice_WorldName(AC1Legacy::PStringBase<char> const& i_strName) → bool
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||
private delegate byte SendNoticeWorldNameDelegate(IntPtr pstringPtr);
|
||||
|
||||
[DllImport("kernel32.dll", SetLastError = true)]
|
||||
private static extern int VirtualQuery(IntPtr lpAddress, out MEMORY_BASIC_INFORMATION lpBuffer, int dwLength);
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
private struct MEMORY_BASIC_INFORMATION
|
||||
{
|
||||
public IntPtr BaseAddress;
|
||||
public IntPtr AllocationBase;
|
||||
public uint AllocationProtect;
|
||||
public IntPtr RegionSize;
|
||||
public uint State;
|
||||
public uint Protect;
|
||||
public uint Type;
|
||||
}
|
||||
private const uint MEM_COMMIT = 0x1000;
|
||||
private const uint PAGE_NOACCESS = 0x01;
|
||||
private const uint PAGE_GUARD = 0x100;
|
||||
|
||||
private static ClientGetInstanceDelegate? _getClientInstance;
|
||||
private static ClientGetAccountNameDelegate? _getAccountName;
|
||||
private static SendNoticeWorldNameDelegate? _originalSendNoticeWorldName;
|
||||
private static SendNoticeWorldNameDelegate? _sendNoticeWorldNameDetour;
|
||||
private static string? _cachedAccountName;
|
||||
private static string? _cachedWorldName;
|
||||
|
||||
public static bool IsInitialized { get; private set; }
|
||||
public static bool WorldHookInstalled { get; private set; }
|
||||
|
||||
public static void Initialize()
|
||||
{
|
||||
try
|
||||
{
|
||||
_getClientInstance = Marshal.GetDelegateForFunctionPointer<ClientGetInstanceDelegate>(
|
||||
new IntPtr(ReferenceClientGetInstance));
|
||||
_getAccountName = Marshal.GetDelegateForFunctionPointer<ClientGetAccountNameDelegate>(
|
||||
new IntPtr(ReferenceClientGetAccountName));
|
||||
IsInitialized = true;
|
||||
RynthLog.Compat("Compat: account hooks ready.");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
RynthLog.Compat($"Compat: account hooks failed - {ex.Message}");
|
||||
}
|
||||
|
||||
HookWorldName();
|
||||
}
|
||||
|
||||
private static void HookWorldName()
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!AcClientModule.TryReadTextSection(out AcClientTextSection textSection))
|
||||
{
|
||||
RynthLog.Compat("Compat: world-name hook skipped - acclient.exe not available.");
|
||||
return;
|
||||
}
|
||||
|
||||
int funcOff = SendNoticeWorldNameVa - textSection.TextBaseVa;
|
||||
if (funcOff < 0 || funcOff >= textSection.Bytes.Length)
|
||||
{
|
||||
RynthLog.Compat($"Compat: world-name hook failed - VA 0x{SendNoticeWorldNameVa:X8} out of text section range.");
|
||||
return;
|
||||
}
|
||||
|
||||
byte firstByte = textSection.Bytes[funcOff];
|
||||
if (firstByte is 0x00 or 0xCC or 0xC3)
|
||||
{
|
||||
RynthLog.Compat($"Compat: world-name hook failed - invalid opcode 0x{firstByte:X2} @ 0x{SendNoticeWorldNameVa:X8}.");
|
||||
return;
|
||||
}
|
||||
|
||||
IntPtr targetAddress = new IntPtr(textSection.TextBaseVa + funcOff);
|
||||
_sendNoticeWorldNameDetour = SendNoticeWorldNameDetour;
|
||||
IntPtr detourPtr = Marshal.GetFunctionPointerForDelegate(_sendNoticeWorldNameDetour);
|
||||
_originalSendNoticeWorldName = Marshal.GetDelegateForFunctionPointer<SendNoticeWorldNameDelegate>(
|
||||
MinHook.HookCreate(targetAddress, detourPtr));
|
||||
Thread.MemoryBarrier();
|
||||
MinHook.Enable(targetAddress);
|
||||
|
||||
WorldHookInstalled = true;
|
||||
RynthLog.Compat($"Compat: world-name hook ready - ECM_Login::SendNotice_WorldName @ 0x{targetAddress.ToInt32():X8}.");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
RynthLog.Compat($"Compat: world-name hook failed - {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
private static byte SendNoticeWorldNameDetour(IntPtr pstringPtr)
|
||||
{
|
||||
byte result = 0;
|
||||
try { result = _originalSendNoticeWorldName!(pstringPtr); } catch { }
|
||||
|
||||
try
|
||||
{
|
||||
if (pstringPtr != IntPtr.Zero && IsReadable(pstringPtr))
|
||||
{
|
||||
// AC1Legacy::PStringBase<char>: first field is PSRefBuffer<char>*
|
||||
IntPtr bufferPtr = Marshal.ReadIntPtr(pstringPtr);
|
||||
if (bufferPtr != IntPtr.Zero && IsReadable(bufferPtr + PStringBufferDataOffset))
|
||||
{
|
||||
int len = Marshal.ReadInt32(bufferPtr + PStringBufferLenOffset);
|
||||
if (len > 1)
|
||||
{
|
||||
string? name = Marshal.PtrToStringAnsi(bufferPtr + PStringBufferDataOffset, len - 1);
|
||||
if (!string.IsNullOrEmpty(name))
|
||||
{
|
||||
_cachedWorldName = name;
|
||||
RynthLog.Compat($"Compat: world name captured - \"{name}\".");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the current account name. Result is cached after the first successful read.
|
||||
/// </summary>
|
||||
public static bool TryGetAccountName(out string name)
|
||||
{
|
||||
name = string.Empty;
|
||||
|
||||
if (_cachedAccountName != null)
|
||||
{
|
||||
name = _cachedAccountName;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (_getClientInstance == null || _getAccountName == null)
|
||||
return false;
|
||||
|
||||
try
|
||||
{
|
||||
IntPtr clientPtr = _getClientInstance();
|
||||
if (clientPtr == IntPtr.Zero || !IsReadable(clientPtr))
|
||||
return false;
|
||||
|
||||
IntPtr accountIdPtr = _getAccountName(clientPtr);
|
||||
if (accountIdPtr == IntPtr.Zero || !IsReadable(accountIdPtr))
|
||||
return false;
|
||||
|
||||
// accountID.name is PStringBase<char> — a 4-byte pointer to PSRefBuffer<char>
|
||||
IntPtr bufferPtr = Marshal.ReadIntPtr(accountIdPtr);
|
||||
if (bufferPtr == IntPtr.Zero || !IsReadable(bufferPtr + PStringBufferDataOffset))
|
||||
return false;
|
||||
|
||||
int len = Marshal.ReadInt32(bufferPtr + PStringBufferLenOffset);
|
||||
if (len <= 1)
|
||||
return false;
|
||||
|
||||
string? str = Marshal.PtrToStringAnsi(bufferPtr + PStringBufferDataOffset, len - 1);
|
||||
if (string.IsNullOrEmpty(str))
|
||||
return false;
|
||||
|
||||
_cachedAccountName = str;
|
||||
name = str;
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the world/server name. Populated by the ECM_Login::SendNotice_WorldName hook
|
||||
/// when the server announces it during login. Falls back to the RynthCore launcher's
|
||||
/// per-process JSON context file if the hook hasn't fired yet.
|
||||
/// </summary>
|
||||
public static bool TryGetWorldName(out string name)
|
||||
{
|
||||
name = string.Empty;
|
||||
|
||||
if (_cachedWorldName != null)
|
||||
{
|
||||
name = _cachedWorldName;
|
||||
return true;
|
||||
}
|
||||
|
||||
// Fallback: read from launcher context file (only present if launched via RynthCore)
|
||||
try
|
||||
{
|
||||
string appData = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
|
||||
string path = System.IO.Path.Combine(appData, "RynthCore", "launch_contexts",
|
||||
$"launch_context_{Environment.ProcessId}.json");
|
||||
|
||||
if (!System.IO.File.Exists(path))
|
||||
return false;
|
||||
|
||||
string json = System.IO.File.ReadAllText(path);
|
||||
|
||||
const string key = "\"ServerName\":\"";
|
||||
int idx = json.IndexOf(key, StringComparison.Ordinal);
|
||||
if (idx < 0)
|
||||
return false;
|
||||
|
||||
int start = idx + key.Length;
|
||||
int end = json.IndexOf('"', start);
|
||||
if (end <= start)
|
||||
return false;
|
||||
|
||||
string serverName = json.Substring(start, end - start);
|
||||
if (string.IsNullOrEmpty(serverName))
|
||||
return false;
|
||||
|
||||
_cachedWorldName = serverName;
|
||||
name = serverName;
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static bool IsReadable(IntPtr ptr)
|
||||
{
|
||||
if (ptr == IntPtr.Zero) return false;
|
||||
if (VirtualQuery(ptr, out var mbi, Marshal.SizeOf<MEMORY_BASIC_INFORMATION>()) == 0) return false;
|
||||
if (mbi.State != MEM_COMMIT) return false;
|
||||
if ((mbi.Protect & (PAGE_NOACCESS | PAGE_GUARD)) != 0) return false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
184
src/RynthCore.Engine/Compatibility/AppraisalHooks.cs
Normal file
184
src/RynthCore.Engine/Compatibility/AppraisalHooks.cs
Normal file
|
|
@ -0,0 +1,184 @@
|
|||
// ============================================================================
|
||||
// RynthCore.Engine - Compatibility/AppraisalHooks.cs
|
||||
//
|
||||
// Hooks CM_Examine::SendNotice_SetAppraiseInfo to cache appraisal bool
|
||||
// properties for inventory items whose m_pQualities is null.
|
||||
// CBaseQualities::InqBool returns 0 for such items because the property
|
||||
// setter skips CBaseQualities storage when m_pQualities is null.
|
||||
//
|
||||
// VA derivation (map_offset + 0x00401000 = live VA):
|
||||
// 002AF5B0 CM_Examine::SendNotice_SetAppraiseInfo → 0x006B05B0
|
||||
//
|
||||
// AppraisalProfile layout (from AppraisalProfile::Clear at 0x005B3BB0):
|
||||
// +0x00 vtable
|
||||
// +0x04 success_flag
|
||||
// +0x08 creature_profile*
|
||||
// +0x0c hook_profile*
|
||||
// +0x10 weapon_profile*
|
||||
// +0x14 armor_profile*
|
||||
// +0x18 _intStatsTable*
|
||||
// +0x1c _int64StatsTable*
|
||||
// +0x20 _boolStatsTable* ← used here
|
||||
// +0x24 _floatStatsTable*
|
||||
// +0x28 _strStatsTable*
|
||||
// +0x2c _didStatsTable*
|
||||
// ...
|
||||
//
|
||||
// PackableHashTable<uint,int> layout (from FUN_005d5760 lookup):
|
||||
// +0x08 bucket_array (IntPtr[] of node ptrs)
|
||||
// +0x0c bucket_count (modulus for key % count)
|
||||
// Node: [+0]=key(uint32), [+4]=value(int), [+8]=next(node* or null)
|
||||
// ============================================================================
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Threading;
|
||||
using RynthCore.Engine.Hooking;
|
||||
|
||||
namespace RynthCore.Engine.Compatibility;
|
||||
|
||||
internal static class AppraisalHooks
|
||||
{
|
||||
// CM_Examine::SendNotice_SetAppraiseInfo — cdecl (uint guid, AppraisalProfile*)
|
||||
// Map: 002AF5B0 → live VA: 0x006B05B0
|
||||
private const int SendNoticeSetAppraiseInfoVa = 0x006B05B0;
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||
private delegate int SendNoticeSetAppraiseInfoDelegate(uint guid, IntPtr profilePtr);
|
||||
|
||||
private static SendNoticeSetAppraiseInfoDelegate? _originalSendNotice;
|
||||
private static SendNoticeSetAppraiseInfoDelegate? _sendNoticeDetour; // held alive to prevent GC
|
||||
|
||||
private static bool _hookInstalled;
|
||||
private static string _statusMessage = "Not initialized.";
|
||||
|
||||
// Bool property cache: guid → (stype → value)
|
||||
private static readonly Dictionary<uint, Dictionary<uint, bool>> _boolCache = new();
|
||||
private static readonly object _cacheLock = new();
|
||||
|
||||
public static bool IsInstalled => _hookInstalled;
|
||||
public static string StatusMessage => _statusMessage;
|
||||
|
||||
/// <summary>
|
||||
/// Returns a bool property from the last server appraisal for this object.
|
||||
/// Only populated after the player has identified the item (RequestId).
|
||||
/// </summary>
|
||||
public static bool TryGetCachedBoolProperty(uint guid, uint stype, out bool value)
|
||||
{
|
||||
value = false;
|
||||
lock (_cacheLock)
|
||||
{
|
||||
if (!_boolCache.TryGetValue(guid, out Dictionary<uint, bool>? props))
|
||||
return false;
|
||||
return props.TryGetValue(stype, out value);
|
||||
}
|
||||
}
|
||||
|
||||
public static void Initialize()
|
||||
{
|
||||
if (_hookInstalled)
|
||||
return;
|
||||
|
||||
if (!AcClientModule.TryReadTextSection(out AcClientTextSection textSection))
|
||||
{
|
||||
_statusMessage = "acclient.exe not available.";
|
||||
return;
|
||||
}
|
||||
|
||||
int funcOff = SendNoticeSetAppraiseInfoVa - textSection.TextBaseVa;
|
||||
if (funcOff < 0 || funcOff >= textSection.Bytes.Length)
|
||||
{
|
||||
_statusMessage = $"CM_Examine::SendNotice_SetAppraiseInfo VA out of range @ 0x{SendNoticeSetAppraiseInfoVa:X8}.";
|
||||
RynthLog.Compat($"Compat: appraisal hook failed - {_statusMessage}");
|
||||
return;
|
||||
}
|
||||
|
||||
byte firstByte = textSection.Bytes[funcOff];
|
||||
if (firstByte is 0x00 or 0xCC or 0xC3)
|
||||
{
|
||||
_statusMessage = $"CM_Examine::SendNotice_SetAppraiseInfo looks invalid @ 0x{SendNoticeSetAppraiseInfoVa:X8} (opcode 0x{firstByte:X2}).";
|
||||
RynthLog.Compat($"Compat: appraisal hook failed - {_statusMessage}");
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
IntPtr targetAddress = new IntPtr(textSection.TextBaseVa + funcOff);
|
||||
_sendNoticeDetour = SendNoticeDetour;
|
||||
IntPtr detourPtr = Marshal.GetFunctionPointerForDelegate(_sendNoticeDetour);
|
||||
_originalSendNotice = Marshal.GetDelegateForFunctionPointer<SendNoticeSetAppraiseInfoDelegate>(
|
||||
MinHook.HookCreate(targetAddress, detourPtr));
|
||||
Thread.MemoryBarrier();
|
||||
MinHook.Enable(targetAddress);
|
||||
|
||||
_hookInstalled = true;
|
||||
_statusMessage = $"Hooked CM_Examine::SendNotice_SetAppraiseInfo @ 0x{targetAddress.ToInt32():X8}.";
|
||||
RynthLog.Compat($"Compat: appraisal hook ready @ 0x{targetAddress.ToInt32():X8}, firstByte=0x{firstByte:X2}");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_statusMessage = ex.Message;
|
||||
RynthLog.Compat($"Compat: appraisal hook failed - {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
private static int SendNoticeDetour(uint guid, IntPtr profilePtr)
|
||||
{
|
||||
// Call original first — notification fires, profile is still live in our frame
|
||||
int result = _originalSendNotice!(guid, profilePtr);
|
||||
|
||||
try
|
||||
{
|
||||
CacheBoolProps(guid, profilePtr);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
try { RynthLog.Compat($"Compat: appraisal bool cache error guid=0x{guid:X8} - {ex.GetType().Name}: {ex.Message}"); } catch { }
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private static void CacheBoolProps(uint guid, IntPtr profilePtr)
|
||||
{
|
||||
if (profilePtr == IntPtr.Zero)
|
||||
return;
|
||||
|
||||
// AppraisalProfile._boolStatsTable* is at offset +0x20
|
||||
IntPtr boolTablePtr = Marshal.ReadIntPtr(profilePtr + 0x20);
|
||||
if (boolTablePtr == IntPtr.Zero)
|
||||
return;
|
||||
|
||||
// PackableHashTable: bucket_array at +0x8, bucket_count at +0xC
|
||||
IntPtr bucketArray = Marshal.ReadIntPtr(boolTablePtr + 0x08);
|
||||
int bucketCount = Marshal.ReadInt32(boolTablePtr + 0x0C);
|
||||
|
||||
if (bucketArray == IntPtr.Zero || bucketCount <= 0 || bucketCount > 65536)
|
||||
return;
|
||||
|
||||
var props = new Dictionary<uint, bool>(4);
|
||||
|
||||
for (int i = 0; i < bucketCount; i++)
|
||||
{
|
||||
IntPtr node = Marshal.ReadIntPtr(bucketArray + i * 4);
|
||||
while (node != IntPtr.Zero)
|
||||
{
|
||||
uint key = (uint)Marshal.ReadInt32(node);
|
||||
int val = Marshal.ReadInt32(node + 4);
|
||||
props[key] = val != 0;
|
||||
node = Marshal.ReadIntPtr(node + 8);
|
||||
}
|
||||
}
|
||||
|
||||
if (props.Count == 0)
|
||||
return;
|
||||
|
||||
lock (_cacheLock)
|
||||
{
|
||||
_boolCache[guid] = props;
|
||||
}
|
||||
|
||||
RynthLog.Compat($"Compat: cached {props.Count} bool prop(s) for guid=0x{guid:X8}");
|
||||
}
|
||||
}
|
||||
|
|
@ -21,6 +21,21 @@ internal static class ClientHelperHooks
|
|||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||
private delegate byte UseWithTargetEventDelegate(uint objectId, uint targetId);
|
||||
|
||||
// CM_Inventory::SendNotice_OpenSalvagePanel(uint toolId) — cdecl
|
||||
// Map: 002AC4F0 → live VA: 0x006AD4F0
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||
private delegate byte SendNoticeOpenSalvagePanelDelegate(uint toolId);
|
||||
|
||||
// gmSalvageUI::AddNewItem(uint itemId) — thiscall
|
||||
// Map: 000CB020 → live VA: 0x004CC020
|
||||
[UnmanagedFunctionPointer(CallingConvention.ThisCall)]
|
||||
private delegate void GmSalvageUIAddNewItemDelegate(IntPtr thisPtr, uint itemId);
|
||||
|
||||
// gmSalvageUI::Salvage(void) — thiscall
|
||||
// Map: 000CB430 → live VA: 0x004CC430
|
||||
[UnmanagedFunctionPointer(CallingConvention.ThisCall)]
|
||||
private delegate void GmSalvageUISalvageDelegate(IntPtr thisPtr);
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.ThisCall)]
|
||||
private delegate void UseEquippedItemDelegate(IntPtr acPlugin, uint sourceObjectId, uint targetObjectId);
|
||||
|
||||
|
|
@ -87,6 +102,9 @@ internal static class ClientHelperHooks
|
|||
private const int CommunicationSystemVa = 0x00870BE4;
|
||||
private const int AddTextToScrollVa = 0x005649F0;
|
||||
private const int UseWithTargetEventVa = 0x006AD3E0;
|
||||
private const int SendNoticeOpenSalvagePanelVa = 0x006AD4F0;
|
||||
private const int GmSalvageUIAddNewItemVa = 0x004CC020;
|
||||
private const int GmSalvageUISalvageVa = 0x004CC430;
|
||||
|
||||
private static SetSelectedObjectDelegate? _setSelectedObject;
|
||||
private static UseObjectDelegate? _useObject;
|
||||
|
|
@ -100,6 +118,9 @@ internal static class ClientHelperHooks
|
|||
private static GetPlayerIdDelegate? _getPlayerId;
|
||||
private static AddTextToScrollDelegate? _addTextToScroll;
|
||||
private static UseWithTargetEventDelegate? _useWithTargetEvent;
|
||||
private static SendNoticeOpenSalvagePanelDelegate? _sendNoticeOpenSalvagePanel;
|
||||
private static GmSalvageUIAddNewItemDelegate? _gmSalvageUIAddNewItem;
|
||||
private static GmSalvageUISalvageDelegate? _gmSalvageUISalvage;
|
||||
private static bool _initialized;
|
||||
private static string _statusMessage = "Not probed yet.";
|
||||
private static int _interactionLogCount;
|
||||
|
|
@ -122,6 +143,7 @@ internal static class ClientHelperHooks
|
|||
public static bool HasGetGroundContainerId => true;
|
||||
public static bool HasWriteToChat => _addTextToScroll != null;
|
||||
public static bool HasInvokeParser => true;
|
||||
public static bool HasSalvagePanel => _sendNoticeOpenSalvagePanel != null && _gmSalvageUIAddNewItem != null && _gmSalvageUISalvage != null;
|
||||
private static int _currentGroundContainerId;
|
||||
|
||||
public static bool Probe()
|
||||
|
|
@ -140,6 +162,9 @@ internal static class ClientHelperHooks
|
|||
_getPlayerId = Marshal.GetDelegateForFunctionPointer<GetPlayerIdDelegate>(new IntPtr(GetPlayerIdVa));
|
||||
_addTextToScroll = Marshal.GetDelegateForFunctionPointer<AddTextToScrollDelegate>(new IntPtr(AddTextToScrollVa));
|
||||
_useWithTargetEvent = Marshal.GetDelegateForFunctionPointer<UseWithTargetEventDelegate>(new IntPtr(UseWithTargetEventVa));
|
||||
_sendNoticeOpenSalvagePanel = Marshal.GetDelegateForFunctionPointer<SendNoticeOpenSalvagePanelDelegate>(new IntPtr(SendNoticeOpenSalvagePanelVa));
|
||||
_gmSalvageUIAddNewItem = Marshal.GetDelegateForFunctionPointer<GmSalvageUIAddNewItemDelegate>(new IntPtr(GmSalvageUIAddNewItemVa));
|
||||
_gmSalvageUISalvage = Marshal.GetDelegateForFunctionPointer<GmSalvageUISalvageDelegate>(new IntPtr(GmSalvageUISalvageVa));
|
||||
_initialized = true;
|
||||
_statusMessage = "Ready.";
|
||||
RynthLog.Compat("Compat: helper hooks ready - validated select/state/chat helpers plus mapped interaction and inventory helpers.");
|
||||
|
|
@ -506,6 +531,86 @@ internal static class ClientHelperHooks
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Open the salvage panel for the given salvage tool.
|
||||
/// Calls CM_Inventory::SendNotice_OpenSalvagePanel (cdecl) which dispatches
|
||||
/// the UI notice asynchronously; allow ~400 ms before calling AddItem.
|
||||
/// </summary>
|
||||
public static bool SalvagePanelOpen(uint toolId)
|
||||
{
|
||||
if (_sendNoticeOpenSalvagePanel == null || toolId == 0)
|
||||
return false;
|
||||
|
||||
try
|
||||
{
|
||||
_sendNoticeOpenSalvagePanel(toolId);
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
RynthLog.Compat($"Compat: SalvagePanelOpen threw - {ex.Message}");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add an item to the salvage panel.
|
||||
/// Calls gmSalvageUI::AddNewItem (thiscall) via the captured singleton.
|
||||
/// Requires the panel to have been opened at least once so SalvageHooks
|
||||
/// has captured the gmSalvageUI instance pointer.
|
||||
/// </summary>
|
||||
public static bool SalvagePanelAddItem(uint itemId)
|
||||
{
|
||||
if (_gmSalvageUIAddNewItem == null || itemId == 0)
|
||||
return false;
|
||||
|
||||
IntPtr inst = SalvageHooks.GmSalvageUIInstance;
|
||||
if (inst == IntPtr.Zero)
|
||||
{
|
||||
RynthLog.Compat("Compat: SalvagePanelAddItem - gmSalvageUI instance not captured yet");
|
||||
return false;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
_gmSalvageUIAddNewItem(inst, itemId);
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
RynthLog.Compat($"Compat: SalvagePanelAddItem threw - {ex.Message}");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Execute the salvage operation (click Salvage button).
|
||||
/// Calls gmSalvageUI::Salvage (thiscall) via the captured singleton.
|
||||
/// </summary>
|
||||
public static bool SalvagePanelExecute()
|
||||
{
|
||||
if (_gmSalvageUISalvage == null)
|
||||
return false;
|
||||
|
||||
IntPtr inst = SalvageHooks.GmSalvageUIInstance;
|
||||
if (inst == IntPtr.Zero)
|
||||
{
|
||||
RynthLog.Compat("Compat: SalvagePanelExecute - gmSalvageUI instance not captured yet");
|
||||
return false;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
_gmSalvageUISalvage(inst);
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
RynthLog.Compat($"Compat: SalvagePanelExecute threw - {ex.Message}");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool InvokeParser(string? text)
|
||||
{
|
||||
if (string.IsNullOrEmpty(text))
|
||||
|
|
@ -541,6 +646,9 @@ internal static class ClientHelperHooks
|
|||
_getPlayerId = null;
|
||||
_addTextToScroll = null;
|
||||
_useWithTargetEvent = null;
|
||||
_sendNoticeOpenSalvagePanel = null;
|
||||
_gmSalvageUIAddNewItem = null;
|
||||
_gmSalvageUISalvage = null;
|
||||
_initialized = false;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -49,6 +49,10 @@ internal static class ClientObjectHooks
|
|||
// CACQualities::InqSkillAdvancementClass(uint stype, SKILL_ADVANCEMENT_CLASS* retval)
|
||||
// SKILL_ADVANCEMENT_CLASS: UNDEF=0, UNTRAINED=1, TRAINED=2, SPECIALIZED=3
|
||||
private const int ReferenceInqSkillAdvancementClass = 0x00592B70;
|
||||
|
||||
// CACQualities::GetVitaeValue() — ThisCall, no args, returns float (1.0=no vitae, 0.95=5% penalty)
|
||||
// Map: 0018EE80 → live VA: 0x0058FE80
|
||||
private const int ReferenceGetVitaeValue = 0x0058FE80;
|
||||
private const int NameTypeSingular = 0;
|
||||
private const int MaxLookupLogs = 12;
|
||||
|
||||
|
|
@ -175,6 +179,10 @@ internal static class ClientObjectHooks
|
|||
[UnmanagedFunctionPointer(CallingConvention.ThisCall)]
|
||||
private delegate int IsSpellKnownDelegate(IntPtr qualitiesPtr, uint spellId);
|
||||
|
||||
// float __thiscall CACQualities::GetVitaeValue()
|
||||
[UnmanagedFunctionPointer(CallingConvention.ThisCall)]
|
||||
private delegate float GetVitaeValueDelegate(IntPtr qualitiesPtr);
|
||||
|
||||
// ClientCombatSystem* __cdecl ClientCombatSystem::GetCombatSystem()
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||
private delegate IntPtr GetCombatSystemDelegate();
|
||||
|
|
@ -233,6 +241,7 @@ internal static class ClientObjectHooks
|
|||
private static InqSkillLevelDelegate? _inqSkillLevel;
|
||||
private static InqSkillAdvancementClassDelegate? _inqSkillAdvancementClass;
|
||||
private static IsSpellKnownDelegate? _isSpellKnown;
|
||||
private static GetVitaeValueDelegate? _getVitaeValue;
|
||||
private static int _lookupLogCount;
|
||||
|
||||
public static bool IsInitialized { get; private set; }
|
||||
|
|
@ -309,6 +318,7 @@ internal static class ClientObjectHooks
|
|||
_inqSkillLevel = Marshal.GetDelegateForFunctionPointer<InqSkillLevelDelegate>(new IntPtr(ReferenceInqSkillLevel));
|
||||
_inqSkillAdvancementClass = Marshal.GetDelegateForFunctionPointer<InqSkillAdvancementClassDelegate>(new IntPtr(ReferenceInqSkillAdvancementClass));
|
||||
_isSpellKnown = Marshal.GetDelegateForFunctionPointer<IsSpellKnownDelegate>(new IntPtr(ReferenceIsSpellKnown));
|
||||
_getVitaeValue = Marshal.GetDelegateForFunctionPointer<GetVitaeValueDelegate>(new IntPtr(ReferenceGetVitaeValue));
|
||||
RynthLog.Compat(
|
||||
$"Compat: client object hooks ready - getWeenie=0x{getWeeniePtr.ToInt32():X8}, getNameStatic=0x{getNameStaticPtr.ToInt32():X8}, getNameInstance=0x{getNameInstancePtr.ToInt32():X8}");
|
||||
return true;
|
||||
|
|
@ -343,6 +353,36 @@ internal static class ClientObjectHooks
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the player's vitae multiplier via CACQualities::GetVitaeValue.
|
||||
/// Returns 1.0 when there is no vitae penalty. 0.95 = 5% penalty, etc.
|
||||
/// </summary>
|
||||
public static bool TryGetVitae(uint playerId, out float value)
|
||||
{
|
||||
value = 1.0f;
|
||||
if (_getVitaeValue == null || _getWeenieObject == null)
|
||||
{
|
||||
if (!Probe() || _getVitaeValue == null || _getWeenieObject == null)
|
||||
return false;
|
||||
}
|
||||
try
|
||||
{
|
||||
IntPtr weeniePtr = _getWeenieObject(playerId);
|
||||
if (weeniePtr == IntPtr.Zero)
|
||||
return false;
|
||||
|
||||
if (!TryGetQualitiesPtr(weeniePtr, out IntPtr qualitiesPtr))
|
||||
return false;
|
||||
|
||||
value = _getVitaeValue(qualitiesPtr);
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called by PlayerVitalsHooks when SendNoticePlayerDescReceived fires, providing the
|
||||
/// known CACQualities* (== PlayerDesc*) so we can probe its offset within ACCWeenieObject.
|
||||
|
|
@ -584,6 +624,40 @@ internal static class ClientObjectHooks
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads PublicWeenieDesc._wcid directly from the weenie struct.
|
||||
/// Returns the Weenie Class ID (WCID) for the given object.
|
||||
/// Layout: ACCWeenieObject + _phys_obj_offset + 4 = start of PublicWeenieDesc.
|
||||
/// PublicWeenieDesc+12 = _wcid: WeenieDesc(4) + _name(4) + _plural_name(4) = 12.
|
||||
/// </summary>
|
||||
public static bool TryGetObjectWcid(uint objectId, out uint wcid)
|
||||
{
|
||||
wcid = 0;
|
||||
if (_getWeenieObject == null)
|
||||
{
|
||||
if (!Probe() || _getWeenieObject == null)
|
||||
return false;
|
||||
}
|
||||
if (_weeniePhysicsObjOffset < 0)
|
||||
return false;
|
||||
try
|
||||
{
|
||||
IntPtr weeniePtr = _getWeenieObject(objectId);
|
||||
if (weeniePtr == IntPtr.Zero)
|
||||
return false;
|
||||
int pwdBase = _weeniePhysicsObjOffset + 4;
|
||||
IntPtr fieldAddr = weeniePtr + pwdBase + 12;
|
||||
if (!IsReadablePointer(fieldAddr))
|
||||
return false;
|
||||
wcid = (uint)Marshal.ReadInt32(fieldAddr);
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static bool TryGetObjectQualitiesPtr(uint objectId, out IntPtr qualitiesPtr)
|
||||
{
|
||||
qualitiesPtr = IntPtr.Zero;
|
||||
|
|
@ -710,16 +784,20 @@ internal static class ClientObjectHooks
|
|||
// Fast path: stypes whose values live in PublicWeenieDesc.
|
||||
// PWD starts at weenie + _phys_obj_offset + 4. Layout (Chorizite Weenie.cs:1734):
|
||||
// +28 _containerID, +32 _wielderID, +40 _valid_locations, +44 _location,
|
||||
// +48 _itemsCapacity, +52 _containersCapacity, +96 _stackSize, +100 _maxStackSize
|
||||
// +48 _itemsCapacity, +52 _containersCapacity, +96 _stackSize, +100 _maxStackSize,
|
||||
// +148 _material_type
|
||||
// CBaseQualities::InqInt fails for inventory/corpse items (m_pQualities is null on pack wienies).
|
||||
// Any stype whose value lives in PWD must be served from here instead.
|
||||
int pwdFieldOffset = stype switch
|
||||
{
|
||||
6 => 48, // ITEMS_CAPACITY → _itemsCapacity
|
||||
7 => 52, // CONTAINERS_CAPACITY → _containersCapacity
|
||||
9 => 40, // LOCATIONS → _valid_locations
|
||||
10 => 44, // CURRENT_WIELDED_LOCATION → _location
|
||||
11 => 100, // MAX_STACK_SIZE → _maxStackSize
|
||||
12 => 96, // STACK_SIZE → _stackSize
|
||||
_ => -1,
|
||||
6 => 48, // ITEMS_CAPACITY → _itemsCapacity
|
||||
7 => 52, // CONTAINERS_CAPACITY → _containersCapacity
|
||||
9 => 40, // LOCATIONS → _valid_locations
|
||||
10 => 44, // CURRENT_WIELDED_LOCATION → _location
|
||||
11 => 100, // MAX_STACK_SIZE → _maxStackSize
|
||||
12 => 96, // STACK_SIZE → _stackSize
|
||||
131 => 148, // MATERIAL_TYPE → _material_type (4 bytes, int)
|
||||
_ => -1,
|
||||
};
|
||||
|
||||
if (pwdFieldOffset >= 0 && _weeniePhysicsObjOffset >= 0)
|
||||
|
|
@ -782,13 +860,44 @@ internal static class ClientObjectHooks
|
|||
/// <summary>
|
||||
/// Calls CBaseQualities::InqFloat on the object's weenie to read a STypeFloat property.
|
||||
/// AC stores these as doubles despite the "Float" name.
|
||||
/// Fast path: stype 280 (ITEM_WORKMANSHIP) is read from PublicWeenieDesc._workmanship
|
||||
/// (Single at PWD+152) because it lives in the weenie descriptor, not CBaseQualities,
|
||||
/// and InqFloat fails for pack/inventory items that have no m_pQualities pointer.
|
||||
/// </summary>
|
||||
public static unsafe bool TryGetObjectDoubleProperty(uint objectId, uint stype, out double value)
|
||||
{
|
||||
value = 0;
|
||||
if (_inqFloat == null || _getWeenieObject == null)
|
||||
if (_getWeenieObject == null)
|
||||
{
|
||||
if (!Probe() || _inqFloat == null || _getWeenieObject == null)
|
||||
if (!Probe() || _getWeenieObject == null)
|
||||
return false;
|
||||
}
|
||||
|
||||
// Fast path: ITEM_WORKMANSHIP (STypeFloat=280) → PublicWeenieDesc._workmanship (Single at PWD+152)
|
||||
if (stype == 280u && _weeniePhysicsObjOffset >= 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
IntPtr weeniePtr = _getWeenieObject(objectId);
|
||||
if (weeniePtr == IntPtr.Zero)
|
||||
return false;
|
||||
int pwdBase = _weeniePhysicsObjOffset + 4;
|
||||
IntPtr fieldAddr = weeniePtr + pwdBase + 152;
|
||||
if (!IsReadablePointer(fieldAddr))
|
||||
return false;
|
||||
int bits = Marshal.ReadInt32(fieldAddr);
|
||||
float f = BitConverter.Int32BitsToSingle(bits);
|
||||
if (f == 0f)
|
||||
return false;
|
||||
value = f;
|
||||
return true;
|
||||
}
|
||||
catch { return false; }
|
||||
}
|
||||
|
||||
if (_inqFloat == null)
|
||||
{
|
||||
if (!Probe() || _inqFloat == null)
|
||||
return false;
|
||||
}
|
||||
try
|
||||
|
|
@ -825,6 +934,12 @@ internal static class ClientObjectHooks
|
|||
public static unsafe bool TryGetObjectBoolProperty(uint objectId, uint stype, out bool value)
|
||||
{
|
||||
value = false;
|
||||
|
||||
// Appraisal cache covers inventory items where m_pQualities is null
|
||||
// (CBaseQualities::InqBool always returns 0 for such objects).
|
||||
if (AppraisalHooks.TryGetCachedBoolProperty(objectId, stype, out value))
|
||||
return true;
|
||||
|
||||
if (_inqBool == null || _getWeenieObject == null)
|
||||
{
|
||||
if (!Probe() || _inqBool == null || _getWeenieObject == null)
|
||||
|
|
|
|||
|
|
@ -19,9 +19,36 @@ internal static class CombatModeHooks
|
|||
private static string _statusMessage = "Not probed yet.";
|
||||
private static int _lastObservedCombatMode;
|
||||
|
||||
// ClientCombatSystem::s_pCombatSystem — pointer to the singleton in .data
|
||||
private const uint CombatSystemPtrVa = 0x0087166C;
|
||||
// Offset of combatMode (COMBAT_MODE) within ClientCombatSystem:
|
||||
// ClientSystem(8) + IInputActionCallback(4) + QualityChangeHandler(4)
|
||||
// + Turbine_RefCount(8) + jump_pending(1) + m_bTrackingTarget(1) + pad(2) = 28
|
||||
private const int CombatModeOffset = 28;
|
||||
|
||||
public static bool IsInstalled { get; private set; }
|
||||
public static string StatusMessage => _statusMessage;
|
||||
|
||||
/// <summary>
|
||||
/// Reads the current combat mode directly from ClientCombatSystem::combatMode.
|
||||
/// Returns NonCombat if the pointer is null or unreadable.
|
||||
/// </summary>
|
||||
public static unsafe int ReadCurrentCombatMode()
|
||||
{
|
||||
try
|
||||
{
|
||||
IntPtr combatSystem = *(IntPtr*)CombatSystemPtrVa;
|
||||
if (combatSystem == IntPtr.Zero)
|
||||
return CombatActionHooks.CombatModeNonCombat;
|
||||
int raw = *(int*)(combatSystem + CombatModeOffset);
|
||||
return NormalizeCombatMode(raw);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return CombatActionHooks.CombatModeNonCombat;
|
||||
}
|
||||
}
|
||||
|
||||
public static void Initialize()
|
||||
{
|
||||
if (IsInstalled)
|
||||
|
|
|
|||
100
src/RynthCore.Engine/Compatibility/SalvageHooks.cs
Normal file
100
src/RynthCore.Engine/Compatibility/SalvageHooks.cs
Normal file
|
|
@ -0,0 +1,100 @@
|
|||
// ============================================================================
|
||||
// RynthCore.Engine - Compatibility/SalvageHooks.cs
|
||||
//
|
||||
// Hooks gmSalvageUI::OpenSalvagePanel to capture the singleton 'this' pointer.
|
||||
// The captured instance is used by ClientHelperHooks for SalvagePanelAddItem
|
||||
// and SalvagePanelExecute, which call the thiscall instance methods directly.
|
||||
//
|
||||
// VA derivation (map_offset + 0x00401000 = live VA):
|
||||
// 000CAF70 gmSalvageUI::OpenSalvagePanel → 0x004CBF70
|
||||
// ============================================================================
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Threading;
|
||||
using RynthCore.Engine.Hooking;
|
||||
|
||||
namespace RynthCore.Engine.Compatibility;
|
||||
|
||||
internal static class SalvageHooks
|
||||
{
|
||||
// gmSalvageUI::OpenSalvagePanel(uint toolId) — thiscall
|
||||
// Map: 000CAF70 → live VA: 0x004CBF70
|
||||
private const int GmSalvageUIOpenSalvagePanelVa = 0x004CBF70;
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.ThisCall)]
|
||||
private delegate void GmSalvageUIOpenSalvagePanelDelegate(IntPtr thisPtr, uint toolId);
|
||||
|
||||
private static GmSalvageUIOpenSalvagePanelDelegate? _originalOpenSalvagePanel;
|
||||
private static GmSalvageUIOpenSalvagePanelDelegate? _openSalvagePanelDetour; // held alive to prevent GC
|
||||
private static IntPtr _gmSalvageUIInstance;
|
||||
private static bool _hookInstalled;
|
||||
private static string _statusMessage = "Not initialized.";
|
||||
|
||||
public static bool IsInstalled => _hookInstalled;
|
||||
public static string StatusMessage => _statusMessage;
|
||||
|
||||
/// <summary>
|
||||
/// The captured gmSalvageUI singleton. Zero until the salvage panel has been
|
||||
/// opened at least once (either by the player or by SalvagePanelOpen).
|
||||
/// </summary>
|
||||
public static IntPtr GmSalvageUIInstance => _gmSalvageUIInstance;
|
||||
|
||||
public static void Initialize()
|
||||
{
|
||||
if (_hookInstalled)
|
||||
return;
|
||||
|
||||
if (!AcClientModule.TryReadTextSection(out AcClientTextSection textSection))
|
||||
{
|
||||
_statusMessage = "acclient.exe not available.";
|
||||
return;
|
||||
}
|
||||
|
||||
int funcOff = GmSalvageUIOpenSalvagePanelVa - textSection.TextBaseVa;
|
||||
if (funcOff < 0 || funcOff >= textSection.Bytes.Length)
|
||||
{
|
||||
_statusMessage = $"gmSalvageUI::OpenSalvagePanel VA out of range @ 0x{GmSalvageUIOpenSalvagePanelVa:X8}.";
|
||||
RynthLog.Compat($"Compat: salvage hook failed - {_statusMessage}");
|
||||
return;
|
||||
}
|
||||
|
||||
byte firstByte = textSection.Bytes[funcOff];
|
||||
if (firstByte is 0x00 or 0xCC or 0xC3)
|
||||
{
|
||||
_statusMessage = $"gmSalvageUI::OpenSalvagePanel looks invalid @ 0x{GmSalvageUIOpenSalvagePanelVa:X8} (opcode 0x{firstByte:X2}).";
|
||||
RynthLog.Compat($"Compat: salvage hook failed - {_statusMessage}");
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
IntPtr targetAddress = new IntPtr(textSection.TextBaseVa + funcOff);
|
||||
_openSalvagePanelDetour = OpenSalvagePanelDetour;
|
||||
IntPtr detourPtr = Marshal.GetFunctionPointerForDelegate(_openSalvagePanelDetour);
|
||||
_originalOpenSalvagePanel = Marshal.GetDelegateForFunctionPointer<GmSalvageUIOpenSalvagePanelDelegate>(
|
||||
MinHook.HookCreate(targetAddress, detourPtr));
|
||||
Thread.MemoryBarrier();
|
||||
MinHook.Enable(targetAddress);
|
||||
|
||||
_hookInstalled = true;
|
||||
_statusMessage = $"Hooked gmSalvageUI::OpenSalvagePanel @ 0x{targetAddress.ToInt32():X8}.";
|
||||
RynthLog.Compat($"Compat: salvage hook ready @ 0x{targetAddress.ToInt32():X8}, firstByte=0x{firstByte:X2}");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_statusMessage = ex.Message;
|
||||
RynthLog.Compat($"Compat: salvage hook failed - {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
private static void OpenSalvagePanelDetour(IntPtr thisPtr, uint toolId)
|
||||
{
|
||||
// Capture the gmSalvageUI singleton on every open so it stays fresh
|
||||
// even across hot-reloads or UI recreation.
|
||||
if (thisPtr != IntPtr.Zero)
|
||||
_gmSalvageUIInstance = thisPtr;
|
||||
|
||||
_originalOpenSalvagePanel!(thisPtr, toolId);
|
||||
}
|
||||
}
|
||||
46
src/RynthCore.Engine/Compatibility/TeleportStateHooks.cs
Normal file
46
src/RynthCore.Engine/Compatibility/TeleportStateHooks.cs
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace RynthCore.Engine.Compatibility;
|
||||
|
||||
/// <summary>
|
||||
/// Reads portal/teleport state directly from CPlayerSystem::teleport_in_progress.
|
||||
///
|
||||
/// Ghidra analysis of CPlayerSystem::SetTeleportInProgress (0x0055E2A0):
|
||||
/// MOV AL, [ESP+4] ; bool arg
|
||||
/// MOV [ESI + 0x238], AL ; stored at this+0x238
|
||||
///
|
||||
/// So: isPortaling = *(CPlayerSystem + 0x238)
|
||||
/// PlayerSystem singleton pointer: 0x0087119C (PlayerSystemVa, already known)
|
||||
/// </summary>
|
||||
internal static class TeleportStateHooks
|
||||
{
|
||||
private const int PlayerSystemPtrVa = 0x0087119C;
|
||||
private const int TeleportInProgressOffset = 0x238;
|
||||
|
||||
public static bool IsInstalled => true; // no hook needed — direct memory read
|
||||
|
||||
/// <summary>Returns true while the player is in the teleport/portal transit state.</summary>
|
||||
public static unsafe bool IsPortaling
|
||||
{
|
||||
get
|
||||
{
|
||||
try
|
||||
{
|
||||
IntPtr playerSystem = *(IntPtr*)PlayerSystemPtrVa;
|
||||
if (playerSystem == IntPtr.Zero) return false;
|
||||
return *(byte*)(playerSystem + TeleportInProgressOffset) != 0;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Called from EntryPoint.Initialize chain — nothing to install for a direct read.
|
||||
public static void Initialize()
|
||||
{
|
||||
RynthLog.Compat($"Compat: teleport-state ready — direct read CPlayerSystem+0x238 @ PlayerSystemPtr=0x{PlayerSystemPtrVa:X8}");
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue