BUGFIX: Scripts are killed too late when prestiging #1683
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
A player reports a bug with stock,
ns.atExit
and soft reset. The gist is that when they sell the stock inns.atExit
, the profit is added to the player's money after the soft reset.MRE:
After the soft reset, the player has "initital money" + profit instead of just "initital money".
The bug happens because
prestigeWorkerScripts()
is called afterPlayer.prestigeAugmentation()
and beforeinitStockMarket
. The flow:Player.prestigeAugmentation()
: Reset the player's money.prestigeWorkerScripts()
: callns.atExit
.ns.atExit
sells stocks and adds the profit to the player's money.initStockMarket
: reset the stock market.The fix is fairly simple: We only need to call
prestigeWorkerScripts()
beforePlayer.prestigeAugmentation()
. However, the problem is more complicated than that. BecauseprestigeWorkerScripts()
will runns.atExit
, it allows the player to run arbitrary code when the game logic is performing the prestige and be in an incomplete transition state. This can create many subtle bugs/weird behaviors/exploits. This is an exploit that I come up with:MRE:
In this PoC:
Player
andFactions
; you can use the dev tool as an alternative way):ns.atExit
.ns.singularity.installAugmentations()
.The cost of QLink will be increased after we buy Synfibril Muscle, but we can "reset" that cost requirement with this exploit.
To prevent this kind of problem, this PR does these things:
prestigeWorkerScripts
as early as possible inprestigeAugmentation
andprestigeSourceFile
.prestigeAugmentation
andprestigeSourceFile
. If those callers modify the game state (installing augmentations, setting BitNode data, etc.), we callprestigeWorkerScripts
before those code.