forked from YuukiPS/Launcher-PC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.cs
2033 lines (1809 loc) · 77.8 KB
/
Main.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
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using Microsoft.Win32;
using Newtonsoft.Json;
using System.Diagnostics;
using System.Net.NetworkInformation;
using System.Reflection;
using YuukiPS_Launcher.Json;
using YuukiPS_Launcher.Json.GameClient;
using YuukiPS_Launcher.Yuuki;
namespace YuukiPS_Launcher
{
public partial class Main : Form
{
// Main Function
private Proxy? proxy;
private Process? progress;
// Server List
Thread? thServerList = null;
List<DataServer> ListServer = new List<DataServer> { new DataServer() };
Json.Config configdata = new Json.Config();
Profile default_profile = new Profile();
// Stats default
public bool notbootyet = true;
public string WatchFile = "";
public string WatchCheat = "melon123";
public string HostName = "YuukiPS"; // host name
public bool IsGameRun = false;
public bool DoneCheck = true;
// Config basic game
public string VersionGame = "";
public int GameChannel = 0;
public string GamePatchMetode = "";
//public int GameType = 1; // 1=GS,2=SR
// Extra
Extra.Discord discord = new Extra.Discord();
// Game
public Game.Genshin.Settings? settings_genshin = null;
//KeyGS key;
Patch? get_version = null;
public Main()
{
InitializeComponent();
}
private void Main_Load(object sender, EventArgs e)
{
Console.WriteLine("Loading....");
// Before starting make sure proxy is turned off
CheckProxy(true);
// Check Update
CheckUpdate();
LoadConfig("Boot"); // if found config
// Load Profile by profile_default
LoadProfile(configdata.profile_default);
// Server List
//GetServerList();
//UpdateServerListTimer();
// Extra
discord.Ready();
notbootyet = false;
}
private void btload_Click(object? sender, EventArgs e)
{
var get_select_profile = GetProfileServer.Text;
LoadProfile(get_select_profile);
}
private void Set_LA_Save_Click(object? sender, EventArgs e)
{
var get_select_profile = GetProfileServer.Text;
SaveProfile(get_select_profile);
}
private void GetProfileServer_SelectedIndexChanged(object? sender, EventArgs e)
{
var get_select_profile = GetProfileServer.Text;
Console.WriteLine("GetProfileServer_SelectedIndexChanged " + get_select_profile);
LoadProfile(get_select_profile);
}
private void GetTypeGame_SelectedIndexChanged(object? sender, EventArgs e)
{
default_profile.game.type = (GameType)GetTypeGame.SelectedItem;
}
public void LoadConfig(string load_by)
{
configdata = Json.Config.LoadConfig();
Console.WriteLine("load config by " + load_by);
// Unsubscribe from SelectedIndexChanged event
GetProfileServer.SelectedIndexChanged -= GetProfileServer_SelectedIndexChanged;
// Profile
GetProfileServer.DisplayMember = "name";
GetProfileServer.DataSource = configdata.profile;
// GameType
GetTypeGame.DataSource = Enum.GetValues(typeof(GameType));
// Find the index of the desired profile
for (int i = 0; i < GetProfileServer.Items.Count; i++)
{
Profile profile = (Profile)GetProfileServer.Items[i];
if (profile.name == configdata.profile_default)
{
Console.WriteLine("Set index " + i + " name profile " + configdata.profile_default);
GetProfileServer.SelectedIndex = i;
break;
}
}
// Subscribe back to SelectedIndexChanged event
GetProfileServer.SelectedIndexChanged += GetProfileServer_SelectedIndexChanged;
}
public void LoadProfile(string load_profile = "")
{
if (string.IsNullOrEmpty(load_profile))
{
Console.WriteLine("No profile");
return;
}
Console.WriteLine("Profile: " + load_profile);
try
{
var tmp_profile = configdata.profile.Find(p => p.name == load_profile);
if (tmp_profile != null)
{
default_profile = tmp_profile;
}
else
{
// use default data
}
Console.WriteLine("Server: " + default_profile.server.url);
}
catch (Exception e)
{
Console.WriteLine("Profile error (" + e.Message + "), use default data");
}
// Data Set
// Game
Set_LA_GameFolder.Text = default_profile.game.path;
GetTypeGame.SelectedIndex = Array.IndexOf(Enum.GetValues(typeof(GameType)), default_profile.game.type);
// Server
CheckProxyEnable.Checked = default_profile.server.proxy.enable;
GetServerHost.Text = default_profile.server.url;
// Extra
Extra_Cheat.Checked = default_profile.game.extra.Akebi;
// Get Data Game
if (!CheckVersionGame(default_profile.game.type))
{
MessageBox.Show("No game folder detected, please manually input game folder then play");
}
}
public void SaveProfile(string name_save = "Default")
{
try
{
var tmp_profile = new Profile();
// Game
tmp_profile.game.path = Set_LA_GameFolder.Text;
tmp_profile.game.type = (GameType)GetTypeGame.SelectedItem;
// Server
tmp_profile.server.url = GetServerHost.Text;
int myInt;
bool isValid = int.TryParse(GetProxyPort.Text, out myInt);
if (isValid)
{
tmp_profile.server.proxy.port = myInt;
}
// Extra
tmp_profile.game.extra.Akebi = Extra_Cheat.Checked;
// Nama Profile
tmp_profile.name = name_save;
try
{
int indexToUpdate = configdata.profile.FindIndex(profile => profile.name == name_save);
if (indexToUpdate != -1)
{
Console.WriteLine("Profile save: " + name_save);
configdata.profile[indexToUpdate] = tmp_profile;
}
else
{
Console.WriteLine("Add new profile: " + name_save);
configdata.profile.Add(tmp_profile);
}
}
catch (Exception ex)
{
Console.WriteLine("Error save config (" + ex.Message + "), so reload it");
configdata = new Json.Config() { profile = new List<Profile>() { tmp_profile } };
}
configdata.profile_default = name_save;
File.WriteAllText(Json.Config.ConfigPath, JsonConvert.SerializeObject(configdata));
Console.WriteLine("Done save config...");
LoadConfig("SaveProfile");
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
}
private void btStartOfficialServer_Click(object sender, EventArgs e)
{
GetServerHost.Text = "official";
CheckProxyEnable.Checked = false;
DoStart();
}
private void btStartYuukiServer_Click(object sender, EventArgs e)
{
GetServerHost.Text = API.WEB_LINK;
CheckProxyEnable.Checked = true;
DoStart();
}
private void btStartNormal_Click(object sender, EventArgs e)
{
DoStart();
}
public void DoStart()
{
// Jika game berjalan...
if (IsGameRun)
{
AllStop();
return;
}
// Setup
bool isCheat = Extra_Cheat.Checked;
bool isProxyNeed = CheckProxyEnable.Checked;
GameType selectedGame = (GameType)GetTypeGame.SelectedItem;
// Get Host
string set_server_host = GetServerHost.Text;
if (string.IsNullOrEmpty(set_server_host))
{
MessageBox.Show("Please select a server first, you can click on one in server list");
return;
}
// Get Proxy
int set_proxy_port = int.Parse(GetProxyPort.Text);
// Get Game
var cst_gamefile = Set_LA_GameFile.Text;
if (String.IsNullOrEmpty(cst_gamefile))
{
MessageBox.Show("No game file config found");
return;
}
if (!File.Exists(cst_gamefile))
{
MessageBox.Show("Please find game install folder!");
return;
}
bool patch = true;
// Check progress
if (!IsGameRun)
{
// if game is not running
if (progress != null)
{
Console.WriteLine("progress tes");
}
// if server is official
if (set_server_host == "official")
{
patch = false;
}
// run patch
var tes = PatchGame(patch, true, GamePatchMetode, GameChannel);
if (!string.IsNullOrEmpty(tes))
{
if (tes.Contains("Key1") || tes.Contains("Key2"))
{
MessageBox.Show("This may happen because you have already patched or you are using an unsupported version game. The solution is you can use Online Method (you can find it in Config Tab) to make sure you have right file.", "Error Patch Offline");
}
else if (tes.Contains("corrupted"))
{
MessageBox.Show("Looks like you're using an unsupported version, try updating game data to latest version", "Game Version not supported (Online Mode)");
Process.Start(new ProcessStartInfo(API.WEB_LINK) { UseShellExecute = true });
}
else
{
MessageBox.Show(tes, "Error Patch");
}
return;
}
}
// For Proxy
if (proxy == null)
{
// skip proxy if official server
if (set_server_host != "official")
{
if (isProxyNeed)
{
proxy = new Proxy(set_proxy_port, set_server_host);
if (!proxy.Start())
{
MessageBox.Show("Maybe port is already use or Windows Firewall does not allow using port " + set_proxy_port + " or Windows Update sometimes takes that range", "Failed Start...");
proxy = null;
return;
}
}
else
{
Console.WriteLine("Proxy is ignored, because you turned it off");
}
}
else
{
Console.WriteLine("Proxy is ignored, because use official server");
}
}
else
{
Console.WriteLine("Proxy is still running...");
}
// For Cheat (tmp)
if (isCheat)
{
Console.WriteLine("Cheat enable");
try
{
var get_file_cheat = API.GetCheat(selectedGame, GameChannel, VersionGame, cst_gamefile);
if (get_file_cheat == null)
{
MessageBox.Show("No update for this version so far or check console");
return;
}
cst_gamefile = get_file_cheat.launcher;
WatchCheat = Path.GetFileNameWithoutExtension(cst_gamefile);
Console.WriteLine($"RUN: Monitor {WatchCheat} at {cst_gamefile}");
}
catch (Exception x)
{
Console.WriteLine(x);
}
}
// For Game
if (progress == null)
{
progress = new Process();
progress.StartInfo = new ProcessStartInfo
{
FileName = cst_gamefile
};
try
{
progress.Start();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error");
AllStop();
}
}
else
{
Console.WriteLine("Progress is still running...");
}
}
public bool CheckVersionGame(GameType game_type)
{
var cst_folder_game = Set_LA_GameFolder.Text;
// If user doesn't have a game config folder, try searching for it automatically
if (String.IsNullOrEmpty(cst_folder_game))
{
var Get_Launcher = GetLauncherPath(game_type);
Console.WriteLine("Folder Launcher: " + Get_Launcher);
if (string.IsNullOrEmpty(Get_Launcher))
{
// If there is no launcher
Console.WriteLine("Please find game install folder!");
return false;
}
else
{
// If there is no launcher, try searching the game folder
cst_folder_game = GetGamePath(Get_Launcher);
}
}
// Check one more time
if (string.IsNullOrEmpty(cst_folder_game))
{
Console.WriteLine("Please find game install folder!");
return false;
}
if (!Directory.Exists(cst_folder_game))
{
Console.WriteLine("Please find game install folder! (2)");
return false;
}
Console.WriteLine("Folder Game: " + cst_folder_game);
string cn = Path.Combine(cst_folder_game, "YuanShen.exe");
string os = Path.Combine(cst_folder_game, "GenshinImpact.exe");
if (game_type == GameType.StarRail)
{
cn = Path.Combine(cst_folder_game, "StarRail.exe"); // todo
os = Path.Combine(cst_folder_game, "StarRail.exe");
}
// Path
string PathfileGame;
string PathMetadata;
string PathUA;
if (game_type == GameType.GenshinImpact)
{
// Pilih Channel
if (File.Exists(cn))
{
// Jika game versi cina
WatchFile = "YuanShen";
GameChannel = 2;
PathfileGame = cn;
PathMetadata = Path.Combine(cst_folder_game, "YuanShen_Data", "Managed", "Metadata");
PathUA = Path.Combine(cst_folder_game, "YuanShen_Data", "Native");
}
else if (File.Exists(os))
{
// jika game versi global
WatchFile = "GenshinImpact";
GameChannel = 1;
PathfileGame = os;
PathMetadata = Path.Combine(cst_folder_game, "GenshinImpact_Data", "Managed", "Metadata");
PathUA = Path.Combine(cst_folder_game, "GenshinImpact_Data", "Native");
}
else
{
// jika game versi tidak di dukung atau tidak ada file
Console.WriteLine("No game files found!!!");
return false;
}
// Settings
try
{
settings_genshin = new Game.Genshin.Settings(GameChannel);
if (settings_genshin != null)
{
Console.WriteLine("Game Text Language: " + settings_genshin.GetGameLanguage());
Console.WriteLine("Game Voice Language: " + settings_genshin.GetVoiceLanguageID());
//Console.WriteLine("JSON: " + settings_genshin.GetDataGeneralString());
}
}
catch (Exception ex)
{
Debug.WriteLine("Error getting game settings: " + ex.ToString());
}
}
else
{
// jika game versi global
WatchFile = "StarRail";
GameChannel = 1;
PathfileGame = os;
PathMetadata = Path.Combine(cst_folder_game, "StarRail_Data", "il2cpp_data", "Metadata");
PathUA = Path.Combine(cst_folder_game); // maybe GameAssembly?
}
// Check MD5 Game
string Game_LOC_Original_MD5 = Tool.CalculateMD5(PathfileGame);
// Check MD5 in Server API
get_version = API.GetMD5Game(Game_LOC_Original_MD5, game_type);
if (get_version == null)
{
//0.0.0
Console.WriteLine("No Support Game with MD5: " + Game_LOC_Original_MD5 + " (Send this log to admin)");
return false;
}
VersionGame = get_version.version;
if (VersionGame == "0.0.0")
{
Console.WriteLine("Version not supported: MD5 " + Game_LOC_Original_MD5);
Set_Metadata_Folder.Text = "";
Set_UA_Folder.Text = "";
Set_LA_GameFile.Text = "";
Get_LA_Version.Text = "Version: Unknown";
Get_LA_CH.Text = "Channel: Unknown";
Get_LA_REL.Text = "Release: Unknown";
Get_LA_Metode.Text = "Metode: Unknown";
Get_LA_MD5.Text = "MD5: Unknown";
return false;
}
var get_channel = get_version.channel;
var get_metode = "None"; // no need patch
if (get_version.patched != null)
{
get_metode = get_version.patched.metode;
}
// Set Folder Patch
Set_Metadata_Folder.Text = PathMetadata;
Set_UA_Folder.Text = PathUA;
Set_LA_GameFile.Text = PathfileGame;
// IF ALL OK
Set_LA_GameFolder.Text = cst_folder_game;
// Set Version
Get_LA_Version.Text = "Version: " + get_version.version;
Get_LA_CH.Text = "Channel: " + get_channel;
Get_LA_REL.Text = "Release: " + get_version.release;
Get_LA_Metode.Text = "Metode: " + get_metode;
var md5_ori = "?";
// Pilih Metode
if (get_version.original != null)
{
if (get_metode == "Metadata")
{
if (get_channel == "CN")
{
md5_ori = get_version.original.md5_check.cn.metadata;
}
if (get_channel == "OS")
{
md5_ori = get_version.original.md5_check.os.metadata;
}
}
else if (get_metode == "UserAssembly")
{
if (get_channel == "CN")
{
md5_ori = get_version.original.md5_check.cn.userassembly;
}
if (get_channel == "OS")
{
md5_ori = get_version.original.md5_check.os.userassembly;
}
}
}
Get_LA_MD5.Text = "MD5: " + md5_ori;
Console.WriteLine("Currently using version game " + VersionGame);
Console.WriteLine("Folder PathMetadata: " + PathMetadata);
Console.WriteLine("File Game: " + PathfileGame);
Console.WriteLine("MD5 Game Currently: " + Game_LOC_Original_MD5);
GamePatchMetode = get_metode;
return true;
}
public string PatchGame(bool patchit = true, bool online = true, string metode = "", int ch = 1)
{
// Check Folder Game
var cst_folder_game = Set_LA_GameFolder.Text;
if (String.IsNullOrEmpty(cst_folder_game))
{
return "No game folder found (1)";
}
if (!Directory.Exists(cst_folder_game))
{
return "No game folder found (2)";
}
if (get_version == null)
{
return "Can't find version, try clicking 'Get Key' in config tab";
}
// Check version
if (VersionGame == "0.0.0")
{
return "This Game Version is not compatible with this method patch";
}
/*
if (get_version.patched == null)
{
return "Can't find config patch cloud";
}
if (get_version.original == null)
{
return "Can't find config original cloud";
}
*/
// API STUFF
var use_metode = "";
if (get_version.patched != null)
{
use_metode = get_version.patched.metode;
}
var use_channel = get_version.channel;
// LOCALHOST
string MD5_UA_API_Original = "";
string MD5_UA_API_Patched = "";
string MD5_Metadata_API_Original = "";
string MD5_Metadata_API_Patched = "";
string MD5_API_Patched = "";
var DL_Patch = "";
if (get_version.patched != null)
{
DL_Patch = get_version.patched.resources + "Patch/";
}
var DL_Original = "";
if (get_version.original != null)
{
DL_Original = get_version.original.resources;
}
var Original_file_MA = "";
var Original_file_UA = "";
var key_to_patch = "";
var key_to_find = "";
if (!String.IsNullOrEmpty(use_metode))
{
// Select Metode (via API Cloud)
if (use_channel == "OS")
{
MD5_UA_API_Original = get_version.original?.md5_check.os.userassembly.ToUpper() ?? string.Empty;
MD5_UA_API_Patched = get_version.patched?.md5_vaild.os.ToUpper() ?? string.Empty;
MD5_Metadata_API_Original = get_version.original?.md5_check.os.metadata ?? string.Empty;
MD5_Metadata_API_Patched = get_version.patched?.md5_vaild.os.ToUpper() ?? string.Empty;
key_to_patch = get_version.patched?.key_patch;
key_to_find = get_version.original?.key_find.os;
Original_file_MA = DL_Original + "GenshinImpact_Data/Managed/Metadata/global-metadata.dat";
Original_file_UA = DL_Original + "GenshinImpact_Data/Native/UserAssembly.dll";
MD5_API_Patched = get_version.patched?.md5_vaild.os.ToUpper() ?? string.Empty;
}
else if (use_channel == "CN")
{
MD5_UA_API_Original = get_version.original?.md5_check.cn.userassembly.ToUpper() ?? string.Empty;
MD5_UA_API_Patched = get_version.patched?.md5_vaild.cn.ToUpper() ?? string.Empty;
MD5_Metadata_API_Original = get_version.original?.md5_check.cn.metadata ?? string.Empty;
MD5_Metadata_API_Patched = get_version.patched?.md5_vaild.cn.ToUpper() ?? string.Empty;
key_to_patch = get_version.patched?.key_patch;
key_to_find = get_version.original?.key_find.cn;
Original_file_MA = DL_Original + "YuanShen_Data/Managed/Metadata/global-metadata.dat";
Original_file_UA = DL_Original + "YuanShen_Data/Native/UserAssembly.dll";
MD5_API_Patched = get_version.patched?.md5_vaild.os.ToUpper() ?? string.Empty;
}
else
{
return "This Game Version is not compatible with Any Method Patch";
}
// >> Make sure MD5 API is not empty <<
if (metode != "RSA")
{
if (String.IsNullOrEmpty(MD5_UA_API_Patched))
{
return "Game version is not supported (3)";
}
if (String.IsNullOrEmpty(MD5_Metadata_API_Patched))
{
return "Game version is not supported (1)";
}
}
if (String.IsNullOrEmpty(MD5_UA_API_Original))
{
return "Game version is not supported (4)";
}
if (String.IsNullOrEmpty(MD5_Metadata_API_Original))
{
return "Game version is not supported (2)";
}
// >> All <<
// Check Folder UA
var cst_folder_UA = Set_UA_Folder.Text;
var cst_folder_Game = Set_LA_GameFolder.Text;
if (String.IsNullOrEmpty(cst_folder_UA))
{
return "No UserAssembly folder found (1)";
}
if (!Directory.Exists(cst_folder_UA))
{
return "No UserAssembly folder found (2)";
}
// Check file UserAssembly
string PathfileUA_Currently = Path.Combine(cst_folder_UA, "UserAssembly.dll");
string PathfileUA_Patched = Path.Combine(cst_folder_UA, "UserAssembly-patched.dll");
string PathfileUA_Original = Path.Combine(cst_folder_UA, "UserAssembly-original.dll");
// Check MD5 local (First time)
string MD5_UA_LOC_Currently = Tool.CalculateMD5(PathfileUA_Currently);
string MD5_UA_LOC_Patched = Tool.CalculateMD5(PathfileUA_Patched);
string MD5_UA_LOC_Original = Tool.CalculateMD5(PathfileUA_Original);
// Check folder Metadata
var cst_folder_metadata = Set_Metadata_Folder.Text;
if (String.IsNullOrEmpty(cst_folder_metadata))
{
return "No MetaData folder found (1)";
}
if (!Directory.Exists(cst_folder_metadata))
{
return "No MetaData folder found (2)";
}
// Check file MetaData
string PathfileMetadata_Currently = Path.Combine(cst_folder_metadata, "global-metadata.dat");
string PathfileMetadata_Patched = Path.Combine(cst_folder_metadata, "global-metadata-patched.dat");
string PathfileMetadata_Original = Path.Combine(cst_folder_metadata, "global-metadata-original.dat");
// Get MD5 local Metadata (First time)
string MD5_Metadata_LOC_Currently = Tool.CalculateMD5(PathfileMetadata_Currently);
string MD5_Metadata_LOC_Original = Tool.CalculateMD5(PathfileMetadata_Original);
string MD5_Metadata_LOC_Patched = Tool.CalculateMD5(PathfileMetadata_Patched);
// Two-method verification even when using offline mode
// >> If UserAssembly is broken <<
var download_ua = false;
if (!File.Exists(PathfileUA_Currently))
{
// Check if found file original
if (File.Exists(PathfileUA_Original))
{
// Check if API Original same with Original LOC
if (MD5_UA_API_Original == MD5_UA_LOC_Original)
{
try
{
File.Copy(PathfileUA_Original, PathfileUA_Currently, true);
MD5_UA_LOC_Currently = Tool.CalculateMD5(PathfileUA_Currently);
Console.WriteLine("We copy PathfileUA_Original to PathfileUA_Currently (UserAssembly) (33)");
}
catch (Exception)
{
// skip
return "Error copy (1)";
}
}
else
{
Console.WriteLine("Download UserAssembly, because PathfileUA_Original with md5 " + MD5_UA_LOC_Original + " does not match " + MD5_UA_API_Original + " (5)");
download_ua = true;
}
}
else
{
Console.WriteLine("Download UserAssembly, because file PathfileUA_Original was not found");
download_ua = true;
}
}
else
{
// If file is found and original file doesn't match currently (Make sure current data is really original before patch)
if (MD5_UA_API_Original != MD5_UA_LOC_Currently)
{
// Check if found file original
if (File.Exists(PathfileUA_Original))
{
// Check if API Original same with Original LOC
if (MD5_UA_API_Original == MD5_UA_LOC_Original)
{
try
{
File.Copy(PathfileUA_Original, PathfileUA_Currently, true);
MD5_UA_LOC_Currently = Tool.CalculateMD5(PathfileUA_Currently);
Console.WriteLine("We copy PathfileUA_Original to PathfileUA_Currently (UserAssembly) (6)");
}
catch (Exception)
{
// skip
return "Error copy (2)";
}
}
else
{
// download if Original file unvaild
Console.WriteLine("Download UserAssembly in 'Currently', because 'PathfileUA_Original' it doesn't match " + MD5_UA_API_Original + " with " + MD5_UA_LOC_Original + " (7)");
download_ua = true;
}
}
else
{
Console.WriteLine("Download UserAssembly in 'Currently' because file PathfileUA_Original not found and it doesn't match " + MD5_UA_API_Original + " with " + MD5_UA_LOC_Currently + " Currently file (8)");
download_ua = true;
}
}
else
{
Console.WriteLine("Skip download UserAssembly, it's up-to-date (4)");
}
}
// if need download ua
if (download_ua)
{
try
{
if (!patchit)
{
return "Unable to download files " + Original_file_UA + " in a closed game state, please try again or download manual and put it in " + PathfileUA_Currently;
}
var CEKDL1 = new Download(Original_file_UA, PathfileUA_Currently);
if (CEKDL1.ShowDialog() != DialogResult.OK)
{
return "Get Original UserAssembly failed";
}
else
{
MD5_UA_LOC_Currently = Tool.CalculateMD5(PathfileUA_Currently);
Console.WriteLine("Currently UserAssembly: " + MD5_UA_LOC_Currently);
}
}
catch (Exception exx)
{
return "Error Get Original UserAssembly: " + exx.ToString();
}
}
else
{
Console.WriteLine("Currently UserAssembly: " + MD5_UA_LOC_Currently);
}
// here current file should match so if original file is not found use current file to copy to original file
if (!File.Exists(PathfileUA_Original))
{
try
{
File.Copy(PathfileUA_Currently, PathfileUA_Original, true);
MD5_UA_LOC_Original = Tool.CalculateMD5(PathfileUA_Original);
Console.WriteLine("We copy file in PathfileUA_Currently to PathfileUA_Original files (22)");
}
catch (Exception)
{
// skip
return "Error copy PathfileUA_Currently to PathfileUA_Original (1)";
}
}
else
{
// if file found (skip)
}
// >> If Metadata is broken <<
var download_metadata = false;
if (!File.Exists(PathfileMetadata_Currently))
{
// Check if found file original
if (File.Exists(PathfileMetadata_Original))
{
// Check if API Original same with Original LOC
if (MD5_Metadata_API_Original == MD5_Metadata_LOC_Original)
{
try
{
File.Copy(PathfileMetadata_Original, PathfileMetadata_Currently, true);
MD5_Metadata_LOC_Currently = Tool.CalculateMD5(PathfileMetadata_Currently);
Console.WriteLine("We copy PathfileMetadata_Original to PathfileMetadata_Currently");
}
catch (Exception)
{
// skip
return "Error copy PathfileMetadata_Original to PathfileMetadata_Currently (111)";
}
}
else
{
// file not vaild so download
download_metadata = true;
Console.WriteLine("Download Metadata in Currently,because file Original with md5 " + MD5_Metadata_API_Original + " doesn't match " + MD5_Metadata_LOC_Original + " (5)");
}
}
else
{
// file not found, so download
download_metadata = true;
Console.WriteLine("Download Metadata, because file PathfileMetadata_Original was not found");
}
}
else
{
// If file is found and original file doesn't match currently (Make sure current data is really original before patch)
if (MD5_Metadata_API_Original != MD5_Metadata_LOC_Currently)
{
// Check if found file original
if (File.Exists(PathfileMetadata_Original))
{
// Check if API Original same with Original LOC
if (MD5_Metadata_API_Original == MD5_Metadata_LOC_Original)
{
try
{
File.Copy(PathfileMetadata_Original, PathfileMetadata_Currently, true);
MD5_Metadata_LOC_Currently = Tool.CalculateMD5(PathfileMetadata_Currently);
Console.WriteLine("We copy file PathfileMetadata_Original to PathfileMetadata_Currently (6)");
}
catch (Exception)
{
// skip
return "Error copy PathfileMetadata_Original to PathfileMetadata_Currently (111)";
}
}
else
{
// file not vaild so download
download_metadata = true;
Console.WriteLine("Download Metadata in Currently, because PathfileMetadata_Original file does not match " + MD5_Metadata_API_Original + " with " + MD5_Metadata_LOC_Original + " (7)");
}
}
else
{
// file not found, so download
download_metadata = true;
Console.WriteLine("Download Metadata in Currently, because file PathfileMetadata_Original was not found (8)");
}
}
else
{
Console.WriteLine("Skip download Metadata, it's up-to-date (4)");
}
}
// if need download
if (download_metadata)
{