internal static void ReadTiles(BinaryReader reader) { TileTables tables = TileTables.Create(); ushort count = reader.ReadUInt16(); for (int k = 0; k < count; k++) { ushort type = reader.ReadUInt16(); string modName = reader.ReadString(); string name = reader.ReadString(); Mod mod = ModLoader.GetMod(modName); tables.tiles[type] = mod == null ? (ushort)0 : (ushort)mod.TileType(name); tables.frameImportant[type] = reader.ReadBoolean(); } count = reader.ReadUInt16(); for (int k = 0; k < count; k++) { ushort wall = reader.ReadUInt16(); string modName = reader.ReadString(); string name = reader.ReadString(); Mod mod = ModLoader.GetMod(modName); tables.walls[wall] = mod == null ? (ushort)0 : (ushort)mod.WallType(name); } ReadTileData(reader, tables); }
internal static void LoadLegacyTiles(BinaryReader reader) { TileTables tables = TileTables.Create(); ushort count = reader.ReadUInt16(); for (int k = 0; k < count; k++) { ushort type = reader.ReadUInt16(); string modName = reader.ReadString(); string name = reader.ReadString(); Mod mod = ModLoader.GetMod(modName); tables.tiles[type] = mod == null ? (ushort)0 : (ushort)mod.TileType(name); if (tables.tiles[type] == 0) { tables.tiles[type] = (ushort)ModContent.GetInstance <ModLoaderMod>().TileType("PendingMysteryTile"); tables.tileModNames[type] = modName; tables.tileNames[type] = name; } tables.frameImportant[type] = reader.ReadBoolean(); } count = reader.ReadUInt16(); for (int k = 0; k < count; k++) { ushort wall = reader.ReadUInt16(); string modName = reader.ReadString(); string name = reader.ReadString(); Mod mod = ModLoader.GetMod(modName); tables.walls[wall] = mod == null ? (ushort)0 : (ushort)mod.WallType(name); } ReadTileData(reader, tables); }
internal static void LoadTiles(TagCompound tag) { if (!tag.ContainsKey("data")) { return; } var tables = TileTables.Create(); foreach (var tileTag in tag.GetList <TagCompound>("tileMap")) { ushort type = (ushort)tileTag.GetShort("value"); string modName = tileTag.GetString("mod"); string name = tileTag.GetString("name"); tables.tiles[type] = ModContent.TryFind(modName, name, out ModTile tile) ? tile.Type : (ushort)0; if (tables.tiles[type] == 0) { tables.tiles[type] = ModContent.Find <ModTile>("ModLoader/PendingUnloadedTile").Type; tables.tileModNames[type] = modName; tables.tileNames[type] = name; } tables.frameImportant[type] = tileTag.GetBool("framed"); } foreach (var wallTag in tag.GetList <TagCompound>("wallMap")) { ushort type = (ushort)wallTag.GetShort("value"); string modName = wallTag.GetString("mod"); string name = wallTag.GetString("name"); tables.walls[type] = ModContent.TryFind(modName, name, out ModWall wall) ? wall.Type : (ushort)0; } using (var memoryStream = new MemoryStream(tag.GetByteArray("data"))) using (var reader = new BinaryReader(memoryStream)) ReadTileData(reader, tables); WorldIO.ValidateSigns(); }
internal static void LoadTiles(TagCompound tag) { if (!tag.ContainsKey("data")) { return; } var tables = TileTables.Create(); foreach (var tileTag in tag.GetList <TagCompound>("tileMap")) { ushort type = (ushort)tileTag.GetShort("value"); string modName = tileTag.GetString("mod"); string name = tileTag.GetString("name"); Mod mod = ModLoader.GetMod(modName); tables.tiles[type] = mod == null ? (ushort)0 : (ushort)mod.TileType(name); if (tables.tiles[type] == 0) { tables.tiles[type] = (ushort)ModLoader.GetMod("ModLoader").TileType("PendingMysteryTile"); tables.tileModNames[type] = modName; tables.tileNames[type] = name; } tables.frameImportant[type] = tileTag.GetBool("framed"); } foreach (var wallTag in tag.GetList <TagCompound>("wallMap")) { ushort wall = (ushort)wallTag.GetShort("value"); string modName = wallTag.GetString("mod"); string name = wallTag.GetString("name"); Mod mod = ModLoader.GetMod(modName); tables.walls[wall] = mod == null ? (ushort)0 : (ushort)mod.WallType(name); } ReadTileData(new BinaryReader(new MemoryStream(tag.GetByteArray("data"))), tables); }
internal static TileTables Create() { TileTables tables = new TileTables(); tables.tiles = new Dictionary<ushort, ushort>(); tables.frameImportant = new Dictionary<ushort, bool>(); tables.walls = new Dictionary<ushort, ushort>(); return tables; }
internal static TileTables Create() { TileTables tables = new TileTables(); tables.tiles = new Dictionary <ushort, ushort>(); tables.frameImportant = new Dictionary <ushort, bool>(); tables.walls = new Dictionary <ushort, ushort>(); return(tables); }
internal static TileTables Create() { TileTables tables = new TileTables { tiles = new Dictionary <ushort, ushort>(), frameImportant = new Dictionary <ushort, bool>(), walls = new Dictionary <ushort, ushort>(), tileModNames = new Dictionary <ushort, string>(), tileNames = new Dictionary <ushort, string>() }; return(tables); }
public void Close() { if (!ProjectLoaded) { return; } Rooms.Clear(); DoorSets.Clear(); Doors.Clear(); ScrollSets.Clear(); PlmSets.Clear(); ScrollPlmDatas.Clear(); Backgrounds.Clear(); Fxs.Clear(); SaveStations.Clear(); LevelDatas.Clear(); EnemySets.Clear(); EnemyGfxs.Clear(); ScrollAsms.Clear(); DoorAsms.Clear(); SetupAsms.Clear(); MainAsms.Clear(); TileSets.Clear(); TileTables.Clear(); TileSheets.Clear(); Palettes.Clear(); AreaMaps.Clear(); PlmTypes.Clear(); EnemyTypes.Clear(); CurrentRom = null; ProjectPath = String.Empty; RomFileName = String.Empty; ProjectFileName = String.Empty; RoomTiles.Clear(); MapTiles.Clear(); BackgroundImage = null; ChangesMade = false; ProjectLoaded = false; ProjectClosed?.Invoke(this, null); }
// Read all tile tables from ROM. private void ReadTileTables(Rom rom) { List <int> addressesPC = new List <int> (); foreach (TileSet t in TileSets) { int address = Tools.LRtoPC(t.SceTablePtr); if (address != 0) // Skip invalid addresses { addressesPC.Add(address); } } Tools.RemoveDuplicates(addressesPC); TileTables.Clear(); TileTables.Add(new TileTable()); TileTables [0].ReadFromROM(rom, TileTable.CreAddressPC); for (int n = 0; n < addressesPC.Count; n++) { TileTables.Add(new TileTable()); TileTables [n + 1].ReadFromROM(rom, addressesPC [n]); } }
internal static void ReadTileData(BinaryReader reader, TileTables tables) { int i = 0; int j = 0; bool nextModTile = false; do { if (!nextModTile) { byte skip = reader.ReadByte(); while (skip == 255) { for (byte k = 0; k < 255; k++) { if (!NextTile(ref i, ref j)) { return; } } skip = reader.ReadByte(); } for (byte k = 0; k < skip; k++) { if (!NextTile(ref i, ref j)) { return; } } } else { nextModTile = false; } ReadModTile(ref i, ref j, tables, reader, ref nextModTile); }while (NextTile(ref i, ref j)); }
internal static void ReadModTile(ref int i, ref int j, TileTables tables, BinaryReader reader, ref bool nextModTile) { byte flags; flags = reader.ReadByte(); Tile tile = Main.tile[i, j]; if ((flags & 1) == 1) { tile.active(true); ushort saveType = reader.ReadUInt16(); tile.type = tables.tiles[saveType]; if (tables.frameImportant[saveType]) { if ((flags & 2) == 2) { tile.frameX = reader.ReadInt16(); } else { tile.frameX = reader.ReadByte(); } if ((flags & 4) == 4) { tile.frameY = reader.ReadInt16(); } else { tile.frameY = reader.ReadByte(); } } else { tile.frameX = -1; tile.frameY = -1; } if (tile.type == ModContent.GetInstance <ModLoaderMod>().TileType("PendingMysteryTile") && tables.tileNames.ContainsKey(saveType)) { MysteryTileInfo info; if (tables.frameImportant[saveType]) { info = new MysteryTileInfo(tables.tileModNames[saveType], tables.tileNames[saveType], tile.frameX, tile.frameY); } else { info = new MysteryTileInfo(tables.tileModNames[saveType], tables.tileNames[saveType]); } MysteryTilesWorld modWorld = ModContent.GetInstance <MysteryTilesWorld>(); int pendingFrameID = modWorld.pendingInfos.IndexOf(info); if (pendingFrameID < 0) { pendingFrameID = modWorld.pendingInfos.Count; modWorld.pendingInfos.Add(info); } MysteryTileFrame pendingFrame = new MysteryTileFrame(pendingFrameID); tile.frameX = pendingFrame.FrameX; tile.frameY = pendingFrame.FrameY; } if ((flags & 8) == 8) { tile.color(reader.ReadByte()); } WorldGen.tileCounts[tile.type] += j <= Main.worldSurface ? 5 : 1; } if ((flags & 16) == 16) { tile.wall = tables.walls[reader.ReadUInt16()]; if ((flags & 32) == 32) { tile.wallColor(reader.ReadByte()); } } if ((flags & 64) == 64) { byte sameCount = reader.ReadByte(); for (byte k = 0; k < sameCount; k++) { NextTile(ref i, ref j); Main.tile[i, j].CopyFrom(tile); WorldGen.tileCounts[tile.type] += j <= Main.worldSurface ? 5 : 1; } } if ((flags & 128) == 128) { nextModTile = true; } }
internal static void ReadModTile(ref int i, ref int j, TileTables tables, BinaryReader reader, ref bool nextModTile) { byte flags; flags = reader.ReadByte(); Tile tile = Main.tile[i, j]; if ((flags & 1) == 1) { tile.active(true); ushort saveType = reader.ReadUInt16(); tile.type = tables.tiles[saveType]; if (tables.frameImportant[saveType]) { if ((flags & 2) == 2) { tile.frameX = reader.ReadInt16(); } else { tile.frameX = reader.ReadByte(); } if ((flags & 4) == 4) { tile.frameY = reader.ReadInt16(); } else { tile.frameY = reader.ReadByte(); } } else { tile.frameX = -1; tile.frameY = -1; } if ((flags & 8) == 8) { tile.color(reader.ReadByte()); } WorldGen.tileCounts[tile.type] += j <= Main.worldSurface ? 5 : 1; } if ((flags & 16) == 16) { tile.wall = tables.walls[reader.ReadUInt16()]; if ((flags & 32) == 32) { tile.wallColor(reader.ReadByte()); } } if ((flags & 64) == 64) { byte sameCount = reader.ReadByte(); for (byte k = 0; k < sameCount; k++) { NextTile(ref i, ref j); Main.tile[i, j].CopyFrom(tile); WorldGen.tileCounts[tile.type] += j <= Main.worldSurface ? 5 : 1; } } if ((flags & 128) == 128) { nextModTile = true; } }
internal static void ReadTileData(BinaryReader reader, TileTables tables) { int i = 0; int j = 0; bool nextModTile = false; do { if (!nextModTile) { byte skip = reader.ReadByte(); while (skip == 255) { for (byte k = 0; k < 255; k++) { if (!NextTile(ref i, ref j)) { return; } } skip = reader.ReadByte(); } for (byte k = 0; k < skip; k++) { if (!NextTile(ref i, ref j)) { return; } } } else { nextModTile = false; } ReadModTile(ref i, ref j, tables, reader, ref nextModTile); } while (NextTile(ref i, ref j)); }
internal static void ReadModTile(ref int i, ref int j, TileTables tables, BinaryReader reader, ref bool nextModTile) { byte flags; flags = reader.ReadByte(); Tile tile = Main.tile[i, j]; if ((flags & 1) == 1) { tile.active(true); ushort saveType = reader.ReadUInt16(); tile.type = tables.tiles[saveType]; if (tables.frameImportant[saveType]) { if ((flags & 2) == 2) { tile.frameX = reader.ReadInt16(); } else { tile.frameX = reader.ReadByte(); } if ((flags & 4) == 4) { tile.frameY = reader.ReadInt16(); } else { tile.frameY = reader.ReadByte(); } } else { tile.frameX = -1; tile.frameY = -1; } if (tile.type == ModLoader.GetMod("ModLoader").TileType("PendingMysteryTile") && tables.tileNames.ContainsKey(saveType)) { MysteryTileInfo info; if (tables.frameImportant[saveType]) { info = new MysteryTileInfo(tables.tileModNames[saveType], tables.tileNames[saveType], tile.frameX, tile.frameY); } else { info = new MysteryTileInfo(tables.tileModNames[saveType], tables.tileNames[saveType]); } MysteryTilesWorld modWorld = (MysteryTilesWorld)ModLoader.GetMod("ModLoader").GetModWorld("MysteryTilesWorld"); int pendingFrameID = modWorld.pendingInfos.IndexOf(info); if (pendingFrameID < 0) { pendingFrameID = modWorld.pendingInfos.Count; modWorld.pendingInfos.Add(info); } MysteryTileFrame pendingFrame = new MysteryTileFrame(pendingFrameID); tile.frameX = pendingFrame.FrameX; tile.frameY = pendingFrame.FrameY; } if ((flags & 8) == 8) { tile.color(reader.ReadByte()); } WorldGen.tileCounts[tile.type] += j <= Main.worldSurface ? 5 : 1; } if ((flags & 16) == 16) { tile.wall = tables.walls[reader.ReadUInt16()]; if ((flags & 32) == 32) { tile.wallColor(reader.ReadByte()); } } if ((flags & 64) == 64) { byte sameCount = reader.ReadByte(); for (byte k = 0; k < sameCount; k++) { NextTile(ref i, ref j); Main.tile[i, j].CopyFrom(tile); WorldGen.tileCounts[tile.type] += j <= Main.worldSurface ? 5 : 1; } } if ((flags & 128) == 128) { nextModTile = true; } }
internal static void ReadModTile(ref int i, ref int j, TileTables tables, BinaryReader reader, ref bool nextModTile) { byte flags; flags = reader.ReadByte(); Tile tile = Main.tile[i, j]; if ((flags & 1) == 1) { tile.active(true); ushort saveType = reader.ReadUInt16(); tile.type = tables.tiles[saveType]; if (tables.frameImportant[saveType]) { if ((flags & 2) == 2) { tile.frameX = reader.ReadInt16(); } else { tile.frameX = reader.ReadByte(); } if ((flags & 4) == 4) { tile.frameY = reader.ReadInt16(); } else { tile.frameY = reader.ReadByte(); } } else { tile.frameX = -1; tile.frameY = -1; } if ((flags & 8) == 8) { tile.color(reader.ReadByte()); } WorldGen.tileCounts[tile.type] += j <= Main.worldSurface ? 5 : 1; } if ((flags & 16) == 16) { tile.wall = tables.walls[reader.ReadUInt16()]; if ((flags & 32) == 32) { tile.wallColor(reader.ReadByte()); } } if ((flags & 64) == 64) { byte sameCount = reader.ReadByte(); for (byte k = 0; k < sameCount; k++) { NextTile(ref i, ref j); Main.tile[i, j].CopyFrom(tile); WorldGen.tileCounts[tile.type] += j <= Main.worldSurface ? 5 : 1; } } if ((flags & 128) == 128) { nextModTile = true; } }
//======================================================================================== // Object management - tools. private void DeleteData(Data data) { if (data is IReferenceable refdata) { refdata.DetachAllReferences(); } switch (data) { case Room d: Rooms.Remove(d); break; case DoorSet d: DoorSets.Remove(d); break; case Door d: Doors.Remove(d); break; case ScrollSet d: ScrollSets.Remove(d); break; case PlmSet d: PlmSets.Remove(d); break; case ScrollPlmData d: ScrollPlmDatas.Remove(d); break; case Background d: Backgrounds.Remove(d); break; case Fx d: Fxs.Remove(d); break; case SaveStation d: SaveStations.Remove(d); break; case LevelData d: LevelDatas.Remove(d); break; case EnemySet d: EnemySets.Remove(d); break; case EnemyGfx d: EnemyGfxs.Remove(d); break; case ScrollAsm d: ScrollAsms.Remove(d); break; case Asm d: DoorAsms.Remove(d); SetupAsms.Remove(d); MainAsms.Remove(d); break; case TileSet d: TileSets.Remove(d); break; case TileTable d: TileTables.Remove(d); break; case TileSheet d: TileSheets.Remove(d); break; case Palette d: Palettes.Remove(d); break; case AreaMap d: AreaMaps.Remove(d); break; default: break; } ChangesMade = true; }