-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGet-Retron5Dump.ps1
288 lines (229 loc) · 9.16 KB
/
Get-Retron5Dump.ps1
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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
#################################
#RetroN 5 ROM Dump Script
#Version 1.2
#Written by pCeSlAyEr
#################################
##Supress error messages to console##
$ErrorActionPreference = 'SilentlyContinue'
##Query output directory existance##
$outExists = (Get-ChildItem -dir | where {$_.name -match 'out'} | select Exists).Exists
##If output directory not exist then create##
if(!($outExists)){
Write-Host "Out directory doesn't Exist... Creating..." -Foregroundcolor Yellow
New-Item -ItemType directory -Name 'out' | out-null
Start-Sleep 3
clear
}
##Main menu select function##
function menuSelect{
Write-Host '==============Retron 5 ROM Dump=============='
Write-Host '1. Dump Rom - Enter Title Manually'
Write-Host '2. Dump Rom - NoIntro Title Automatic'
Write-Host '3. Quit and Exit'
$selection = Read-Host 'Please make a selection'
switch($selection){
'1'{
Write-Host 'You selected Dump Rom - Enter Title Manually' -Foregroundcolor magenta
Write-Host ''
dumpROM
}
'2'{
Write-Host 'You selected Dump Rom - NoIntro Title Automatic' -Foregroundcolor magenta
write-host ''
dumpROMnoIntro
}
'3'{
Write-Host 'Quitting...'
return
}
default{
Write-Host 'Please select a valid option...' -Foregroundcolor yellow
Write-Host ''
Write-Host ''
menuSelect
}
}
}
##Function to dump ROM with manually entered Title/Name##
function dumpROM{
Write-Host 'Enter title of game you are dumping' -foregroundcolor cyan
##Capture name input from user##
[string]$gameTitle = Read-Host "Enter Title"
##Call ADB.exe to copy dump.* ROM from Retron 5 to out directory##
.\adb.exe pull /mnt/ram/. ./out
##Import dump.* ROM file info to variable##
$dump = Get-ChildItem ./out/dump.*
##File dump.* does not exit throw error!##
if(!($dump)){
Write-Host ''
Write-Host '!!!!!!!!!!!!!!!!!!!!' -Foregroundcolor red -Backgroundcolor black
Write-Host 'ROM dump not found, please verify ADB is installed and can connect to your Retron 5.' -Foregroundcolor red -Backgroundcolor black
}
##File dump.part detected throw error/warning and delete##
elseif($dump.Name -eq 'dump.part'){
Write-Host ''
Write-Host '!WARNING! Partial dump found!' -Foregroundcolor yellow -Backgroundcolor black
Write-Host 'Disable Fast Cartridgle Loading and re-insert game cartridge in your Retron 5.' -Foregroundcolor yellow -Backgroundcolor black
Remove-Item $dump
}
##File dump.* exists so attempt to rename file##
else{
##Create game name based on user input and original file extension##
[string]$extension = $dump.extension
[string]$gameName = $gameTitle + $Extension
##Rename dump.* to manually entered name##
Rename-Item $dump -NewName $gameName
Write-Host "$gameName ROM has been dumped successfully!"
}
##Call exitQuestion function##
exitQuestion
}
##Function to dump ROM with automatic Title/Name based on NoIntro data##
function dumpROMnoIntro{
Write-Host 'Insert cartridge into Retron 5 and press Enter to continue...' -foregroundcolor yellow
pause
Write-Host 'Copying ROM from Retron 5 and Renaming...' -foregroundcolor cyan
##Call ADB.exe to copy dump.* ROM from Retron 5 to out directory##
.\adb.exe pull /mnt/ram/. ./out
##Import dump.* ROM file info to variable##
$dump = Get-ChildItem ./out/dump.*
##File dump.* does not exit throw error!##
if(!($dump)){
Write-Host ''
Write-Host '!!!!!!!!!!!!!!!!!!!!' -Foregroundcolor red -Backgroundcolor black
Write-Host 'ROM dump not found, please verify ADB is installed and can connect to your Retron 5.' -Foregroundcolor red -Backgroundcolor black
}
##File dump.part detected throw error/warning and delete##
elseif($dump.Name -eq 'dump.part'){
Write-Host ''
Write-Host '!WARNING! Partial dump found!' -Foregroundcolor yellow -Backgroundcolor black
Write-Host 'Disable Fast Cartridgle Loading and re-insert game cartridge in your Retron 5.' -Foregroundcolor yellow -Backgroundcolor black
Remove-Item $dump
}
##File dump.* exists so attempt to rename##
else{
##Get hashes for dump.* ROM##
$sha1 = Get-FileHash $dump.FullName -Algorithm SHA1
$md5 = Get-FileHash $dump.FullName -Algorithm MD5
[string]$sha1Hash = $sha1.hash
[string]$md5Hash = $md5.hash
##Compare hashes to CSV for match##
[string]$gameTitle = $csv.Where({($PSItem.sha1 -eq $sha1Hash) -and ($PSItem.md5 -eq $md5Hash)}).Name
##No match Found for dump.NES ROM. Try to strip header and match##
if(!($gameTitle) -and ($dump.Extension -eq '.NES')){
Write-Host ''
Write-Host 'No match was found in NoIntro CSV...' -Foregroundcolor red
Write-Host 'Stripping header and comparing to NoIntro CSV...' -Foregroundcolor yellow
##Create paths to create headerless temp.nes file##
$directory = $dump.DirectoryName
$extension = $dump.Extension
$tempOut = $directory + '\temp' + $extension
##Convert dump.nes to hex, remove first 16bytes and output to temp.nes##
$bytes = [System.IO.File]::ReadAllBytes($dump)
$bytesToTrim = 16
$trimmedBytes = $bytes[$bytesToTrim..($bytes.length - 1)]
[System.IO.File]::WriteAllBytes($tempOut, $trimmedBytes)
##Import headerless temp.nes file info to variable##
$temp = Get-ChildItem ./out/temp.*
##Get hashes for headerless temp.nes##
$tempsha1 = Get-FileHash $temp.FullName -Algorithm SHA1
$tempmd5 = Get-FileHash $temp.FullName -Algorithm MD5
[string]$tempsha1Hash = $tempsha1.hash
[string]$tempmd5Hash = $tempmd5.hash
##Compare hashes of headerless NES rom to CSV for match##
[string]$tempGameTitle = $csv.Where({($PSItem.sha1 -eq $tempsha1Hash) -and ($PSItem.md5 -eq $tempmd5Hash)}).Name
##No match for headerless ROM found so ask if you want manual input##
if(!($tempGameTitle)){
Write-Host ''
Write-Host 'No match was found in NoIntro CSV even without header...' -Foregroundcolor red
Write-Host ''
Write-Host '!WARNING! ROM dump will be deleted if No is selected.' -Foregroundcolor yellow
Write-Host 'Do you want to manually name this ROM?' -Foregroundcolor cyan
Write-Host "Enter Y for Yes / N for No" -foregroundcolor magenta
$answer = Read-Host "Y/N"
##If Yes ask for manual input##
if($answer -eq 'Y'){
Write-Host ''
Write-Host 'Enter title of game you are dumping' -foregroundcolor cyan
##Capture name input from user and add original file extension##
[string]$gameTitle = Read-host "Enter Title"
[string]$extension = $dump.extension
[string]$gameName = $gameTitle + $Extension
##Rename dump.nes to manually entered name##
Rename-Item $dump -NewName $gameName
Write-Host "$gameName ROM has been dumped successfully!"
##Delete temp.nes file##
Remove-Item $temp
}
##If anything other than Yes for manual input##
else{
##Delete both temp.nes and dump.nes##
Remove-Item $dump
Remove-Item $temp
}
}
##Match was found for headerless temp.nes##
else{
Write-Host "$tempGameTitle was matched without header. Temp files will be Deleted." -Foregroundcolor cyan
##Rename dump.nes to name found in CSV that matched headerless temp.nes file##
Rename-Item $dump -NewName $tempGameTitle
##Delete temp.nes file##
Remove-Item $temp
Write-Host "$tempGameTitle ROM has been dumped successfully!" -Foregroundcolor green
}
}
##No match Found for dump.* ROM and not NES file so ask if you want manual input##
elseif(!($gameTitle) -and ($dump.Extension -ne '.NES')){
Write-Host ''
Write-Host 'No match was found in NoIntro CSV...' -Foregroundcolor red -Backgroundcolor black
Write-Host ''
Write-Host '!WARNING! ROM dump will be deleted if No is selected.' -Foregroundcolor yellow
Write-Host 'Do you want to manually name this ROM?' -Foregroundcolor cyan
Write-Host "Enter Y for Yes / N for No" -foregroundcolor magenta
$answer = Read-Host "Y/N"
##If Yes ask for manual input##
if($answer -eq 'Y'){
Write-Host ''
Write-Host 'Enter title of game you are dumping' -foregroundcolor cyan
##Capture name input from user and add original file extension##
[string]$gameTitle = Read-host "Enter Title"
[string]$extension = $dump.extension
[string]$gameName = $gameTitle + $Extension
##Rename ROM to manually entered name##
Rename-Item $dump -NewName $gameName
Write-Host "$gameName ROM has been dumped successfully!"
}
##If anything other than Yes for manual input##
else{
##Delete dump.* ROM##
Remove-Item $dump
}
}
##Match was found for dump.^ ROM in NoIntro CSV##
else{
##Renamp dump.* ROM to matching name from NoIntro CSV##
Rename-Item $dump -NewName $gameTitle
Write-Host "$gameTitle ROM has been dumped successfully!"
}
}
##Call exitQuestion function##
exitQuestion
}
##Do you want to dump another? Function##
function exitQuestion{
Write-Host ''
Write-Host ''
Write-Host "Do you want to dump another?" -foregroundcolor cyan
Write-Host "Enter Y for Yes / N for No" -foregroundcolor magenta
$answer = Read-Host "Y/N"
if($answer -eq 'Y'){
clear
menuSelect
}
elseif($answer -eq 'N'){ break }
else{ exitQuestion }
}
##Import CSV of meged NoIntro dats##
$csv = import-csv "noIntroList.csv"
##Call menuSelect function##
menuSelect