summaryrefslogtreecommitdiff
path: root/hercules/code/servertoclient/luas.py
blob: 6399da633ebc09c3b8cb41ab7e5b786a73b9f021 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# -*- coding: utf8 -*-
#
# Copyright (C) 2015  Evol Online
# Author: Andrei Karas (4144)

import re
from sets import Set

from code.fileutils import *
from code.stringutils import *

comaSplit = re.compile(",")
equalSplit = re.compile("=")

def extractLuaArray(fileName, arrName):
    with open(fileName, "r") as f:
        for line in f:
            if line.find(arrName) == 0:
                line = line[line.find("{") + 1:]
                line = line[:line.find("}")]
                return line
    return ""

def convertJobName():
    jobs = dict()
    jobNameFile = "rodata/decompiled/jobname.lua"
    line = extractLuaArray(jobNameFile, "JobNameTable")
    arr = comaSplit.split(line)
    for itemStr in arr:
        parts = equalSplit.split(itemStr.strip())
        if parts[0].find("[jobtbl.") == 0:
            key = parts[0].strip()
            key = key[8:-1].strip()
            val = parts[1].strip()
            val = val[1:-1].strip()
            jobs[key] = val
    return jobs

def convertIdentity(jobs):
    idents = dict()
    npcIdentityFile = "rodata/decompiled/npcidentity.lua"
    line = extractLuaArray(npcIdentityFile, "jobtbl = ")
    arr = comaSplit.split(line)
    for itemStr in arr:
        parts = equalSplit.split(itemStr.strip())
        key = parts[0].strip()
        val = parts[1].strip()
        if key in jobs:
            idents[val] = jobs[key].lower()
    return idents

def convertLuas():
    jobs = convertJobName()
    idtofile = convertIdentity(jobs)
    return idtofile