예제 #1
0
        public void ReadDictionary(BinBuffer bb)
        {
            int modAmt = bb.ReadByte();

            for (int i = 0; i < modAmt; i++)
            {
                Mods.Add(bb.ReadString(), bb.ReadByte());
            }

            for (int i = 0; i < modAmt; i++)
            {
                ModID mid = bb.ReadByte();

                var modObjs = new BiDictionary <ObjName, ObjID>();

                short objAmt = bb.ReadInt16();

                for (int j = 0; j < objAmt; j++)
                {
                    modObjs.Add(bb.ReadString(), bb.ReadUInt16());
                }

                ModObjects.Add(mid, modObjs);
            }
        }
예제 #2
0
        static void Read2DArray(BinBuffer bb, ModIdMap map, int xLen, int yLen, Action <int, int, int> setElemV, Action <int, int, ObjectRef> setElemM)
        {
            var dictPos   = bb.ReadInt32();
            var dataStart = bb.Position;

            bb.Position = dictPos;

            map.ReadDictionary(bb);

            var endOfStream = bb.Position;

            bb.Position = dataStart;

            int amt = 0;

            bool      isM  = false;
            ObjectRef curM = ObjectRef.Null;
            int       curV = 0;

            for (int y = 0; y < yLen; y++)
            {
                for (int x = 0; x < xLen; x++)
                {
                    if (amt == 0)
                    {
                        map.GetRef(bb.ReadUInt32(),
                                   oid =>
                        {
                            curV = oid;
                            isM  = false;

                            setElemV(x, y, curV);     // amt == 0 -> one element
                        },
                                   or =>
                        {
                            curM = or;
                            isM  = true;

                            setElemM(x, y, curM);     // amt == 0 -> one element
                        });
                        amt = bb.ReadUInt16();
                    }
                    else
                    {
                        if (isM)
                        {
                            setElemM(x, y, curM);
                        }
                        else
                        {
                            setElemV(x, y, curV);
                        }

                        amt--;
                    }
                }
            }

            bb.Position = endOfStream;
        }
예제 #3
0
        static void LoadTileTypes(BinBuffer bb, int v)
        {
            // don't read anything for now, custom tiles aren't implemented
            return;

#pragma warning disable 162
            // to be used in future versions
            if (v == 0)
            {
                return;
            }
#pragma warning restore 162

            var map = new ModIdMap(TileID.Count, or => new TileRef(or).Resolve().Type, id => new TileRef(id));

            var tp         = bb.Position;
            var dictOffset = bb.ReadInt32();
            bb.Position += dictOffset;

            map.ReadDictionary(bb);

            var end = bb.Position;

            bb.Position = tp;

            int amt = 0;

            for (int y = 0; y < Main.maxTilesY; y++)
            {
                for (int x = 0; x < Main.maxTilesX; x++)
                {
                    if (amt == 0)
                    {
                        var t = bb.ReadUInt32();
                        Main.tile[x, y].type = (ushort)new TileRef(map.GetRef(t)).Resolve().Type;

                        amt = bb.ReadUInt16();
                    }
                    else
                    {
                        amt--;
                    }
                }
            }

            bb.Position = end;
        }