-
Notifications
You must be signed in to change notification settings - Fork 1
Editing Blueprints
IMPORTANT FOREWORD: Once units (and other things) are loaded into an area, most (all?) of their properties and fields are locked in. If you want to test changes to a Unit's blueprint or otherwise, you will need to go through an area load beforehand.
Generally, in order to edit blueprints in the game, the typical process is to use a postfix harmony patch after the point at which the game loads the blueprint library. However, note that in Pathfinder: WoR, the process is slightly difference, due to blueprints being loaded and unloaded dynamically, which can allow the garbage collector to eat our changes.
Pathfinder WoR Example:
static class ResourcesLibrary_LoadLibrary_Patch
{
static bool Initialized;
static bool Prefix()
{
//Log stacktrace for debugging purposes
Main.Log($"ResourcesLibrary_LoadLibrary_Patch Called");
Main.Log(Environment.StackTrace);
if (Initialized)
{
// When wrath first loads into the main menu InitializeLibrary is called by Kingmaker.GameStarter.
// When loading into maps, Kingmaker.Runner.Start will call InitializeLibrary which will
// clear the ResourcesLibrary.s_LoadedBlueprints cache which causes loaded blueprints to be garbage collected.
// Return false here to prevent ResourcesLibrary.InitializeLibrary from being called twice
// to prevent blueprints from being garbage collected.
return false;
}
else
{
return true;
}
}
static void Postfix()
{
if(Initialized) return;
Initialized = true;
try
{
Main.logger.Log("Library patching initiated");
EnemyReplacement.FixTest();
}
catch (Exception ex)
{
Main.logger.Log("Error while patching library");
Main.logger.Log(ex.ToString());
}
}
}
Once you have set up the above, modifications made to blueprints will persist for the session, so if you do not want to replace original blueprints, you should copy before editing them.
Units are the NPCs and other actors in the game that have statistics. At their core, they have a brain, an inventory, and a fairly wide variety of other properties needed to function. Alongside that, they have a list of facts, and a componentsList that defines more details.
Generally you will usually:
- Modify core values, such as race, portrait, faction, size, alignment, etc...
- Add or remove facts from the unit
- Edit their inventory
- Add or remove components from their componentList
Components are things like the class levels a unit has (add feats, spells, etc... that come from it's class), working with it's tactical/army statistics (for the army battles), or a few other things.
As class levels and the class-related information on a unit is something that is commonly edited, that will be the part mainly focused on here.
The general way to access a component is via something like:
var CRtest = YourBlueprintUnit.GetComponent<Experience>().CR;
In this case, we are getting the CR value of the Experience component which is located in the componentsList of YourBlueprintUnit. Other components and their fields can be accessed and changed in the same way. Take a look at the fields in both the dumped blueprint as well as the dnspy/ilspy decompiled code for complete understanding (eg. the "Experience" component here is under Kingmaker.Blueprints.Classes.Experience - if you access that via dnspy/ilspy, you will see all of the fields and such that make up the component)