Beispiel #1
0
        public void Write(string fileName)
        {
            using (EOFile file = new EOFile(File.Open(fileName, FileMode.Create, FileAccess.Write)))
            {
                file.AddString("EMF");
                file.AddInt(0);

                byte[] padName = new byte[24];

                for (int i = 0; i < 24; ++i)
                    padName[i] = 0xFF;

                byte[] encName = EncodeString(name);

                Array.Resize(ref encName, Math.Min(24, encName.Length));

                Array.Copy(encName, 0, padName, 24 - encName.Length, encName.Length);

                file.AddBytes(padName);
                file.AddChar((byte)type);
                file.AddChar((byte)effect);
                file.AddChar(music);
                file.AddChar(musicExtra);
                file.AddShort((short)ambientNoise);
                file.AddChar(width);
                file.AddChar(height);
                file.AddShort((short)fillTile);
                file.AddChar(mapAvailable);
                file.AddChar(canScroll);
                file.AddChar(relogX);
                file.AddChar(relogY);
                file.AddChar(unknown);

                file.AddChar((byte)npcs.Count);

                foreach (NPC npc in npcs)
                {
                    file.AddChar(npc.x);
                    file.AddChar(npc.y);
                    file.AddShort((short)npc.id);
                    file.AddChar(npc.spawnType);
                    file.AddShort((short)npc.spawnTime);
                    file.AddChar(npc.amount);
                }

                file.AddChar((byte)unknowns.Count);

                foreach (Unknown unknown_ in unknowns)
                {
                    file.AddBytes(unknown_.data);
                }

                file.AddChar((byte)chests.Count);

                foreach (Chest chest in chests)
                {
                    file.AddChar(chest.x);
                    file.AddChar(chest.y);
                    file.AddShort((short)chest.key);
                    file.AddChar(chest.slot);
                    file.AddShort((short)chest.item);
                    file.AddShort((short)chest.time);
                    file.AddThree((int)chest.amount);
                }

                file.AddChar((byte)tileRows.Count);

                foreach (TileRow row in tileRows)
                {
                    file.AddChar(row.y);
                    file.AddChar((byte)row.tiles.Count);

                    foreach (Tile tile in row.tiles)
                    {
                        file.AddChar(tile.x);
                        file.AddChar((byte)tile.spec);
                    }
                }

                file.AddChar((byte)warprows.Count);

                foreach (WarpRow row in warprows)
                {
                    file.AddChar(row.y);
                    file.AddChar((byte)row.tiles.Count);

                    foreach (Warp warp in row.tiles)
                    {
                        file.AddChar(warp.x);
                        file.AddShort((short)warp.warpMap);
                        file.AddChar(warp.warpX);
                        file.AddChar(warp.warpY);
                        file.AddChar(warp.levelRequirement);
                        file.AddShort((short)warp.door);
                    }
                }

                for (int layer = 0; layer < GFXLayers; ++layer)
                {
                    file.AddChar((byte)gfxRows[layer].Count);

                    foreach (GFXRow row in gfxRows[layer])
                    {
                        file.AddChar(row.y);
                        file.AddChar((byte)row.tiles.Count);

                        foreach (GFX gfx in row.tiles)
                        {
                            file.AddChar(gfx.x);
                            file.AddShort((short)gfx.tile);
                        }
                    }
                }

                file.AddChar((byte)signs.Count);

                foreach (Sign sign in signs)
                {
                    file.AddChar(sign.x);
                    file.AddChar(sign.y);
                    file.AddShort((short)(sign.title.Length + sign.message.Length + 1));
                    file.AddBytes(EncodeString(sign.title + sign.message));
                    file.AddChar((byte)sign.title.Length);
                }

                revisionId = file.WriteHash(3);
            }
        }