InjectLib
Dauda wants to inject things
About this mod Author’s original text
Features
- Inject Custom Fields to Il2Cpp type
- Inject Custom Json fields to Il2Cpp type
Referencing to your plugin
[BepInDependency("GTFO.InjectLib", BepInDependency.DependencyFlags.HardDependency)]
$(GameFolder)\BepInEx\cache
Inject Fields
- Feature to extends il2cpp domain types and inject your own data to it!
//Defining Field is reqired in order to set/get data
FieldInjector.DefineValueField(string fieldName);
FieldInjector.DefineManagedField(string fieldName);
//Set data
bool FieldInjector.TrySetValueField(Il2CppType obj, string fieldName, UnmanagedType value);
bool FieldInjector.TrySetManagedField(Il2CppType obj, string fieldName, ManagedType value);
//Load Saved data
bool FieldInjector.TryGetValueField(Il2CppType obj, string fieldName, out UnmanagedType value);
bool FieldInjector.TryGetManagedField(Il2CppType obj, string fieldName, out ManagedType value);
Inject Custom Jsons to existing il2cpp type (base game json)
//SetConverter alter the whole json parse behaviour
//Useful if you want to fully alter the content of json
JsonInjector.SetConverter(Il2CppJsonReferenceTypeConverter converter);
JsonInjector.SetConverter(Il2CppJsonUnmanagedTypeConverter converter); //Type must be defined on il2cpp domain!!!
//AddHandler is similar to Harmony Postfix without out ref __result param
//You only can get JToken of parsed json and result object
//So you could inject your own field using FieldInjector
JsonInjector.AddHandler(Il2CppJsonReferenceTypeHandler handler);
JsonInjector.AddHandler(Il2CppJsonUnmanagedTypeHandler handler);
public abstract class Il2CppJsonReferenceTypeConverter: INativeJsonConverter where T: Il2CppObjectBase
{
protected abstract T Read(JToken jToken, T existingValue, JsonSerializer serializer);
protected abstract void Write(JsonWriter writer, T value, JsonSerializer serializer);
}
public abstract class Il2CppJsonUnmanagedTypeConverter: INativeJsonConverter where T: unmanaged
{
protected abstract T Read(JToken jToken, T existingValue, JsonSerializer serializer);
protected abstract void Write(JsonWriter writer, T value, JsonSerializer serializer);
protected abstract Il2CppSystem.Object ToIl2CppObject(T value);
}
public abstract class Il2CppJsonReferenceTypeHandler: INativeJsonHandler where T: Il2CppObjectBase
{
public abstract void OnRead(in Il2CppSystem.Object result, in JToken jToken);
}
public abstract class Il2CppJsonUnmanagedTypeHandler: INativeJsonHandler where T: unmanaged
{
public abstract void OnRead(in Il2CppSystem.Object result, in JToken jToken);
}
Bare example of Json Injection
JsonInjector.SetConverter(new EventTypeConverter());
JsonInjector.AddHandler(new EventDataHandler());
//This converter alter the behaviour of reading/writing eWardenObjectiveEventType enum
//So you could Parse extended enum types!
internal class EventTypeConverter: Il2CppJsonUnmanagedTypeConverter
{
protected override eWardenObjectiveEventType Read(JToken jToken, eWardenObjectiveEventType existingValue, JsonSerializer serializer)
{
int value = 0;
switch(jToken.Type)
{
case JTokenType.Integer:
value = (int)jToken;
break;
case JTokenType.String:
var str = (string)jToken;
if (Enum.TryParse(str, ignoreCase: true, out var weeResult))
{
value = (int)weeResult;
break;
}
else if (Enum.TryParse(str, ignoreCase: true, out var woResult))
{
value = (int)woResult;
break;
}
return eWardenObjectiveEventType.None;
default:
return eWardenObjectiveEventType.None;
}
return (eWardenObjectiveEventType)value;
}
protected override void Write(JsonWriter writer, eWardenObjectiveEventType value, JsonSerializer serializer)
{
writer.WriteValue((int)value);
}
protected override Il2CppSystem.Object ToIl2CppObject(eWardenObjectiveEventType value)
{
return new Il2CppSystem.Int32() { m_value = (int)value }.BoxIl2CppObject();
}
}
//This one reads Custom Fields from WardenObjectiveEventData type!
internal class EventDataHandler: Il2CppJsonReferenceTypeHandler
{
private readonly static J
Install & use Install: follow the bundled instructions
- Unzip the archive from playbuff and read the bundled readme / instructions first.
- Most mods rely on the game's mod loader — the usual route is a community mod manager (such as r2modman): pick this game, install, and it handles the loader and dependencies.
- For a manual install, put the mod files into the matching Mod / plugins folder inside the game directory.
- Launch the game to confirm it loaded; mods with listed dependencies need those installed as well.
Install locations vary a lot between mods — the bundled readme is the most reliable guide.
Install these first, or the mod will not work: