-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathForm1.cs
More file actions
228 lines (202 loc) · 6.75 KB
/
Copy pathForm1.cs
File metadata and controls
228 lines (202 loc) · 6.75 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
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 UoKRLoader;
using System.IO;
using System.Net;
using System.Diagnostics;
using System.Threading;
namespace UoSALoader {
public partial class Form1 : Form {
private class ConfigArgs {
public IPAddress ipHost;
public uint uPort;
}
public Form1() {
InitializeComponent();
this.lnkOpen.VisitedLinkColor = this.lnkOpen.ActiveLinkColor;
string exePath = Utility.GetExePath(StaticData.UOEC_REGKEY);
if (exePath == null)
exePath = Utility.GetExePath(StaticData.UOSA_REGKEY);
if (exePath == null)
exePath = Utility.GetExePath(StaticData.UOHS_REGKEY);
if (exePath != null)
this.txtUokrPath.Text = exePath;
if (System.IO.File.Exists("login.cfg")) {
string str2 = null;
using (StreamReader reader = System.IO.File.OpenText("login.cfg")) {
str2 = reader.ReadToEnd();
}
if ((str2 != null) && (str2.Length != 0)) {
string[] strArray = str2.Trim().Split(new char[] { ',' });
this.txtIptopatch.Text = strArray[0].Trim();
this.nudPort.Value = int.Parse(strArray[1].Trim());
//Path
//strArray[2];
}
}
}
private void btnLaunch_Click(object sender, EventArgs e) {
PathOrLaunch(false, ParseConfig());
}
private void btnPatch_Click(object sender, EventArgs e) {
PathOrLaunch(true, ParseConfig());
}
#region Program
private bool ListValidValues(List<theListItem> theList) {
if (theList.Count == 0)
return false;
foreach (theListItem num in theList) {
if (num.Offset <= 0)
return false;
}
return true;
}
private ConfigArgs ParseConfig() {
if ((this.nudPort.Value <= 0M) || (this.nudPort.Value > 65535M)) {
MessageBox.Show("Invalid port: " + this.nudPort.Value.ToString() + " !", Application.ProductName + " Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
return null;
}
IPAddress address = null;
try {
address = IPAddress.Parse(this.txtIptopatch.Text.Trim());
} catch (Exception e) {
MessageBox.Show("Invalid ip: " + this.txtIptopatch.Text + " !" + e.Message.ToString(), Application.ProductName + " Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
return null;
}
if (this.ckbRemind.Checked && (this.txtIptopatch.Text.Length > 0)) {
using (StreamWriter writer = System.IO.File.CreateText("login.cfg")) {
writer.Write(this.txtIptopatch.Text.Trim() + "," + this.nudPort.Value.ToString());
}
}
ConfigArgs args = new ConfigArgs();
args.uPort = (uint)this.nudPort.Value;
args.ipHost = address;
return args;
}
private void PathOrLaunch(bool bPatch, ConfigArgs caTouse) {
if (caTouse != null) {
string Curr_Client = UoKRLoader.StaticData.UOSA_CLIENT;
string Patch_Client = UoKRLoader.StaticData.UOSA_PATCHCLIENT;
//int num3b = 0;
Stream stream2;
//int num = 0;
//int iVersion = 0;
//int num3 = 0;
int num4 = 0;
List<theListItem> theList = new List<theListItem>();
//ENCRYPTION_PATCH_TYPE encType = caTouse.encType;
Process process = null;
FileStream stream = null;
if (!bPatch) {
process = new Process();
#region SA
process.StartInfo.FileName = this.txtUokrPath.Text + Curr_Client;
#endregion
process.StartInfo.WorkingDirectory = this.txtUokrPath.Text;
if (!process.Start()) {
MessageBox.Show("Cannot start the client !", Application.ProductName + " Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
return;
}
} else {
try {
#region SA
System.IO.File.Copy(this.txtUokrPath.Text + Curr_Client, this.txtUokrPath.Text + Patch_Client, true);
#endregion
} catch (Exception) {
#region SA
MessageBox.Show("Cannot create file " + this.txtUokrPath.Text + Patch_Client, Application.ProductName + " Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
#endregion
return;
}
try {
#region SA
stream = System.IO.File.Open(this.txtUokrPath.Text + Patch_Client, FileMode.Open, FileAccess.ReadWrite);
#endregion
} catch (Exception) {
#region SA
MessageBox.Show("Cannot open file " + this.txtUokrPath.Text + Patch_Client, Application.ProductName + " Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
#endregion
return;
}
}
if (bPatch)
stream2 = stream;
else
stream2 = new ProcessStream((IntPtr)process.Id);
for (num4 = 0; num4 < StaticData.UOKR_IPDATA_VERSION; ++num4) {
List<byte[]> staticdata = StaticData.GetIPData(num4);
if (num4 > 5) {
for (int i = 0; i < staticdata.Count; ++i) {
int off = 0;
bool stillsearch = true;
while (stillsearch) {
off = Utility.Search(stream2, staticdata[i], bPatch, off);
if (off <= 0)
stillsearch = false;
else
theList.Add(new theListItem(off, i));
}
}
}else{
for (int i = 0; i < staticdata.Count; ++i)
theList.Add(new theListItem(Utility.Search(stream2, staticdata[i], bPatch), i));
}
if (this.ListValidValues(theList))
break;
theList.Clear();
}
if (this.ListValidValues(theList)) {
if (bPatch) {
stream2.Seek(0L, SeekOrigin.Begin);
}
List<byte[]> list3 = StaticData.GetPatchedIPData(num4, caTouse.ipHost, caTouse.uPort);
for (int i = 0; i < list3.Count; i++) {
for (int j = 0; j < theList.Count; ++j) {
if (theList[j].Parent != i)
continue;
stream2.Seek((long)theList[j].Offset, SeekOrigin.Begin);
stream2.Write(list3[i], 0, list3[i].Length);
}
}
stream2.Close();
if (!bPatch) {
Thread.Sleep(10);
base.Close();
} else {
this.ckbRemind.Checked = false;
MessageBox.Show("Client " + this.txtUokrPath.Text + Patch_Client + " succesfully patched.", "Patch Done", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
}
} else {
stream2.Close();
if (!bPatch) {
process.Kill();
}
MessageBox.Show("Cannot patch IP on the client !", Application.ProductName + " Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
}
}
}
#endregion
private void lnkOpen_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) {
if (this.ofdUOKRClient.ShowDialog(this) == DialogResult.OK) {
this.txtUokrPath.Text = this.ofdUOKRClient.FileName.Substring(0, this.ofdUOKRClient.FileName.LastIndexOf('\\'));
}
}
private void btnAbout_Click(object sender, EventArgs e) {
Form2 form = new Form2();
if (form.ShowDialog(this) == DialogResult.OK) {
form.Close();
} else {
base.Close();
}
}
private void Form1_Load(object sender, EventArgs e) {
this.Text = "UO:SA Loader v" + Application.ProductVersion + " - Kons 2011";
}
}
}