From be98eb3cb215a2715e8c2d42eb476329b0c194eb Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Wed, 3 Sep 2014 15:29:09 +0300 Subject: Rename mapcache into hercules. --- hercules/.gitignore | 3 + hercules/cachetotmx.py | 1 + hercules/extract.py | 1 + hercules/list.py | 1 + hercules/maptool.py | 172 +++++++++++++++++++++++++++++++++++++++ hercules/templates/collision.png | Bin 0 -> 275 bytes hercules/templates/example.tmx | 38 +++++++++ hercules/templates/template.tmx | 25 ++++++ hercules/templates/tileset.png | Bin 0 -> 1132 bytes mapcache/.gitignore | 3 - mapcache/cachetotmx.py | 1 - mapcache/extract.py | 1 - mapcache/list.py | 1 - mapcache/maptool.py | 172 --------------------------------------- mapcache/templates/collision.png | Bin 275 -> 0 bytes mapcache/templates/example.tmx | 38 --------- mapcache/templates/template.tmx | 25 ------ mapcache/templates/tileset.png | Bin 1132 -> 0 bytes 18 files changed, 241 insertions(+), 241 deletions(-) create mode 100644 hercules/.gitignore create mode 120000 hercules/cachetotmx.py create mode 120000 hercules/extract.py create mode 120000 hercules/list.py create mode 100755 hercules/maptool.py create mode 100644 hercules/templates/collision.png create mode 100644 hercules/templates/example.tmx create mode 100644 hercules/templates/template.tmx create mode 100644 hercules/templates/tileset.png delete mode 100644 mapcache/.gitignore delete mode 120000 mapcache/cachetotmx.py delete mode 120000 mapcache/extract.py delete mode 120000 mapcache/list.py delete mode 100755 mapcache/maptool.py delete mode 100644 mapcache/templates/collision.png delete mode 100644 mapcache/templates/example.tmx delete mode 100644 mapcache/templates/template.tmx delete mode 100644 mapcache/templates/tileset.png diff --git a/hercules/.gitignore b/hercules/.gitignore new file mode 100644 index 0000000..9092a2d --- /dev/null +++ b/hercules/.gitignore @@ -0,0 +1,3 @@ +clientdata +maps +serverdata diff --git a/hercules/cachetotmx.py b/hercules/cachetotmx.py new file mode 120000 index 0000000..df2b3e6 --- /dev/null +++ b/hercules/cachetotmx.py @@ -0,0 +1 @@ +maptool.py \ No newline at end of file diff --git a/hercules/extract.py b/hercules/extract.py new file mode 120000 index 0000000..df2b3e6 --- /dev/null +++ b/hercules/extract.py @@ -0,0 +1 @@ +maptool.py \ No newline at end of file diff --git a/hercules/list.py b/hercules/list.py new file mode 120000 index 0000000..df2b3e6 --- /dev/null +++ b/hercules/list.py @@ -0,0 +1 @@ +maptool.py \ No newline at end of file diff --git a/hercules/maptool.py b/hercules/maptool.py new file mode 100755 index 0000000..375a25d --- /dev/null +++ b/hercules/maptool.py @@ -0,0 +1,172 @@ +#! /usr/bin/env python +# -*- coding: utf8 -*- +# +# Copyright (C) 2014 Evol Online +# Author: Andrei Karas (4144) + +import array +import base64 +import gzip +import os +import re +import datetime +import xml +import csv +import ogg.vorbis +import StringIO +import sys +import zlib +import struct +import shutil + +def detectCommand(): + if sys.argv[0][-8:] == "/list.py": + return "list" + elif sys.argv[0][-11:] == "/extract.py": + return "extract" + elif sys.argv[0][-14:] == "/cachetotmx.py": + return "cachetotmx" + return "help" + +def makeDir(path): + if not os.path.exists(path): + os.makedirs(path) + +def readInt32(f): + data = f.read(4) + arr = array.array("I") + arr.fromstring(data) + return arr[0] + +def readInt16(f): + data = f.read(2) + arr = array.array("H") + arr.fromstring(data) + return arr[0] + +def readMapName(f): + data = f.read(12) + data = str(data) + while data[-1] == '\x00': + data = data[:-1] + return data + +def readData(f, sz): + return f.read(sz) + +def readFile(path): + with open(path, "r") as f: + return f.read() + +def getTile(mapData, x, y, sx): + data = mapData[y * sx + x] + arr = array.array("B") + arr.fromstring(data) + return arr[0] + +def getGroundTile(flag): + return str(flag + 1) + +def getCollisionTile(flag): + if flag == 0: + return "0" + return "4" + +def copyFile(src, dst, name): + shutil.copyfile(src + name, dst + name) + +def saveFile(fileName, data): + with open(fileName, "w") as w: + w.write(data) + +def printHelp(): + print "Unknown options selected." + print "" + print "Use list.py for list maps in cache" + print "Use extract.py to extract maps from cache" + exit(0) + +def listMapCache(f, mapsCount): + print "Known maps:" + print "{0:12} {1:<4}x {2:<4} {3:<10}".format("Map name", "sx", "sy", "compressed size") + for i in xrange(0, mapsCount): + name = readMapName(f) + sx = readInt16(f) + sy = readInt16(f) + sz = readInt32(f) + print "{0:12} {1:<4}x {2:<4} {3:<10}".format(name, sx, sy, sz) + f.seek(sz, 1) + +def extractMaps(f, mapsCount): + destDir = "maps/" + makeDir(destDir) + for i in xrange(0, mapsCount): + name = readMapName(f) + sx = readInt16(f) + sy = readInt16(f) + sz = readInt32(f) + data = readData(f, sz) + dc = zlib.decompressobj() + data = dc.decompress(data) + with open(destDir + name, "wb") as w: + w.write(struct.pack("H", sx)) + w.write(struct.pack("H", sy)) + w.write(data) + +def covertToTmx(f, mapsCount): + destDir = "clientdata/" + mapsDir = destDir + "maps/" + tilesetsDir = destDir + "graphics/tilesets/" + templatesDir = "templates/" + makeDir(mapsDir) + makeDir(tilesetsDir) + copyFile(templatesDir, tilesetsDir, "collision.png") + copyFile(templatesDir, tilesetsDir, "tileset.png") + tmx = readFile("templates/template.tmx") + for i in xrange(0, mapsCount): + name = readMapName(f) + print "converting map [{0:4}/{1:4}]: {2}".format(i, mapsCount + 1, name) + sx = readInt16(f) + sy = readInt16(f) + sz = readInt32(f) + mapData = readData(f, sz) + dc = zlib.decompressobj() + mapData = dc.decompress(mapData) + ground = "" + collision = "" + fringe = "" + for y in xrange(0, sy): + for x in xrange(0, sx): + tile = getTile(mapData, x, y, sx) + if x + 1 == sx and y + 1 == sy: + ground = ground + getGroundTile(tile) + collision = collision + getCollisionTile(tile) + fringe = fringe + "0"; + else: + ground = ground + getGroundTile(tile) + "," + collision = collision + getCollisionTile(tile) + "," + fringe = fringe + "0,"; + ground = ground + "\n" + collision = collision + "\n" + saveFile(mapsDir + name + ".tmx", tmx.format(sx, sy, ground, collision, fringe)) + +def readMapCache(path, cmd): + if cmd == "help": + printHelp() + with open(path, "rb") as f: + size = readInt32(f) + if os.path.getsize(path) != size: + print "Map cache corrupted, wrong file size." + exit(1) + mapsCount = readInt16(f) + print "Maps count: " + str(mapsCount) + readInt16(f) # padding + if cmd == "list": + listMapCache(f, mapsCount) + elif cmd == "extract": + extractMaps(f, mapsCount) + elif cmd == "cachetotmx": + covertToTmx(f, mapsCount) + + +readMapCache("serverdata/db/re/map_cache.dat", detectCommand()) diff --git a/hercules/templates/collision.png b/hercules/templates/collision.png new file mode 100644 index 0000000..f360c63 Binary files /dev/null and b/hercules/templates/collision.png differ diff --git a/hercules/templates/example.tmx b/hercules/templates/example.tmx new file mode 100644 index 0000000..1d14957 --- /dev/null +++ b/hercules/templates/example.tmx @@ -0,0 +1,38 @@ + + + + + + + + + + + +1,2,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0 + + + + +4,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0 + + + diff --git a/hercules/templates/template.tmx b/hercules/templates/template.tmx new file mode 100644 index 0000000..40d8d14 --- /dev/null +++ b/hercules/templates/template.tmx @@ -0,0 +1,25 @@ + + + + + + + + + + + +{2} + + + + +{4} + + + + +{3} + + + diff --git a/hercules/templates/tileset.png b/hercules/templates/tileset.png new file mode 100644 index 0000000..cee4071 Binary files /dev/null and b/hercules/templates/tileset.png differ diff --git a/mapcache/.gitignore b/mapcache/.gitignore deleted file mode 100644 index 9092a2d..0000000 --- a/mapcache/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -clientdata -maps -serverdata diff --git a/mapcache/cachetotmx.py b/mapcache/cachetotmx.py deleted file mode 120000 index df2b3e6..0000000 --- a/mapcache/cachetotmx.py +++ /dev/null @@ -1 +0,0 @@ -maptool.py \ No newline at end of file diff --git a/mapcache/extract.py b/mapcache/extract.py deleted file mode 120000 index df2b3e6..0000000 --- a/mapcache/extract.py +++ /dev/null @@ -1 +0,0 @@ -maptool.py \ No newline at end of file diff --git a/mapcache/list.py b/mapcache/list.py deleted file mode 120000 index df2b3e6..0000000 --- a/mapcache/list.py +++ /dev/null @@ -1 +0,0 @@ -maptool.py \ No newline at end of file diff --git a/mapcache/maptool.py b/mapcache/maptool.py deleted file mode 100755 index 375a25d..0000000 --- a/mapcache/maptool.py +++ /dev/null @@ -1,172 +0,0 @@ -#! /usr/bin/env python -# -*- coding: utf8 -*- -# -# Copyright (C) 2014 Evol Online -# Author: Andrei Karas (4144) - -import array -import base64 -import gzip -import os -import re -import datetime -import xml -import csv -import ogg.vorbis -import StringIO -import sys -import zlib -import struct -import shutil - -def detectCommand(): - if sys.argv[0][-8:] == "/list.py": - return "list" - elif sys.argv[0][-11:] == "/extract.py": - return "extract" - elif sys.argv[0][-14:] == "/cachetotmx.py": - return "cachetotmx" - return "help" - -def makeDir(path): - if not os.path.exists(path): - os.makedirs(path) - -def readInt32(f): - data = f.read(4) - arr = array.array("I") - arr.fromstring(data) - return arr[0] - -def readInt16(f): - data = f.read(2) - arr = array.array("H") - arr.fromstring(data) - return arr[0] - -def readMapName(f): - data = f.read(12) - data = str(data) - while data[-1] == '\x00': - data = data[:-1] - return data - -def readData(f, sz): - return f.read(sz) - -def readFile(path): - with open(path, "r") as f: - return f.read() - -def getTile(mapData, x, y, sx): - data = mapData[y * sx + x] - arr = array.array("B") - arr.fromstring(data) - return arr[0] - -def getGroundTile(flag): - return str(flag + 1) - -def getCollisionTile(flag): - if flag == 0: - return "0" - return "4" - -def copyFile(src, dst, name): - shutil.copyfile(src + name, dst + name) - -def saveFile(fileName, data): - with open(fileName, "w") as w: - w.write(data) - -def printHelp(): - print "Unknown options selected." - print "" - print "Use list.py for list maps in cache" - print "Use extract.py to extract maps from cache" - exit(0) - -def listMapCache(f, mapsCount): - print "Known maps:" - print "{0:12} {1:<4}x {2:<4} {3:<10}".format("Map name", "sx", "sy", "compressed size") - for i in xrange(0, mapsCount): - name = readMapName(f) - sx = readInt16(f) - sy = readInt16(f) - sz = readInt32(f) - print "{0:12} {1:<4}x {2:<4} {3:<10}".format(name, sx, sy, sz) - f.seek(sz, 1) - -def extractMaps(f, mapsCount): - destDir = "maps/" - makeDir(destDir) - for i in xrange(0, mapsCount): - name = readMapName(f) - sx = readInt16(f) - sy = readInt16(f) - sz = readInt32(f) - data = readData(f, sz) - dc = zlib.decompressobj() - data = dc.decompress(data) - with open(destDir + name, "wb") as w: - w.write(struct.pack("H", sx)) - w.write(struct.pack("H", sy)) - w.write(data) - -def covertToTmx(f, mapsCount): - destDir = "clientdata/" - mapsDir = destDir + "maps/" - tilesetsDir = destDir + "graphics/tilesets/" - templatesDir = "templates/" - makeDir(mapsDir) - makeDir(tilesetsDir) - copyFile(templatesDir, tilesetsDir, "collision.png") - copyFile(templatesDir, tilesetsDir, "tileset.png") - tmx = readFile("templates/template.tmx") - for i in xrange(0, mapsCount): - name = readMapName(f) - print "converting map [{0:4}/{1:4}]: {2}".format(i, mapsCount + 1, name) - sx = readInt16(f) - sy = readInt16(f) - sz = readInt32(f) - mapData = readData(f, sz) - dc = zlib.decompressobj() - mapData = dc.decompress(mapData) - ground = "" - collision = "" - fringe = "" - for y in xrange(0, sy): - for x in xrange(0, sx): - tile = getTile(mapData, x, y, sx) - if x + 1 == sx and y + 1 == sy: - ground = ground + getGroundTile(tile) - collision = collision + getCollisionTile(tile) - fringe = fringe + "0"; - else: - ground = ground + getGroundTile(tile) + "," - collision = collision + getCollisionTile(tile) + "," - fringe = fringe + "0,"; - ground = ground + "\n" - collision = collision + "\n" - saveFile(mapsDir + name + ".tmx", tmx.format(sx, sy, ground, collision, fringe)) - -def readMapCache(path, cmd): - if cmd == "help": - printHelp() - with open(path, "rb") as f: - size = readInt32(f) - if os.path.getsize(path) != size: - print "Map cache corrupted, wrong file size." - exit(1) - mapsCount = readInt16(f) - print "Maps count: " + str(mapsCount) - readInt16(f) # padding - if cmd == "list": - listMapCache(f, mapsCount) - elif cmd == "extract": - extractMaps(f, mapsCount) - elif cmd == "cachetotmx": - covertToTmx(f, mapsCount) - - -readMapCache("serverdata/db/re/map_cache.dat", detectCommand()) diff --git a/mapcache/templates/collision.png b/mapcache/templates/collision.png deleted file mode 100644 index f360c63..0000000 Binary files a/mapcache/templates/collision.png and /dev/null differ diff --git a/mapcache/templates/example.tmx b/mapcache/templates/example.tmx deleted file mode 100644 index 1d14957..0000000 --- a/mapcache/templates/example.tmx +++ /dev/null @@ -1,38 +0,0 @@ - - - - - - - - - - - -1,2,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0 - - - - -4,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0 - - - diff --git a/mapcache/templates/template.tmx b/mapcache/templates/template.tmx deleted file mode 100644 index 40d8d14..0000000 --- a/mapcache/templates/template.tmx +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - - - - - - -{2} - - - - -{4} - - - - -{3} - - - diff --git a/mapcache/templates/tileset.png b/mapcache/templates/tileset.png deleted file mode 100644 index cee4071..0000000 Binary files a/mapcache/templates/tileset.png and /dev/null differ -- cgit v1.2.3-70-g09d2