public void Read(uint version, IoBuffer io) { uint spriteCount = 0; if (version < 20003) { spriteCount = io.ReadUInt16(); Direction = io.ReadByte(); Zoom = io.ReadByte(); } else { Direction = io.ReadUInt32(); Zoom = io.ReadUInt32(); spriteCount = io.ReadUInt32(); } this.Sprites = new DGRPSprite[spriteCount]; for (var i = 0; i < spriteCount; i++) { var sprite = new DGRPSprite(Parent); sprite.Read(version, io); this.Sprites[i] = sprite; } }
public DGRPRCParams(IoBuffer io, int version) { Rotations = new bool[4]; for (int i = 0; i < 4; i++) { Rotations[i] = io.ReadByte() > 0; } DoorFix = io.ReadByte() > 0; CounterFix = io.ReadByte() > 0; StartDGRP = io.ReadInt32(); EndDGRP = io.ReadInt32(); BlenderTweak = io.ReadByte() > 0; Simplify = io.ReadByte() > 0; }
public static void ReadNFloats(IoBuffer io, int floats, Action <int, float> output) { float lastValue = 0; for (int i = 0; i < floats; i++) { var code = io.ReadByte(); switch (code) { case 0xFF: lastValue = io.ReadFloat(); break; case 0xFE: //repeat count var repeats = io.ReadUInt16(); for (int j = 0; j < repeats; j++) { output(i++, lastValue); } break; default: lastValue += Delta[code]; break; } output(i, lastValue); } }
public OBJTEntry(IoBuffer io, int version) { //16 bytes of data GUID = io.ReadUInt32(); if (GUID == 0) { return; } Unknown1a = io.ReadUInt16(); Unknown1b = io.ReadUInt16(); Unknown2a = io.ReadUInt16(); Unknown2b = io.ReadUInt16(); //increases by one each time, one based, essentially an ID for this loaded type. Mostly matches index in array, but I guess it can possibly be different. TypeID = io.ReadUInt16(); OBJDType = (OBJDType)io.ReadUInt16(); //then the name, null terminated Name = io.ReadNullTerminatedString(); if (Name.Length % 2 == 0) { io.ReadByte(); //pad to short width } if (version > 2) { io.ReadInt32(); //not sure what this is } }
public CPFFile(byte[] file) { if (Encoding.UTF8.GetChars(file)[0] == '<') { ReadAsXML(file); return; } var stream = new MemoryStream(file); var io = new IoBuffer(stream); io.ByteOrder = ByteOrder.LITTLE_ENDIAN; var typeID = io.ReadUInt32(); var version = io.ReadUInt16(); var numberOfItems = io.ReadUInt32(); for (var i = 0; i < numberOfItems; i++) { var dataType = (DataType)io.ReadUInt32(); var fieldNameLength = io.ReadInt32(); var fieldName = io.ReadCString(fieldNameLength); if (fieldName[0] != '"') { switch (dataType) { case DataType.UInt: var data = new CPFEntry(fieldName, dataType, io.ReadUInt32()); entries.Add(fieldName, data); break; case DataType.Int2: var data5 = new CPFEntry(fieldName, dataType, io.ReadInt32()); entries.Add(fieldName, data5); break; case DataType.String: var dataLength = io.ReadInt32(); var data2 = new CPFEntry(fieldName, dataType, io.ReadCString(dataLength)); entries.Add(fieldName, data2); break; case DataType.Float: var data3 = new CPFEntry(fieldName, dataType, io.ReadFloat()); entries.Add(fieldName, data3); break; case DataType.Boolean: var boole = false; if (io.ReadByte() == (byte)1) { boole = true; } var data4 = new CPFEntry(fieldName, dataType, boole); entries.Add(fieldName, data4); break; } } } }
public WALmEntry(IoBuffer io, int id) { Name = io.ReadNullTerminatedString(); if (Name.Length % 2 == 0) { io.ReadByte(); //pad to short width } Unknown = io.ReadInt32(); //index in iff? ID = io.ReadByte(); Unknown2 = io.ReadBytes(5 + id * 2); //id 0 seems to be an older format //unknown2 is 01 00 00 00 00 00 //id 1 adds more fields //unknown2 is 01 01 00 00 00 00 00 00 //related to number of walls or floors in the file? }
/// <summary> /// Reads a bone from a IOBuffer. /// </summary> /// <param name="reader">An IOBuffer instance used to read from a stream holding a skeleton.</param> /// <returns>A Bone instance.</returns> private Bone ReadBone(IoBuffer reader, bool bcf) { var bone = new Bone(); if (!bcf) { bone.Unknown = reader.ReadInt32(); } bone.Name = reader.ReadPascalString(); bone.ParentName = reader.ReadPascalString(); bone.HasProps = reader.ReadByte(); if (bcf && bone.Name == "") { return(null); } if (bone.HasProps != 0) { var propertyCount = reader.ReadInt32(); var property = new PropertyListItem(); for (var i = 0; i < propertyCount; i++) { var pairCount = reader.ReadInt32(); for (var x = 0; x < pairCount; x++) { property.KeyPairs.Add(new KeyValuePair <string, string>( reader.ReadPascalString(), reader.ReadPascalString() )); } } bone.Properties.Add(property); } var xx = -reader.ReadFloat(); bone.Translation = new Vector3( xx, reader.ReadFloat(), reader.ReadFloat() ); bone.Rotation = new Quaternion( reader.ReadFloat(), -reader.ReadFloat(), -reader.ReadFloat(), -reader.ReadFloat() ); bone.CanTranslate = reader.ReadInt32(); bone.CanRotate = reader.ReadInt32(); bone.CanBlend = reader.ReadInt32(); bone.WiggleValue = reader.ReadFloat(); bone.WigglePower = reader.ReadFloat(); return(bone); }
string readstr(IoBuffer reader) { var stri = new List <byte>(); byte byt = 1; do { byt = reader.ReadByte(); stri.Add(byt); }while (byt != 0); return(System.Text.Encoding.UTF8.GetString(stri.ToArray())); }
public void Read(IoBuffer io, int version) { Flags = io.ReadInt32(); Unknown = io.ReadInt32(); Label = (version > 1) ? io.ReadVariableLengthPascalString() : io.ReadNullTerminatedString(); Comment = (version > 1) ? io.ReadVariableLengthPascalString() : io.ReadNullTerminatedString(); if (version > 0) { RangeEnabled = io.ReadByte(); LowRange = io.ReadInt16(); HighRange = io.ReadInt16(); } }
public void Read(IoBuffer io, int version, bool odd) { Flags = io.ReadInt32(); Unknown = io.ReadInt32(); Label = (version > 1) ? io.ReadVariableLengthPascalString() : io.ReadNullTerminatedString(); if (version < 2 && ((Label.Length % 2 == 0) ^ odd)) { io.ReadByte(); } Comment = (version > 1) ? io.ReadVariableLengthPascalString() : io.ReadNullTerminatedString(); if (version < 2 && (Comment.Length % 2 == 0)) { io.ReadByte(); } if (version > 0) { RangeEnabled = io.ReadByte(); LowRange = io.ReadInt16(); HighRange = io.ReadInt16(); //io.ReadByte(); } }
public void Read(IoBuffer io, int version) { Type = (TREEBoxType)io.ReadUInt16(); Unknown = io.ReadUInt16(); Width = io.ReadInt16(); Height = io.ReadInt16(); X = io.ReadInt16(); Y = io.ReadInt16(); CommentSize = io.ReadInt16(); TruePointer = io.ReadInt16(); Special = io.ReadInt16(); FalsePointer = io.ReadInt32(); Comment = io.ReadNullTerminatedString(); if (Comment.Length % 2 == 0) { io.ReadByte(); //padding to 2 byte align } if (version > 0) { TrailingZero = io.ReadInt32(); } if (!Enum.IsDefined(typeof(TREEBoxType), Type)) { throw new Exception("Unexpected TREE box type: " + Type.ToString()); } if (Special < -1 || Special > 0) { throw new Exception("Unexpected TREE special: " + Special); } if (Unknown != 0) { throw new Exception("Unexpected Unknown: " + Unknown); } if (TrailingZero != 0) { Console.WriteLine("Unexpected TrailingZero: " + TrailingZero); } }
public OBJTEntry(IoBuffer io, int version) { //16 bytes of data GUID = io.ReadUInt32(); if (GUID == 0) { return; } Unknown1 = io.ReadUInt32(); //7 a lot Unknown2 = io.ReadUInt32(); //131074 a lot Unknown3 = io.ReadUInt16(); //increases by one each time, but sometimes skips one. ID? Unknown4 = io.ReadUInt16(); //mostly 4, sometimes 8, sometimes 7 (dollhouse). catalog category? //then the name, null terminated Name = io.ReadNullTerminatedString(); if (Name.Length % 2 == 0) { io.ReadByte(); //pad to short width } if (version > 2) { io.ReadInt32(); } }
private void Decode(IoBuffer io) { var palette = Parent.ChunkParent.Get<PALT>(Parent.PaletteID); if (palette == null) { palette = DEFAULT_PALT; } var y = 0; var endmarker = false; while (!endmarker) { var command = io.ReadByte(); var count = io.ReadByte(); switch (command) { /** Start marker **/ case 0x00: case 0x10: break; /** Fill row with pixel data **/ case 0x04: var bytes = count - 2; var x = 0; while (bytes > 0) { var pxCommand = io.ReadByte(); var pxCount = io.ReadByte(); bytes -= 2; switch (pxCommand) { /** Next {n} pixels are transparent **/ case 0x01: x += pxCount; break; /** Next {n} pixels are the same palette color **/ case 0x02: var index = io.ReadByte(); var padding = io.ReadByte(); bytes -= 2; var color = palette.Colors[index]; for (var j = 0; j < pxCount; j++) { this.SetPixel(x, y, color); x++; } break; /** Next {n} pixels are specific palette colours **/ case 0x03: for (var j = 0; j < pxCount; j++) { var index2 = io.ReadByte(); var color2 = palette.Colors[index2]; this.SetPixel(x, y, color2); x++; } bytes -= pxCount; if (pxCount % 2 != 0) { //Padding io.ReadByte(); bytes--; } break; } } y++; break; /** End marker **/ case 0x05: endmarker = true; break; /** Leave next rows transparent **/ case 0x09: y += count; continue; } } }
public LotDescription(byte[] data, Neighborhood nehood) { var stream = new MemoryStream(data); var io = new IoBuffer(stream); io.ByteOrder = ByteOrder.LITTLE_ENDIAN; var version1 = io.ReadUInt16(); //13, 14=OFB, 18=AL var version2 = io.ReadUInt16(); // 6, 7, 8=FT, 11=AL var lotWidth = io.ReadUInt32(); var lotHeight = io.ReadUInt32(); var lotType = io.ReadByte(); //0=Residential,1=Community,2=Dorm,3=GreekHouse,4=SecretSociety,5=Hotel,6=HiddenVacationLot,7=HiddenHobbyLot,8=ApartmentBase,9=ApartmentSublot,10=HiddenWitchesLot var roadBitfield = io.ReadByte(); var rotation = io.ReadByte(); //0=Left, 1=Top, 2=Right, 3=Bottom var flags = io.ReadUInt32(); var lotNameLength = io.ReadInt32(); name = io.ReadCString(lotNameLength); var lotDescriptionLength = io.ReadInt32(); var lotDescription = io.ReadCString(lotDescriptionLength); var dunnoCount = io.ReadUInt32(); for (var i = 0; i < dunnoCount; i++) { io.Skip(4); } if (version2 >= 7) { var unknownFloat = io.ReadFloat(); } if (version2 >= 8) { var unknownInt = io.ReadUInt32(); } if (version2 == 11) { var apartmentCount = io.ReadByte(); var apartmentRentalPriceHigh = io.ReadUInt32(); var apartmentRentalPriceLow = io.ReadUInt32(); var lotClass = io.ReadUInt32(); var overrideLotClass = io.ReadByte(); } var lotY = io.ReadUInt32(); var lotX = io.ReadUInt32(); var lotZ = io.ReadFloat(); position = new Vector3((float)lotY * World.neighborhoodTerrainSize, lotZ, (float)lotX * World.neighborhoodTerrainSize); lotNumber = io.ReadUInt32(); var lotOrientation = io.ReadByte(); //0=Below road, 1=Left of road, 2=Above road, 3=Right of road var textureLength = io.ReadInt32(); var textureName = io.ReadCString(textureLength); var uselessfkinByte = io.ReadByte(); if (version1 >= 14) { var businessOwner = io.ReadUInt32(); //Sim Description Instance Number } if (version2 == 11) { var apartmentBaseInstance = io.ReadUInt32(); //If the current lot is an apartment sublot (Lot Type = 9), this is the associated apartment base; otherwise, zero io.Skip(9); //9 bytes, always zero apparently var itemCount = io.ReadUInt32(); for (var i = 0; i < itemCount; i++) { var apartmentSublotInstance = io.ReadUInt32(); var occupyingFamily = io.ReadUInt32(); //Family Information Instance Number io.Skip(4); //unknown dword var roommateSim = io.ReadUInt32(); //Roommate sim description instance number } itemCount = io.ReadUInt32(); for (var i = 0; i < itemCount; i++) { io.Skip(4); //unknown dword } } InitializeLot(nehood); }
private void Decode(IoBuffer io) { var y = 0; var endmarker = false; var hasPixels = (this.Flags & 0x01) == 0x01; var hasZBuffer = (this.Flags & 0x02) == 0x02; var hasAlpha = (this.Flags & 0x04) == 0x04; var numPixels = this.Width * this.Height; if (hasPixels) { this.PixelData = new Color[numPixels]; } if (hasZBuffer) { this.ZBufferData = new byte[numPixels]; } if (hasAlpha) { this.AlphaData = new byte[numPixels]; } var palette = Parent.ChunkParent.Get <PALT>(this.PaletteID); var transparentPixel = palette.Colors[TransparentColorIndex]; while (!endmarker) { var marker = io.ReadUInt16(); var command = marker >> 13; var count = marker & 0x1FFF; switch (command) { /** Fill with pixel data **/ case 0x00: var bytes = count; bytes -= 2; var x = 0; while (bytes > 0) { var pxMarker = io.ReadUInt16(); var pxCommand = pxMarker >> 13; var pxCount = pxMarker & 0x1FFF; bytes -= 2; switch (pxCommand) { case 0x01: case 0x02: var pxWithAlpha = pxCommand == 0x02; for (var col = 0; col < pxCount; col++) { var zValue = io.ReadByte(); var pxValue = io.ReadByte(); bytes -= 2; var pxColor = palette.Colors[pxValue]; if (pxWithAlpha) { pxColor.A = (byte)(io.ReadByte() * 8.2258064516129032258064516129032); bytes--; } else { if (pxColor.PackedValue == transparentPixel.PackedValue) { pxColor.A = 0; } } var offset = (y * Width) + x; this.PixelData[offset] = pxColor; this.ZBufferData[offset] = zValue; x++; } if (pxWithAlpha) { /** Padding? **/ if ((pxCount * 3) % 2 != 0) { bytes--; io.ReadByte(); } } break; case 0x03: for (var col = 0; col < pxCount; col++) { var offset = (y * Width) + x; this.PixelData[offset] = transparentPixel; this.PixelData[offset].A = 0; if (hasZBuffer) { this.ZBufferData[offset] = 255; } x++; } break; case 0x06: for (var col = 0; col < pxCount; col++) { var pxIndex = io.ReadByte(); bytes--; var offset = (y * Width) + x; var pxColor = palette.Colors[pxIndex]; byte z = 0; if (pxColor.PackedValue == transparentPixel.PackedValue) { pxColor.A = 0; z = 255; } this.PixelData[offset] = pxColor; if (hasZBuffer) { this.ZBufferData[offset] = z; } x++; } if (pxCount % 2 != 0) { bytes--; io.ReadByte(); } break; } } /** If row isnt filled in, the rest is transparent **/ while (x < Width) { var offset = (y * Width) + x; if (hasZBuffer) { this.ZBufferData[offset] = 255; } x++; } break; /** Leave the next count rows in the color channel filled with the transparent color, * in the z-buffer channel filled with 255, and in the alpha channel filled with 0. **/ case 0x04: for (var row = 0; row < count; row++) { for (var col = 0; col < Width; col++) { var offset = ((y + row) * Width) + col; if (hasPixels) { this.PixelData[offset] = transparentPixel; } if (hasAlpha) { this.PixelData[offset].A = 0; } if (hasZBuffer) { ZBufferData[offset] = 255; } } } y += count - 1; break; case 0x05: endmarker = true; break; } y++; } }
/// <summary> /// Decodes this SPR2Frame. /// </summary> /// <param name="io">An IOBuffer instance used to read a SPR2Frame.</param> private void Decode(IoBuffer io) { var y = 0; var endmarker = false; var hasPixels = (this.Flags & 0x01) == 0x01; var hasZBuffer = (this.Flags & 0x02) == 0x02; var hasAlpha = (this.Flags & 0x04) == 0x04; var numPixels = this.Width * this.Height; var ow = Width; var fc = Parent.FloorCopy; if (fc > 0) { numPixels += Height; Width++; } if (hasPixels) { this.PixelData = new Color[numPixels]; this.PalData = new byte[numPixels]; } if (hasZBuffer) { this.ZBufferData = new byte[numPixels]; } var palette = Parent.ChunkParent.Get <PALT>(this.PaletteID); if (palette == null) { palette = new PALT() { Colors = new Color[256] } } ; palette.References++; var transparentPixel = palette.Colors[TransparentColorIndex]; transparentPixel.A = 0; while (!endmarker && io.HasMore) { var marker = io.ReadUInt16(); var command = marker >> 13; var count = marker & 0x1FFF; switch (command) { /** Fill with pixel data **/ case 0x00: var bytes = count; bytes -= 2; var x = 0; while (bytes > 0) { var pxMarker = io.ReadUInt16(); var pxCommand = pxMarker >> 13; var pxCount = pxMarker & 0x1FFF; bytes -= 2; switch (pxCommand) { case 0x01: case 0x02: var pxWithAlpha = pxCommand == 0x02; for (var col = 0; col < pxCount; col++) { var zValue = io.ReadByte(); var pxValue = io.ReadByte(); bytes -= 2; var pxColor = palette.Colors[pxValue]; if (pxWithAlpha) { var alpha = io.ReadByte(); pxColor.A = (byte)(alpha * 8.2258064516129032258064516129032); bytes--; } //this mode draws the transparent colour as solid for some reason. //fixes backdrop theater var offset = (y * Width) + x; this.PixelData[offset] = pxColor; this.PalData[offset] = pxValue; this.ZBufferData[offset] = zValue; x++; } if (pxWithAlpha) { /** Padding? **/ if ((pxCount * 3) % 2 != 0) { bytes--; io.ReadByte(); } } break; case 0x03: for (var col = 0; col < pxCount; col++) { var offset = (y * Width) + x; this.PixelData[offset] = transparentPixel; this.PalData[offset] = (byte)TransparentColorIndex; this.PixelData[offset].A = 0; if (hasZBuffer) { this.ZBufferData[offset] = 255; } x++; } break; case 0x06: for (var col = 0; col < pxCount; col++) { var pxIndex = io.ReadByte(); bytes--; var offset = (y * Width) + x; var pxColor = palette.Colors[pxIndex]; byte z = 0; //not sure if this should happen /*if (pxIndex == TransparentColorIndex) * { * pxColor.A = 0; * z = 255; * }*/ this.PixelData[offset] = pxColor; this.PalData[offset] = pxIndex; if (hasZBuffer) { this.ZBufferData[offset] = z; } x++; } if (pxCount % 2 != 0) { bytes--; io.ReadByte(); } break; } } /** If row isnt filled in, the rest is transparent **/ while (x < ow) { var offset = (y * Width) + x; if (hasZBuffer) { this.ZBufferData[offset] = 255; } x++; } break; /** Leave the next count rows in the color channel filled with the transparent color, * in the z-buffer channel filled with 255, and in the alpha channel filled with 0. **/ case 0x04: for (var row = 0; row < count; row++) { for (var col = 0; col < Width; col++) { var offset = ((y + row) * Width) + col; if (hasPixels) { this.PixelData[offset] = transparentPixel; this.PalData[offset] = (byte)TransparentColorIndex; } if (hasAlpha) { this.PixelData[offset].A = 0; } if (hasZBuffer) { ZBufferData[offset] = 255; } } } y += count - 1; break; case 0x05: endmarker = true; break; } y++; } if (!IffFile.RETAIN_CHUNK_DATA) { PalData = null; } if (Parent.ZAsAlpha) { CopyZToAlpha(); } if (Parent.FloorCopy == 1) { FloorCopy(); } if (Parent.FloorCopy == 2) { FloorCopyWater(); } }
/// <summary> /// Decodes this SPRFrame. /// </summary> /// <param name="io">IOBuffer used to read a SPRFrame.</param> private void Decode(IoBuffer io) { var palette = Parent.ChunkParent.Get <PALT>(Parent.PaletteID); if (palette == null) { palette = DEFAULT_PALT; } var y = 0; var endmarker = false; while (!endmarker) { var command = io.ReadByte(); var count = io.ReadByte(); switch (command) { /** Start marker **/ case 0x00: case 0x10: break; /** Fill row with pixel data **/ case 0x04: var bytes = count - 2; var x = 0; while (bytes > 0) { var pxCommand = io.ReadByte(); var pxCount = io.ReadByte(); bytes -= 2; switch (pxCommand) { /** Next {n} pixels are transparent **/ case 0x01: x += pxCount; break; /** Next {n} pixels are the same palette color **/ case 0x02: var index = io.ReadByte(); var padding = io.ReadByte(); bytes -= 2; var color = palette.Colors[index]; for (var j = 0; j < pxCount; j++) { this.SetPixel(x, y, color); x++; } break; /** Next {n} pixels are specific palette colours **/ case 0x03: for (var j = 0; j < pxCount; j++) { var index2 = io.ReadByte(); var color2 = palette.Colors[index2]; this.SetPixel(x, y, color2); x++; } bytes -= pxCount; if (pxCount % 2 != 0) { //Padding io.ReadByte(); bytes--; } break; } } y++; break; /** End marker **/ case 0x05: endmarker = true; break; /** Leave next rows transparent **/ case 0x09: y += count; continue; } } }
private Bone ReadBone(IoBuffer reader) { var bone = new Bone(); bone.Unknown = reader.ReadInt32(); bone.Name = reader.ReadPascalString(); bone.ParentName = reader.ReadPascalString(); bone.HasProps = reader.ReadByte(); if (bone.HasProps != 0) { var propertyCount = reader.ReadInt32(); var property = new PropertyListItem(); for (var i = 0; i < propertyCount; i++) { var pairCount = reader.ReadInt32(); for (var x = 0; x < pairCount; x++) { property.KeyPairs.Add(new KeyValuePair<string, string>( reader.ReadPascalString(), reader.ReadPascalString() )); } } bone.Properties.Add(property); } var xx = -reader.ReadFloat(); bone.Translation = new Vector3( xx, reader.ReadFloat(), reader.ReadFloat() ); bone.Rotation = new Vector4( reader.ReadFloat(), -reader.ReadFloat(), -reader.ReadFloat(), reader.ReadFloat() ); bone.CanTranslate = reader.ReadInt32(); bone.CanRotate = reader.ReadInt32(); bone.CanBlend = reader.ReadInt32(); bone.WiggleValue = reader.ReadFloat(); bone.WigglePower = reader.ReadFloat(); return bone; }
private void Decode(IoBuffer io) { var y = 0; var endmarker = false; var hasPixels = (this.Flags & 0x01) == 0x01; var hasZBuffer = (this.Flags & 0x02) == 0x02; var hasAlpha = (this.Flags & 0x04) == 0x04; var numPixels = this.Width * this.Height; if (hasPixels) { this.PixelData = new Color[numPixels]; } if (hasZBuffer) { this.ZBufferData = new byte[numPixels]; } if (hasAlpha) { this.AlphaData = new byte[numPixels]; } var palette = Parent.ChunkParent.Get<PALT>(this.PaletteID); var transparentPixel = palette.Colors[TransparentColorIndex]; while (!endmarker) { var marker = io.ReadUInt16(); var command = marker >> 13; var count = marker & 0x1FFF; switch (command) { /** Fill with pixel data **/ case 0x00: var bytes = count; bytes -= 2; var x = 0; while (bytes > 0) { var pxMarker = io.ReadUInt16(); var pxCommand = pxMarker >> 13; var pxCount = pxMarker & 0x1FFF; bytes -= 2; switch (pxCommand) { case 0x01: case 0x02: var pxWithAlpha = pxCommand == 0x02; for (var col = 0; col < pxCount; col++) { var zValue = io.ReadByte(); var pxValue = io.ReadByte(); bytes -= 2; var pxColor = palette.Colors[pxValue]; if (pxWithAlpha) { pxColor.A = io.ReadByte(); bytes--; } else { if (pxColor.PackedValue == transparentPixel.PackedValue) { pxColor.A = 0; } } var offset = (y * Width) + x; this.PixelData[offset] = pxColor; this.ZBufferData[offset] = zValue; x++; } if (pxWithAlpha) { /** Padding? **/ if ((pxCount * 3) % 2 != 0) { bytes--; io.ReadByte(); } } break; case 0x03: for (var col = 0; col < pxCount; col++) { var offset = (y * Width) + x; this.PixelData[offset] = transparentPixel; this.PixelData[offset].A = 0; if (hasZBuffer) { this.ZBufferData[offset] = 255; } x++; } break; case 0x06: for (var col = 0; col < pxCount; col++) { var pxIndex = io.ReadByte(); bytes--; var offset = (y * Width) + x; var pxColor = palette.Colors[pxIndex]; byte z = 0; if (pxColor.PackedValue == transparentPixel.PackedValue) { pxColor.A = 0; z = 255; } this.PixelData[offset] = pxColor; if (hasZBuffer) { this.ZBufferData[offset] = z; } x++; } if (pxCount % 2 != 0) { bytes--; io.ReadByte(); } break; } } /** If row isnt filled in, the rest is transparent **/ while (x < Width) { var offset = (y * Width) + x; if (hasZBuffer) { this.ZBufferData[offset] = 255; } x++; } break; /** Leave the next count rows in the color channel filled with the transparent color, in the z-buffer channel filled with 255, and in the alpha channel filled with 0. **/ case 0x04: for (var row = 0; row < count; row++) { for (var col = 0; col < Width; col++) { var offset = (row * Width) + col; if (hasPixels) { this.PixelData[offset] = transparentPixel; } if (hasAlpha) { this.PixelData[offset].A = 0; } if (hasZBuffer) { ZBufferData[offset] = 255; } } } break; case 0x05: endmarker = true; break; } y++; } }
public Neighbour(IoBuffer io) { Unknown1 = io.ReadInt32(); if (Unknown1 != 1) { return; } Version = io.ReadInt32(); if (Version == 0xA) { //TODO: what version does this truly start? Unknown3 = io.ReadInt32(); if (Unknown3 != 9) { } } Name = io.ReadNullTerminatedString(); if (Name.Length % 2 == 0) { io.ReadByte(); } MysteryZero = io.ReadInt32(); if (MysteryZero != 0) { } PersonMode = io.ReadInt32(); if (PersonMode > 0) { var size = (Version == 0x4) ? 0xa0 : 0x200; PersonData = new short[88]; int pdi = 0; for (int i = 0; i < size; i += 2) { if (pdi >= 88) { io.ReadBytes(size - i); break; } PersonData[pdi++] = io.ReadInt16(); } } NeighbourID = io.ReadInt16(); GUID = io.ReadUInt32(); UnknownNegOne = io.ReadInt32(); if (UnknownNegOne != -1) { } var entries = io.ReadInt32(); Relationships = new Dictionary <int, List <int> >(); for (int i = 0; i < entries; i++) { var keyCount = io.ReadInt32(); if (keyCount != 1) { } var key = io.ReadInt32(); var values = new List <int>(); var valueCount = io.ReadInt32(); for (int j = 0; j < valueCount; j++) { values.Add(io.ReadInt32()); } } }
public IffFieldEncode(IoBuffer io) : base(io) { curByte = io.ReadByte(); odd = !odd; bitPos = 0; }
public NeighborhoodTerrainFile(byte[] data, Neighborhood nehood) { var stream = new MemoryStream(data); var io = new IoBuffer(stream); io.ByteOrder = ByteOrder.LITTLE_ENDIAN; var version = io.ReadUInt32(); io.Skip(2); var treeCount = io.ReadUInt32(); for (var i = 0; i < treeCount; i++) { var treeByte = io.ReadByte(); var treeY = io.ReadFloat(); var treeX = io.ReadFloat(); var treeZ = io.ReadFloat(); var treeBBTopLeftY = io.ReadFloat(); var treeBBTopRightX = io.ReadFloat(); var treeBBBotLeftY = io.ReadFloat(); var treeBBBotRightX = io.ReadFloat(); var treeByte2 = io.ReadByte(); var treeRotation = io.ReadFloat(); var treeGUID = io.ReadUInt32(); NHoodDecorationDescription decoResource = null; if (Environment.hoodDecoByGUID.ContainsKey(treeGUID)) { decoResource = Environment.hoodDecoByGUID[treeGUID]; } if (decoResource != null) { var deco = new NHoodDecoration(); deco.description = decoResource; deco.position = new Vector3(treeY, treeZ, treeX); deco.rotation = treeRotation * -1; decos.Add(deco); } //io.Skip(38); // ToDo: Load Trees } io.Skip(2); var roadCount = io.ReadUInt32(); for (var i = 0; i < roadCount; i++) { io.Skip(124); // ToDo: Load Roads } io.Skip(2); var bridgeCount = io.ReadUInt32(); for (var i = 0; i < bridgeCount; i++) { io.Skip(165); // ToDo: Load Bridges } io.Skip(2); var decorationCount = io.ReadUInt32(); for (var i = 0; i < decorationCount; i++) { io.Skip(1); var yPos = io.ReadFloat(); var xPos = io.ReadFloat(); var zPos = io.ReadFloat(); var BBTopLeftY = io.ReadFloat(); var BBTopRightX = io.ReadFloat(); var BBBotLeftY = io.ReadFloat(); var BBBotRightX = io.ReadFloat(); io.Skip(1); var resourceID = io.ReadUInt32(); var rotation = io.ReadFloat(); NHoodDecorationDescription decoResource = null; if (Environment.hoodDecoByGUID.ContainsKey(resourceID)) { decoResource = Environment.hoodDecoByGUID[resourceID]; } if (decoResource != null) { var deco = new NHoodDecoration(); deco.description = decoResource; deco.position = new Vector3(yPos, zPos, xPos); deco.rotation = rotation * -1; decos.Add(deco); } } io.Dispose(); stream.Dispose(); }
public TTABFieldEncode(IoBuffer io) : base(io) { curByte = io.ReadByte(); bitPos = 0; }
public void Read(uint version, IoBuffer io) { uint spriteCount = 0; if (version < 20003) { spriteCount = io.ReadUInt16(); Direction = io.ReadByte(); Zoom = io.ReadByte(); } else { Direction = io.ReadUInt32(); Zoom = io.ReadUInt32(); spriteCount = io.ReadUInt32(); } this.Sprites = new DGRPSprite[spriteCount]; for (var i = 0; i < spriteCount; i++) { var sprite = new DGRPSprite(Parent); sprite.Read(version, io); this.Sprites[i] = sprite; } }