| 
|  |  |  |  |  | 
|  组别 | 节度使 |  |  级别 | 军师将军 |  |  好贴 | 3 |  |  功绩 | 475 |  |  帖子 | 984 |  |  编号 | 25461 |  |  注册 | 2004-11-24 |  |  |  |  |  |  |  |  |  
 
 | 
|  |  | 英杰传系列LS格式压缩文件解析 
 
 经过长时间的摸索,终于发现了英杰传系列所专用的文件格式“LS”的一些信息。下面作一些描述。三国志系列的文件一般是不压缩的,而英杰传则不同,它的文件一般是LS11(英杰或孔明传)或LS12(曹操传)格式。这是一个压缩文件,因此我一直以来都无法破译其中包含的信息。最近我终于搞清楚了具体的解码算法。我还是直接给出代码,这样可能比说要清楚。
 (在三国志7和9中的M_Msg文件也是这种格式的)
 
 typedef integer Type;
 
 static Type nc;
 static unsigned char c;
 static Type rc;
 
 void GetData(char *FileName,long Pos,long n)
 {
 FILE *f,*f1;
 char *a,b[256];
 f=fopen(FileName,"rb");
 fseek(f,16,0);
 fread(b,1,256,f);
 fseek(f,Pos,0);
 a=new char[n];
 if (DeCode(f,n,a,
  ==-1) {
 printf("Error!");
 getchar();
 }
 else
 {
 f1=fopen("h:\\temp.dat","w");
 fwrite(a,1,n,f1);
 fclose(f1);
 }
 fclose(f);
 delete []a;
 }
 
 Type DeCode(FILE *f,Type n,char *a,char *
  {
 Type i,t,nc,c=0;
 while (n>0)
 {
 t=getCode(f);
 if (t==-1)
 return -1;
 if (t>=0x100)
 {
 t-=0x100;
 if (t>c)
 return -1;
 nc=getCode(f);
 if (nc==-1)
 return -1;
 nc+=3;
 //*a++=t;
 //*a++=nc;
 for (i=0;i<nc;i++)
 {
 *a=*(a-t);
 a++;
 }
 n-=nc;
 c+=nc;
 }
 else
 {
 *a++=b[t];
 n--;
 c++;
 }
 }
 if (n<0) return -1; else return 0;
 }
 
 Type getCode(FILE *f)
 {
 Type t=0,t2,n=0;
 do
 {
 t2=getbit(f,1);
 if (t2==-1)
 return -1;
 t=(t<<1)+t2;
 n++;
 } while (t2);
 t2=getbit(f,n);
 if (t2==-1)
 return -1;
 return t2+t;
 }
 
 Type getbit(FILE *f,Type n)
 {
 Type ct,t=0;
 while (n--!=0)
 {
 if (nc==0)
 {
 //c=fgetc(f);
 if (fread(&c,1,1,f)==0)
 return -1;
 nc=8;
 rc++;
 }
 nc--;
 ct=c&0x80;
 t=(t<<1)+(ct>>7);
 c<<=1;
 }
 return t;
 }
 
 [ 本帖最后由 恋芸 于 2006-9-10 09:06 编辑 ]
 |  | 
   
 
 |  |  |  |