MapComponent injection (with solution!)

Started by Ratys, March 04, 2015, 02:56:37 PM

Previous topic - Next topic

Ratys

Since I've stumbled upon a solution I'll leave it here for posterity.

What I'm using in my Mad Skills mod (and probably any future mods, should they require the functionality) is MonoBehavior and defloader sorcery: basically there's an ITab class that gets loaded by the game, but instead of doing what the game assumes it will (be a tab, duh) it's constructor creates a MonoBehavior that checks if a map is loaded and then if it needs inoculation.

So, here are the classes and the def that make it happen. I've marked the places one would need to change in order to hook this injector to their MapComponent.


ORIGINAL POST:
I've been tinkering with various ways to inoculate games-in-progress with MapComponents... It's surprisingly easy, actually: Find.Map.components.Add(mapComponent);

The tricky part is making the injector dissolve, so to speak: right now I have this thingComponent perform the injection, but can't get the building it's attached to (a copy of trade beacon stripped down to bare building) to vanish from the game, ie menus, after it's done. So the end user would install the mod, plop down the building, and then pout whenever they see it hanging out there, useless.

Any ideas how to make it happen? Or a different injection point altogether, like an incident that happens immidiately on loading the save?

KnucklyDuck

Quote from: Ratys on March 04, 2015, 02:56:37 PM
I've been tinkering with various ways to inoculate games-in-progress with MapComponents... It's surprisingly easy, actually: Find.Map.components.Add(mapComponent);

The tricky part is making the injector dissolve, so to speak: right now I have this thingComponent perform the injection, but can't get the building it's attached to (a copy of trade beacon stripped down to bare building) to vanish from the game, ie menus, after it's done. So the end user would install the mod, plop down the building, and then pout whenever they see it hanging out there, useless.

Any ideas how to make it happen? Or a different injection point altogether, like an incident that happens immidiately on loading the save?

When it's done running it's code can't you run Destroy();?
Why do Java programmers have glasses?
.
.
Because they can't C#.

KnucklyDuck

Oh wait, I misunderstood, I wouldn't have a clue mate. Sorry.
Why do Java programmers have glasses?
.
.
Because they can't C#.

mipen

Once the building has been placed and has started the MapComponent, you could have a method inside the MapComponent which Despawns the building and then changes the def of the building to be menu hidden and have no category. That way, it wouldn't show up in the menu. Another way you could do this is use an item that cannot be traded and will not appear in the game in any way other than being spawned in with the dev tools. That way you could have it start the MapComponent and destroy itself and never worrying about ever seeing it again

Ratys

#4
Quote from: mipen on March 05, 2015, 01:09:27 AM
Once the building has been placed and has started the MapComponent, you could have a method inside the MapComponent which Despawns the building and then changes the def of the building to be menu hidden and have no category. That way, it wouldn't show up in the menu.
...

I tried doing that from within the ThingComponent itself by running  this.parent.def.designationCategory = null  prior to  this.parent.Destroy(), but that didn't do anything; I assumed that's because I'm missing something that would rebuild the menus, and then proceeded to not find it for an hour... So I guess I'd like more info on that, please :)  Also, does having the MapComponent run the "get-out-of-menus" code really make a difference?

EDIT:
There is another way! I took a close look at Pawn State Icons source, it's... quite ingenious, really, abusing def loader like that. I even had a similar idea at some point, but (for shame) didn't have a clue how to go about it.

I've stripped down PSI injector and it's working just fine, inoculating a map with my MapComponent and then lying low, zero input from user needed (save for installing and enabling the mod, naturally). I'll tinker with it some more and link my solution in first post.