-
Notifications
You must be signed in to change notification settings - Fork 1
/
PatchForm.cs
241 lines (209 loc) · 10.6 KB
/
PatchForm.cs
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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Threading;
using HyoutaTools;
namespace ToVPatcher {
public partial class PatchForm : Form {
List<FileSelectControl> FileSelectControls = new List<FileSelectControl>();
Dictionary<string, string> OutputChecksums = new Dictionary<string,string>();
bool IsInteractionEnabled = true;
public PatchForm() {
this.Icon = Properties.Resources.icon;
InitializeComponent();
}
bool CheckForExecutable( string file ) {
if ( !File.Exists( file ) && !File.Exists( file + ".exe" ) ) {
MessageBox.Show( this,
file + " could not be found at " + Path.GetFullPath( file + Util.exeSuffix ) + "." + Environment.NewLine +
"Please make sure the archive containing ToVPatcher was fully extracted and no files were moved or renamed, then run the patcher again.",
file + " found!", MessageBoxButtons.OK, MessageBoxIcon.Error
);
return false;
}
return true;
}
private void PatchForm_Load( object sender, EventArgs e ) {
TempUtil.RemoveTempFolder();
if ( !Directory.Exists( "new/patches" ) ) {
MessageBox.Show( this,
"Patch folder could not be found at " + Path.GetFullPath( "new/patches" ) + "." + Environment.NewLine +
"Please make sure the archive containing the patch files was fully extracted and no files were moved or renamed, then run the patcher again.",
"Patches not found!", MessageBoxButtons.OK, MessageBoxIcon.Error
);
Close();
return;
}
if ( !CheckForExecutable( "comptoe" ) || ( Util.isRunningOnWindows() && !CheckForExecutable( "xdelta3" ) ) ) {
Close();
return;
}
if ( !LoadOutputChecksums() ) {
Close();
return;
}
string ebootModPath = Path.GetFullPath( "ebootmod/ebootMOD.exe" );
string fSelfPath = Path.GetFullPath( "PS3Py/fself.py" );
string unSelfPath = Path.GetFullPath ("eboot_tools/unself");
string warningMessage = "{0} could not be found at {1}" + "." + Environment.NewLine +
"{0} is required to patch EBOOT.BIN. Please read the readme, find a copy of {0}, and place it at the appropriate location." + Environment.NewLine +
"The patcher will still run, but will not be able to patch EBOOT.BIN until you do so.";
if (!File.Exists (ebootModPath) && Util.isRunningOnWindows()) {
MessageBox.Show (this,
String.Format(warningMessage, "ebootMOD", ebootModPath),
"ebootMOD not found!", MessageBoxButtons.OK, MessageBoxIcon.Warning
);
} else if ( (!File.Exists (fSelfPath) || !File.Exists (unSelfPath) ) && !Util.isRunningOnWindows()) {
MessageBox.Show (this,
String.Format(warningMessage, "fself and unself", fSelfPath + " and " + unSelfPath),
"fself and unself not found!", MessageBoxButtons.OK, MessageBoxIcon.Warning
);
}
fileSelectControlElf.LabelText = "EBOOT.BIN";
fileSelectControlElf.FilePath = Path.Combine( Directory.GetCurrentDirectory(), "EBOOT.BIN" );
fileSelectControlElf.PatchDir = "new/patches";
fileSelectControlElf.PatchFunction = ElfPatcher.PatchElf;
fileSelectControlElf.OutputChecksum = OutputChecksums.GetValueOrDefault( "ToV.elf", null );
fileSelectControlString.LabelText = "string.svo";
fileSelectControlString.FilePath = Path.Combine( Directory.GetCurrentDirectory(), "string.svo" );
fileSelectControlString.PatchDir = "new/patches";
fileSelectControlString.PatchFunction = Patcher.PatchString;
fileSelectControlString.OutputChecksum = OutputChecksums.GetValueOrDefault( "string.svo", null );
fileSelectControlScenario.LabelText = "scenario.dat";
fileSelectControlScenario.FilePath = Path.Combine( Directory.GetCurrentDirectory(), "scenario.dat" );
fileSelectControlScenario.PatchDir = "new/patches/scenario";
fileSelectControlScenario.PatchFunction = Patcher.PatchScenario;
fileSelectControlScenario.OutputChecksum = OutputChecksums.GetValueOrDefault( "scenario.dat", null );
fileSelectControlBtl.LabelText = "btl.svo";
fileSelectControlBtl.FilePath = Path.Combine( Directory.GetCurrentDirectory(), "btl.svo" );
fileSelectControlBtl.PatchDir = "new/patches/btl";
fileSelectControlBtl.PatchFunction = Patcher.PatchBtl;
fileSelectControlBtl.OutputChecksum = OutputChecksums.GetValueOrDefault( "btl.svo", null );
fileSelectControlChat.LabelText = "chat.svo";
fileSelectControlChat.FilePath = Path.Combine( Directory.GetCurrentDirectory(), "chat.svo" );
fileSelectControlChat.PatchDir = "new/patches/chat";
fileSelectControlChat.PatchFunction = Patcher.PatchChat;
fileSelectControlChat.OutputChecksum = OutputChecksums.GetValueOrDefault( "chat.svo", null );
fileSelectControlUI.LabelText = "UI.svo";
fileSelectControlUI.FilePath = Path.Combine( Directory.GetCurrentDirectory(), "UI.svo" );
fileSelectControlUI.PatchDir = "new/patches/UI";
fileSelectControlUI.PatchFunction = Patcher.PatchUI;
fileSelectControlUI.OutputChecksum = OutputChecksums.GetValueOrDefault( "UI.svo", null );
fileSelectControlEffect.LabelText = "effect.svo";
fileSelectControlEffect.FilePath = Path.Combine( Directory.GetCurrentDirectory(), "effect.svo" );
fileSelectControlEffect.PatchDir = "new/patches/effect";
fileSelectControlEffect.PatchFunction = Patcher.PatchEffect;
fileSelectControlEffect.OutputChecksum = OutputChecksums.GetValueOrDefault( "effect.svo", null );
fileSelectControlChara.LabelText = "chara.svo";
fileSelectControlChara.FilePath = Path.Combine( Directory.GetCurrentDirectory(), "chara.svo" );
fileSelectControlChara.PatchDir = "new/patches/chara";
fileSelectControlChara.PatchFunction = Patcher.PatchChara;
fileSelectControlChara.OutputChecksum = OutputChecksums.GetValueOrDefault( "chara.svo", null );
fileSelectControlMenu.LabelText = "menu.svo";
fileSelectControlMenu.FilePath = Path.Combine( Directory.GetCurrentDirectory(), "menu.svo" );
fileSelectControlMenu.PatchDir = "new/patches";
fileSelectControlMenu.PatchFunction = Patcher.PatchMenu;
fileSelectControlMenu.OutputChecksum = OutputChecksums.GetValueOrDefault( "menu.svo", null );
fileSelectControlParam.LabelText = "PARAM.SFO";
fileSelectControlParam.FilePath = Path.Combine( Directory.GetCurrentDirectory(), "PARAM.SFO" );
fileSelectControlParam.PatchDir = null;
fileSelectControlParam.PatchFunction = Patcher.PatchParam;
fileSelectControlParam.OutputChecksum = OutputChecksums.GetValueOrDefault( "PARAM.SFO", null );
fileSelectControlTrophy.LabelText = "TROPHY.TRP";
fileSelectControlTrophy.FilePath = Path.Combine( Directory.GetCurrentDirectory(), "TROPHY.TRP" );
fileSelectControlTrophy.PatchDir = "new/patches";
fileSelectControlTrophy.PatchFunction = PatchTrophyAfterWarning;
fileSelectControlTrophy.OutputChecksum = OutputChecksums.GetValueOrDefault( "TROPHY.TRP", null );
FileSelectControls.Add( fileSelectControlElf );
FileSelectControls.Add( fileSelectControlBtl );
FileSelectControls.Add( fileSelectControlChara );
FileSelectControls.Add( fileSelectControlChat );
FileSelectControls.Add( fileSelectControlEffect );
FileSelectControls.Add( fileSelectControlMenu );
FileSelectControls.Add( fileSelectControlScenario );
FileSelectControls.Add( fileSelectControlString );
FileSelectControls.Add( fileSelectControlUI );
FileSelectControls.Add( fileSelectControlParam );
FileSelectControls.Add( fileSelectControlTrophy );
}
private bool LoadOutputChecksums() {
string path = "new/patches/checksums.md5";
if ( File.Exists( path ) ) {
foreach ( string line in File.ReadAllLines( path ) ) {
string md5 = line.Substring( 0, 32 );
string filename = line.Substring( 34 );
OutputChecksums.Add( filename, md5 );
}
return true;
} else {
MessageBox.Show( this,
"File containing checksums for the patched files could not be found." + Environment.NewLine +
"Please make sure the archive containing the patch files was fully extracted and no files were moved or renamed.",
"Checksums not found!", MessageBoxButtons.OK, MessageBoxIcon.Error
);
return false;
}
}
private delegate void BoolDelegate( bool value );
private void SetInteractionEnabled( bool value ) {
buttonPatch.Enabled = value;
foreach ( var ctrl in FileSelectControls ) {
ctrl.SetInteractionEnabled( value );
}
checkBoxLogging.Enabled = value;
IsInteractionEnabled = value;
}
public static void PatchTrophyAfterWarning( string trophyTrp, string patchDir, string outDir, string outMd5 = null, BackgroundWorker worker = null ) {
if ( File.Exists( trophyTrp ) ) {
if ( worker != null ) { worker.ReportProgress( 0, "Disclaimer has opened up in other window. Read carefully!" ); }
var result = MessageBox.Show(
"TROPHY.TRP is officially signed, so the patched file will not work (and will, in fact, delete all your Tales of Vesperia trophies " +
"if you happen to have some!) unless you can find a way to make the console not confirm that TROPHY.TRP is signed correctly. " +
"This patching process is only provided in case such a thing becomes possible in the future. " +
"It is also not recommend to use a modified TROPHY.TRP file if you ever plan to sync your trophies with the official PSN servers." +
"\n\nAre you absolutely sure you want to patch TROPHY.TRP?", "A Note on TROPHY.TRP", MessageBoxButtons.YesNo, MessageBoxIcon.Warning );
if ( result == DialogResult.Yes ) {
Patcher.PatchTrophy( trophyTrp, patchDir, outDir, outMd5, worker );
} else {
throw new PatchingException( "Cancelled by user." );
}
} else {
throw new PatchingException( "File not found: " + trophyTrp );
}
}
private void buttonPatch_Click( object sender, EventArgs e ) {
Invoke( new BoolDelegate( SetInteractionEnabled ), false );
string outDirPath = @"new/patched";
var outDir = Directory.CreateDirectory( outDirPath );
Thread thread = new Thread( delegate() {
foreach ( var ctrl in FileSelectControls ) {
ctrl.OutDir = outDir.FullName;
ctrl.StartWorker();
while ( ctrl.IsWorkerRunning() ) {
Thread.Sleep( 300 );
}
}
TempUtil.RemoveTempFolder();
Invoke( new BoolDelegate( SetInteractionEnabled ), true );
} );
thread.Start();
}
protected override void OnFormClosing( FormClosingEventArgs e ) {
base.OnFormClosing( e );
if ( e.CloseReason == CloseReason.WindowsShutDown ) return;
if ( !IsInteractionEnabled ) {
MessageBox.Show( this, "Please wait until the patching has completed." );
e.Cancel = true;
}
}
private void checkBoxLogging_CheckedChanged( object sender, EventArgs e ) {
Logger.LoggingEnabled = checkBoxLogging.Checked;
}
}
}