C#C
C#9mo ago
ero

Versioned API client architecture

Unfortunately the IPC implementation I made a post about a while back was completely useless as there is no IL2CPP API to get a class' static field data. So now I'm falling back to manual memory interop.

For this, I need to handle many different versions of both Mono and IL2CPP. I need to expose methods such as these;
nint GetMonoImage(string name);
nint GetMonoClass(nint pImage, uint typeToken);
nint GetMonoClass(nint pImage, string @namespace, string name);
nint GetMonoClassField(nint pClass, string name);
string GetFieldName(nint pField);
uint GetFieldOffset(nint pField);
nint GetFieldType(nint pField);
... (many more)

The implementation of these methods and internal details (like linked lists or hashmaps) frequently changes between the (~8) versions. The crux of the problem is that working with this API requires some initialization, which is also different between all versions.
I need a solution where I infer some basic information (Mono or IL2CPP), then run the code which fetches the initial data (some addresses, tokens) and finally return the correct class for the corresponding version.

I need to be very clear that I'm using .NET Standard 2.0; I don't have access to static abstract.

My initial naive idea was this:
interface IMonoApiInitializer; // like 2-3 methods
interface IIl2CppApiInitializer : IMonoApiInitializer; // maybe 1 or 2 more methods

class MonoInitializer10 // 1.0
  : IMonoApiInitializer;

class MonoInitializer11 // 1.1
  : MonoInitializer10;

class Il2CppInitializer180 // 18.0
  : IIl2CppApiInitializer;

class Il2CppInitializer240 // 24.0
  : Il2CppInitializer180;

interface IMonoInteroperator; // like 30-ish methods?

class MonoInterop10 // implements methods
  : IMonoInteroperator;

class MonoInitializer11 // overrides maybe 2 methods
  : MonoInitializer10;

class Il2CppInitializer180 // overrides something internal
  : MonoInitializer11; // <- !!!

class Il2CppInitializer240 // ...
  : Il2CppInitializer180;
Was this page helpful?