// Mode engages public override void OnEngage() { base.OnEngage(); // Nothing highlighted highlighted = null; hx = -1; hy = -1; // Custom presentation to hide the grid CustomPresentation p = new CustomPresentation(); p.AddLayer(new PresentLayer(RendererLayer.Background, BlendingMode.Mask, General.Settings.BackgroundAlpha)); p.AddLayer(new PresentLayer(RendererLayer.Surface, BlendingMode.Mask)); p.AddLayer(new PresentLayer(RendererLayer.Overlay, BlendingMode.Alpha, 1f, true)); p.AddLayer(new PresentLayer(RendererLayer.Things, BlendingMode.Alpha, 1.0f)); p.AddLayer(new PresentLayer(RendererLayer.Geometry, BlendingMode.Alpha, 1f, true)); renderer.SetPresentation(p); // Make the blockmap RectangleF area = MapSet.CreateArea(General.Map.Map.Vertices); area = MapSet.IncreaseArea(area, General.Map.Map.Things); blockmap = new BlockMap <BlockEntry>(area); blockmap.AddLinedefsSet(General.Map.Map.Linedefs); blockmap.AddSectorsSet(General.Map.Map.Sectors); blockmap.AddThingsSet(General.Map.Map.Things); }
public static BlockMountType GetMountPrevention(Mobile mob) { if (mob == null) { return(BlockMountType.None); } BlockEntry entry = null; if (m_Table.ContainsKey(mob)) { entry = m_Table[mob]; } if (entry == null) { return(BlockMountType.None); } if (entry.IsExpired) { ExpireMountPrevention(mob); return(BlockMountType.None); } return(entry.m_Type); }
public static BlockMountType GetMountPrevention(Mobile mob, BaseMount mount) { if (mob == null) { return(BlockMountType.None); } BlockEntry entry = null; if (m_Table.ContainsKey(mob)) { entry = m_Table[mob]; } if (entry == null) { return(BlockMountType.None); } if (entry.IsExpired(mount)) { return(BlockMountType.None); } if (Core.TOL && entry.m_Type >= BlockMountType.RidingSwipe && entry.m_Expiration > DateTime.UtcNow) { return(BlockMountType.DismountRecovery); } return(entry.m_Type); }
public static void SetMountPrevention(Mobile mob, IMount mount, BlockMountType type, TimeSpan duration) { if (mob == null) { return; } DateTime expiration = DateTime.UtcNow + duration; BlockEntry entry = null; if (m_Table.ContainsKey(mob)) { entry = m_Table[mob]; } if (entry != null) { entry.m_Type = type; entry.m_Expiration = expiration; } else { m_Table[mob] = entry = new BlockEntry(mob, mount, type, expiration); } BuffInfo.AddBuff(mob, new BuffInfo(BuffIcon.DismountPrevention, 1075635, 1075636, duration, mob)); }
public static void SaveGame(string name, List <GameObject> _mapData) { if (!(Directory.Exists(Application.persistentDataPath + "/Saves/" + name))) { Directory.CreateDirectory(Application.persistentDataPath + "/Saves/" + name); } MapData _myMap = new MapData(); foreach (GameObject _go in _mapData) { if (_go != null) { GOData _goD = _go.GetComponent <GOData>(); BlockEntry bE = new BlockEntry(); bE.blockName = _goD.blockTypeName; bE.blockPosition = _goD.position; bE.blockYRotation = _goD.yRotation; bE.coloured = _goD.coloured; _myMap.mapBlocks.Add(bE); } } XmlSerializer serialiser = new XmlSerializer(typeof(MapData)); FileStream stream = new FileStream(Application.persistentDataPath + "/Saves/" + name + "/block_data.xml", FileMode.Create); serialiser.Serialize(stream, _myMap); stream.Close(); Debug.Log("Successfully Saved Level: " + name + " At " + Application.persistentDataPath + "/Saves/" + name + "/block_data.xml"); }
private void GetBlockEntry(int index, out BlockEntry b) { b.FilePos = blockTable[index * 4 + 0]; b.CSize = blockTable[index * 4 + 1]; b.FSize = blockTable[index * 4 + 2]; b.Flags = blockTable[index * 4 + 3]; }
// Mouse moves over display public override void OnMouseMove(MouseEventArgs e) { base.OnMouseMove(e); BlockEntry newhighlight = null; hx = -1; hy = -1; // Determine highlighted block float nhx = (mousemappos.x - blockmap.Range.Left) / (float)blockmap.BlockSize; float nhy = (mousemappos.y - blockmap.Range.Top) / (float)blockmap.BlockSize; if ((nhx < (float)blockmap.Size.Width) && (nhy < (float)blockmap.Size.Height) && (nhx >= 0.0f) && (nhy >= 0.0f)) { newhighlight = blockmap.GetBlockAt(mousemappos); if (newhighlight != null) { hx = (int)nhx; hy = (int)nhy; } } if (newhighlight != highlighted) { highlighted = newhighlight; General.Interface.RedrawDisplay(); } }
// This runs the check public override void Run() { BlockMap <BlockEntry> blockmap = BuilderPlug.Me.ErrorCheckForm.BlockMap; Dictionary <Vertex, List <Vertex> > doneverts = new Dictionary <Vertex, List <Vertex> >(); int progress = 0; int stepprogress = 0; // Go for all the verts foreach (Vertex v in General.Map.Map.Vertices) { BlockEntry block = blockmap.GetBlockAt(v.Position); // Go for all the linedefs that our vertex could overlap foreach (Linedef l in block.Lines) { if (v == l.Start || v == l.End) { continue; } if (Math.Round(l.Line.GetDistanceToLine(v.Position, true), 3) == 0) { SubmitResult(new ResultVertexOverlappingLine(v, l)); } } // Go for all the verts that our vertex could overlap foreach (Vertex bv in block.Vertices) { if (bv == v || (doneverts.ContainsKey(v) && doneverts[v].Contains(bv)) || (doneverts.ContainsKey(bv) && doneverts[bv].Contains(v))) { continue; } if (bv.Position == v.Position) { SubmitResult(new ResultVertexOverlappingVertex(v, bv)); } if (!doneverts.ContainsKey(v)) { doneverts.Add(v, new List <Vertex>()); } doneverts[v].Add(bv); } // Handle thread interruption try { Thread.Sleep(0); } catch (ThreadInterruptedException) { return; } // We are making progress! if ((++progress / PROGRESS_STEP) > stepprogress) { stepprogress = (progress / PROGRESS_STEP); AddProgress(1); } } }
private static uint FileKey(string path, ref BlockEntry b) { var filename = GetFileName(path); uint fileKey = HashString(filename, 0x300); if ((b.Flags & FileFixKey) != 0) { fileKey = (fileKey + b.FilePos) ^ b.FSize; } return(fileKey); }
private void WriteBlockEntries(BinaryWriter writer, MemoryStream blockStream, bool flushAllData, byte[] compressorBufferCache) { int dataRemainder = 0; int readPosition = 0; while (true) { dataRemainder = (int)Math.Min(blockStream.Length - readPosition, WriterBlockSizeThreshold); if (dataRemainder == 0 || (dataRemainder < WriterBlockSizeThreshold && !flushAllData)) { break; } var blockEntry = new BlockEntry() { DecompressedOffset = WriterDecompressedBlockOffset, DecompressedSize = (uint)dataRemainder, Offset = (ulong)writer.BaseStream.Position, }; // Compress long compressedSize = Utility.OodleLZ.Compress(blockStream.GetBuffer().AsSpan().Slice(readPosition, dataRemainder), compressorBufferCache); if (compressedSize == -1) { throw new Exception("Buffer compression failed"); } blockEntry.Size = (uint)compressedSize; // Encrypt if (Header.IsEncrypted) { blockEntry.XorDataBuffer(compressorBufferCache); } // Write to disk writer.Write(compressorBufferCache, 0, (int)blockEntry.Size); WriterDecompressedBlockOffset += blockEntry.DecompressedSize; readPosition += dataRemainder; BlockEntries.Add(blockEntry); } // Free MemoryStream data that was already written to prevent excessive memory consumption if (readPosition > 0 && dataRemainder > 0) { Buffer.BlockCopy(blockStream.GetBuffer(), readPosition, blockStream.GetBuffer(), 0, dataRemainder); blockStream.SetLength(blockStream.Length - readPosition); } }
public KeywordControl(BlockEntry block) { this.InitializeComponent(); ViewModel = new BlockEntryCreateModel(block); if (String.IsNullOrEmpty(ViewModel.BlockEntry.Operator)) { ViewModel.BlockEntry.Operator = MainPage.Current.Userinfo.Username; } if (!string.IsNullOrEmpty(ViewModel.BlockEntry.Keywords)) { Keywords.Document.SetText(TextSetOptions.ApplyRtfDocumentDefaults, ViewModel.BlockEntry.Keywords); } }
public static BlockEntry FromData(BinaryReader reader) { var x = new BlockEntry(); x.DecompressedOffset = reader.ReadUInt64(); // 0 x.DecompressedSize = reader.ReadUInt32(); // 8 _ = reader.ReadUInt32(); // 12 x.Offset = reader.ReadUInt64(); // 16 x.Size = reader.ReadUInt32(); // 24 _ = reader.ReadUInt32(); // 28 return(x); }
private FileMetadata WriteMergedTable(Version version, MergeEnumerator mergeEnumerator, ref int count) { var newFileMeta = new FileMetadata { FileNumber = version.GetNewFileNumber() }; var newFileInfo = new FileInfo(GetTableFileName(newFileMeta.FileNumber)); using FileStream newFileStream = newFileInfo.Create(); var creator = new TableCreator(newFileStream); byte[] smallestKey = null; byte[] largestKey = null; ReadOnlyMemory <byte> prevKey = null; while (mergeEnumerator.MoveNext()) { BlockEntry entry = mergeEnumerator.Current; count++; ReadOnlyMemory <byte> key = entry.Key; if (prevKey.Length != 0) { if (prevKey.Span.UserKey().SequenceEqual(key.Span.UserKey())) { Log.Warn($"Duplicate keys - Prev Key: {prevKey.ToHexString()}, Key: {key.ToHexString()}"); continue; } } prevKey = key; creator.Add(key.Span, entry.Data.Span); smallestKey ??= key.ToArray(); largestKey = key.ToArray(); if (creator.CurrentSize > Options.MaxTableFileSize) { break; } } creator.Finish(); newFileMeta.SmallestKey = smallestKey; newFileMeta.LargestKey = largestKey; newFileInfo.Refresh(); newFileMeta.FileSize = (ulong)newFileInfo.Length; return(newFileMeta); }
/// <summary> /// checks if this mutation blocks the addition of the otherMutation. /// </summary> /// checks if this mutation on the 'thisPart' blocks the addition of the otherMutation on the 'addPart' /// checks if this mutation on the 'thisPart' blocks the addition of the otherMutation on the 'addPart' /// <param name="otherMutation">The other mutation.</param> /// <param name="thisPart">The part this mutation is already on.</param> /// <param name="addPart">The part the otherMutation will be added to.</param> /// <returns></returns> public bool BlocksMutation([NotNull] MutationDef otherMutation, [CanBeNull] BodyPartRecord thisPart, [CanBeNull] BodyPartRecord addPart) { if (blockSites?.Contains(addPart?.def) == true) { return(true); } BlockEntry entry = blockList?.FirstOrDefault(e => e.mutation == otherMutation); if (entry == null) { return(false); } return(thisPart == addPart || entry.blockOnAnyPart); }
public override void OnDeath(Container c) { base.OnDeath(c); Mobile owner = GetMaster(); if (owner != null && m_Table.ContainsKey(owner)) { BlockEntry entry = m_Table[owner]; if (entry.m_Type >= BlockMountType.RidingSwipe && entry.m_Mount == this) { ExpireMountPrevention(owner); } } }
public void OnItemCountChanged(int value) { int v = this.BlockGrid.Children.Count; if (value > v) { BlockVisualStyle style = BlockStyle ?? BlockVisualStyle.DefaultStyle; for (int i = 0; i < value - v; ++i) { var ctrl = new BlockEntry(); style.UseStyle(ctrl); this.BlockGrid.Children.Add(ctrl); } } else if (value < v) { var length = v - value; this.BlockGrid.Children.RemoveRange(this.BlockGrid.Children.Count - length, length); } }
public static void SetMountPrevention(Mobile mob, BlockMountType type, TimeSpan duration) { if (mob == null) { return; } DateTime expiration = DateTime.Now + duration; BlockEntry entry = m_Table[mob] as BlockEntry; if (entry != null) { entry.m_Type = type; entry.m_Expiration = expiration; } else { m_Table[mob] = entry = new BlockEntry(type, expiration); } }
//private async void EditBtn_Click(object sender, RoutedEventArgs e) //{ // var block = ResultList.Where(x => x.selected).FirstOrDefault(); // if (block != null) // { // keywordControl = new KeywordControl(block); // if(keywordControl.ViewModel.KeywordsCategory.Count == 0) // keywordControl.ViewModel.KeywordsCategory.AddRange(await BlockEntryCreateModel.InitCategory()); // keywordControl.Show(); // keywordControl.AddRecordClick += KeywordControl_Refresh; // } //} private async void BlockEntryControl_EditClicked(object sender, ItemClickEventArgs e) { try { BlockEntry block = (sender as Button).DataContext as BlockEntry; if (block != null) { keywordControl = new KeywordControl(block); if (keywordControl.ViewModel.KeywordsCategory.Count == 0) { keywordControl.ViewModel.KeywordsCategory.AddRange(await BlockEntryCreateModel.InitCategory()); } keywordControl.Show(); keywordControl.AddRecordClick += KeywordControl_Refresh; } } catch (Exception ex) { MainPage.ShowErrorMessage(ex.Message); } }
public static BlockMountType GetMountPrevention(Mobile mob) { if (mob == null) { return(BlockMountType.None); } BlockEntry entry = m_Table[mob] as BlockEntry; if (entry == null) { return(BlockMountType.None); } if (entry.IsExpired) { m_Table.Remove(mob); return(BlockMountType.None); } return(entry.m_Type); }
public Packfile(string archivePath, FileMode mode = FileMode.Open) { if (mode == FileMode.Open) { ArchiveFileHandle = File.Open(archivePath, mode, FileAccess.Read, FileShare.Read); using (var reader = new BinaryReader(ArchiveFileHandle, Encoding.UTF8, true)) { Header = PackfileHeader.FromData(reader); if (Header.Magic != PackfileHeader.HardcodedMagic) { throw new InvalidDataException("Unknown header magic"); } FileEntries = new FileEntry[Header.FileEntryCount]; BlockEntries = new BlockEntry[Header.BlockEntryCount]; for (uint i = 0; i < FileEntries.Length; i++) { FileEntries[i] = FileEntry.FromData(reader); } for (uint i = 0; i < BlockEntries.Length; i++) { BlockEntries[i] = BlockEntry.FromData(reader); } } } else if (mode == FileMode.Create || mode == FileMode.CreateNew) { throw new NotImplementedException("Writing archives is not supported at the moment"); } else { throw new NotImplementedException("Archive file mode must be Open, Create, or CreateNew"); } }
private void WriteBlockEntries(BinaryWriter writer, ConcurrentBag <CompressBlock> blocks) { foreach (var block in blocks.OrderBy(x => x.DecompressedOffset)) { var blockEntry = new BlockEntry() { DecompressedOffset = block.DecompressedOffset, DecompressedSize = block.DecompressedSize, Offset = (ulong)writer.BaseStream.Position, Size = block.Size }; // Encrypt if (Header.IsEncrypted) { blockEntry.XorDataBuffer(block.CompressBuffer); } // Write to disk writer.Write(block.CompressBuffer, 0, (int)blockEntry.Size); BlockEntries.Add(blockEntry); } }
/// <summary> /// Open an archive (.bin) file and prepare for reading /// </summary> /// <param name="archivePath">Disk path</param> public PackfileReader(string archivePath) { _fileHandle = CreateReadStream(archivePath); using var reader = new BinaryReader(_fileHandle, Encoding.UTF8, true); Header = PackfileHeader.FromData(reader); _fileEntries = new List <FileEntry>((int)Header.FileEntryCount); _blockEntries = new List <BlockEntry>(Header.BlockEntryCount); Span <byte> fileData = reader.ReadBytesStrict((int)Header.FileEntryCount * FileEntry.DataHeaderSize); Span <byte> blockData = reader.ReadBytesStrict(Header.BlockEntryCount * BlockEntry.DataHeaderSize); for (int i = 0; i < (int)Header.FileEntryCount; i++) { var data = fileData.Slice(i * FileEntry.DataHeaderSize); _fileEntries.Add(FileEntry.FromData(data, Header)); } for (int i = 0; i < Header.BlockEntryCount; i++) { var data = blockData.Slice(i * BlockEntry.DataHeaderSize); _blockEntries.Add(BlockEntry.FromData(data, Header)); } }
public void UseStyle(BlockEntry target) { target.StatusColors = this.StatusColors; target.Margin = this.Margin; }
public override void Bind(Entity result, Main main, bool creating = false) { result.CannotSuspend = true; Transform transform = result.Get<Transform>(); ModelInstance model = result.Get<ModelInstance>(); model.Add(new Binding<Matrix>(model.Transform, transform.Matrix)); model.Scale.Value = Vector3.Zero; Property<bool> scale = result.GetProperty<bool>("Scale"); Property<Vector3> start = result.GetProperty<Vector3>("StartPosition"); start.Set = delegate(Vector3 value) { start.InternalValue = value; transform.Position.Value = value; }; Property<Matrix> startOrientation = result.GetProperty<Matrix>("StartOrientation"); Vector3 startEuler = Vector3.Zero; startOrientation.Set = delegate(Matrix value) { startOrientation.InternalValue = value; startEuler = Quaternion.CreateFromRotationMatrix(startOrientation).ToEuler(); transform.Orientation.Value = value; }; Property<Entity.Handle> map = result.GetProperty<Entity.Handle>("TargetMap"); Property<Map.Coordinate> coord = result.GetProperty<Map.Coordinate>("TargetCoord"); Property<int> stateId = result.GetProperty<int>("TargetCellStateID"); Property<float> totalLifetime = result.GetProperty<float>("TotalLifetime"); Property<float> lifetime = result.GetProperty<float>("Lifetime"); Updater update = null; update = new Updater { delegate(float dt) { lifetime.Value += dt; float blend = lifetime / totalLifetime; if (map.Value.Target == null || !map.Value.Target.Active) { result.Delete.Execute(); return; } Map m = map.Value.Target.Get<Map>(); if (blend > 1.0f) { if (stateId != 0) { Map.Coordinate c = coord; bool foundAdjacentCell = false; foreach (Direction dir in DirectionExtensions.Directions) { Map.Coordinate adjacent = c.Move(dir); if (m[adjacent].ID != 0) { foundAdjacentCell = true; break; } } if (foundAdjacentCell) { bool foundConflict = false; Vector3 absolutePosition = m.GetAbsolutePosition(c); foreach (Map m2 in Map.ActivePhysicsMaps) { if (m2 != m && m2[absolutePosition].Permanent) { foundConflict = true; break; } } if (!foundConflict) { Map.CellState state = m[coord]; if (state.Permanent) foundConflict = true; else { if (state.ID != 0) m.Empty(coord); m.Fill(coord, WorldFactory.States[stateId]); m.Regenerate(); Sound.PlayCue(main, "BuildBlock", transform.Position, 1.0f, 0.06f); result.Delete.Execute(); return; } } } // For one reason or another, we can't fill the cell // Animate nicely into oblivion update.Delete.Execute(); result.Add(new Animation ( new Animation.Vector3MoveTo(model.Scale, Vector3.Zero, 1.0f), new Animation.Execute(result.Delete) )); } } else { if (scale) model.Scale.Value = new Vector3(blend); else model.Scale.Value = new Vector3(1.0f); Matrix finalOrientation = m.Transform; finalOrientation.Translation = Vector3.Zero; Vector3 finalEuler = Quaternion.CreateFromRotationMatrix(finalOrientation).ToEuler(); finalEuler = Vector3.Lerp(startEuler, finalEuler, blend); transform.Orientation.Value = Matrix.CreateFromYawPitchRoll(finalEuler.X, finalEuler.Y, finalEuler.Z); Vector3 finalPosition = m.GetAbsolutePosition(coord); float distance = (finalPosition - start).Length() * 0.1f * Math.Max(0.0f, 0.5f - Math.Abs(blend - 0.5f)); transform.Position.Value = Vector3.Lerp(start, finalPosition, blend) + new Vector3((float)Math.Sin(blend * Math.PI) * distance); } }, }; result.Add(update); BlockEntry entry = new BlockEntry(); result.Add(new NotifyBinding(delegate() { if (entry.Map != null) this.animatingBlocks.Remove(entry); Entity m = map.Value.Target; entry.Map = m != null ? m.Get<Map>() : null; if (entry.Map != null) { entry.Coordinate = coord; this.animatingBlocks[entry] = true; } }, map, coord, stateId)); result.Add(new CommandBinding(result.Delete, delegate() { if (entry.Map != null) this.animatingBlocks.Remove(entry); entry.Map = null; })); this.SetMain(result, main); IBinding offsetBinding = null; model.Add(new NotifyBinding(delegate() { if (offsetBinding != null) model.Remove(offsetBinding); offsetBinding = new Binding<Vector3>(model.GetVector3Parameter("Offset"), result.GetProperty<Vector3>("Offset")); model.Add(offsetBinding); }, model.FullInstanceKey)); }
public bool IsAnimating(BlockEntry block) { return this.animatingBlocks.ContainsKey(block); }
public long GetStoredSize() { return(BlockEntry.GetBlockSize()); }
public long GetActualSize() { return(BlockEntry.GetFileSize()); }
public static void SetMountPrevention( Mobile mob, BlockMountType type, TimeSpan duration ) { if( mob == null ) return; DateTime expiration = DateTime.Now + duration; BlockEntry entry = m_Table[mob] as BlockEntry; if( entry != null ) { entry.m_Type = type; entry.m_Expiration = expiration; } else { m_Table[mob] = entry = new BlockEntry(type, expiration); } }
private static uint FileKey(string path, ref BlockEntry b) { var filename = GetFileName(path); uint fileKey = HashString(filename, 0x300); if ((b.Flags & FileFixKey) != 0) fileKey = (fileKey + b.FilePos) ^ b.FSize; return fileKey; }
public BlockFlags GetFlags() { return(BlockEntry.GetFlags()); }