public Object(Reader reader) { cur_id++; id = cur_id; AttributeType = reader.ReadUInt16(); // Object type, 1 byte, unsigned type = reader.ReadByte(); //Type // Object subtype, 1 byte, unsigned subtype = reader.ReadByte(); //SubType/PropertyValue //a position, made of 8 bytes, 4 for X, 4 for Y position = new Position(reader); //Console.WriteLine("ATTRIBUTE COUNT:" + Pad(AttributeType,16)); string Pad(int b, int length) { return(Convert.ToString(b, 2).PadLeft(length, '0')); } if ((AttributeType & 1) != 0) { if ((AttributeType & 2) == 0) { if ((AttributeType & 4) == 0) { if ((AttributeType & 8) == 0) { if ((AttributeType & 0x10) == 0) { if ((AttributeType & 0x20) == 0) { if ((AttributeType & 0x40) == 0) { if ((AttributeType & 0x80) == 0) { if ((AttributeType & 0x100) == 0) { if ((AttributeType & 0x200) == 0) { if ((AttributeType & 0x400) == 0) { if ((AttributeType & 0x800) == 0) { if ((AttributeType & 0x1000) == 0) { if ((AttributeType & 0x2000) == 0) { if ((AttributeType & 0x4000) != 0) { ReadAttribute(reader, 13); } goto END_LOOP; } ReadAttribute(reader, 12); goto END_LOOP; } ReadAttribute(reader, 11); goto END_LOOP; } ReadAttribute(reader, 10); goto END_LOOP; } ReadAttribute(reader, 9); goto END_LOOP; } ReadAttribute(reader, 8); goto END_LOOP; } ReadAttribute(reader, 7); goto END_LOOP; } ReadAttribute(reader, 6); goto END_LOOP; } ReadAttribute(reader, 5); goto END_LOOP; } ReadAttribute(reader, 4); goto END_LOOP; } ReadAttribute(reader, 3); goto END_LOOP; } ReadAttribute(reader, 2); goto END_LOOP; } ReadAttribute(reader, 1); goto END_LOOP; } ReadAttribute(reader, 0); goto END_LOOP; } END_LOOP: Console.WriteLine(id + " Obj Values: Type: " + type + ", Subtype: " + subtype + ", Xpos = " + xPos + ", Ypos = " + yPos + ", Attribute Type = " + AttributeType + ", Attribute = " + attribute); }
private void ReadAttribute(Reader reader, int ID) { switch (ID) { case 0: attribute = reader.ReadInt32(); break; case 1: attribute = reader.ReadInt32(); break; case 2: attribute = reader.ReadInt32(); break; case 3: attribute = reader.ReadByte(); break; case 4: attribute = reader.ReadByte(); break; case 5: attribute = reader.ReadByte(); break; case 6: attribute = reader.ReadByte(); break; case 7: attribute = reader.ReadInt32(); break; case 8: attribute = reader.ReadByte(); break; case 9: attribute = reader.ReadByte(); break; case 10: attribute = reader.ReadInt32(); break; case 11: attribute = reader.ReadInt32(); break; case 12: attribute = reader.ReadInt32(); break; case 13: attribute = reader.ReadInt32(); break; } }
public FileInfo(Reader reader, List <string> FileList, int cnt) { for (int y = 0; y < 16; y += 4) { md5Hash[y + 3] = reader.ReadByte(); md5Hash[y + 2] = reader.ReadByte(); md5Hash[y + 1] = reader.ReadByte(); md5Hash[y] = reader.ReadByte(); } MD5FileName = ConvertByteArrayToString(md5Hash); var md5 = MD5.Create(); FileName = (cnt + 1) + ".bin"; //Make a base name for (int i = 0; i < FileList.Count; i++) { // RSDKvB Hashes all Strings at Lower Case string fp = FileList[i].ToLower(); bool match = true; for (int z = 0; z < 16; z++) { if (CalculateMD5Hash(fp)[z] != md5Hash[z]) { match = false; break; } } if (match) { FileName = FileList[i]; break; } } DataOffset = reader.ReadUInt32(); uint tmp = reader.ReadUInt32(); Encrypted = (tmp & 0x80000000) != 0; FileSize = (tmp & 0x7FFFFFFF); long tmp2 = reader.BaseStream.Position; reader.BaseStream.Position = DataOffset; Filedata = reader.ReadBytes(FileSize); // Decrypt File if Encrypted if (Encrypted) { Filedata = Decrypt(Filedata); } reader.BaseStream.Position = tmp2; Extension = GetExtensionFromData(); if (FileName == (cnt + 1) + ".bin") { switch (Extension) { case ExtensionTypes.GIF: FileName = "Sprite" + (cnt + 1) + ".gif"; break; case ExtensionTypes.R3D: FileName = "Model" + (cnt + 1) + ".bin"; break; case ExtensionTypes.OGG: FileName = "Music" + (cnt + 1) + ".ogg"; break; case ExtensionTypes.PNG: FileName = "Image" + (cnt + 1) + ".png"; break; case ExtensionTypes.WAV: FileName = "SoundEffect" + (cnt + 1) + ".wav"; break; case ExtensionTypes.UNKNOWN: FileName = "UnknownFileType" + (cnt + 1) + ".bin"; break; } } md5.Dispose(); }
public BGLayer(Reader reader) { byte[] buffer = new byte[2]; width = reader.ReadByte(); reader.ReadByte(); height = reader.ReadByte(); reader.ReadByte(); Behaviour = reader.ReadByte(); reader.Read(buffer, 0, 2); //Read parallax factor RelativeSpeed = (short)(buffer[0] + (buffer[1] << 8)); ConstantSpeed = reader.ReadByte(); byte[] buf = new byte[3]; bool finished = false; int cnt = 0; int loop = 0; LineIndexes = new byte[height * 128]; while (!finished) { buf[0] = reader.ReadByte(); if (buf[0] == 255) { buf[1] = reader.ReadByte(); if (buf[1] == 255) { finished = true; break; } else { buf[2] = (byte)(reader.ReadByte() - 1); loop = 0; while (loop < buf[2] && !reader.IsEof && cnt + 1 < LineIndexes.Length) { LineIndexes[cnt++] = buf[1]; loop++; } } } else { if (!reader.IsEof && cnt + 1 < LineIndexes.Length) { LineIndexes[cnt++] = buf[0]; } } } MapLayout = new ushort[height][]; for (int m = 0; m < height; m++) { MapLayout[m] = 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 RSDKvB reader.Read(buffer, 0, 2); //Read size MapLayout[y][x] = (ushort)(buffer[0] + (buffer[1] << 8)); } } }
public Object(Reader reader) { cur_id++; id = cur_id; //Attribute bits, 2 bytes, unsigned byte t1 = reader.ReadByte(); byte t2 = reader.ReadByte(); AttributeType = (ushort)((t2 << 8) + t1); // Object type, 1 byte, unsigned type = reader.ReadByte(); //Type // Object subtype, 1 byte, unsigned subtype = reader.ReadByte(); //SubType/PropertyValue //a position, made of 8 bytes, 4 for X, 4 for Y position = new Position(reader); for (int i = 0; i < attributes.Length; i++) { attributes[i] = uint.MaxValue; } if ((AttributeType & 0x1) != 0) { attributes[0] = reader.ReadUInt32(); } if ((AttributeType & 0x2) != 0) { attributes[1] = reader.ReadByte(); } if ((AttributeType & 0x4) != 0) { attributes[2] = reader.ReadUInt32(); } if ((AttributeType & 0x8) != 0) { attributes[3] = reader.ReadUInt32(); } if ((AttributeType & 0x10) != 0) { attributes[4] = reader.ReadByte(); } if ((AttributeType & 0x20) != 0) { attributes[5] = reader.ReadByte(); } if ((AttributeType & 0x40) != 0) { attributes[6] = reader.ReadByte(); } if ((AttributeType & 0x80) != 0) { attributes[7] = reader.ReadByte(); } if ((AttributeType & 0x100) != 0) { attributes[8] = reader.ReadUInt32(); } if ((AttributeType & 0x200) != 0) { attributes[9] = reader.ReadByte(); } if ((AttributeType & 0x400) != 0) { attributes[10] = reader.ReadByte(); } if ((AttributeType & 0x800) != 0) { attributes[11] = reader.ReadUInt32(); } if ((AttributeType & 0x1000) != 0) { attributes[12] = reader.ReadUInt32(); } if ((AttributeType & 0x2000) != 0) { attributes[13] = reader.ReadUInt32(); } else if ((AttributeType & 0x4000) != 0) { attributes[14] = reader.ReadUInt32(); } }
public Scene(Reader reader) { Title = reader.ReadRSDKString(); Console.WriteLine(Title); byte[] buffer = new byte[5]; ActiveLayer0 = reader.ReadByte(); ActiveLayer1 = reader.ReadByte(); ActiveLayer2 = reader.ReadByte(); ActiveLayer3 = reader.ReadByte(); Midpoint = reader.ReadByte(); width = 0; height = 0; // Map width in 128 pixel units // In RSDKvB it's two bytes long, little-endian reader.Read(buffer, 0, 2); //Read Map Width width = (ushort)(buffer[0] + (buffer[1] << 8)); reader.Read(buffer, 0, 2); //Read Height height = (ushort)(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 int ObjCount = 0; // 4 bytes, little-endian, unsigned byte t1 = reader.ReadByte(); byte t2 = reader.ReadByte(); ObjCount = (t2 << 8) + t1; Console.WriteLine("Object Count = " + ObjCount); Object.cur_id = 0; int n = 0; try { for (n = 0; n < ObjCount; n++) { // Add object objects.Add(new Object(reader)); } //Console.WriteLine("Current Reader Position = " + reader.BaseStream.Position + " Current File Length = " + reader.BaseStream.Length + " Data Left = " + (reader.BaseStream.Length - reader.BaseStream.Position)); } catch (Exception ex) { if (reader.IsEof) { Console.WriteLine("F**k, not the end! Objects Left: " + (ObjCount - n)); Console.WriteLine("Current Reader Position = " + reader.BaseStream.Position + " Current File Length = " + reader.BaseStream.Length + " Data Left = " + (reader.BaseStream.Length - reader.BaseStream.Position)); reader.Close(); return; } } Console.WriteLine("Current Reader Position = " + reader.BaseStream.Position + " Current File Length = " + reader.BaseStream.Length + " Data Left = " + (reader.BaseStream.Length - reader.BaseStream.Position)); reader.Close(); }
public Scene(Reader reader) { Title = reader.ReadRSDKString(); //Console.WriteLine(Title); byte[] buffer = new byte[5]; ActiveLayer0 = reader.ReadByte(); ActiveLayer1 = reader.ReadByte(); ActiveLayer2 = reader.ReadByte(); ActiveLayer3 = reader.ReadByte(); Midpoint = reader.ReadByte(); width = 0; height = 0; // Map width in 128 pixel units // In RSDKvB it's two bytes long, little-endian reader.Read(buffer, 0, 2); //Read Map Width width = (ushort)(buffer[0] + (buffer[1] << 8)); reader.Read(buffer, 0, 2); //Read Height height = (ushort)(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 RSDKvB reader.Read(buffer, 0, 2); //Read size MapLayout[y][x] = (ushort)(buffer[0] + (buffer[1] << 8)); } } // Read object data int ObjCount = 0; // 2 bytes, little-endian, unsigned byte t1 = reader.ReadByte(); byte t2 = reader.ReadByte(); ObjCount = (t2 << 8) + t1; Object.cur_id = 0; int n = 0; for (n = 0; n < ObjCount; n++) { // Add object objects.Add(new Object(reader)); } reader.Close(); }