You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, completely custom parsing of chunks is not really well-supported. Parsing individual fields with custom methods is already a fully supported first-class API, but classes are missing. An official, easy way to do this would be useful.
My current plan for how to tackle this in the best possible way is to easily allow the creation of custom ChunkParser<TChunk> instances. This would probably look like this:
publicclassTestChunk:Chunk{// Some custom fields}[CustomChunkParser]publicclassTestChunkParser:ChunkParser<CustomChunk>{publicoverrideCustomChunkParse(GameBoxReaderreader,uintchunkId){// ParsereturnnewCustomChunk();}// Tuples of (chunkId, skippable)publicoverrideList<Tuple<uint,bool>>ParseableIds=>newList<Tuple<uint,bool>>(){Tuple.Create(0x0000000,true)};}
These chunk parsers would then be registered as all chunk parsers were usually registered.
Official "unofficial" way to write code that works now and can easily be adapted to the official API later
For now, until this is officially supported, it's possible to implement the same feature with some small workarounds, which can easily be adapted to the final official API later on with minimal changes:
publicclassTestChunk:Chunk{// Some custom fields}publicclassTestChunkParser:PregeneratedChunkParser<CustomChunk>{publicoverrideCustomChunkParse(GameBoxReaderreader,uintchunkId){// ParsereturnnewCustomChunk();}// Tuples of (chunkId, skippable)publicoverrideList<Tuple<uint,bool>>ParseableIds=>newList<Tuple<uint,bool>>(){Tuple.Create(0x0000000,true)};}// Put this code somewhere and run it to register the custom parser// Keep in mind this misuses private APIs that are not officially supported in this way// It should however work reliably at least until the official feature for custom chunk parsers is released((Dictionary<uint,IChunkParser<Chunk>>)typeof(ParserFactory).GetField("chunkParsersByID",BindingFlags.Static|BindingFlags.NonPublic).GetValue(null)).Add(chunkId,newTestChunkParser());((HashSet<uint>)typeof(ParserFactory).GetField("chunkIds",BindingFlags.Static|BindingFlags.NonPublic).GetValue(null)).Add(chunkId);
Currently, completely custom parsing of chunks is not really well-supported. Parsing individual fields with custom methods is already a fully supported first-class API, but classes are missing. An official, easy way to do this would be useful.
Implementing this kind of behaviour is already possible using only official public APIs, but that requires wrapping the actual contents in a custom struct or other similar workarounds. See e.g. https://github.com/stefan-baumann/ManiaPlanetSharp/blob/c9e84b463ea980645e26974b23c3361142205887/src/ManiaPlanetSharp/GameBox/Parsing/Chunks/Replay/ReplayMainChunk.cs
The text was updated successfully, but these errors were encountered: