Histidine91 / Nexerelin

The Nexerelin 4x mod for Starsector.
65 stars 15 forks source link

Special Task Forces despawning with reason REACHED_DESTINATION #72

Closed Dessix closed 1 month ago

Dessix commented 1 month ago

I tweaked SpecialForcesIntel to dump the reason parameter when this line is reached.

Apparently, it thinks my fleet is where it was meant to be, because it always reports the despawn reason as REACHED_DESTINATION.

Observed behaviour:

I can respawn my fleet for 0 credits, presumably because it previously had this issue, and it will orbit the planet for a moment, then park back on the planet, disappearing and triggering the "please report this as a bug" UI.

If I give it orders to do anything else, it seems to instantly dive back into the planet, not even leaving to orbit it before despawning. If I wait for it to reach orbit, then tell it to go to another system and orbit the Prism Freeport (or any other target), it instantly despawns wherever it is located, again with REACHED_DESTINATION.

I suspect the delayed despawning I'm observing when I don't give it an order is when it decides one for itself? The fleet composition appears to be unrelated to this state.

Histidine91 commented 1 month ago

Well that's messed up.

Do you have a save (preferably with <50 mods) that I can try poking?

Otherwise, there might be some things to investigate in PlayerSpecialForcesIntel and its related classes. Things that come to mind from a quick look: logging the fleet assignment before and at the moment it despawns; checking if entity.isAlive() or isNoAutoDespawn() are somehow returning false prior to the despawn.

(Did a quick search: SpecialForcesAssignmentAI.advance should be the only place in Nex code that should be giving a GO_TO_LOCATION_AND_DESPAWN assignment to the task group, and then only if the intel item is ending or ended.)

Dessix commented 1 month ago

Unfortunately, I've got 127 mods installed and a setup that relies on 20 gigs of ram to run. If you have a build setup, I could run instrumented versions of the binary. So far, my tweaks have been done through bytecode editing, because setting up a build on Windows sounded awful.

Histidine91 commented 1 month ago

README.md has instructions for setting up the mod project in IntelliJ that someone wrote a couple of years back, if that helps.

Dessix commented 1 month ago

@Histidine91 That was surprisingly complicated for a project setup; I've never found myself missing cmake before.

As for the topic at hand: that block in SpecialForcesAssignmentAI.advance is not hit during this repro; it appears that starfarer.campaign.ai.AssignmentModule.advance is doing it, but I haven't been able to identify where or why because my debugger refuses to set breakpoints in that (decompiled) function.

I'll note that, when I hit a breakpoint on the invocation of (but not within) AssignmentModule.advance, this.assignments contained ORBIT_PASSIVE followed by 470 copies of GO_TO_LOCATION_AND_DESPAWN. This number appears to increment by one additional copy per frame (presumably per advance call on some other module?) until it begins moving back toward the planet to actually despawn.

Edit / Update:

The best hint I have on what's producing this command is this stack, but I can't seem to break into whatever script acs_industry_scavbase2 is.

However... It turns out the breakpoint watches had enough reflection metadata when I broke into it that I was able to inspect the planet's industries- and it turns out the Scavenger Den from the mod Indies Expansion Pack is what's providing the despawn order. Here's the responsible call stack (no line numbers available because of decompilation):

addAssignment:-1, AssignmentModule (com.fs.starfarer.campaign.ai)
addAssignment:-1, ModularFleetAI (com.fs.starfarer.campaign.ai)
addAssignment:-1, CampaignFleet (com.fs.starfarer.campaign.fleet)
advance:186, acs_industry_scavbase2 (data.scripts.industry)
advance:-1, Market (com.fs.starfarer.campaign.econ)
advance:-1, Economy (com.fs.starfarer.campaign.econ)
advance:-1, CampaignEngine (com.fs.starfarer.campaign)
advance:-1, CampaignState (com.fs.starfarer.campaign)
traverse:-1, BaseGameState (com.fs.starfarer)
begin:-1, AppDriver (com.fs.state)
main:-1, CombatMain (com.fs.starfarer.combat)
super:-1, StarfarerLauncher (com.fs.starfarer)
run:-1, StarfarerLauncher$1 (com.fs.starfarer)
runWith:1588, Thread (java.lang)
run:1575, Thread (java.lang)

For anyone hitting this issue- delete your Scavenger Den until that mod is patched.

Histidine91 commented 1 month ago

Amazing detective work 🧎

I think I can close this issue now, but it might be a good idea to let NeoLemon know your finding if you haven't already.