private unsafe void exportToolStripMenuItem_Click(object sender, EventArgs e) { BrawlBoxViewerSettings settings = CollectSettings(); SaveFileDialog sd = new SaveFileDialog(); sd.Filter = "Brawlbox Settings (*.settings)|*.settings"; sd.FileName = Application.StartupPath; if (sd.ShowDialog() == DialogResult.OK) { string path = sd.FileName; using (FileStream stream = new FileStream(path, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite, 8, FileOptions.SequentialScan)) { CompactStringTable s = new CompactStringTable(); s.Add(ScreenCapBgLocText.Text); stream.SetLength((long)BrawlBoxViewerSettings.Size + s.TotalSize); using (FileMap map = FileMap.FromStream(stream)) { *(BrawlBoxViewerSettings *)map.Address = settings; s.WriteTable(map.Address + BrawlBoxViewerSettings.Size); ((BrawlBoxViewerSettings *)map.Address)->_screenCapPathOffset = (uint)s[ScreenCapBgLocText.Text] - (uint)map.Address; } } MessageBox.Show("Settings successfully saved to " + path); } }
public override unsafe void Export(string outPath) { int length = 12 + (_numEntries != 0 ? _colors.Count * 4 : 4); using (FileStream stream = new FileStream(outPath, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None, 8, FileOptions.RandomAccess)) { stream.SetLength(length); using (FileMap map = FileMap.FromStream(stream)) { CLR0MaterialEntry *entry = (CLR0MaterialEntry *)map.Address; entry->_colorMask = _colorMask; entry->_data = 8; *((bint *)entry + 2) = _numEntries; RGBAPixel *pData = entry->Data; if (_numEntries != 0) { foreach (ARGBPixel p in _colors) { *pData++ = (RGBAPixel)p; } } else { *pData = _solidColor; } } } }
public void Export(string filePath) { FileStream outStream = new FileStream(filePath, FileMode.Open, FileAccess.ReadWrite); outStream.SetLength(Length); using (FileMap map = FileMap.FromStream(outStream)) Win32.MoveMemory(map.Address, Address, (uint)Length); }
public override unsafe void Export(string outPath) { using (FileStream stream = new FileStream(outPath, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None, 8, FileOptions.RandomAccess)) { stream.SetLength(_dataBuffer.Length); using (FileMap map = FileMap.FromStream(stream)) Memory.Move(map.Address, _dataBuffer.Address, (uint)_dataBuffer.Length); } }
public override unsafe void Export(string outPath) { int dataLen = OnCalculateSize(true); using (FileStream stream = new FileStream(outPath, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None, 8, FileOptions.RandomAccess)) { stream.SetLength(dataLen); using (FileMap map = FileMap.FromStream(stream)) AnimationConverter.EncodeSRT0Keyframes(Keyframes, map.Address, map.Address + _entryLen, _code); } }
public override unsafe void Export(string outPath) { int length = OnCalculateSize(true); using (FileStream stream = new FileStream(outPath, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None, 8, FileOptions.RandomAccess)) { stream.SetLength(length); using (FileMap map = FileMap.FromStream(stream)) OnRebuild(map.Address, length, true); } }
public override void Export(string outPath) { StringTable table = new StringTable() { Name }; int totalLength = OnCalculateSize(true) + table.GetTotalSize(); using (FileStream stream = new FileStream(outPath, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None, 8, FileOptions.RandomAccess)) { stream.SetLength(totalLength); using (FileMap map = FileMap.FromStream(stream)) { _dataAddr = map.Address + _entryLength; Rebuild(map.Address, totalLength, true); table.WriteTable(_dataAddr + _dataLength); PostProcess(map.Address, table); } } //string temp1 = Path.GetTempFileName(); //string temp2 = Path.GetTempFileName(); //Parent.Rebuild(); //Parent.Export(temp1); //int index = Parent.Children.IndexOf(this); //using (ResourceNode copied = NodeFactory.FromFile(null, temp1)) { // for (int i = 0; i < index; i++) { // copied.RemoveChild(copied.Children[0]); // } // while (copied.Children.Count > 1) { // copied.RemoveChild(copied.Children[1]); // } // copied.Export(temp2); //} //using (ResourceNode copied = NodeFactory.FromFile(null, temp2)) { // SRT0EntryNode entry = (SRT0EntryNode)copied.Children[0]; // int dataLen = entry.OnCalculateSize(true); // using (FileStream stream = new FileStream(outPath, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None, 8, FileOptions.RandomAccess)) { // stream.SetLength(dataLen); // using (FileMap map = FileMap.FromStream(stream)) // Memory.Move(map.Address, entry.WorkingSource.Address, (uint)dataLen); // } //} //File.Delete(temp1); //File.Delete(temp2); }
public void ExportUncompressed(FileStream outStream) { if (WorkingUncompressed.Length != 0) { outStream.SetLength(WorkingUncompressed.Length); using (FileMap map = FileMap.FromStream(outStream)) Memory.Move(map.Address, WorkingUncompressed.Address, (uint)WorkingUncompressed.Length); } else { MessageBox.Show("Data was empty!"); } }
public unsafe void ExportInitialized(string outPath) { using (FileStream stream = new FileStream(outPath, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None, 8, FileOptions.RandomAccess)) { stream.SetLength(_dataBuffer.Length); using (FileMap map = FileMap.FromStream(stream)) { buint *addr = (buint *)map.Address; foreach (Relocation loc in Relocations) { *addr++ = loc.SectionOffset; } } } }
public override unsafe void Export(string outPath) { using (FileStream stream = new FileStream(outPath, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None, 8, FileOptions.RandomAccess)) { stream.SetLength(_dataBuffer.Length); using (FileMap map = FileMap.FromStream(stream)) { VoidPtr addr = _dataBuffer.Address; byte *pIn = (byte *)addr; byte *pOut = (byte *)map.Address; for (int i = 0; i < _dataBuffer.Length; i++) { *pOut++ = *pIn++; } } } }
public void ExportCompressed(string outPath) { if (_compression != CompressionType.None) { base.Export(outPath); } else { using (FileStream inStream = new FileStream(Path.GetTempFileName(), FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None, 0x8, FileOptions.SequentialScan | FileOptions.DeleteOnClose)) using (FileStream outStream = new FileStream(outPath, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None, 8, FileOptions.SequentialScan)) { Compressor.Compact(CompressionType.RunLengthYAZ0, WorkingUncompressed.Address, WorkingUncompressed.Length, inStream, this); outStream.SetLength(inStream.Length); using (FileMap map = FileMap.FromStream(inStream)) using (FileMap outMap = FileMap.FromStream(outStream)) Memory.Move(outMap.Address, map.Address, (uint)map.Length); } } }
public override unsafe void Export(string outPath) { StringTable table = new StringTable(); GetStrings(table); int dataLen = OnCalculateSize(true); int totalLen = dataLen + table.GetTotalSize(); using (FileStream stream = new FileStream(outPath, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None, 8, FileOptions.RandomAccess)) { stream.SetLength(totalLen); using (FileMap map = FileMap.FromStream(stream)) { Rebuild(map.Address, dataLen, false); table.WriteTable(map.Address + dataLen); PostProcess(map.Address, map.Address, table); } } }
public override unsafe void Export(string outPath) { StringTable table = new StringTable(); table.Add(_name); int dataLen = OnCalculateSize(true); int totalLen = dataLen + table.GetTotalSize(); using (FileStream stream = new FileStream(outPath, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None, 8, FileOptions.RandomAccess)) { stream.SetLength(totalLen); using (FileMap map = FileMap.FromStream(stream)) { AnimationConverter.EncodeKeyframes(Keyframes, map.Address, map.Address + _entryLen); table.WriteTable(map.Address + dataLen); PostProcess(map.Address, table); } } }
public void ExportPatched() { string outPath; int index = Program.SaveFile(ExportFilter, Text, out outPath); if (index != 0) { if (Parent == null) { _resource.Merge(Control.ModifierKeys == (Keys.Control | Keys.Shift)); } //_resource.Rebuild(); HavokNode p = _resource as HavokNode; using (FileStream stream = new FileStream(outPath, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite, 8, FileOptions.SequentialScan)) { stream.SetLength(p._buffer.Length); using (FileMap map = FileMap.FromStream(stream)) Memory.Move(map.Address, p._buffer.Address, (uint)p._buffer.Length); } } }
public override unsafe void Export(string outPath) { Rebuild(); StringTable table = new StringTable(); GetStrings(table); int dataLen = WorkingUncompressed.Length.Align(4); int size = dataLen + table.GetTotalSize(); using (FileStream stream = new FileStream(outPath, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None, 8, FileOptions.RandomAccess)) { stream.SetLength(size); using (FileMap map = FileMap.FromStream(stream)) { System.Memory.Move(map.Address, WorkingUncompressed.Address, (uint)WorkingUncompressed.Length); table.WriteTable(map.Address + dataLen); PostProcess(null, map.Address, WorkingUncompressed.Length, table); } } table.Clear(); }
public static unsafe void ToStream(Bitmap bmp, FileStream stream) { int w = bmp.Width, h = bmp.Height; TGAHeader header = new TGAHeader(); TGAFooter footer = new TGAFooter(0, 0); PaletteEncoder pEnc = null; ColorParser cEnc = null; ColorPalette pal = null; header.imageSpecification.width = (ushort)w; header.imageSpecification.height = (ushort)h; header.imageType = TGAImageType.UncompressedTrueColor; switch (bmp.PixelFormat) { case PixelFormat.Format4bppIndexed: case PixelFormat.Format8bppIndexed: { pal = bmp.Palette; header.colorMapType = 1; header.imageType = TGAImageType.UncompressedColorMapped; header.colorMapSpecification.length = (ushort)pal.Entries.Length; header.colorMapSpecification.entrySize = 24; header.imageSpecification.pixelDepth = 8; pEnc = (ref VoidPtr ptr, Color c) => { *(RGBPixel *)ptr = (RGBPixel)c; ptr += 3; }; if (bmp.PixelFormat == PixelFormat.Format4bppIndexed) { cEnc = delegate(VoidPtr sPtr, int sIndex, VoidPtr dPtr, int dIndex) { ((byte *)dPtr)[dIndex] = ((sIndex & 1) == 0) ? (byte)(((byte *)sPtr)[sIndex >> 1] >> 4) : (byte)(((byte *)sPtr)[sIndex >> 1] & 0xF); } } ; else { cEnc = delegate(VoidPtr sPtr, int sIndex, VoidPtr dPtr, int dIndex) { ((byte *)dPtr)[dIndex] = ((byte *)sPtr)[sIndex]; } }; break; } case PixelFormat.Format32bppRgb: case PixelFormat.Format32bppArgb: { header.imageSpecification.pixelDepth = 32; header.imageSpecification.AlphaBits = (bmp.PixelFormat == PixelFormat.Format32bppArgb) ? (byte)8 : (byte)0; cEnc = delegate(VoidPtr sPtr, int sIndex, VoidPtr dPtr, int dIndex) { ((ARGBPixel *)dPtr)[dIndex] = ((ARGBPixel *)sPtr)[sIndex]; }; break; } case PixelFormat.Format24bppRgb: { header.imageSpecification.pixelDepth = 24; cEnc = delegate(VoidPtr sPtr, int sIndex, VoidPtr dPtr, int dIndex) { ((RGBPixel *)dPtr)[dIndex] = ((RGBPixel *)sPtr)[sIndex]; }; break; } case PixelFormat.Format16bppRgb555: { header.imageSpecification.pixelDepth = 15; cEnc = delegate(VoidPtr sPtr, int sIndex, VoidPtr dPtr, int dIndex) { ((RGB555Pixel *)dPtr)[dIndex] = ((RGB555Pixel *)sPtr)[sIndex]; }; break; } case PixelFormat.Format16bppArgb1555: { header.imageSpecification.pixelDepth = 16; header.imageSpecification.AlphaBits = 1; cEnc = delegate(VoidPtr sPtr, int sIndex, VoidPtr dPtr, int dIndex) { ((RGB555Pixel *)dPtr)[dIndex] = ((RGB555Pixel *)sPtr)[sIndex]; }; break; } default: throw new FormatException("Input pixel format unsupported."); } int mapLen = header.colorMapSpecification.DataLength; int dataLen = header.imageSpecification.DataLength; int totalLen = TGAHeader.Size + mapLen + dataLen + TGAFooter.Size; stream.SetLength(totalLen); BitmapData data = bmp.LockBits(new Rectangle(0, 0, w, h), ImageLockMode.ReadOnly, bmp.PixelFormat); //using (FileStream stream = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.None, 0x1000, FileOptions.RandomAccess)) using (FileMap view = FileMap.FromStream(stream))// stream.MapView(0, (uint)totalLen, FileMapProtect.ReadWrite)) { //Create header TGAHeader *pHeader = (TGAHeader *)view.Address; * pHeader = header; //Write id //Write color map if (pal != null) { VoidPtr pMap = pHeader->ColorMapData; for (int i = 0; i < pal.Entries.Length; i++) { pEnc(ref pMap, pal.Entries[i]); } } //Write color data int dstStride = (pHeader->imageSpecification.pixelDepth * w).Align(8) / 8; int origin = (int)pHeader->imageSpecification.ImageOrigin; int xStep = ((origin & 1) == 0) ? 1 : -1; int yStep = ((origin & 2) != 0) ? 1 : -1; byte *imgDst = pHeader->ImageData; for (int sY = (yStep == 1) ? 0 : h - 1, dY = 0; dY < h; sY += yStep, dY++) { VoidPtr imgSrc = (VoidPtr)data.Scan0 + (data.Stride * sY); //Do RLE encoding for (int sX = (xStep == 1) ? 0 : w - 1, dX = 0; dX < w; sX += xStep, dX++) { cEnc(imgSrc, sX, imgDst, dX); } imgDst += dstStride; } //Write footer TGAFooter *pFooter = (TGAFooter *)(pHeader->ImageData + pHeader->imageSpecification.DataLength); * pFooter = footer; } bmp.UnlockBits(data); }
public void ExportUncompressed(FileStream outStream) { outStream.SetLength(WorkingUncompressed.Length); using (FileMap map = FileMap.FromStream(outStream)) Memory.Move(map.Address, WorkingUncompressed.Address, (uint)WorkingUncompressed.Length); }