|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## What This Is |
| 6 | + |
| 7 | +Strongly-typed MapleStory2 .m2d file parsing library. Reads encrypted game data files and provides typed access to game entities (items, NPCs, quests, maps, skills, etc.). |
| 8 | + |
| 9 | +## Build Commands |
| 10 | + |
| 11 | +```bash |
| 12 | +dotnet build # Build entire solution |
| 13 | +dotnet test # Run all tests (MSTest) |
| 14 | +dotnet test --filter "FullyQualifiedName~XBlockParserTest" # Run single test class |
| 15 | +dotnet pack Maple2.File.Parser # Pack the NuGet package |
| 16 | +``` |
| 17 | + |
| 18 | +Tests require a `MS2_DATA_FOLDER` environment variable (or `.env` file) pointing to extracted MapleStory2 data. |
| 19 | + |
| 20 | +## Architecture |
| 21 | + |
| 22 | +### Projects |
| 23 | + |
| 24 | +- **Maple2.File.IO** — Low-level encrypted .m2d/.m2h file reading, decryption (AES), memory-mapped files. Multi-targets `net8.0` and `netstandard2.1`. |
| 25 | +- **Maple2.File.Flat** — Interface definitions for all game entity types (`IMapEntity`, `ISpawnPointNPC`, `IPortal`, etc.). ~252 files across model libraries. |
| 26 | +- **Maple2.File.Parser** — High-level parsers. Published as NuGet `Maple2.File.Parser.Tadeucci`. Contains: |
| 27 | + - `Flat/` — `FlatTypeIndex`, `FlatType`, `FlatProperty` for the model type hierarchy |
| 28 | + - `MapXBlock/` — `XBlockParser` for map entity data with runtime IL class generation |
| 29 | + - `Xml/` — Strongly-typed XML model classes for game data |
| 30 | + - `Tools/` — `Filter` (locale/feature), `Sanitizer`, `HierarchyMap`, `ILEmitter` |
| 31 | + - Root-level parsers: `ItemParser`, `NpcParser`, `QuestParser`, `SkillParser`, `TableParser` (60+ methods), etc. |
| 32 | +- **Maple2.File.Generator** — Roslyn source generator for XML serialization. Embedded as analyzer in Parser project. Custom attributes: `M2dArray`, `M2dNullable`, `M2dVector3`, `M2dEnum`, `M2dColor`, `M2dFeatureLocale`. |
| 33 | +- **Maple2.File.Unity** — Lightweight `netstandard2.1` subset for Unity. Shares source files via linked references from Parser. |
| 34 | +- **Maple2.File.Cli** — Interactive CLI explorer for flat type data. |
| 35 | +- **Maple2.File.Tests** — MSTest unit tests. |
| 36 | +- **Maple2.File.Generator.Debugger** — For debugging the source generator. |
| 37 | + |
| 38 | +### Key Patterns |
| 39 | + |
| 40 | +**Encrypted pack files**: `M2dReader` opens .m2d/.m2h pairs, decrypts via `CryptoManager`, returns `PackFileEntry[]`. Use `GetXmlReader()`, `GetBytes()`, `GetString()` to access content. |
| 41 | + |
| 42 | +**Runtime IL class generation**: `RuntimeClassLookup` uses `Reflection.Emit` to create concrete classes from `IMapEntity` interfaces at runtime. Types are cached after first generation. |
| 43 | + |
| 44 | +**Locale/feature filtering**: Call `Filter.Load(reader, locale, env)` before XML parsing. Locales: TW, TH, NA, CN, JP, KR. Environments: Dev, Qa, DevStage, Stage, Live. |
| 45 | + |
| 46 | +**XML parser pattern**: Each parser takes an `M2dReader`, has a `Parse()` method returning typed tuples, and uses `XmlSerializer` with source-generated helpers. |
| 47 | + |
| 48 | +**XML sanitization**: `Sanitizer` fixes malformed game XML (empty attributes, invalid booleans, UTF-8 BOM issues) before deserialization. |
| 49 | + |
| 50 | +## Code Style |
| 51 | + |
| 52 | +- C# 12, .NET 8.0 SDK (see `global.json`) |
| 53 | +- K&R brace style (no opening brace on new line) |
| 54 | +- 4-space indentation |
| 55 | +- `camelCase` for private fields, `_camelCase` for private static fields, `PascalCase` for private constants/static readonly |
| 56 | +- `ALL_UPPER` for public/internal constants |
| 57 | +- Prefer explicit types over `var` for built-in types |
| 58 | +- Space after cast |
| 59 | +- Nullable reference types enabled |
| 60 | +- Overflow checking enabled in Parser |
0 commit comments