-
-
[求助]一个资源文件读取方法,看看各位大侠有什么办法能够还原出来并且重新打包
-
发表于: 2007-7-1 21:56 4650
-
一个资源文件读取方法,看看各位大侠有什么办法能够还原出来并且重新打包
或者做个编辑器
例如 .Load(".\\data\\Test.spr", 555) 这样调用
BOOL xSprite::Load(char *name, int ScreenRGBMode)
{
FILE *fp;
SPRFILEHEAD tempsfhead;
SPRHEAD30 shead;
if( (fp = fopen( name, "rb")) == NULL )
{
return FALSE;
}
fread(&tempsfhead, sizeof(SPRFILEHEAD), 1, fp);
if(strncmp("93XYZ sprite",tempsfhead.Identifier,13) != 0)
{
fclose(fp);
return FALSE;
}
Remove();
memcpy(&sfhead, &tempsfhead, sizeof(SPRFILEHEAD));
spr = (SPRITE30*) malloc(sizeof(SPRITE30) * sfhead.TotalSprNum);
if(spr==NULL)
{
return FALSE;
}
ZeroMemory(spr, sizeof(SPRITE30) * sfhead.TotalSprNum);
for(int i=0; i < sfhead.TotalSprNum; i++)
{
fread(&shead, sizeof(SPRHEAD30), 1, fp);
spr[i].compress = shead.compress;
spr[i].colorkey = shead.colorkey;
spr[i].rx = shead.rx;
spr[i].ry = shead.ry;
spr[i].xl = shead.xl;
spr[i].yl = shead.yl;
spr[i].mx = shead.mx;
spr[i].my = shead.my;
spr[i].hitNum = shead.hitNum;
spr[i].atckNum = shead.atckNum;
spr[i].hit = NULL;
spr[i].atck = NULL;
spr[i].dsize = shead.dsize;
spr[i].PixelFormat = shead.PixelFormat;
spr[i].SprFormat = shead.SprFormat;
spr[i].Dithering = shead.Dithering;
spr[i].byUserVal = shead.byUserVal;
if(spr[i].hitNum>0) spr[i].hit = (SPRPOS*)malloc(sizeof(SPRPOS)*spr[i].hitNum);
if(spr[i].atckNum>0) spr[i].atck = (SPRPOS*)malloc(sizeof(SPRPOS)*spr[i].atckNum);
fread(spr[i].hit, sizeof(SPRPOS)*spr[i].hitNum, 1, fp);
fread(spr[i].atck, sizeof(SPRPOS)*spr[i].atckNum, 1, fp);
if(spr[i].SprFormat == 1) {
BOOL bDither = FALSE;
if(spr[i].Dithering == 1) bDither = TRUE;
fpos_t pos;
fgetpos(fp, &pos);
int width=0, height=0;
WORD *pNewImage = Make16bitFromJpeg(fp, &width, &height, bDither);
if(!pNewImage) {
fclose(fp);
return FALSE;
}
if(width != spr[i].xl || height != spr[i].yl) {
fclose(fp);
return FALSE;
}
spr[i].dsize = width * height * 2;
spr[i].data = pNewImage;
spr[i].compress = 0;
if(shead.compress == 1) {
Compress(i);
}
pos += shead.dsize;
fsetpos(fp, &pos);
}
else {
spr[i].data = (WORD *)malloc( shead.dsize );
if(spr[i].data==NULL) {
return FALSE;
}
ZeroMemory(spr[i].data, shead.dsize);
fread(spr[i].data, shead.dsize, 1, fp);
}
}
if(sfhead.CharacterNum > 0) ani.Load(fp);
fclose(fp);
if(sfhead.FixelFormat != 4444) ChangeFixelFormat(ScreenRGBMode);
return TRUE;
}
或者做个编辑器
例如 .Load(".\\data\\Test.spr", 555) 这样调用
BOOL xSprite::Load(char *name, int ScreenRGBMode)
{
FILE *fp;
SPRFILEHEAD tempsfhead;
SPRHEAD30 shead;
if( (fp = fopen( name, "rb")) == NULL )
{
return FALSE;
}
fread(&tempsfhead, sizeof(SPRFILEHEAD), 1, fp);
if(strncmp("93XYZ sprite",tempsfhead.Identifier,13) != 0)
{
fclose(fp);
return FALSE;
}
Remove();
memcpy(&sfhead, &tempsfhead, sizeof(SPRFILEHEAD));
spr = (SPRITE30*) malloc(sizeof(SPRITE30) * sfhead.TotalSprNum);
if(spr==NULL)
{
return FALSE;
}
ZeroMemory(spr, sizeof(SPRITE30) * sfhead.TotalSprNum);
for(int i=0; i < sfhead.TotalSprNum; i++)
{
fread(&shead, sizeof(SPRHEAD30), 1, fp);
spr[i].compress = shead.compress;
spr[i].colorkey = shead.colorkey;
spr[i].rx = shead.rx;
spr[i].ry = shead.ry;
spr[i].xl = shead.xl;
spr[i].yl = shead.yl;
spr[i].mx = shead.mx;
spr[i].my = shead.my;
spr[i].hitNum = shead.hitNum;
spr[i].atckNum = shead.atckNum;
spr[i].hit = NULL;
spr[i].atck = NULL;
spr[i].dsize = shead.dsize;
spr[i].PixelFormat = shead.PixelFormat;
spr[i].SprFormat = shead.SprFormat;
spr[i].Dithering = shead.Dithering;
spr[i].byUserVal = shead.byUserVal;
if(spr[i].hitNum>0) spr[i].hit = (SPRPOS*)malloc(sizeof(SPRPOS)*spr[i].hitNum);
if(spr[i].atckNum>0) spr[i].atck = (SPRPOS*)malloc(sizeof(SPRPOS)*spr[i].atckNum);
fread(spr[i].hit, sizeof(SPRPOS)*spr[i].hitNum, 1, fp);
fread(spr[i].atck, sizeof(SPRPOS)*spr[i].atckNum, 1, fp);
if(spr[i].SprFormat == 1) {
BOOL bDither = FALSE;
if(spr[i].Dithering == 1) bDither = TRUE;
fpos_t pos;
fgetpos(fp, &pos);
int width=0, height=0;
WORD *pNewImage = Make16bitFromJpeg(fp, &width, &height, bDither);
if(!pNewImage) {
fclose(fp);
return FALSE;
}
if(width != spr[i].xl || height != spr[i].yl) {
fclose(fp);
return FALSE;
}
spr[i].dsize = width * height * 2;
spr[i].data = pNewImage;
spr[i].compress = 0;
if(shead.compress == 1) {
Compress(i);
}
pos += shead.dsize;
fsetpos(fp, &pos);
}
else {
spr[i].data = (WORD *)malloc( shead.dsize );
if(spr[i].data==NULL) {
return FALSE;
}
ZeroMemory(spr[i].data, shead.dsize);
fread(spr[i].data, shead.dsize, 1, fp);
}
}
if(sfhead.CharacterNum > 0) ani.Load(fp);
fclose(fp);
if(sfhead.FixelFormat != 4444) ChangeFixelFormat(ScreenRGBMode);
return TRUE;
}
赞赏
他的文章
赞赏
雪币:
留言: