Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alexbevi
GitHub Repository: alexbevi/BizHawk
Path: blob/master/libmupen64plus/mupen64plus-core/tools/cheat_code_convert.py
2 views
1
#!/usr/bin/python
2
'''* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
3
* Mupen64plus - code_convert.c *
4
* Mupen64Plus homepage: http://code.google.com/p/mupen64plus/ *
5
* Copyright (C) 2010 Rhett Osborne *
6
* *
7
* This program is free software; you can redistribute it and/or modify *
8
* it under the terms of the GNU General Public License as published by *
9
* the Free Software Foundation; either version 2 of the License, or *
10
* (at your option) any later version. *
11
* *
12
* This program is distributed in the hope that it will be useful, *
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15
* GNU General Public License for more details. *
16
* *
17
* You should have received a copy of the GNU General Public License *
18
* along with this program; if not, write to the *
19
* Free Software Foundation, Inc., *
20
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
21
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
22
23
Usage:
24
25
python code_convert.py > ../data/mupencheat.txt < ../data/mupen64plus.cht
26
27
'''
28
29
from sys import stdin
30
31
class cheat:
32
def __init__(self):
33
self.n=""
34
self.d=""
35
self.c=[]
36
self.v=0
37
self.hb='00'
38
def add(self, l):
39
if(self.n == ""):
40
return
41
l.append(" cn %s"%(self.n))
42
if(self.d != ""): l.append(" cd %s"%(self.d))
43
for code in self.c:
44
l.append(" "+code)
45
def clear(self):
46
self.n=""
47
self.d=""
48
self.c=[]
49
self.v=0
50
51
52
l=[]
53
cCount=0
54
_cs = []
55
for i in range(225):
56
_cs.append(cheat())
57
cs = _cs[:]
58
59
def print_l():
60
global l, cs
61
for cheat in cs:
62
cheat.add(l)
63
for line in l:
64
print line.replace("\x00", "")
65
l=[]
66
cCount=0
67
for i in range(225):
68
cs[i].clear()
69
70
lines = stdin.read().split("\n")
71
72
for line in lines:
73
if len(line) < 2: continue
74
elif(line[:2] == "//" and line != "//----" and line != "//---" ):
75
l.append(line)
76
elif len(line) < 4: continue
77
elif(line[0] == '[' and line[-1] == ']' and len(line) > 23):
78
print_l()
79
l.append("\ncrc %s" % line[1:-1])
80
elif(line[:5] == "Name="):
81
l.append("gn %s" % (line[5:]))
82
elif(line[:5] == "Cheat"):
83
t = line[5:].split('=')[0]
84
if (len(t)>1 and t[-2] == '_'):
85
n = int(t[:-2])
86
if(t[-1] == 'N'):
87
cs[n].d = line.split("=")[1]
88
else:
89
for option in line.split("=")[1].split("$")[1:]:
90
if(len(option) < 4):
91
break;
92
if(option[-1]==','): end =-1
93
else: end = None
94
if(option[2] == " "):
95
cs[n].c[cs[n].v] += "%s%s:\"%s\""%(cs[n].hb,option[:2],option[3:end].replace("\"", "\\\""))
96
else:
97
cs[n].c[cs[n].v] += "%s:\"%s\""%(option[:4],option[5:end].replace("\"", "\\\""))
98
cs[n].c[cs[n].v]+=','
99
cs[n].c[cs[n].v] = cs[n].c[cs[n].v][:-1]
100
else:
101
n = int(t)
102
cn = line.split('"')
103
cs[n].c = cn[2][1:].split(',')
104
cs[n].n = cn[1];
105
i=0
106
for cheat in cs[n].c:
107
if(cheat[-1] == '?'):
108
if(cheat[-2:] == '??' and cheat[-4:-2] != '??'):
109
cs[n].hb = cheat[-4:-2]
110
else:
111
cs[n].hb = '00'
112
cs[n].c[i] = cheat[:9] + "???? ";
113
cs[n].v=i
114
i+=1
115
if(n > cCount):
116
cCount = n
117
elif(line != "//----" and line != "//---" ):
118
l.append("//%s" %line)
119
120