Repository navigation
Expand file tree
/
Copy pathNierAutoModSave.py
More file actions
executable file
·250 lines (198 loc) · 9.33 KB
/
Copy pathNierAutoModSave.py
File metadata and controls
executable file
·250 lines (198 loc) · 9.33 KB
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
NieR:AutoModSave v0.1 by jimmyazrael
This script will guide and help you to import Nier:Automata's game saves shared by others.
Requirements:
1. Preferably you should have received the whole save folder,
or at least you should have the following files:
GameData.dat, one or more than one of the SlotData files
and probably SystemData.dat. Although the use of SystemData.dat
is still unknown.
2. Please make sure you back up your own save folder, as using other's
save file will make yours unreadable. If you would like to use your save files
again, simply treat your own backup save folder as the one shared by someone else
and repeat the very same steps stated below.
Steps:
1. Back up your WHOLE save folder, which is likely located at `Documents/My Games/NieR_Automata`.
2. Remove everything except `Graphic.ini` in that folder.
3. Put the files (except `Graphic.ini`) you received from another player in the folder.
If you prefer exe:
4. Put `NierAutoModSave.exe` in the same folder, run it, follow it, done.
If you prefer a Python script and you have Python installed:
4. Put `NierAutoModSave.py` in the same folder and run it, follow it, done.
"""
import os
import sys
import glob
import time
class Main():
"""
The main class.
"""
def __init__(self):
"""
The initialization method of Main() class.
"""
# self.messages format: {<language>: {<message_id>: <message>},}
# You can add a new language by adding a new item to the `self.messages` variable.
self.messages = {
"English": {
"gd_not_found": """\
GameData.dat not found in this directory, please find and put it here.
Press ENTER to continue when the file is ready.""",
"confirm_gd_found": "GameData.dat found in default folder:\n{0}",
"gen_msg": """\
A new GameData.dat is currently needed to continue the process.
It can be generated by the game.
Please start the game. Do not close this window.""",
"modsv": "Modifying {0}...",
"modgd": "Modifying `GameData.dat`...",
"end": "\nFinished. Glory to mankind!\nPress enter to exit..."
},
u"Chinese (中文)": {
"gd_not_found": u"本目录下没有GameData.dat文件,请将其放入。\n放入后按回车继续。",
"confirm_gd_found": "GameData.dat 在默认文件夹中找到:\n{0}",
"gen_msg": u"""\
现在需要一个新的GameData.dat文件。
该文件应该由游戏自动生成。
请启动游戏。不要关闭此窗口。""",
"modsv": u"修改 {0}...",
"modgd": u"修改 GameData.dat...",
"end": u"\n任务完成。荣耀归于人类!"
},
"Tagalog": {
"gd_not_found": "Hindi makita ang GameData.dat sa folder na ito. Pakihanap at pakilagay ang mga files dito at i-press ang ENTER.",
"confirm_gd_found": "Nakita ang GameData.dat sa default folder:\n{0}",
"gen_msg": """\
Kasalukuyang kailangan ang isang bagong GameData.dat upang magpatuloy sa proseso.
Ito ay awtomatikong gagawin ng laro.
Mangyaring buksan ang laro. Huwag isarado ang window na ito.""",
"modsv": "Minomodify ang {0}...",
"modgd": "Minomodify ang GameData.dat...",
"end": "Tapos na. Glory to mankind! Pindutin ang enter para matapos na ang proseso."
}
}
self.language = "English" # Set default language to English.
self.default_savefile_path = os.path.join(os.path.expanduser("~"), "Documents", "My Games", "NieR_Automata")
def languageSelect(self):
"""
Select a language from self.messages.
:returns void:
"""
print("Please select preferred language:\n")
available_languages = list(self.messages.keys())
i = 1
# Print available keys (languages) of self.messages.
for language in available_languages:
print("[{0}] {1}".format(i, language))
i += 1
print()
while True:
try:
# Get user's choice.
user_choice = int(input("Language: ")) - 1 # Because Python index starts with 0.
if user_choice < 0 or user_choice >= len(available_languages):
print("[ERROR] Language #{0} doesn't exist.".format(user_choice + 1))
continue
else:
self.language = available_languages[user_choice] # Set language.
break
except(TypeError, ValueError):
print("[ERROR] Please enter the number of the language you want to use.")
continue
except KeyboardInterrupt:
print("[!] Using {0} as default language.".format(self.language))
break
return
def getMessage(self, message_key: str):
"""
Return a message from self.messages.
:param str message_key: The key of the message to print.
:returns str: The value of the key.
"""
return self.messages[self.language][message_key]
def main(self):
"""
The main method of Main() class.
:returns int: Error code.
0 = No error, all good.
1 = GameData.dat not found.
2 = CTRL+C pressed. (try/except block defined on program start.)
3 = An unknown error occured. (try/except block defined on program start.)
"""
self.languageSelect() # Select a language.
# ? STEP #1: Check if GameData.dat is in the current or default save folder.
# Check if GameData.dat is in the current directory.
gamedata_exists = False
while not gamedata_exists:
if not os.path.isfile("GameData.dat"):
# Try to find GameData.dat in the default save folder.
if not os.path.isfile(os.path.join(self.default_savefile_path, "GameData.dat")):
input(self.getMessage("gd_not_found"))
continue
else:
print(self.getMessage("confirm_gd_found").format(self.default_savefile_path))
while True:
set_savefile_path_confirm = input("Do you want to continue? (y/n): ")
if set_savefile_path_confirm.lower().startswith('y'):
self.savefile_path = self.default_savefile_path # Set save folder.
gamedata_exists = True
break
elif set_savefile_path_confirm.lower().startswith('n'):
input(self.getMessage("gd_not_found"))
return 1
else:
continue
else:
# This means that the user has the GameData.dat in the current directory.
self.savefile_path = "."
break
# ? STEP #2: Rename GameData.dat to savemod_GameData.dat.
# If savemod_GameData.dat exists, delete it.
if os.path.isfile(os.path.join(self.savefile_path, "savemod_GameData.dat")):
os.remove(os.path.join(self.savefile_path, "savemod_GameData.dat"))
else:
# Rename GameData.dat to savemod_GameData.dat.
os.rename(os.path.join(self.savefile_path, "GameData.dat"), os.path.join(self.savefile_path, "savemod_GameData.dat"))
# ? STEP #3: Extract signature string.
while True:
try:
with open(os.path.join(self.savefile_path, "GameData.dat"), "rb") as f:
signature = f.read(15)
break
except IOError:
print(self.getMessage("gen_msg"))
while not os.path.exists(os.path.join(self.savefile_path, "GameData.dat")):
time.sleep(0.5)
continue
os.remove(os.path.join(self.savefile_path, "GameData.dat")) # We don't need the original GameData.dat.
# ? STEP #4: Modify save slot(s) data header with the signature string.
for save_slot in glob.glob(os.path.join(self.savefile_path, "SlotData_?.dat")):
print(self.getMessage("modsv").format(save_slot))
with open(save_slot, "rb+") as f:
content = f.read()
content = content[:4] + signature + content[19:]
f.seek(0)
f.write(content)
# ? STEP #5: Modify original shared GameData.dat.
print(self.getMessage("modgd"))
os.rename(os.path.join(self.savefile_path, "savemod_GameData.dat"), os.path.join(self.savefile_path, "GameData.dat"))
with open(os.path.join(self.savefile_path, "GameData.dat"), "rb+") as f:
content = f.read()
content = signature + content[15:]
f.seek(0)
f.write(content)
# ? STEP #6: Profit.
input(self.getMessage("end"))
return 0
if __name__ == "__main__":
try:
sys.exit(Main().main())
except KeyboardInterrupt:
print("\n[!] Exiting...")
sys.exit(2)
except Exception as e:
print("[!] An error occurred: {0}".format(e))
input("Press enter to exit.")
sys.exit(3)