NPK文件格式

用驴子拖了个<<Drakensang>>, 想把资源弄出来利用一下

这游戏是用N2+N3做的, 文件格式什么的, 还是N2的

到N2的代码里找了下, 果然有读取NPK文件的代码

想想自己全部解压出来太麻烦, 不如做个查看器

但是从头自己做一个性价比不是很高, 再加上我是TC的死忠

那么, 就做个像MPQ那样的插件好了

NPK的文件包格式, 看完N2的注释就明白了, 无非就是把文件一个个都拼了起来

数据段就是FourCC+Size+Data的这种Chunk结构, 没有版本号的概念

这样无压缩也无加密, 属于最原始的文件包格式

npk file format: @verbatim # header block HEADER { uint32 'NPK0' // magic number uint32 blockLen // number of following bytes in block uint32 dataOffset // byte offset of data block from beginning of file } # table of contents, sequence of blocks of 3 types: block DIR { uint32 'DIR_' // magic number of directory block uint32 blockLen // number of following bytes in block uint16 dirNameLength // length of the following name char[] dirName // name of directory } block FILE { uint32 'FILE' // magic number of file block uint32 blockLen // number of following bytes in block uint32 fileOffset // start of file data inside data block uint32 fileLength // length of file data in bytes uint16 fileNameLength // length of the following name char[] fileName // name of file } block ENDOFDIR { uint32 'DEND' // magic number of end of dir block uint32 blockLen // number of following bytes in block (0) } # the data block block DATA { uint32 'DATA' // magic number of data block uint32 blockLen // number of following bytes in block char[] data // the data } @endverbatim

整个文件的结构, 是这样组织的:

  • NPK0
  • DIR_
    • DIR_
      • FILE
      • FILE
      • ...
    • DEND
    • DIR_
      • FILE
      • FILE
      • ...
    • DEND
    • ...
  • DEND
  • DATA

简单得不能再简单了, 要写一个文件读取的话, 连N2的库都不用依赖

又下了一个TC的ISO源码看了下, 原来就是个DLL, 把相应的函数实现一下, 然后扔给TC就可以用

=========================================================

更新一个TC插件:

### 回答1: Python可以使用numpy库来修改npk文件。 首先,需要导入numpy库,可以使用以下代码: import numpy as np 然后,使用np.load()函数加载npk文件,例如: data = np.load('file.npk') 接下来,可以对加载的数据进行修改,例如修改某个元素的值: data[0][0] = 10 或者修改某一行或一列的值: data[1,:] = 20 data[:,2] = 30 完成修改后,可以使用np.save()函数将修改后的数据保存到npk文件中,例如: np.save('file_modified.npk', data) 最后,记得关闭文件: data.close() 总结起来,通过导入numpy库,使用np.load()函数加载npk文件,对加载的数据进行修改,然后使用np.save()函数保存修改后的数据到npk文件中,最后关闭文件,就可以完成对npk文件的修改。 需要注意的是,npk文件包含多个数组,所以在使用索引访问元素时,需要指定具体数组的位置。另外,要确保修改后的数据的维度与原来的数据维度一致,否则可能会引起数据错误。 ### 回答2: Python 可以使用 numpy 库来修改 NPK(Numpy Pickle)文件。 首先,需要导入 numpy 模块和 pickle 模块: ```python import numpy as np import pickle ``` 然后,使用 pickle 模块来加载 NPK 文件的内容: ```python with open('file.npk', 'rb') as file: data = pickle.load(file) ``` 接下来,可以对加载的数据进行修改操作。例如,假设 NPK 文件中存储的是一个 numpy 的数组,可以直接对其中的元素进行修改: ```python data[0] = 10 ``` 修改后的数据可以直接用 pickle 模块再次保存到 NPK 文件中: ```python with open('file.npk', 'wb') as file: pickle.dump(data, file) ``` 完整的代码如下所示: ```python import numpy as np import pickle with open('file.npk', 'rb') as file: data = pickle.load(file) # 对数据进行修改操作,例如:data[0] = 10 with open('file.npk', 'wb') as file: pickle.dump(data, file) ``` 这样,就可以使用 Python 的 numpy 和 pickle 模块来修改 NPK 文件了。 ### 回答3: 要使用Python修改npk文件,首先需要了解npk文件的格式和内容。 npk文件是一个打包文件格式,通常用于游戏资源或软件安装包。它包含了多个文件文件夹,以及与之相关的元数据。要修改npk文件,可以按照以下步骤进行: 1. 导入相应的Python库,如`zipfile`和`os`,以处理zip压缩和文件操作。 2. 使用`zipfile`库的`ZipFile`函数打开npk文件。例如,可以使用如下代码打开名为`example.npk`的npk文件: ```python import zipfile npk_file = zipfile.ZipFile('example.npk', 'a') ``` 3. 通过`ZipFile`对象,可以使用`extract()`方法提取npk文件中的特定文件,或使用`extractall()`方法将所有文件解压到指定目录。例如,可以使用如下代码将npk文件中的`data.txt`文件提取到当前目录: ```python npk_file.extract('data.txt', './') ``` 4. 若要修改npk文件中的文件内容,可以先将其提取出来,修改后再重新压缩到npk文件中。例如,可以使用以下代码修改`data.txt`文件并重新压缩到npk文件中: ```python # 提取文件 npk_file.extract('data.txt', './') # 修改文件内容 with open('data.txt', 'w') as file: file.write('This is the modified content.') # 将修改后的文件重新压缩到npk文件npk_file.write('data.txt') ``` 5. 修改完毕后,记得关闭npk文件: ```python npk_file.close() ``` 以上就是使用Python修改npk文件的基本步骤。根据npk文件的具体内容和格式,可能需要进一步处理其他元数据或修改其他文件
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值