2004-11-26 23:54
van
英杰传系列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,B)==-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 *B)
{
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;
}
[[i] 本帖最后由 恋芸 于 2006-9-10 09:06 编辑 [/i]]
2004-12-30 19:51
金圭子
[quote]原帖由[i]Maxwell[/i]于2004-12-30, 19:46:31发表
个人推测LS11和LS12只在压缩上不同,上面的程序是解压的,在我的帖子里有位朋友写了个压缩的程序。 [/quote]
是这个么?
[url=http://www.xycq.net/forum/index.php?showtopic=35276&st=30]http://www.xycq.net/forum/index.php?showto...pic=35276&st=30[/url]
的第三个
手头没有vc啊 T_T,vb倒有………………
(如果实在没现成的压缩解压程序只能自己用vb参照写一个了…………嗯……我是懒人 )
2005-4-1 17:46
博雅张生
[quote]void GetData(char *FileName,long Pos,long n)[/quote]
请问这个程序在什么版本下能够正常运行?
Pos和n应当怎样确定?
我在运行这个程序的时候,发现n比较小时尚能解压出一些东西,n稍微大一点就会出错。
2007-9-27 12:39
mayulei2007
8 错,不过很想知道,van是怎么摸索的?靠察看文件二进制编码吗?
还得到一个信息:看了之后也才知道,不是所有的游戏都压缩,还有只打包不压缩的。
继续学习。