Ludeon Forums

Ludeon Forums

  • May 17, 2021, 11:43:59 AM
  • Welcome, Guest
Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: help with Reflection  (Read 515 times)


  • Muffalo
  • *
  • Posts: 1
  • Refugee
    • View Profile
help with Reflection
« on: September 21, 2019, 05:41:36 AM »

I am trying to improve my mod "WeaponStats" ( by searching for weapons / apparel inside inventories (e.g. in [KV] Weapon Storage), but I do not want to add any of these mods as dependencies.

For example I could simply do:
foreach (WeaponStorage.Building_WeaponStorage ws in WeaponStorage.WorldComp.GetWeaponStorages(Find.CurrentMap))
    foreach (ThingWithComps pth in ws.AllWeapons)
    { <code to add weapons to table> }

but this requires having WeaponStorage assembly as a dependency.

What is the best way out of this? I can use Reflection to some extent, but my knowledge is not deep enough (I can find out whether the WeaponStorage assembly is loaded, but that's all) - is Reflection best way to do this? Or should I try something different.. like create harmony patches for my own code (this I can do, but it would probably require lots of rewriting of the mod).

Thanks for help!


  • Colonist
  • ***
  • Posts: 154
  • Glory to the Machine God!
    • View Profile
Re: help with Reflection
« Reply #1 on: September 22, 2019, 12:17:44 PM »

Generally mods are going to implement interfaces or extend classes from the base game that give most of the functionality that they need. Instead of searching for Building_WeaponStorage, why not look for Building_Storage (which includes derived classes)?