Emberveil source

tests/GodWarsSpecialAssetCheck.java

import java.io.*;
import java.util.zip.GZIPInputStream;
/** Exercises every special-attack body/effect frame through the real client model code. */
public final class GodWarsSpecialAssetCheck {
 static byte[] inflate(byte[] raw)throws Exception {
  try(GZIPInputStream in=new GZIPInputStream(new ByteArrayInputStream(raw));ByteArrayOutputStream out=new ByteArrayOutputStream()) {
   byte[] b=new byte[8192];int n;while((n=in.read(b))!=-1)out.write(b,0,n);return out.toByteArray();
  }
 }
 public static void main(String[] args)throws Exception {
  String root="runtime/client-cache/";int checks=0;
  try(RandomAccessFile dat=new RandomAccessFile(root+"main_file_cache.dat","r")) {
   Decompressor[] stores=new Decompressor[3];RandomAccessFile[] indexes=new RandomAccessFile[3];
   try {
    for(int i=0;i<3;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);IDK.unpackConfig(config);Animation.unpackConfig(config);SpotAnim.unpackConfig(config);
    Model.method459(65000,new OnDemandFetcher());Class36.method528(65535);
    for(int type=0;type<2;type++) {
     Stream v=new Stream(versions.getDataForName(type==0?"model_version":"anim_version"));
     for(int id=0;id<v.buffer.length/2;id++)if(v.readUnsignedWord()!=0){byte[] raw=inflate(stores[type+1].decompress(id));if(type==0)Model.method460(raw,id);else Class36.method529(raw);}
    }
    int[] weapons={11694,11696,11698,11700,11730},sequences={17074,17073,17071,17070,17072},effects={11222,11223,11220,11221,11224};
    for(int i=0;i<weapons.length;i++) {
     Player.mruNodes.unlinkAll();Player player=new Player();player.visible=true;player.equipment[3]=512+weapons[i];player.equipment[4]=512+11724;player.equipment[0]=512+11718;
     player.anim=sequences[i];player.anInt1529=0;player.anInt1517=-1;player.anInt1520=effects[i];
     Animation body=Animation.anims[sequences[i]],effect=SpotAnim.cache[effects[i]].aAnimation_407;
     if(effect==null)throw new AssertionError("Missing effect sequence "+effects[i]);
     for(int frame=0;frame<Math.max(body.anInt352,effect.anInt352);frame++) {
      player.anInt1527=Math.min(frame,body.anInt352-1);player.anInt1521=Math.min(frame,effect.anInt352-1);
      if(player.getRotatedModel()==null)throw new AssertionError("Missing special model "+weapons[i]);checks++;
     }
     System.out.println("Rendered all special frames for "+weapons[i]);
    }
    System.out.println("PASS "+checks+" godsword/sword special model frames");
   } finally {for(RandomAccessFile index:indexes)if(index!=null)index.close();}
  }
 }
}