hk-modding / api

Hollow Knight Modding API
MIT License
226 stars 62 forks source link

Add API for mods to interact with other mods' preloads #147

Open flibber-hk opened 1 year ago

flibber-hk commented 1 year ago

TL;DR: This is the cleanest way to fix what is ostensibly a bug in Custom Knight.

The rationale for this PR is as follows. Custom Knight has a feature where objects not associated with the knight can get skinned - for example, a skin might want to replace all copies of a grub with a custom sprite.

For base game items, the way this works is that the skin author declares that hash 568482B2D16BF50AE18B394EC15B290048B75DCD is associated with the grub skin, and then CustomKnight looks up in a precomputed lookup here which scenes/objects need to be skinned.

Obviously this approach doesn't work if another mod has preloaded and instantiated grubs, because they won't be found in any of the listed scenes/paths.

The best approach we could come up with was for Custom Knight to add a component to preloaded objects to indicate where they originally came from, so for example if a mod preloaded a grub like this then the data could be added as a component on the preloaded object to indicate the source of the preload (or similar). This method is added as an alternative to CK having to IL-Hook internal MAPI methods in the mod constructor.


Note - the new API is added as a virtual method rather than an event because the event would have to be subscribed before mod.Initialize, which is not ideal.

ETA: This approach does feel a bit awkward and I'd be much happier with an approach that didn't involve adding a niche function to the mod class.

BadMagic100 commented 1 year ago

A feature request that is hell bent on making it CKs responsibility to skin another mods' content.

is pretty unnecessarily aggressive and not really based in fact - the folks who believe this is a CK issue (myself includes) are not asserting that CK should be skinning all other mods' content by default, we are asserting that CK should be skinning all vanilla game sprites, without respect to what/where the GameObject is or who created it.