예제 #1
0
        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)));
                }
            }
        }
예제 #2
0
 private void WriteBitmapEmptyFill(Stream file, GameFileLayout layout)
 {
     for (uint i = 0; i < layout.BitmapEmptyFillSize; i++)
     {
         file.WriteByte(0xFF);
     }
 }
예제 #3
0
        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);
            }
        }
예제 #4
0
        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);
                }
            }
        }