Npk 文件格式
来源:互联网 发布:程序员显示器219 编辑:程序博客网 时间:2024/05/19 09:03
某游戏的压缩资源格式
涉及两个结构体:
struct st_NpkHeader{int _magic;// [_offset + 0]int _count;// [_offset + 4]size(count * 28)int _unknonw2;int _unknonw3;int _bUseTrunkCompressType;int _offset;};
struct st_NpkTrunk{ int _trunkHash; int _dataOffset; int _compressSize; int _realSize; int _unknown1; int _unknonw2; int _compressType;};
完整代码:
// UnNpk.cpp : 定义控制台应用程序的入口点。//#include "./liblz4/lz4.h"#include "./zlib/zlib.h"#include "stdafx.h"#include <string>#include <io.h>#include <direct.h>struct st_NpkHeader{int _magic;// [_offset + 0]int _count;// [_offset + 4]size(count * 28)int _unknonw2;int _unknonw3;int _bUseTrunkCompressType;int _offset;};struct st_NpkTrunk{int _trunkHash;int _dataOffset;int _compressSize;int _realSize;int _unknown1;int _unknonw2;int _compressType;};std::string GetNpkFileName(char *pData, unsigned int maxLen){std::string name;for (int i = 0; i < maxLen; ++i){if ((pData[i] >= 'a' && pData[i] <= 'z') || (pData[i] >= 'A' && pData[i] <= 'Z') ){name += pData[i];}}return name;}int _tmain(int argc, _TCHAR* argv[]){if (argc < 2){printf("%s npkFile\n", argv[0]);return 0;}FILE *fp = fopen(argv[1], "rb");if (!fp){return 0;}unsigned int nFileLen = 0;fseek(fp,0,SEEK_END); //定位到文件末nFileLen = ftell(fp); //文件长度 fseek(fp,0,SEEK_SET);st_NpkHeader npkHeader;fread(&npkHeader, sizeof(npkHeader), 1, fp);if (npkHeader._magic != 0x4b50584e){printf("not npk file\n");return 0;}fseek(fp,0,SEEK_SET);st_NpkTrunk* pNpkTrunkList = new st_NpkTrunk[npkHeader._count];std::string strDir = "./Dump";if (_access(strDir.c_str(), 0) != 0){_mkdir(strDir.c_str());}fseek(fp, npkHeader._offset,SEEK_SET);int nRSize = fread(pNpkTrunkList, sizeof(st_NpkTrunk), npkHeader._count, fp);for (int i = 0; i < nRSize; ++i){fseek(fp, pNpkTrunkList[i]._dataOffset, SEEK_SET);char *pSrc = new char[pNpkTrunkList[i]._compressSize];fread(pSrc, pNpkTrunkList[i]._compressSize, 1, fp);char *pDst = new char[pNpkTrunkList[i]._realSize];if (pNpkTrunkList[i]._compressType == 2){LZ4_decompress_safe(pSrc, pDst, pNpkTrunkList[i]._compressSize, pNpkTrunkList[i]._realSize);}else if (pNpkTrunkList[i]._compressType == 1){int realSize = pNpkTrunkList[i]._realSize;int nRet = uncompress((Bytef *)pDst, (uLongf*)&realSize, (Bytef *)pSrc, pNpkTrunkList[i]._compressSize);}else{memcpy(pDst, pSrc, pNpkTrunkList[i]._realSize);}char fileName[126];std::string format = GetNpkFileName(pDst, 5);sprintf_s<126>(fileName, "%s/%x.%s", strDir.c_str(), pNpkTrunkList[i]._trunkHash, format.c_str());FILE *fp2 = fopen(fileName, "wb");fwrite(pDst, pNpkTrunkList[i]._realSize, 1, fp2);fclose(fp2);delete[] pSrc;delete[] pDst;}return 0;}
0 0
- NPK文件格式
- Npk 文件格式
- 文件格式
- 文件格式
- 文件格式
- 文件格式
- 文件格式
- 关于DNF的多媒体包NPK文件的那些事儿(4)- NPK文件操作流程
- 【文件格式】BMP文件格式
- 关于DNF的多媒体包NPK文件的那些事儿(1)
- 关于DNF的多媒体包NPK文件的那些事儿(2)
- 关于DNF的多媒体包NPK文件的那些事儿(3)
- 关于DNF的多媒体包NPK文件的那些事儿(6)
- 关于DNF的多媒体包NPK文件的那些事儿(7)
- 关于DNF的多媒体包NPK文件的那些事儿(8)
- 关于DNF的多媒体包NPK文件的那些事儿(9)
- MIDI 文件格式
- AVI文件格式
- 洛谷 堆专题 最小函数值
- 寄存器读写测试方法
- 新技术 汇总
- 【Web前端】linux 下配置 node.js
- 测试总结---持续更新中
- Npk 文件格式
- C语言中的字符串处理函数
- JavaScript单例模式
- 在新版本caffe里添加新的一层(向新格式中加)
- echarts的使用详解
- PAT甲级1080
- ES6-Module模块
- linux 启动、关闭、重启tomcat脚本
- POI 生成Excel