Skip to content

Commit

Permalink
STAS: Verify script before saving (warn on issue)
Browse files Browse the repository at this point in the history
  • Loading branch information
MonsterDruide1 committed Nov 3, 2023
1 parent ffde530 commit d4eb176
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/main/java/io/github/jadefalke2/script/STas.java
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,14 @@ public static byte[] write(Script script) {
data.add(c.getBytes());
}

byte[] full = Util.merge(data);
try {
read(full);
} catch(Exception e) {
// not thrown, as just creating it is enough for the box to show up
new CorruptedScriptException("Verification of the saved script failed! You won't be able to open the saved .stas file again. Please make a backup in .txt form instead, and report this issue to MonsterDruide1!", -1, e);
}

return Util.merge(data);
}

Expand Down Expand Up @@ -265,7 +273,7 @@ public static Command readCommand(ByteDataStream data) {

c = new ControllerCommand(playerId, buttons, stickL, stickR);
} else {
throw new RuntimeException("Unknown command: " + commandId);
throw new RuntimeException("Unknown command: " + commandId+" at offset "+Integer.toHexString(data.position()));
}
data.assertPosition(position+payloadLength);
return c;
Expand Down

0 comments on commit d4eb176

Please sign in to comment.