本文整理汇总了C#中Map.ValidateHeader方法的典型用法代码示例。如果您正苦于以下问题:C# Map.ValidateHeader方法的具体用法?C# Map.ValidateHeader怎么用?C# Map.ValidateHeader使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Map
的用法示例。
在下文中一共展示了Map.ValidateHeader方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Load
public Map Load( [NotNull] string fileName )
{
if( fileName == null ) throw new ArgumentNullException( "fileName" );
using( FileStream mapStream = File.OpenRead( fileName ) ) {
GZipStream gs = new GZipStream( mapStream, CompressionMode.Decompress, true );
NBTag tag = NBTag.ReadStream( gs );
NBTag mapTag = tag["Map"];
// ReSharper disable UseObjectOrCollectionInitializer
Map map = new Map( null,
mapTag["Width"].GetShort(),
mapTag["Length"].GetShort(),
mapTag["Height"].GetShort(),
false );
map.Spawn = new Position {
X = mapTag["Spawn"][0].GetShort(),
Z = mapTag["Spawn"][1].GetShort(),
Y = mapTag["Spawn"][2].GetShort(),
R = 0,
L = 0
};
// ReSharper restore UseObjectOrCollectionInitializer
if( !map.ValidateHeader() ) {
throw new MapFormatException( "One or more of the map dimensions are invalid." );
}
map.Blocks = mapTag["Blocks"].GetBytes();
map.RemoveUnknownBlocktypes();
return map;
}
}
示例2: Load
public Map Load( string fileName ) {
using( FileStream mapStream = File.OpenRead( fileName ) ) {
GZipStream gs = new GZipStream( mapStream, CompressionMode.Decompress, true );
NBTag tag = NBTag.ReadStream( gs );
NBTag mapTag = tag["Map"];
Map map = new Map( null,
mapTag["Width"].GetShort(),
mapTag["Length"].GetShort(),
mapTag["Height"].GetShort(),
false );
map.Spawn = new Position {
X = mapTag["Spawn"][0].GetShort(),
H = mapTag["Spawn"][1].GetShort(),
Y = mapTag["Spawn"][2].GetShort(),
R = 0,
L = 0
};
if( !map.ValidateHeader() ) {
throw new MapFormatException( "One or more of the map dimensions are invalid." );
}
map.Blocks = mapTag["Blocks"].GetBytes();
map.RemoveUnknownBlocktypes( false );
return map;
}
}
示例3: Load
public Map Load( [NotNull] string fileName ) {
if( fileName == null ) throw new ArgumentNullException( "fileName" );
using( FileStream mapStream = File.OpenRead( fileName ) ) {
byte[] temp = new byte[8];
Map map = null;
mapStream.Seek( -4, SeekOrigin.End );
mapStream.Read( temp, 0, 4 );
mapStream.Seek( 0, SeekOrigin.Begin );
int uncompressedLength = BitConverter.ToInt32( temp, 0 );
byte[] data = new byte[uncompressedLength];
using( GZipStream reader = new GZipStream( mapStream, CompressionMode.Decompress, true ) ) {
reader.Read( data, 0, uncompressedLength );
}
for( int i = 0; i < uncompressedLength - 1; i++ ) {
if( data[i] != 0xAC || data[i + 1] != 0xED ) continue;
// bypassing the header crap
int pointer = i + 6;
Array.Copy( data, pointer, temp, 0, 2 );
pointer += IPAddress.HostToNetworkOrder( BitConverter.ToInt16( temp, 0 ) );
pointer += 13;
int headerEnd;
// find the end of serialization listing
for( headerEnd = pointer; headerEnd < data.Length - 1; headerEnd++ ) {
if( data[headerEnd] == 0x78 && data[headerEnd + 1] == 0x70 ) {
headerEnd += 2;
break;
}
}
// start parsing serialization listing
int offset = 0;
int width = 0, length = 0, height = 0;
Position spawn = new Position();
while( pointer < headerEnd ) {
switch( (char)data[pointer] ) {
case 'Z':
offset++;
break;
case 'F':
case 'I':
offset += 4;
break;
case 'J':
offset += 8;
break;
}
pointer += 1;
Array.Copy( data, pointer, temp, 0, 2 );
short skip = IPAddress.HostToNetworkOrder( BitConverter.ToInt16( temp, 0 ) );
pointer += 2;
// look for relevant variables
Array.Copy( data, headerEnd + offset - 4, temp, 0, 4 );
if( MemCmp( data, pointer, "width" ) ) {
width = (ushort)IPAddress.HostToNetworkOrder( BitConverter.ToInt32( temp, 0 ) );
} else if( MemCmp( data, pointer, "depth" ) ) {
height = (ushort)IPAddress.HostToNetworkOrder( BitConverter.ToInt32( temp, 0 ) );
} else if( MemCmp( data, pointer, "height" ) ) {
length = (ushort)IPAddress.HostToNetworkOrder( BitConverter.ToInt32( temp, 0 ) );
} else if( MemCmp( data, pointer, "xSpawn" ) ) {
spawn.X = (short)( IPAddress.HostToNetworkOrder( BitConverter.ToInt32( temp, 0 ) ) * 32 + 16 );
} else if( MemCmp( data, pointer, "ySpawn" ) ) {
spawn.Z = (short)( IPAddress.HostToNetworkOrder( BitConverter.ToInt32( temp, 0 ) ) * 32 + 16 );
} else if( MemCmp( data, pointer, "zSpawn" ) ) {
spawn.Y = (short)( IPAddress.HostToNetworkOrder( BitConverter.ToInt32( temp, 0 ) ) * 32 + 16 );
}
pointer += skip;
}
map = new Map( null, width, length, height, false ) { Spawn = spawn };
if( !map.ValidateHeader() ) {
throw new MapFormatException( "One or more of the map dimensions are invalid." );
}
// find the start of the block array
bool foundBlockArray = false;
offset = Array.IndexOf<byte>( data, 0x00, headerEnd );
while( offset != -1 && offset < data.Length - 2 ) {
if( data[offset] == 0x00 && data[offset + 1] == 0x78 && data[offset + 2] == 0x70 ) {
foundBlockArray = true;
pointer = offset + 7;
}
offset = Array.IndexOf<byte>( data, 0x00, offset + 1 );
}
// copy the block array... or fail
if( foundBlockArray ) {
map.Blocks = new byte[map.Volume];
Array.Copy( data, pointer, map.Blocks, 0, map.Blocks.Length );
map.ConvertBlockTypes( Mapping );
} else {
throw new MapFormatException( "Could not locate block array." );
}
//.........这里部分代码省略.........
示例4: LoadMeta
static Map LoadMeta( Stream stream ) {
INIFile metaFile = new INIFile( stream );
if( metaFile.IsEmpty() ) {
throw new Exception( "Metadata file is empty or incorrectly formatted." );
}
if( !metaFile.Contains( "size", "x", "y", "z" ) ) {
throw new Exception( "Metadata file is missing map dimensions." );
}
int widthX = Int32.Parse( metaFile["size", "x"] );
int widthY = Int32.Parse( metaFile["size", "z"] );
int height = Int32.Parse( metaFile["size", "y"] );
Map map = new Map( null, widthX, widthY, height, false );
if( !map.ValidateHeader() ) {
throw new MapFormatException( "One or more of the map dimensions are invalid." );
}
if( metaFile.Contains( "spawn", "x", "y", "z", "h" ) ) {
Position spawn = new Position {
X = (short)(Int16.Parse( metaFile["spawn", "x"] ) * 32 + 16),
Y = (short)(Int16.Parse( metaFile["spawn", "z"] ) * 32 + 16),
H = (short)(Int16.Parse( metaFile["spawn", "y"] ) * 32 + 16),
R = Byte.Parse( metaFile["spawn", "h"] ),
L = 0
};
map.SetSpawn( spawn );
} else {
map.ResetSpawn();
}
return map;
}
示例5: LoadMeta
static Map LoadMeta( [NotNull] Stream stream )
{
if( stream == null ) throw new ArgumentNullException( "stream" );
INIFile metaFile = new INIFile( stream );
if( metaFile.IsEmpty ) {
throw new Exception( "Metadata file is empty or incorrectly formatted." );
}
if( !metaFile.Contains( "size", "x", "y", "z" ) ) {
throw new Exception( "Metadata file is missing map dimensions." );
}
int width = Int32.Parse( metaFile["size", "x"] );
int length = Int32.Parse( metaFile["size", "z"] );
int height = Int32.Parse( metaFile["size", "y"] );
Map map = new Map( null, width, length, height, false );
if( !map.ValidateHeader() ) {
throw new MapFormatException( "One or more of the map dimensions are invalid." );
}
if( metaFile.Contains( "spawn", "x", "y", "z", "h" ) ) {
map.Spawn = new Position {
X = (short)(Int16.Parse( metaFile["spawn", "x"] ) * 32 + 16),
Y = (short)(Int16.Parse( metaFile["spawn", "z"] ) * 32 + 16),
Z = (short)(Int16.Parse( metaFile["spawn", "y"] ) * 32 + 16),
R = Byte.Parse( metaFile["spawn", "h"] ),
L = 0
};
}
return map;
}
示例6: Load
public Map Load( string fileName ) {
using( FileStream mapStream = File.OpenRead( fileName ) ) {
BinaryReader reader = new BinaryReader( mapStream );
if( reader.ReadInt32() != Identifier || reader.ReadByte() != Revision ) {
throw new MapFormatException();
}
// read dimensions
int widthX = reader.ReadInt16();
int height = reader.ReadInt16();
int widthY = reader.ReadInt16();
Map map = new Map( null, widthX, widthY, height, false );
// read spawn
map.Spawn.X = (short)reader.ReadInt32();
map.Spawn.H = (short)reader.ReadInt32();
map.Spawn.Y = (short)reader.ReadInt32();
map.Spawn.R = reader.ReadByte();
map.Spawn.L = reader.ReadByte();
if( !map.ValidateHeader() ) {
throw new MapFormatException( "One or more of the map dimensions are invalid." );
}
// read modification/creation times
map.DateModified = reader.ReadUInt32().ToDateTime();
map.DateCreated = reader.ReadUInt32().ToDateTime();
// read UUID
map.Guid = new Guid( reader.ReadBytes( 16 ) );
// read the index
int layerCount = reader.ReadByte();
List<DataLayer> layers = new List<DataLayer>( layerCount );
for( int i = 0; i < layerCount; i++ ) {
DataLayer layer = new DataLayer {
Type = (DataLayerType)reader.ReadByte(),
Offset = reader.ReadInt64(),
CompressedLength = reader.ReadInt32(),
GeneralPurposeField = reader.ReadInt32(),
ElementSize = reader.ReadInt32(),
ElementCount = reader.ReadInt32()
};
layers.Add( layer );
}
// read metadata
int metaSize = reader.ReadInt32();
using( DeflateStream ds = new DeflateStream( mapStream, CompressionMode.Decompress ) ) {
BinaryReader br = new BinaryReader( ds );
for( int i = 0; i < metaSize; i++ ) {
string group = ReadLengthPrefixedString( br ).ToLowerInvariant();
string key = ReadLengthPrefixedString( br ).ToLowerInvariant();
string newValue = ReadLengthPrefixedString( br );
string oldValue = map.GetMeta( group, key );
if( oldValue != null && oldValue != newValue ) {
Logger.Log( "MapFCMv3.Load: Duplicate metadata entry found for [{0}].[{1}]. " +
"Old value (overwritten): \"{2}\". New value: \"{3}\"", LogType.Warning,
group, key, map.GetMeta( group, key ), newValue );
}
if( group == "zones" ) {
try {
map.AddZone( new Zone( newValue, map.World ) );
} catch( Exception ex ) {
Logger.Log( "MapFCMv3.Load: Error importing zone definition: {0}", LogType.Error, ex );
}
} else {
map.SetMeta( group, key, newValue );
}
}
for( int i = 0; i < layerCount; i++ ) {
ReadLayer( layers[i], ds, map );
}
}
return map;
}
}