v3.0.0: added a saving check on pause for alchemy to prevent exploits

This commit is contained in:
Evan Debenham
2024-10-23 15:18:39 -04:00
parent 2139c3c68a
commit d045a49ef5
@@ -531,6 +531,7 @@ public class AlchemyScene extends PixelScene {
fadeIn(); fadeIn();
saveNeeded = false;
try { try {
Dungeon.saveAll(); Dungeon.saveAll();
Badges.saveGlobal(); Badges.saveGlobal();
@@ -754,8 +755,11 @@ public class AlchemyScene extends PixelScene {
Statistics.itemsCrafted++; Statistics.itemsCrafted++;
Badges.validateItemsCrafted(); Badges.validateItemsCrafted();
saveNeeded = false;
try { try {
Dungeon.saveAll(); Dungeon.saveAll();
Badges.saveGlobal();
Journal.saveGlobal();
} catch (IOException e) { } catch (IOException e) {
ShatteredPixelDungeon.reportException(e); ShatteredPixelDungeon.reportException(e);
} }
@@ -804,6 +808,23 @@ public class AlchemyScene extends PixelScene {
updateState(); updateState();
} }
private boolean saveNeeded = false;
@Override
public void onPause() {
if (saveNeeded) {
saveNeeded = false;
clearSlots();
try {
Dungeon.saveAll();
Badges.saveGlobal();
Journal.saveGlobal();
} catch (IOException e) {
ShatteredPixelDungeon.reportException(e);
}
}
}
@Override @Override
public void destroy() { public void destroy() {
synchronized ( inputs ) { synchronized ( inputs ) {
@@ -813,6 +834,7 @@ public class AlchemyScene extends PixelScene {
} }
} }
saveNeeded = false;
try { try {
Dungeon.saveAll(); Dungeon.saveAll();
Badges.saveGlobal(); Badges.saveGlobal();
@@ -863,6 +885,9 @@ public class AlchemyScene extends PixelScene {
sparkEmitter.burst(SparkParticle.FACTORY, 20); sparkEmitter.burst(SparkParticle.FACTORY, 20);
Sample.INSTANCE.play( Assets.Sounds.LIGHTNING ); Sample.INSTANCE.play( Assets.Sounds.LIGHTNING );
//queue a save here, as items may be in the input windows and we don't want to clear them
// but if the game becomes paused we do this to prevent exploits
saveNeeded = true;
updateState(); updateState();
} }