Files
neoLegacy/tools/AddResetEndCheckbox.java
T

85 lines
3.4 KiB
Java

import com.jpexs.decompiler.flash.SWF;
import com.jpexs.decompiler.flash.tags.*;
import com.jpexs.decompiler.flash.tags.base.*;
import com.jpexs.decompiler.flash.types.*;
import java.io.*;
import java.util.*;
public class AddResetEndCheckbox {
public static void main(String[] args) throws Exception {
if (args.length < 1) {
System.out.println("Usage: AddResetEndCheckbox <swf_file> [output_file]");
System.exit(1);
}
String inputPath = args[0];
String outputPath = args.length > 1 ? args[1] : inputPath;
SWF swf = new SWF(new FileInputStream(inputPath), false);
DefineSpriteTag worldOptions = null;
PlaceObject3Tag resetNether = null;
for (Tag tag : swf.getTags()) {
if (!(tag instanceof DefineSpriteTag)) continue;
DefineSpriteTag sprite = (DefineSpriteTag) tag;
for (Tag sub : sprite.getTags()) {
if (sub instanceof PlaceObject3Tag) {
PlaceObject3Tag po = (PlaceObject3Tag) sub;
if ("CheckboxResetEnd".equals(po.name)) {
System.out.println("CheckboxResetEnd already exists in " + inputPath + ", skipping.");
return;
}
if ("CheckboxResetNether".equals(po.name)) {
worldOptions = sprite;
resetNether = po;
}
}
}
}
if (resetNether == null) {
System.err.println("ERROR: Could not find CheckboxResetNether in " + inputPath);
System.exit(1);
}
int maxDepth = 0;
int rowSpacing = 0;
Integer flatY = null, resetY = resetNether.matrix.translateY;
for (Tag sub : worldOptions.getTags()) {
if (sub instanceof PlaceObjectTypeTag) {
PlaceObjectTypeTag po = (PlaceObjectTypeTag) sub;
if (po.getDepth() > maxDepth) maxDepth = po.getDepth();
if ("CheckboxFlatWorld".equals(po.getInstanceName())) flatY = po.getMatrix().translateY;
}
}
rowSpacing = flatY != null ? Math.abs(resetY - flatY) : 900;
PlaceObject3Tag resetEnd = new PlaceObject3Tag(swf);
resetEnd.placeFlagHasClassName = resetNether.placeFlagHasClassName;
resetEnd.placeFlagHasName = true;
resetEnd.placeFlagHasMatrix = true;
resetEnd.placeFlagHasImage = resetNether.placeFlagHasImage;
resetEnd.placeFlagHasCharacter = resetNether.placeFlagHasCharacter;
resetEnd.placeFlagMove = resetNether.placeFlagMove;
resetEnd.className = resetNether.className;
resetEnd.characterId = resetNether.characterId;
resetEnd.name = "CheckboxResetEnd";
resetEnd.depth = maxDepth + 1;
MATRIX m = new MATRIX(resetNether.matrix);
m.translateY += rowSpacing;
resetEnd.matrix = m;
resetEnd.setTimelined(worldOptions);
resetEnd.setModified(true);
List<Tag> subTags = worldOptions.getTags().toArrayList();
int index = subTags.indexOf(resetNether);
worldOptions.addTag(index + 1, resetEnd);
worldOptions.setModified(true);
System.out.println(inputPath + ": CheckboxResetEnd at Y=" + m.translateY + " depth=" + resetEnd.depth);
try (FileOutputStream fos = new FileOutputStream(outputPath)) {
swf.saveTo(fos);
}
}
}