[B18] CompExplosive on Apparel Detonate where equipped, not its Current Position

Started by Jaxxa, December 22, 2017, 05:41:48 AM

Previous topic - Next topic

Jaxxa

CompExplosive on Apparel Detonate where the Apparel was put on, not its Current Location.

I tossed up posting this in the Mod bugs section as this needs a mod to show the issue, but as I think this is an issue with Rimworld Code I posted it here, sorry if I should have posted it over there.

This started from this thread: https://ludeon.com/forums/index.php?topic=37720.msg386056#msg386056

The core issue appears to be that CompExplosive.Detonate Method Calls "parent.Kill" before calling "parent.PositionHeld"  to get the location for the explosion. Doing it in this order PositionHeld will return the same value as Position (which for Apparel is the last location that it was spawned in the world / when it was equipped). Calling parent.PositionHeld prior to "parent.Kill" appears to function correctly and return the current location of the pawn.

I propose that you fix this by caching the value of parent.PositionHeld early in the execution of the CompExplosive.Detonate Method.


Here is a version of the mod by Rustic Fox with a Harmony patch to fix the issue:
https://github.com/jaxxa/Firefoam-Belt/releases/tag/0.18.0.0

With most of the interesting code happening here:
https://github.com/jaxxa/Firefoam-Belt/blob/master/Source/FirefoamBelt/Patch.cs

You can use that mod to replicate the issue. Deleting the .dll files will run the mod how it was originally displaying the issue.

ReopSteps:

1. Run Rimworld with that Mod Enabled.
2. Open a Colony.
3. Use Dev mode to Place a "Firefoam Belt"
4. Have a Colonist wear the belt.
5. Move the colonist away
6. Strike the Colonist with Lightening
7. Wait for the detonation

8a. Without the .dll files observe that the detonation happened where the belt was last equipped.

8b. With the .dll files observe that the detonation happened around the colonist as expected. Opening the Console should show something similar to the following log entries, logging the value of Position and PositionHeld before and after killing the parent.


Executing Detonate_Prefix
PositionHeld Cached
Parent Pos: (123, 0, 110) Parent Pos Held: (141, 0, 103)
About to Do Explosion, PositionHeld now returns Parent Position, not the same Pos Held Value as before the parent was killed, so use the cached value.
Parent Pos: (123, 0, 110) Parent Pos Held: (123, 0, 110)


As you can see I have a workaround, but I think that this should be fixed in the Base game, even if it wont become apparent in Vanilla games currently.