From c6095ad062eaa0f5576cfab1c4fe436b90c2fbfe Mon Sep 17 00:00:00 2001 From: Jesusaves Date: Sat, 10 Apr 2021 00:45:07 -0300 Subject: Add initial tools --- .gitignore | 92 + Makefile | 79 + client/dailylogin.py | 86 + client/minimap-dyecmd.py | 18 + client/minimap-dyecmd.sh | 261 + client/minimap-override/008-3-0.png | Bin 0 -> 10671 bytes client/minimap-render.py | 165 + client/weapons.py | 89 + hercules/.gitignore | 12 + hercules/code/__init__.py | 0 hercules/code/clienttoserver/__init__.py | 0 hercules/code/clienttoserver/maps.py | 190 + hercules/code/configutils.py | 51 + hercules/code/fileutils.py | 86 + hercules/code/server/__init__.py | 0 hercules/code/server/account.py | 63 + hercules/code/server/accreg.py | 52 + hercules/code/server/db/__init__.py | 0 hercules/code/server/db/char.py | 187 + hercules/code/server/db/charregnumdb.py | 34 + hercules/code/server/db/inventory.py | 44 + hercules/code/server/db/skill.py | 31 + hercules/code/server/dbitem.py | 7 + hercules/code/server/dbskill.py | 7 + hercules/code/server/dbuser.py | 7 + hercules/code/server/evol/__init__.py | 0 hercules/code/server/evol/athena.py | 207 + hercules/code/server/evol/consts.py | 49 + hercules/code/server/evol/itemdb.py | 104 + hercules/code/server/evol/main.py | 43 + hercules/code/server/evol/mobdb.py | 89 + hercules/code/server/evol/mobskilldb.py | 50 + hercules/code/server/evol/npcs.py | 281 + hercules/code/server/maps.py | 43 + hercules/code/server/party.py | 80 + hercules/code/server/questsdb.py | 33 + hercules/code/server/storage.py | 81 + hercules/code/server/tmw/__init__.py | 0 hercules/code/server/tmw/athena.py | 207 + hercules/code/server/tmw/consts.py | 129 + hercules/code/server/tmw/itemdb.py | 291 + hercules/code/server/tmw/main.py | 49 + hercules/code/server/tmw/mobdb.py | 173 + hercules/code/server/tmw/mobskilldb.py | 55 + hercules/code/server/tmw/npcs.py | 878 ++ hercules/code/server/utils.py | 12 + hercules/code/servertoclient/__init__.py | 0 hercules/code/servertoclient/groups.py | 185 + hercules/code/servertoclient/homunculuses.py | 31 + hercules/code/servertoclient/items.py | 138 + hercules/code/servertoclient/luas.py | 51 + hercules/code/servertoclient/maps.py | 48 + hercules/code/servertoclient/mercenaries.py | 31 + hercules/code/servertoclient/monsters.py | 43 + hercules/code/servertoclient/npcs.py | 29 + hercules/code/servertoclient/pets.py | 31 + hercules/code/servertoclient/quests.py | 39 + hercules/code/servertoclient/skills.py | 33 + hercules/code/servertoclient/sprites.py | 467 ++ hercules/code/serverutils.py | 12 + hercules/code/stringutils.py | 62 + hercules/code/tileutils.py | 48 + hercules/convert_db.py | 25 + hercules/convert_groups.py | 9 + hercules/convert_mapcache_to_tmx.py | 24 + hercules/convert_server.py | 30 + hercules/convert_server_to_client.py | 29 + hercules/convert_tmx_to_mapcache.py | 9 + hercules/extract_mapcache.py | 24 + hercules/import_newdb.sh | 24 + hercules/list_mapcache.py | 24 + hercules/templates/acc_reg_num_db.sql | 11 + hercules/templates/char.sql | 72 + hercules/templates/char_reg_num_db.sql | 11 + hercules/templates/collision.png | Bin 0 -> 275 bytes hercules/templates/constants.tpl | 45 + hercules/templates/group.tpl | 10 + hercules/templates/groups.xml | 7 + hercules/templates/homunculus.tpl | 3 + hercules/templates/homunculuses.xml | 6 + hercules/templates/inventory.sql | 23 + hercules/templates/item.tpl | 7 + hercules/templates/item_db.tpl | 63 + hercules/templates/items.xml | 148 + hercules/templates/login.sql | 25 + hercules/templates/mercenaries.xml | 6 + hercules/templates/mercenary.tpl | 3 + hercules/templates/mob_db.tpl | 101 + hercules/templates/mob_skill_db.tpl | 56 + hercules/templates/monster.tpl | 3 + hercules/templates/monsters.xml | 11 + hercules/templates/npc.tpl | 3 + hercules/templates/npcs.xml | 11 + hercules/templates/party.sql | 12 + hercules/templates/pet.tpl | 3 + hercules/templates/pets.xml | 6 + hercules/templates/quest.tpl | 5 + hercules/templates/quest_db.tpl | 5 + hercules/templates/quests.xml | 6 + hercules/templates/skill.sql | 10 + hercules/templates/skill.tpl | 1 + hercules/templates/skills.xml | 15 + hercules/templates/sprite.xml | 21 + hercules/templates/storage.sql | 22 + hercules/templates/template.tmx | 25 + hercules/templates/tileset.png | Bin 0 -> 3550 bytes hercules/tmx_converter.py | 550 ++ herculeswrapper/char.sh | 7 + herculeswrapper/herc-map-wrapper-config.example | 77 + herculeswrapper/include.sh | 287 + herculeswrapper/login.sh | 7 + herculeswrapper/map.sh | 102 + lang/fetch.py | 48 + lang/in/.gitignore | 1 + lang/out/.gitignore | 1 + lang/serverdata.pot | 9906 +++++++++++++++++++++++ lang/updatelang.py | 399 + lang_client/clientdata-beta.pot | 13 + lang_client/clientdata-dict.pot | 0 lang_client/clientdata.pot | 1687 ++++ lang_client/createpots.sh | 50 + lang_client/fetch.py | 58 + lang_client/its/avatars.xml | 8 + lang_client/its/clans.xml | 8 + lang_client/its/deadmessages.xml | 6 + lang_client/its/emotes.xml | 8 + lang_client/its/groups.xml | 9 + lang_client/its/homunculuses.xml | 8 + lang_client/its/itemcolors.xml | 7 + lang_client/its/itemfields.xml | 8 + lang_client/its/items.xml | 18 + lang_client/its/mercenaries.xml | 8 + lang_client/its/monsters.xml | 8 + lang_client/its/npcdialogs.xml | 8 + lang_client/its/npcs.xml | 8 + lang_client/its/pets.xml | 8 + lang_client/its/skills.xml | 10 + lang_client/its/skillunits.xml | 8 + lang_client/its/stats.xml | 11 + lang_client/its/status-effects.xml | 8 + lang_client/its/texts.xml | 7 + lang_client/its/tmx.xml | 8 + lang_client/processtmx.sh | 6 + localserver/.gitignore | 1 + localserver/README | 14 + localserver/build.sh | 6 + localserver/buildasan.sh | 5 + localserver/checktime.sh | 9 + localserver/clean.sh | 6 + localserver/conf/battle.conf | 32 + localserver/conf/char-server.conf | 31 + localserver/conf/constants.conf | 34 + localserver/conf/inter-server.conf | 32 + localserver/conf/login-server.conf | 32 + localserver/conf/logs.conf | 32 + localserver/conf/map-server.conf | 32 + localserver/conf/msg_conf.txt | 0 localserver/conf/ports.conf | 8 + localserver/conf/script.conf | 32 + localserver/conf/socket.conf | 32 + localserver/conf/sql_connection.conf | 52 + localserver/givegm.sh | 8 + localserver/initdb.sh | 26 + localserver/installconfigs.sh | 12 + localserver/npc/motd-debug-text.txt | 4 + localserver/updateconfigs.sh | 36 + localserver/updatedb.sh | 112 + update/addmods.sh | 32 + update/adler32.c | 79 + update/commit.txt | 1 + update/commit_old.txt | 1 + update/createnew.sh | 36 + update/evol_news.txt | 324 + update/musiccommit.txt | 1 + update/musicnew.sh | 31 + update/news.txt | 30 + update/update.sh | 39 + update/update_music.sh | 40 + 178 files changed, 21190 insertions(+) create mode 100644 .gitignore create mode 100644 Makefile create mode 100755 client/dailylogin.py create mode 100755 client/minimap-dyecmd.py create mode 100755 client/minimap-dyecmd.sh create mode 100644 client/minimap-override/008-3-0.png create mode 100755 client/minimap-render.py create mode 100755 client/weapons.py create mode 100644 hercules/.gitignore create mode 100644 hercules/code/__init__.py create mode 100644 hercules/code/clienttoserver/__init__.py create mode 100644 hercules/code/clienttoserver/maps.py create mode 100644 hercules/code/configutils.py create mode 100644 hercules/code/fileutils.py create mode 100644 hercules/code/server/__init__.py create mode 100644 hercules/code/server/account.py create mode 100644 hercules/code/server/accreg.py create mode 100644 hercules/code/server/db/__init__.py create mode 100644 hercules/code/server/db/char.py create mode 100644 hercules/code/server/db/charregnumdb.py create mode 100644 hercules/code/server/db/inventory.py create mode 100644 hercules/code/server/db/skill.py create mode 100644 hercules/code/server/dbitem.py create mode 100644 hercules/code/server/dbskill.py create mode 100644 hercules/code/server/dbuser.py create mode 100644 hercules/code/server/evol/__init__.py create mode 100644 hercules/code/server/evol/athena.py create mode 100644 hercules/code/server/evol/consts.py create mode 100644 hercules/code/server/evol/itemdb.py create mode 100644 hercules/code/server/evol/main.py create mode 100644 hercules/code/server/evol/mobdb.py create mode 100644 hercules/code/server/evol/mobskilldb.py create mode 100644 hercules/code/server/evol/npcs.py create mode 100644 hercules/code/server/maps.py create mode 100644 hercules/code/server/party.py create mode 100644 hercules/code/server/questsdb.py create mode 100644 hercules/code/server/storage.py create mode 100644 hercules/code/server/tmw/__init__.py create mode 100644 hercules/code/server/tmw/athena.py create mode 100644 hercules/code/server/tmw/consts.py create mode 100644 hercules/code/server/tmw/itemdb.py create mode 100644 hercules/code/server/tmw/main.py create mode 100644 hercules/code/server/tmw/mobdb.py create mode 100644 hercules/code/server/tmw/mobskilldb.py create mode 100644 hercules/code/server/tmw/npcs.py create mode 100644 hercules/code/server/utils.py create mode 100644 hercules/code/servertoclient/__init__.py create mode 100644 hercules/code/servertoclient/groups.py create mode 100644 hercules/code/servertoclient/homunculuses.py create mode 100644 hercules/code/servertoclient/items.py create mode 100644 hercules/code/servertoclient/luas.py create mode 100644 hercules/code/servertoclient/maps.py create mode 100644 hercules/code/servertoclient/mercenaries.py create mode 100644 hercules/code/servertoclient/monsters.py create mode 100644 hercules/code/servertoclient/npcs.py create mode 100644 hercules/code/servertoclient/pets.py create mode 100644 hercules/code/servertoclient/quests.py create mode 100644 hercules/code/servertoclient/skills.py create mode 100644 hercules/code/servertoclient/sprites.py create mode 100644 hercules/code/serverutils.py create mode 100644 hercules/code/stringutils.py create mode 100644 hercules/code/tileutils.py create mode 100755 hercules/convert_db.py create mode 100755 hercules/convert_groups.py create mode 100755 hercules/convert_mapcache_to_tmx.py create mode 100755 hercules/convert_server.py create mode 100755 hercules/convert_server_to_client.py create mode 100755 hercules/convert_tmx_to_mapcache.py create mode 100755 hercules/extract_mapcache.py create mode 100755 hercules/import_newdb.sh create mode 100755 hercules/list_mapcache.py create mode 100644 hercules/templates/acc_reg_num_db.sql create mode 100644 hercules/templates/char.sql create mode 100644 hercules/templates/char_reg_num_db.sql create mode 100644 hercules/templates/collision.png create mode 100644 hercules/templates/constants.tpl create mode 100644 hercules/templates/group.tpl create mode 100644 hercules/templates/groups.xml create mode 100644 hercules/templates/homunculus.tpl create mode 100644 hercules/templates/homunculuses.xml create mode 100644 hercules/templates/inventory.sql create mode 100644 hercules/templates/item.tpl create mode 100644 hercules/templates/item_db.tpl create mode 100644 hercules/templates/items.xml create mode 100644 hercules/templates/login.sql create mode 100644 hercules/templates/mercenaries.xml create mode 100644 hercules/templates/mercenary.tpl create mode 100644 hercules/templates/mob_db.tpl create mode 100644 hercules/templates/mob_skill_db.tpl create mode 100644 hercules/templates/monster.tpl create mode 100644 hercules/templates/monsters.xml create mode 100644 hercules/templates/npc.tpl create mode 100644 hercules/templates/npcs.xml create mode 100644 hercules/templates/party.sql create mode 100644 hercules/templates/pet.tpl create mode 100644 hercules/templates/pets.xml create mode 100644 hercules/templates/quest.tpl create mode 100644 hercules/templates/quest_db.tpl create mode 100644 hercules/templates/quests.xml create mode 100644 hercules/templates/skill.sql create mode 100644 hercules/templates/skill.tpl create mode 100644 hercules/templates/skills.xml create mode 100644 hercules/templates/sprite.xml create mode 100644 hercules/templates/storage.sql create mode 100644 hercules/templates/template.tmx create mode 100644 hercules/templates/tileset.png create mode 100755 hercules/tmx_converter.py create mode 100755 herculeswrapper/char.sh create mode 100644 herculeswrapper/herc-map-wrapper-config.example create mode 100644 herculeswrapper/include.sh create mode 100755 herculeswrapper/login.sh create mode 100755 herculeswrapper/map.sh create mode 100755 lang/fetch.py create mode 100644 lang/in/.gitignore create mode 100644 lang/out/.gitignore create mode 100644 lang/serverdata.pot create mode 100755 lang/updatelang.py create mode 100644 lang_client/clientdata-beta.pot create mode 100644 lang_client/clientdata-dict.pot create mode 100644 lang_client/clientdata.pot create mode 100755 lang_client/createpots.sh create mode 100755 lang_client/fetch.py create mode 100644 lang_client/its/avatars.xml create mode 100644 lang_client/its/clans.xml create mode 100644 lang_client/its/deadmessages.xml create mode 100644 lang_client/its/emotes.xml create mode 100644 lang_client/its/groups.xml create mode 100644 lang_client/its/homunculuses.xml create mode 100644 lang_client/its/itemcolors.xml create mode 100644 lang_client/its/itemfields.xml create mode 100644 lang_client/its/items.xml create mode 100644 lang_client/its/mercenaries.xml create mode 100644 lang_client/its/monsters.xml create mode 100644 lang_client/its/npcdialogs.xml create mode 100644 lang_client/its/npcs.xml create mode 100644 lang_client/its/pets.xml create mode 100644 lang_client/its/skills.xml create mode 100644 lang_client/its/skillunits.xml create mode 100644 lang_client/its/stats.xml create mode 100644 lang_client/its/status-effects.xml create mode 100644 lang_client/its/texts.xml create mode 100644 lang_client/its/tmx.xml create mode 100755 lang_client/processtmx.sh create mode 100644 localserver/.gitignore create mode 100644 localserver/README create mode 100755 localserver/build.sh create mode 100755 localserver/buildasan.sh create mode 100755 localserver/checktime.sh create mode 100755 localserver/clean.sh create mode 100644 localserver/conf/battle.conf create mode 100644 localserver/conf/char-server.conf create mode 100644 localserver/conf/constants.conf create mode 100644 localserver/conf/inter-server.conf create mode 100644 localserver/conf/login-server.conf create mode 100644 localserver/conf/logs.conf create mode 100644 localserver/conf/map-server.conf create mode 100644 localserver/conf/msg_conf.txt create mode 100644 localserver/conf/ports.conf create mode 100644 localserver/conf/script.conf create mode 100644 localserver/conf/socket.conf create mode 100644 localserver/conf/sql_connection.conf create mode 100755 localserver/givegm.sh create mode 100755 localserver/initdb.sh create mode 100755 localserver/installconfigs.sh create mode 100644 localserver/npc/motd-debug-text.txt create mode 100755 localserver/updateconfigs.sh create mode 100755 localserver/updatedb.sh create mode 100755 update/addmods.sh create mode 100644 update/adler32.c create mode 100644 update/commit.txt create mode 100644 update/commit_old.txt create mode 100755 update/createnew.sh create mode 100644 update/evol_news.txt create mode 100644 update/musiccommit.txt create mode 100755 update/musicnew.sh create mode 100644 update/news.txt create mode 100755 update/update.sh create mode 100755 update/update_music.sh diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..afc3351 --- /dev/null +++ b/.gitignore @@ -0,0 +1,92 @@ +# temp files +*.xml~ +*.py~ +*.txt~ +*.conf~ +*deploy.sh +*~ +._* + +# updates +update/files +update/upload +!update/adler32.c +update/adler32 +update/files/Bugfix-* +update/save* + +hercules_update/files +hercules_update/upload +!hercules_update/adler32.c +hercules_update/adler32 + +# saedit +saedit/saedit +saedit/make.log + +# langs +lang/tx +lang/new +login.txt +password.txt + +# lang client +lang_client/tmp +lang_client/pot +lang_client/dict + +# tx +tx + +# temp files +*.o +localserver/.~* + +# dyecmd +dyecmd/dyecmd +dyecmd/src/dyecmd +dyecmd/src/CMakeFiles/ +dyecmd/src/Makefile +dyecmd/src/cmake_install.cmake + +# testxml +testxml/errors.txt + +# gitlab merger +herculeswrapper/herc-map-wrapper-config + +# license check +licensecheck/npcs.txt + +# wiki +wiki/Items.md +wiki/Monsters.md +wiki/*.html +wiki/*.txt + +# web +1index.bin +backup.bin +web/po/* + +# Proccessed other server data +hercules/data* +hercules/osd* +hercules/old* + +# Diffs and Patches related files +*.diff +*.patch +*.orig +*.rej + +# Jesusalva's personal stuff +misc/* +update/*back* +lang/in/JSave + +# Beta Server +localserver/beta.patch +localserver/beta.patch2 +manaplus/* + diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..4e9e5a8 --- /dev/null +++ b/Makefile @@ -0,0 +1,79 @@ +XSLTPROC = xsltproc + +all: + @echo "Current makes:" + @echo "contrib - makes contributors list for wiki and client-data" + @echo "testxml - performs a minimal XML test" + @echo "wiki - makes wiki automated databases" + @echo "maps - makes server-data information" + @echo "update - makes update and propagate web information (untested)" + @echo "news - propagate web information" + @echo "translation - fetches Transifex translations for server, and updates both." + @echo "client - generate weapons.xml and daily.xml" + @echo "full - make contrib + wiki + translation + client + update + news" + +contrib: + cd contrib_xsl ; make + @echo "Please commit the result on wiki and clientdata." + +.PHONY: testxml +testxml: + cd testxml ; ./testxml.py silent |grep -v "Checking" + +.PHONY: wiki +wiki: + cd wiki ; ./wikigen.py + cd wiki ; mv *.md ../../wiki/ + @echo "Wiki files updated, please commit the result on wiki." + +.PHONY: maps +maps: + cd hercules ; ./tmx_converter.py ../../client-data/ ../../server-data + cd hercules ; ./convert_tmx_to_mapcache.py + @echo "Please commit the result on serverdata." + +.PHONY: update +update: + @cd ../web ; echo "Checking for web/ folder..." # check if web directory exists + cd update ; ./update.sh + cd wiki ; ./elegen.py ; mv EleMonsters.html ../../web/Monsters.html + cd web ; ./deploy.sh + @echo "Update deployed, please move upload/ and commit result on web." + @echo "Don't forget to make translations, client, news and wiki too!" + +translation: + @echo "Fetching server translations, ensure lang/login.txt and lang/password.txt exists..." + cd lang/ ; ./fetch.py + @echo "Updating server translations and preparing for pull..." + cd lang/ ; ./updatelang.py + @echo "Fetching client translations, ensure lang/login.txt and lang/password.txt exists..." + cd lang_client/ ; ./fetch.py + @echo "Updating client translations and preparing for pull..." + cd lang_client/ ; ./createpots.sh + @echo "Translations updated, please commit result on server-data, client-data and tools." + +.PHONY: news +news: + @cd ../web ; echo "Checking for web/ folder..." # check if web directory exists + cd web ; ./deploy.sh + @echo "News updated, please commit result on web." + +.PHONY: client +client: + @cd client ; ./weapons.py + @cd client ; mv weapons.tmp ../../client-data/weapons.xml + @cd client ; ./minimap-render.py all + @cd client ; ./minimap-dyecmd.py ; ./minimap-dyecmd.sh + cp client/minimap-override/* ../client-data/graphics/minimaps/ + @echo "XML files and minimaps updated, please commit result on client-data." + +.PHONY: full +full: + @echo "full - make contrib + wiki + translation + client + update + news" + make contrib + make wiki + make translation + make client + make update + make news + diff --git a/client/dailylogin.py b/client/dailylogin.py new file mode 100755 index 0000000..fc9296f --- /dev/null +++ b/client/dailylogin.py @@ -0,0 +1,86 @@ +#!/usr/bin/python2.7 + +# Setup +x=y=0 +i=j=0 + +# Functions +def headers(val): + return '\n\t\n\t\t\n\t\t\t\n \n\t\n' + +def override_check(vl, over, text1, text2): + global j + if not over: + j=0 + return '\t\t\t\n' % (text1, text2) + else: + j+=1 + if (j == vl): + return '\t\t\t\n' % (text1) + elif (j < vl): + return '\t\t\t\n' % (text1) + else: + return "" + +def spammer(val, override=False): + bf="" + + bf+=override_check(val, override, 'x="35" y="35"', 'jexp') + bf+=override_check(val, override, 'x="70" y="35"', 'bexp') + bf+=override_check(val, override, 'x="105" y="35"', 'sc') + bf+=override_check(val, override, 'x="140" y="35"', 'jexp') + bf+=override_check(val, override, 'x="175" y="35"', 'bexp') + + bf+=override_check(val, override, 'x="35" y="70"', 'gp') + bf+=override_check(val, override, 'x="70" y="70"', 'sc') + bf+=override_check(val, override, 'x="105" y="70"', 'bexp') + bf+=override_check(val, override, 'x="140" y="70"', 'gp') + bf+=override_check(val, override, 'x="175" y="70"', 'jexp') + + bf+=override_check(val, override, 'x="35" y="105"', 'bexp') + bf+=override_check(val, override, 'x="70" y="105"', 'gp') + bf+=override_check(val, override, 'x="105" y="105"', 'jexp') + bf+=override_check(val, override, 'x="140" y="105"', 'gift') + bf+=override_check(val, override, 'x="175" y="105"', 'gp') + + bf+=override_check(val, override, 'x="35" y="140"', 'jexp') + bf+=override_check(val, override, 'x="70" y="140"', 'bexp') + bf+=override_check(val, override, 'x="105" y="140"', 'gp') + bf+=override_check(val, override, 'x="140" y="140"', 'jexp') + bf+=override_check(val, override, 'x="175" y="140"', 'bexp') + + bf+=override_check(val, override, 'x="35" y="175"', 'gift') + bf+=override_check(val, override, 'x="70" y="175"', 'jexp') + bf+=override_check(val, override, 'x="105" y="175"', 'bexp') + bf+=override_check(val, override, 'x="140" y="175"', 'gp') + bf+=override_check(val, override, 'x="175" y="175"', 'jexp') + + bf+=override_check(val, override, 'x="35" y="210"', 'bexp') + bf+=override_check(val, override, 'x="70" y="210"', 'gp') + bf+=override_check(val, override, 'x="105" y="210"', 'last') + bf+=override_check(val, override, 'x="140" y="210"', 'sc') + bf+=override_check(val, override, 'x="175" y="210"', 'sc') + + bf+=override_check(val, override, 'x="35" y="245"', 'sc') + + return bf + +# Begin +f=open("daily.tmp", "w") + +f.write('\n\n') + +while (i < 31): + i+=1 + f.write(headers(i)) + f.write(spammer(i, False)) + f.write('\n\t\t\t\n\n\t\t\t\n') + f.write(spammer(i, True)) + f.write(tail()) + +f.write('\n') +f.close() + diff --git a/client/minimap-dyecmd.py b/client/minimap-dyecmd.py new file mode 100755 index 0000000..8f3e0c7 --- /dev/null +++ b/client/minimap-dyecmd.py @@ -0,0 +1,18 @@ +#!/usr/bin/env python +#-*- coding:utf-8 -*- + +import os +f=open("minimap-dyecmd.sh", "w"); +CLIENT_DATA_ROOT="../../client-data" + +map_names = sorted([os.path.splitext(p)[0] for p in os.listdir(os.path.join(CLIENT_DATA_ROOT, u'graphics', u'minimaps'))]) + +f.write('cd '+os.path.join(CLIENT_DATA_ROOT, u'graphics', u'minimaps')+'\n') +for c in map_names: + if os.path.exists(os.path.join(CLIENT_DATA_ROOT, u'graphics', u'minimaps', c+u'.png')): + i=c+u'.png' + f.write("dyecmd %s tmp ; mv tmp %s\n" % (i, i)) + f.write("echo \"Converted "+i+" successfully.\"\n") + +#f.write("git checkout -- minimap-dyecmd.sh") +f.close() diff --git a/client/minimap-dyecmd.sh b/client/minimap-dyecmd.sh new file mode 100755 index 0000000..4c3f1e0 --- /dev/null +++ b/client/minimap-dyecmd.sh @@ -0,0 +1,261 @@ +cd ../../client-data/graphics/minimaps +dyecmd 000-1.png tmp ; mv tmp 000-1.png +echo "Converted 000-1.png successfully." +dyecmd 001-1.png tmp ; mv tmp 001-1.png +echo "Converted 001-1.png successfully." +dyecmd 001-2.png tmp ; mv tmp 001-2.png +echo "Converted 001-2.png successfully." +dyecmd 001-3.png tmp ; mv tmp 001-3.png +echo "Converted 001-3.png successfully." +dyecmd 002-1.png tmp ; mv tmp 002-1.png +echo "Converted 002-1.png successfully." +dyecmd 002-2.png tmp ; mv tmp 002-2.png +echo "Converted 002-2.png successfully." +dyecmd 002-3.png tmp ; mv tmp 002-3.png +echo "Converted 002-3.png successfully." +dyecmd 002-4.png tmp ; mv tmp 002-4.png +echo "Converted 002-4.png successfully." +dyecmd 002-5.png tmp ; mv tmp 002-5.png +echo "Converted 002-5.png successfully." +dyecmd 003-1.png tmp ; mv tmp 003-1.png +echo "Converted 003-1.png successfully." +dyecmd 003-4.png tmp ; mv tmp 003-4.png +echo "Converted 003-4.png successfully." +dyecmd 004-1.png tmp ; mv tmp 004-1.png +echo "Converted 004-1.png successfully." +dyecmd 004-3.png tmp ; mv tmp 004-3.png +echo "Converted 004-3.png successfully." +dyecmd 004-4.png tmp ; mv tmp 004-4.png +echo "Converted 004-4.png successfully." +dyecmd 004-5.png tmp ; mv tmp 004-5.png +echo "Converted 004-5.png successfully." +dyecmd 005-3.png tmp ; mv tmp 005-3.png +echo "Converted 005-3.png successfully." +dyecmd 006-1.png tmp ; mv tmp 006-1.png +echo "Converted 006-1.png successfully." +dyecmd 006-2.png tmp ; mv tmp 006-2.png +echo "Converted 006-2.png successfully." +dyecmd 006-3.png tmp ; mv tmp 006-3.png +echo "Converted 006-3.png successfully." +dyecmd 007-1.png tmp ; mv tmp 007-1.png +echo "Converted 007-1.png successfully." +dyecmd 007-2.png tmp ; mv tmp 007-2.png +echo "Converted 007-2.png successfully." +dyecmd 008-1.png tmp ; mv tmp 008-1.png +echo "Converted 008-1.png successfully." +dyecmd 009-1.png tmp ; mv tmp 009-1.png +echo "Converted 009-1.png successfully." +dyecmd 009-2.png tmp ; mv tmp 009-2.png +echo "Converted 009-2.png successfully." +dyecmd 009-3.png tmp ; mv tmp 009-3.png +echo "Converted 009-3.png successfully." +dyecmd 009-4.png tmp ; mv tmp 009-4.png +echo "Converted 009-4.png successfully." +dyecmd 009-5.png tmp ; mv tmp 009-5.png +echo "Converted 009-5.png successfully." +dyecmd 009-6.png tmp ; mv tmp 009-6.png +echo "Converted 009-6.png successfully." +dyecmd 009-7.png tmp ; mv tmp 009-7.png +echo "Converted 009-7.png successfully." +dyecmd 009-8.png tmp ; mv tmp 009-8.png +echo "Converted 009-8.png successfully." +dyecmd 010-1.png tmp ; mv tmp 010-1.png +echo "Converted 010-1.png successfully." +dyecmd 010-2.png tmp ; mv tmp 010-2.png +echo "Converted 010-2.png successfully." +dyecmd 011-1.png tmp ; mv tmp 011-1.png +echo "Converted 011-1.png successfully." +dyecmd 011-3.png tmp ; mv tmp 011-3.png +echo "Converted 011-3.png successfully." +dyecmd 011-4.png tmp ; mv tmp 011-4.png +echo "Converted 011-4.png successfully." +dyecmd 011-6.png tmp ; mv tmp 011-6.png +echo "Converted 011-6.png successfully." +dyecmd 012-1.png tmp ; mv tmp 012-1.png +echo "Converted 012-1.png successfully." +dyecmd 012-3.png tmp ; mv tmp 012-3.png +echo "Converted 012-3.png successfully." +dyecmd 012-4.png tmp ; mv tmp 012-4.png +echo "Converted 012-4.png successfully." +dyecmd 013-1.png tmp ; mv tmp 013-1.png +echo "Converted 013-1.png successfully." +dyecmd 013-2.png tmp ; mv tmp 013-2.png +echo "Converted 013-2.png successfully." +dyecmd 013-3.png tmp ; mv tmp 013-3.png +echo "Converted 013-3.png successfully." +dyecmd 014-1.png tmp ; mv tmp 014-1.png +echo "Converted 014-1.png successfully." +dyecmd 014-3.png tmp ; mv tmp 014-3.png +echo "Converted 014-3.png successfully." +dyecmd 015-1.png tmp ; mv tmp 015-1.png +echo "Converted 015-1.png successfully." +dyecmd 015-3.png tmp ; mv tmp 015-3.png +echo "Converted 015-3.png successfully." +dyecmd 016-1.png tmp ; mv tmp 016-1.png +echo "Converted 016-1.png successfully." +dyecmd 016-2.png tmp ; mv tmp 016-2.png +echo "Converted 016-2.png successfully." +dyecmd 017-1.png tmp ; mv tmp 017-1.png +echo "Converted 017-1.png successfully." +dyecmd 017-2.png tmp ; mv tmp 017-2.png +echo "Converted 017-2.png successfully." +dyecmd 017-3.png tmp ; mv tmp 017-3.png +echo "Converted 017-3.png successfully." +dyecmd 017-4.png tmp ; mv tmp 017-4.png +echo "Converted 017-4.png successfully." +dyecmd 017-9.png tmp ; mv tmp 017-9.png +echo "Converted 017-9.png successfully." +dyecmd 018-1.png tmp ; mv tmp 018-1.png +echo "Converted 018-1.png successfully." +dyecmd 018-2.png tmp ; mv tmp 018-2.png +echo "Converted 018-2.png successfully." +dyecmd 018-3.png tmp ; mv tmp 018-3.png +echo "Converted 018-3.png successfully." +dyecmd 019-1.png tmp ; mv tmp 019-1.png +echo "Converted 019-1.png successfully." +dyecmd 019-3.png tmp ; mv tmp 019-3.png +echo "Converted 019-3.png successfully." +dyecmd 019-4.png tmp ; mv tmp 019-4.png +echo "Converted 019-4.png successfully." +dyecmd 020-1.png tmp ; mv tmp 020-1.png +echo "Converted 020-1.png successfully." +dyecmd 020-2.png tmp ; mv tmp 020-2.png +echo "Converted 020-2.png successfully." +dyecmd 020-3.png tmp ; mv tmp 020-3.png +echo "Converted 020-3.png successfully." +dyecmd 021-3.png tmp ; mv tmp 021-3.png +echo "Converted 021-3.png successfully." +dyecmd 023-1.png tmp ; mv tmp 023-1.png +echo "Converted 023-1.png successfully." +dyecmd 023-2.png tmp ; mv tmp 023-2.png +echo "Converted 023-2.png successfully." +dyecmd 023-3.png tmp ; mv tmp 023-3.png +echo "Converted 023-3.png successfully." +dyecmd 025-1.png tmp ; mv tmp 025-1.png +echo "Converted 025-1.png successfully." +dyecmd 025-3.png tmp ; mv tmp 025-3.png +echo "Converted 025-3.png successfully." +dyecmd 025-4.png tmp ; mv tmp 025-4.png +echo "Converted 025-4.png successfully." +dyecmd 026-1.png tmp ; mv tmp 026-1.png +echo "Converted 026-1.png successfully." +dyecmd 026-2.png tmp ; mv tmp 026-2.png +echo "Converted 026-2.png successfully." +dyecmd 027-1.png tmp ; mv tmp 027-1.png +echo "Converted 027-1.png successfully." +dyecmd 027-2.png tmp ; mv tmp 027-2.png +echo "Converted 027-2.png successfully." +dyecmd 027-3.png tmp ; mv tmp 027-3.png +echo "Converted 027-3.png successfully." +dyecmd 027-4.png tmp ; mv tmp 027-4.png +echo "Converted 027-4.png successfully." +dyecmd 027-5.png tmp ; mv tmp 027-5.png +echo "Converted 027-5.png successfully." +dyecmd 027-6.png tmp ; mv tmp 027-6.png +echo "Converted 027-6.png successfully." +dyecmd 027-7.png tmp ; mv tmp 027-7.png +echo "Converted 027-7.png successfully." +dyecmd 027-8.png tmp ; mv tmp 027-8.png +echo "Converted 027-8.png successfully." +dyecmd 028-1.png tmp ; mv tmp 028-1.png +echo "Converted 028-1.png successfully." +dyecmd 028-3.png tmp ; mv tmp 028-3.png +echo "Converted 028-3.png successfully." +dyecmd 029-1.png tmp ; mv tmp 029-1.png +echo "Converted 029-1.png successfully." +dyecmd 029-2.png tmp ; mv tmp 029-2.png +echo "Converted 029-2.png successfully." +dyecmd 029-3.png tmp ; mv tmp 029-3.png +echo "Converted 029-3.png successfully." +dyecmd 029-4.png tmp ; mv tmp 029-4.png +echo "Converted 029-4.png successfully." +dyecmd 030-1.png tmp ; mv tmp 030-1.png +echo "Converted 030-1.png successfully." +dyecmd 030-2.png tmp ; mv tmp 030-2.png +echo "Converted 030-2.png successfully." +dyecmd 030-3.png tmp ; mv tmp 030-3.png +echo "Converted 030-3.png successfully." +dyecmd 030-4.png tmp ; mv tmp 030-4.png +echo "Converted 030-4.png successfully." +dyecmd 031-1.png tmp ; mv tmp 031-1.png +echo "Converted 031-1.png successfully." +dyecmd 031-2.png tmp ; mv tmp 031-2.png +echo "Converted 031-2.png successfully." +dyecmd 031-3.png tmp ; mv tmp 031-3.png +echo "Converted 031-3.png successfully." +dyecmd 031-4.png tmp ; mv tmp 031-4.png +echo "Converted 031-4.png successfully." +dyecmd 032-3.png tmp ; mv tmp 032-3.png +echo "Converted 032-3.png successfully." +dyecmd 033-1.png tmp ; mv tmp 033-1.png +echo "Converted 033-1.png successfully." +dyecmd 034-1.png tmp ; mv tmp 034-1.png +echo "Converted 034-1.png successfully." +dyecmd 034-2.png tmp ; mv tmp 034-2.png +echo "Converted 034-2.png successfully." +dyecmd 035-2.png tmp ; mv tmp 035-2.png +echo "Converted 035-2.png successfully." +dyecmd 036-2.png tmp ; mv tmp 036-2.png +echo "Converted 036-2.png successfully." +dyecmd 041-1.png tmp ; mv tmp 041-1.png +echo "Converted 041-1.png successfully." +dyecmd 042-1.png tmp ; mv tmp 042-1.png +echo "Converted 042-1.png successfully." +dyecmd 043-1.png tmp ; mv tmp 043-1.png +echo "Converted 043-1.png successfully." +dyecmd 043-3.png tmp ; mv tmp 043-3.png +echo "Converted 043-3.png successfully." +dyecmd 043-4.png tmp ; mv tmp 043-4.png +echo "Converted 043-4.png successfully." +dyecmd 045-1.png tmp ; mv tmp 045-1.png +echo "Converted 045-1.png successfully." +dyecmd 046-1.png tmp ; mv tmp 046-1.png +echo "Converted 046-1.png successfully." +dyecmd 046-3.png tmp ; mv tmp 046-3.png +echo "Converted 046-3.png successfully." +dyecmd 047-1.png tmp ; mv tmp 047-1.png +echo "Converted 047-1.png successfully." +dyecmd 047-3.png tmp ; mv tmp 047-3.png +echo "Converted 047-3.png successfully." +dyecmd 048-2.png tmp ; mv tmp 048-2.png +echo "Converted 048-2.png successfully." +dyecmd 051-1.png tmp ; mv tmp 051-1.png +echo "Converted 051-1.png successfully." +dyecmd 051-3.png tmp ; mv tmp 051-3.png +echo "Converted 051-3.png successfully." +dyecmd 052-1.png tmp ; mv tmp 052-1.png +echo "Converted 052-1.png successfully." +dyecmd 052-2.png tmp ; mv tmp 052-2.png +echo "Converted 052-2.png successfully." +dyecmd 055-1.png tmp ; mv tmp 055-1.png +echo "Converted 055-1.png successfully." +dyecmd 055-3.png tmp ; mv tmp 055-3.png +echo "Converted 055-3.png successfully." +dyecmd 056-2.png tmp ; mv tmp 056-2.png +echo "Converted 056-2.png successfully." +dyecmd 057-1.png tmp ; mv tmp 057-1.png +echo "Converted 057-1.png successfully." +dyecmd 069-2.png tmp ; mv tmp 069-2.png +echo "Converted 069-2.png successfully." +dyecmd 070-1.png tmp ; mv tmp 070-1.png +echo "Converted 070-1.png successfully." +dyecmd 070-3.png tmp ; mv tmp 070-3.png +echo "Converted 070-3.png successfully." +dyecmd 099-1.png tmp ; mv tmp 099-1.png +echo "Converted 099-1.png successfully." +dyecmd 099-2.png tmp ; mv tmp 099-2.png +echo "Converted 099-2.png successfully." +dyecmd 099-3.png tmp ; mv tmp 099-3.png +echo "Converted 099-3.png successfully." +dyecmd 099-4.png tmp ; mv tmp 099-4.png +echo "Converted 099-4.png successfully." +dyecmd 099-5.png tmp ; mv tmp 099-5.png +echo "Converted 099-5.png successfully." +dyecmd 099-6.png tmp ; mv tmp 099-6.png +echo "Converted 099-6.png successfully." +dyecmd 099-7.png tmp ; mv tmp 099-7.png +echo "Converted 099-7.png successfully." +dyecmd 099-8.png tmp ; mv tmp 099-8.png +echo "Converted 099-8.png successfully." +dyecmd botcheck.png tmp ; mv tmp botcheck.png +echo "Converted botcheck.png successfully." diff --git a/client/minimap-override/008-3-0.png b/client/minimap-override/008-3-0.png new file mode 100644 index 0000000..fa94222 Binary files /dev/null and b/client/minimap-override/008-3-0.png differ diff --git a/client/minimap-render.py b/client/minimap-render.py new file mode 100755 index 0000000..716e9e3 --- /dev/null +++ b/client/minimap-render.py @@ -0,0 +1,165 @@ +#!/usr/bin/env python +#-*- coding:utf-8 -*- + +import sys +import os +import subprocess +import tempfile + +CLIENT_DATA_ROOT = os.path.realpath( + os.path.join( + os.path.dirname(__file__), + u'../../client-data', + ) +) + +class MinimapRenderer(object): + + PROGRAMS = { + 'default': { + 'tmxrasterizer': 'tmxrasterizer', + 'im_convert': 'convert', + }, + 'win32': { + 'tmxrasterizer': 'tmxrasterizer.exe', + 'im_convert': 'convert.exe', + }, + } + + def __init__(self, map_name, tilesize, useAntiAliasing): + self.map_name = map_name + self.tilesize = tilesize + self.useAntiAliasing = useAntiAliasing + + def render(self): + """ + Processes a map + """ + if not os.path.exists(os.path.join(CLIENT_DATA_ROOT, u'maps', self.map_name+u'.tmx')): + sys.stderr.write(u'Invalid map name: %s. Skipping.\n' % self.map_name) + return 1 + if not self.map_name.endswith(u'.tmx'): + self.map_name = self.map_name+u'.tmx' + + map_number = os.path.splitext(os.path.basename(self.map_name))[0] + tmx_file = os.path.join(CLIENT_DATA_ROOT, u'maps', self.map_name) + minimap_file = os.path.join(CLIENT_DATA_ROOT, u'graphics', u'minimaps', map_number+u'.png') + + prefix = os.path.commonprefix((tmx_file, minimap_file)) + sys.stdout.write(u'%s -> %s\n' % (os.path.relpath(tmx_file, prefix), os.path.relpath(minimap_file, prefix))) + + try: + self.do_render(tmx_file, minimap_file) + except Exception as e: + sys.stderr.write(u'\x1b[31m\x1b[1mError while rendering %s: %s\x1b[0m\n' % (self.map_name, e)) + return 1 + else: + return 0 + + def do_render(self, tmx_file, bitmap_file): + """ + The map rendering implementation + """ + platform_programs = MinimapRenderer.PROGRAMS.get(sys.platform, MinimapRenderer.PROGRAMS.get('default')) + # tmx rasterize + mrf, map_raster = tempfile.mkstemp(suffix='.png') + tmxrasterizer_cmd = [ + platform_programs.get('tmxrasterizer'), + '--tilesize', str(self.tilesize), '--hide-layer', 'Collision','--hide-layer', 'Height','--hide-layer', 'Collisions','--hide-layer', 'collision','--hide-layer', 'height','--hide-layer', 'Heights', '--hide-layer', 'height', '--ignore-visibility', + ] + if self.useAntiAliasing: + tmxrasterizer_cmd.append('--anti-aliasing') + tmxrasterizer_cmd += [tmx_file, map_raster] + subprocess.check_call(tmxrasterizer_cmd) + if os.stat(map_raster).st_size == 0: + raise Exception('A problem was encountered when rendering a map') + # add cell-shading to the minimap to improve readability + ebf, edges_bitmap = tempfile.mkstemp(suffix='.png') + subprocess.check_call([ + platform_programs.get('im_convert'), map_raster, + '-set', 'option:convolve:scale', '-1!', + '-morphology', 'Convolve', 'Laplacian:0', + '-colorspace', 'gray', + '-auto-level', + '-threshold', '2.8%', + '-negate', + '-transparent', 'white', + edges_bitmap + ]) + subprocess.check_call([ + platform_programs.get('im_convert'), map_raster, edges_bitmap, + '-compose', 'Dissolve', + '-define', 'compose:args=35', + '-composite', + bitmap_file + ]) + os.unlink(map_raster) + os.unlink(edges_bitmap) + + @staticmethod + def check_programs(): + """ + Checks the require programs are available + """ + def which(program): + import os + def is_exe(fpath): + return os.path.isfile(fpath) and os.access(fpath, os.X_OK) + fpath, fname = os.path.split(program) + if fpath: + if is_exe(program): + return program + else: + for path in os.environ["PATH"].split(os.pathsep): + exe_file = os.path.join(path, program) + if is_exe(exe_file): + return exe_file + return None + + platform_programs = MinimapRenderer.PROGRAMS.get(sys.platform, MinimapRenderer.PROGRAMS.get('default')) + for program in platform_programs.values(): + if not which(program): + raise Exception('The required "%s" program is missing from your PATH.' % program) + +def usage(): + sys.stderr.write(u'''Usage: %s MAP_NAME... + + Example: + $ ./minimap-render.py 007-1 + will render the map at maps/007-1.tmx in the graphics/minimaps directory. + $ ./minimap-render.py all + will render all existing maps found in the maps directory. + $ ./minimap-render.py update + will update all existing minimaps found in the graphics/minimaps directory. + + For convenience, + $ ./minimap-render.py 007-1.tmx + is also accepted. + \n''' % sys.argv[0]) + +def main(): + if not len(sys.argv) > 1: + usage() + return 127 + try: + MinimapRenderer.check_programs() + except Exception as e: + sys.stderr.write(u'%s\n' % e) + return 126 + + status = 0 + if sys.argv[1].lower() == 'all': + map_names = sorted([os.path.splitext(p)[0] for p in os.listdir(os.path.join(CLIENT_DATA_ROOT, u'maps'))]) + elif sys.argv[1].lower() == 'update': + map_names = sorted([os.path.splitext(p)[0] for p in os.listdir(os.path.join(CLIENT_DATA_ROOT, u'graphics', u'minimaps'))]) + else: + map_names = sys.argv[1:] + + for map_name in map_names: + # Render tiles at 1 pixel size + map_renderer = MinimapRenderer(map_name, 1, True) + status += map_renderer.render() + return 0 + +if __name__ == '__main__': + sys.exit(main()) diff --git a/client/weapons.py b/client/weapons.py new file mode 100755 index 0000000..be2f60e --- /dev/null +++ b/client/weapons.py @@ -0,0 +1,89 @@ +#!/usr/bin/python2.7 + +class Item: + def __init__(self, xid): + self.id=xid + self.lvl=0 + +a=open("../../client-data/items.xml", "r") + +swords=[] +bows=[] +shields=[] + +gid="0" +rid=0 +ctx=Item(0) +mem=[] + +for l in a: + if "= 2700 and rid <= 2899: + shields.append(rid) + elif rid >= 3500 and rid <= 3999: + swords.append(rid) + elif rid >= 6000 and rid <= 6499: + bows.append(rid) + +a.close() + +#shields=sorted(shields, reverse=True) +#bows=sorted(bows, reverse=True) +#swords=sorted(swords, reverse=True) + +b=open("weapons.tmp", "w") + +b.write('\n\ +\n\ +\n\ +\n') + +b.write(' \n') + +for i in swords: + b.write(' \n' % i) + +b.write(' \n \n') + +for i in bows: + b.write(' \n' % i) + +b.write(' \n \n') + +for i in shields: + b.write(' \n' % i) + +b.write(' \n') + +b.close() diff --git a/hercules/.gitignore b/hercules/.gitignore new file mode 100644 index 0000000..7eeffc2 --- /dev/null +++ b/hercules/.gitignore @@ -0,0 +1,12 @@ +clientdata +maps +serverdata +oldserverdata +newserverdata +mapcache +olddb +newdb +rodata +tools/luadec + +*.pyc diff --git a/hercules/code/__init__.py b/hercules/code/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/hercules/code/clienttoserver/__init__.py b/hercules/code/clienttoserver/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/hercules/code/clienttoserver/maps.py b/hercules/code/clienttoserver/maps.py new file mode 100644 index 0000000..b9a1626 --- /dev/null +++ b/hercules/code/clienttoserver/maps.py @@ -0,0 +1,190 @@ +# -*- coding: utf8 -*- +# +# Copyright (C) 2014 Evol Online +# Author: Andrei Karas (4144) + +import array +import csv +import hashlib +import os +import zlib +import struct +import StringIO +from xml.dom import minidom + +from code.fileutils import makeDir, writeInt16, writeInt32, writeData, removeDir + +def getTmxFiles(srcDir): + names = [] + for name in os.listdir(srcDir): + names.append(name) + names.sort() + for name in names: + fileName = srcDir + name + if os.path.isfile(fileName) == False: + continue + if name.endswith(".tmx") == False: + continue + yield (fileName, name) + +def findFirstGid(tilesets, tile): + found = -1 + for t in tilesets: + if t <= tile: + found = t + break + return found + +# client +# 0 - walkable ground +# 1 - non walkable wall +# 2 - air allowed shootable too +# 3 - water allowed water, shootable too +# 4 - sit, walkable ground +# 5 - player walk not allowed +# 6 - monster walk not allowed + +# server +# 0 - walkable ground +# 1 - non walkable wall +# 2 - air allowed shootable too +# 3 - water allowed water, shootable too +# 4 - sit, walkable ground +# 5 - none +# 6 - monster walk not allowed +def convertTileType(tile, idx, width, height): + if tile == 5: + tile = 0; + if tile > 6 or tile < 0: + y = int(idx / width) + x = idx - y * width + print "Error: wrong tile: ({0}, {1}) = {2}".format(x, y, tile) + tile = 1 + return tile + +# map file format +# +# int16 version; +# uint8 md5_checksum[16]; +# int16 xs; +# int16 ys; +# int32 len; +# ...data... + +def recreateMap(names): + collisionLayerName = "collision" + destDir = "../../server-data/maps/pre-re/" + tmxName = names[0] + mCaheName = destDir + names[1][:-3] + "mcache" + with open(mCaheName, "wb") as w: + print tmxName + dom = minidom.parse(tmxName) + root = dom.documentElement + tilesets = [] + for tileset in root.getElementsByTagName("tileset"): + tilesets.append(int(tileset.attributes["firstgid"].value)) + tilesets.sort(reverse = True) + found = False + for layer in root.getElementsByTagName("layer"): + if layer.attributes["name"].value.lower() == collisionLayerName: + data = layer.getElementsByTagName("data") + if data is None or len(data) != 1: + continue + data = data[0] + width = int(layer.attributes["width"].value) + height = int(layer.attributes["height"].value) + encoding = data.attributes["encoding"].value + try: + compression = data.attributes["compression"].value + except: + compression = "" + + tiles = [] + if encoding == "base64": + binData = data.childNodes[0].data.strip() + binData = binData.decode('base64') + if compression == "gzip": + dc = zlib.decompressobj(16 + zlib.MAX_WBITS) + else: + dc = zlib.decompressobj() + layerData = dc.decompress(binData) + arr = array.array("I") + arr.fromstring(layerData) + idx = 0 + for tile in arr: + if tile == 0: + tileType = 0 + else: + firstgid = findFirstGid(tilesets, tile) + tileType = convertTileType(tile - firstgid, idx, width, height); + tiles.append(tileType) + idx = idx + 1 + elif encoding == "csv": + binData = data.childNodes[0].data.strip() + f = StringIO.StringIO(binData) + arr = list(csv.reader(f, delimiter=',', quotechar='|')) + idx = 0 + for row in arr: + for item in row: + if item != "": + tile = int(item) + if tile == 0: + tileType = 0 + else: + firstgid = findFirstGid(tilesets, tile) + tileType = convertTileType(tile - firstgid, idx, width, height); + # tmx collision format + # 0 - walkable ground + # 1 - non walkable wall + # 2 - air allowed shootable too + # 3 - water allowed water, shootable too + # 4 - sit, walkable ground + # 5 - none + + # server collision format + # 000 0 - walkable, shootable + # 001 1 - wall + # 010 2 - same with 0 + # 011 3 - walkable, shootable, water + # 100 4 - same with 0 + # 101 5 - shootable + # 110 6 - same with 0 + # 111 7 - none + if tileType > 128 or tileType < 0: + tileType = 1 + tiles.append(tileType) + idx = idx + 1 + f.close() + else: + print "map format not supported: " + tmxName + continue + + #comp = zlib.compressobj() + binData = struct.pack(str(len(tiles))+"B", *tiles) + binData = zlib.compress(binData) + writeInt16(w, 1) + writeData(w, hashlib.md5(binData).digest()) # 16 bytes + writeInt16(w, width) + writeInt16(w, height) + writeInt32(w, len(binData)) + writeData(w, binData) + #print tmxName + found = True + break + if found == False: + print "Error: missing collision layer in file: {0}".format(tmxName) + return + return + with open(mCaheName + ".debug", "wb") as w: + writeInt16(w, width) + writeInt16(w, height) + writeData(w, struct.pack(str(len(tiles))+"B", *tiles)) + + +def recreateMapCache(): + destDir = "../../server-data/maps/pre-re/" + srcDir = "../../client-data/maps/" + removeDir(destDir) + makeDir(destDir) + for names in getTmxFiles(srcDir): + recreateMap(names) diff --git a/hercules/code/configutils.py b/hercules/code/configutils.py new file mode 100644 index 0000000..6d9ddb2 --- /dev/null +++ b/hercules/code/configutils.py @@ -0,0 +1,51 @@ +# -*- coding: utf8 -*- +# +# Copyright (C) 2014 Evol Online +# Author: Andrei Karas (4144) + +def writeIntField(w, name, value): + if value == "": + value = "0" + w.write(" {0}: {1}\n".format(name, value)) + +def writeIntField2(w, name, value): + if value == "": + value = "0" + w.write(" {0}: {1}\n".format(name, value)) + +def writeStrField(w, name, value): + w.write(" {0}: \"{1}\"\n".format(name, value)) + +def writeCondField2(w, cond, name): + if cond != 0: + w.write(" {0}: true\n".format(name)) + +def writeSubField(w, name, value): + w.write(" {0}: {1}\n".format(name, value)) + +def writeFieldArr(w, name, value, value2): + w.write(" {0}: [{1}, {2}]\n".format(name, value, value2)) + +def writeFieldList(w, name, value, value2): + w.write(" {0}: ({1}, {2})\n".format(name, value, value2)) + +def writeStartBlock(w, text): + w.write(" {0}: {{\n".format(text)) + +def writeEndBlock(w): + w.write(" }\n") + +def writeStartScript(w, name): + w.write(" {0}: <\"\n".format(name)) + +def writeEndScript(w): + w.write(" \">\n") + +def isHaveData(fields, start, cnt): + for f in range(0, cnt): + value = fields[start + f * 2] + chance = fields[start + f * 2] + if value == "" or value == "0" or chance == "" or chance == "0": + continue + return True + return False diff --git a/hercules/code/fileutils.py b/hercules/code/fileutils.py new file mode 100644 index 0000000..a0635d4 --- /dev/null +++ b/hercules/code/fileutils.py @@ -0,0 +1,86 @@ +# -*- coding: utf8 -*- +# +# Copyright (C) 2014 Evol Online +# Author: Andrei Karas (4144) + +import array +import os +import struct +import shutil + +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 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) + while data[-1] == '\x00': + data = data[:-1] + return data + +def skipData(f, sz): + f.read(sz) + +def readData(f, sz): + return f.read(sz) + +def readFile(path): + with open(path, "r") as f: + return f.read() + +def writeInt32(f, i): + f.write(struct.pack("I", i)) + +def writeInt16(f, i): + f.write(struct.pack("H", i)) + +def writeMapName(f, name): + if len(name) > 12: + name = name[:12] + while len(name) < 12: + name = name + '\x00' + f.write(struct.pack("12s", name)) + +def writeData(f, data): + f.write(data) + +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 makeDir(path): + if not os.path.exists(path): + os.makedirs(path) + +def removeDir(path): + if os.path.exists(path): + shutil.rmtree(path) + +def removeAllFiles(path): + if os.path.exists(path): + shutil.rmtree(path) + +def findFileIn(names, dirs): + for name in names: + for path in dirs: + if os.path.exists(path + name): + return path + return None diff --git a/hercules/code/server/__init__.py b/hercules/code/server/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/hercules/code/server/account.py b/hercules/code/server/account.py new file mode 100644 index 0000000..7763766 --- /dev/null +++ b/hercules/code/server/account.py @@ -0,0 +1,63 @@ +# -*- coding: utf8 -*- +# +# Copyright (C) 2014 Evol Online +# Author: Andrei Karas (4144) + +import re + +from code.fileutils import readFile +from code.stringutils import stripNewLine, escapeSqlStr + +def convertSex(sex): + if sex == "M" or sex == "F" or sex == "S": + return sex + return "M" + +def convertAccount(): + srcFile = "olddb/account.txt" + dstFile = "newdb/login.sql" + fieldsSplit = re.compile("\t") + tpl = readFile("templates/login.sql") + firstLine = True + with open(dstFile, "w") as w: + w.write(tpl) + w.write("INSERT INTO `login` VALUES ") + with open(srcFile, "r") as r: + for line in r: + if line[:2] == "//": + continue + rows = fieldsSplit.split(line) + if len(rows) == 2: + continue + if len(rows) != 14: + print "wrong account.txt line: " + stripNewLine(line) + continue + + if firstLine == False: + w.write(",\n") + else: + firstLine = False + + w.write(("({account_id},'{userid}','{user_pass}','{sex}'," + + "'{email}',{group_id},{state},{unban_time}," + + "{expiration_time},{logincount},'{lastlogin}'," + + "'{last_ip}','{birthdate}',{character_slots}," + + "'{pincode}',{pincode_change})").format( + account_id = rows[0], + userid = escapeSqlStr(rows[1]), + user_pass = escapeSqlStr(rows[2]), + sex = convertSex(rows[4]), + email = escapeSqlStr(rows[7]), + group_id = 0, + state = 0, + unban_time = rows[12], + expiration_time = rows[9], + logincount = rows[5], + lastlogin = rows[3], + last_ip = rows[10], + birthdate = '0000-00-00', + character_slots = 0, + pincode = '', + pincode_change = 0 + )) + w.write("\n") diff --git a/hercules/code/server/accreg.py b/hercules/code/server/accreg.py new file mode 100644 index 0000000..b69910f --- /dev/null +++ b/hercules/code/server/accreg.py @@ -0,0 +1,52 @@ +# -*- coding: utf8 -*- +# +# Copyright (C) 2014 Evol Online +# Author: Andrei Karas (4144) + +import re + +from code.fileutils import readFile +from code.stringutils import stripNewLine + +def convertAccReg(): + srcFile = "olddb/accreg.txt" + dstFile = "newdb/acc_reg_num_db.sql" + fieldsSplit = re.compile("\t") + comaSplit = re.compile(",") + spaceSplit = re.compile(" ") + tpl = readFile("templates/acc_reg_num_db.sql") + firstLine = True + with open(dstFile, "w") as w: + w.write(tpl) + w.write("INSERT INTO `acc_reg_num_db` VALUES ") + with open(srcFile, "r") as r: + for line in r: + if line[:2] == "//": + continue + line = stripNewLine(line) + rows = fieldsSplit.split(line) + if len(rows) != 2: + print "wrong accreg.txt line: " + line + continue + + accountId = rows[0] + + data = spaceSplit.split(rows[1]) + for varStr in data: + if varStr == "": + continue + + tmp = comaSplit.split(varStr) + + if firstLine == False: + w.write(",\n") + else: + firstLine = False + + w.write(("({account_id},'{key}',{index},{value})").format( + account_id = accountId, + key = tmp[0], + index = "0", + value = tmp[1] + )) + w.write("\n") diff --git a/hercules/code/server/db/__init__.py b/hercules/code/server/db/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/hercules/code/server/db/char.py b/hercules/code/server/db/char.py new file mode 100644 index 0000000..cd8e0cc --- /dev/null +++ b/hercules/code/server/db/char.py @@ -0,0 +1,187 @@ +# -*- coding: utf8 -*- +# +# Copyright (C) 2015 Evol Online +# Author: Andrei Karas (4144) + +from code.fileutils import readFile +from code.stringutils import escapeSqlStr + +def saveCharTable(users): + dstFile = "newdb/char.sql" + firstLine = True + tpl = readFile("templates/char.sql") + with open(dstFile, "w") as w: + w.write(tpl) + w.write("INSERT INTO `char` VALUES ") + for userId in users: + user = users[userId] + + if firstLine == False: + w.write(",\n") + else: + firstLine = False + + w.write(("({char_id},{account_id},{char_num},'{name}',{CLASS}," + + "{base_level},{job_level},{base_exp},{job_exp},{zeny}," + + "{str},{agi},{vit},{INT},{dex},{luk},{max_hp},{hp},{max_sp}," + + "{sp},{status_point},{skill_point},{option},{karma},{manner}," + + "{party_id},{guild_id},{pet_id},{homun_id},{elemental_id}," + + "{hair},{hair_color},{clothes_color},{body},{weapon},{shield}," + + "{head_top},{head_mid},{head_bottom},{robe}," + + "'{last_map}',{last_x},{last_y},'{save_map}',{save_x},{save_y}," + + "{partner_id},{online},{father},{mother},{child},{fame}," + + "{rename},{delete_date},{slotchange},{char_opt},{font}," + + "{unban_time},{uniqueitem_counter},'{sex}',{hotkey_rowshift})").format( + char_id = user.char_id, + account_id = user.account_id, + char_num = user.char_num, + name = escapeSqlStr(user.char_name), + CLASS = user.char_class, + base_level = user.base_level, + job_level = user.job_level, + base_exp = user.base_exp, + job_exp = user.job_exp, + zeny = user.zeny, + str = user.stat_str, + agi = user.stat_agi, + vit = user.stat_vit, + INT = user.stat_int, + dex = user.stat_dex, + luk = user.stat_luk, + max_hp = user.max_hp, + hp = user.hp, + max_sp = user.max_sp, + sp = user.sp, + status_point = user.status_point, + skill_point = user.skill_point, + option = user.option, + karma = user.karma, + manner = user.manner, + party_id = user.party_id, + guild_id = user.guild_id, + pet_id = user.pet_id, + homun_id = "0", + elemental_id = "0", + hair = user.hair, + hair_color = user.hair_color, + clothes_color = user.clothes_color, + body = 0, + weapon = user.weapon, + shield = user.shield, + head_top = user.head_top, + head_mid = user.head_mid, + head_bottom = user.head_bottom, + robe = "0", + last_map = escapeSqlStr(user.last_map), + last_x = user.last_x, + last_y = user.last_y, + save_map = escapeSqlStr(user.save_map), + save_x = user.save_x, + save_y = user.save_y, + partner_id = user.partner_id, + online = "0", + father = "0", + mother = "0", + child = "0", + fame = "0", + rename = "0", + delete_date = "0", + slotchange = "0", + char_opt = "0", + font = "0", + unban_time = "0", + uniqueitem_counter = len(user.inventory), + sex = "U", + hotkey_rowshift = 0 + )) + w.write("\n") + +def saveCharTableCustom(users): + dstFile = "newdb/char.sql" + firstLine = True + tpl = readFile("templates/char.sql") + with open(dstFile, "w") as w: + w.write(tpl) + w.write("INSERT INTO `char` VALUES ") + for userId in users: + user = users[userId] + + if firstLine == False: + w.write(",\n") + else: + firstLine = False + + w.write(("({char_id},{account_id},{char_num},'{name}',{CLASS}," + + "{base_level},{job_level},{base_exp},{job_exp},{zeny}," + + "{str},{agi},{vit},{INT},{dex},{luk},{max_hp},{hp},{max_sp}," + + "{sp},{status_point},{skill_point},{option},{karma},{manner}," + + "{party_id},{guild_id},{pet_id},{homun_id},{elemental_id}," + + "{hair},{hair_color},{clothes_color},{body},{weapon},{shield}," + + "{head_top},{head_mid},{head_bottom},{robe}," + + "'{last_map}',{last_x},{last_y},'{save_map}',{save_x},{save_y}," + + "{partner_id},{online},{father},{mother},{child},{fame}," + + "{rename},{delete_date},{slotchange},{char_opt},{font}," + + "{unban_time},{uniqueitem_counter},'{sex}',{hotkey_rowshift})").format( + char_id = user.char_id, + account_id = user.account_id, + char_num = user.char_num, + name = escapeSqlStr(user.char_name), + CLASS = 0, + base_level = user.base_level, + job_level = user.job_level, + base_exp = user.base_exp, + job_exp = user.job_exp, + zeny = user.zeny, + str = user.stat_str, + agi = user.stat_agi, + vit = user.stat_vit, + INT = user.stat_int, + dex = user.stat_dex, + luk = user.stat_luk, + max_hp = user.max_hp, + hp = user.hp, + max_sp = user.max_sp, + sp = user.sp, + status_point = user.status_point, + skill_point = user.skill_point, + option = user.option, + karma = user.karma, + manner = user.manner, + party_id = 0, + guild_id = 0, + pet_id = 0, + homun_id = "0", + elemental_id = "0", + hair = user.hair, + hair_color = user.hair_color, + clothes_color = user.clothes_color, + body = 0, + weapon = 0, + shield = 0, + head_top = 0, + head_mid = 0, + head_bottom = 0, + robe = "0", + last_map = "000-2-1", + last_x = 50, + last_y = 37, + save_map = "00-2-1", + save_x = 50, + save_y = 37, + partner_id = user.partner_id, + online = "0", + father = "0", + mother = "0", + child = "0", + fame = "0", + rename = "0", + delete_date = "0", + slotchange = "0", + char_opt = "0", + font = "0", + unban_time = "0", + uniqueitem_counter = len(user.inventory), + sex = "U", + hotkey_rowshift = 0 + )) + w.write("\n") diff --git a/hercules/code/server/db/charregnumdb.py b/hercules/code/server/db/charregnumdb.py new file mode 100644 index 0000000..1617c13 --- /dev/null +++ b/hercules/code/server/db/charregnumdb.py @@ -0,0 +1,34 @@ +# -*- coding: utf8 -*- +# +# Copyright (C) 2015 Evol Online +# Author: Andrei Karas (4144) + +from code.fileutils import readFile + +def saveCharRegNumDbTable(users): + dstFile = "newdb/char_reg_num_db.sql" + firstLine = True + tpl = readFile("templates/char_reg_num_db.sql") + with open(dstFile, "w") as w: + w.write(tpl) + w.write("INSERT INTO `char_reg_num_db` VALUES ") + for userId in users: + user = users[userId] + for varKey in user.variables: + if varKey == "ShipQuests": + continue + + varValue = user.variables[varKey] + + if firstLine == False: + w.write(",\n") + else: + firstLine = False + + w.write(("({char_id},'{key}',{index},{value})").format( + char_id = user.char_id, + key = varKey, + index = "0", + value = varValue + )) + w.write("\n") diff --git a/hercules/code/server/db/inventory.py b/hercules/code/server/db/inventory.py new file mode 100644 index 0000000..e5c1e6a --- /dev/null +++ b/hercules/code/server/db/inventory.py @@ -0,0 +1,44 @@ +# -*- coding: utf8 -*- +# +# Copyright (C) 2015 Evol Online +# Author: Andrei Karas (4144) + +from code.fileutils import readFile + +def saveInventoryTable(users): + dstFile = "newdb/inventory.sql" + firstLine = True + tpl = readFile("templates/inventory.sql") + with open(dstFile, "w") as w: + w.write(tpl) + w.write("INSERT INTO `inventory` VALUES ") + for userId in users: + user = users[userId] + for item in user.inventory: + + if firstLine == False: + w.write(",\n") + else: + firstLine = False + + w.write(("({id},{char_id},{nameid},{amount},{equip},{identify}," + + "{refine},{attribute},{card0},{card1},{card2},{card3}," + + "{expire_time},{favorite},{bound},{unique_id})").format( + id = 0, + char_id = user.char_id, + nameid = item.itemId, + amount = item.amount, + equip = item.equip, + identify = "1", + refine = item.refine, + attribute = item.attribute, + card0 = "0", + card1 = "0", + card2 = "0", + card3 = "0", + expire_time = "0", + favorite = "0", + bound = "0", + unique_id = "0" + )) + w.write("\n") diff --git a/hercules/code/server/db/skill.py b/hercules/code/server/db/skill.py new file mode 100644 index 0000000..d21eb3d --- /dev/null +++ b/hercules/code/server/db/skill.py @@ -0,0 +1,31 @@ +# -*- coding: utf8 -*- +# +# Copyright (C) 2015 Evol Online +# Author: Andrei Karas (4144) + +from code.fileutils import readFile + +def saveSkillTable(users): + dstFile = "newdb/skill.sql" + firstLine = True + tpl = readFile("templates/skill.sql") + with open(dstFile, "w") as w: + w.write(tpl) + w.write("INSERT INTO `skill` VALUES ") + for userId in users: + user = users[userId] + for skill in user.skills: + + if firstLine == False: + w.write(",\n") + else: + firstLine = False + + w.write(("({char_id},{id},{lv},{flag})").format( + char_id = user.char_id, + id = skill.skillId, + lv = skill.level, + flag = 0 +# flag = skill.flags + )) + w.write("\n") diff --git a/hercules/code/server/dbitem.py b/hercules/code/server/dbitem.py new file mode 100644 index 0000000..8534ad4 --- /dev/null +++ b/hercules/code/server/dbitem.py @@ -0,0 +1,7 @@ +# -*- coding: utf8 -*- +# +# Copyright (C) 2015 Evol Online +# Author: Andrei Karas (4144) + +class Item: + pass diff --git a/hercules/code/server/dbskill.py b/hercules/code/server/dbskill.py new file mode 100644 index 0000000..343f3af --- /dev/null +++ b/hercules/code/server/dbskill.py @@ -0,0 +1,7 @@ +# -*- coding: utf8 -*- +# +# Copyright (C) 2015 Evol Online +# Author: Andrei Karas (4144) + +class Skill: + pass diff --git a/hercules/code/server/dbuser.py b/hercules/code/server/dbuser.py new file mode 100644 index 0000000..95ad55d --- /dev/null +++ b/hercules/code/server/dbuser.py @@ -0,0 +1,7 @@ +# -*- coding: utf8 -*- +# +# Copyright (C) 2015 Evol Online +# Author: Andrei Karas (4144) + +class User: + pass diff --git a/hercules/code/server/evol/__init__.py b/hercules/code/server/evol/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/hercules/code/server/evol/athena.py b/hercules/code/server/evol/athena.py new file mode 100644 index 0000000..bad35da --- /dev/null +++ b/hercules/code/server/evol/athena.py @@ -0,0 +1,207 @@ +# -*- coding: utf8 -*- +# +# Copyright (C) 2015 Evol Online +# Author: Andrei Karas (4144) + +import re + +from code.stringutils import stripNewLine, removeGat +from code.server.dbitem import Item +from code.server.dbskill import Skill +from code.server.dbuser import User + +comaSplit = re.compile(",") +spaceSplit = re.compile(" ") + +def parseInventory(line, data): + items = [] + + if data == "": + return items + + rows = spaceSplit.split(data) + if len(rows) < 1: + return items + + for data2 in rows: + if data2 == "": + continue + + rows2 = comaSplit.split(data2) + + if len(rows2) != 12: + print "wrong inventory in account.txt line: " + stripNewLine(line) + continue + + item = Item() + + item.uknownId = rows2[0] + item.itemId = rows2[1] + item.amount = rows2[2] + item.equip = rows2[3] + item.color = rows2[4] + item.refine = rows2[5] + item.attribute = rows2[6] + item.card0 = rows2[7] + item.card1 = rows2[8] + item.card2 = rows2[9] + item.card3 = rows2[10] + item.broken = rows2[11] + + items.append(item) + + return items + +def parseSkills(line, data): + skills = [] + + if data == "": + return skills + + rows = spaceSplit.split(data) + if len(rows) < 1: + return skills + + for data2 in rows: + if data2 == "": + continue + + rows2 = comaSplit.split(data2) + + if len(rows2) != 2: + print "wrong skills in account.txt line: " + stripNewLine(line) + continue + + skill = Skill() + skill.skillId = rows2[0] + skill.level = int(rows2[1]) & 0xffff + skill.flags = (int(rows2[1]) * 0xffff) & 0xffff + + skills.append(skill) + + return skills + +def parseVars(line, data): + variables = {} + + if data == "": + return variables + + rows = spaceSplit.split(data) + if len(rows) < 1: + return variables + + for data2 in rows: + if data2 == "": + continue + + rows2 = comaSplit.split(data2) + + if len(rows2) != 2: + print "wrong variables in account.txt line: " + stripNewLine(line) + continue + + variables[rows2[0]] = rows2[1] + + return variables + +def readAthena(): + srcFile = "olddb/athena.txt" + fieldsSplit = re.compile("\t") + + users = {} + with open(srcFile, "r") as r: + for line in r: + if line[:2] == "//": + continue + rows = fieldsSplit.split(line) + if len(rows) == 2: + continue + if len(rows) != 20: + print "wrong account.txt line: " + stripNewLine(line) + continue + + user = User() + + user.char_id = rows[0] + tmp = comaSplit.split(rows[1]) + user.account_id = tmp[0] + user.char_num = tmp[1] + user.char_name = rows[2] + + tmp = comaSplit.split(rows[3]) + user.char_class = tmp[0] + user.base_level = tmp[1] + user.job_level = tmp[2] + + tmp = comaSplit.split(rows[4]) + user.base_exp = tmp[0] + user.job_exp = tmp[1] + user.zeny = tmp[2] + + tmp = comaSplit.split(rows[5]) + user.hp = tmp[0] + user.max_hp = tmp[1] + user.sp = tmp[2] + user.max_sp = tmp[3] + + tmp = comaSplit.split(rows[6]) + user.stat_str = tmp[0] + user.stat_agi = tmp[1] + user.stat_vit = tmp[2] + user.stat_int = tmp[3] + user.stat_dex = tmp[4] + user.stat_luk = tmp[5] + + tmp = comaSplit.split(rows[7]) + user.status_point = tmp[0] + user.skill_point = tmp[1] + + tmp = comaSplit.split(rows[8]) + user.option = tmp[0] + user.karma = tmp[1] + user.manner = tmp[2] + + tmp = comaSplit.split(rows[9]) + user.party_id = tmp[0] + user.guild_id = tmp[1] + user.pet_id = tmp[2] + + tmp = comaSplit.split(rows[10]) + user.hair = tmp[0] + user.hair_color = tmp[1] + user.clothes_color = tmp[2] + + tmp = comaSplit.split(rows[11]) + user.weapon = tmp[0] + user.shield = tmp[1] + user.head_top = tmp[2] + user.head_mid = tmp[3] + user.head_bottom = tmp[4] + + tmp = comaSplit.split(rows[12]) + user.last_map = removeGat(tmp[0]) + user.last_x = tmp[1] + user.last_y = tmp[2] + + tmp = comaSplit.split(rows[13]) + user.save_map = removeGat(tmp[0]) + user.save_x = tmp[1] + user.save_y = tmp[2] + user.partner_id = tmp[3] + user.language_id = tmp[4] + + # skip 14 + + user.inventory = parseInventory(line, rows[15]) + + # skip 16 + + user.skills = parseSkills(line, rows[17]) + + user.variables = parseVars(line, rows[18]) + user.variables["Lang"] = user.language_id + + users[user.char_id] = user + + return users diff --git a/hercules/code/server/evol/consts.py b/hercules/code/server/evol/consts.py new file mode 100644 index 0000000..c63f559 --- /dev/null +++ b/hercules/code/server/evol/consts.py @@ -0,0 +1,49 @@ +# -*- coding: utf8 -*- +# +# Copyright (C) 2014 Evol Online +# Author: Andrei Karas (4144) + +import re + +def convertConsts(quests): + dstFile = "newserverdata/db/const.txt" + fieldsSplit = re.compile("\t+") + fields = dict() + with open(dstFile, "w") as w: + srcFile = "serverdata/db/const.txt" + with open(srcFile, "r") as r: + for line in r: + if len(line) < 2 or line[0:2] == "//": + continue + line = line.replace(" ", "\t") + rows = fieldsSplit.split(line) + sz = len(rows) + if sz < 2 or sz > 3: + continue + + fields[rows[0]] = rows[1][:-1] + if sz == 2: + w.write("{0}\t{1}".format(rows[0], rows[1])) + else: + w.write("{0}\t{1}\t{2}".format(rows[0], rows[1], rows[2])) + # build in parameters + w.write("ClientVersion\t10000\t1\n"); + + srcFile = "oldserverdata/db/const.txt" + w.write("// evol constants\n") + with open(srcFile, "r") as r: + for line in r: + if len(line) < 2 or line[0:2] == "//": + continue + line = line.replace(" ", "\t") + rows = fieldsSplit.split(line) + if len(rows) != 2: + continue + + if rows[0] in quests: + rows[1] = str(quests[rows[0]]) + "\n" + if rows[0] in fields: + if fields[rows[0]] != rows[1][:-1]: + print "warning: different const values for {0} ({1}, {2})".format(rows[0], rows[1][:-1], fields[rows[0]]) + else: + w.write("{0}\t{1}".format(rows[0], rows[1])) diff --git a/hercules/code/server/evol/itemdb.py b/hercules/code/server/evol/itemdb.py new file mode 100644 index 0000000..a60e57d --- /dev/null +++ b/hercules/code/server/evol/itemdb.py @@ -0,0 +1,104 @@ +# -*- coding: utf8 -*- +# +# Copyright (C) 2014 Evol Online +# Author: Andrei Karas (4144) + +import re + +from code.configutils import writeIntField, writeStartBlock, writeEndBlock, writeStartScript, writeEndScript, writeStrField, writeSubField +from code.fileutils import readFile + +def convertItemDb(): + srcFile = "oldserverdata/db/item_db.txt" + dstFile = "newserverdata/db/re/item_db.conf" + constsFile = "newserverdata/db/const.txt" + fieldsSplit = re.compile(",") + scriptsSplit = re.compile("{") + items = dict() + with open(srcFile, "r") as r: + with open(dstFile, "w") as w: + with open(constsFile, "a") as c: + c.write("// items\n"); + tpl = readFile("templates/item_db.tpl") + w.write(tpl) + for line in r: + if len(line) < 2 or line[0] == "#" or line[0:2] == "//": + continue + rows = fieldsSplit.split(line) + if len(rows) < 5 or rows[0] == "0": + continue + + sz = len(rows) + if sz > 19: + sz = 19 + for f in xrange(0, sz): + rows[f] = rows[f].strip() + if rows[4] == "2": + rows[4] = "0" + rows[3] = str(int(rows[3]) | 4) + + items[rows[1]] = rows[0] + w.write("{\n") + c.write("{0}\t{1}\n".format(rows[1], rows[0])) + writeIntField(w, "Id", rows[0]) + writeStrField(w, "AegisName", rows[1]) + writeStrField(w, "Name", rows[2]) + writeIntField(w, "Type", rows[4]) + writeIntField(w, "Buy", rows[5]) + writeIntField(w, "Sell", rows[6]) + writeIntField(w, "Weight", rows[7]) + writeIntField(w, "Atk", rows[8]) + writeIntField(w, "Matk", "0") + writeIntField(w, "Def", rows[9]) + writeIntField(w, "Range", rows[10]) + writeIntField(w, "Slots", "0") + writeIntField(w, "Job", "0xFFFFFFFF") + writeIntField(w, "Upper", "0x3F") + writeIntField(w, "Gender", rows[13]) + writeIntField(w, "Loc", rows[14]) + writeIntField(w, "WeaponLv", rows[15]) + writeIntField(w, "EquipLv", rows[16]) + writeIntField(w, "Refine", "false") + if rows[14] == "2": + writeIntField(w, "View", "1") + else: + writeIntField(w, "View", rows[0]) + writeIntField(w, "BindOnEquip", "false") + writeIntField(w, "BuyingStore", "false") + writeIntField(w, "Delay", "0") + trade = int(rows[3]) + if trade != 0: + writeStartBlock(w, "Trade") + if trade & 1 == 1: + writeSubField(w, "nodrop", "true") + if trade & 2 == 2: + writeSubField(w, "notrade", "true") + if trade & 4 == 4: + writeSubField(w, "nodelonuse", "true") + if trade & 8 == 8: + writeSubField(w, "nostorage", "true") + if trade & 256 == 256: + writeSubField(w, "nogstorage", "true") + if trade & 512 == 512: + writeSubField(w, "noselltonpc", "true") + if trade != 0: + writeEndBlock(w) + writeIntField(w, "Sprite", "0") + + scripts = "" + for f in xrange(sz, len(rows)): + scripts = scripts + ", " + rows[f] + rows = scriptsSplit.split(scripts) + cnt = len(rows) + if cnt > 1: + text = rows[1].strip() + if len(text) > 1: + text = text[:-2] + if text != "": + writeStartScript(w, "Script") + w.write(" {0}\n".format(text)) + writeEndScript(w) + + w.write("},\n") + w.write(")\n") + return items diff --git a/hercules/code/server/evol/main.py b/hercules/code/server/evol/main.py new file mode 100644 index 0000000..be9f0ab --- /dev/null +++ b/hercules/code/server/evol/main.py @@ -0,0 +1,43 @@ +#! /usr/bin/env python +# -*- coding: utf8 -*- +# +# Copyright (C) 2014 Evol Online +# Author: Andrei Karas (4144) + +from code.server.account import convertAccount +from code.server.accreg import convertAccReg +from code.server.party import convertParty +from code.server.storage import convertStorage +from code.server.db.char import saveCharTable +from code.server.db.charregnumdb import saveCharRegNumDbTable +from code.server.db.inventory import saveInventoryTable +from code.server.db.skill import saveSkillTable +from code.server.evol.athena import readAthena +from code.server.evol.consts import convertConsts +from code.server.evol.itemdb import convertItemDb +from code.server.evol.mobdb import convertMobDb +from code.server.evol.mobskilldb import convertMobSkillDb +from code.server.evol.npcs import createMainScript, convertNpcs +from code.server.questsdb import convertQuestsDb +from code.server.utils import cleanServerData + +def serverEvolMain(): + cleanServerData() + createMainScript() + items = convertItemDb() + convertNpcs(items) + convertMobDb() + quests = convertQuestsDb() + convertConsts(quests) + convertMobSkillDb() + +def dbEvolMain(): + convertAccount() + users = readAthena() + saveCharTable(users) + saveCharRegNumDbTable(users) + saveSkillTable(users) + saveInventoryTable(users) + convertStorage() + convertAccReg() + convertParty(users) \ No newline at end of file diff --git a/hercules/code/server/evol/mobdb.py b/hercules/code/server/evol/mobdb.py new file mode 100644 index 0000000..74eda04 --- /dev/null +++ b/hercules/code/server/evol/mobdb.py @@ -0,0 +1,89 @@ +# -*- coding: utf8 -*- +# +# Copyright (C) 2014 Evol Online +# Author: Andrei Karas (4144) + +import re + +def convertMobDb(): + srcFile = "oldserverdata/db/mob_db.txt" + dstFile = "newserverdata/db/re/mob_db.txt" + fieldsSplit = re.compile(",") + with open(srcFile, "r") as r: + with open(dstFile, "w") as w: + for line in r: +# if len(line) < 2 or line[0] == "#": + if len(line) < 2: + w.write(line) + continue + rows = fieldsSplit.split(line) + for f in xrange(0, len(rows)): + rows[f] = rows[f].strip() + w.write("{0:<5} {1:<15} {2:<16} {3:<16} {4:<5} {5:<5} {6:<5} " + "{7:<5} {8:<5} {9:<7} {10:<5} {11:<5} {12:<5} {13:<5} " + "{14:<5} {15:<5} {16:<5} {17:<5} {18:<5} {19:<5} {20:<7}" + " {21:<7} {22:<6} {23:<5} {24:<8} {25:<8} {26:<6} " + "{27:<8} {28:<9} {29:<8} {30:<5} {31:<7} {32:<8} {33:<7}" + " {34:<8} {35:<7} {36:<8} {37:<8} {38:<9} {39:<8} " + "{40:<9} {41:<8} {42:<9} {43:<8} {44:<9} {45:<8} {46:<9}" + " {47:<8} {48:<9} {49:<8} {50:<9} {51:<8} {52:<9} " + "{53:<8} {54:<9} {55:<8} {56:<8} \n".format( + rows[0] + ",", + rows[1] + ",", + rows[2] + ",", + rows[2] + ",", + rows[3] + ",", + rows[4] + ",", + rows[5] + ",", + rows[6] + ",", + rows[7] + ",", + rows[8] + ",", + rows[9] + ",", + rows[10] + ",", + rows[11] + ",", + rows[12] + ",", + rows[13] + ",", + rows[14] + ",", + rows[15] + ",", + rows[16] + ",", + rows[17] + ",", + rows[18] + ",", + rows[19] + ",", + rows[20] + ",", + rows[21] + ",", + rows[22] + ",", + rows[23] + ",", + rows[24] + ",", + rows[25] + ",", + rows[26] + ",", + rows[27] + ",", + rows[28] + ",", + rows[45] + ",", + rows[47] + ",", + rows[48] + ",", + rows[49] + ",", + rows[50] + ",", + rows[51] + ",", + rows[52] + ",", + rows[29] + ",", + rows[30] + ",", + rows[31] + ",", + rows[32] + ",", + rows[33] + ",", + rows[34] + ",", + rows[35] + ",", + rows[36] + ",", + rows[37] + ",", + rows[38] + ",", + rows[39] + ",", + rows[40] + ",", + rows[41] + ",", + rows[42] + ",", + rows[43] + ",", + rows[44] + ",", + "0,", + "0,", + "0,", + "0" + )) + diff --git a/hercules/code/server/evol/mobskilldb.py b/hercules/code/server/evol/mobskilldb.py new file mode 100644 index 0000000..a5a7d5f --- /dev/null +++ b/hercules/code/server/evol/mobskilldb.py @@ -0,0 +1,50 @@ +# -*- coding: utf8 -*- +# +# Copyright (C) 2014 Evol Online +# Author: Andrei Karas (4144) + +import re + +from code.fileutils import readFile + +def convertMobSkillDb(): + srcFile = "oldserverdata/db/mob_skill_db.txt" + dstFile = "newserverdata/db/re/mob_skill_db.txt" + fieldsSplit = re.compile(",") + with open(srcFile, "r") as r: + with open(dstFile, "w") as w: + tpl = readFile("templates/mob_skill_db.tpl") + w.write(tpl) + for line in r: + if len(line) < 2: + w.write(line) + continue + rows = fieldsSplit.split(line) + if len(rows) < 10: + w.write(line) + continue + + for f in xrange(0, len(rows)): + rows[f] = rows[f].strip() + + w.write("{0},{1},{2},{3},{4},{5},{6}," + "{7},{8},{9},{10},{11},{12},{13}," + "{14},{15},,,\n".format( + rows[0], + rows[1], + rows[2], + rows[3], + rows[4], + rows[5], + rows[6], + rows[7], + rows[8], + rows[9], + rows[10], + rows[11], + rows[13], + rows[14], + rows[15], + rows[16] + )) + diff --git a/hercules/code/server/evol/npcs.py b/hercules/code/server/evol/npcs.py new file mode 100644 index 0000000..6efe811 --- /dev/null +++ b/hercules/code/server/evol/npcs.py @@ -0,0 +1,281 @@ +# -*- coding: utf8 -*- +# +# Copyright (C) 2014 Evol Online +# Author: Andrei Karas (4144) + +import os +import re + +from code.fileutils import makeDir +from code.stringutils import stripWindows, stripNewLine + +mapsConfFile = "newserverdata/conf/maps.conf" +mapsIndexFile = "newserverdata/db/map_index.txt" +npcMainScript = "newserverdata/npc/re/scripts_main.conf" +mapsIndex = 1 +scriptRe = re.compile("^(?P[^/](.+))[.]gat,([ ]*)(?P[\d]+),([ ]*)(?P[\d]+),([ ]*)(?P[\d]+)(|,(?P[\d]+))" + + "[\t](?Pscript)[\t](?P[\w#' ]+)[\t]" + "(?P[\d]+)((,((?P[\d]+),(?P[\d]+)))|)(|;(?P[\d]+))(|,|;){$") + +shopRe = re.compile("^(?P[^/](.+))[.]gat,([ ]*)(?P[\d]+),([ ]*)(?P[\d]+),([ ]*)(?P[\d]+)(|,(?P[\d]+))" + + "[\t](?Pshop)[\t](?P[\w#' ]+)[\t]" + "(?P[\d]+),(?P(.+))$") + +mapFlagRe = re.compile("^(?P[^/](.+))[.]gat" + + "[ ](?Pmapflag)[ ](?P[\w#']+)(|[ ](?P.*))$") + +warpRe = re.compile("^(?P[^/](.+))[.]gat,([ ]*)(?P[\d]+),([ ]*)(?P[\d]+)[\t]" + "(?Pwarp)[\t](?P[^\t]+)[\t](?P[\d-]+),(?P[\d-]+),(?P[^/](.+))[.]gat,([ ]*)(?P[\d]+),([ ]*)(?P[\d]+)$") + +monsterRe = re.compile("^(?P[^/](.+))[.]gat,([ ]*)(?P[\d]+),([ ]*)(?P[\d]+),([ ]*)(?P[\d-]+),(?P[\d-]+)\t" + "(?Pmonster)[\t](?P[\w#' ]+)[\t]" + "(?P[\d]+),(?P[\d]+),(?P[\d-]+),(?P[\d]+),(?P[\d]+)$") + +setRe = re.compile("^(?P[ ]+)set[ ](?P[^,]+),([ ]*)(?P[^;]+);$"); + +class ScriptTracker: + pass + +def createMainScript(): + with open(npcMainScript, "w") as w: + w.write("npc: npc/functions/main.txt\n") + w.write("import: npc/scripts.conf\n") + +def convertNpcs(items): + processNpcDir("oldserverdata/npc/", "newserverdata/npc/", items) + +def processNpcDir(srcDir, dstDir, items): + makeDir(dstDir) + files = os.listdir(srcDir) + for file1 in files: + if file1[0] == '.': + continue + srcPath = os.path.abspath(srcDir + os.path.sep + file1) + dstPath = os.path.abspath(dstDir + os.path.sep + file1) + if not os.path.isfile(srcPath): + processNpcDir(srcPath, dstPath, items) + else: + if file1[-5:] == ".conf" or file1[-4:] == ".txt": + processNpcFile(srcPath, dstPath, items) + +def processNpcFile(srcFile, dstFile, items): +# print "file: " + srcFile + tracker = ScriptTracker() + tracker.insideScript = False + tracker.items = items + with open(srcFile, "r") as r: + with open(dstFile, "w") as w: + tracker.w = w + for line in r: + tracker.line = stripWindows(line) + res = convertTextLine(tracker) + if res: + w.write(tracker.line) + +def convertTextLine(tracker): + line = tracker.line + if line[:5] == "map: ": + processScriptMapLine(line) + return False + + idx = line.find("\tscript\t") + if idx >= 0: + processScript(tracker) + return False + idx = line.find("\tshop\t") + if idx >= 0: + processShop(tracker) + return False + idx = line.find("\tmonster\t") + if idx >= 0: + processMonster(tracker) + return False + idx = line.find("\twarp\t") + if idx >= 0: + processWarp(tracker) + return False + idx = line.find(".gat mapflag ") + if idx >= 0: + processMapFlag(tracker) + return False + processStrReplace(tracker) + return False + +def processScriptMapLine(line): + global mapsIndex + line = stripNewLine(line) + if line[-4:] == ".gat": + line = line[:-4] + with open(mapsConfFile, "a") as w: + w.write(line + "\n") + + with open(mapsIndexFile, "a") as w: + w.write("{0} {1}\n".format(line[5:], mapsIndex)) + mapsIndex = mapsIndex + 1 + +def writeScript(w, m): + if m.group("gender") != None: + w.write("// Gender = {0}\n".format(m.group("gender"))); + + if m.group("x") == 0 and m.group("y") == 0: # float npc + w.write("-") + else: + w.write("{0},{1},{2},{3}".format(m.group("map"), m.group("x"), m.group("y"), m.group("dir"))) + class_ = m.group("class") + if class_ == "0": # hidden npc + class_ = "32767" + else: + class_ = int(class_) + if class_ > 125 and class_ <= 400: + class_ = class_ + 100 + w.write("\t{0}\t{1}\t{2}".format(m.group("tag"), m.group("name"), class_)); + +def processScript(tracker): + line = tracker.line + w = tracker.w + if line[:9] == "function\t": + tracker.w.write(line) + return + + m = scriptRe.search(line) + if m == None: + print "error in parsing: " + line + w.write("!!!error parsing line") + w.write(line) + return +# print "source=" + line[:-1] +# print "map={0} x={1} y={2} dir={3} gender={4} tag={5} name={6} class={7}, xs={8}, ys={9}, size={10}".format( +# m.group("map"), m.group("x"), m.group("y"), m.group("dir"), m.group("gender"), +# m.group("tag"), m.group("name"), m.group("class"), m.group("xs"), m.group("ys"), m.group("size")) + + if m.group("size") != None: + w.write("// Size = {0}\n".format(m.group("size"))); + writeScript(w, m) + if m.group("xs") != None: + w.write(",{0},{1}".format(m.group("xs"), m.group("ys"))); + w.write(",{\n"); + + +def itemsToShop(tracker, itemsStr): + itemsSplit = re.compile(",") + itemsSplit2 = re.compile(":") + itemsDict = tracker.items + outStr = "" + items = itemsSplit.split(itemsStr) + for str2 in items: + parts = itemsSplit2.split(str2) + if outStr != "": + outStr = outStr + "," + outStr = outStr + itemsDict[parts[0].strip()] + ":" + parts[1] + return outStr + +def processShop(tracker): + line = tracker.line + w = tracker.w + + m = shopRe.search(line) + if m == None: + print "error in parsing: " + line + w.write("!!!error parsing line") + w.write(line) + return +# print "source=" + line[:-1] +# print "map={0} x={1} y={2} dir={3} gender={4} tag={5} name={6} class={7} items={8}".format( +# m.group("map"), m.group("x"), m.group("y"), m.group("dir"), m.group("gender"), +# m.group("tag"), m.group("name"), m.group("class"), m.group("items")) + + writeScript(w, m) + w.write("," + itemsToShop(tracker, m.group("items")) + "\n") + +def processMapFlag(tracker): + line = tracker.line + w = tracker.w + + m = mapFlagRe.search(line) + if m == None: + print "error in parsing: " + line + w.write("!!!error parsing line") + w.write(line) + return +# print "source=" + line[:-1] +# print "map={0} tag={1} name={2} flag={3}".format( +# m.group("map"), m.group("tag"), m.group("name"), m.group("flag")) + + w.write("{0}\t{1}\t{2}".format(m.group("map"), m.group("tag"), m.group("name"))) + if m.group("flag") == None: + w.write("\n") + else: + w.write("\t{0}\n".format(m.group("flag"))) + +def processWarp(tracker): + line = tracker.line + w = tracker.w + m = warpRe.search(line) + if m == None: + print "error in parsing: " + line + w.write("!!!error parsing line") + w.write(line) + return + +# print "source=" + line[:-1] +# print "map={0} xy={1},{2} tag={3} name={4} xs={5} ys={6} target: map={7} xy={8},{9}".format( +# m.group("map"), m.group("x"), m.group("y"), m.group("tag"), m.group("name"), m.group("xs"), m.group("ys"), m.group("targetmap"), m.group("targetx"), m.group("targety")) + + xs = int(m.group("xs")) + ys = int(m.group("ys")) + if xs < 0: + xs = 0 + if ys < 0: + ys = 0 + w.write("{0},{1},{2},{3}\t{4}\t{5}\t{6},{7},{8},{9},{10}\n".format( + m.group("map"), m.group("x"), m.group("y"), "0", m.group("tag"), m.group("name"), + xs, ys, m.group("targetmap"), m.group("targetx"), m.group("targety"))) + + +def processMonster(tracker): + line = tracker.line + w = tracker.w + m = monsterRe.search(line) + if m == None: + print "error in parsing: " + line + w.write("!!!error parsing line") + w.write(line) + return + +# print "source=" + line[:-1] +# print ("map={0} xy={1},{2} xs={3} ys={4} tag={5} name={6} class={7} " + +# "num={8} look={9} delays={10},{11}").format( +# m.group("map"), m.group("x"), m.group("y"), m.group("xs"), m.group("ys"), +# m.group("tag"), m.group("name"), m.group("class"), +# m.group("num"), m.group("look"), m.group("delay1"), m.group("delay2")) + w.write("{0},{1},{2},{3},{4}\t{5}\t{6}\t{7},{8},{9},{10}\n".format(m.group("map"), + m.group("x"), m.group("y"), m.group("xs"), m.group("ys"), + m.group("tag"), m.group("name"), + m.group("class"), m.group("num"), m.group("delay1"), m.group("delay2"))) + + +def processStrReplace(tracker): + line = tracker.line + w = tracker.w + line = line.replace("setskill ", "addtoskill ") + line = line.replace("zeny", "Zeny") + line = line.replace("getclientversion(\"\")", "ClientVersion") + line = line.replace("getclientversion()", "ClientVersion") + line = line.replace("setlang @", "Lang = @") + line = re.sub("([^@^$])@([^@])", "\\1.@\\2", line) + line = line.replace(".@menu", "@menu") + idx = line.find("getmapmobs(") + if idx >= 0: + idx2 = line.find("\"", idx + len("getmapmobs(") + 1) + idx3 = line.find(")", idx + len("getmapmobs(") + 1) + if idx2 + 1 == idx3: + line = line[:idx2 + 1] + ",\"all\"" + line[idx2 + 1:] + + line = line.replace("getmapmobs(", "mobcount(") + + m = setRe.search(line); + if m != None: + line = "{0}{1} = {2};\n".format(m.group("space"), m.group("var"), m.group("val")) + + w.write(line) + diff --git a/hercules/code/server/maps.py b/hercules/code/server/maps.py new file mode 100644 index 0000000..2ef0173 --- /dev/null +++ b/hercules/code/server/maps.py @@ -0,0 +1,43 @@ +# -*- coding: utf8 -*- +# +# Copyright (C) 2014 Evol Online +# Author: Andrei Karas (4144) + +import array +import struct +import zlib + +from code.fileutils import readMapName, readInt16, readInt32, readData, makeDir + +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) + with open(destDir + name + ".txt", "wb") as w: + arr = array.array("B") + arr.fromstring(data) + for x in xrange(0, sx): + for y in xrange(0, sy): + w.write("{0},{1}:{2}\n".format(x, y, arr[x + y * sx])) diff --git a/hercules/code/server/party.py b/hercules/code/server/party.py new file mode 100644 index 0000000..c75a541 --- /dev/null +++ b/hercules/code/server/party.py @@ -0,0 +1,80 @@ +# -*- coding: utf8 -*- +# +# Copyright (C) 2014 Evol Online +# Author: Andrei Karas (4144) + +import re + +from code.fileutils import readFile +from code.stringutils import stripNewLine, escapeSqlStr + +def findLeaderId(name, users): + for userId in users: + user = users[userId] + if user.char_name == name: + return user.char_id + return 0 + +def convertParty(users): + srcFile = "olddb/party.txt" + dstFile = "newdb/party.sql" + fieldsSplit = re.compile("\t") + comaSplit = re.compile(",") + tpl = readFile("templates/party.sql") + firstLine = True + with open(dstFile, "w") as w: + w.write(tpl) + w.write("INSERT INTO `party` VALUES ") + with open(srcFile, "r") as r: + for line in r: + if line[:2] == "//": + continue + line = stripNewLine(line) + rows = fieldsSplit.split(line) + if len(rows) == 2: + continue + if len(rows) < 3: + print "wrong party.txt line: " + line + continue + + partyId = rows[0] + partyName = rows[1] + + tmp = comaSplit.split(rows[2]) + partyExp = tmp[0] + partyItem = tmp[1] + + leaderId = 0 + leaderName = "" + accountId = "" + + for f in xrange(3, len(rows), 2): + + if rows[f] == "0,0" or rows[f] == "": + continue + + tmp = comaSplit.split(rows[f]) + accountId = tmp[0] + leader = tmp[1] + charName = rows[f + 1] + if leader == "1": + leaderId = accountId + leaderName = charName + + if firstLine == False: + w.write(",\n") + else: + firstLine = False + + leaderCharId = findLeaderId(leaderName, users) + + w.write(("({party_id},'{name}',{exp},{item}," + + "{leader_id},{leader_char})").format( + party_id = partyId, + name = escapeSqlStr(partyName), + exp = partyExp, + item = partyItem, + leader_id = leaderId, + leader_char = leaderCharId + )) + w.write("\n") diff --git a/hercules/code/server/questsdb.py b/hercules/code/server/questsdb.py new file mode 100644 index 0000000..880a7f9 --- /dev/null +++ b/hercules/code/server/questsdb.py @@ -0,0 +1,33 @@ +# -*- coding: utf8 -*- +# +# Copyright (C) 2014 Evol Online +# Author: Andrei Karas (4144) + +from code.fileutils import readFile + +def convertQuestsDb(): + srcFile = "oldserverdata/db/questvars.txt" + dstFile = "newserverdata/db/quest_db.txt" + quests = dict() + with open(srcFile, "r") as r: + with open(dstFile, "w") as w: + tpl = readFile("templates/quest_db.tpl") + w.write(tpl) + cnt = 0 + for line in r: + if len(line) < 2 or line[0:2] == "//": + continue + + idx = line.find("// ") + if idx < 3: + continue + line = line[idx + 3:] + idx = line.find(" ") + if idx < 3: + continue + line = line[:idx] + + w.write("{0},0,0,0,0,0,0,0,\"{1}\"\n".format(cnt, line)) + quests[line] = cnt + cnt = cnt + 1 + return quests diff --git a/hercules/code/server/storage.py b/hercules/code/server/storage.py new file mode 100644 index 0000000..6bddb52 --- /dev/null +++ b/hercules/code/server/storage.py @@ -0,0 +1,81 @@ +# -*- coding: utf8 -*- +# +# Copyright (C) 2014 Evol Online +# Author: Andrei Karas (4144) + +import re + +from code.fileutils import readFile +from code.stringutils import stripNewLine +from code.server.dbitem import Item + +def convertStorage(): + srcFile = "olddb/storage.txt" + dstFile = "newdb/storage.sql" + fieldsSplit = re.compile("\t") + comaSplit = re.compile(",") + spaceSplit = re.compile(" ") + tpl = readFile("templates/storage.sql") + firstLine = True + with open(dstFile, "w") as w: + w.write(tpl) + w.write("INSERT INTO `storage` VALUES ") + with open(srcFile, "r") as r: + for line in r: + if line[:2] == "//": + continue + rows = fieldsSplit.split(line) + if len(rows) == 2: + continue + if len(rows) != 3: + print "wrong storage.txt line: " + stripNewLine(line) + continue + + tmp = comaSplit.split(rows[0]) + accountId = tmp[0] +# storage_amount = tmp[1] + + data = spaceSplit.split(rows[1]) + for itemStr in data: + if itemStr == "": + continue + + tmp = comaSplit.split(itemStr) + item = Item() + item.unknownId = tmp[0] + item.itemId = tmp[1] + item.amount = tmp[2] + item.equip = tmp[3] + item.color = tmp[4] + item.refine = tmp[5] + item.attribute = tmp[6] + item.card0 = tmp[7] + item.card1 = tmp[8] + item.card2 = tmp[9] + item.card3 = "0" + + if firstLine == False: + w.write(",\n") + else: + firstLine = False + + w.write(("({id},{account_id},{nameid},{amount},{equip},{identify}," + + "{refine},{attribute},{card0},{card1},{card2},{card3}," + + "{expire_time},{bound},{unique_id})").format( + id = 0, + account_id = accountId, + nameid = item.itemId, + amount = item.amount, + equip = item.equip, + identify = "1", + refine = item.refine, + attribute = item.attribute, + card0 = "0", + card1 = "0", + card2 = "0", + card3 = "0", + expire_time = "0", + bound = "0", + unique_id = "0" + )) + w.write("\n") diff --git a/hercules/code/server/tmw/__init__.py b/hercules/code/server/tmw/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/hercules/code/server/tmw/athena.py b/hercules/code/server/tmw/athena.py new file mode 100644 index 0000000..6548b2e --- /dev/null +++ b/hercules/code/server/tmw/athena.py @@ -0,0 +1,207 @@ +# -*- coding: utf8 -*- +# +# Copyright (C) 2015 Evol Online +# Author: Andrei Karas (4144) + +import re + +from code.stringutils import stripNewLine +from code.server.dbitem import Item +from code.server.dbskill import Skill +from code.server.dbuser import User + +comaSplit = re.compile(",") +spaceSplit = re.compile(" ") + +def parseInventory(line, data): + items = [] + + if data == "": + return items + + rows = spaceSplit.split(data) + if len(rows) < 1: + return items + + for data2 in rows: + if data2 == "": + continue + + rows2 = comaSplit.split(data2) + + if len(rows2) != 12: + print "wrong inventory in account.txt line: " + stripNewLine(line) + continue + + item = Item() + + item.uknownId = rows2[0] + item.itemId = rows2[1] + item.amount = rows2[2] + item.equip = rows2[3] + item.color = rows2[4] + item.refine = rows2[5] + item.attribute = rows2[6] + item.card0 = rows2[7] + item.card1 = rows2[8] + item.card2 = rows2[9] + item.card3 = rows2[10] + item.broken = rows2[11] + + items.append(item) + + return items + +def parseSkills(line, data): + skills = [] + + if data == "": + return skills + + rows = spaceSplit.split(data) + if len(rows) < 1: + return skills + + for data2 in rows: + if data2 == "": + continue + + rows2 = comaSplit.split(data2) + + if len(rows2) != 2: + print "wrong skills in account.txt line: " + stripNewLine(line) + continue + + skill = Skill() + skill.skillId = rows2[0] + skill.level = int(rows2[1]) & 0xffff + skill.flags = (int(rows2[1]) * 0xffff) & 0xffff + + skills.append(skill) + + return skills + +def parseVars(line, data): + variables = {} + + if data == "": + return variables + + rows = spaceSplit.split(data) + if len(rows) < 1: + return variables + + for data2 in rows: + if data2 == "": + continue + + rows2 = comaSplit.split(data2) + + if len(rows2) != 2: + print "wrong variables in account.txt line: " + stripNewLine(line) + continue + + variables[rows2[0]] = rows2[1] + + return variables + +def readAthena(): + srcFile = "olddb/athena.txt" + fieldsSplit = re.compile("\t") + + users = {} + with open(srcFile, "r") as r: + for line in r: + if line[:2] == "//": + continue + rows = fieldsSplit.split(line) + if len(rows) == 2: + continue + if len(rows) != 20: + print "wrong account.txt line: " + stripNewLine(line) + continue + + user = User() + + user.char_id = rows[0] + tmp = comaSplit.split(rows[1]) + user.account_id = tmp[0] + user.char_num = tmp[1] + user.char_name = rows[2] + + tmp = comaSplit.split(rows[3]) + user.char_class = tmp[0] + user.base_level = tmp[1] + user.job_level = tmp[2] + + tmp = comaSplit.split(rows[4]) + user.base_exp = tmp[0] + user.job_exp = tmp[1] + user.zeny = tmp[2] + + tmp = comaSplit.split(rows[5]) + user.hp = tmp[0] + user.max_hp = tmp[1] + user.sp = tmp[2] + user.max_sp = tmp[3] + + tmp = comaSplit.split(rows[6]) + user.stat_str = tmp[0] + user.stat_agi = tmp[1] + user.stat_vit = tmp[2] + user.stat_int = tmp[3] + user.stat_dex = tmp[4] + user.stat_luk = tmp[5] + + tmp = comaSplit.split(rows[7]) + user.status_point = tmp[0] + user.skill_point = tmp[1] + + tmp = comaSplit.split(rows[8]) + user.option = tmp[0] + user.karma = tmp[1] + user.manner = tmp[2] + + tmp = comaSplit.split(rows[9]) + user.party_id = tmp[0] + user.guild_id = tmp[1] + user.pet_id = tmp[2] + + tmp = comaSplit.split(rows[10]) + user.hair = tmp[0] + user.hair_color = tmp[1] + user.clothes_color = tmp[2] + + tmp = comaSplit.split(rows[11]) + user.weapon = tmp[0] + user.shield = tmp[1] + user.head_top = tmp[2] + user.head_mid = tmp[3] + user.head_bottom = tmp[4] + + tmp = comaSplit.split(rows[12]) + user.last_map = tmp[0] + user.last_x = tmp[1] + user.last_y = tmp[2] + + tmp = comaSplit.split(rows[13]) + user.save_map = tmp[0] + user.save_x = tmp[1] + user.save_y = tmp[2] + + user.partner_id = "0" + user.language_id = "0" + + # skip 14 + + user.inventory = parseInventory(line, rows[15]) + + # skip 16 + + user.skills = parseSkills(line, rows[17]) + + user.variables = parseVars(line, rows[18]) + + users[user.char_id] = user + + return users diff --git a/hercules/code/server/tmw/consts.py b/hercules/code/server/tmw/consts.py new file mode 100644 index 0000000..5b8403e --- /dev/null +++ b/hercules/code/server/tmw/consts.py @@ -0,0 +1,129 @@ +# -*- coding: utf8 -*- +# +# Copyright (C) 2014 Evol Online +# Author: Andrei Karas (4144) + +import os +import re + +from code.fileutils import readFile +from code.stringutils import stripNewLine + +fieldsSplit = re.compile(":") + +def getConstsFile(srcDir): + files = os.listdir(srcDir) + for srcFile in files: + if srcFile.find("const") == 0 and srcFile[-4:] == ".txt": + yield srcDir + srcFile + +def readOneConst(r, line): + key = "" + val = "" + depr = 0 + if line.find(": {") > 0: + rows = fieldsSplit.split(line) + key = rows[0].strip() + line = r.next().strip() + rows = fieldsSplit.split(line) + if len(rows) != 2: + print "error" + return ("", "", 0) + if rows[0] == "Value": + val = rows[1] + line = r.next().strip() + rows = fieldsSplit.split(line) + if len(rows) != 2: + print "error" + return ("", "", 0) + rows[1] = rows[1].strip() + if rows[0] == "Deprecated" and rows[1].find("true") == 0: + depr = 1 + else: + rows = fieldsSplit.split(line) + if len(rows) != 2: + return ("", "", 0) + key = rows[0]; + val = rows[1] + return (key, val, depr) + +def writeConst(w, const): + if const[2] == 1: + w.write("\t{0}: {{\n\t\tValue:{1}\n\t\tDeprecated: true\n\t}}\n".format(const[0], const[1])) + else: + w.write("\t{0}:{1}\n".format(const[0], const[1])) + +def convertConsts(quests, npcIds): + dstFile = "newserverdata/db/constants.conf" + fields = dict() + vals = [("MF_NOTELEPORT", "mf_noteleport"), + ("MF_NORETURN", "mf_noreturn"), + ("MF_MONSTER_NOTELEPORT", "mf_monster_noteleport"), + ("MF_NOSAVE", "mf_nosave"), + ("MF_NOPENALTY", "mf_nopenalty"), + ("MF_PVP", "mf_pvp"), + ("MF_PVP_NOPARTY", "mf_pvp_noparty"), + ("MF_PVP_NOCALCRANK", "mf_pvp_nocalcrank"), + ("MF_NOWARP", "mf_nowarp"), + ("MF_NOWARPTO", "mf_nowarpto"), + ("MF_SNOW", "mf_snow"), + ("MF_FOG", "mf_fog"), + ("MF_SAKURA", "mf_sakura"), + ("MF_LEAVES", "mf_leaves"), + ("MF_TOWN", "mf_town"), + ("sc_poison", "SC_POISON"), + ("sc_slowpoison", "SC_SLOWPOISON"), + ("sc_adrenaline", "SC_ADRENALINE"), + ] + with open(dstFile, "w") as w: + tpl = readFile("templates/constants.tpl") + w.write(tpl); + srcFile = "serverdata/db/constants.conf" + with open(srcFile, "r") as r: + for line in r: + if line.find("**************************************************************************/") >= 0: + break + + for line in r: + line = line.strip() + if len(line) < 2 or line[0:2] == "//" or line[0:2] == "/*": + continue + const = readOneConst(r, line) + if const[0] == "comment__": + continue + fields[const[0]] = const[1].strip() + writeConst(w, const) + + srcDir = "oldserverdata/world/map/db/" + w.write("// tmw constants\n") + + fieldsSplit = re.compile("\t+") + + for srcFile in getConstsFile(srcDir): + with open(srcFile, "r") as r: + for line in r: + if len(line) < 2 or line[0:2] == "//": + continue + line = line.replace(" ", "\t") + rows = fieldsSplit.split(line) + if len(rows) != 2: + continue + + for val in vals: + if rows[0] == val[0]: + rows[0] = val[1] + if rows[0] in quests: + rows[1] = str(quests[rows[0]]) + "\n" + if rows[0] in fields: + if fields[rows[0]] != rows[1][:-1]: + print "warning: different const values for {0} ({1}, {2})".format(rows[0], rows[1][:-1], fields[rows[0]]) + else: + writeConst(w, (rows[0], stripNewLine(rows[1]), 0)) + w.write("// tmw npcs\n") + for npc in npcIds: + if npc == -1: + key = "MINUS1" + else: + key = str(npc) + writeConst(w, ("NPC" + key, npc, 0)) + w.write("}") diff --git a/hercules/code/server/tmw/itemdb.py b/hercules/code/server/tmw/itemdb.py new file mode 100644 index 0000000..dde9aaa --- /dev/null +++ b/hercules/code/server/tmw/itemdb.py @@ -0,0 +1,291 @@ +# -*- coding: utf8 -*- +# +# Copyright (C) 2014 Evol Online +# Author: Andrei Karas (4144) + +import os +import re + +from code.configutils import writeStartScript, writeEndScript, writeIntField, writeStrField +from code.fileutils import readFile + +def getItemDbFile(srcDir): + files = os.listdir(srcDir) + for srcFile in files: + if srcFile.find("item_db") >= 0: + yield srcFile + +def replaceStr(line): + vals = [ + ("setskill ", "addtoskill "), + ("zeny", "Zeny"), + ("sc_poison", "SC_POISON"), + ("sc_slowpoison", "SC_SLOWPOISON"), + ("sex", "Sex"), + ("SEX", "Sex"), + + (".gat", ""), + ("Bugleg", "BugLeg"), + ("set BugLeg, 0;", "//set BugLeg, 0;"), + ("set CaveSnakeLamp, 0;", "//set CaveSnakeLamp, 0;"), + ("set Class, @BaseClass;", "//set Class, @BaseClass;"), + ("goto_Exit;", "goto L_Exit;"), + ("if @spants_state < 7 goto", "if(@spants_state < 7) goto"), + ("isdead()", "ispcdead()"), + ("changeSex", "changecharsex()"), + ("getpartnerid2()", "getpartnerid()"), + + ("getmap()", "getmapname()"), + ("L_end", "L_End"), + ("gmcommand", "atcommand"), + ("MF_NOSAVE", "mf_nosave"), + ("S_update_var", "S_Update_Var"), + ("L_teach", "L_Teach"), + ("L_focus", "L_Focus"), + ("L_unfocus", "L_Unfocus"), + ("L_main", "L_Main"), + ("L_next", "L_Next"), + ("L_close", "L_Close"), + ("@NpcName$", "@npcname$"), + ("@cost", "@Cost"), + ("@TEMP", "@temp"), + ("L_Menuitems", "L_MenuItems"), + ("L_no_item", "L_No_Item"), + ("L_no_water", "L_No_Water"), + ("L_NOT_ENOUGH", "L_No_Water"), + ("L_bye", "L_Bye"), + ("L_NOHELP", "L_NoHelp"), + ("L_Eyepatch", "L_EyePatch"), + ("@PC_STAMINA", "@pc_stamina"), + ("L_magic", "L_Magic"), + ("L_cont", "L_Cont"), + ("L_accept", "L_Accept"), + ("L_no_event", "L_No_Event"), + ("L_event_done", "L_Event_Done"), + ("L_nobeer", "L_NoBeer"), + ("L_iron", "L_Iron"), + ("L_sulphur", "L_Sulphur"), + ("L_red", "L_Red"), + ("L_yellow", "L_Yellow"), + ("L_green", "L_Green"), + ("L_orange", "L_Orange"), + ("L_pink", "L_Pink"), + ("L_purple", "L_Purple"), + ("L_question", "L_Question"), + ("L_quest", "L_Quest"), + ("L_dead", "L_Dead"), + ("L_menu", "L_Menu"), + ("L_give", "L_Give"), + ("@Items$", "@items$"), + ("@menuItems$", "@menuitems$"), + ("L_Teach_initial", "L_Teach_Initial"), + ("L_finish", "L_Finish"), + ("L_No_ash", "L_No_Ash"), + ("L_No_water", "L_No_Water"), + ("L_cave", "L_Cave"), + ("L_farewell", "L_Farewell"), + ("@Q_forestbow_", "@Q_Forestbow_"), + ("L_game", "L_Game"), + ("L_good", "L_Good"), + ("L_abort", "L_Abort"), + ("@menuID", "@menuid"), + ("L_NO_ITEM", "L_No_Item"), + ("L_HELP", "L_Help"), + ("L_Noitem", "L_NoItem"), + ("L_No_fur", "L_No_Fur"), + ("@EXP", "@Exp"), + ("L_water", "L_Water"), + ("L_get", "L_Get"), + ("L_happy", "L_Happy"), + ("L_cheat", "L_Cheat"), + ("@Reward_EXP", "@Reward_Exp"), + ("@REWARD_EXP", "@Reward_Exp"), + ("L_no_money", "L_No_Money"), + ("@MinLevel", "@minLevel"), + ("L_return", "L_Return"), + ("L_intro", "L_Intro"), + ("L_full", "L_Full"), + ("@minlevel", "@minLevel"), + ("@MinLevel", "@minLevel"), + ("L_Cleanup", "L_CleanUp"), + ("L_Alreadystarted", "L_AlreadyStarted"), + ("@amount", "@Amount"), + ("L_again", "L_Again"), + ("L_no_potion", "L_No_Potion"), + ("L_wizard_hat", "L_Wizard_Hat"), + ("L_notenough", "L_NotEnough"), + ("L_offer", "L_Offer"), + ("L_giveup", "L_GiveUp"), + ("L_not_ready", "L_Not_Ready"), + ("@MobID", "@mobId"), + ("@mobID", "@mobId"), + ("L_naked", "L_Naked"), + ("L_shortcut", "L_Shortcut"), + ("L_shirt", "L_Shirt"), + ("L_goodjob", "L_GoodJob"), + ("L_kill", "L_Kill"), + ("L_nothing", "L_Nothing"), + ("L_lowlevel", "L_LowLevel"), + ("@mask", "@Mask"), + ("Foice", "FoiceItem"), + ("LanternaJack", "LanternaJackItem"), + # fix at same time usage with same name function and variable + ("\"DailyQuestPoints\"", "\"DailyQuestPointsFunc\""), + ("sc_adrenaline", "SC_ADRENALINE"), + ]; + + for val in vals: + line = line.replace(val[0], val[1]); + return line + +def getItType(it): + try: + i=int(it) + except: + i=None + if i == 0: + return '"IT_HEALING"' + elif i == 2: + return '"IT_USABLE"' + elif i == 3: + return '"IT_ETC"' + elif i == 4: + return '"IT_WEAPON"' + elif i == 5: + return '"IT_ARMOR"' + elif i == 6: + return '"IT_CARD"' + elif i == 7: + return '"IT_HEALING"' + elif i == 2: + return '"IT_HEALING"' + elif i == 2: + return '"IT_HEALING"' + elif i == 2: + return '"IT_HEALING"' + else: + print("Unrecognized item type: %s" % it) + return '"IT_ETC"' + +def convertItemDb(isNew): + srcDir = "oldserverdata/world/map/db/" + dstFile = "newserverdata/db/re/item_db.conf" + if os.path.isfile(dstFile): + os.remove(dstFile) + constsFile = "newserverdata/db/const.txt" + if os.path.isfile(constsFile): + os.remove(constsFile) + fieldsSplit = re.compile(",") + scriptsSplit = re.compile("},") + scriptsTextClean = re.compile('([{}])') + scriptsTextComma = re.compile('^,') + scriptsTextColon = re.compile('; ') + items = dict() + + tpl = readFile("templates/item_db.tpl") + with open(dstFile, "w") as w: + w.write(tpl) + with open(constsFile, "a") as c: + c.write("// items\n"); + for srcFile in getItemDbFile(srcDir): + with open(srcDir + srcFile, "r") as r: + for line in r: + if len(line) < 2 or line[0] == "#" or line[0:2] == "//": + continue + line = replaceStr(line) + rows = fieldsSplit.split(line) + if len(rows) < 5 or rows[0] == "0": + continue + + sz = len(rows) + if sz > 19: + sz = 19 + for f in xrange(0, sz): + rows[f] = rows[f].strip() + + items[rows[1]] = {'id':rows[0],'buy':rows[4],'name':rows[1]} + items[rows[0]] = {'id':rows[0],'buy':rows[4],'name':rows[1]} + items[int(rows[0])] = {'id':rows[0],'buy':rows[4],'name':rows[1]} + # set all values then write + w.write("{\n") + c.write("{0}\t{1}\n".format(rows[1], rows[0])) + writeIntField(w, "Id", rows[0]) + writeStrField(w, "AegisName", rows[1]) + if isNew == True: + offset = -1 + else: + offset = 0 + writeStrField(w, "Name", rows[offset + 2]) + if rows[offset + 3] == "0": + itemType = "2" + else: + itemType = rows[offset + 3] + writeIntField(w, "Type", itemType) + + writeIntField(w, "Buy", rows[offset + 4]) + if int(rows[offset + 4])*.75 <= int(rows[offset + 5])*1.24: + writeIntField(w, "Sell", str(int(int(rows[offset + 4])*.50))) + else: + writeIntField(w, "Sell", rows[offset + 5]) + writeIntField(w, "Weight", rows[offset + 6]) + writeIntField(w, "Atk", rows[offset + 7]) + writeIntField(w, "Matk", "0") + writeIntField(w, "Def", rows[offset + 8]) + writeIntField(w, "Range", rows[offset + 9]) + writeIntField(w, "Slots", "0") + writeIntField(w, "Gender", rows[offset + 12]) + writeIntField(w, "Loc", rows[offset + 13]) + writeIntField(w, "WeaponLv", rows[offset + 14]) + writeIntField(w, "EquipLv", rows[offset + 15]) + writeIntField(w, "Refine", "false") + if isNew == True: + offset = 2 + else: + offset = 0 + if rows[offset + 13] == "2": + writeIntField(w, "ViewSprite", "1") + elif rows[offset + 13] == "34": + writeIntField(w, "ViewSprite", "11") + elif rows[offset + 13] == "32768": + writeIntField(w, "ViewSprite", "1") + elif itemType == "4": # weapon + writeIntField(w, "ViewSprite", "1") + else: + writeIntField(w, "View", rows[0]) + writeIntField(w, "BindOnEquip", "false") + writeIntField(w, "BuyingStore", "false") + writeIntField(w, "Delay", "0") + writeIntField(w, "Sprite", "0") + + scripts = "" + if isNew == True: + offset = -1 + else: + offset = 0 + for f in xrange(offset + 17, len(rows)): + scripts = scripts + ", " + rows[f] + rows = scriptsSplit.split(scripts) + # Needs .split(';') and \n each + if len(rows) > 1: + UseScript = scriptsTextColon.sub(';',scriptsTextComma.sub('', scriptsTextClean.sub('', rows[0]))).strip().split(';') + EquipScript = scriptsTextColon.sub(';',scriptsTextComma.sub('', scriptsTextClean.sub('', rows[1]))).strip().split(';') + else: + UseScript = "" + EquipScript = "" + # move to for stmt + if len(UseScript) > 1: + writeStartScript(w, "Script") + for uline in UseScript: + if len(uline) > 0: + w.write(" {0};\n".format(uline)) + writeEndScript(w) + if len(EquipScript) > 1: + writeStartScript(w, "OnEquipScript") + for eline in EquipScript: + if len(eline) > 0: + w.write(" {0};\n".format(eline)) + writeEndScript(w) + + w.write("},\n") + w.write(")\n") + return items diff --git a/hercules/code/server/tmw/main.py b/hercules/code/server/tmw/main.py new file mode 100644 index 0000000..bfbf5ef --- /dev/null +++ b/hercules/code/server/tmw/main.py @@ -0,0 +1,49 @@ +#! /usr/bin/env python +# -*- coding: utf8 -*- +# +# Copyright (C) 2014 Evol Online +# Author: Andrei Karas (4144) + +from sets import Set + +from code.server.account import convertAccount +from code.server.accreg import convertAccReg +from code.server.party import convertParty +from code.server.storage import convertStorage +from code.server.db.char import saveCharTableCustom +from code.server.db.charregnumdb import saveCharRegNumDbTable +from code.server.db.inventory import saveInventoryTable +from code.server.db.skill import saveSkillTable +from code.server.tmw.athena import readAthena +from code.server.tmw.consts import convertConsts +from code.server.tmw.itemdb import convertItemDb +from code.server.tmw.mobdb import convertMobDb +from code.server.tmw.mobskilldb import convertMobSkillDb +from code.server.tmw.npcs import createMainScript, convertNpcs +from code.server.utils import cleanServerData + +def serverTmwMain(isNew): + try: + cleanServerData() + except: + print "Updating server" + createMainScript() + items = convertItemDb(isNew) + npcIds = Set() + convertNpcs(items, npcIds) + convertMobDb(items) + quests = dict() + convertConsts(quests, npcIds) + convertMobSkillDb() + +def dbTmwMain(): + convertAccount() + users = readAthena() +# saveCharTable(users) + saveCharTableCustom(users) + saveCharRegNumDbTable(users) + saveSkillTable(users) + saveInventoryTable(users) + convertStorage() + convertAccReg() + convertParty(users) diff --git a/hercules/code/server/tmw/mobdb.py b/hercules/code/server/tmw/mobdb.py new file mode 100644 index 0000000..10edfd1 --- /dev/null +++ b/hercules/code/server/tmw/mobdb.py @@ -0,0 +1,173 @@ +# -*- coding: utf8 -*- +# +# Copyright (C) 2014 Evol Online +# Author: Andrei Karas (4144) + +import math +import os +import re + +from code.configutils import isHaveData, writeCondField2, writeStartBlock, writeEndBlock, writeIntField, writeStrField, writeFieldArr, writeIntField2, writeFieldList, writeSubField +from code.fileutils import readFile + +def getMobDbFile(srcDir): + files = os.listdir(srcDir) + for srcFile in files: + if srcFile.find("mob_db") >= 0: + yield srcFile + +def replaceStr(line): + vals = [ + ("lanternaJack", "LanternaJack"), + ("foice", "Foice"), + ("BlueFairy", "BlueFairyMob"), + ("RedFairy", "RedFairyMob"), + ("GreenFairy", "GreenFairyMob"), + ("Scorpion", "ScorpionMob"), + ("Tritan", "TritanMob"), + ("Ukar", "UkarMob"), + ]; + + for val in vals: + line = line.replace(val[0], val[1]); + return line + +def convertMobDb(items): + srcDir = "oldserverdata/world/map/db/" + dstFile = "newserverdata/db/re/mob_db.conf" + fieldsSplit = re.compile(",") + tpl = readFile("templates/mob_db.tpl") + with open(dstFile, "w") as w: + w.write(tpl) + for srcFile in getMobDbFile(srcDir): + with open(srcDir + srcFile, "r") as r: + for line in r: + if len(line) < 2 or line[:2] == "//" or line[:1] == "#": + w.write(line) + continue + line = replaceStr(line) + rows = fieldsSplit.split(line) + for f in xrange(0, len(rows)): + rows[f] = rows[f].strip() + try: + val = int(rows[23]) + if val < 20: + rows[23] = "20" + except: + None + + # Experience and Job experience, following *tmw-eathena*/src/map/mob.c + calc_exp = 0 + + if rows[6] == "0": + if int(rows[4]) <= 1: + calc_exp = 1 + + mod_def = 100 - int(rows[11]) + + if mod_def == 0: + mod_def = 1 + + effective_hp = ((50 - int(rows[18])) * int(rows[4]) / 50) + (2 * int(rows[18]) * int(rows[4]) / mod_def) + attack_factor = (int(rows[9]) + int(rows[10]) + int(rows[13]) / 3 + int(rows[17]) / 2 + int(rows[18])) * (1872 / int(rows[26])) / 4 + dodge_factor = (int(rows[3]) + int(rows[14]) + int(rows[18]) / 2)**(4 / 3) + persuit_factor = (3 + int(rows[8])) * (int(rows[24]) % 2) * 1000 / int(rows[25]) + aggression_factor = 1 + + if False: + aggression_factor = 10 / 9 + + base_exp_rate = 100 # From *tmw-eathena-data*/conf/battle_athena.conf + + calc_exp = int(math.floor(effective_hp * (math.sqrt(attack_factor) + math.sqrt(dodge_factor) + math.sqrt(persuit_factor) + 55)**3 * aggression_factor / 2000000 * base_exp_rate / 100)) + + if calc_exp < 1: + calc_exp = 1 + else: + calc_exp = rows[6] + + w.write("{\n") + writeIntField(w, "Id", rows[0]) + writeStrField(w, "SpriteName", rows[1]) + if (rows[2] != rows[1]): + writeStrField(w, "Name", rows[2]) + else: + writeStrField(w, "Name", "The %s" % rows[2]) + writeIntField(w, "Lv", rows[3]) + writeIntField(w, "Hp", rows[4]) + writeIntField(w, "Sp", rows[5]) + writeIntField(w, "Exp", calc_exp) + writeIntField(w, "JExp", rows[7]) + writeIntField(w, "AttackRange", rows[8]) + writeFieldArr(w, "Attack", rows[9], rows[10]) + writeIntField(w, "Def", rows[11]) + writeIntField(w, "Mdef", rows[12]) + writeStartBlock(w, "Stats") + writeIntField2(w, "Str", rows[13]) + writeIntField2(w, "Agi", rows[14]) + writeIntField2(w, "Vit", rows[15]) + writeIntField2(w, "Int", rows[16]) + writeIntField2(w, "Dex", rows[17]) + writeIntField2(w, "Luk", rows[18]) + writeEndBlock(w) + writeIntField(w, "ViewRange", rows[19]) + writeIntField(w, "ChaseRange", 10) + writeIntField(w, "Size", rows[21]) + writeIntField(w, "Race", rows[22]) + writeFieldList(w, "Element", int(rows[23]) % 10, int(rows[23]) / 20) + mode = int(rows[24], 0) + if mode != 0: + writeStartBlock(w, "Mode") + writeCondField2(w, mode & 0x0001, "CanMove") + writeCondField2(w, mode & 0x0002, "Looter") + writeCondField2(w, mode & 0x0004, "Aggressive") + writeCondField2(w, mode & 0x0008, "Assist") + writeCondField2(w, mode & 0x0010, "CastSensorIdle") + writeCondField2(w, mode & 0x0020, "Boss") + writeCondField2(w, mode & 0x0040, "Plant") + writeCondField2(w, mode & 0x0080, "CanAttack") + writeCondField2(w, mode & 0x0100, "Detector") + writeCondField2(w, mode & 0x0200, "CastSensorChase") + writeCondField2(w, mode & 0x0400, "ChangeChase") + writeCondField2(w, mode & 0x0800, "Angry") + writeCondField2(w, mode & 0x1000, "ChangeTargetMelee") + writeCondField2(w, mode & 0x2000, "ChangeTargetChase") + writeCondField2(w, mode & 0x4000, "TargetWeak") + writeCondField2(w, mode & 0x8000, "LiveWithoutMaster") + writeEndBlock(w) + writeIntField(w, "MoveSpeed", rows[25]) + writeIntField(w, "AttackDelay", rows[26]) + writeIntField(w, "AttackMotion", rows[27]) + writeIntField(w, "DamageMotion", rows[28]) + writeIntField(w, "MvpExp", rows[45]) + + if isHaveData(rows, 47, 3): + writeStartBlock(w, "MvpDrops") + for f in range(0, 3): + value = rows[47 + f * 2] + chance = rows[47 + f * 2] + if value == "" or value == "0" or chance == "" or chance == "0": + continue + value = int(value) + if value not in items: + w.write("// Error: mvp drop with id {0} not found in item db\n".format(value)) + print("Error: mvp drop with id {0} not found in item db".format(value)) + else: + writeSubField(w, items[value]["name"], chance) + writeEndBlock(w) + if isHaveData(rows, 29, 10): + writeStartBlock(w, "Drops") + for f in range(0, 10): + value = rows[29 + f * 2] + chance = rows[30 + f * 2] + if value == "" or value == "0" or chance == "" or chance == "0": + continue + value = int(value) + if value not in items: + w.write("// Error: drop with id {0} not found in item db\n".format(value)) + print("Error: drop with id {0} not found in item db".format(value)) + else: + writeSubField(w, items[value]["name"], chance) + writeEndBlock(w) + w.write("},\n") + w.write(")\n") diff --git a/hercules/code/server/tmw/mobskilldb.py b/hercules/code/server/tmw/mobskilldb.py new file mode 100644 index 0000000..7188824 --- /dev/null +++ b/hercules/code/server/tmw/mobskilldb.py @@ -0,0 +1,55 @@ +# -*- coding: utf8 -*- +# +# Copyright (C) 2014 Evol Online +# Author: Andrei Karas (4144) + +import re + +from code.fileutils import readFile + +def convertMobSkillDb(): + srcFile = "oldserverdata/world/map/db/mob_skill_db.txt" + dstFile = "newserverdata/db/re/mob_skill_db.txt" + fieldsSplit = re.compile(",") + notintown = re.compile("notintown") + notintownSub = re.compile("notintown,0") + with open(srcFile, "r") as r: + with open(dstFile, "w") as w: + tpl = readFile("templates/mob_skill_db.tpl") + w.write(tpl) + for line in r: + if notintown.search(line): + if line[0:2] == "//": + line = '' + line = notintownSub.sub("myhpltmaxrate,20",line) + if len(line) < 2 or line[0:2] == "//": + w.write(line) + continue + rows = fieldsSplit.split(line) + if len(rows) < 10: + w.write(line) + continue + + for f in xrange(0, len(rows)): + rows[f] = rows[f].strip() + + w.write("{0},{1},{2},{3},{4},{5},{6}," + "{7},{8},{9},{10},{11},{12},{13}," + "{14},,,,\n".format( + rows[0], + rows[1], + rows[2], + rows[3], + rows[4], + rows[5], + rows[6], + rows[7], + rows[8], + rows[9], + rows[10], + rows[11], + rows[12], + rows[13], + rows[14] + )) + diff --git a/hercules/code/server/tmw/npcs.py b/hercules/code/server/tmw/npcs.py new file mode 100644 index 0000000..c51da78 --- /dev/null +++ b/hercules/code/server/tmw/npcs.py @@ -0,0 +1,878 @@ +# -*- coding: utf8 -*- +# +# Copyright (C) 2014 Evol Online +# Author: Andrei Karas (4144) + +import os +import re + +from code.fileutils import makeDir +from code.stringutils import stripWindows, stripNewLine + +mapsConfFile = "newserverdata/conf/maps.conf" +if os.path.isfile(mapsConfFile): + os.remove(mapsConfFile) +mapsIndexFile = "newserverdata/db/map_index.txt" +if os.path.isfile(mapsIndexFile): + os.remove(mapsIndexFile) +npcMainScript = "newserverdata/npc/re/scripts_main.conf" +mapsIndex = 1 +scriptRe = re.compile("^(((?P[^/](.+)),([ ]*)(?P[\d]+),([ ]*)(?P[\d]+),([ ]*)(?P[\d]+))|(?Pfunction)|-)" + + "[|](?Pscript)[|](?P[^|]+)([|]" + "(?P[\d-]+)((,((?P[\d]+),(?P[\d]+)))|)|)$") + +scriptRe2 = re.compile("^(((?P[^/](.+))[.]gat,([ ]*)(?P[\d]+),([ ]*)(?P[\d]+),([ ]*)(?P[\d]+))|(?Pfunction)|-)" + + "[\t](?Pscript)[\t](?P[\w#'\\[\\]_ äü.-]+)[\t]" + "(((?P[\d-]+)((,((?P[\d-]+),(?P[\d-]+)))|)(|,)(|[ \t]))|){(|[ ])$") + +shopRe = re.compile("^(?P[^/](.+)),([ ]*)(?P[\d]+),([ ]*)(?P[\d]+),([ ]*)(?P[\d]+)(|,(?P[\d]+))" + + "[|](?Pshop)[|](?P[^|]+)[|]" + "(?P[\d-]+),(?P(.+))$") + +shopRe2 = re.compile("^(?P[^/](.+))[.]gat,([ ]*)(?P[\d]+),([ ]*)(?P[\d]+),([ ]*)(?P[\d]+)" + + "[\t](?Pshop)[\t](?P[^\t]+)[\t]" + "(?P[\d]+),(?P(.+))$") + +mapFlagRe = re.compile("^(?P[^/](.+))" + + "[|](?Pmapflag)[|](?P[\w#']+)(|[|](?P.*))$") + +mapFlagRe2 = re.compile("^(?P[^/](.+))[.]gat" + + "[ ](?Pmapflag)[ ](?P[\w#']+)(|[ ](?P.*))$") + +warpRe = re.compile("^(?P[^/](.+)),([ ]*)(?P[\d]+),([ ]*)(?P[\d]+)[|]" + "(?Pwarp)[|](?P[^|]+)[|](?P[\d-]+),(?P[\d-]+),(?P[^/](.+)),([ ]*)(?P[\d]+),([ ]*)(?P[\d]+)$") +warpRe2 = re.compile("^(?P[^/](.+))[.]gat,([ ]*)(?P[\d]+),([ ]*)(?P[\d]+)([\t]+)" + "(?Pwarp)[\t](?P[^\t]+)([\t]+)(?P[\d-]+),(?P[\d-]+),(?P[^/](.+))[.]gat,([ ]*)(?P[\d]+),([ ]*)(?P[\d]+)$") +warpRe3 = re.compile("^(?P[^/](.+)),([ ]*)(?P[\d]+),([ ]*)(?P[\d]+)[|]" + "(?Pwarp)[|](?P[\d-]+),(?P[\d-]+),(?P[^/](.+)),([ ]*)(?P[\d]+),([ ]*)(?P[\d]+)$") + +monsterRe = re.compile("^(?P[^/](.+)),([ ]*)(?P[\d]+),([ ]*)(?P[\d]+),([ ]*)(?P[\d-]+),(?P[\d-]+)[|]" + "(?Pmonster)[|](?P[^|]+)[|]" + "(?P[\d]+),(?P[\d]+),(?P[\d]+)ms,(?P[\d]+)ms(|,(?P