summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2015-09-16 20:55:28 +0300
committerAndrei Karas <akaras@inbox.ru>2015-09-16 20:55:28 +0300
commitd27db8cca78e06582d8372a9d05f6483202c26ba (patch)
treeb0cd0384dc86d822ecf5a233ddbe2d046ea19585
parentd71aa7d6d7203e5408730cfd86d5f402e0e17a4a (diff)
downloadtools-d27db8cca78e06582d8372a9d05f6483202c26ba.tar.gz
tools-d27db8cca78e06582d8372a9d05f6483202c26ba.tar.bz2
tools-d27db8cca78e06582d8372a9d05f6483202c26ba.tar.xz
tools-d27db8cca78e06582d8372a9d05f6483202c26ba.zip
Add parsing for some RO formats.
Parsing act files and start of parsing spr files (for monsters)
-rw-r--r--hercules/.gitignore2
-rw-r--r--hercules/code/fileutils.py9
-rw-r--r--hercules/code/servertoclient/luas.py55
-rw-r--r--hercules/code/servertoclient/monsters.py9
-rw-r--r--hercules/code/servertoclient/sprites.py153
-rwxr-xr-xhercules/convert_server_to_client.py14
6 files changed, 236 insertions, 6 deletions
diff --git a/hercules/.gitignore b/hercules/.gitignore
index a2120ce..7eeffc2 100644
--- a/hercules/.gitignore
+++ b/hercules/.gitignore
@@ -6,5 +6,7 @@ newserverdata
mapcache
olddb
newdb
+rodata
+tools/luadec
*.pyc
diff --git a/hercules/code/fileutils.py b/hercules/code/fileutils.py
index 884768f..44ec591 100644
--- a/hercules/code/fileutils.py
+++ b/hercules/code/fileutils.py
@@ -20,6 +20,12 @@ def readInt16(f):
arr.fromstring(data)
return arr[0]
+def readInt8(f):
+ data = f.read(1)
+ arr = array.array("B")
+ arr.fromstring(data)
+ return arr[0]
+
def readMapName(f):
data = f.read(12)
data = str(data)
@@ -27,6 +33,9 @@ def readMapName(f):
data = data[:-1]
return data
+def skipData(f, sz):
+ f.read(sz)
+
def readData(f, sz):
return f.read(sz)
diff --git a/hercules/code/servertoclient/luas.py b/hercules/code/servertoclient/luas.py
new file mode 100644
index 0000000..6399da6
--- /dev/null
+++ b/hercules/code/servertoclient/luas.py
@@ -0,0 +1,55 @@
+# -*- coding: utf8 -*-
+#
+# Copyright (C) 2015 Evol Online
+# Author: Andrei Karas (4144)
+
+import re
+from sets import Set
+
+from code.fileutils import *
+from code.stringutils import *
+
+comaSplit = re.compile(",")
+equalSplit = re.compile("=")
+
+def extractLuaArray(fileName, arrName):
+ with open(fileName, "r") as f:
+ for line in f:
+ if line.find(arrName) == 0:
+ line = line[line.find("{") + 1:]
+ line = line[:line.find("}")]
+ return line
+ return ""
+
+def convertJobName():
+ jobs = dict()
+ jobNameFile = "rodata/decompiled/jobname.lua"
+ line = extractLuaArray(jobNameFile, "JobNameTable")
+ arr = comaSplit.split(line)
+ for itemStr in arr:
+ parts = equalSplit.split(itemStr.strip())
+ if parts[0].find("[jobtbl.") == 0:
+ key = parts[0].strip()
+ key = key[8:-1].strip()
+ val = parts[1].strip()
+ val = val[1:-1].strip()
+ jobs[key] = val
+ return jobs
+
+def convertIdentity(jobs):
+ idents = dict()
+ npcIdentityFile = "rodata/decompiled/npcidentity.lua"
+ line = extractLuaArray(npcIdentityFile, "jobtbl = ")
+ arr = comaSplit.split(line)
+ for itemStr in arr:
+ parts = equalSplit.split(itemStr.strip())
+ key = parts[0].strip()
+ val = parts[1].strip()
+ if key in jobs:
+ idents[val] = jobs[key].lower()
+ return idents
+
+def convertLuas():
+ jobs = convertJobName()
+ idtofile = convertIdentity(jobs)
+ return idtofile
diff --git a/hercules/code/servertoclient/monsters.py b/hercules/code/servertoclient/monsters.py
index d08ce66..32255a3 100644
--- a/hercules/code/servertoclient/monsters.py
+++ b/hercules/code/servertoclient/monsters.py
@@ -9,7 +9,9 @@ from sets import Set
from code.fileutils import *
from code.stringutils import *
-def convertMonsters():
+from code.servertoclient.sprites import *
+
+def convertMonsters(isNonFree = False, idtofile = None):
destDir = "clientdata/"
templatesDir = "templates/"
monstersDbFile = "serverdata/sql-files/mob_db_re.sql"
@@ -20,6 +22,7 @@ def convertMonsters():
monsters = readFile(templatesDir + "monsters.xml")
data = ""
ids = Set()
+
monsterSprite = """<sprite>monsters/blub.xml</sprite>
<sprite>accessories/blub-tentacle.xml|#3e4164,3a3968,544a82,64437a,7d6db4,a26392,8f99c4,d294ab,b3cdcd,e7b8b8,d9ecd1,f0e8c5</sprite>""";
with open(monstersDbFile, "r") as f:
@@ -33,6 +36,10 @@ def convertMonsters():
if len(rows) < 5:
continue
monsterId = rows[0]
+ if isNonFree == True:
+ if monsterId in idtofile:
+ convertSprite("rodata/data/sprite/ёуЅєЕН/" + idtofile[monsterId])
+
name = strToXml(stripQuotes(rows[2]))
data = data + tpl.format(monsterId, name, monsterSprite)
diff --git a/hercules/code/servertoclient/sprites.py b/hercules/code/servertoclient/sprites.py
new file mode 100644
index 0000000..1a04745
--- /dev/null
+++ b/hercules/code/servertoclient/sprites.py
@@ -0,0 +1,153 @@
+# -*- coding: utf8 -*-
+#
+# Copyright (C) 2015 Evol Online
+# Author: Andrei Karas (4144)
+
+import os
+
+from code.fileutils import *
+from code.stringutils import *
+
+class ActClass:
+ pass
+
+class ActAnimationClass:
+ pass
+
+class ActSpriteClass:
+ pass
+
+class ActFrameClass:
+ pass
+
+class ActPivotClass:
+ pass
+
+class ActEventClass:
+ pass
+
+class SprClass:
+ pass
+
+def readIndexedRLEImage(f, spr):
+
+
+def readIndexedImage(f, spr):
+ pass
+
+def readRgbaImage(f, spr):
+ pass
+
+def readAct(actFile):
+ act = ActClass()
+ with open(actFile, "r") as f:
+ act.header = readInt16(f)
+ if act.header != 17217:
+ #print "Wrong header in file {0}".format(actFile)
+ return None
+ act.minorVersion = readInt8(f)
+ act.majorVersion = readInt8(f)
+ #print "file: {0}, version: {1}.{2}".format(actFile, act.majorVersion, act.minorVersion)
+ act.nanimations = readInt16(f)
+ #print " animations: " + str(act.nanimations)
+ act.animations = dict()
+ skipData(f, 10)
+ for animN in range(0, act.nanimations):
+ anim = ActAnimationClass()
+ act.animations[animN] = anim
+ anim.nsprites = readInt32(f)
+ #print " sprites: " + str(anim.nsprites)
+ anim.sprites = dict()
+ for spriteN in range(0, anim.nsprites):
+ sprite = ActSpriteClass()
+ anim.sprites[spriteN] = sprite
+ sprite.left1 = readInt32(f)
+ sprite.top1 = readInt32(f)
+ sprite.right1 = readInt32(f)
+ sprite.buttom1 = readInt32(f)
+ sprite.left2 = readInt32(f)
+ sprite.top2 = readInt32(f)
+ sprite.right2 = readInt32(f)
+ sprite.buttom2 = readInt32(f)
+ sprite.nframes = readInt32(f)
+ sprite.frames = dict()
+ #print " frames: " + str(sprite.nframes)
+ for frameN in range(0, sprite.nframes):
+ frame = ActFrameClass()
+ sprite.frames[frameN] = frame
+ frame.offsetX = readInt32(f)
+ frame.offsetY = readInt32(f)
+ frame.frameIndex = readInt32(f)
+ #print " index: " + str(frame.frameIndex)
+ frame.mirror = readInt32(f)
+ if act.majorVersion >= 2:
+ frame.color = readInt32(f)
+ frame.scaleX = readInt32(f)
+ if act.majorVersion > 2 or (act.majorVersion == 2 and act.minorVersion >= 4):
+ frame.scaleY = readInt32(f)
+ else:
+ frame.scaleY = frame.scaleX
+ frame.angle = readInt32(f)
+ frame.spriteType = readInt32(f)
+ if act.majorVersion > 2 or (act.majorVersion == 2 and act.minorVersion >= 5):
+ frame.width = readInt32(f)
+ frame.height = readInt32(f)
+ #print " width: " + str(frame.width)
+ #print " height: " + str(frame.height)
+ if act.majorVersion >= 2:
+ sprite.eventIndex = readInt32(f)
+ if act.majorVersion > 2 or (act.majorVersion == 2 and act.minorVersion >= 3):
+ sprite.npivots = readInt32(f)
+ sprite.pivots = dict()
+ #if sprite.npivots > 0:
+ #print " pivotes: " + str(sprite.npivots)
+ for pivotN in range(0, sprite.npivots):
+ pivot = ActPivotClass()
+ sprite.pivots[pivotN] = pivot
+ pivot.unknown = readInt32(f)
+ pivot.centerX = readInt32(f)
+ pivot.centerY = readInt32(f)
+ pivot.nAttribute = readInt32(f)
+ if act.majorVersion > 2 or (act.majorVersion == 2 and act.minorVersion >= 1):
+ act.nevents = readInt32(f)
+ act.events = dict()
+ for eventN in range(0, act.nevents):
+ event = ActEventClass()
+ act.events[eventN] = event;
+ event.name = readData(f, 40)
+ if act.majorVersion > 2 or (act.majorVersion == 2 and act.minorVersion >= 2):
+ for animN in range(0, act.nanimations):
+ anim = act.animations[animN]
+ anim.delay = readInt32(f)
+
+def readSpr(sprFile):
+ spr = SprClass()
+ with open(sprFile, "r") as f:
+ spr.header1 = readInt8(f)
+ spr.header2 = readInt8(f)
+ if spr.header1 != 0x53 or spr.header2 != 0x50:
+ return None
+ spr.minorVersion = readInt8(f)
+ spr.majorVersion = readInt8(f)
+ spr.indexedSpritesCount = readInt16(f)
+ if spr.majorVersion > 1 or (spr.majorVersion == 1 and spr.minorVersion >= 1):
+ spr.rgbaSpritesCount = readInt16(f)
+ else:
+ spr.rgbaSpritesCount = 0
+ print "{0}, {1}.{2}, {3}, {4}".format(sprFile, spr.majorVersion, spr.minorVersion, spr.indexedSpritesCount, spr.rgbaSpritesCount)
+ spr.frames = spr.indexedSpritesCount + spr.rgbaSpritesCount
+
+ if spr.majorVersion > 2 or (spr.majorVersion == 2 and spr.minorVersion >= 1):
+ readIndexedRLEImage(f, spr)
+ else:
+ readIndexedImage(f, spr)
+ readRgbaImage(f, spr)
+
+
+def convertSprite(spriteName):
+ actFile = "{0}.act".format(spriteName)
+ sprFile = "{0}.spr".format(spriteName)
+ if os.path.exists(actFile) == False or os.path.exists(sprFile) == False:
+ return None
+ #readAct(actFile)
+ readSpr(sprFile)
diff --git a/hercules/convert_server_to_client.py b/hercules/convert_server_to_client.py
index 379a292..d2fb2c7 100755
--- a/hercules/convert_server_to_client.py
+++ b/hercules/convert_server_to_client.py
@@ -6,16 +6,20 @@
from code.servertoclient.homunculuses import *
from code.servertoclient.items import *
+from code.servertoclient.luas import *
from code.servertoclient.mercenaries import *
from code.servertoclient.monsters import *
from code.servertoclient.pets import *
from code.servertoclient.quests import *
from code.servertoclient.skills import *
-convertHomunculuses();
+# non free data
+idtofile = convertLuas()
+
+convertHomunculuses()
convertItems()
-convertMercenaries();
-convertMonsters();
-convertPets();
-convertSkillsToXml();
+convertMercenaries()
+convertMonsters(True, idtofile)
+convertPets()
+convertSkillsToXml()
convertQuests()