Skip to content

Commit

Permalink
STAS: Fix saving scripts ending with empty line
Browse files Browse the repository at this point in the history
  • Loading branch information
MonsterDruide1 committed Nov 3, 2023
1 parent d6e6624 commit ffde530
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
15 changes: 10 additions & 5 deletions src/main/java/io/github/jadefalke2/script/STas.java
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,10 @@ public static byte[] write(Script script) {
commands.add(new FrameCommand(i));
commands.add(new ControllerCommand((byte) 0, inputLines[i]));
}
commands.add(new FrameCommand(lastNonEmptyLine+1));
commands.add(new ControllerCommand((byte) 0, InputLine.getEmpty()));
if(!inputLines[inputLines.length-1].isEmpty()) {
commands.add(new FrameCommand(lastNonEmptyLine+1));
commands.add(new ControllerCommand((byte) 0, InputLine.getEmpty()));
}

ArrayList<byte[]> data = new ArrayList<>();

Expand Down Expand Up @@ -188,9 +190,12 @@ public static Script read(byte[] script) throws CorruptedScriptException {

int commandCount = data.getInt();
int editingSeconds = data.getInt();
data.expectBytes(new byte[] {1}, "player count"); // currently ignored
data.storePos();
System.out.println(Arrays.toString(data.getBytes(0x20)));
data.loadPos();
data.expectByte(1, "player count"); // currently ignored
data.align(4);
data.expectBytes(new byte[] {0}, "controller type of player 0"); // procon
data.expectByte(0, "controller type of player 0"); // procon
data.align(4);

short authorLength = data.getShort();
Expand All @@ -205,7 +210,7 @@ public static Script read(byte[] script) throws CorruptedScriptException {
if(c instanceof FrameCommand) {
FrameCommand fc = (FrameCommand) c;
if(fc.frameId < inputLines.size())
throw new CorruptedScriptException("Line numbers misordered, got "+fc.frameId+" after "+inputLines.size(), inputLines.size());
throw new CorruptedScriptException("Line numbers misordered, got "+fc.frameId+" after "+inputLines.size()+", offset "+Integer.toHexString(data.position()), inputLines.size());
while(inputLines.size() <= fc.frameId) {
if(inputLines.isEmpty())
inputLines.add(InputLine.getEmpty());
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/io/github/jadefalke2/util/ByteDataStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -150,37 +150,37 @@ public void assertEOF() {
public void expectByte(int value, String message) {
byte val = getByte();
if(val != value) {
throw new UnsupportedOperationException("Unexpected "+message+". expected: "+value+", actual: "+val);
throw new UnsupportedOperationException("Unexpected "+message+" at "+Integer.toHexString(position()-1)+". expected: "+value+", actual: "+val);
}
}
public void expectShort(int value, String message) {
short val = getShort();
if(val != value) {
throw new UnsupportedOperationException("Unexpected "+message+". expected: "+value+", actual: "+val);
throw new UnsupportedOperationException("Unexpected "+message+" at "+Integer.toHexString(position()-1)+". expected: "+value+", actual: "+val);
}
}
public void expectInt(int value, String message) {
int val = getInt();
if(val != value) {
throw new UnsupportedOperationException("Unexpected "+message+". expected: "+value+", actual: "+val);
throw new UnsupportedOperationException("Unexpected "+message+" at "+Integer.toHexString(position()-1)+". expected: "+value+", actual: "+val);
}
}
public void expectLong(long value, String message) {
long val = getLong();
if(val != value) {
throw new UnsupportedOperationException("Unexpected "+message+". expected: "+value+", actual: "+val);
throw new UnsupportedOperationException("Unexpected "+message+" at "+Integer.toHexString(position()-1)+". expected: "+value+", actual: "+val);
}
}
public void expectFloat(float value, String message) {
float val = getFloat();
if(val != value) {
throw new UnsupportedOperationException("Unexpected "+message+". expected: "+value+", actual: "+val);
throw new UnsupportedOperationException("Unexpected "+message+" at "+Integer.toHexString(position()-1)+". expected: "+value+", actual: "+val);
}
}
public void expectBytes(byte[] data, String message) {
byte[] val = getBytes(data.length);
if(!Arrays.equals(val, data)) {
throw new UnsupportedOperationException("Unexpected "+message+". expected: "+Arrays.toString(data)+", actual: "+Arrays.toString(val));
throw new UnsupportedOperationException("Unexpected "+message+" at "+Integer.toHexString(position()-1)+". expected: "+Arrays.toString(data)+", actual: "+Arrays.toString(val));
}
}

Expand Down

0 comments on commit ffde530

Please sign in to comment.