跳转到主要内容

一个用于读取WoW的DBC文件的简单Python库

项目描述

关于

此存储库包含用于编辑各种DBC文件的python3库的代码。该库仅在3.3.5a DBCs和TrinityCore服务器上进行了测试。如果此库不符合您的使用案例,请考虑使用pywowlib。尽管pywowlib的README声明无法读取/写入DBC,但功能似乎已经实现

安装

pip install dbcpy

记录

dbcpy 不使用 WoWDBDefs 来解析DBC。必须手动添加DBC表示形式,有关支持的DBC列表,请参阅records

添加记录

添加记录很简单。只需从此处复制粘贴定义到Python字典中,并定义一个新的数据类。请参阅处的参考实现。

示例

修改现有物品的display_ids(将花费约1秒)
#!/usr/bin/env python3
from dbcpy.dbc_file import DBCFile
from dbcpy.records.item_record import ItemRecord

def change_display_ids(item_record):
    # entry: new_display_id
    new_display_ids = {
        1501: 37388,
        15534: 27083,
    }
    try:
        item_record.display_id = new_display_ids[item_record.entry]
        return item_record
    except KeyError:
        return item_record

if __name__ == '__main__':
    with open('Item.dbc', 'r+b') as f:
        dbc_file = DBCFile.from_file(f, ItemRecord)
        some_item = dbc_file.records.find(873)
        some_item.entry = 56807
        some_item.display_id = 20300
        with open('Item.dbc.new', 'w+b') as ff:
            dbc_file.write_to_file(change_display_ids, ff)

    with open('Item.dbc.new', 'r+b') as f:
        dbc_file = DBCFile.from_file(f, ItemRecord)
        print(dbc_file.records.find(1501).display_id)
        print(dbc_file.records.find(15534).display_id)
添加Spell.dbc条目(将花费>1秒)
#!/usr/bin/env python3
from dbcpy.dbc_file import DBCFile
from dbcpy.records.spell_record import SpellRecord

if __name__ == '__main__':
    with open('Spell.dbc', 'r+b') as f:
        dbc_file = DBCFile.from_file(f, SpellRecord)
        some_spell = dbc_file.records.find(116)
        some_spell.name.en_us = 'New spell name'
        some_spell.entry = 80865
        dbc_file.records.append(some_spell)

    with open('Spell.dbc', 'r+b') as f:
        dbc_file = DBCFile.from_file(f, SpellRecord)
        the_spell = dbc_file.records.find(80865)
        print(the_spell.name.en_us)
修改现有法术的名称(将花费约30秒)
#!/usr/bin/env python3
from dbcpy.dbc_file import DBCFile
from dbcpy.records.spell_record import SpellRecord

def rename_spell(spell_record):
    new_names = {
        8716: 'i love',
        37263: 'long',
        37290: 'discussions',
    }
    try:
        spell_record.name.en_us = new_names[spell_record.entry]
        return spell_record
    except KeyError:
        return spell_record

if __name__ == '__main__':
    with open('Spell.dbc', 'r+b') as f:
        dbc_file = DBCFile.from_file(f, SpellRecord)
        with open('Spell.dbc.new', 'w+b') as ff:
            dbc_file.write_to_file(rename_spell, ff)

    with open('Spell.dbc.new', 'r+b') as f:
        dbc_file = DBCFile.from_file(f, SpellRecord)
        print(dbc_file.records.find(8716).name.en_us)
        print(dbc_file.records.find(37263).name.en_us)
        print(dbc_file.records.find(37290).name.en_us)

为什么修改现有记录需要这么长时间?

嗯,并不总是这样。为了修改现有记录,我们必须重写整个DBC文件,因为字符串块。SpellRecord尤其 ,并且RecordReader.read_record 方法不适合读取这样的大记录。它处理较小的记录(如ItemRecord)足够好(约1秒)。最简单的修复方法是实现特定于SpellRecord的RecordReader。

如何贡献?

  1. 确保您的提交有有意义的注释
  2. 如果您的贡献很小(例如修复一个小的错误),请增加修订版(版本号的最后一位)在setup.py中。
  3. 提供测试用例

法律声明

《魔兽世界》是暴雪娱乐和/或其他相关权利所有者的注册商标。本软件不是由暴雪娱乐或其附属公司创建的,仅供教育和研究目的使用。本软件不用于制作作弊(黑客)软件或可能破坏《魔兽世界》游戏体验的修改。您有责任遵守版权法、游戏的ToS和EULA。创作者不对使用本软件的后果承担责任。

代码受LGPL 3.0许可。

项目详情


下载文件

下载适用于您平台的应用程序。如果您不确定选择哪个,请了解有关安装包的更多信息。

源代码分发

dbcpy-1.0.9.tar.gz (12.6 kB 查看哈希值)

上传时间 源代码

构建分发

dbcpy-1.0.9-py3-none-any.whl (15.2 kB 查看哈希值)

上传时间 Python 3

由以下机构支持

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF 赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误日志 StatusPage StatusPage 状态页