public void WriteToGameFile(Stream file, GameFileLayout layout) { byte colourCount = 0; for (ushort i = 0; i < colours.Length; i++) { if (colours[i] != null) { colours[i].WriteToGameFile(file, layout, i); colourCount++; } } file.Position = layout.ColourCountIndex; file.WriteByte(colourCount); file.Position = layout.BitmapStartIndex; WriteBitmapEmptyFill(file, layout); for (ushort y = 0; y < BitmapHeight; y++) { for (ushort x = 0; x < BitmapWidth; x += 2) { file.WriteByte((byte)((bitmapData[x + 1, y] << 4) + (bitmapData[x, y] & 0xF))); } } }
private void WriteBitmapEmptyFill(Stream file, GameFileLayout layout) { for (uint i = 0; i < layout.BitmapEmptyFillSize; i++) { file.WriteByte(0xFF); } }
static void WriteToGameFile(string directory, CarTexture texture, OutputType outputType) { GameFileLayout layout = outputType == OutputType.GT2 ? (GameFileLayout) new CDPFileLayout() : new TEXFileLayout(); using (var file = new FileStream(CreateFilename(Path.GetFileNameWithoutExtension(directory), outputType), FileMode.Create, FileAccess.Write)) { file.Write(layout.HeaderData); texture.WriteToGameFile(file, layout); } }
public void LoadFromGameFile(Stream file, GameFileLayout layout) { file.Position = layout.ColourCountIndex; ushort colourCount = file.ReadUShort(); for (ushort i = 0; i < colourCount; i++) { var colour = new CarColour(); colour.LoadFromGameFile(file, layout, i); colours[i] = colour; } file.Position = layout.BitmapStartIndex + layout.BitmapEmptyFillSize; for (ushort y = 0; y < BitmapHeight; y++) { for (ushort x = 0; x < BitmapWidth; x += 2) { byte pixelPair = (byte)file.ReadByte(); bitmapData[x, y] = (byte)(pixelPair & 0xF); bitmapData[x + 1, y] = (byte)(pixelPair >> 4); } } }