Patching abstract copies in older mods

Started by CannibarRechter, September 09, 2017, 04:18:45 PM

Previous topic - Next topic

CannibarRechter

Many older mods, still in use in A17, have copied abstract classes into their mod from the core. This gives each mod copies of things like "BaseGun," for example. At least I think that's what happens. Is there a way using xpath to query for a mod by name so that I can patch their abstract class copies?
CR All Mods and Tools Download Link
CR Total Texture Overhaul : Gives RimWorld a Natural Feel
CR Moddable: make RimWorld more moddable.
CR CompFX: display dynamic effects over RimWorld objects

Fluffy (l2032)

I'm having to make quite a few assumptions on what you're actually trying to do here, if this is not a useful answer, please provide more information on what it is you're trying to do, and how you're trying to do it.

++++++++++++++

patching happens on the text of the defs, before any parsing is done.

What that means is that yes, you can patch abstract defs (please don't call them classes, it's confusing to us C# people). Querying a specific mod by name is not possible, but if that mod has a def in it that has a unique name, you can use that as a proxy for the mods' existance. That said, there shouldn't really be any need, since patches are allowed to silently fail - so you could just try to patch all the abstract classes you know of, and let the patches silently fail if they don't exist.


CannibarRechter

I noticed that if I patch BaseWeapon, it works, but if a mod copied the abstract Def into the mod, it doesn't work for weapons in that mod. I.e., it appears that the BaseWeapon def exists twice in Rimworld. I've gotten around this by patching the uniquely named instances of weapons in the various mods, but the thing I'm patching is the same, and would be best on a base Def. Looks like there is no way to do it, though, from what you are saying.
CR All Mods and Tools Download Link
CR Total Texture Overhaul : Gives RimWorld a Natural Feel
CR Moddable: make RimWorld more moddable.
CR CompFX: display dynamic effects over RimWorld objects

Fluffy (l2032)

There should be, but perhaps for some reason, it's stopping after the first occurrence. I'm by no means an export on xml patches (I try to avoid them like the plague), but if the defs in question all inherit from a given 'baseDef' directly, you could try to select those defs directly by targeting the 'parent' attribute of these defs. That should, in theory at least, catch all defs that descent from the parent.

There's some caveats with inheritance there, but it should work. Then again, I might be completely wrong. XML patches are horrible. Great when they work, but a pita to debug when they don't.

CannibarRechter

#4
I'm finding the patching system to be generally a pleasure to work with, but you really have to have a well-structured approach. One of the reasons I like them is they completely codify what is modded: the older method of copy and modify def is really bad that way, as there is huge amounts of unnecessary copy; you need a diff tool to really see what was modded, and that's horrible.

Don't use Sequences yet, though. These result in genuine difficulty in development, as patch failures are opaque.

It's also worth noting that Rimworld is case insensitive in defs, but case sensitive in patches. That can be a real gotcha. Anyway, you can avoid most of your oopsies by avoiding <success>Always</success>. Develop with out that, and only add that back in if you are conditionally patching a 3rd party mod, and only then after you are fully developed.

As for the topic, I don't believe the rimworld patching system is able to patch N-items. It can only patch one at a time.

.
CR All Mods and Tools Download Link
CR Total Texture Overhaul : Gives RimWorld a Natural Feel
CR Moddable: make RimWorld more moddable.
CR CompFX: display dynamic effects over RimWorld objects