XCOM 2
XCOM Restart Mission
Donovan Trevos  [developer] 12 Feb, 2016 @ 2:58am
Technical Notes
This is mostly for myself, but others might find it interesting, so why not.

Due to bugs in the RestartLevel functionality I've had to search for a new way to implement this. After some digging I came up with some code that approximates the functionality of the RestartLevel code almost 1:1, including the bug where the perks and items are not persisted properly.

local XComGameStateHistory History; local XComGameState_BattleData BattleDataState; if (eAction == eUIAction_Accept) { //`XCOMVISUALIZATIONMGR.DisableForShutdown(); History = `XCOMHISTORY; History.ObliterateGameStatesFromHistory(History.GetNumGameStates() - History.FindStartStateIndex() - 2); BattleDataState = XComGameState_BattleData(History.GetSingleGameStateObjectForClass(class'XComGameState_BattleData')); ConsoleCommand(BattleDataState.m_strMapCommand); }

If we take this one step further and instead of subtracting two, subtract one, completely obliterating the state after the start mission state the game properly plays the mission intro and all of the perks are available, but the UI is horrendously broken(duplicated action buttons and UI elements are often duplicated on top of one another.) I haven't been able to track down a method of properly marking to the UI that it needs to shut down and come back up the way it does when you transition from the avenger to the tactical game.

Unfortunately due to the way the UI elements are brought up when loading a map with a specific state, if you reload a game with the broken UI method, you get an extra copy of all actions each restart, and they are persisted into save games(It looks like the game is duplicating state somewhere from the game state into the HUD and not releasing it, and I haven't tracked it down.)

The other potential option is to discard the state history for the entire mission after extracting the required information, transitioning back into the avenger, and then relaunching the mission. The problems encountered with this are that transitioning between maps requires saving state in multiple areas and hooking many classes, not an ideal solution for such a simple command.

For those wondering if you can use the history system to implement an undo action or undo turn function, yes, and no. It is theoretically possible to revert the game state back to before the action happened, but reverting the game state while the tactical game is running almost always leads to crashing.
Last edited by Donovan Trevos; 12 Feb, 2016 @ 3:09am
< >
Showing 1-7 of 7 comments
MOD 14 Feb, 2016 @ 8:33am 
Maybe you could do a sort of unlisted auto-save before the tactical section loads? Maybe the game has a hook somewhere for when the strategic model gives control to the tactical model and could save the game there, then a restart mission would be a simple save-game load?
kMotion 14 Feb, 2016 @ 10:12am 
I've use this mod, and shotdown him, my save game can't be load. How can I clear my save game?
BiTSHiFTeD 14 Feb, 2016 @ 11:50am 
Okay, for a clear step by step guide to resolve save error issue...


1. Locate your workshop directory
<drive_letter>/steam/steamapps/workshop/content/268500/
2. navigate to dir 618681066/ and copy contents all but RestartMission.XComMod
3. navigate to dir 619019230 and paste previously copied contents to directory and over write when asked.
4. rename XcomRestartMisison.XComMod -> RestartMission.XComMod
5. launch game and enjoy your saves.

Tested and working on my own game saves.
Enjoy!
Donovan Trevos  [developer] 14 Feb, 2016 @ 1:08pm 
Originally posted by chmod:
Maybe you could do a sort of unlisted auto-save before the tactical section loads? Maybe the game has a hook somewhere for when the strategic model gives control to the tactical model and could save the game there, then a restart mission would be a simple save-game load?

I don't think I can hide a specific save game without mucking about with the load game lists and hooking the core save game manager. I'd much prefer not to touch those classes if I can avoid it. I could automatically save on the first turn when the game fully comes up much the same way the autosave system does, but again, a class that is going to be popular to modify, and thus one I'd like to avoid touching unless I can avoid it.
Christophlette 14 Feb, 2016 @ 3:25pm 
I'm only making hypothesis but here is what I imagine :

If the -2 is to get the state of the game where the mission starts. And you don't get your perks.

And the -1 gives you perks but leads to a UI bug.

Maybe it is because the -1 represents a state between start and full load of the mission.
It might be interesting to try with -3 (Maybe before) and see what it does if you didn't already. It might lead you to a state between the avenger and the tactical mode. Maybe in the Firebird when mission is loading ?

This loading must represent a kind of translation between the avenger and the tactical play. Creating an entity class with perks and items that were previously held by another class in the avenger.
Donovan Trevos  [developer] 14 Feb, 2016 @ 3:39pm 
-3 actually advances forwards into your first turn. Moving back past the start state causes the game to crash after a loading screen, most likely because there is no map to load at that state. I tried going back a few more steps and it continues to crash. It looks like you can't swap between tactical and strategy without taking the correct route of ending the tactical game.

It does seem like -1 is a transition state of some kind, but it appears that the only major issue is that the tactical game is already running and all of the variables are set up, not that the game can't recover from visiting it again.
Christophlette 15 Feb, 2016 @ 10:00am 
Thanks for the answer. It's good to know.

I may start looking into modding to search for a kind of refreshUI method of some kind.

Again, apologies for the misunderstanding. Keep up the good work.
< >
Showing 1-7 of 7 comments
Per page: 1530 50