Skip to content

Commit

Permalink
Parse Meret Market, Shop UGC (#35)
Browse files Browse the repository at this point in the history
* Parse Meret Market, Shop UGC

* bump up version

* jk .28
  • Loading branch information
Zintixx authored Sep 16, 2024
1 parent bedefef commit d7ccf56
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Maple2.File.Parser/Maple2.File.Parser.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<PackageTags>MapleStory2, File, Parser, m2d, xml</PackageTags>
<!-- Use following lines to write the generated files to disk. -->
<EmitCompilerGeneratedFiles Condition=" '$(Configuration)' == 'Debug' ">true</EmitCompilerGeneratedFiles>
<PackageVersion>2.1.27</PackageVersion>
<PackageVersion>2.1.28</PackageVersion>
<TargetFramework>net8.0</TargetFramework>
<PackageReadmeFile>README.md</PackageReadmeFile>
<ImplicitUsings>enable</ImplicitUsings>
Expand Down
25 changes: 25 additions & 0 deletions Maple2.File.Parser/ServerTableParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public class ServerTableParser {
private readonly XmlSerializer unlimitedEnchantOptionSerializer;
private readonly XmlSerializer itemMergeOptionSerializer;
private readonly XmlSerializer enchantOptionSerializer;
private readonly XmlSerializer shopMeretSerializer;

public ServerTableParser(M2dReader xmlReader) {
this.xmlReader = xmlReader;
Expand Down Expand Up @@ -79,6 +80,7 @@ public ServerTableParser(M2dReader xmlReader) {
unlimitedEnchantOptionSerializer = new XmlSerializer(typeof(UnlimitedEnchantOptionRoot));
itemMergeOptionSerializer = new XmlSerializer(typeof(ItemMergeOptionRoot));
enchantOptionSerializer = new XmlSerializer(typeof(EnchantOptionRoot));
shopMeretSerializer = new XmlSerializer(typeof(ShopMeretRoot));

// var seen = new HashSet<string>();
// this.bankTypeSerializer.UnknownAttribute += (sender, args) => {
Expand Down Expand Up @@ -319,6 +321,18 @@ public ServerTableParser(M2dReader xmlReader) {
}
}

public IEnumerable<(int ShopId, ShopGame ShopGame)> ParseShopUgc() {
string xml = Sanitizer.RemoveEmpty(xmlReader.GetString(xmlReader.GetEntry("table/Server/shop_UGC.xml")));
xml = Sanitizer.RemoveSpaces(xml);
var reader = XmlReader.Create(new StringReader(xml));
var data = shopGameSerializer.Deserialize(reader) as ShopGameRoot;
Debug.Assert(data != null);

foreach (ShopGame shopGame in data.shop) {
yield return (shopGame.shopID, shopGame);
}
}

public IEnumerable<(int ShopId, ShopBeauty ShopBeauty)> ParseShopBeauty() {
XmlReader reader = xmlReader.GetXmlReader(xmlReader.GetEntry("table/Server/NA/shop_beauty.xml"));
var data = shopBeautySerializer.Deserialize(reader) as ShopBeautyRoot;
Expand Down Expand Up @@ -602,4 +616,15 @@ public ServerTableParser(M2dReader xmlReader) {
yield return (entry.id, entry);
}
}

public IEnumerable<(int Sn, ShopMeret ShopMeret)> ParseShopMeret() {
string xml = Sanitizer.RemoveEmpty(xmlReader.GetString(xmlReader.GetEntry("table/Server/shop_merat.xml")));
var reader = XmlReader.Create(new StringReader(xml));
var data = shopMeretSerializer.Deserialize(reader) as ShopMeretRoot;
Debug.Assert(data != null);

foreach (ShopMeret shopMeret in data.item) {
yield return (shopMeret.sn, shopMeret);
}
}
}
4 changes: 4 additions & 0 deletions Maple2.File.Parser/Tools/Sanitizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ public static string RemoveEmpty(string xml) {
return Regex.Replace(xml, "\\w+=\"\"", string.Empty);
}

public static string RemoveSpaces(string xml) {
return Regex.Replace(xml, "(\\w+)=\"([^\"]*?)\\s+\"", "$1=\"$2\"");
}

// Floats using ',' are converted to '.' (1,2 -> 1.2)
private static string FixCommaFloats(string xml, params string[] attributes) {
string pattern = $"({string.Join('|', attributes)})=\"(-?\\d+)(?:,(\\d+))\"";
Expand Down
31 changes: 31 additions & 0 deletions Maple2.File.Parser/Xml/Table/Server/ShopMeret.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System.Xml.Serialization;

namespace Maple2.File.Parser.Xml.Table.Server;

// ./data/server/table/Server/shop_merat.xml
[XmlRoot("ms2")]
public class ShopMeretRoot {
[XmlElement] public List<ShopMeret> item;
}

public partial class ShopMeret {
[XmlAttribute] public int sn;
[XmlAttribute] public int id;
[XmlAttribute] public string category = string.Empty;
[XmlAttribute] public long price;
[XmlAttribute] public long price_1;
[XmlAttribute] public long price_7;
[XmlAttribute] public long price_30;
[XmlAttribute] public long salePrice;
[XmlAttribute] public long salePrice_1;
[XmlAttribute] public long salePrice_7;
[XmlAttribute] public long salePrice_30;
[XmlAttribute] public int defPriceIndex;
[XmlAttribute] public short grade;
[XmlAttribute] public int saleTag;
[XmlAttribute] public bool visible;
[XmlAttribute] public string createDate = string.Empty;
[XmlAttribute] public int chartOrder;
[XmlAttribute] public int buyLimit;
[XmlAttribute] public int buyLimitMax;
}
18 changes: 18 additions & 0 deletions Maple2.File.Tests/ServerTableParserTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,15 @@ public void TestShopGame() {
}
}

[TestMethod]
public void TestShopUgc() {
var parser = new ServerTableParser(TestUtils.ServerReader);

foreach ((_, _) in parser.ParseShopUgc()) {
continue;
}
}

[TestMethod]
public void TestShopBeauty() {
var parser = new ServerTableParser(TestUtils.ServerReader);
Expand Down Expand Up @@ -381,4 +390,13 @@ public void TestEnchantOption() {
continue;
}
}

[TestMethod]
public void TestMeretShop() {
var parser = new ServerTableParser(TestUtils.ServerReader);

foreach ((_, _) in parser.ParseShopMeret()) {
continue;
}
}
}

0 comments on commit d7ccf56

Please sign in to comment.