-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMainWindow.cs
443 lines (388 loc) · 17.5 KB
/
MainWindow.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
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
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
using Splat3GearView.Properties;
using Splat3GearView.Resources;
using Splat3GearView.Structures;
using SysBot.Base;
using System.Linq.Expressions;
using System.Net.Sockets;
using System.Text.Json;
using static System.Buffers.Binary.BinaryPrimitives;
namespace Splat3GearView
{
public partial class MainWindow : Form
{
private readonly static SwitchConnectionConfig Config = new() { Protocol = SwitchProtocol.WiFi, IP = Settings.Default.SwitchIP, Port = 6000 };
private readonly static SwitchSocketAsync SwitchConnection = new(Config);
public readonly GearData GearData = new();
private List<Gear> GearList = new();
private int index;
string CachedText = string.Empty;
bool GrindTT;
public MainWindow()
{
string build = string.Empty;
#if DEBUG
var date = File.GetLastWriteTime(System.Reflection.Assembly.GetEntryAssembly()!.Location);
build = $" (dev-{date:yyyyMMdd})";
#endif
var v = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version!;
Text = "Splat3GearView v" + v.Major + "." + v.Minor + "." + v.Build + build;
InitializeComponent();
}
private void MainWindow_Load(object sender, EventArgs e)
{
InputSwitchIP.Text = Settings.Default.SwitchIP;
LabelIndex.Text = string.Empty;
CachedText = Text;
GrindMode.SelectedIndex = 0;
}
private void InputSwitchIP_Changed(object sender, EventArgs e)
{
TextBox textBox = (TextBox)sender;
if (textBox.Text != "192.168.0.0")
{
Settings.Default.SwitchIP = textBox.Text;
Config.IP = textBox.Text;
}
Settings.Default.Save();
}
private async void Connect_ClickAsync(object sender, EventArgs e)
{
try
{
ConnectionStatusText.Text = "Connecting...";
SwitchConnection.Connect();
//var game = SwitchConnection.GetGameInfo("name", CancellationToken.None).Result;
var vers = SwitchConnection.GetGameInfo("version", CancellationToken.None).Result.Trim();
//var id = SwitchConnection.GetTitleID(CancellationToken.None).Result;
var vs = $" - S3 ver {vers}";
Text = CachedText + vs;
index = 0;
uint dlcOffs = 0;
ButtonConnect.Enabled = false;
ButtonDisconnect.Enabled = true;
ConnectionStatusText.Text = "Reading seed block...";
var offs = Offsets.GachaBlock;
var block = await SwitchConnection.ReadBytesAsync(offs, GachaSeed.SIZE, CancellationToken.None);
var seeds = ReadGachaSeeds(block);
if (seeds.Count == 0)
{
dlcOffs = Offsets.DLC_Offs;
block = await SwitchConnection.ReadBytesAsync(offs + dlcOffs, GachaSeed.SIZE, CancellationToken.None);
seeds = ReadGachaSeeds(block);
}
try
{
Gacha0.Text = $"{seeds[0].s0:X08}";
Gacha1.Text = $"{seeds[0].s1:X08}";
Gacha2.Text = $"{seeds[0].s2:X08}";
Gacha3.Text = $"{seeds[0].s3:X08}";
}
catch { };
try
{
Fest0.Text = $"{seeds[1].s0:X08}";
Fest1.Text = $"{seeds[1].s1:X08}";
Fest2.Text = $"{seeds[1].s2:X08}";
Fest3.Text = $"{seeds[1].s3:X08}";
}
catch { };
try
{
Murch0.Text = $"{seeds[2].s0:X08}";
Murch1.Text = $"{seeds[2].s1:X08}";
Murch2.Text = $"{seeds[2].s2:X08}";
Murch3.Text = $"{seeds[2].s3:X08}";
}
catch { };
try
{
Title0.Text = $"{seeds[3].s0:X08}";
Title1.Text = $"{seeds[3].s1:X08}";
Title2.Text = $"{seeds[3].s2:X08}";
Title3.Text = $"{seeds[3].s3:X08}";
}
catch { };
try
{
Banner0.Text = $"{seeds[4].s0:X08}";
Banner1.Text = $"{seeds[4].s1:X08}";
Banner2.Text = $"{seeds[4].s2:X08}";
Banner3.Text = $"{seeds[4].s3:X08}";
}
catch { };
ConnectionStatusText.Text = "Reading gear...";
GearList.Clear();
uint pos = 0x40 + dlcOffs; // First gear is located at offset + 0x40
Gear gear;
int CHUNK_SIZE = 10;
bool IsValid = true;
// Load Headgear
ConnectionStatusText.Text = "Reading headgear...";
do
{
var Data = await SwitchConnection.ReadBytesAsync(Offsets.GearList_Head + pos, Gear.SIZE * CHUNK_SIZE, CancellationToken.None); // Read gear in chunks
for (int i = 0; i < CHUNK_SIZE; i++)
{
gear = new Gear(Data.AsSpan(i * Gear.SIZE, Gear.SIZE).ToArray())
{
GearType = (byte)GearTypes.Headgear
};
if (gear.IsValid)
{
gear.SetInfoFromJSON();
GearList.Add(gear);
}
else
{
// Reached junk data/end of list, break out of both loops
IsValid = false;
break;
}
}
pos += (uint)(Gear.SIZE * CHUNK_SIZE);
} while (IsValid);
// Load Clothes
pos = 0x40 + dlcOffs;
IsValid = true;
ConnectionStatusText.Text = "Reading clothes...";
do
{
var Data = await SwitchConnection.ReadBytesAsync(Offsets.GearList_Clothes + pos, Gear.SIZE * CHUNK_SIZE, CancellationToken.None);
for (int i = 0; i < CHUNK_SIZE; i++)
{
gear = new Gear(Data.AsSpan(i * Gear.SIZE, Gear.SIZE).ToArray())
{
GearType = (byte)GearTypes.Clothes
};
if (gear.IsValid)
{
gear.SetInfoFromJSON();
GearList.Add(gear);
}
else
{
IsValid = false;
break;
}
}
pos += (uint)(Gear.SIZE * CHUNK_SIZE);
} while (IsValid);
// Load Shoes
pos = 0x40 + dlcOffs;
IsValid = true;
ConnectionStatusText.Text = "Reading shoes...";
do
{
var Data = await SwitchConnection.ReadBytesAsync(Offsets.GearList_Shoes + pos, Gear.SIZE * CHUNK_SIZE, CancellationToken.None);
for (int i = 0; i < CHUNK_SIZE; i++)
{
gear = new Gear(Data.AsSpan(i * Gear.SIZE, Gear.SIZE).ToArray())
{
GearType = (byte)GearTypes.Shoes
};
if (gear.IsValid)
{
gear.SetInfoFromJSON();
GearList.Add(gear);
}
else
{
IsValid = false;
break;
}
}
pos += (uint)(Gear.SIZE * CHUNK_SIZE);
} while (IsValid);
LabelLoadedGear.Text = $"Loaded Gear: {GearList.Count}";
LabelLoadedHeadgear.Text = $"Headgear: {GearList.Where(g => g.GearType == (byte)GearTypes.Headgear).Count()}";
LabelLoadedClothes.Text = $"Clothes: {GearList.Where(g => g.GearType == (byte)GearTypes.Clothes).Count()}";
LabelLoadedShoes.Text = $"Shoes: {GearList.Where(g => g.GearType == (byte)GearTypes.Shoes).Count()}";
GearList = GearList.OrderBy(g => g.GearType).ThenBy(g => g.ID).ToList();
if (GearList.Count > 0)
{
DisplayGear(index);
ButtonDumpGear.Enabled = true;
}
else ButtonDumpGear.Enabled = false;
ConnectionStatusText.Text = "Done.";
//Disconnect();
}
catch (SocketException err)
{
// a bit hacky but it works
if (err.Message.Contains("failed to respond") || err.Message.Contains("actively refused"))
{
ConnectionStatusText.Text = "Unable to connect.";
MessageBox.Show(err.Message);
}
else
{
ConnectionStatusText.Text = "Disconnected.";
}
ButtonConnect.Enabled = true;
ButtonDisconnect.Enabled = false;
}
}
private static Dictionary<byte, GachaSeed> ReadGachaSeeds(byte[] data)
{
var ret = new Dictionary<byte, GachaSeed>();
for (uint i = 0; i < GachaSeed.SIZE; i += GachaSeed.STRUCT_SIZE)
{
var chunk = data.AsSpan((int)i, (int)GachaSeed.STRUCT_SIZE);
var key = ReadUInt32LittleEndian(chunk[..8]);
// Init the seed here so it's easier to find the unknown keys
var rawseed = chunk[(byte)GachaSeed.SEED_OFFSET..((int)GachaSeed.SEED_OFFSET + GachaSeed.SEED_SIZE)];
var seed = new GachaSeed(rawseed.ToArray());
switch (key)
{
case GachaSeed.NORMAL_KEY:
ret.Add(0, seed);
break;
case GachaSeed.FEST_KEY:
ret.Add(1, seed);
break;
case GachaSeed.MURCH_KEY:
ret.Add(2, seed);
break;
case GachaSeed.TITLE_KEY:
ret.Add(3, seed);
break;
case GachaSeed.BANNER_KEY:
ret.Add(4, seed);
break;
default:
break;
}
}
return ret;
}
private void Disconnect_Click(object sender, EventArgs e)
{
Disconnect();
ConnectionStatusText.Text = "Disconnected.";
ButtonConnect.Enabled = true;
ButtonDisconnect.Enabled = false;
}
private async void Disconnect()
{
if (SwitchConnection.Connected)
{
await SwitchConnection.SendAsync(SwitchCommand.DetachController(true), CancellationToken.None).ConfigureAwait(false);
SwitchConnection.Disconnect();
}
}
private void DisplayGear(int num)
{
LabelIndex.Text = $"{(index + 1):D2} / {GearList.Count}";
Gear gear = GearList[num];
GearName.Text = gear.Name;
GearBrand.Text = gear.Brand;
GearID.Text = $"{gear.ID:D5}";
GearSeed.Text = $"{gear.Seed:X8}";
GearRarity.Text = $"{gear.Rarity}";
GearSlots.Text = $"{gear.Ability_SubCount}";
string fp = $".\\Resources\\Images\\Gear\\{gear.__RowID}.png";
GearIcon.Image = File.Exists(fp) ? Image.FromFile(fp) : null;
string BasePath = $".\\Resources\\Images\\Skill\\Base.png";
var Base = File.Exists(BasePath) ? Image.FromFile(BasePath) : null;
string Primary = $".\\Resources\\Images\\Skill\\{gear.Ability_Primary}.png";
GearPrimaryAbility.Text = Strings.Abilities[gear.Ability_Primary];
var p = File.Exists(Primary) ? Image.FromFile(Primary) : null;
PrimaryIcon.Image = (Base is not null && p is not null) ? LayerImage(Base, p, 0, 0) : null;
string Sub1 = $".\\Resources\\Images\\Skill\\{gear.Ability_Sub1}.png";
GearSubAbility1.Text = Strings.Abilities[gear.Ability_Sub1];
var s1 = File.Exists(Sub1) ? Image.FromFile(Sub1) : null;
Sub1Icon.Image = (Base is not null && s1 is not null) ? LayerImage(Base, s1, 0, 0) : null;
string Sub2 = $".\\Resources\\Images\\Skill\\{(gear.Rarity >= 1 ? gear.Ability_Sub2 : -1)}.png";
GearSubAbility2.Text = gear.Rarity >= 1 ? Strings.Abilities[gear.Ability_Sub2] : "(None)";
var s2 = File.Exists(Sub2) ? Image.FromFile(Sub2) : null;
Sub2Icon.Image = (Base is not null && s2 is not null) ? LayerImage(Base, s2, 0, 0) : null;
string Sub3 = $".\\Resources\\Images\\Skill\\{(gear.Rarity >= 2 ? gear.Ability_Sub3 : -1)}.png";
GearSubAbility3.Text = gear.Rarity >= 2 ? Strings.Abilities[gear.Ability_Sub3] : "(None)";
var s3 = File.Exists(Sub3) ? Image.FromFile(Sub3) : null;
Sub3Icon.Image = (Base is not null && s3 is not null) ? LayerImage(Base, s3, 0, 0) : null;
}
private void ButtonPrevious_Click(object sender, EventArgs e)
{
if (GearList.Count > 0)
{
index = (index + GearList.Count - 1) % GearList.Count; // Wrap around
DisplayGear(index);
}
}
private void ButtonNext_Click(object sender, EventArgs e)
{
if (GearList.Count > 0)
{
index = (index + GearList.Count + 1) % GearList.Count; // Wrap around
DisplayGear(index);
}
}
public static Bitmap LayerImage(Image baseLayer, Image overLayer, int x, int y)
{
Bitmap img = new(baseLayer);
using Graphics gr = Graphics.FromImage(img);
gr.DrawImage(overLayer, x, y, overLayer.Width, overLayer.Height);
return img;
}
private readonly static Dictionary<string, Dictionary<string, WebsiteFormat>> WebsiteJSON = new();
private void ButtonDumpGear_Click(object sender, EventArgs e)
{
WebsiteJSON["HaveGearHeadMap"] = new();
WebsiteJSON["HaveGearClothesMap"] = new();
WebsiteJSON["HaveGearShoesMap"] = new();
foreach (Gear gear in GearList)
{
string key = gear.GearType switch
{
(byte)GearTypes.Headgear => "HaveGearHeadMap",
(byte)GearTypes.Clothes => "HaveGearClothesMap",
_ => "HaveGearShoesMap",
};
WebsiteJSON[key][$"{gear.ID}"] = new()
{
MainSkill = // Website format is weird
gear.Ability_Primary - 1 >= (byte)Abilities.IntensifyAction
? (gear.Ability_Primary - (byte)Abilities.IntensifyAction) + 99
: gear.Ability_Primary - 1,
RandomContext = gear.Seed,
ExDrinksArray = Array.Empty<int>(),
ExSkillArray = new int[] { gear.Ability_Sub1 - 1, gear.Ability_Sub2 - 1, gear.Ability_Sub3 - 1 }
};
}
string JSONString = JsonSerializer.Serialize(WebsiteJSON);
Clipboard.SetText(JSONString);
MessageBox.Show("Copied JSON to clipboard!\nUpload it at https://leanny.github.io/splat3seedchecker/#/settings");
}
private async void ButtonGrindTableturf_Click(object sender, EventArgs e)
{
GrindTT = true;
if (SwitchConnection.Connected)
{
while (GrindTT)
{
switch (GrindMode.SelectedIndex)
{
case 0:
if (SwitchConnection.Connected) await Click(SwitchButton.DUP, 20, CancellationToken.None);
if (SwitchConnection.Connected) await Click(SwitchButton.A, 20, CancellationToken.None);
if (SwitchConnection.Connected) await Click(SwitchButton.A, 20, CancellationToken.None);
if (SwitchConnection.Connected) await Click(SwitchButton.B, 20, CancellationToken.None);
await Task.Delay(1_000, CancellationToken.None);
break;
}
}
await SwitchConnection.SendAsync(SwitchCommand.DetachController(true), CancellationToken.None).ConfigureAwait(false);
}
}
private static new async Task Click(SwitchButton button, int delay, CancellationToken token)
{
await SwitchConnection.SendAsync(SwitchCommand.Click(button, true), token).ConfigureAwait(false);
await Task.Delay(delay, token).ConfigureAwait(false);
}
private void ButtonStopGrind_Click(object sender, EventArgs e)
{
GrindTT = false;
}
}
}