Emberveil source

tests/FishingQuestClientAssets.java

import java.io.*;
import java.util.*;
import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;
/** Tests the exact shipping cache with the real client decoders and renderer. */
public class FishingQuestClientAssets {
 static int checks;
 static void check(boolean value,String label){checks++;if(!value)throw new AssertionError(label);}
 public static void main(String[] args)throws Exception {
  String root="runtime/ammunition-stage/cache/";new File("runtime/fishing-quest-assets").mkdirs();
  try(RandomAccessFile dat=new RandomAccessFile(root+"main_file_cache.dat","r")){
   RandomAccessFile[] indexes=new RandomAccessFile[5];Decompressor[] stores=new Decompressor[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)),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"));
    for(int id=0;id<modelVersions.buffer.length/2;id++)if(modelVersions.readUnsignedWord()!=0)Model.method460(GodWarsAssetCheck.inflate(stores[1].decompress(id)),id);
    Stream animationVersions=new Stream(versions.getDataForName("anim_version"));
    for(int id=0;id<animationVersions.buffer.length/2;id++)if(animationVersions.readUnsignedWord()!=0)Class36.method529(GodWarsAssetCheck.inflate(stores[2].decompress(id)));
    VarBit.unpackConfig(config);EntityDef.clientInstance=new Game();
    for(int i=233;i<=236;i++)System.out.println("CONTEST SPOT "+i+" "+Arrays.toString(EntityDef.forID(i).actions));
    for(int id:new int[]{232,3679,225,226,227,228,229,230,233}){
     EntityDef npc=EntityDef.forID(id);if(npc.childrenIDs!=null){npc=npc.method161();check(npc!=null,"default quest NPC morph visible "+id);}check(npc.name!=null,"NPC name "+id);
     int standFrame=npc.anInt77<0 ? -1 : Animation.anims[npc.anInt77].anIntArray353[0];
     check(npc.method164(-1,standFrame,null)!=null,"NPC model and stand frame "+id);
     if(id!=233)check(npc.method160()!=null,"dialogue head "+id);
    }
    for(int seq:new int[]{622,830,839,828})for(int frame:Animation.anims[seq].anIntArray353)if(frame!=-1)check(Class36.method531(frame)!=null,"quest animation frame "+seq);
    DrawingArea.initDrawingArea(128,768,new int[128*768]);Texture.method364();Texture.method372(0.8);
    int[] ids={27,25,26,338,1550,307,952};
    BufferedImage preview=new BufferedImage(12*64,2*64,BufferedImage.TYPE_INT_RGB);
    for(int i=0;i<ids.length;i++){
     Sprite sprite=ItemDef.getSprite(ids[i],1,0);check(sprite!=null,"item sprite "+ids[i]);int pixels=0;
     for(int y=0;y<32;y++)for(int x=0;x<32;x++)if(sprite.pixels[y*32+x]!=0){pixels++;preview.setRGB((i%12)*64+16+x,(i/12)*64+16+y,sprite.pixels[y*32+x]);}
     check(pixels>15,"visible quest item "+ids[i]);
    }
    ImageIO.write(preview,"png",new File("runtime/fishing-quest-assets/items.png"));
    GodWarsSceneCheck.stores=stores;GodWarsSceneCheck.outputRoot="runtime/fishing-quest-assets/";
    Texture.method368(new StreamLoader(stores[0].decompress(6)));Texture.method372(0.8);Texture.method367();
    Stream map=new Stream(versions.getDataForName("map_index"));
    while(map.currentOffset<map.buffer.length){int r=map.readUnsignedWord(),g=map.readUnsignedWord(),o=map.readUnsignedWord();map.readUnsignedByte();GodWarsSceneCheck.regions.put(r,new int[]{g,o});}
    GodWarsSceneCheck.scene("hemenster",2638,3442,0);
    GodWarsSceneCheck.scene("worm-vine",2631,3498,0);
    GodWarsSceneCheck.scene("west-dwarf",2822,3485,0);
    GodWarsSceneCheck.scene("mountain-passage",2822,9883,0);
    System.out.println("PASS: "+checks+" Fishing Contest client asset checks and four rendered scenes");
   }finally{for(RandomAccessFile index:indexes)if(index!=null)index.close();}
  }
 }
}