feat: port aelrynth 2026.9.27.2 snapshot onto GitHub history
Overlay upstream/main (9b5e276) onto BlankenshipG main without rewriting
history. Keep origin-only Decal/plugin/docs trees. Re-apply aelrynth.com
and sibling-fork URL fixes that aelrynth git still has as tombohar links.
Co-authored-by: BlankenshipG <BlankenshipG@users.noreply.github.com>
This commit is contained in:
parent
ac0d743e16
commit
4ddbb52eb2
244 changed files with 59710 additions and 3067 deletions
|
|
@ -25,20 +25,17 @@ internal static class ChatCallbackHooks
|
|||
private const bool EnableOutgoingHook = true;
|
||||
private static IncomingChatMode CurrentIncomingMode => IncomingChatMode.AddTextToScrollHostEat;
|
||||
|
||||
private static readonly byte[] IncomingChatAddTextToScrollSignature =
|
||||
// Verified unique + lands at 0x005649F0 offline (tools/pe_pattern.py).
|
||||
private static readonly byte?[] IncomingChatAddTextToScrollPattern =
|
||||
[
|
||||
0x81, 0xEC, 0x48, 0x09, 0x00, 0x00, 0x8A, 0x84,
|
||||
0x24, 0x54, 0x09, 0x00, 0x00, 0x53, 0x55, 0x56,
|
||||
0x33, 0xF6, 0x84, 0xC0, 0x57, 0x8B, 0xBC, 0x24,
|
||||
0x5C, 0x09, 0x00, 0x00, 0x89, 0x4C, 0x24, 0x24
|
||||
0x81, 0xEC, 0x48, 0x09, 0x00, 0x00, 0x8A, 0x84
|
||||
];
|
||||
|
||||
private static readonly byte[] IncomingChatWrapperSignature =
|
||||
// Verified unique + lands at 0x0058A000 offline (tools/pe_pattern.py).
|
||||
private static readonly byte?[] IncomingChatWrapperPattern =
|
||||
[
|
||||
0xA1, 0xE4, 0x0B, 0x87, 0x00, 0x85, 0xC0, 0x75,
|
||||
0x06, 0xB8, 0x01, 0x00, 0x00, 0x00, 0xC3, 0x56,
|
||||
0x8B, 0x74, 0x24, 0x10, 0x83, 0xFE, 0x01, 0x74,
|
||||
0x0F
|
||||
0x06, 0xB8, 0x01, 0x00, 0x00, 0x00, 0xC3, 0x56
|
||||
];
|
||||
|
||||
private static readonly byte?[] OutgoingChatPattern =
|
||||
|
|
@ -73,6 +70,15 @@ internal static class ChatCallbackHooks
|
|||
private static int _incomingChatSuppressionEnabled;
|
||||
private static int _incomingCallCount;
|
||||
|
||||
// Captured live from the outgoing-chat detour so we can re-invoke AC's outgoing
|
||||
// chat function DIRECTLY (deterministic) instead of simulating keystrokes into
|
||||
// the native chat bar. Keystroke simulation depends on the bar's open/closed
|
||||
// state, which the first simulated send corrupts — so the second send silently
|
||||
// fails to submit ("works once, then stops"). Calling the function directly has
|
||||
// no chat-bar state and is fully repeatable.
|
||||
private static IntPtr _lastOutgoingThis;
|
||||
private static uint _lastOutgoingSource = 8;
|
||||
|
||||
public static bool IncomingInstalled { get; private set; }
|
||||
public static bool OutgoingInstalled { get; private set; }
|
||||
public static bool IsInstalled => (!EnableIncomingHook || IncomingInstalled) && (!EnableOutgoingHook || OutgoingInstalled);
|
||||
|
|
@ -189,17 +195,17 @@ internal static class ChatCallbackHooks
|
|||
|
||||
private static bool TryInstallIncomingWrapperHook(AcClientTextSection textSection, out string incomingStatus)
|
||||
{
|
||||
int incomingOff = IncomingChatWrapperVa - textSection.TextBaseVa;
|
||||
if (!PatternScanner.VerifyBytes(textSection.Bytes, incomingOff, IncomingChatWrapperSignature))
|
||||
HookResolver.ResolveResult resolved = HookResolver.Resolve(textSection, "ChatCallback.IncomingChatWrapper", IncomingChatWrapperPattern, IncomingChatWrapperVa);
|
||||
if (!resolved.Success)
|
||||
{
|
||||
incomingStatus = $"signature mismatch @ 0x{IncomingChatWrapperVa:X8}";
|
||||
incomingStatus = $"unresolved (VA 0x{IncomingChatWrapperVa:X8})";
|
||||
RynthLog.Compat($"Compat: incoming chat hook unavailable - {incomingStatus}");
|
||||
return false;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
_incomingAddress = new IntPtr(textSection.TextBaseVa + incomingOff);
|
||||
_incomingAddress = resolved.Address;
|
||||
_incomingChatWrapperDetour = IncomingChatWrapperDetour;
|
||||
IntPtr incomingPtr = Marshal.GetFunctionPointerForDelegate(_incomingChatWrapperDetour);
|
||||
_originalIncomingChatWrapper = Marshal.GetDelegateForFunctionPointer<IncomingChatWrapperDelegate>(MinHook.HookCreate(_incomingAddress, incomingPtr));
|
||||
|
|
@ -218,10 +224,10 @@ internal static class ChatCallbackHooks
|
|||
|
||||
private static bool TryInstallIncomingAddTextHook(AcClientTextSection textSection, out string incomingStatus)
|
||||
{
|
||||
int incomingOff = IncomingChatAddTextToScrollVa - textSection.TextBaseVa;
|
||||
if (!PatternScanner.VerifyBytes(textSection.Bytes, incomingOff, IncomingChatAddTextToScrollSignature))
|
||||
HookResolver.ResolveResult resolved = HookResolver.Resolve(textSection, "ChatCallback.IncomingChatAddTextToScroll", IncomingChatAddTextToScrollPattern, IncomingChatAddTextToScrollVa);
|
||||
if (!resolved.Success)
|
||||
{
|
||||
incomingStatus = $"signature mismatch @ 0x{IncomingChatAddTextToScrollVa:X8}";
|
||||
incomingStatus = $"unresolved (VA 0x{IncomingChatAddTextToScrollVa:X8})";
|
||||
RynthLog.Compat($"Compat: incoming chat hook unavailable - {incomingStatus}");
|
||||
return false;
|
||||
}
|
||||
|
|
@ -230,7 +236,7 @@ internal static class ChatCallbackHooks
|
|||
{
|
||||
unsafe
|
||||
{
|
||||
_incomingAddress = new IntPtr(textSection.TextBaseVa + incomingOff);
|
||||
_incomingAddress = resolved.Address;
|
||||
delegate* unmanaged[Thiscall]<IntPtr, IntPtr, uint, uint, IntPtr, int> pDetour = &IncomingChatAddTextDetour;
|
||||
MinHook.Hook(_incomingAddress, (IntPtr)pDetour, out _originalIncomingChatAddTextPtr);
|
||||
}
|
||||
|
|
@ -247,6 +253,7 @@ internal static class ChatCallbackHooks
|
|||
|
||||
private static int IncomingChatWrapperDetour(int flags, IntPtr text, int chatChannel)
|
||||
{
|
||||
RecursionGuard.Tick("ChatCallbackHooks.IncomingChatWrapper");
|
||||
try
|
||||
{
|
||||
return CurrentIncomingMode switch
|
||||
|
|
@ -269,6 +276,7 @@ internal static class ChatCallbackHooks
|
|||
[UnmanagedCallersOnly(CallConvs = new[] { typeof(CallConvThiscall) })]
|
||||
private static unsafe int IncomingChatAddTextDetour(IntPtr thisPtr, IntPtr text, uint chatType, uint unknown, IntPtr stringInfo)
|
||||
{
|
||||
RecursionGuard.Tick("ChatCallbackHooks.IncomingChatAddText");
|
||||
// 1. Read string BEFORE original — buffer may be freed after
|
||||
string? line = (text != IntPtr.Zero) ? ReadIncomingChatLine(text, chatType) : null;
|
||||
|
||||
|
|
@ -326,9 +334,25 @@ internal static class ChatCallbackHooks
|
|||
|
||||
private static int OutgoingChatDetour(IntPtr thisPtr, IntPtr text, uint commandSource)
|
||||
{
|
||||
RecursionGuard.Tick("ChatCallbackHooks.OutgoingChat");
|
||||
try
|
||||
{
|
||||
string? line = ReadWidePString(text);
|
||||
LogoffOriginProbe.RecordChat($"AC OutgoingChat src={commandSource}", line);
|
||||
|
||||
// Capture the chat-manager 'this' + command source from the live submit
|
||||
// so ChatCommandDispatcher can re-invoke this function directly later.
|
||||
if (thisPtr != IntPtr.Zero)
|
||||
{
|
||||
_lastOutgoingThis = thisPtr;
|
||||
_lastOutgoingSource = commandSource;
|
||||
}
|
||||
|
||||
// RynthCore engine commands (/rc ...) — consume before plugins or
|
||||
// AC see the line so the user never broadcasts "/rc resetbar" and
|
||||
// a hidden overlay bar stays recoverable.
|
||||
if (RynthCoreChatCommands.TryHandle(line))
|
||||
return 1;
|
||||
|
||||
if (PluginManager.DispatchChatBarEnter(line))
|
||||
return 1;
|
||||
|
|
@ -514,4 +538,114 @@ internal static class ChatCallbackHooks
|
|||
{
|
||||
return opcode is 0xE9 or 0xE8 or 0xEB or 0x68 or 0xFF;
|
||||
}
|
||||
|
||||
/// <summary>True once a chat-manager 'this' has been captured from a live submit.</summary>
|
||||
public static bool CanDispatchDirect =>
|
||||
OutgoingInstalled && _originalOutgoingChat != null && _lastOutgoingThis != IntPtr.Zero;
|
||||
|
||||
/// <summary>
|
||||
/// Dispatches a chat line by calling AC's outgoing-chat function directly — the
|
||||
/// same path AC takes when you press Enter on the native chat bar, but with no
|
||||
/// keystroke simulation and no chat-bar state, so it is repeatable. Uses the
|
||||
/// 'this' + command source captured by <see cref="OutgoingChatDetour"/> from a
|
||||
/// prior real submit. Returns false if the hook isn't installed or no 'this' has
|
||||
/// been captured yet — the caller then falls back to keystroke simulation, whose
|
||||
/// first successful send seeds the capture for all subsequent calls.
|
||||
/// Plugin pre-dispatch / engine-command handling is the caller's responsibility
|
||||
/// (already done in ChatCommandDispatcher.Dispatch), so this goes straight to AC.
|
||||
/// </summary>
|
||||
public static unsafe bool TryDispatchDirect(string? text)
|
||||
{
|
||||
if (!OutgoingInstalled || _originalOutgoingChat == null)
|
||||
return false;
|
||||
|
||||
IntPtr self = _lastOutgoingThis;
|
||||
if (self == IntPtr.Zero || string.IsNullOrWhiteSpace(text))
|
||||
return false;
|
||||
|
||||
string line = text!.TrimEnd('\r', '\n');
|
||||
if (line.Length == 0)
|
||||
return false;
|
||||
foreach (char c in line)
|
||||
if (c < 0x20 && c != '\t')
|
||||
return false; // never feed AC control chars
|
||||
LogoffOriginProbe.RecordChat("OutgoingChat direct", line);
|
||||
|
||||
try
|
||||
{
|
||||
ushort[] chars = new ushort[line.Length + 1]; // +1 null terminator (wcslen)
|
||||
for (int i = 0; i < line.Length; i++)
|
||||
chars[i] = line[i];
|
||||
|
||||
var wide = OutgoingWidePString.Create(chars);
|
||||
try
|
||||
{
|
||||
// 'wide' is a stack local (unmanaged struct) — its address is stable
|
||||
// for the synchronous call, so no 'fixed' pin is needed (or allowed).
|
||||
_originalOutgoingChat(self, (IntPtr)(&wide), _lastOutgoingSource);
|
||||
return true;
|
||||
}
|
||||
finally { wide.Dispose(); }
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
RynthLog.Compat($"OutgoingChat direct failed: {ex.GetType().Name}: {ex.Message}");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clears the cached chat-manager 'this'. Called on logout: AC frees the object
|
||||
/// during the world→charselect transition, so the stale pointer must not be
|
||||
/// reused. It is re-captured from the next real submit after the next login.
|
||||
/// </summary>
|
||||
public static void ResetOutgoingTarget()
|
||||
{
|
||||
_lastOutgoingThis = IntPtr.Zero;
|
||||
}
|
||||
|
||||
// Minimal duplicate of ClientHelperHooks.WidePString (AC1Legacy::PStringBase<wchar_t>).
|
||||
// Duplicated deliberately so the actively-used WriteToChat path stays untouched.
|
||||
// Phase B / 1a-dup: resolve the PStringBase<wchar_t> ctor/dtor (fn VAs) by pattern and the
|
||||
// s_NullBuffer (data VA) by code-xref. These were duplicate raw VAs left by 1a's per-file pass.
|
||||
private static readonly byte?[] PatWidePStringCtor = [ 0x56, 0x57, 0x8B, 0x7C, 0x24, 0x0C, 0x85, 0xFF, 0x8B, 0xF1, 0x74, 0x2C ];
|
||||
private static readonly byte?[] PatWidePStringDtor = [ 0x56, 0x8B, 0x31, 0x83, 0xEE, 0x14, 0x8D, 0x46 ];
|
||||
private static readonly byte?[] PatXrefWideNullBuffer = [ 0x3B, 0x05, null, null, null, null, 0x74, 0xE7 ];
|
||||
private static unsafe void* ResolveFnVa(string name, byte?[] pattern, int fallbackVa)
|
||||
{
|
||||
if (!AcClientModule.TryReadTextSection(out AcClientTextSection text)) return (void*)fallbackVa;
|
||||
HookResolver.ResolveResult r = HookResolver.Resolve(text, name, pattern, fallbackVa);
|
||||
return (void*)(r.Success ? r.Address : new IntPtr(fallbackVa));
|
||||
}
|
||||
private static IntPtr ResolveDataVa(string name, byte?[] pattern, int operandOffset, int fallbackVa)
|
||||
{
|
||||
if (!AcClientModule.TryReadTextSection(out AcClientTextSection text)) return new IntPtr(fallbackVa);
|
||||
return HookResolver.ResolveData(text, name, pattern, operandOffset, fallbackVa).Address;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
private unsafe struct OutgoingWidePString
|
||||
{
|
||||
private static readonly IntPtr NullWideBufferVa = ResolveDataVa("ChatCallback.PStringW_NullBuffer", PatXrefWideNullBuffer, 2, 0x00818340);
|
||||
private static readonly delegate* unmanaged[Thiscall]<OutgoingWidePString*, ushort*, void> Ctor =
|
||||
(delegate* unmanaged[Thiscall]<OutgoingWidePString*, ushort*, void>)ResolveFnVa("ChatCallback.PStringW_ctor", PatWidePStringCtor, 0x00402730);
|
||||
private static readonly delegate* unmanaged[Thiscall]<OutgoingWidePString*, void> Dtor =
|
||||
(delegate* unmanaged[Thiscall]<OutgoingWidePString*, void>)ResolveFnVa("ChatCallback.PStringW_dtor", PatWidePStringDtor, 0x004011B0);
|
||||
|
||||
public IntPtr CharBuffer;
|
||||
|
||||
public static OutgoingWidePString Create(ushort[] chars)
|
||||
{
|
||||
var value = new OutgoingWidePString { CharBuffer = Marshal.ReadIntPtr(NullWideBufferVa) };
|
||||
fixed (ushort* pChars = chars)
|
||||
Ctor(&value, pChars);
|
||||
return value;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
fixed (OutgoingWidePString* ptr = &this)
|
||||
Dtor(ptr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue