RimWorld

RimWorld

RimWorld Workshop
Mods and scenarios for RimWorld. Mods can also be found at the Ludeon forums at ludeon.com/forums
Trying to make a simple XML Mod - What am I doing wrong?
I'm trying to make a simple XML PatchOperationReplace mod to change how the Shattered Empire names itself on world generation. What I have so far partially works, but it generates an error when the game first loads. I'm testing with all mods except my own disabled, so it's not a mod conflict issue.

The mod I'm working on consists of only three files:
Dignified Empire Namer\About\about.xml
<?xml version="1.0" encoding="utf-8" ?> <ModMetaData> <name>Dignified Empire Names</name> <author>A Horrible Goose</author> <supportedVersions> <li>1.6</li> </supportedVersions> <packageId>GooseChoosesViolence.Empirenames</packageId> <description>Replaces the Empire faction's Broken and Fallen-patterned names with names an empire might actually call themselves.</description> <modDependencies> <li> <packageId>Ludeon.RimWorld.Royalty</packageId> <displayName>Royalty</displayName> </li> </modDependencies> </ModMetaData>

Dignified Empire Namer\Patches\Namers_Patch.xml
<?xml version="1.0" encoding="utf-8" ?> <Patch> <Operation Class="PatchOperationReplace"> <xpath>Defs/NamerFactionEmpire</xpath> <value> <defName>NamerFactionEmpire</defName> </value> </Operation> </Patch>

Dignified Empire Namer\Defs\Namer.xml
<?xml version="1.0" encoding="utf-8"?> <Defs> <RulePackDef> <defName>NamerFactionEmpire</defName> <include> <li>EmpireNameUtility</li> </include> <rulePack> <rulesStrings> <li>r_name(p=2)->The [imprefix] Sophian [empire]</li> <li>r_name->The [empire] of [ofThing]</li> <li>r_name->The [ImperialNameLast] Dynasty</li> <li>r_name->The [empirename_fixed] [empire]</li> <li>imprefix->Holy</li> <li>imprefix->Sacred</li> <li>imprefix->Grand</li> <li>imprefix->Exalted</li> <li>imprefix->Blessed</li> <li>empire->Empire</li> <li>empire->Commonwealth</li> <li>empire->Imperium</li> <li>empire->Dominion</li> <li>empire->Sovereignty</li> <li>ofThing->Man</li> <li>ofThing->the Stars</li> <li>ofThing->Eternity</li> <li>ofThing->Eltex</li> </rulesStrings> <rulesFiles> <li>empirename_fixed->Names/EmpireTown</li> </rulesFiles> </rulePack> </RulePackDef> </Defs>

The base game code I'm trying to replace is found in RimWorld\Data\Royalty\Defs\FactionDefs\Faction_Empire.xml - specifically this part:
<RulePackDef> <defName>NamerFactionEmpire</defName> <include> <li>EmpireNameUtility</li> </include> <rulePack> <rulesStrings> <li>r_name(p=2)->[empire] of [ofThing]</li> <li>r_name(p=2)->The [empire] of [ofThing]</li> <li>r_name->The Exodus [empire]</li> <li>r_name->The Refugee [empire]</li> <li>r_name->The Broken [empire]</li> <li>r_name->The Shattered [empire]</li> <li>r_name->The Fallen [empire]</li> <li>r_name->The [Color] [empire]</li> <li>empire(p=4)->Empire</li> <li>empire->Commonwealth</li> <li>empire->Imperium</li> <li>empire->Dominion</li> <li>empire->Sovereignty</li> <li>ofThing(p=4)->[WordImperial]</li> <li>ofThing->the Sun</li> <li>ofThing->the Moon</li> <li>ofThing->the Universe</li> <li>ofThing->God</li> <li>ofThing->Perfection</li> <li>ofThing->Eternity</li> <li>ofThing->the Spirit</li> </rulesStrings> </rulePack> </RulePackDef>

I say the mod partially works because on world generation, I see names following some of my new rules but it seems to lean heavily towards Dynasty names - out of 100 trials, 80 of the names were "The [ImperialNameLast] Dynasty" (and 0 followed "The [imprefix] Sophian [empire]" rule), and I don't know why.

The error message I'm getting is:
RimWorld 1.6.4523 rev1054 UnityEngine.StackTraceUtility:ExtractStackTrace () Verse.Log:Message (string) RimWorld.VersionControl:LogVersionNumber () Verse.Root:CheckGlobalInit () Verse.Root:Start () Verse.Root_Entry:Start () [Dignified Empire Names] Patch operation Verse.PatchOperationReplace(Defs/NamerFactionEmpire) failed file: C:\Program Files (x86)\Steam\steamapps\common\Rimworld\Mods\Dignified Empire Namer\Patches\Namers_Patch.xml UnityEngine.StackTraceUtility:ExtractStackTrace () Verse.Log:Error (string) Verse.PatchOperation:Complete (string) Verse.LoadedModManager:ClearCachedPatches () Verse.LoadedModManager:LoadAllActiveMods (bool) Verse.PlayDataLoader:DoPlayLoad () Verse.PlayDataLoader:LoadAllPlayData (bool) Verse.Root/<>c:<Start>b__10_1 () Verse.LongEventHandler:RunEventFromAnotherThread (System.Action) Verse.LongEventHandler/<>c:<UpdateCurrentAsynchronousEvent>b__28_0 () System.Threading.ThreadHelper:ThreadStart_Context (object) System.Threading.ExecutionContext:RunInternal (System.Threading.ExecutionContext,System.Threading.ContextCallback,object,bool) System.Threading.ExecutionContext:Run (System.Threading.ExecutionContext,System.Threading.ContextCallback,object,bool) System.Threading.ExecutionContext:Run (System.Threading.ExecutionContext,System.Threading.ContextCallback,object) System.Threading.ThreadHelper:ThreadStart ()

Do any more experienced modders have any idea what I'm doing wrong?
< >
Showing 1-2 of 2 comments
First, change the defname of your new RulePackDef. This can be any name as long as it doesn't overlap with another RulePackDef.
Next, you'll want to change the patch's xpath to Defs/FactionDef/Empire/factionNameMaker, this is what identifies what namer the empire uses. Set the value of the patch to <factionNameMaker>[your new namer defname here]</factionNameMaker>, and you're done.
Last edited by StockSounds; 20 Jul @ 6:59am
I got it working, thank you for your help.
< >
Showing 1-2 of 2 comments
Per page: 1530 50