Initial commit

A modern .NET 9 NativeAOT framework for Asheron's Call client modding.
Self-contained injection system that hooks D3D9 EndScene to render an
ImGui overlay inside the AC client process.
This commit is contained in:
tombohar 2026-04-10 18:38:07 -04:00
commit 80b71d295d
179 changed files with 52858 additions and 0 deletions

View file

@ -0,0 +1,109 @@
using System;
namespace RynthCore.Engine.Compatibility;
internal static class PatternScanner
{
public static int FindPattern(byte[] data, byte[] pattern)
{
return FindPatternInRegion(data, pattern, 0, data.Length);
}
public static int FindPattern(byte[] data, byte?[] pattern)
{
return FindPatternInRegion(data, pattern, 0, data.Length);
}
public static int FindPatternInRegion(byte[] data, byte[] pattern, int start, int end)
{
int limit = Math.Min(end, data.Length) - pattern.Length;
for (int i = Math.Max(0, start); i <= limit; i++)
{
bool match = true;
for (int j = 0; j < pattern.Length; j++)
{
if (data[i + j] == pattern[j])
continue;
match = false;
break;
}
if (match)
return i;
}
return -1;
}
public static int FindPatternInRegion(byte[] data, byte?[] pattern, int start, int end)
{
int limit = Math.Min(end, data.Length) - pattern.Length;
for (int i = Math.Max(0, start); i <= limit; i++)
{
bool match = true;
for (int j = 0; j < pattern.Length; j++)
{
byte? expected = pattern[j];
if (expected.HasValue && data[i + j] != expected.Value)
{
match = false;
break;
}
}
if (match)
return i;
}
return -1;
}
public static int FindPrologueBefore(byte[] data, int opcodeOffset, byte[] prologue, int maxDistance = 300)
{
for (int back = 1; back < maxDistance; back++)
{
int pos = opcodeOffset - back;
if (pos < 1 || pos + prologue.Length > data.Length)
continue;
if (!VerifyBytes(data, pos, prologue))
continue;
byte prev = data[pos - 1];
if (prev == 0xCC || prev == 0x90 || prev == 0xC3)
return pos;
}
return -1;
}
public static bool VerifyBytes(byte[] data, int offset, byte[] expected)
{
if (offset < 0 || offset + expected.Length > data.Length)
return false;
for (int i = 0; i < expected.Length; i++)
{
if (data[offset + i] != expected[i])
return false;
}
return true;
}
public static bool VerifyPattern(byte[] data, int offset, byte?[] expected)
{
if (offset < 0 || offset + expected.Length > data.Length)
return false;
for (int i = 0; i < expected.Length; i++)
{
byte? value = expected[i];
if (value.HasValue && data[offset + i] != value.Value)
return false;
}
return true;
}
}