Beispiel #1
0
    public void Read(GameBoxReader reader, IProgress <GameBoxReadProgress>?progress = null)
    {
        CMwNod.Parse(GBX.Node, reader, progress);

        IsParsed = true;

        using var ms = new MemoryStream();
        var s = reader.BaseStream;

        s.CopyTo(ms);
        Rest = ms.ToArray();
        Debug.WriteLine("Amount read: " + (s.Position / (float)(s.Position + Rest.Length)).ToString("P"));
    }
Beispiel #2
0
        public T ReadNodeRef <T>(GameBoxBody body) where T : CMwNod
        {
            var index = ReadInt32() - 1;                                                                     // GBX seems to start the index at 1

            if (index >= 0 && (!body.AuxilaryNodes.ContainsKey(index) || body.AuxilaryNodes[index] == null)) // If index is 0 or bigger and the node wasn't read yet, or is null
            {
                body.AuxilaryNodes[index] = CMwNod.Parse <T>(this);
            }

            if (index < 0) // If aux node index is below 0 then there's not much to solve
            {
                return(null);
            }
            body.AuxilaryNodes.TryGetValue(index, out CMwNod n); // Tries to get the available node from index

            if (n is T nod)                                      // If the node is presented at the index, then it's simple
            {
                return(nod);
            }

            // But sometimes it indexes the node reference that is further in the expected indexes
            return((T)body.AuxilaryNodes.Last().Value); // So it grabs the last one instead, needs to be further tested
        }