internal TileConfig(Reader reader) { Collision = reader.ReadBytes(10); // Collision, I think Config = reader.ReadBytes(5); // ??? }
public Level(Reader reader) { Title = reader.ReadRSDKString(); Console.WriteLine(Title); byte[] buffer = new byte[5]; reader.Read(displayBytes, 0, 5); //Waste 5 bytes, I don't care about them right now. //The first 4 bytes are loaded into StageSystem.ActiveTileLayers. 5th byte is tLayerMidPoint. //If you want to know the values then look at the values for "DisplayBytes" reader.Read(buffer, 0, 2); //Read Map Width width = 0; height = 0; // Map width in 128 pixel units // In Sonic 1 it's two bytes long, little-endian width = buffer[0] + (buffer[1] << 8); reader.Read(buffer, 0, 2); //Read Height height = buffer[0] + (buffer[1] << 8); Console.WriteLine("Width " + width + " Height " + height); MapLayout = new ushort[height][]; for (int i = 0; i < height; i++) { MapLayout[i] = new ushort[width]; } for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { //128x128 Block number is 16-bit //Little-Endian in RSDKv4 reader.Read(buffer, 0, 2); //Read size MapLayout[y][x] = (ushort)(buffer[0] + (buffer[1] << 8)); } } // Read object data //NOTE: Object data reading is wrong somehow, int ObjCount = 0; // 4 bytes, little-endian, unsigned ObjCount = reader.ReadByte(); ObjCount |= reader.ReadByte() << 8; ObjCount |= reader.ReadByte() << 16; ObjCount |= reader.ReadByte() << 24; Console.WriteLine(ObjCount); ObjCount = ObjCount - 1; int obj_type = 0; int obj_subtype = 0; int obj_xPos = 0; int obj_yPos = 0; try { for (int n = 0; n < ObjCount; n++) { // Object type, 1 byte, unsigned obj_type = reader.ReadByte(); //obj_type|= reader.ReadByte() << 8; // Object subtype, 1 byte, unsigned obj_subtype = reader.ReadByte(); //obj_subtype|= reader.ReadByte() << 8; //Hm? What are these for? reader.ReadBytes(2); // X Position, 4 bytes, little-endian, unsigned obj_xPos = reader.ReadByte(); obj_xPos |= reader.ReadByte() << 8; obj_xPos |= reader.ReadByte() << 16; obj_xPos |= reader.ReadByte() << 24; // Y Position, 4 bytes, little-endian, unsigned obj_yPos = reader.ReadByte(); obj_yPos |= reader.ReadByte() << 8; obj_yPos |= reader.ReadByte() << 16; obj_yPos |= reader.ReadByte() << 24; // Add object objects.Add(new Object(obj_type, obj_subtype, obj_xPos, obj_yPos)); //Console.WriteLine(reader.BaseStream.Position + " Object "+ n + " Obj Values: Type: " + obj_type + " Subtype: " + obj_subtype + " Xpos = " + obj_xPos + " Ypos = " + obj_yPos); } Console.WriteLine("Current Reader Position = " + reader.BaseStream.Position + " Current File Length = " + reader.BaseStream.Length); } catch (Exception ex) { if (reader.IsEof) { throw ex; } } reader.Close(); }