-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtranslate.py
147 lines (132 loc) · 6.03 KB
/
translate.py
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
import argparse
import os
from mapping import *
from convert import *
from encrypt import *
def main():
# Handle input arguments
parser = argparse.ArgumentParser(allow_abbrev=False)
parser.add_argument('--no-grind', action='store_true', help='activate powerups in output save file')
do_activate_powerups = parser.parse_args().no_grind
# Test for output file
if os.path.isfile('highscores.lua') or os.path.isfile('settings.lua'):
print('Output save file (highscores.lua / settings.lua) already exists')
while True:
response = input('Overwrite? [y/n] ')
if re.match('^[Yy]$', response) is not None:
break
elif re.match('^[Nn]$', response) is not None:
exit(0)
# Read save data
try:
save_file = open('getGameState', encoding='utf-8', errors='ignore')
except FileNotFoundError as exception:
raise Exception('Input save file (getGameState) is not found') from exception
save_raw = save_file.read()
save_file.close()
try:
save_data = json.loads(re.sub('^[^{]+(.*)[^}]+$', '\\1', save_raw))
except json.decoder.JSONDecodeError as exception:
raise Exception('Input save file (getGameState) has incorrect content format') from exception
# Initialize output save data
highscores_data = {}
settings_data = {
'settingsVersion': {
'id': 4,
'version': '4.3.0',
'newId': 6
},
'isPremium': True,
'shopChildlockOn': True,
'cumulativeStars': 0
}
# Convert Golden Egg acquisition data
if 'acquisitions' in save_data:
highscores_data['openGoldenEggLevels'] = {}
for golden_egg in save_data['acquisitions']:
highscores_data['openGoldenEggLevels'][GoldenEggName[golden_egg['name']]] = {
'unlocked': True,
'opened': False
}
for golden_egg_name in GoldenEggName.values():
if golden_egg_name not in highscores_data['openGoldenEggLevels']:
highscores_data['openGoldenEggLevels'][golden_egg_name] = {
'unlocked': False,
'opened': False
}
assert len(highscores_data['openGoldenEggLevels']) == len(GoldenEggName) - 5
# Convert score data
if 'episodes' in save_data:
for episode in save_data['episodes']:
for level in episode['levelScores']:
is_minigame = '#' in level['LevelName']
if is_minigame:
level_name = GoldenEggName[level['LevelName']]
else:
level_name = 'Level' + level['LevelName']
highscores_data[level_name] = {}
highscores_data[level_name]['completed'] = level['Points'] > 0
highscores_data[level_name]['legitScore'] = 0 if is_minigame else level['Points']
highscores_data[level_name]['score'] = 0 if is_minigame else level['Points']
highscores_data[level_name]['lowScore'] = 0 if is_minigame else level['Points']
highscores_data[level_name]['powerUpScore'] = 0
highscores_data[level_name]['birds'] = 0 if is_minigame else 1
settings_data['cumulativeStars'] += level['Stars']
if level['EagleHighScore'] > 0:
highscores_data[level_name]['eagleScoreMax'] = level['EagleHighScore']
highscores_data[level_name]['eagleScoreMin'] = level['EagleHighScore']
highscores_data[level_name]['eagleScore'] = 100 if level['EagleTotalDestruction'] else 0
if level_name in highscores_data['openGoldenEggLevels'] and level['Points'] > 0:
highscores_data['openGoldenEggLevels'][level_name]['opened'] = True
# Convert shown tutorial data
if 'shownTutorials' in save_data:
settings_data['tutorials'] = {}
for tutorial in save_data['shownTutorials']:
settings_data['tutorials'][BirdReference[tutorial][0]] = {
'sprite': BirdReference[tutorial][1]
}
if BirdReference[tutorial][2]:
settings_data['tutorials'][BirdReference[tutorial][0]]['showHelp'] = False
# Convert last viewed episode page data
if 'episodePages' in save_data:
settings_data['currentLevelSelectionPages'] = {}
for episode in save_data['episodePages']:
settings_data['currentLevelSelectionPages'][EpisodeID[episode['id']]] = episode['page'] + 1
# Convert Boomerang bird acquisition data
if 'boomerangAcquired' in save_data:
settings_data['boomerangBirdAchieved'] = save_data['boomerangAcquired']
else:
settings_data['boomerangBirdAchieved'] = False
# Update powerups data
if do_activate_powerups:
settings_data['shopChildlockOn'] = False
settings_data['mightyEagleUnlocked'] = True
settings_data['mightyEagleEnabled'] = True
settings_data['flagTable'] = {
'redsMightyFeathersPurchased': True
}
settings_data['syncedFlagTable'] = {
'shockwavePowerupUnlocked': True
}
settings_data['installationSpecificInventory'] = {}
for powerup in PowerupInventory:
settings_data['installationSpecificInventory'][powerup] = {
'totalCount': PowerupInventory[powerup],
'usedCount': 0
}
# Format and encrypt converted data
highscores_raw = encrypt(convert(highscores_data))
settings_raw = encrypt(convert(settings_data))
# Output converted data to file
try:
highscores_file = open('highscores.lua', 'wb')
settings_file = open('settings.lua', 'wb')
except PermissionError as exception:
raise Exception('Output save file (highscores.lua / settings.lua) is not writable') from exception
highscores_file.write(highscores_raw)
highscores_file.close()
settings_file.write(settings_raw)
settings_file.close()
print("Translation completed")
if __name__ == '__main__':
main()