Analysis and unpacking of game resource formats in Double Star slogan, and resources in Double Star slogan

Source: Internet
Author: User

Analysis and unpacking of game resource formats in Double Star slogan, and resources in Double Star slogan

As an old game launched in 2001, the packaging algorithm should not be very complex. The blogger with this idea tried to analyze the packaging format of the game resource package and finally successfully unwrapped the resource, next let's take a look at the game resource package format of Double Star slogan;

The game resource package uses dat as the extension. There are two resource packages: wav. dat and BIN. dat, where wav. dat is small. Start with it and open it with a hexadecimal editor. You can see the neat file header, the entire resource package is structured like [Baotou] [file type information] [file information] [file data;

The first is the [Baotou], which is 8 bytes in size. The first four bytes are fixed as decimal data 12345678 (hexadecimal 0x00BC614E ), the last four bytes are the number of file types contained in the resource package, such as wav, scr, dec, pal, txm, and chr;

Next we will see [file type information]. The size is 12 bytes. The first four bytes are the file extensions of this type of file, and the four bytes in the middle are the number of files of this type, the last four bytes are the offset values of such file information in the resource package;

Next is the [file information]. The size is 16 bytes. The first eight bytes are file names, excluding the extension. The four middle bytes are the file size, the last four bytes are the offset values of the file data in the resource package;

The last is [file data], which is arranged according to the description in [file information;

Based on the above descriptions, we can organize the following three most important struct:

// Baotou struct PACK_HEADER {__ int32 nSig ;__ int32 nFileTypeNumber ;}; // file type information struct FILETYPE_INFO {char szType [4] ;__ int32 nOffset ;__ int32 nFileNumber ;}; // File Information struct FILE_INFO {char szFileName [8] ;__ int32 nSize ;__ int32 nOffset ;};

Next, you only need to read the resource package according to the data structure described above to extract all the resource files. Unfortunately, the resource files obtained after unpacking, except for the wav audio files, other files have been processed;

The following is the source code. Use Visual Studio to create a Win32 console project, and then place the generated exe file with wav. dat, BIN. in the directories of the two dat files at the same level, you can double-click to unpackage. a directory with the same name will be created when you unpackage the files;

# Include <windows. h> # include <stdio. h> struct PACK_HEADER {inline PACK_HEADER () {memset (this, 0, sizeof (PACK_HEADER) ;}__ int32 nSig ;__ int32 nFileTypeNumber ;}; struct FILETYPE_INFO {inline FILETYPE_INFO () {memset (this, 0, sizeof (FILETYPE_INFO);} char szType [4] ;__ int32 nOffset ;__ int32 nFileNumber ;}; struct FILE_INFO {inline FILE_INFO () {memset (this, 0, sizeof (FILE_INFO);} char szFileName [8] ;__ int32 nSize ;__ in T32 nOffset ;}; BOOL WriteDataToFile (const char * szPack, const char * szFile, const char * szExt, const void * pData, const int nSize) {BOOL bRet = TRUE; FILE * pFile = 0; char szFileNameOut [MAX_PATH] = {0}; if (0! = SzPack & 0! = SzFile & 0! = SzExt & 0! = PData & 0! = NSize) {sprintf (szFileNameOut, "% s/% s. % s ", szPack, szFile, szExt); pFile = fopen (szFileNameOut," wb "); if (0! = PFile) {if (nSize! = Fwrite (pData, 1, nSize, pFile) {bRet = FALSE ;}fclose (pFile); pFile = 0 ;}else {bRet = FALSE ;}} else {bRet = FALSE;} return bRet;} BOOL ExtractPack (const char * szPack) {BOOL bRet = TRUE; char szFullPackName [MAX_PATH] = {0 }; FILE * pFilePack = 0; PACK_HEADER PackHeader; FILETYPE_INFO * pFileTypeInfoList = 0; FILE_INFO * pFileInfoList = 0; void * pFileData = 0; if (0! = SzPack) {CreateDirectoryA (szPack, 0); sprintf (szFullPackName, "% s. dat", szPack); pFilePack = fopen (szFullPackName, "rb"); if (0! = PFilePack) {// Baotou if (sizeof (PACK_HEADER) = fread (& PackHeader, 1, sizeof (PACK_HEADER), pFilePack )) {// file type information header pFileTypeInfoList = new FILETYPE_INFO [PackHeader. nFileTypeNumber]; if (0! = PFileTypeInfoList) {if (sizeof (FILETYPE_INFO) * PackHeader. nFileTypeNumber = fread (pFileTypeInfoList, 1, sizeof (FILETYPE_INFO) * PackHeader. nFileTypeNumber, pFilePack) {// File Information header for (int I = 0; I <PackHeader. nFileTypeNumber; ++ I) {pFileInfoList = new FILE_INFO [pFileTypeInfoList [I]. nFileNumber]; if (0! = PFileInfoList) {fseek (pFilePack, pFileTypeInfoList [I]. nOffset, SEEK_SET); fread (pFileInfoList, 1, sizeof (FILE_INFO) * pFileTypeInfoList [I]. nFileNumber, pFilePack); // file data for (int j = 0; j <pFileTypeInfoList [I]. nFileNumber; ++ j) {pFileData = malloc (pFileInfoList [j]. nSize); if (0! = PFileData) {printf ("% s. % s \ n ", pFileInfoList [j]. szFileName, pFileTypeInfoList [I]. szType); fseek (pFilePack, pFileInfoList [j]. nOffset, SEEK_SET); fread (pFileData, 1, pFileInfoList [j]. nSize, pFilePack); WriteDataToFile (szPack, pFileInfoList [j]. szFileName, pFileTypeInfoList [I]. szType, pFileData, pFileInfoList [j]. nSize); free (pFileData); pFileData = 0 ;}} delete [] pFileInfoList; pFileInfoList = 0 ;}} delete [] pFileTypeInfoList; pFileTypeInfoList = 0 ;}} fclose (pFilePack); pFilePack = 0;} else {bRet = FALSE;} return bRet;} int main (int argc, char * argv []) {ExtractPack ("wav"); ExtractPack ("BIN"); return 0 ;}

The above code is for reference only. The ownership of all the data in the game belongs to the game developer. Please do not use the resources for any commercial purposes;

This article is an original technical article. Please indicate the source for reprinting. Thank you;

Link: http://www.cnblogs.com/NekoDev/p/5929644.html

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.