public BlockContentsSource(string archiveFilePath, BlockFlags flags, long position, long compressedSize, long uncompressedSize) { if (archiveFilePath == null) { throw new ArgumentNullException("archiveFilePath"); } if (position < 0) { throw new ArgumentOutOfRangeException("position cannot be negative.", "position"); } if (compressedSize < 0) { throw new ArgumentOutOfRangeException("compressedSize cannot be negative.", "compressedSize"); } if (uncompressedSize < 0) { throw new ArgumentOutOfRangeException("uncompressedSize cannot be negative.", "uncompressedSize"); } this.ArchiveFilePath = archiveFilePath; this.Flags = flags; this.Position = position; this.CompressedSize = compressedSize; this.UncompressedSize = uncompressedSize; }
/// <summary>Fire event.</summary> /// <returns>Any block flags generated by decorators.</returns> public BlockFlags Dispatch() { BlockFlags block = BlockFlags.NONE; if (_hasDecorators) { for (int i = 0; i < _decorators.Length; ++i) { if (_decorators[i].active) { (_decorators[i] as SmartEventDecoratorBase).OnDispatched(ref block); if (block.Contains(BlockFlags.DECORATORS)) { break; } } } } if (!block.Contains(BlockFlags.DISPATCH)) { _relay.Dispatch(); #if UNITY_EDITOR && !SMARTDATA_NO_GRAPH_HOOKS SmartData.Editors.SmartDataRegistry.OnRefCallToSmart(null, this); #endif } return(block); }
private bool FreeBlock(long blockId, BlockFlags expected) { using (FileBlock first = new FileBlock(_blockSize, _useAlignedIo)) { ReadBlock(blockId, first, FileBlock.HeaderSize, expected | BlockFlags.BlockDeleted); if ((first.Flags & expected) != expected) { return(false); } using (FileBlock last = first.Clone()) { while (last.NextBlockId != 0) { last.Flags = BlockFlags.BlockDeleted; WriteBlock(last.BlockId, last, FileBlock.HeaderSize); ReadBlock(last.NextBlockId, last, FileBlock.HeaderSize, BlockFlags.InternalBlock); } using (new SafeLock(_syncFreeBlock)) { last.Flags = BlockFlags.BlockDeleted; last.NextBlockId = _nextFree; WriteBlock(last.BlockId, last, FileBlock.HeaderSize); _nextFree = first.BlockId; } return(true); } } }
void SpecialSetBlockAt(Chunk chunk, int X, int Y, int Z, BlockInternal bi) { if (X < 0 || Y < 0 || Z < 0 || X >= Chunk.CHUNK_SIZE || Y >= Chunk.CHUNK_SIZE || Z >= Chunk.CHUNK_SIZE) { Vector3i chloc = chunk.OwningRegion.ChunkLocFor(new Location(X, Y, Z)); Chunk ch = chunk.OwningRegion.LoadChunkNoPopulate(chunk.WorldPosition + chloc); int x = (int)(X - chloc.X * Chunk.CHUNK_SIZE); int y = (int)(Y - chloc.Y * Chunk.CHUNK_SIZE); int z = (int)(Z - chloc.Z * Chunk.CHUNK_SIZE); BlockInternal orig = ch.GetBlockAt(x, y, z); BlockFlags flags = ((BlockFlags)orig.BlockLocalData); if (!flags.HasFlag(BlockFlags.EDITED) && !flags.HasFlag(BlockFlags.PROTECTED)) { // TODO: lock? ch.BlocksInternal[chunk.BlockIndex(x, y, z)] = bi; } } else { BlockInternal orig = chunk.GetBlockAt(X, Y, Z); BlockFlags flags = ((BlockFlags)orig.BlockLocalData); if (!flags.HasFlag(BlockFlags.EDITED) && !flags.HasFlag(BlockFlags.PROTECTED)) { chunk.BlocksInternal[chunk.BlockIndex(X, Y, Z)] = bi; } } }
// // trampoline must be static, and someone else needs to keep a ref to it // public unsafe void SetupBlock(Delegate trampoline, Delegate userDelegate) { isa = block_class; invoke = Marshal.GetFunctionPointerForDelegate(trampoline); local_handle = (IntPtr)GCHandle.Alloc(userDelegate); global_handle = IntPtr.Zero; flags = BlockFlags.BLOCK_HAS_COPY_DISPOSE | BlockFlags.BLOCK_HAS_SIGNATURE; /* FIXME: support stret blocks */ // we allocate one big block of memory, the first part is the BlockDescriptor, // the second part is the signature string (no need to allocate a second time // for the signature if we can avoid it). One descriptor is allocated for every // Block; this is potentially something the static registrar can fix, since it // should know every possible trampoline signature. var signature = Runtime.ComputeSignature(trampoline.Method); var bytes = System.Text.Encoding.UTF8.GetBytes(signature); var desclen = sizeof(XamarinBlockDescriptor) + bytes.Length + 1 /* null character */; var descptr = Marshal.AllocHGlobal(desclen); block_descriptor = descptr; var xblock_descriptor = (XamarinBlockDescriptor *)block_descriptor; xblock_descriptor->descriptor = *(BlockDescriptor *)xamarin_get_block_descriptor(); xblock_descriptor->descriptor.signature = descptr + sizeof(BlockDescriptor) + 4 /* signature_length */; xblock_descriptor->xamarin_size = desclen; Marshal.Copy(bytes, 0, xblock_descriptor->descriptor.signature, bytes.Length); Marshal.WriteByte(xblock_descriptor->descriptor.signature + bytes.Length, 0); // null terminate string }
internal GroundedBlock(string name, string namedId, BlockFlags flags, TextureLayout layout) : base( name, namedId, flags, layout) { }
public override void OnDispatched(ref BlockFlags blockFlags) { Send(); if (_networkOnlyDispatch) { blockFlags |= BlockFlags.DISPATCH; } }
public BlockTableEntry([NotNull] byte[] data) { using var ms = new MemoryStream(data); using var br = new BinaryReader(ms); _blockOffset = br.ReadUInt32(); _blockSize = br.ReadUInt32(); _fileSize = br.ReadUInt32(); Flags = (BlockFlags)br.ReadUInt32(); }
// // trampoline must be static, and someone else needs to keep a ref to it // public unsafe void SetupBlock(Delegate trampoline, Delegate userDelegate) { isa = block_class; invoke = Marshal.GetFunctionPointerForDelegate(trampoline); local_handle = (IntPtr)GCHandle.Alloc(userDelegate); global_handle = IntPtr.Zero; flags = BlockFlags.BLOCK_HAS_DESCRIPTOR | BlockFlags.BLOCK_HAS_COPY_DISPOSE; block_descriptor = global_descriptor_ptr; }
/// <summary> /// Create a new connecting block. /// </summary> /// <param name="name">The name of the blocks.</param> /// <param name="namedId">The string ID of the block.</param> /// <param name="flags">The flags describing the block.</param> /// <param name="boundingBox">The block bounding box.</param> /// <param name="targetBuffer">The target rendering buffer.</param> protected ConnectingBlock(string name, string namedId, BlockFlags flags, BoundingBox boundingBox, TargetBuffer targetBuffer) : base( name, namedId, flags, boundingBox, targetBuffer) { }
public Block(int id, string name, BlockFlags flags) { this.id = id; this.name = name; this.flags = flags; blockArray[id] = this; textureCoords = makeTextureCoords(id, 0); }
protected BaseScreen(ITagContainer diContainer, BlockFlags blockFlags) : base(diContainer.GetTag <DefaultEcs.World>(), CreateEntityContainer, useBuffer: false) { this.blockFlags = blockFlags; zzContainer = diContainer.GetTag <IZanzarahContainer>(); zanzarah = diContainer.GetTag <Zanzarah>(); ui = diContainer.GetTag <UI>(); preload = ui.GetTag <UIPreloader>(); uiWorld = ui.GetTag <DefaultEcs.World>(); World.SetMaxCapacity <TComponent>(1); openSubscription = World.Subscribe <TMessage>(HandleOpen); addedSubscription = World.SubscribeComponentAdded <TComponent>(HandleAdded); removedSubscription = World.SubscribeComponentRemoved <TComponent>(HandleRemoved); }
/// <summary> /// Deserializes a <see cref="BlockTableEntry"/> from provided binary data. /// </summary> /// <param name="data">The serialized data.</param> public BlockTableEntry(byte[] data) { using (MemoryStream ms = new MemoryStream(data)) { using (BinaryReader br = new BinaryReader(ms)) { BlockOffset = br.ReadUInt32(); BlockSize = br.ReadUInt32(); FileSize = br.ReadUInt32(); Flags = (BlockFlags)br.ReadUInt32(); } } }
// // trampoline must be static, and someone else needs to keep a ref to it // public unsafe void SetupBlock(Delegate trampoline, Delegate userDelegate) { isa = block_class; invoke = Marshal.GetFunctionPointerForDelegate(trampoline); local_handle = (IntPtr)GCHandle.Alloc(userDelegate); global_handle = IntPtr.Zero; flags = BlockFlags.BLOCK_HAS_COPY_DISPOSE | BlockFlags.BLOCK_HAS_SIGNATURE; /* FIXME: support stret blocks */ // We need to get the signature of the target method, so that we can compute // the ObjC signature correctly (the generated method that's actually // invoked by native code does not have enough type information to compute // the correct signature). // This attribute might not exist for third-party libraries created // with earlier versions of Xamarin.iOS, so make sure to cope with // the attribute not being available. var userDelegateType = trampoline.GetType().GetCustomAttribute <UserDelegateTypeAttribute> ()?.UserDelegateType; bool blockSignature; MethodInfo userMethod; if (userDelegateType != null) { userMethod = userDelegateType.GetMethod("Invoke"); blockSignature = true; } else { userMethod = trampoline.Method; blockSignature = false; } // we allocate one big block of memory, the first part is the BlockDescriptor, // the second part is the signature string (no need to allocate a second time // for the signature if we can avoid it). One descriptor is allocated for every // Block; this is potentially something the static registrar can fix, since it // should know every possible trampoline signature. var signature = Runtime.ComputeSignature(userMethod, blockSignature); var bytes = System.Text.Encoding.UTF8.GetBytes(signature); var desclen = sizeof(XamarinBlockDescriptor) + bytes.Length + 1 /* null character */; var descptr = Marshal.AllocHGlobal(desclen); block_descriptor = descptr; var xblock_descriptor = (XamarinBlockDescriptor *)block_descriptor; xblock_descriptor->descriptor = *(BlockDescriptor *)xamarin_get_block_descriptor(); xblock_descriptor->descriptor.signature = descptr + sizeof(BlockDescriptor) + 4 /* signature_length */; xblock_descriptor->ref_count = 1; Marshal.Copy(bytes, 0, xblock_descriptor->descriptor.signature, bytes.Length); Marshal.WriteByte(xblock_descriptor->descriptor.signature + bytes.Length, 0); // null terminate string }
/// <summary> /// Decompresses a sector of a file stored in an MPQ archive. /// </summary> /// <param name="pendingSector">The compressed sector data.</param> /// <param name="blockFlags">The flags of the file block, taken from the block table.</param> /// <returns>The decompressed sector data.</returns> public static byte[] DecompressSector(byte[] pendingSector, BlockFlags blockFlags) { if (blockFlags.HasFlag(BlockFlags.IsCompressedMultiple)) { return(DecompressData(pendingSector)); } else if (blockFlags.HasFlag(BlockFlags.IsImploded)) { // This file or sector uses a single-pass PKWARE Implode algorithm. // Decompress sector using PKWARE pendingSector = DecompressPKWAREImplode(pendingSector); } return(pendingSector); }
void SetValue(TData v, RestoreMode restore) { // When setting initial value, don't dispatch anything or use decorators if (restore == RestoreMode.INIT) { _runtimeValue = v; return; } // Auto-bound SmartRefs get bound first time value changes after they're queued if (_binder.hasRefsToBind) { _binder.AutoBind(); } BlockFlags block = BlockFlags.NONE; if (_hasDecorators) { TData temp = v; temp = ExecuteDecoratorsOnUpdate(_decorators, _runtimeValue, temp, restore, ref block); // If decorators blocked, do not continue to other decorators if (!block.Contains(BlockFlags.DECORATORS) && _multiDecorators.Count > 0) { foreach (var a in _multiDecorators) { temp = ExecuteDecoratorsOnUpdate(a.Value, _runtimeValue, temp, restore, ref block); } } // If data blocked, do not update runtime value if (!block.Contains(BlockFlags.DATA)) { _runtimeValue = temp; } } else { _runtimeValue = v; } // If dispatch blocked, do not dispatch relay if (!block.Contains(BlockFlags.DISPATCH)) { _relay.Dispatch(_runtimeValue); } }
public BlockContentsSource(string archiveFilePath, BlockFlags flags) { if (archiveFilePath == null) { throw new ArgumentNullException("archiveFilePath"); } if (flags.IsMemoryResident) { throw new ArgumentOutOfRangeException("must provide position, compressedSize and uncompressedSize when memory resident", "flags.IsMemoryResident"); } this.ArchiveFilePath = archiveFilePath; this.Flags = flags; this.Position = 0; this.CompressedSize = 0; this.UncompressedSize = 0; }
public BlockStreamReader(FragmentedFile file, long ordinal, BlockFlags typeExpected, bool validated) { _file = file; _blockPos = 0; _validated = validated; _block = new FileBlock(file._blockSize, file._useAlignedIo); _file.ReadBlock(ordinal, _block, file._blockSize, typeExpected, _validated); if (_validated) { _expectedSum = _block.CheckSum; _checksum = new Crc32(); _checksum.Add(_block.BlockData, _block.DataOffset, _block.Length); if (_block.NextBlockId == 0 && _checksum != _expectedSum) { throw new InvalidDataException(); } } }
/// <summary> /// Create a new block. /// </summary> /// <param name="name">The name of the block. Can be localized.</param> /// <param name="namedId">The named ID of the block. A unique and unlocalized identifier.</param> /// <param name="flags">The block flags setting specific options.</param> /// <param name="boundingBox">The base bounding box for this block. Is used for placement checks.</param> /// <param name="targetBuffer">The target rendering buffer.</param> protected Block(string name, string namedId, BlockFlags flags, BoundingBox boundingBox, TargetBuffer targetBuffer) { Name = name; NamedId = namedId; IsFull = flags.IsFull; IsOpaque = flags.IsOpaque; RenderFaceAtNonOpaques = flags.RenderFaceAtNonOpaques; IsSolid = flags.IsSolid; ReceiveCollisions = flags.ReceiveCollisions; IsTrigger = flags.IsTrigger; IsReplaceable = flags.IsReplaceable; IsInteractable = flags.IsInteractable; this.boundingBox = boundingBox; TargetBuffer = targetBuffer; Debug.Assert( (TargetBuffer != TargetBuffer.Simple) ^ IsFull, $"TargetBuffer '{nameof(TargetBuffer.Simple)}' requires {nameof(IsFull)} to be {!IsFull}, all other target buffers cannot be full."); Debug.Assert(IsFull || !IsOpaque, "A block that is not full cannot be opaque."); #pragma warning disable S3060 // "is" should not be used with "this" Debug.Assert( TargetBuffer == TargetBuffer.VaryingHeight == this is IHeightVariable, $"The target buffer should be {nameof(TargetBuffer.VaryingHeight)} if and only if the block implements {nameof(IHeightVariable)}."); #pragma warning restore S3060 // "is" should not be used with "this" if (blockList.Count < BlockLimit) { blockList.Add(this); namedBlockDictionary.Add(namedId, this); Id = (uint) (blockList.Count - 1); } else { Debug.Fail($"Not more than {BlockLimit} blocks are allowed."); } }
private void ReadBlock(long ordinal, FileBlock block, int length, BlockFlags type, bool exactId) { using (Stream io = OpenBlock(FileAccess.Read, ordinal)) block.Read(io, length); if (exactId && block.BlockId != ordinal) { throw new InvalidDataException(); } if ((block.Flags & type) == 0 && type != 0) { throw new InvalidDataException(); } if (block.Length < 0 || block.Length > (_blockSize - FileBlock.HeaderSize)) { throw new InvalidDataException(); } }
public override void OnInspectorGUI() { EditorGUILayout.PropertyField(serializedObject.FindProperty("m_BlockName")); SerializedProperty ty = serializedObject.FindProperty("m_Type"); BlockType type = (BlockType)Enum.Parse(typeof(BlockType), ty.enumNames[ty.enumValueIndex], true); ShowBlockTypeEnum(ty); SerializedProperty fs = serializedObject.FindProperty("m_Flags"); BlockFlags flags = (target as Block).Flags; EditorGUILayout.PropertyField(fs); SerializedProperty vertexType = serializedObject.FindProperty("m_VertexType"); BlockVertexType v = (BlockVertexType)Enum.Parse(typeof(BlockVertexType), vertexType.enumNames[vertexType.enumValueIndex], true); EditorGUILayout.PropertyField(vertexType); if ((flags & BlockFlags.Liquid) == BlockFlags.Liquid && v == BlockVertexType.PerpendicularQuads) { Debug.LogWarning("液体的顶点类型应该是立方体"); } EditorGUILayout.PropertyField(serializedObject.FindProperty("m_MoveResistance")); EditorGUILayout.PropertyField(serializedObject.FindProperty("m_LightOpacity")); EditorGUILayout.PropertyField(serializedObject.FindProperty("m_LightValue")); EditorGUILayout.PropertyField(serializedObject.FindProperty("m_Hardness")); EditorGUILayout.PropertyField(serializedObject.FindProperty("m_DestoryEffectColor")); EditorGUILayout.Space(); m_ExtraAssets.DoLayoutList(); EditorGUILayout.Space(); UVFoldout(v); EditorGUILayout.Space(); AudioClipsFoldout(type); serializedObject.ApplyModifiedProperties(); }
public override void CopyFrom(DxfHandledObject from, CloneContext cloneContext) { base.CopyFrom(from, cloneContext); DxfBlock dxfBlock = (DxfBlock)from; this.blockFlags_0 = dxfBlock.blockFlags_0; this.blockStatusFlags_0 = dxfBlock.blockStatusFlags_0; this.vector3D_0 = dxfBlock.vector3D_0; this.string_0 = dxfBlock.string_0; this.string_1 = dxfBlock.string_1; this.string_2 = dxfBlock.string_2; this.BlockBegin = (DxfBlockBegin)dxfBlock.BlockBegin.Clone(cloneContext); this.BlockEnd = (DxfBlockEnd)dxfBlock.BlockEnd.Clone(cloneContext); if (object.ReferenceEquals((object)dxfBlock.dxfEntityCollection_0, (object)cloneContext.SourceModel.Entities)) { this.method_10(cloneContext.TargetModel.Entities); } this.drawingUnits_0 = dxfBlock.drawingUnits_0; this.bool_0 = dxfBlock.bool_0; this.bool_1 = dxfBlock.bool_1; }
private long AllocBlock(FileBlock block, BlockFlags type) { using (new SafeLock(_syncFreeBlock)) { long blockId = _nextFree; if (blockId == 0 && _reallocSize > 0) { long fsize; using (Stream s = _streamCache.Open(FileAccess.Read)) fsize = LastAllocated(s); ResizeFile(fsize + _blockSize, fsize + _reallocSize); blockId = _nextFree; } if (blockId <= 0) { throw new IOException(); } using (Stream io = OpenBlock(FileAccess.Read, blockId)) block.Read(io, FileBlock.HeaderSize); if ((block.BlockId & _maskOffset) != (blockId & _maskOffset) || (block.Flags & BlockFlags.BlockDeleted) == 0) { throw new InvalidDataException(); } _nextFree = block.NextBlockId; block.BlockId = blockId; block.IncrementId(_maskVersion); block.NextBlockId = 0; block.Flags = type == BlockFlags.ExternalBlock ? (type | BlockFlags.Temporary) : type; block.Length = 0; WriteBlock(block.BlockId, block, FileBlock.HeaderSize); return(block.BlockId); } }
public static bool Has(this BlockFlags value, BlockFlags flag) { return((value & flag) != 0); }
/// <summary> /// Initializes a new instance of the <see cref="Warcraft.MPQ.MPQ"/> class. /// </summary> /// <param name="mpqStream">An open stream to data containing an MPQ archive.</param> public MPQ(Stream mpqStream) { this.ArchiveReader = new BinaryReader(mpqStream); this.Header = new MPQHeader(this.ArchiveReader.ReadBytes((int)PeekHeaderSize())); // Seek to the hash table and load it this.ArchiveReader.BaseStream.Position = (long)this.Header.GetHashTableOffset(); byte[] hashTableData; if (this.Header.IsHashTableCompressed()) { byte[] encryptedData = this.ArchiveReader.ReadBytes((int)this.Header.GetCompressedHashTableSize()); byte[] decryptedData = MPQCrypt.DecryptData(encryptedData, HashTable.TableKey); BlockFlags tableFlags = BlockFlags.IsCompressedMultiple; hashTableData = Compression.DecompressSector(decryptedData, tableFlags); } else { byte[] encryptedData = this.ArchiveReader.ReadBytes((int)this.Header.GetHashTableSize()); hashTableData = MPQCrypt.DecryptData(encryptedData, HashTable.TableKey); } this.ArchiveHashTable = new HashTable(hashTableData); // Seek to the block table and load it this.ArchiveReader.BaseStream.Position = (long)this.Header.GetBlockTableOffset(); byte[] blockTableData; if (this.Header.IsBlockTableCompressed()) { byte[] encryptedData = this.ArchiveReader.ReadBytes((int)this.Header.GetCompressedBlockTableSize()); byte[] decryptedData = MPQCrypt.DecryptData(encryptedData, BlockTable.TableKey); BlockFlags tableFlags = BlockFlags.IsCompressedMultiple; blockTableData = Compression.DecompressSector(decryptedData, tableFlags); } else { byte[] encryptedData = this.ArchiveReader.ReadBytes((int)this.Header.GetBlockTableSize()); blockTableData = MPQCrypt.DecryptData(encryptedData, BlockTable.TableKey); } this.ArchiveBlockTable = new BlockTable(blockTableData); // TODO: Seek to the extended hash table and load it // TODO: Seek to the extended block table and load it if (this.Header.GetFormat() >= MPQFormat.ExtendedV1) { // Seek to the extended block table and load it, if neccesary if (this.Header.GetExtendedBlockTableOffset() > 0) { this.ArchiveReader.BaseStream.Position = (long)this.Header.GetExtendedBlockTableOffset(); for (int i = 0; i < this.Header.GetBlockTableEntryCount(); ++i) { this.ExtendedBlockTable.Add(this.ArchiveReader.ReadUInt16()); } } } }
private void ReadBlock(long ordinal, FileBlock block, int length, BlockFlags type, bool exactId) { using (Stream io = OpenBlock(FileAccess.Read, ordinal)) block.Read(io, length); if (exactId && block.BlockId != ordinal) throw new InvalidDataException(); if ((block.Flags & type) == 0 && type != 0) throw new InvalidDataException(); if (block.Length < 0 || block.Length > (_blockSize - FileBlock.HeaderSize)) throw new InvalidDataException(); }
public static byte[] DecompressSector(byte[] PendingSector, BlockFlags Flags) { if (Flags.HasFlag(BlockFlags.IsCompressedMultiple)) { // The sector is compressed using a combination of techniques. // Examine the first byte to determine the compression algorithms used CompressionAlgorithms compressionAlgorithms = (CompressionAlgorithms)PendingSector[0]; // Drop the first byte byte[] sectorData = new byte[PendingSector.Length - 1]; Buffer.BlockCopy(PendingSector, 1, sectorData, 0, sectorData.Length); PendingSector = sectorData; // Walk through each compression algorithm in reverse order if (compressionAlgorithms.HasFlag(CompressionAlgorithms.BZip2)) { // Decompress sector using BZIP2 PendingSector = DecompressBZip2(PendingSector); } if (compressionAlgorithms.HasFlag(CompressionAlgorithms.Implode_PKWARE)) { // Decompress sector using PKWARE Implode PendingSector = DecompressPKWAREImplode(PendingSector); } if (compressionAlgorithms.HasFlag(CompressionAlgorithms.Deflate_ZLIB)) { // Decompress sector using Deflate PendingSector = DecompressDeflate(PendingSector); } if (compressionAlgorithms.HasFlag(CompressionAlgorithms.Huffman)) { // Decompress sector using Huffman PendingSector = DecompressHuffman(PendingSector); } if (compressionAlgorithms.HasFlag(CompressionAlgorithms.IMA_ADPCM_Stereo)) { // Decompress sector using ADPCM Stereo PendingSector = DecompressADPCMStereo(PendingSector); } if (compressionAlgorithms.HasFlag(CompressionAlgorithms.IMA_ADPCM_Mono)) { // Decompress sector using ADPCM Mono PendingSector = DecompressADPCMMono(PendingSector); } if (compressionAlgorithms.HasFlag(CompressionAlgorithms.Sparse)) { // Decompress sector using Sparse PendingSector = DecompressSparse(PendingSector); } } else if (Flags.HasFlag(BlockFlags.IsImploded)) { // This file or sector uses a single-pass PKWARE Implode algorithm. // Decompress sector using PKWARE PendingSector = DecompressPKWAREImplode(PendingSector); } return PendingSector; }
private void ReadBlock(long ordinal, FileBlock block, int length, BlockFlags type) { ReadBlock(ordinal, block, length, type, true); }
public override float OnUpdated(float oldValue, float newValue, RestoreMode restoreMode, ref BlockFlags block) { float result = Mathf.Clamp(newValue, _min, _max); if (result != newValue) { _onRangeClamped.Dispatch(this, result, newValue); } return(result); }
internal TintedCustomModelBlock(string name, string namedId, BlockFlags flags, string modelName, BoundingBox boundingBox) : base( name, namedId, flags with {
private long AllocBlock(FileBlock block, BlockFlags type) { using (new SafeLock(_syncFreeBlock)) { long blockId = _nextFree; if (blockId == 0 && _reallocSize > 0) { long fsize; using (Stream s = _streamCache.Open(FileAccess.Read)) fsize = LastAllocated(s); ResizeFile(fsize + _blockSize, fsize + _reallocSize); blockId = _nextFree; } if (blockId <= 0) throw new IOException(); using (Stream io = OpenBlock(FileAccess.Read, blockId)) block.Read(io, FileBlock.HeaderSize); if ((block.BlockId & _maskOffset) != (blockId & _maskOffset) || (block.Flags & BlockFlags.BlockDeleted) == 0) throw new InvalidDataException(); _nextFree = block.NextBlockId; block.BlockId = blockId; block.IncrementId(_maskVersion); block.NextBlockId = 0; block.Flags = type == BlockFlags.ExternalBlock ? (type | BlockFlags.Temporary) : type; block.Length = 0; WriteBlock(block.BlockId, block, FileBlock.HeaderSize); return block.BlockId; } }
private bool FreeBlock(long blockId, BlockFlags expected) { using (FileBlock first = new FileBlock(_blockSize, _useAlignedIo)) { ReadBlock(blockId, first, FileBlock.HeaderSize, expected | BlockFlags.BlockDeleted); if ((first.Flags & expected) != expected) return false; using (FileBlock last = first.Clone()) { while (last.NextBlockId != 0) { last.Flags = BlockFlags.BlockDeleted; WriteBlock(last.BlockId, last, FileBlock.HeaderSize); ReadBlock(last.NextBlockId, last, FileBlock.HeaderSize, BlockFlags.InternalBlock); } using (new SafeLock(_syncFreeBlock)) { last.Flags = BlockFlags.BlockDeleted; last.NextBlockId = _nextFree; WriteBlock(last.BlockId, last, FileBlock.HeaderSize); _nextFree = first.BlockId; } return true; } } }
TData ExecuteDecoratorsOnUpdate(SmartDecoratorBase[] decorators, TData oldValue, TData newValue, RestoreMode restore, ref BlockFlags block) { if (decorators != null && decorators.Length != 0) { for (int i = 0; i < decorators.Length; ++i) { var d = decorators[i]; if (d.active) { newValue = (decorators[i] as SmartDataDecoratorBase <TData>).OnUpdated(oldValue, newValue, restore, ref block); // If decorators blocked, do not continue to other decorators if (block.Contains(BlockFlags.DECORATORS)) { break; } } } } return(newValue); }
public static bool HasFlag(this BlockData block, BlockFlags flag) { return((block.Flags & flag) == flag); }
public BlockStreamReader(FragmentedFile file, long ordinal, BlockFlags typeExpected, bool validated) { _file = file; _blockPos = 0; _validated = validated; _block = new FileBlock(file._blockSize, file._useAlignedIo); _file.ReadBlock(ordinal, _block, file._blockSize, typeExpected, _validated); if (_validated) { _expectedSum = _block.CheckSum; _checksum = new Crc32(); _checksum.Add(_block.BlockData, _block.DataOffset, _block.Length); if (_block.NextBlockId == 0 && _checksum != _expectedSum) throw new InvalidDataException(); } }
/// <summary> /// Initializes a new instance of a cross plant. /// </summary> /// <param name="name">The name of this block.</param> /// <param name="namedId">The unique and unlocalized name of this block.</param> /// <param name="texture">The name of the texture of this block.</param> /// <param name="flags">The block flags.</param> /// <param name="boundingBox">The bounding box of this block.</param> internal CrossPlantBlock(string name, string namedId, string texture, BlockFlags flags, BoundingBox boundingBox) : base( name, namedId, flags with {
// // trampoline must be static, and someone else needs to keep a ref to it // public unsafe void SetupBlock(Delegate trampoline, Delegate userDelegate) { isa = block_class; invoke = Marshal.GetFunctionPointerForDelegate (trampoline); local_handle = (IntPtr) GCHandle.Alloc (userDelegate); global_handle = IntPtr.Zero; flags = BlockFlags.BLOCK_HAS_DESCRIPTOR | BlockFlags.BLOCK_HAS_COPY_DISPOSE; block_descriptor = global_descriptor_ptr; }