-
Notifications
You must be signed in to change notification settings - Fork 111
/
ConsoleHelper.cs
1658 lines (1572 loc) · 91.5 KB
/
ConsoleHelper.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 System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using System.IO;
using System.Threading;
using IL2CPP;
using System.Diagnostics;
using YgoMaster;
namespace YgoMasterClient
{
class ConsoleHelper
{
public static void Run()
{
new Thread(delegate ()
{
while (true)
{
string consoleInput = Console.ReadLine();
Win32Hooks.Invoke(delegate
{
try
{
HandleCommand(consoleInput);
}
catch (Exception e)
{
Console.WriteLine(e);
}
});
}
}).Start();
}
unsafe static void HandleCommand(string consoleInput)
{
string[] splitted = consoleInput.Split();
switch (splitted[0].ToLower())
{
case "itemid":// Creates json for values in IDS_ITEM (all item ids)
{
bool dumpInvalid = false;
if (splitted.Length > 1)
{
bool.TryParse(splitted[1], out dumpInvalid);
}
Dictionary<YgomGame.Utility.ItemUtil.Category, List<string>> categories = new Dictionary<YgomGame.Utility.ItemUtil.Category, List<string>>();
IL2Class classInfo = classInfo = Assembler.GetAssembly("Assembly-CSharp").GetClass("IDS_ITEM", "YgomGame.TextIDs");
IL2Field[] fields = classInfo.GetFields();
foreach (IL2Field field in fields)
{
string fieldName = field.Name;
int id;
if (fieldName.StartsWith("ID") && int.TryParse(fieldName.Substring(2), out id) &&
(ClientSettings.BrokenItems == null || !ClientSettings.BrokenItems.Contains(id)))
{
string name = YgomGame.Utility.ItemUtil.GetItemName(id);
if (IsWeirdName(name))
{
continue;
}
YgomGame.Utility.ItemUtil.Category cat = YgomGame.Utility.ItemUtil.GetCategoryFromID(id);
if (!categories.ContainsKey(cat))
{
categories[cat] = new List<string>();
}
bool invalid = string.IsNullOrEmpty(name) || name == "deleted" || name == "coming soon" || name.StartsWith("ICON_FRAME");
if (invalid && !dumpInvalid)
{
continue;
}
string prefix = " " + (invalid ? "//" : "");
categories[cat].Add(prefix + id + ",//" + name);
}
}
StringBuilder res = new StringBuilder();
res.AppendLine("{");
foreach (KeyValuePair<YgomGame.Utility.ItemUtil.Category, List<string>> cat in categories.OrderBy(x => x.Key))
{
res.AppendLine(" \"" + cat.Key + "\": [");
res.AppendLine(string.Join(Environment.NewLine, cat.Value));
res.AppendLine(" ],");
}
res.AppendLine("}");
File.WriteAllText("ItemID.json", res.ToString());
Console.WriteLine("Done");
}
break;
case "itemid_enum":// Creates enums for values in IDS_ITEM (all item ids)
{
Dictionary<YgomGame.Utility.ItemUtil.Category, List<string>> categories = new Dictionary<YgomGame.Utility.ItemUtil.Category, List<string>>();
IL2Class classInfo = classInfo = Assembler.GetAssembly("Assembly-CSharp").GetClass("IDS_ITEM", "YgomGame.TextIDs");
IL2Field[] fields = classInfo.GetFields();
foreach (IL2Field field in fields)
{
string fieldName = field.Name;
int id;
if (fieldName.StartsWith("ID") && int.TryParse(fieldName.Substring(2), out id))
{
string name = YgomGame.Utility.ItemUtil.GetItemName(id);
YgomGame.Utility.ItemUtil.Category cat = YgomGame.Utility.ItemUtil.GetCategoryFromID(id);
if (!categories.ContainsKey(cat))
{
categories[cat] = new List<string>();
}
//name = name.Replace("\"", "\\\"");
string prefix = name == "deleted" ? "//" : "";
//categories[cat].Add(prefix + "[Name(\"" + name + "\")]" + fieldName + " = " + id + ",");
categories[cat].Add(prefix + fieldName + " = " + id + ",//" + name);
}
}
StringBuilder res = new StringBuilder();
foreach (KeyValuePair<YgomGame.Utility.ItemUtil.Category, List<string>> cat in categories)
{
res.AppendLine("public enum " + cat.Key + "{");
res.AppendLine(string.Join(Environment.NewLine, cat.Value));
res.AppendLine("}");
}
File.WriteAllText("dump-itemid-enum.txt", res.ToString());
Console.WriteLine("Done");
}
break;
case "packnames":// Gets all the card pack names
{
// TODO: Ensure IDS_CARDPACK is loaded before calling GetText (currently need to be in shop screen)
IL2Class classInfo = Assembler.GetAssembly("Assembly-CSharp").GetClass("IDS_CARDPACK", "YgomGame.TextIDs");
IL2Field[] fields = classInfo.GetFields();
StringBuilder sb = new StringBuilder();
Dictionary<int, string> idVals = new Dictionary<int, string>();
foreach (IL2Field field in fields)
{
string fieldName = field.Name;
if (fieldName.StartsWith("ID") && fieldName.EndsWith("_NAME"))
{
int id = int.Parse(((fieldName.Split('_'))[0]).Substring(2));
idVals[id] = YgomSystem.Utility.TextData.GetText("IDS_CARDPACK." + fieldName);
}
}
foreach (KeyValuePair<int, string> idVal in idVals.OrderBy(x => x.Key))
{
if (!string.IsNullOrEmpty(idVal.Value))
{
sb.AppendLine("ID" + idVal.Key.ToString().PadLeft(4, '0') + "_NAME" + " " + idVal.Value);
}
}
File.WriteAllText("dump-packnames.txt", sb.ToString());
Console.WriteLine("Done");
}
break;
case "packimages":// Attempts to discover all card pack images (which are based on a given card id)
{
// TODO: Improve this (get a card id list as currently this will be very slow)
StringBuilder sb = new StringBuilder();
sb.Append("\"PackShopImages\": [");
sb.Append("\"CardPackTex01_0000\",");
for (int j = 0; j < 30000; j++)
{
for (int i = 0; i < 5; i++)
{
string name = "CardPackTex" + i.ToString().PadLeft(2, '0') + "_" + j;
if (AssetHelper.FileExists("Images/CardPack/<_RESOURCE_TYPE_>/<_CARD_ILLUST_>/" + name))
{
sb.Append("\"" + name + "\",");
}
}
}
sb.Append("]");
File.WriteAllText("dump-packimages.txt", sb.ToString());
Console.WriteLine("Done");
}
break;
case "text":// Gets a IDS_XXXX value based on the input string (e.g. "IDS_CARD.STYLE3")
{
string id = splitted[1];
Console.WriteLine(YgomSystem.Utility.TextData.GetText(id));
}
break;
case "textenum":// Gets all text from the given enum
{
string enumName = splitted[1];
IL2Class classInfo = Assembler.GetAssembly("Assembly-CSharp").GetClass(enumName, "YgomGame.TextIDs");
if (classInfo == null)
{
Console.WriteLine("Invalid enum");
}
else
{
YgomSystem.Utility.TextData.LoadGroup(enumName);
foreach (IL2Field field in classInfo.GetFields())
{
string fieldName = field.Name;
string str = YgomSystem.Utility.TextData.GetText(enumName + "." + fieldName);
if (!string.IsNullOrEmpty(str))
{
Console.WriteLine(fieldName);
Console.WriteLine(str);
}
}
}
}
break;
case "textdump":// Dumps all IDS enums
{
foreach (IL2Class classInfo in Assembler.GetAssembly("Assembly-CSharp").GetClasses())
{
if (classInfo.IsEnum && classInfo.Namespace == "YgomGame.TextIDs" && classInfo.Name.StartsWith("IDS"))
{
StringBuilder sb = new StringBuilder();
YgomSystem.Utility.TextData.LoadGroup(classInfo.Name);
foreach (IL2Field field in classInfo.GetFields())
{
if (field.Name == "value__")
{
continue;
}
string name = classInfo.Name + "." + field.Name;
string str = YgomSystem.Utility.TextData.GetText(name);
if (!string.IsNullOrEmpty(str))
{
sb.AppendLine("[" + name + "]" + Environment.NewLine + str);
}
}
if (sb.Length > 0)
{
string targetPath = Path.Combine(Program.ClientDataDumpDir, "IDS", classInfo.Name + ".txt");
try
{
Directory.CreateDirectory(Path.GetDirectoryName(targetPath));
}
catch { }
string text = sb.ToString();
if (text.EndsWith(Environment.NewLine))
{
text = text.Substring(0, text.Length - Environment.NewLine.Length);
}
File.WriteAllText(targetPath, text);
}
}
}
Console.WriteLine("Done");
}
break;
case "textreload":// Reloads custom text data (IDS)
{
YgomSystem.Utility.TextData.LoadCustomTextData();
Console.WriteLine("Done");
}
break;
case "soloreload":// Reloads custom solo data
{
AssetHelper.LoadSoloData();
Console.WriteLine("Done");
}
break;
case "resultcodes":// Gets all network result codes found in "YgomSystem.Network"
{
StringBuilder sb = new StringBuilder();
foreach (IL2Class classInfo in Assembler.GetAssembly("Assembly-CSharp").GetClasses())
{
if (classInfo.Namespace == "YgomSystem.Network" && classInfo.IsEnum && classInfo.Name.EndsWith("Code"))
{
sb.AppendLine("public enum " + classInfo.Name);
sb.AppendLine("{");
foreach (IL2Field field in classInfo.GetFields())
{
if (field.Name == "value__")
{
continue;
}
sb.AppendLine(" " + field.Name + " = " + field.GetValue().GetValueRef<int>() + ",");
}
sb.AppendLine("}");
sb.AppendLine();
}
}
File.WriteAllText("dump-resultcodes.txt", sb.ToString());
Console.WriteLine("Done");
}
break;
// TODO: Remove "locate"/"locateraw"? It doesn't serve much purpose and "crc" is more accurate
// - One reason to keep locate/locateraw is that it might be useful for non-existing files
// as "crc" might do the auto conversion wrong for non-existing files (SD/HighEnd_HD)
case "locate":// Finds a file on disk from the given input path which is in /LocalData/
case "locateraw":// Don't convert the file path
{
// NOTE: Some images (just cards?) resolve to /masterduel_Data/StreamingAssets/AssetBundle/
string path = consoleInput.Trim().Substring(consoleInput.Trim().IndexOf(' ') + 1);
string convertedPath = splitted[0].ToLower() == "locate" ? AssetHelper.ConvertAssetPath(path) : path;
bool exists = AssetHelper.FileExists(path);
string convertedPathOnDisk = AssetHelper.GetAssetBundleOnDiskConverted(convertedPath);
string autoConvertPathOnDisk = AssetHelper.GetAssetBundleOnDisk(path);
string dir = YgomSystem.LocalFileSystem.StandardStorageIO.LocalDataDir;
bool existsOnDisk = File.Exists(Path.Combine(dir, "0000", convertedPathOnDisk));
bool existsOnDiskNoConvert = File.Exists(Path.Combine(dir, "0000", autoConvertPathOnDisk));
Console.WriteLine("Converted: " + convertedPath);
Console.WriteLine(convertedPathOnDisk + " existsOnDisk: " + existsOnDisk +
" existsOnDisk(auto):" + existsOnDiskNoConvert + " exists:" + exists);
}
break;
case "crc":// Gets the CRC of a file path and shows the file in explorer if it exists
{
string path = consoleInput.Trim().Substring(consoleInput.Trim().IndexOf(' ') + 1);
string pathOnDisk = AssetHelper.GetAssetBundleOnDisk(path);
string dir = YgomSystem.LocalFileSystem.StandardStorageIO.LocalDataDir;
string fullPath = Path.Combine(dir, "0000", pathOnDisk);
Console.WriteLine(pathOnDisk);
if (File.Exists(fullPath))
{
try
{
Process.Start("explorer.exe", "/select, \"" + fullPath + "\"");
}
catch
{
}
}
else
{
Console.WriteLine("File does not exist on disk");
}
}
break;
case "carddata":// dumps card data
{
IL2Assembly assembly = Assembler.GetAssembly("Assembly-CSharp");
IL2Class contentClassInfo = assembly.GetClass("Content", "YgomGame.Card");
IntPtr instance = contentClassInfo.GetField("s_instance").GetValue().ptr;
string intIdPath = contentClassInfo.GetField("IntIdPath").GetValue(instance).GetValueObj<string>();
Console.WriteLine("intIdPath: " + intIdPath);
string path = intIdPath.Replace("/#/", "/");
path = path.Substring(0, path.LastIndexOf('/'));
Console.WriteLine("path: " + path);
string[] files =
{
path + "/#/CARD_Genre",
path + "/#/CARD_IntID",
path + "/#/CARD_Named",
path + "/#/CARD_Prop",
path + "/#/CARD_RubyIndx",
path + "/#/CARD_RubyName",
path + "/en-US/CARD_Desc",
path + "/en-US/CARD_Indx",
path + "/en-US/CARD_Name",
path + "/en-US/DLG_Indx",
path + "/en-US/DLG_Text",
path + "/en-US/WORD_Indx",
path + "/en-US/WORD_Text",
path + "/MD/all_gadget_monsters",
path + "/MD/all_monsters",
path + "/MD/cards_all",
path + "/MD/cards_in_maindeck",
path + "/MD/CARD_Link",
path + "/MD/CARD_Same",
path + "/MD/monsters_in_maindeck"
};
foreach (string file in files)
{
if (file.Contains("CARD_") || file.Contains("DLG_") || file.Contains("WORD_"))
{
byte[] buffer = AssetHelper.GetBytesDecryptionData(file);
if (buffer != null && buffer.Length > 0)
{
string fullPath = Path.Combine(Program.ClientDataDumpDir, file + ".bytes");
try
{
Directory.CreateDirectory(Path.GetDirectoryName(fullPath));
}
catch { }
try
{
File.WriteAllBytes(fullPath, buffer);
}
catch { }
}
}
}
Console.WriteLine("Done");
}
break;
case "updatediff":// Dumps referenced enums / functions (use this to diff and update enums / funcs)
{
IL2Assembly assembly = Assembler.GetAssembly("Assembly-CSharp");
IL2Class engineClass = assembly.GetClass("Engine", "YgomGame.Duel");
IL2Class contentClass = assembly.GetClass("Content", "YgomGame.Card");
Dictionary<string, IL2Class> allEnums = new Dictionary<string, IL2Class>();
allEnums["Card.cs"] = null;
allEnums["CardFrame"] = contentClass.GetNestedType("Frame");
allEnums["CardKind"] = contentClass.GetNestedType("Kind");
allEnums["CardIcon"] = contentClass.GetNestedType("Icon");
allEnums["Misc.cs"] = null;
allEnums["TopicsBannerPatern"] = assembly.GetClass("TopicsBannerResourceBinder", "YgomGame.Menu.Common").GetNestedType("BannerPatern");
allEnums["CardRarity"] = contentClass.GetNestedType("Rarity");
allEnums["CardStyleRarity"] = assembly.GetClass("SearchFilter", "YgomGame.Deck").GetNestedType("Setting").GetNestedType("STYLE");
allEnums["StandardRank"] = assembly.GetClass("ColosseumUtil", "YgomGame.Colosseum").GetNestedType("StandardRank");
allEnums["PlayMode"] = assembly.GetClass("ColosseumUtil", "YgomGame.Colosseum").GetNestedType("PlayMode");
allEnums["ServerStatus"] = assembly.GetClass("ServerStatus", "YgomSystem.Network");
allEnums["GameMode"] = assembly.GetClass("Util", "YgomGame.Duel").GetNestedType("GameMode");
allEnums["PlatformID"] = assembly.GetClass("Util", "YgomGame.Duel").GetNestedType("PlatformID");
allEnums["ChapterStatus"] = assembly.GetClass("SoloModeUtil", "YgomGame.Solo").GetNestedType("ChapterStatus");
allEnums["ChapterUnlockType"] = assembly.GetClass("SoloModeUtil", "YgomGame.Solo").GetNestedType("UnlockType");
allEnums["SoloDeckType"] = assembly.GetClass("SoloModeUtil", "YgomGame.Solo").GetNestedType("DeckType");
allEnums["RoomEntryViewController.Mode"] = assembly.GetClass("RoomEntryViewController", "YgomGame.Room").GetNestedType("Mode");
allEnums["HowToObtainCard"] = null;
allEnums["DuelResultScore"] = null;
//allEnums["DuelRoomTableState"] = null;// TODO: Generate
allEnums["DuelClientStep"] = assembly.GetClass("DuelClient", "YgomGame.Duel").GetNestedType("Step");
allEnums["DuelReplayCardVisibility"] = assembly.GetClass("Util", "YgomGame.Duel").GetNestedType("PublicLevel");
allEnums["Category"] = assembly.GetClass("ItemUtil", "YgomGame.Utility").GetNestedType("Category");
allEnums["Duel.cs"] = null;
allEnums["DuelResultType"] = engineClass.GetNestedType("ResultType");
allEnums["DuelCpuParam"] = engineClass.GetNestedType("CpuParam");
allEnums["DuelType"] = engineClass.GetNestedType("DuelType");
allEnums["DuelAffectType"] = engineClass.GetNestedType("AffectType");
allEnums["DuelBtlPropFlag"] = engineClass.GetNestedType("BtlPropFlag");
allEnums["DuelCardLink"] = engineClass.GetNestedType("CardLink");
allEnums["DuelCardLinkBit"] = engineClass.GetNestedType("CardLinkBit");
allEnums["DuelCardMoveType"] = engineClass.GetNestedType("CardMoveType");
allEnums["DuelCommandBit"] = engineClass.GetNestedType("CommandBit");
allEnums["DuelCommandType"] = engineClass.GetNestedType("CommandType");
allEnums["DuelCounterType"] = engineClass.GetNestedType("CounterType");
allEnums["DuelCutinActivateType"] = engineClass.GetNestedType("CutinActivateType");
allEnums["DuelCutinSummonType"] = engineClass.GetNestedType("CutinSummonType");
allEnums["DuelDamageType"] = engineClass.GetNestedType("DamageType");
allEnums["DuelDialogEffectType"] = engineClass.GetNestedType("DialogEffectType");
allEnums["DuelDialogInfo"] = engineClass.GetNestedType("DialogInfo");
allEnums["DuelDialogMixTextType"] = engineClass.GetNestedType("DialogMixTextType");
allEnums["DuelDialogOkType"] = engineClass.GetNestedType("DialogOkType");
allEnums["DuelDialogRitualType"] = engineClass.GetNestedType("DialogRitualType");
allEnums["DuelDialogType"] = engineClass.GetNestedType("DialogType");
allEnums["DuelDmgStepType"] = engineClass.GetNestedType("DmgStepType");
allEnums["DuelFieldAnimeType"] = engineClass.GetNestedType("FieldAnimeType");
allEnums["DuelFinishType"] = engineClass.GetNestedType("FinishType");
allEnums["DuelLimitedType"] = engineClass.GetNestedType("LimitedType");
allEnums["DuelListAttribute"] = engineClass.GetNestedType("ListAttribute");
allEnums["DuelListType"] = engineClass.GetNestedType("ListType");
allEnums["DuelMenuActType"] = engineClass.GetNestedType("MenuActType");
allEnums["DuelMenuParamType"] = engineClass.GetNestedType("MenuParamType");
allEnums["DuelPhase"] = engineClass.GetNestedType("Phase");
allEnums["DuelPlayerType"] = engineClass.GetNestedType("PlayerType");
allEnums["DuelPvpCommand"] = assembly.GetClass("PvP", "YgomSystem.Network").GetNestedType("Command");
allEnums["DuelPvpCommandType"] = engineClass.GetNestedType("PvpCommandType");
allEnums["DuelPvpFieldType"] = engineClass.GetNestedType("PvpFieldType");
allEnums["DuelRunCommandType"] = engineClass.GetNestedType("RunCommandType");
allEnums["DuelShowParam"] = engineClass.GetNestedType("ShowParam");
allEnums["DuelSpSummonType"] = engineClass.GetNestedType("SpSummonType");
allEnums["DuelStepType"] = engineClass.GetNestedType("StepType");
allEnums["DuelTagType"] = engineClass.GetNestedType("TagType");
allEnums["DuelToEngineActType"] = engineClass.GetNestedType("ToEngineActType");
allEnums["DuelViewType"] = engineClass.GetNestedType("ViewType");
using (TextWriter tw = File.CreateText("updatediff.cs"))
{
tw.WriteLine("// Client version " + assembly.GetClass("Version", "YgomSystem.Utility").GetProperty("AppVersion").GetGetMethod().Invoke().GetValueObj<string>());
tw.WriteLine("// This file is generated using the 'updatediff' command in YgoMasterClient. This information is used to determine changes between client versions which impact YgoMaster.");
tw.WriteLine("// Run the command, diff against the old file, and use the changes to update code.");
tw.WriteLine();
foreach (KeyValuePair<string, IL2Class> enumClass in allEnums)
{
if (enumClass.Value == null)
{
if (enumClass.Key.EndsWith(".cs"))
{
tw.WriteLine("//==================================");
tw.WriteLine("// " + enumClass.Key);
tw.WriteLine("//==================================");
}
else
{
switch (enumClass.Key)
{
case "HowToObtainCard":
YgomSystem.Utility.TextData.LoadGroup("IDS_DECKEDIT");
IL2Class idsDeckEditClass = assembly.GetClass("IDS_DECKEDIT", "YgomGame.TextIDs");
tw.WriteLine("/// <summary>");
tw.WriteLine("/// IDS_DECKEDIT.HOWTOGET_CATEGORY (off by 1?)");
tw.WriteLine("/// </summary>");
tw.WriteLine("enum HowToObtainCard");
tw.WriteLine("{");
tw.WriteLine(" None,");
foreach (IL2Field field in idsDeckEditClass.GetFields())
{
if (field.Name.StartsWith("HOWTOGET_CATEGORY"))
{
string str = YgomSystem.Utility.TextData.GetText(idsDeckEditClass.Name + "." + field.Name);
str = FixWeirdNameForEnum(str);
str = str.Replace(" ", string.Empty);
if (!string.IsNullOrEmpty(str))
{
tw.WriteLine(" " + str + ",// " + field.Name);
}
}
}
tw.WriteLine("}");
break;
case "DuelResultScore":
YgomSystem.Utility.TextData.LoadGroup("IDS_SCORE");
IL2Class idsScoreClass = assembly.GetClass("IDS_SCORE", "YgomGame.TextIDs");
tw.WriteLine("/// <summary>");
tw.WriteLine("/// IDS_SCORE (IDS_SCORE.DETAIL_XXX)");
tw.WriteLine("/// </summary>");
tw.WriteLine("enum DuelResultScore");
tw.WriteLine("{");
tw.WriteLine(" None,");
foreach (IL2Field field in idsScoreClass.GetFields())
{
if (field.Name.StartsWith("DETAIL_"))
{
string str = YgomSystem.Utility.TextData.GetText(idsScoreClass.Name + "." + field.Name);
str = FixWeirdNameForEnum(str);
str = str.Replace(" ", string.Empty);
str = str.Replace("!", string.Empty);
tw.WriteLine(" " + str + ",");
}
}
tw.WriteLine("}");
break;
default:
Console.WriteLine(enumClass.Key + " is null");
break;
}
}
continue;
}
tw.WriteLine("/// <summary>");
tw.WriteLine("/// " + enumClass.Value.FullNameEx);
tw.WriteLine("/// </summary>");
tw.WriteLine("enum " + enumClass.Key);
tw.WriteLine("{");
int nextValue = 0;
foreach (IL2Field field in enumClass.Value.GetFields())
{
if (field.Name == "value__")
{
continue;
}
int value = field.GetValue().GetValueRef<int>();
tw.WriteLine(" " + field.Name + (nextValue == value ? "," : " = " + value + ","));
nextValue = value + 1;
}
tw.WriteLine("}");
}
tw.WriteLine("//==================================");
tw.WriteLine("// ResultCodes.cs");
tw.WriteLine("//==================================");
foreach (IL2Class enumClass in assembly.GetClasses().OrderBy(x => x.Name))
{
if (enumClass.Namespace == "YgomSystem.Network" && enumClass.IsEnum)
{
tw.WriteLine("enum " + enumClass.Name);
tw.WriteLine("{");
int nextValue = 0;
foreach (IL2Field field in enumClass.GetFields())
{
if (field.Name == "value__")
{
continue;
}
int value = field.GetValue().GetValueRef<int>();
tw.WriteLine(" " + field.Name + (nextValue == value ? "," : " = " + value + ","));
nextValue = value + 1;
}
tw.WriteLine("}");
}
}
tw.WriteLine("//==================================");
tw.WriteLine("// Network API");
tw.WriteLine("//==================================");
IL2Class apiClass = assembly.GetClass("API", "YgomSystem.Network");
foreach (IL2Method method in apiClass.GetMethods())
{
tw.WriteLine("//" + method.GetSignature());
}
tw.WriteLine("//==================================");
tw.WriteLine("// duel.dll functions (Engine)");
tw.WriteLine("//==================================");
foreach (IL2Method method in engineClass.GetMethods().OrderBy(x => x.Name))
{
if (method.Name.StartsWith("DLL_"))
{
tw.WriteLine("//" + method.GetSignature());
}
}
tw.WriteLine("//==================================");
tw.WriteLine("// duel.dll functions (Content)");
tw.WriteLine("//==================================");
foreach (IL2Method method in contentClass.GetMethods().OrderBy(x => x.Name))
{
if (method.Name.StartsWith("DLL_"))
{
tw.WriteLine("//" + method.GetSignature());
}
}
}
Console.WriteLine("Done");
}
break;
case "updatejson":// Update the json data store for data that is sent server->client (useful for testing)
YgomSystem.Utility.ClientWork.UpdateJson(splitted[1], splitted[2]);
Console.WriteLine("Done");
break;
case "updatejsonraw":// Update the json data store for data that is sent server->client (useful for testing)
YgomSystem.Utility.ClientWork.UpdateJson(splitted[1]);
Console.WriteLine("Done");
break;
case "cardswithart":// List all cards with art (requires setup of YgoMaster/Data/CardData/)
{
HashSet<int> missingCardsWithArt = new HashSet<int>();
IntPtr cardRarePtr = YgomSystem.Utility.ClientWork.GetByJsonPath("$.Master.CardRare");
if (cardRarePtr != IntPtr.Zero)
{
IL2Dictionary<string, object> cardRare = new IL2Dictionary<string, object>(cardRarePtr);
Dictionary<int, YdkHelper.GameCardInfo> cards = YdkHelper.LoadCardDataFromGame(Program.DataDir);
foreach (KeyValuePair<int, YdkHelper.GameCardInfo> card in cards)
{
if (!cardRare.ContainsKey(card.Key.ToString()) && AssetHelper.FileExists("Card/Images/Illust/tcg/" + card.Key) && card.Value.Frame != YgoMaster.CardFrame.Token)
{
missingCardsWithArt.Add(card.Key);
}
}
}
Console.WriteLine("Missing cards with art: " + string.Join(", ", missingCardsWithArt));
}
break;
case "vcargs":// Get the args for the top view controller
{
IntPtr manager = YgomGame.Menu.ContentViewControllerManager.GetManager();
if (manager != IntPtr.Zero)
{
IntPtr topViewController = YgomSystem.UI.ViewControllerManager.GetStackTopViewController(manager);
if (topViewController != IntPtr.Zero)
{
IL2Assembly assembly = Assembler.GetAssembly("Assembly-CSharp");
IL2Class classInfo = assembly.GetClass("ViewController", "YgomSystem.UI");
IL2Object instance = classInfo.GetField("args").GetValue(topViewController);
string className = "UNKNOWN";
IntPtr viewControllerClass = Import.Object.il2cpp_object_get_class(topViewController);
if (viewControllerClass != IntPtr.Zero)
{
className = Marshal.PtrToStringAnsi(Import.Class.il2cpp_class_get_name(viewControllerClass));
}
if (instance != null)
{
Console.WriteLine(className + " args: " + YgomMiniJSON.Json.Serialize(instance.ptr));
}
else
{
Console.WriteLine(className + " args: (null)");
}
}
}
}
break;
case "pvpops":// Generates enum for YgoMaster.PvpOperation
{
using (TextWriter tw = File.CreateText(Path.Combine(Program.CurrentDir, "PvpOps.txt")))
{
IL2Assembly assembly = Assembler.GetAssembly("Assembly-CSharp");
IL2Class engineClass = assembly.GetClass("Engine", "YgomGame.Duel");
foreach (IL2Method method in engineClass.GetMethods().OrderBy(x => x.Name))
{
if (method.Name.StartsWith("DLL_"))
{
tw.WriteLine(method.Name + ",");
}
}
}
Console.WriteLine("Done");
}
break;
case "unityplayerupdate":// Updates UnityPlayer.dll function addresses based on the provided PDB
UnityPlayerPdb.Update();
break;
case "bgreload":
CustomBackground.ReloadBg();
break;
case "solo_clear":// Clears all of solo content (used for updating secret packs using new accounts)
{
Dictionary<string, object> solo = YgomSystem.Utility.ClientWork.GetDict("$.Master.Solo");
if (solo == null || solo.Count == 0)
{
Console.WriteLine("No data");
return;
}
IL2Assembly assembly = Assembler.GetAssembly("Assembly-CSharp");
IL2Class apiClass = assembly.GetClass("API", "YgomSystem.Network");
IL2Class handleClass = assembly.GetClass("Handle", "YgomSystem.Network");
IL2Method isCompleted = handleClass.GetMethod("IsCompleted");
IL2Method Solo_info = apiClass.GetMethod("Solo_info");
IL2Method Solo_gate_entry = apiClass.GetMethod("Solo_gate_entry");
IL2Method Solo_detail = apiClass.GetMethod("Solo_detail");
IL2Method Solo_set_use_deck_type = apiClass.GetMethod("Solo_set_use_deck_type");
IL2Method Solo_start = apiClass.GetMethod("Solo_start");
IL2Method Duel_begin = apiClass.GetMethod("Duel_begin");
IL2Method Duel_end = apiClass.GetMethod("Duel_end");
HashSet<int> chaptersList = new HashSet<int>();
HashSet<int> lockedChapters = new HashSet<int>();
Dictionary<string, object> allChapterData = Utils.GetDictionary(solo, "chapter");
if (allChapterData == null)
{
Console.WriteLine("Failed to find chapter data");
return;
}
Dictionary<int, Dictionary<string, object>> allChapters = new Dictionary<int, Dictionary<string, object>>();
Dictionary<int, List<int>> allGatesChapterIds = new Dictionary<int, List<int>>();
foreach (KeyValuePair<string, object> gateChapterData in allChapterData)
{
Dictionary<string, object> chapters = gateChapterData.Value as Dictionary<string, object>;
int gateId;
if (!int.TryParse(gateChapterData.Key, out gateId) || chapters == null)
{
continue;
}
List<int> chapterIds = new List<int>();
foreach (KeyValuePair<string, object> chapter in chapters)
{
Dictionary<string, object> chapterData = chapter.Value as Dictionary<string, object>;
int chapterId;
if (!int.TryParse(chapter.Key, out chapterId) || chapterData == null)
{
continue;
}
allChapters[chapterId] = chapterData;
chapterIds.Add(chapterId);
}
allGatesChapterIds[gateId] = chapterIds;
}
List<int> seenGateIds = new List<int>();
List<int> gatesToProcess = new List<int>();
Dictionary<int, Dictionary<string, object>> allGates = new Dictionary<int, Dictionary<string, object>>();
Dictionary<string, object> allGateData = Utils.GetDictionary(solo, "gate");
if (allGateData == null)
{
Console.WriteLine("Failed to find gate data");
return;
}
foreach (KeyValuePair<string, object> gate in allGateData)
{
Dictionary<string, object> gateData = gate.Value as Dictionary<string, object>;
int gateId;
if (!int.TryParse(gate.Key, out gateId) || gateData == null)
{
continue;
}
allGates[gateId] = gateData;
int viewGate;
int unlockId;
if (Utils.TryGetValue(gateData, "view_gate", out viewGate) && viewGate == 0 &&
Utils.TryGetValue(gateData, "unlock_id", out unlockId) && unlockId == 0)
{
seenGateIds.Add(gateId);
gatesToProcess.Add(gateId);
}
}
while (gatesToProcess.Count > 0)
{
List<int> gateIds = new List<int>(gatesToProcess);
gatesToProcess.Clear();
foreach (int gateId in gateIds)
{
List<int> seenChapterIds = new List<int>();
List<int> chaptersToProcess = new List<int>();
List<int> gateChapterIds;
if (allGatesChapterIds.TryGetValue(gateId, out gateChapterIds))
{
foreach (int chapterId in gateChapterIds)
{
Dictionary<string, object> chapterData;
if (allChapters.TryGetValue(chapterId, out chapterData))
{
int parentChapterId;
if (Utils.TryGetValue(chapterData, "parent_chapter", out parentChapterId) && parentChapterId == 0)
{
seenChapterIds.Add(chapterId);
chaptersToProcess.Add(chapterId);
}
}
}
}
while (chaptersToProcess.Count > 0)
{
List<int> chapterIds = new List<int>(chaptersToProcess);
chaptersToProcess.Clear();
foreach (int chapterId in chapterIds)
{
if (!lockedChapters.Contains(chapterId))
{
chaptersList.Add(chapterId);
}
foreach (int childChapterId in gateChapterIds)
{
Dictionary<string, object> childChapterData;
if (allChapters.TryGetValue(childChapterId, out childChapterData))
{
int parentChapterId = Utils.GetValue<int>(childChapterData, "parent_chapter");
if (parentChapterId == chapterId && !seenChapterIds.Contains(childChapterId))
{
seenChapterIds.Add(childChapterId);
chaptersToProcess.Add(childChapterId);
int unlockId = Utils.GetValue<int>(childChapterData, "unlock_id");
if (unlockId != 0 || lockedChapters.Contains(parentChapterId))
{
// TODO: Determine unlock requirements and add the locked chapters in the correct order
lockedChapters.Add(childChapterId);
}
}
}
}
}
}
}
for (int i = 0; i < 2; i++)
{
Dictionary<string, object> allUnlockData = Utils.GetDictionary(solo, "unlock");
if (allUnlockData == null)
{
Console.WriteLine("Failed to get unlock data");
return;
}
foreach (KeyValuePair<string, object> unlock in allUnlockData)
{
Dictionary<string, object> unlockData = unlock.Value as Dictionary<string, object>;
int unlockId;
if (!int.TryParse(unlock.Key, out unlockId) || unlockData == null)
{
continue;
}
int numConditionsMet = 0;
foreach (KeyValuePair<string, object> unlockRequirement in unlockData)
{
List<int> chapterIds = Utils.GetIntList(unlockData, unlockRequirement.Key);
ChapterUnlockType unlockType;
if (Enum.TryParse(unlockRequirement.Key, out unlockType))
{
switch (unlockType)
{
case ChapterUnlockType.CHAPTER_AND:
if (chapterIds.All(x => chaptersList.Contains(x)))
{
numConditionsMet++;
}
break;
case ChapterUnlockType.CHAPTER_OR:
if (chapterIds.Any(x => chaptersList.Contains(x)))
{
numConditionsMet++;
}
break;
}
}
}
if (numConditionsMet == unlockData.Count)
{
foreach (KeyValuePair<int, Dictionary<string, object>> gate in allGates)
{
int gateUnlockId = Utils.GetValue<int>(gate.Value, "unlock_id");
if (gateUnlockId == unlockId && !seenGateIds.Contains(gate.Key))
{
seenGateIds.Add(gate.Key);
gatesToProcess.Add(gate.Key);
}
}
}
}
if (i == 0)
{
if (gatesToProcess.Count > 0)
{
break;
}
else
{
foreach (int chapterId in lockedChapters)
{
chaptersList.Add(chapterId);
}
}
}
}
}
Console.WriteLine("Chapters: " + chaptersList.Count + " / " + allChapters.Count + " (missing:" + string.Join(",", allChapters.Keys.Except(chaptersList).ToList()) + ")");
Console.WriteLine("Gates: " + seenGateIds.Count + " / " + allGates.Count + " (missing:" + string.Join(",", allGates.Keys.Except(seenGateIds).ToList()) + ")");
new Thread(delegate ()
{
int lastGateId = 0;
foreach (int chapterId in chaptersList)
{
Dictionary<string, object> chapterData;
if (!allChapters.TryGetValue(chapterId, out chapterData))
{
continue;
}
int gateId = chapterId / 10000;
if (gateId != lastGateId)
{
lastGateId = gateId;
MakeNetworkRequest(isCompleted, () =>
{
int gateIdLoc = gateId;
return Solo_gate_entry.Invoke(new IntPtr[] { new IntPtr(&gateIdLoc) }).ptr;
});
}
Console.WriteLine("Doing chapter " + chapterId + " for gate " + gateId);
Dictionary<string, object> gateData = Utils.GetDictionary(allGateData, gateId.ToString());
bool isGoal = Utils.GetValue<int>(gateData, "clear_chapter") == chapterId;
bool isScenario = !string.IsNullOrWhiteSpace(Utils.GetValue<string>(chapterData, "begin_sn"));
bool isLock = Utils.GetValue<int>(chapterData, "unlock_id") != 0;
if (isScenario || isLock || isGoal)
{
MakeNetworkRequest(isCompleted, () =>
{
int chapterIdLoc = chapterId;
return Solo_start.Invoke(new IntPtr[] { new IntPtr(&chapterIdLoc) }).ptr;
});
}
else
{
int myDeckSetId = Utils.GetValue<int>(chapterData, "mydeck_set_id");
int loanerDeckSetId = Utils.GetValue<int>(chapterData, "set_id");
for (int i = 0; i < 2; i++)
{
if ((SoloDeckType)i == SoloDeckType.POSSESSION && myDeckSetId == 0)
{
continue;
}
if ((SoloDeckType)i == SoloDeckType.STORY && loanerDeckSetId == 0)
{
continue;
}
MakeNetworkRequest(isCompleted, () =>
{
int chapterIdLoc = chapterId;
int deckType = i;
return Solo_set_use_deck_type.Invoke(new IntPtr[] { new IntPtr(&chapterIdLoc), new IntPtr(&deckType) }).ptr;
});
MakeNetworkRequest(isCompleted, () =>
{
int chapterIdLoc = chapterId;
return Solo_start.Invoke(new IntPtr[] { new IntPtr(&chapterIdLoc) }).ptr;
});
MakeNetworkRequest(isCompleted, () =>
{
Dictionary<string, object> rule = new Dictionary<string, object>()
{
{ "GameMode", 9 },
{ "chapter", chapterId },
{ "FirstPlayer", 1 }
};
return Duel_begin.Invoke(new IntPtr[] { YgomMiniJSON.Json.Deserialize(MiniJSON.Json.Serialize(rule)) }).ptr;
});
MakeNetworkRequest(isCompleted, () =>
{
Dictionary<string, object> param = new Dictionary<string, object>()
{
{ "res", (int)DuelResultType.Win },
{ "finish", (int)DuelFinishType.Normal }
};
return Duel_end.Invoke(new IntPtr[] { YgomMiniJSON.Json.Deserialize(MiniJSON.Json.Serialize(param)) }).ptr;
});
}
}
}
Console.WriteLine("Done");
}).Start();
}
break;
case "dismantle_all_cards":// Dismantles every single card you own of the given type(s) (Normal, Rare, SuperRare, UltraRare)
{
HashSet<CardRarity> rarities = new HashSet<CardRarity>();
Dictionary<CardRarity, int> raritiesNum = new Dictionary<CardRarity, int>();