- public class ZONHandler
- {
- public enum BlockType
- {
- Block0,
- SpawnPoints,
- Textures,
- Tiles,
- Economy
- }
- public static string RootName(int type)
- {
- switch (type)
- {
- case 0:
- return "Block0";
- case 1:
- return "SpawnPoints";
- case 2:
- return "Textures";
- case 3:
- return "Tiles";
- case 4:
- return "Economy";
- default:
- return "Unknown";
- }
- }
- public enum RotationType
- {
- Normal = 1,
- LeftRight = 2,
- TopBottom = 3,
- LeftRightTopBottom = 4,
- Rotate90Clockwise = 5,
- Rotate90CounterClockwise = 6
- }
- public struct Block
- {
- public Int32 Type { get; set; }
- public Int32 Offset { get; set; }
- }
- public class Block0
- {
- public struct ZonePart
- {
- public byte UseMap { get; set; }
- public float PositionX { get; set; }
- public float PositionY { get; set; }
- };
- public Int32 ZoneType { get; set; }
- public Int32 ZoneWidth { get; set; }
- public Int32 ZoneHeight { get; set; }
- public Int32 GridCount { get; set; }
- public float GridSize { get; set; }
- public Int32 XCount { get; set; }
- public Int32 YCount { get; set; }
- public ZonePart[,] ZoneParts { get; set; }
- }
- public class SpawnPoint
- {
- public float PositionX { get; set; }
- public float PositionZ { get; set; }
- public float PositionY { get; set; }
- public string Name { get; set; }
- }
- public class Texture
- {
- public string Path { get; set; }
- }
- public class Tile
- {
- public Int32 BaseID1 { get; set; }
- public Int32 BaseID2 { get; set; }
- public Int32 Offset1 { get; set; }
- public Int32 Offset2 { get; set; }
- public Int32 ID1
- {
- get { return BaseID1 + Offset1; }
- }
- public Int32 ID2
- {
- get { return BaseID2 + Offset2; }
- }
- public Int32 IsBlending { get; set; }
- public RotationType Rotation { get; set; }
- public Int32 TileType { get; set; }
- }
- public class Economy
- {
- public string AreaName { get; set; }
- public Int32 IsUnderground { get; set; }
- public string ButtonBGM { get; set; }
- public string ButtonBack { get; set; }
- public Int32 CheckCount { get; set; }
- public Int32 StandardPopulation { get; set; }
- public Int32 StandardGrowthRate { get; set; }
- public Int32 MetalConsumption { get; set; }
- public Int32 StoneConsumption { get; set; }
- public Int32 WoodConsumption { get; set; }
- public Int32 LeatherConsumption { get; set; }
- public Int32 ClothConsumption { get; set; }
- public Int32 AlchemyConsumption { get; set; }
- public Int32 ChemicalConsumption { get; set; }
- public Int32 IndustrialConsumption { get; set; }
- public Int32 MedicineConsumption { get; set; }
- public Int32 FoodConsumption { get; set; }
- }
- public string FilePath { get; set; }
- public Int32 blockCount { get; set; }
- public Block[] Blocks;
- public Block0 ZoneInfo { get; set; }
- public List<SpawnPoint> SpawnPoints { get; set; }
- public List<Texture> Textures { get; set; }
- public List<Tile> Tiles { get; set; }
- public Economy EconomyInfo { get; set; }
- public void LoadZon(string filePath)
- {
- BinaryReader br = new BinaryReader(File.Open(filePath, FileMode.Open));
- blockCount = br.ReadInt32();
- Blocks = new Block[blockCount];
- for (int i = 0; i != blockCount; i++)
- {
- Blocks[i].Type = br.ReadInt32();
- Blocks[i].Offset = br.ReadInt32();
- }
- for (int i = 0; i != blockCount; i++)
- {
- br.BaseStream.Seek(Blocks[i].Offset, 0);
- switch (Blocks[i].Type)
- {
- case 0:
- {
- ZoneInfo = new Block0()
- {
- ZoneType = br.ReadInt32(),
- ZoneWidth = br.ReadInt32(),
- ZoneHeight = br.ReadInt32(),
- GridCount = br.ReadInt32(),
- GridSize = br.ReadSingle(),
- XCount = br.ReadInt32(),
- YCount = br.ReadInt32()
- };
- ZoneInfo.ZoneParts = new Block0.ZonePart[ZoneInfo.ZoneWidth, ZoneInfo.ZoneHeight];
- for (int j = 0; j < ZoneInfo.ZoneWidth; j++)
- {
- for (int k = 0; k < ZoneInfo.ZoneHeight; k++)
- {
- ZoneInfo.ZoneParts[j, k] = new Block0.ZonePart()
- {
- UseMap = br.ReadByte(),
- PositionX = br.ReadSingle(),
- PositionY = br.ReadSingle()
- };
- }
- }
- }
- break;
- case 1:
- {
- int spawnPointCount = br.ReadInt32();
- SpawnPoints = new List<SpawnPoint>(spawnPointCount);
- for (int j = 0; j < spawnPointCount; j++)
- {
- SpawnPoints.Add(new SpawnPoint()
- {
- PositionX = ((br.ReadSingle() + 520000.00f) / 100.00f),
- PositionZ = br.ReadSingle() / 100.0f,
- PositionY = 5200 + (br.ReadSingle() / 100),
- Name = RoseFile.ReadBString(ref br)
- });
- }
- }
- break;
- case 2:
- {
- int textureCount = br.ReadInt32();
- Textures = new List<Texture>(textureCount);
- for (int j = 0; j < textureCount; j++)
- {
- Textures.Add(new Texture()
- {
- Path = RoseFile.ReadBString(ref br)
- });
- }
- }
- break;
- case 3:
- {
- int tileCount = br.ReadInt32();
- Tiles = new List<Tile>(tileCount);
- for (int j = 0; j < tileCount; j++)
- {
- Tiles.Add(new Tile()
- {
- BaseID1 = br.ReadInt32(),
- BaseID2 = br.ReadInt32(),
- Offset1 = br.ReadInt32(),
- Offset2 = br.ReadInt32(),
- IsBlending = br.ReadInt32(),
- Rotation = (RotationType)br.ReadInt32(),
- TileType = br.ReadInt32()
- });
- }
- }
- break;
- case 4:
- {
- EconomyInfo = new Economy()
- {
- AreaName = RoseFile.ReadBString(ref br),
- IsUnderground = br.ReadInt32(),
- ButtonBGM = RoseFile.ReadBString(ref br),
- ButtonBack = RoseFile.ReadBString(ref br),
- CheckCount = br.ReadInt32(),
- StandardPopulation = br.ReadInt32(),
- StandardGrowthRate = br.ReadInt32(),
- MetalConsumption = br.ReadInt32(),
- StoneConsumption = br.ReadInt32(),
- WoodConsumption = br.ReadInt32(),
- LeatherConsumption = br.ReadInt32(),
- ClothConsumption = br.ReadInt32(),
- AlchemyConsumption = br.ReadInt32(),
- ChemicalConsumption = br.ReadInt32(),
- IndustrialConsumption = br.ReadInt32(),
- MedicineConsumption = br.ReadInt32(),
- FoodConsumption = br.ReadInt32()
- };
- }
- break;
- }
- }
- br.Close();
- }
- }
- public class RoseFile
- {
- public static string ReadBString(ref BinaryReader br)
- {
- int strlen = br.ReadByte();
- if ((strlen > 128))
- {
- strlen = strlen | (br.ReadByte() << 7);
- }
- return System.Text.Encoding.UTF8.GetString(br.ReadBytes(strlen));
- }
- }
.ZON Handler.
.HIM Handler
- public class HIMHandler
- {
- public Int32 WIDTH { get; set; }
- public Int32 HEIGHT { get; set; }
- public Int32 gridCount { get; set; }
- public float gridSize { get; set; }
- public float[,] heightData { get; set; }
- public void LoadHIM(string filePath)
- {
- BinaryReader br = new BinaryReader(File.Open(filePath, FileMode.Open));
- HEIGHT = br.ReadInt32();
- WIDTH = br.ReadInt32();
- gridCount = br.ReadInt32();
- gridSize = br.ReadSingle();
- heightData = new float[WIDTH, HEIGHT];
- for (int i = 0; i < WIDTH; i++)
- {
- for (int y = 0; y < HEIGHT; y++)
- {
- float height = (br.ReadSingle() / 100);
- heightData[WIDTH - 1 - i, HEIGHT - 1 - y] = height;
- }
- }
- br.Close();
- }
- }
.TIL Handler
- public class TILHandler
- {
- public Int32 width { get; set; }
- public Int32 height { get; set; }
- public tilData[,] TILData { get; set; }
- public struct tilData
- {
- public byte BrushId { get; set; }
- public byte tileIndex { get; set; }
- public byte tileSetNumber { get; set; }
- public byte tileID { get; set; }
- }
- public void LoadTIL(string filePath)
- {
- BinaryReader br = new BinaryReader(File.Open(filePath, FileMode.Open));
- width = br.ReadInt32();
- height = br.ReadInt32();
- TILData = new tilData[width, height];
- for (int i = 0; i < height; i++)
- {
- for (int y = 0; y < width; y++)
- {
- byte BrushId = br.ReadByte();
- TILData[width - 1 - y, height - 1 - i].BrushId = BrushId;
- byte tileIndex = br.ReadByte();
- TILData[width - 1 - y, height - 1 - i].tileIndex = tileIndex;
- byte tileSetNumber = br.ReadByte();
- TILData[width - 1 - y, height - 1 - i].tileSetNumber = tileSetNumber;
- byte tileID = br.ReadByte();
- TILData[width - 1 - y, height - 1 - i].tileID = tileID;
- }
- }
- br.Close();
- }
- }
If you find any problems with this code, just let me know. As of now I am only certain that the .ZON and .HIM work properly. Although the .HIM doesn't read the max heights or the quad data, it works for rendering the scene. If anyone wants to pick up on this project, please feel free to! Also if you need any help understanding the handlers, just give me a PM!