GithubHelp home page GithubHelp logo

jacadzaca / dbcpy Goto Github PK

View Code? Open in Web Editor NEW
2.0 1.0 2.0 54 KB

python3 library for reading/writing DBC files

Home Page: https://pypi.org/project/dbcpy/

License: GNU Lesser General Public License v3.0

Python 100.00%
world-of-warcraft trinitycore dbc

dbcpy's Introduction

About

This repository contains code for a python3 library that is capable of editing various DBC files. The library was only tested with 3.3.5a DBCs and a TrinityCore server. If this library dose not fit your use case, please consider using pywowlib. Although pywowlib's README states that reading/writing DBCs is not possible, the features seem to be already implemented.

Instalation

pip install dbcpy

Records

dbcpy dose NOT use WoWDBDefs to parse the DBCs. DBC representations must be added manually, for a list of supported DBCs see records

Adding records

Adding a record is easy. Just pick a copy-paste the definition from here into a python dictionary and define a new dataclass. See this for a reference implementation.

Examples

Modifying an existing items' display_ids (will take ~1 second)
#!/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)
Adding a Spell.dbc entry (will take >1 second):
#!/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)
Modyfing an existing spells' names (will take ~30 seconds)
#!/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)

Why dose modifying an existing record takes so long?

Well, not always. In order to modify an existing record, we must rewrite the whole DBC file, because of the string block. The SpellRecord is especially large and the RecordReader.read_record method is not suited for reading large records like that. It handles smaller records (like ItemRecord) well enough (~1 second). The simplest fix would be to implement a SpellRecord specific RecordReader.

How to contribute?

  1. Ensure that your commits have meaningful comments
  2. If your contribution is small (e.g it fixes a minor bug) increment revision (the last digit of version) in setup.py
  3. Provide test-cases

Legal Note

World of Warcraft is a registered trademark of Blizzard Entertainment and/or other respective owners. This software is not created by Blizzard Entertainment or its affiliates, and is for purely educational and research purposes. This software is not intended for the use and production of cheating (hacking) software or modifications that can disrupt World of Warcraft's gameplay. It is your sole responsibility to follow copyright law, game's ToS and EULA. The creators hold no responsibility for the consequences of use of this software.

The code is licensed under LGPL 3.0.

dbcpy's People

Contributors

jacadzaca avatar acostar7819 avatar

Stargazers

anyway avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.