File: cheat_code_convert.py

package info (click to toggle)
mupen64plus-core 2.5-4
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 5,776 kB
  • ctags: 7,778
  • sloc: ansic: 59,320; asm: 1,994; cpp: 1,823; python: 619; makefile: 600; sh: 311
file content (118 lines) | stat: -rwxr-xr-x 4,287 bytes parent folder | download | duplicates (6)
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#!/usr/bin/python
'''* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 *   Mupen64plus - code_convert.c                                          *
 *   Mupen64Plus homepage: http://code.google.com/p/mupen64plus/           *
 *   Copyright (C) 2010 Rhett Osborne                                      *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.          *
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

Usage:

python code_convert.py > ../data/mupencheat.txt < ../data/mupen64plus.cht

'''

from sys import stdin

class cheat:
    def __init__(self):
        self.n=""
        self.d=""
        self.c=[]
        self.v=0
        self.hb='00'
    def add(self, l):
        if(self.n == ""):
            return
        l.append(" cn %s"%(self.n))
        if(self.d != ""): l.append("  cd %s"%(self.d))
        for code in self.c:
            l.append("  "+code)
    def clear(self):
        self.n=""
        self.d=""
        self.c=[]
        self.v=0
        

l=[]
cCount=0
_cs = []
for i in range(225):
 _cs.append(cheat())
cs = _cs[:]

def print_l():
    global l, cs
    for cheat in cs:
        cheat.add(l)
    for line in l:
        print line.replace("\x00", "")
    l=[]
    cCount=0
    for i in range(225):
        cs[i].clear()

lines = stdin.read().split("\n")

for line in lines:
    if len(line) < 2: continue
    elif(line[:2] == "//" and line != "//----" and line != "//---" ):
        l.append(line)
    elif len(line) < 4: continue
    elif(line[0] == '[' and line[-1] == ']' and len(line) > 23):
        print_l()
        l.append("\ncrc %s" % line[1:-1])
    elif(line[:5] == "Name="):
        l.append("gn %s" % (line[5:]))
    elif(line[:5] == "Cheat"):
        t = line[5:].split('=')[0]
        if (len(t)>1 and t[-2] == '_'):
            n = int(t[:-2])
            if(t[-1] == 'N'):
                cs[n].d = line.split("=")[1]
            else:
                for option in line.split("=")[1].split("$")[1:]:
                    if(len(option) < 4):
                        break;
                    if(option[-1]==','): end =-1
                    else: end = None
                    if(option[2] == " "):
                        cs[n].c[cs[n].v] += "%s%s:\"%s\""%(cs[n].hb,option[:2],option[3:end].replace("\"", "\\\""))
                    else:
                        cs[n].c[cs[n].v] += "%s:\"%s\""%(option[:4],option[5:end].replace("\"", "\\\""))
                    cs[n].c[cs[n].v]+=','
                cs[n].c[cs[n].v] = cs[n].c[cs[n].v][:-1]
        else:
            n = int(t)
            cn = line.split('"')
            cs[n].c = cn[2][1:].split(',')
            cs[n].n = cn[1];
            i=0
            for cheat in cs[n].c:
                if(cheat[-1] == '?'):
                    if(cheat[-2:] == '??' and cheat[-4:-2] != '??'):
                        cs[n].hb = cheat[-4:-2]
                    else:
                        cs[n].hb = '00'
                    cs[n].c[i] = cheat[:9] + "???? ";
                    cs[n].v=i
                i+=1
        if(n > cCount):
            cCount = n
    elif(line != "//----" and line != "//---" ):
        l.append("//%s" %line)