Emberveil source

tests/GodWarsAssetCheck.java

import java.io.*;
import java.util.zip.GZIPInputStream;
import java.awt.*;
import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;

/** Loads staged assets through the actual legacy client decoders. */
public final class GodWarsAssetCheck {
    static int checks;
    static void check(boolean value,String label){if(!value)throw new AssertionError(label);checks++;}
    static byte[] inflate(byte[] data)throws Exception {
        try(GZIPInputStream in=new GZIPInputStream(new ByteArrayInputStream(data));ByteArrayOutputStream out=new ByteArrayOutputStream()){
            byte[] buffer=new byte[8192];int n;while((n=in.read(buffer))!=-1)out.write(buffer,0,n);return out.toByteArray();
        }
    }
    public static void main(String[] args)throws Exception {
        String root="runtime/godwars-stage/cache/";
        try(RandomAccessFile dat=new RandomAccessFile(root+"main_file_cache.dat","r")) {
            Decompressor[] stores=new Decompressor[5];RandomAccessFile[] indexes=new RandomAccessFile[5];
            try {
                for(int i=0;i<5;i++){indexes[i]=new RandomAccessFile(root+"main_file_cache.idx"+i,"r");stores[i]=new Decompressor(dat,indexes[i],i+1);}
                StreamLoader config=new StreamLoader(stores[0].decompress(2));
                StreamLoader versions=new StreamLoader(stores[0].decompress(5));
                ItemDef.unpackConfig(config);EntityDef.unpackConfig(config);ObjectDef.unpackConfig(config);Animation.unpackConfig(config);Flo.unpackConfig(config);
                Model.method459(65000,new OnDemandFetcher());Class36.method528(65535);
                Stream modelVersions=new Stream(versions.getDataForName("model_version"));
                int modelCount=0;
                for(int id=0;id<modelVersions.buffer.length/2;id++) {
                    int version=modelVersions.readUnsignedWord();if(version==0)continue;
                    byte[] raw=stores[1].decompress(id);if(raw==null)throw new AssertionError("Missing model "+id);
                    Model.method460(inflate(raw),id);
                    if(id>=30000){Model m=Model.method462(id);check(m!=null,"model "+id);m.method469();modelCount++;}
                }
                Stream animVersions=new Stream(versions.getDataForName("anim_version"));
                for(int id=0;id<animVersions.buffer.length/2;id++)if(animVersions.readUnsignedWord()!=0)Class36.method529(inflate(stores[2].decompress(id)));
                for(int seq=10000;seq<Animation.anims.length;seq++) {
                    Animation animation=Animation.anims[seq];check(animation!=null,"sequence "+seq);
                    for(int frame:animation.anIntArray353)if(frame!=-1)check(Class36.method531(frame)!=null,"loaded frame "+frame);
                }
                for(int id:new int[]{3900,3919,3944,3957}) {
                    EntityDef npc=EntityDef.forID(id);check(npc.name!=null,"NPC definition "+id);
                    Model model=npc.method164(-1,Animation.anims[npc.anInt77].anIntArray353[0],null);
                    check(model!=null,"animated NPC model "+id);
                    System.out.println("NPC asset: "+id+" "+npc.name+" stand="+npc.anInt77);
                }
                DrawingArea.initDrawingArea(128,512,new int[512*128]);Texture.method364();Texture.method372(0.8);
                BufferedImage preview=new BufferedImage(512,128,BufferedImage.TYPE_INT_RGB);Graphics2D g=preview.createGraphics();g.setColor(new Color(48,40,30));g.fillRect(0,0,512,128);
                int index=0;
                for(int id:new int[]{11694,11696,11698,11700,11716,11718,11720,11722,11724,11726,11728,11730,11732,11736}) {
                    ItemDef item=ItemDef.forID(id);check(item.name!=null,"item definition "+id);
                    for(int gender=0;gender<2;gender++)check(item.method195(gender)&&item.method196(gender)!=null,"wearable model "+id+" gender "+gender);
                    Sprite sprite=ItemDef.getSprite(id,1,0);check(sprite!=null,"item sprite "+id);
                    int x=(index%8)*64+16,y=(index/8)*64+8;
                    for(int yy=0;yy<32;yy++)for(int xx=0;xx<32;xx++)if(sprite.pixels[yy*32+xx]!=0)preview.setRGB(x+xx,y+yy,sprite.pixels[yy*32+xx]);
                    g.setColor(Color.WHITE);g.drawString(""+id,x-3,y+46);index++;
                }
                g.dispose();ImageIO.write(preview,"png",new File("runtime/godwars-stage/equipment-preview.png"));
                System.out.println("PASS: "+checks+" asset checks; "+modelCount+" imported models decoded");
            } finally {for(RandomAccessFile index:indexes)if(index!=null)index.close();}
        }
    }
}