Skip to content

Commit 32357e6

Browse files
Feat: KR Xml Parsing (#49)
* Feat: KR Xml Parsing * fix naming * suggestions * suggestion * suggestion2 * formatttttt
1 parent 74361ba commit 32357e6

55 files changed

Lines changed: 2569 additions & 407 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Maple2.File.Generator/XmlArrayGenerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public string _{xmlAttributeName} {{
6666

6767
private void AddSerializer(StringBuilder source, IFieldSymbol field, char delimiter) {
6868
string fieldName = $"this.{field.FieldName()}";
69-
source.Append($"return {fieldName} != null ? string.Join('{delimiter}', {fieldName}) : null;");
69+
source.Append(@$" return {fieldName} != null ? string.Join('{delimiter}', {fieldName}) : string.Empty;");
7070
}
7171

7272
private void AddDeserializer(GeneratorExecutionContext context, StringBuilder source, IFieldSymbol field, char delimiter, bool keepEmpty) {

Maple2.File.Parser/Enum/ConditionType.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public enum ConditionType {
3535
exp_rate = 43,
3636
adventure_level = 44,
3737
adventure_level_up = 45,
38+
level_max = 322,
3839

3940
// group 8
4041
item_pickup = 2,

Maple2.File.Parser/Enum/DungeonType.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public enum DungeonTimerType {
3939
public enum DungeonBossRankingType {
4040
None = 0,
4141
Kill = 1,
42+
kill = Kill,
4243
Damage = 2,
4344
KillRumble = 3,
4445
MultiKill = 4,

Maple2.File.Parser/Enum/ItemExchangeScrollType.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ public enum ItemExchangeScrollType {
55
exchange = 1,
66
updated = 2,
77
trading = 3,
8+
upgrade = 4,
89
}

Maple2.File.Parser/Enum/NameTagSymbolConditionType.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ public enum NameTagSymbolConditionType {
1313
adventure_level,
1414
Burning,
1515
survivallevel,
16+
return_user,
1617
}

Maple2.File.Parser/Enum/QuestPropertyType.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ public enum QuestPropertyType {
44
special = 0,
55
hidebeginablelist = 1,
66
availablecompletionticket = 2,
7+
hideworldmap = 3,
78
}

Maple2.File.Parser/Enum/QuestRewardType.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@ public enum QuestRewardType {
44
unknown = 0,
55
item = 1,
66
skillPoint = 2,
7+
SkillPoint = skillPoint,
78
statPoint = 3,
89
}

Maple2.File.Parser/ItemOptionParser.cs

Lines changed: 100 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,27 +20,66 @@ public class ItemOptionParser {
2020
"mergematerial",
2121
"skin",
2222
];
23-
private readonly string[] randomSuffix = {
24-
"12", "13", "14", "15", "16", "17", "18", "19",
25-
"20", "21", "22",
26-
"30", "31", "32", "33", "34",
27-
"40", "41",
28-
"50", "51", "52", "53", "54", "54_pvp", "55", "56",
23+
private readonly string[] randomSuffix = [
24+
"12",
25+
"13",
26+
"14",
27+
"15",
28+
"16",
29+
"17",
30+
"18",
31+
"19",
32+
"20",
33+
"21",
34+
"22",
35+
"30",
36+
"31",
37+
"32",
38+
"33",
39+
"34",
40+
"40",
41+
"41",
42+
"50",
43+
"51",
44+
"52",
45+
"53",
46+
"54",
47+
"54_pvp",
48+
"55",
49+
"56",
2950
"accmanual",
3051
"armormanual",
3152
"pet_60",
3253
"weaponmanual",
33-
};
34-
private readonly string[] staticSuffix = {
35-
"12", "13", "14", "15", "16", "17", "18", "19",
36-
"20", "21", "22",
37-
"30", "31", "32", "33", "34",
38-
"40", "41",
39-
"50", "51", "52", "53", "54",
54+
];
55+
private readonly string[] staticSuffix = [
56+
"12",
57+
"13",
58+
"14",
59+
"15",
60+
"16",
61+
"17",
62+
"18",
63+
"19",
64+
"20",
65+
"21",
66+
"22",
67+
"30",
68+
"31",
69+
"32",
70+
"33",
71+
"34",
72+
"40",
73+
"41",
74+
"50",
75+
"51",
76+
"52",
77+
"53",
78+
"54",
4079
"armormanual",
4180
"mergematerial",
4281
"petequipment",
43-
};
82+
];
4483
private readonly string[] variationSuffix = [
4584
"acc",
4685
"armor",
@@ -50,7 +89,10 @@ public class ItemOptionParser {
5089

5190
private readonly M2dReader xmlReader;
5291
private readonly XmlSerializer itemOptionConstantSerializer;
92+
private readonly XmlSerializer itemOptionConstantKrSerializer;
5393
private readonly XmlSerializer itemOptionSerializer;
94+
private readonly XmlSerializer itemOptionKrSerializer;
95+
private readonly XmlSerializer itemMergeOptionKrSerializer;
5496
private readonly XmlSerializer itemMergeOptionSerializer;
5597
private readonly XmlSerializer itemOptionPickSerializer;
5698
private readonly XmlSerializer itemVariationSerializer;
@@ -59,7 +101,10 @@ public class ItemOptionParser {
59101
public ItemOptionParser(M2dReader xmlReader) {
60102
this.xmlReader = xmlReader;
61103
itemOptionConstantSerializer = new XmlSerializer(typeof(ItemOptionConstantRoot));
104+
itemOptionConstantKrSerializer = new XmlSerializer(typeof(ItemOptionConstantRootKR));
62105
itemOptionSerializer = new XmlSerializer(typeof(ItemOptionRoot));
106+
itemOptionKrSerializer = new XmlSerializer(typeof(ItemOptionRandomRootKR));
107+
itemMergeOptionKrSerializer = new XmlSerializer(typeof(ItemMergeOptionRootKR));
63108
itemMergeOptionSerializer = new XmlSerializer(typeof(ItemMergeOptionRoot));
64109
itemOptionPickSerializer = new XmlSerializer(typeof(ItemOptionPickRoot));
65110
itemVariationSerializer = new XmlSerializer(typeof(ItemOptionVariation));
@@ -82,6 +127,20 @@ public IEnumerable<ItemOptionConstantData> ParseConstant() {
82127
}
83128
}
84129

130+
public IEnumerable<ItemOptionConstant> ParseConstantKr() {
131+
string xml = Sanitizer.RemoveEmpty(xmlReader.GetString(xmlReader.GetEntry("table/itemoptionconstant.xml")));
132+
xml = Sanitizer.RemoveUtf8Bom(xml);
133+
var reader = XmlReader.Create(new StringReader(xml));
134+
var root = itemOptionConstantKrSerializer.Deserialize(reader) as ItemOptionConstantRootKR;
135+
Debug.Assert(root != null);
136+
137+
foreach (ItemOptionConstant option in root.options) {
138+
if (option.code > 0) {
139+
yield return option;
140+
}
141+
}
142+
}
143+
85144
public IEnumerable<ItemOptionData> ParseRandom() {
86145
foreach (string suffix in randomSuffix) {
87146
string filename = $"itemoption/option/random/itemoptionrandom_{suffix}.xml";
@@ -98,6 +157,21 @@ public IEnumerable<ItemOptionData> ParseRandom() {
98157
}
99158
}
100159

160+
public IEnumerable<ItemOptionRandomKR> ParseRandomKr() {
161+
string xml = Sanitizer.RemoveEmpty(xmlReader.GetString(xmlReader.GetEntry("table/itemoptionrandom.xml")));
162+
xml = Sanitizer.RemoveUtf8Bom(xml);
163+
var reader = XmlReader.Create(new StringReader(xml));
164+
var root = itemOptionKrSerializer.Deserialize(reader) as ItemOptionRandomRootKR;
165+
Debug.Assert(root != null);
166+
167+
foreach (ItemOptionRandomKR option in root.options) {
168+
if (option.code > 0) {
169+
yield return option;
170+
}
171+
}
172+
173+
}
174+
101175
public IEnumerable<ItemOptionData> ParseStatic() {
102176
foreach (string suffix in staticSuffix) {
103177
string filename = $"itemoption/option/static/itemoptionstatic_{suffix}.xml";
@@ -114,6 +188,18 @@ public IEnumerable<ItemOptionData> ParseStatic() {
114188
}
115189
}
116190

191+
public IEnumerable<MergeOptionKR> ParseMergeOptionBaseKr() {
192+
string xml = Sanitizer.RemoveEmpty(xmlReader.GetString(xmlReader.GetEntry("table/itemmergeoptionbase.xml")));
193+
xml = Sanitizer.RemoveUtf8Bom(xml);
194+
var reader = XmlReader.Create(new StringReader(xml));
195+
var root = itemMergeOptionKrSerializer.Deserialize(reader) as ItemMergeOptionRootKR;
196+
Debug.Assert(root != null);
197+
198+
foreach (MergeOptionKR option in root.mergeOption) {
199+
yield return option;
200+
}
201+
}
202+
117203
public IEnumerable<MergeOption> ParseMergeOptionBase() {
118204
string xml = Sanitizer.RemoveEmpty(xmlReader.GetString(xmlReader.GetEntry("table/itemmergeoptionbase.xml")));
119205
var reader = XmlReader.Create(new StringReader(xml));

Maple2.File.Parser/ItemParser.cs

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System.Diagnostics;
22
using System.Xml;
33
using System.Xml.Serialization;
4+
using M2dXmlGenerator;
45
using Maple2.File.IO;
56
using Maple2.File.IO.Crypto.Common;
67
using Maple2.File.Parser.Xml.Item;
@@ -10,31 +11,45 @@ namespace Maple2.File.Parser;
1011

1112
public class ItemParser {
1213
private readonly M2dReader xmlReader;
13-
public readonly XmlSerializer NameSerializer;
14-
public readonly XmlSerializer ItemSerializer;
14+
private readonly XmlSerializer nameSerializer;
15+
private readonly XmlSerializer itemSerializer;
1516

1617
public ItemParser(M2dReader xmlReader) {
1718
this.xmlReader = xmlReader;
18-
NameSerializer = new XmlSerializer(typeof(StringMapping));
19-
ItemSerializer = new XmlSerializer(typeof(ItemDataRoot));
19+
nameSerializer = new XmlSerializer(typeof(StringMapping));
20+
Type type = FeatureLocaleFilter.Locale is "KR" ? typeof(ItemDataKR) : typeof(ItemDataRoot);
21+
itemSerializer = new XmlSerializer(type);
22+
23+
}
24+
25+
public IEnumerable<(int Id, string Name, ItemData Data)> Parse<T>() where T : class {
26+
Dictionary<int, string> itemNames = ItemNames();
27+
string folderName = "item/";
28+
if (FeatureLocaleFilter.Locale == "KR") {
29+
folderName = "itemdata/";
30+
}
31+
foreach (PackFileEntry entry in xmlReader.Files.Where(e => e.Name.StartsWith(folderName))) {
32+
var xml = itemSerializer.Deserialize(xmlReader.GetXmlReader(entry)) as T;
33+
switch (xml) {
34+
case ItemDataRoot root when root.environment != null:
35+
int itemId = int.Parse(Path.GetFileNameWithoutExtension(entry.Name));
36+
yield return (itemId, itemNames.GetValueOrDefault(itemId, string.Empty), root.environment);
37+
break;
38+
case ItemDataKR rootKr:
39+
foreach (var dataRoot in rootKr.items) {
40+
if (dataRoot.environment == null) continue;
41+
yield return (dataRoot.id, itemNames.GetValueOrDefault(dataRoot.id, string.Empty), dataRoot.environment);
42+
}
43+
break;
44+
}
45+
}
2046
}
2147

22-
public IEnumerable<(int Id, string Name, ItemData Data)> Parse() {
48+
public Dictionary<int, string> ItemNames() {
2349
XmlReader reader = xmlReader.GetXmlReader(xmlReader.GetEntry("en/itemname.xml"));
24-
var mapping = NameSerializer.Deserialize(reader) as StringMapping;
50+
var mapping = nameSerializer.Deserialize(reader) as StringMapping;
2551
Debug.Assert(mapping != null);
2652

27-
Dictionary<int, string> itemNames = mapping.key.ToDictionary(key => int.Parse(key.id), key => key.name);
28-
29-
foreach (PackFileEntry entry in xmlReader.Files.Where(entry => entry.Name.StartsWith("item/"))) {
30-
var root = ItemSerializer.Deserialize(xmlReader.GetXmlReader(entry)) as ItemDataRoot;
31-
Debug.Assert(root != null);
32-
33-
ItemData data = root.environment;
34-
if (data == null) continue;
35-
36-
int itemId = int.Parse(Path.GetFileNameWithoutExtension(entry.Name));
37-
yield return (itemId, itemNames.GetValueOrDefault(itemId), data);
38-
}
53+
return mapping.key.ToDictionary(key => int.Parse(key.id), key => key.name);
3954
}
4055
}

Maple2.File.Parser/MapParser.cs

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System.Diagnostics;
22
using System.Xml;
33
using System.Xml.Serialization;
4+
using M2dXmlGenerator;
45
using Maple2.File.IO;
56
using Maple2.File.IO.Crypto.Common;
67
using Maple2.File.Parser.Tools;
@@ -17,26 +18,49 @@ public class MapParser {
1718
public MapParser(M2dReader xmlReader) {
1819
this.xmlReader = xmlReader;
1920
NameSerializer = new XmlSerializer(typeof(StringMapping));
20-
MapSerializer = new XmlSerializer(typeof(MapDataRoot));
21+
Type type = FeatureLocaleFilter.Locale == "KR" ? typeof(MapDataRootKR) : typeof(MapDataRoot);
22+
MapSerializer = new XmlSerializer(type);
2123
}
2224

2325
public IEnumerable<(int Id, string Name, MapData Data)> Parse() {
24-
XmlReader reader = xmlReader.GetXmlReader(xmlReader.GetEntry("en/mapname.xml"));
25-
var mapping = NameSerializer.Deserialize(reader) as StringMapping;
26-
Debug.Assert(mapping != null);
26+
Dictionary<int, string> mapNames = ParseMapNames();
2727

28-
Dictionary<int, string> mapNames = mapping.key.ToDictionary(key => int.Parse(key.id), key => key.name);
28+
IEnumerable<PackFileEntry> entries;
29+
if (FeatureLocaleFilter.Locale == "KR") {
30+
entries = [xmlReader.GetEntry("table/fielddata.xml")];
31+
} else {
32+
entries = xmlReader.Files.Where(entry => entry.Name.StartsWith("map/"));
33+
}
34+
35+
foreach (PackFileEntry entry in entries) {
36+
XmlReader reader = XmlReader.Create(new StringReader(Sanitizer.SanitizeMap(xmlReader.GetString(entry))));
37+
if (FeatureLocaleFilter.Locale == "KR") {
38+
var rootKr = MapSerializer.Deserialize(reader) as MapDataRootKR;
39+
Debug.Assert(rootKr != null);
40+
foreach (MapDataRootKR item in rootKr.fieldData) {
41+
if (item.environment == null) continue;
42+
MapData dataKr = item.environment;
43+
yield return (item.id, mapNames.GetValueOrDefault(item.id, string.Empty), dataKr);
44+
}
45+
continue;
46+
}
2947

30-
foreach (PackFileEntry entry in xmlReader.Files.Where(entry => entry.Name.StartsWith("map/"))) {
31-
reader = XmlReader.Create(new StringReader(Sanitizer.SanitizeMap(xmlReader.GetString(entry))));
3248
var root = MapSerializer.Deserialize(reader) as MapDataRoot;
3349
Debug.Assert(root != null);
3450

3551
MapData data = root.environment;
3652
if (data == null) continue;
3753

3854
int mapId = int.Parse(Path.GetFileNameWithoutExtension(entry.Name));
39-
yield return (mapId, mapNames.GetValueOrDefault(mapId), data);
55+
yield return (mapId, mapNames.GetValueOrDefault(mapId, string.Empty), data);
4056
}
4157
}
58+
59+
public Dictionary<int, string> ParseMapNames() {
60+
var reader = xmlReader.GetXmlReader(xmlReader.GetEntry("en/mapname.xml"));
61+
var mapping = NameSerializer.Deserialize(reader) as StringMapping;
62+
Debug.Assert(mapping != null);
63+
64+
return mapping.key.ToDictionary(key => int.Parse(key.id), key => key.name);
65+
}
4266
}

0 commit comments

Comments
 (0)