- fixed heisenburg-endianness in map loader
- THERES A BUG in the mix loading; I need another 4 bytes padding to load temperat.mix and snow.mix (not interior.mix, though)
- ShpViewer can now load and view map files
- Copy TEMPERAT, SNOW, INFERIOR (sic) mixes into $(SolutionDir) for this to work
- Left-click to reload tile-ID file, middle-click scrolls
- the tile-id file has some collisions between tile-sets, be careful about ordering if you change anything
git-svn-id: svn://svn.ijw.co.nz/svn/OpenRa@1081 993157c7-ee19-0410-b2c4-bb4e9862e678
107 lines
2.7 KiB
C#
107 lines
2.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
using System.IO;
|
|
|
|
namespace OpenRa.FileFormats
|
|
{
|
|
public static class Format80
|
|
{
|
|
static byte ReadByte( MemoryStream input )
|
|
{
|
|
int inp = input.ReadByte();
|
|
if( inp == -1 )
|
|
throw new InvalidDataException();
|
|
|
|
return (byte)inp;
|
|
}
|
|
|
|
static int ReadWord( MemoryStream input )
|
|
{
|
|
int inp = ReadByte( input );
|
|
return inp + ( ReadByte( input ) << 8 );
|
|
}
|
|
|
|
static void ReplicatePrevious( byte[] dest, int destIndex, int srcIndex, int count )
|
|
{
|
|
if( srcIndex >= destIndex )
|
|
throw new NotImplementedException( string.Format( "srcIndex >= destIndex {0} {1}", srcIndex, destIndex ) );
|
|
|
|
if( destIndex - srcIndex == 1 )
|
|
{
|
|
for( int i = 0 ; i < count ; i++ )
|
|
dest[ destIndex + i ] = dest[ destIndex - 1 ];
|
|
}
|
|
else
|
|
{
|
|
for( int i = 0 ; i < count ; i++ )
|
|
dest[ destIndex + i ] = dest[ srcIndex + i ];
|
|
}
|
|
}
|
|
|
|
public static int DecodeInto( MemoryStream input, byte[] dest )
|
|
{
|
|
int destIndex = 0;
|
|
while( true )
|
|
{
|
|
byte i = ReadByte( input );
|
|
if( ( i & 0x80 ) == 0 )
|
|
{
|
|
// case 2
|
|
byte secondByte = ReadByte( input );
|
|
int count = ( ( i & 0x70 ) >> 4 ) + 3;
|
|
int rpos = ( ( i & 0xf ) << 8 ) + secondByte;
|
|
|
|
ReplicatePrevious( dest, destIndex, destIndex - rpos, count );
|
|
destIndex += count;
|
|
}
|
|
else if( ( i & 0x40 ) == 0 )
|
|
{
|
|
// case 1
|
|
int count = i & 0x3F;
|
|
if( count == 0 )
|
|
return destIndex;
|
|
|
|
input.Read( dest, destIndex, count );
|
|
destIndex += count;
|
|
}
|
|
else
|
|
{
|
|
int count3 = i & 0x3F;
|
|
if( count3 == 0x3E )
|
|
{
|
|
// case 4
|
|
int count = ReadWord( input );
|
|
byte color = ReadByte( input );
|
|
|
|
for( int end = destIndex + count ; destIndex < end ; destIndex++ )
|
|
dest[ destIndex ] = color;
|
|
}
|
|
else if( count3 == 0x3F )
|
|
{
|
|
// case 5
|
|
int count = ReadWord( input );
|
|
int srcIndex = ReadWord( input );
|
|
if( srcIndex >= destIndex )
|
|
throw new NotImplementedException( string.Format( "srcIndex >= destIndex {0} {1}", srcIndex, destIndex ) );
|
|
|
|
for( int end = destIndex + count ; destIndex < end ; destIndex++ )
|
|
dest[ destIndex ] = dest[ srcIndex++ ];
|
|
}
|
|
else
|
|
{
|
|
// case 3
|
|
int count = count3 + 3;
|
|
int srcIndex = ReadWord( input );
|
|
if( srcIndex >= destIndex )
|
|
throw new NotImplementedException( string.Format( "srcIndex >= destIndex {0} {1}", srcIndex, destIndex ) );
|
|
|
|
for( int end = destIndex + count ; destIndex < end ; destIndex++ )
|
|
dest[ destIndex ] = dest[ srcIndex++ ];
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|