Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.4.22</PackageVersion>
<PackageVersion>2.4.23</PackageVersion>
<TargetFramework>net8.0</TargetFramework>
<PackageReadmeFile>README.md</PackageReadmeFile>
<ImplicitUsings>enable</ImplicitUsings>
Expand Down
13 changes: 13 additions & 0 deletions Maple2.File.Parser/TableParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ public class TableParser {
private readonly XmlSerializer blackMarketSerializer;
private readonly XmlSerializer changeJobSerializer;
private readonly XmlSerializer fieldMissionSerializer;
private readonly XmlSerializer fieldMetaDataSerializer;
private readonly XmlSerializer worldMapSerializer;
private readonly XmlSerializer mapleSurvivalSkinInfoSerializer;
private readonly XmlSerializer weddingExpSerializer;
Expand Down Expand Up @@ -212,6 +213,7 @@ public TableParser(M2dReader xmlReader, string language) {
blackMarketSerializer = new XmlSerializer(typeof(BlackMarketRoot));
changeJobSerializer = new XmlSerializer(typeof(ChangeJobRoot));
fieldMissionSerializer = new XmlSerializer(typeof(FieldMissionRoot));
fieldMetaDataSerializer = new XmlSerializer(typeof(FieldMetaDataRoot));
worldMapSerializer = new XmlSerializer(typeof(WorldMapRoot));
mapleSurvivalSkinInfoSerializer = new XmlSerializer(typeof(MapleSurvivalSkinInfoRoot));
weddingExpSerializer = new XmlSerializer(typeof(WeddingExpRoot));
Expand Down Expand Up @@ -1405,6 +1407,17 @@ public IEnumerable<JobTableNew> ParseJobTableNew() {
}
}

public IEnumerable<(int Id, FieldPortal Portal)> ParseFieldMetaData() {
string xml = Sanitizer.RemoveEmpty(xmlReader.GetString(xmlReader.GetEntry($"table/{locale}/fieldmetadata.xml")));
var reader = XmlReader.Create(new StringReader(xml));
var data = fieldMetaDataSerializer.Deserialize(reader) as FieldMetaDataRoot;
Debug.Assert(data != null);

foreach (FieldPortal entry in data.fieldPortal) {
yield return (entry.field, entry);
}
}

public IEnumerable<(string Feature, IList<WorldMap.Map> Maps)> ParseWorldMap() {
string xml = Sanitizer.RemoveEmpty(xmlReader.GetString(xmlReader.GetEntry($"table/{locale}/newworldmap.xml")));
var reader = XmlReader.Create(new StringReader(xml));
Expand Down
31 changes: 31 additions & 0 deletions Maple2.File.Parser/Xml/Table/FieldMetaData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System.Xml.Serialization;
using M2dXmlGenerator;

namespace Maple2.File.Parser.Xml.Table;

// ./data/xml/table/na/fieldmetadata.xml
//
// Only the <fieldPortal> section is modelled. The file also carries <npc>, <interactObject>,
// <fluid>, <liftable>, <pet> and <taxiStation> sections, which nothing consumes yet.
[XmlRoot("ms2")]
public partial class FieldMetaDataRoot {
[M2dFeatureLocale(Selector = "field")] private IList<FieldPortal> _fieldPortal;
}

// The client builds its sub-map to exploration-zone table from these entries: portals with
// portalIndoor != 0 are edges, and every map reachable from an indoor="0" entry belongs to
// that outdoor field. See PrivateMaple2 docs/client-re/field-mission-binding.md.
public partial class FieldPortal : IFeatureLocale {
[XmlAttribute] public int field;
[XmlAttribute] public bool indoor;
[XmlElement] public List<Portal> portal = new();

// <portal id="17" targetField="2000025" targetPortal="1" portalType="0" portalIndoor="1" />
public partial class Portal {
[XmlAttribute] public int id;
[XmlAttribute] public int targetField;
[XmlAttribute] public int targetPortal;
[XmlAttribute] public int portalType;
[XmlAttribute] public bool portalIndoor;
}
}
26 changes: 26 additions & 0 deletions Maple2.File.Tests/TableParserTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,32 @@ public void TestFieldMission() {
}
}

// fieldPortal is the client's sub-map to exploration-zone source. The counts and the
// Turtcoli Cave edge are what PrivateMaple2 ingests into FieldPortalZoneTable, so a
// parse that silently drops portalIndoor or indoor would change server behaviour.
[TestMethod]
public void TestFieldMetaData() {
Dictionary<int, FieldPortal> entries = _parser.ParseFieldMetaData()
.ToDictionary(result => result.Id, result => result.Portal);

Assert.AreEqual(1008, entries.Count);
Assert.AreEqual(299, entries.Values.Count(entry => !entry.indoor));

// Turtcoli Cave reaches Royal Road Plaza through a portalIndoor edge (PrivateMaple2 #388).
Assert.IsTrue(entries.TryGetValue(2000250, out FieldPortal? cave));
Assert.IsNotNull(cave);
Assert.IsTrue(cave.indoor);
Assert.IsTrue(cave.portal.Any(portal => portal.targetField == 2000114 && portal.portalIndoor));

// The PvP arena's portals all target field 0, so it joins no component.
Assert.IsTrue(entries.TryGetValue(65010004, out FieldPortal? arena));
Assert.IsNotNull(arena);
Assert.IsTrue(arena.portal.All(portal => portal.targetField == 0));

// Wedding Village has no entry at all and never remaps.
Assert.IsFalse(entries.ContainsKey(84000001));
}

[TestMethod]
public void TestWorldMap() {
foreach ((_, _) in _parser.ParseWorldMap()) {
Expand Down
Loading