-
Notifications
You must be signed in to change notification settings - Fork 6
The EBF Protocol
The Elite Bionics Framework Protocol ("EBF Protocol") is a protocol for letting other C# mods read the true max HP of body parts affected by EBF-enabled Hediffs.
While it is most recommended for C# mods to "connect to" EBF by referencing the EBF DLLs at the birth of the mods themselves, it is still possible to "connect to" EBF later on using C# reflection.
NOTE: the endpoint to retrieve EBF max HP is currently a makeshift one; that endpoint may become obsolete as I tidy up the EBF codebase and release an official endpoint.
details WIP
This is the simpler method to connect to EBF, but requires that mod users also install the EBF at the same time, or a big red ReflectionException: could not find namespace EBF
will show up in RimWorld's error log, and the savefile will not be loadable until EBF is also installed. If transitioning from no-EBF to yes-EBF, it is recommended to use the below method using C# reflection.
The steps to do so is not described here since the steps are essentially identical to how a C# development environment is set up to mod the vanilla game, except that you pick the EBF DLL instead of the vanilla game's Assembly-CSharp.dll
.
You may obtain the DLL either by Steam Workshop subscription, or by git clone
.
After referencing the DLL in your C# project, refactor your code so that it uses the following methods from EBF:
// first case: general max HP
// this is currently the makeshift endpoint
float realMaxHealth = EBF.VanillaExtender.GetRawMaxHealth(BodyPartDef def, Pawn pawn)
// second case: specific max HP
// this is currently the makeshift endpoint
float realMaxHealth = EBF.VanillaExtender.GetMaxHealth(BodyPartDef def, Pawn pawn, BodyPartRecord record)
Depending on your IDE settings, you may read documentation of those methods in your IDE.
This is the more adaptive method to connect to EBF, does not require mod users to also have EBF, and if done properly, will never raise big red ReflectionExceptions
(unless EBF is refactored, but then it will become EBF's problem, not external mods' problems).
While it is recommended to have some knowledge on how C# reflection works, some sample code is provided below to jumpstart development.
// first case: general max HP
// this is currently the makeshift endpoint
// feel free to optimize this by e.g. making a dedicated function, caching the endpoint during mod load, etc.
float realMaxHealth;
BodyPartDef def;
Pawn pawn;
var makeshiftEndpoint = Type.GetType("EBF.VanillaExtender")?.GetMethod("GetRawMaxHealth");
if (makeshiftEndpoint != null)
{
// EBF detected
realMaxHealth = makeshiftEndpoint.Invoke(null, new Object[] {def, pawn});
}
else
{
// EBF not detected, use vanilla
realMaxHealth = def.GetMaxHealth(pawn);
}
// second case: specific max HP
// this is currently the makeshift endpoint
// feel free to optimize this by e.g. making a dedicated function, caching the endpoint during mod load, etc.
float realMaxHealth;
BodyPartDef def;
Pawn pawn;
BodyPartRecord record;
var makeshiftEndpoint = Type.GetType("EBF.VanillaExtender")?.GetMethod("GetMaxHealth");
if (makeshiftEndpoint != null)
{
// EBF detected
realMaxHealth = makeshiftEndpoint.Invoke(null, new Object[] {def, pawn, record});
}
else
{
// EBF not detected, use vanilla
realMaxHealth = def.GetMaxHealth(pawn);
}
WIP