Skip to content

Commit

Permalink
[DBC] More generator stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
navv1234 committed Dec 23, 2017
1 parent 774db02 commit 6e0fd27
Show file tree
Hide file tree
Showing 9 changed files with 134 additions and 70 deletions.
3 changes: 3 additions & 0 deletions casc_extract/casc.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,7 @@ class CDNIndex(CASCObject):
PATCH_BASE_URL = 'http://us.patch.battle.net:1119'

PATCH_BETA = 'wow_beta'
PATCH_ALPHA = 'wow_alpha'
PATCH_PTR = 'wowt'
PATCH_LIVE = 'wow'

Expand Down Expand Up @@ -413,6 +414,8 @@ def patch_base_url(self):
return '%s/%s' % ( CDNIndex.PATCH_BASE_URL, CDNIndex.PATCH_PTR )
elif self.options.beta:
return '%s/%s' % ( CDNIndex.PATCH_BASE_URL, CDNIndex.PATCH_BETA )
elif self.options.alpha:
return '%s/%s' % ( CDNIndex.PATCH_BASE_URL, CDNIndex.PATCH_ALPHA )
else:
return '%s/%s' % ( CDNIndex.PATCH_BASE_URL, CDNIndex.PATCH_LIVE )

Expand Down
1 change: 1 addition & 0 deletions casc_extract/casc_extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
parser.add_option( '-x', '--cache', type = 'string', dest = 'cache', default = 'cache', help = 'Cache directory [default cache]' )
parser.add_option( '--ptr', action = 'store_true', dest = 'ptr', default = False, help = 'Download PTR files [default no, only used for --cdn]' )
parser.add_option( '--beta', action = 'store_true', dest = 'beta', default = False, help = 'Download Beta files [default no, only used for --cdn]' )
parser.add_option( '--alpha', action = 'store_true', dest = 'alpha', default = False, help = 'Download Alpha files [default no, only used for --cdn]' )
parser.add_option( '--locale', action = 'store', dest = 'locale', default = 'en_US', help = 'Extraction locale [default en_US, only used for --cdn]' )

if __name__ == '__main__':
Expand Down
45 changes: 24 additions & 21 deletions dbc_extract3/dbc/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,23 @@ def dbc_name(self):
def is_hotfixed(self):
return self._flags != 0

def __init__(self, parser, dbc_id, data, key = None):
def __init__(self, parser, dbc_id, data, key = 0):
self._dbcp = parser

self._id = dbc_id
self._d = data
self._key = key
self._flags = 0
if key != None:
self._key = key
else:
self._key = -1

if not self._d:
self._d = (0,) * len(self._fi)

def __getattr__(self, name):
if name == 'id' and self._id > -1:
return self._id
# Always return the parent id, even as 0 if the block does not exist in the db2 file
elif name == 'id_parent':
return self._key
else:
raise AttributeError

Expand All @@ -41,7 +41,7 @@ def __str__(self):
for i in range(0, len(self._d)):
s.append('f%d=%d' % (i + 1, self._d[i]))

if self.key > 0:
if self._dbcp.has_key_block():
s.append('id_parent=%u' % self._key)

return ' '.join(s)
Expand All @@ -53,13 +53,9 @@ class DBCRecord(RawDBCRecord):

# Default value if database is accessed with a missing key (id)
@classmethod
def default(cls, *args):
def default(cls, parser):
if not cls.__d:
cls.__d = cls(None, 0, None, -1)

# Ugly++ but it will have to do
for i in range(0, len(args), 2):
setattr(cls.__d, args[i], args[i + 1])
cls.__d = cls(parser, 0, None, 0)

return cls.__d

Expand Down Expand Up @@ -138,14 +134,14 @@ def get_link(self, name, index = 0):
raise AttributeError

if not hasattr(self, '_l'):
return self.__l[name].default()
return self.__l[name].default(self._dbcp)

if name not in self._l:
return self.__l[name].default()
return self.__l[name].default(self._dbcp)

v = self._l[name]
if index >= len(v):
return self.__l[name].default()
return self.__l[name].default(self._dbcp)
else:
return v[index]

Expand Down Expand Up @@ -177,9 +173,6 @@ def __getattr__(self, name):
try:
field_idx = self._cd[name]
except:
#if name == 'id':
# return self._id
#raise AttributeError
return super().__getattr__(name)

if self._fo[field_idx] == 'S' and self._d[field_idx] > 0:
Expand All @@ -196,6 +189,9 @@ def field(self, *args):
if field == 'id' and self._id > -1:
f.append(_FORMATDB.id_format(self.dbc_name()) % self._id)
continue
elif self._dbcp.has_key_block() and field == 'id_parent':
f.append(self._dbcp.key_format() % self._key)
continue
else:
field_idx = self._cd[field]
# If the field isnt found, insert none and skip it. Presumably a child class
Expand Down Expand Up @@ -253,7 +249,7 @@ def __str__(self):
else:
s.append('%s=%u' % (field, self._d[i]))

if self._key > 0:
if self._dbcp.has_key_block():
s.append('id_parent=%u' % self._key)

return ' '.join(s)
Expand Down Expand Up @@ -282,7 +278,7 @@ def csv(self, delim = ',', header = False):
else:
s += '%u%c' % (self._d[i], delim)

if self._key > 0:
if self.dbcp_.has_key_block():
s += '%u%c' % (self._key, delim)

if len(s) > 0:
Expand Down Expand Up @@ -321,7 +317,7 @@ def __getattr__(self, name):
# are the only ones that may be missing in Spellxxx. Just in case raise an
# attributeerror if something else is being accessed
if 'effect_' in name:
return SpellEffect.default()
return SpellEffect.default(self._dbcp)

return DBCRecord.__getattr__(self, name)

Expand Down Expand Up @@ -441,6 +437,10 @@ def initialize_data_model(options, obj):
dbc.data.Spell.link('scaling', dbc.data.SpellScaling)
dbc.data.Spell.link('artifact_power', dbc.data.ArtifactPowerRank)
dbc.data.Spell.link('label', dbc.data.SpellLabel)
dbc.data.Spell.link('misc', dbc.data.SpellMisc)

if options.build >= 25600:
dbc.data.Spell.link('desc_var_link', dbc.data.SpellXDescriptionVariables)

if 'SpellEffect' in dir(obj) and options.build < 25600:
dbc.data.SpellEffect.link('scaling', dbc.data.SpellEffectScaling)
Expand All @@ -466,3 +466,6 @@ def initialize_data_model(options, obj):
elif 'ItemSparse' in dir(obj):
dbc.data.GemProperties.link('item', dbc.data.ItemSparse)

if 'SpellXDescriptionVariables' in dir(obj):
dbc.data.SpellXDescriptionVariables.link('desc', dbc.data.SpellDescriptionVariables)

8 changes: 6 additions & 2 deletions dbc_extract3/dbc/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@
import dbc

class DBCDB(dict):
def __init__(self, obj = None):
def __init__(self, obj = None, parser = None):
dict.__init__(self)
self.__obj = obj
self.__parser = parser

def parser(self):
return self.__parser

def __missing__(self, key):
if self.__obj:
return self.__obj.default()
return self.__obj.default(self.__parser)
else:
raise KeyError

Expand Down
2 changes: 1 addition & 1 deletion dbc_extract3/dbc/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def __next__(self):
data = self._parser.get_record(self._wdb_parser, offset, size)
self._record += 1

return self._data_class(self._parser, dbc_id, data)
return self._data_class(self._parser, dbc_id, data, 0)

class DBCache:
def __init__(self, options):
Expand Down
Loading

0 comments on commit 6e0fd27

Please sign in to comment.