RynthCore as of 2026-10-04 (internal 843c801): RynthNav auto-travel and the navigation map, plugin API v75 (server and titles), launcher with Available plugins, download progress and the update on the front page, opt-in usage statistics, NPC names, radar colours, title-bar text size, FPS limiter, client action unlocks, release 2026.10.4.6
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
9b5e2765b7
commit
a24ed6df7c
322 changed files with 83009 additions and 7504 deletions
216
spikes/CoreClrHost/native/SpikeHost.c
Normal file
216
spikes/CoreClrHost/native/SpikeHost.c
Normal file
|
|
@ -0,0 +1,216 @@
|
|||
// SpikeHost: Phase 0 spike for docs/UNLOADABLE_ENGINE_PLAN.md.
|
||||
//
|
||||
// Starts an app-local CoreCLR (x86) through the raw coreclr_* hosting API, loads
|
||||
// Shim.dll into the default ALC and calls Shim.Entry.Run, which loads Payload.dll
|
||||
// into a collectible ALC N times, calls into it from native code, unloads it and
|
||||
// measures free address space through the HostApi below.
|
||||
//
|
||||
// Built as a DLL (SpikeHost.dll, export SpikeRun) so the same code can be injected
|
||||
// into acclient; SpikeHostExe.exe is a console driver that LoadLibrary's it.
|
||||
|
||||
#include <windows.h>
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
typedef int (__stdcall *coreclr_initialize_fn)(const char* exePath, const char* appDomainFriendlyName,
|
||||
int propertyCount, const char** propertyKeys, const char** propertyValues,
|
||||
void** hostHandle, unsigned int* domainId);
|
||||
typedef int (__stdcall *coreclr_create_delegate_fn)(void* hostHandle, unsigned int domainId,
|
||||
const char* assemblyName, const char* typeName, const char* methodName, void** fn);
|
||||
|
||||
typedef struct HostApi {
|
||||
int size;
|
||||
double (__stdcall *freeMb)(double* largestFreeMb);
|
||||
void (__stdcall *log)(const char* utf8);
|
||||
int (__stdcall *callBinary)(void* fn, int a, int b); // native frame -> managed fn pointer
|
||||
unsigned int (__stdcall *committedMb)(void);
|
||||
} HostApi;
|
||||
|
||||
typedef int (__stdcall *shim_run_fn)(HostApi* api, int cycles, int mode);
|
||||
|
||||
static char g_dir[MAX_PATH];
|
||||
static FILE* g_log;
|
||||
|
||||
static void LogLine(const char* fmt, ...)
|
||||
{
|
||||
char buf[2048];
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
_vsnprintf_s(buf, sizeof buf, _TRUNCATE, fmt, ap);
|
||||
va_end(ap);
|
||||
SYSTEMTIME t;
|
||||
GetLocalTime(&t);
|
||||
char line[2200];
|
||||
_snprintf_s(line, sizeof line, _TRUNCATE, "[%02d:%02d:%02d.%03d] [pid:%lu] %s\n",
|
||||
t.wHour, t.wMinute, t.wSecond, t.wMilliseconds, GetCurrentProcessId(), buf);
|
||||
fputs(line, stdout);
|
||||
fflush(stdout);
|
||||
if (g_log) { fputs(line, g_log); fflush(g_log); }
|
||||
OutputDebugStringA(line);
|
||||
}
|
||||
|
||||
static double __stdcall FreeMb(double* largestFreeMb)
|
||||
{
|
||||
SYSTEM_INFO si;
|
||||
GetSystemInfo(&si);
|
||||
unsigned char* p = (unsigned char*)si.lpMinimumApplicationAddress;
|
||||
unsigned char* end = (unsigned char*)si.lpMaximumApplicationAddress;
|
||||
unsigned long long total = 0, largest = 0;
|
||||
MEMORY_BASIC_INFORMATION mbi;
|
||||
while (p < end && VirtualQuery(p, &mbi, sizeof mbi) == sizeof mbi) {
|
||||
if (mbi.State == MEM_FREE) {
|
||||
total += mbi.RegionSize;
|
||||
if (mbi.RegionSize > largest) largest = mbi.RegionSize;
|
||||
}
|
||||
p = (unsigned char*)mbi.BaseAddress + mbi.RegionSize;
|
||||
}
|
||||
if (largestFreeMb) *largestFreeMb = largest / (1024.0 * 1024.0);
|
||||
return total / (1024.0 * 1024.0);
|
||||
}
|
||||
|
||||
static unsigned int __stdcall CommittedMb(void)
|
||||
{
|
||||
SYSTEM_INFO si;
|
||||
GetSystemInfo(&si);
|
||||
unsigned char* p = (unsigned char*)si.lpMinimumApplicationAddress;
|
||||
unsigned char* end = (unsigned char*)si.lpMaximumApplicationAddress;
|
||||
unsigned long long total = 0;
|
||||
MEMORY_BASIC_INFORMATION mbi;
|
||||
while (p < end && VirtualQuery(p, &mbi, sizeof mbi) == sizeof mbi) {
|
||||
if (mbi.State == MEM_COMMIT && mbi.Type == MEM_PRIVATE) total += mbi.RegionSize;
|
||||
p = (unsigned char*)mbi.BaseAddress + mbi.RegionSize;
|
||||
}
|
||||
return (unsigned int)(total / (1024 * 1024));
|
||||
}
|
||||
|
||||
static void __stdcall ManagedLog(const char* utf8) { LogLine("[shim] %s", utf8); }
|
||||
|
||||
static int __stdcall CallBinary(void* fn, int a, int b)
|
||||
{
|
||||
typedef int (__stdcall *bin_fn)(int, int);
|
||||
return ((bin_fn)fn)(a, b);
|
||||
}
|
||||
|
||||
// Appends every *.dll in dir to the ';'-separated TPA list.
|
||||
static void AppendDlls(char* tpa, size_t cap, const char* dir)
|
||||
{
|
||||
char pattern[MAX_PATH];
|
||||
_snprintf_s(pattern, sizeof pattern, _TRUNCATE, "%s\\*.dll", dir);
|
||||
WIN32_FIND_DATAA fd;
|
||||
HANDLE h = FindFirstFileA(pattern, &fd);
|
||||
if (h == INVALID_HANDLE_VALUE) return;
|
||||
do {
|
||||
// Native runtime DLLs sit in the same folder; skip what isn't managed.
|
||||
const char* n = fd.cFileName;
|
||||
if (!_stricmp(n, "coreclr.dll") || !_stricmp(n, "clrjit.dll") || !_stricmp(n, "clrgc.dll") ||
|
||||
!_stricmp(n, "hostfxr.dll") || !_stricmp(n, "hostpolicy.dll") || !_stricmp(n, "mscordaccore.dll") ||
|
||||
!_stricmp(n, "mscordbi.dll") || !_stricmp(n, "mscorrc.dll") || !_stricmp(n, "clretwrc.dll") ||
|
||||
!_strnicmp(n, "mscordaccore_", 13) || !_stricmp(n, "msquic.dll") ||
|
||||
!_stricmp(n, "System.IO.Compression.Native.dll") || !_stricmp(n, "Microsoft.DiaSymReader.Native.x86.dll") ||
|
||||
!_stricmp(n, "SpikeHost.dll"))
|
||||
continue;
|
||||
strcat_s(tpa, cap, dir);
|
||||
strcat_s(tpa, cap, "\\");
|
||||
strcat_s(tpa, cap, n);
|
||||
strcat_s(tpa, cap, ";");
|
||||
} while (FindNextFileA(h, &fd));
|
||||
FindClose(h);
|
||||
}
|
||||
|
||||
__declspec(dllexport) int __stdcall SpikeRun(int cycles, int mode)
|
||||
{
|
||||
HMODULE self;
|
||||
GetModuleHandleExA(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
|
||||
(LPCSTR)&SpikeRun, &self);
|
||||
GetModuleFileNameA(self, g_dir, MAX_PATH);
|
||||
*strrchr(g_dir, '\\') = 0;
|
||||
|
||||
char logPath[MAX_PATH];
|
||||
_snprintf_s(logPath, sizeof logPath, _TRUNCATE, "%s\\spike.%lu.log", g_dir, GetCurrentProcessId());
|
||||
fopen_s(&g_log, logPath, "a");
|
||||
|
||||
double largest;
|
||||
double free0 = FreeMb(&largest);
|
||||
LogLine("host: start, free %.0f MB (largest %.0f), private commit %u MB", free0, largest, CommittedMb());
|
||||
|
||||
char runtimeDir[MAX_PATH], coreclrPath[MAX_PATH];
|
||||
_snprintf_s(runtimeDir, sizeof runtimeDir, _TRUNCATE, "%s\\runtime", g_dir);
|
||||
_snprintf_s(coreclrPath, sizeof coreclrPath, _TRUNCATE, "%s\\coreclr.dll", runtimeDir);
|
||||
|
||||
DWORD t0 = GetTickCount();
|
||||
HMODULE clr = LoadLibraryExA(coreclrPath, NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
|
||||
if (!clr) { LogLine("host: LoadLibrary coreclr failed %lu", GetLastError()); return -1; }
|
||||
coreclr_initialize_fn init = (coreclr_initialize_fn)GetProcAddress(clr, "coreclr_initialize");
|
||||
coreclr_create_delegate_fn create = (coreclr_create_delegate_fn)GetProcAddress(clr, "coreclr_create_delegate");
|
||||
if (!init || !create) { LogLine("host: coreclr exports missing"); return -2; }
|
||||
|
||||
static char tpa[64 * 1024];
|
||||
tpa[0] = 0;
|
||||
AppendDlls(tpa, sizeof tpa, runtimeDir);
|
||||
AppendDlls(tpa, sizeof tpa, g_dir); // Shim.dll + Contracts.dll (default ALC)
|
||||
|
||||
// Mode bit 0x200: concurrent (background) GC on.
|
||||
const char* keys[] = {
|
||||
"TRUSTED_PLATFORM_ASSEMBLIES", "APP_PATHS", "NATIVE_DLL_SEARCH_DIRECTORIES",
|
||||
"System.GC.Server", "System.GC.Concurrent", "System.Globalization.Invariant",
|
||||
"System.GC.RetainVM",
|
||||
};
|
||||
char nativeDirs[2 * MAX_PATH + 4];
|
||||
_snprintf_s(nativeDirs, sizeof nativeDirs, _TRUNCATE, "%s;%s;", runtimeDir, g_dir);
|
||||
const char* values[] = {
|
||||
tpa, "", nativeDirs,
|
||||
"false", (mode & 0x200) ? "true" : "false", "true",
|
||||
"false",
|
||||
};
|
||||
int count = sizeof keys / sizeof keys[0];
|
||||
|
||||
char exePath[MAX_PATH];
|
||||
GetModuleFileNameA(NULL, exePath, MAX_PATH);
|
||||
void* hostHandle = NULL;
|
||||
unsigned int domainId = 0;
|
||||
int hr = init(exePath, "RynthCoreSpike", count, keys, values, &hostHandle, &domainId);
|
||||
if (hr < 0) { LogLine("host: coreclr_initialize failed 0x%08x", hr); return -3; }
|
||||
LogLine("host: CoreCLR up in %lu ms, free %.0f MB (cost %.0f MB), private commit %u MB",
|
||||
GetTickCount() - t0, FreeMb(&largest), free0 - FreeMb(NULL), CommittedMb());
|
||||
|
||||
shim_run_fn run = NULL;
|
||||
hr = create(hostHandle, domainId, "Shim", "Shim.Entry", "Run", (void**)&run);
|
||||
if (hr < 0 || !run) { LogLine("host: create_delegate Shim.Entry.Run failed 0x%08x", hr); return -4; }
|
||||
|
||||
static HostApi api;
|
||||
api.size = sizeof api;
|
||||
api.freeMb = FreeMb;
|
||||
api.log = ManagedLog;
|
||||
api.callBinary = CallBinary;
|
||||
api.committedMb = CommittedMb;
|
||||
int rc = run(&api, cycles, mode);
|
||||
LogLine("host: Shim.Run returned %d, free %.0f MB (largest %.0f)", rc, FreeMb(&largest), largest);
|
||||
if (g_log) { fclose(g_log); g_log = NULL; }
|
||||
return rc;
|
||||
}
|
||||
|
||||
// Injected use: RYNTH_SPIKE_AUTORUN="cycles,mode,delayMs" in the target's environment
|
||||
// makes DllMain start a worker (no CLR work under the loader lock).
|
||||
static int g_autoCycles = 20, g_autoMode = 0, g_autoDelay = 3000;
|
||||
|
||||
static DWORD WINAPI AutoRun(LPVOID p)
|
||||
{
|
||||
(void)p;
|
||||
Sleep(g_autoDelay);
|
||||
SpikeRun(g_autoCycles, g_autoMode);
|
||||
return 0;
|
||||
}
|
||||
|
||||
BOOL WINAPI DllMain(HINSTANCE h, DWORD reason, LPVOID reserved)
|
||||
{
|
||||
(void)h; (void)reserved;
|
||||
if (reason == DLL_PROCESS_ATTACH) {
|
||||
char v[64];
|
||||
if (GetEnvironmentVariableA("RYNTH_SPIKE_AUTORUN", v, sizeof v) > 0) {
|
||||
sscanf_s(v, "%d,%i,%d", &g_autoCycles, &g_autoMode, &g_autoDelay);
|
||||
HANDLE t = CreateThread(NULL, 0, AutoRun, NULL, 0, NULL);
|
||||
if (t) CloseHandle(t);
|
||||
}
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
19
spikes/CoreClrHost/native/SpikeHostExe.c
Normal file
19
spikes/CoreClrHost/native/SpikeHostExe.c
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
// Console driver: SpikeHostExe.exe [cycles] [mode]. LoadLibrary's SpikeHost.dll the
|
||||
// way an injected loader would and calls SpikeRun.
|
||||
#include <windows.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
typedef int (__stdcall *spike_run_fn)(int cycles, int mode);
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
int cycles = argc > 1 ? atoi(argv[1]) : 20;
|
||||
int mode = argc > 2 ? (int)strtol(argv[2], NULL, 0) : 0;
|
||||
HMODULE h = LoadLibraryA("SpikeHost.dll");
|
||||
if (!h) { printf("LoadLibrary SpikeHost.dll failed %lu\n", GetLastError()); return 1; }
|
||||
spike_run_fn run = (spike_run_fn)GetProcAddress(h, "_SpikeRun@8");
|
||||
if (!run) run = (spike_run_fn)GetProcAddress(h, "SpikeRun");
|
||||
if (!run) { printf("SpikeRun export missing\n"); return 2; }
|
||||
return run(cycles, mode);
|
||||
}
|
||||
53
spikes/CoreClrHost/native/SpikeInject.c
Normal file
53
spikes/CoreClrHost/native/SpikeInject.c
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
// SpikeInject: starts acclient.exe suspended, LoadLibrary's SpikeHost.dll into it with
|
||||
// RYNTH_SPIKE_AUTORUN set, resumes it, waits, then terminates it.
|
||||
// SpikeInject.exe <acclient.exe> <SpikeHost.dll> <cycles,mode,delayMs> <waitSeconds> [acclient args...]
|
||||
#include <windows.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
if (argc < 5) { printf("usage: SpikeInject <acclient.exe> <SpikeHost.dll> <cycles,mode,delayMs> <waitSeconds> [args]\n"); return 1; }
|
||||
const char* exe = argv[1];
|
||||
const char* dll = argv[2];
|
||||
int waitSeconds = atoi(argv[4]);
|
||||
SetEnvironmentVariableA("RYNTH_SPIKE_AUTORUN", argv[3]);
|
||||
|
||||
char cmd[4096];
|
||||
_snprintf_s(cmd, sizeof cmd, _TRUNCATE, "\"%s\"", exe);
|
||||
for (int i = 5; i < argc; i++) { strcat_s(cmd, sizeof cmd, " "); strcat_s(cmd, sizeof cmd, argv[i]); }
|
||||
char dir[MAX_PATH];
|
||||
strcpy_s(dir, sizeof dir, exe);
|
||||
*strrchr(dir, '\\') = 0;
|
||||
|
||||
STARTUPINFOA si = { sizeof si };
|
||||
PROCESS_INFORMATION pi;
|
||||
if (!CreateProcessA(exe, cmd, NULL, NULL, FALSE, CREATE_SUSPENDED, NULL, dir, &si, &pi)) {
|
||||
printf("CreateProcess failed %lu\n", GetLastError()); return 2;
|
||||
}
|
||||
printf("SPIKE_PID=%lu\n", pi.dwProcessId);
|
||||
|
||||
size_t len = strlen(dll) + 1;
|
||||
void* remote = VirtualAllocEx(pi.hProcess, NULL, len, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
|
||||
WriteProcessMemory(pi.hProcess, remote, dll, len, NULL);
|
||||
FARPROC loadLib = GetProcAddress(GetModuleHandleA("kernel32.dll"), "LoadLibraryA");
|
||||
HANDLE t = CreateRemoteThread(pi.hProcess, NULL, 0, (LPTHREAD_START_ROUTINE)loadLib, remote, 0, NULL);
|
||||
if (!t) { printf("CreateRemoteThread failed %lu\n", GetLastError()); TerminateProcess(pi.hProcess, 1); return 3; }
|
||||
WaitForSingleObject(t, 30000);
|
||||
DWORD mod = 0;
|
||||
GetExitCodeThread(t, &mod);
|
||||
printf("LoadLibrary in target -> 0x%08lx\n", mod);
|
||||
CloseHandle(t);
|
||||
ResumeThread(pi.hThread);
|
||||
|
||||
DWORD r = WaitForSingleObject(pi.hProcess, waitSeconds * 1000);
|
||||
if (r == WAIT_OBJECT_0) {
|
||||
DWORD code = 0;
|
||||
GetExitCodeProcess(pi.hProcess, &code);
|
||||
printf("acclient exited by itself, code 0x%08lx\n", code);
|
||||
} else {
|
||||
TerminateProcess(pi.hProcess, 0);
|
||||
printf("acclient terminated after %d s\n", waitSeconds);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
Loading…
Reference in a new issue