/// <summary> /// Stream the field to a buffer /// </summary> /// <param name="output"></param> public override void Write(IO.EndianWriter output) { byte[] temp = new byte[Value]; temp.Initialize(); output.Write(temp); temp = null; }
public void Write(IO.EndianWriter s) { //Flags = EnumFlags.Remove(Flags, FileFlags.EncryptHeader | FileFlags.EncryptContent); s.Write(Flags, FileFlagsStreamer.Instance); s.Write((ushort)kVersion); Write(s, EnumFlags.Test(Flags, FileFlags.EncryptHeader), Header, MediaHeader.kSizeOf); GenerateHash(); if (EnumFlags.Test(Flags, FileFlags.CompressContent)) { using (var cs = new CompressedStream(true)) using (var ms = new System.IO.MemoryStream(kMaxContentSize)) using (var sout = new IO.EndianWriter(ms, Shell.EndianFormat.Big)) { sout.Write(Content); sout.Seek(0); cs.InitializeFromStream(ms); cs.Compress(); Write(s, EnumFlags.Test(Flags, FileFlags.EncryptContent), cs, userKey: Header.DataCryptKey, writeLeftovers: WriteLeftovers); } } else { s.Write(Content); } }
public void Write(IO.EndianWriter s) { foreach (var e in mEntries.Values) { e.Write(s); } }
/// <summary> /// Stream the field header data to a tag stream /// </summary> /// <param name="ts"></param> public override void WriteHeader(IO.ITagStream ts) { IO.EndianWriter s = ts.GetOutputStream(); OwnerId = ts.OwnerId; Handle.Write(s); }
public void Write(IO.EndianWriter s) { var xmbContext = s.UserData as XmbFileContext; s.Write(RootElementIndex); XmbVariantSerialization.Write(s, NameVariant); XmbVariantSerialization.Write(s, InnerTextVariant); if (xmbContext.PointerSize == Shell.ProcessorSize.x64) { s.Pad32(); } #region Attributes header s.Write(Attributes.Count); if (xmbContext.PointerSize == Shell.ProcessorSize.x64) { s.Pad32(); } mAttributesOffsetPos = s.PositionPtr; s.WriteVirtualAddress(Values.PtrHandle.InvalidHandle32); #endregion #region Children header s.Write(ChildrenIndices.Count); if (xmbContext.PointerSize == Shell.ProcessorSize.x64) { s.Pad32(); } mChildrenOffsetPos = s.PositionPtr; s.WriteVirtualAddress(Values.PtrHandle.InvalidHandle32); #endregion }
/// <summary> /// Process the reference data to a stream /// </summary> /// <param name="s">Stream</param> public override void WriteHeader(IO.EndianWriter s) { s.Write(elements.Count); headerOffset = s.PositionUnsigned; // we'll come back here and write the element's offset s.Write(-1); s.Write(0); }
public override void Write(IO.EndianWriter stream) { Compiler comp = stream.Owner as Compiler; uint elementsAddress = 0; int flags = ( (tagRef.IsNonResolving ? 1 << 1 : 0) ); if (tagRef.Elements.Count > 1) { elementsAddress = stream.PositionUnsigned; foreach (string i in tagRef.Elements) { stream.WriteTag(i); } comp.MarkLocationFixup(tagRef.Name, stream, true); stream.Write(flags); stream.Write((int)-1); stream.WritePointer(elementsAddress); } else { comp.MarkLocationFixup(tagRef.Name, stream, true); stream.Write(flags); stream.WriteTag(tagRef.Elements[0]); stream.Write((int)0); } }
public override void Write(IO.EndianWriter stream) { Compiler comp = stream.Owner as Compiler; TagBlock tb = new TagBlock((Import.TagBlock)tagGroup.Block); tb.Write(stream); comp.MarkLocationFixup(tagGroup.Name, stream, false); stream.Write(tagGroup.Name); stream.Write((int)0); stream.WriteTag(tagGroup.GroupTag); if (tagGroup.ParentTag != null) { stream.WriteTag(tagGroup.ParentTag); } else { stream.Write((int)-1); } stream.Write(tagGroup.Version); stream.Write((short)1); // init'd stream.Write((int)0); stream.Write((int)0); stream.Write((int)0); stream.Write((int)0); stream.WritePointer(tb.RuntimeAddress); for (int x = 0; x < 17; x++) { stream.Write((int)0); // child group tags } stream.Write((int)0); // we don't support that shit, gtfo stream.Write(comp.Strings.GetNull()); }
static void Read(IO.EndianReader s, bool decrypt, IO.IEndianStreamable obj, long size = 0, ulong userKey = 0, Action <IO.EndianReader> readLeftovers = null) { if (!decrypt) { obj.Read(s); } else { using (var ms = new System.IO.MemoryStream()) using (var sout = new IO.EndianWriter(ms, Shell.EndianFormat.Big)) using (var decrypted = new IO.EndianReader(ms, Shell.EndianFormat.Big)) { long position = s.BaseStream.Position; var tea = new Security.Cryptography.PhxTEA(s, sout); tea.InitializeKey(Security.Cryptography.PhxTEA.kKeyGameFile, userKey); tea.Decrypt(size); decrypted.Seek(0); obj.Read(decrypted); if (readLeftovers != null) { readLeftovers(decrypted); } } } }
static void Write(IO.EndianWriter s, bool encrypt, IO.IEndianStreamable obj, long size = 0, ulong userKey = 0, Action <IO.EndianWriter> writeLeftovers = null) { if (!encrypt) { obj.Write(s); if (writeLeftovers != null) { writeLeftovers(s); } } else { using (var ms = new System.IO.MemoryStream()) using (var sin = new IO.EndianWriter(ms, Shell.EndianFormat.Big)) using (var encrypted = new IO.EndianReader(ms, Shell.EndianFormat.Big)) { obj.Write(sin); if (writeLeftovers != null) { writeLeftovers(sin); } encrypted.Seek(0); var tea = new Security.Cryptography.PhxTEA(encrypted, s); tea.InitializeKey(Security.Cryptography.PhxTEA.kKeyGameFile, userKey); tea.Encrypt(size); } } }
public void Write(IO.EndianWriter stream) { int orgPos = stream.Position; if (address != 0) { if (offsets.Count == 0) { string name = (stream.Owner as Compiler).GetLocationName(this); Debug.LogFile.WriteLine("LocationWriteback: unused address! There are no references to '{0}'", name); } else { foreach (uint tempPos in offsets) { stream.PositionUnsigned = tempPos; stream.WritePointer(address); } } } else { string name = (stream.Owner as Compiler).GetLocationName(this); Debug.LogFile.WriteLine("LocationWriteback: failed to writeback! '{0}'s address was not set, {1} memory locations will be null!", name, offsets.Count.ToString()); } stream.Position = orgPos; }
/// <summary> /// Closes the map resources /// </summary> /// <remarks>Eg, tag manager, string id manager, IO streams, etc</remarks> public virtual void Close() { if (!CacheId.IsNull) { CloseTagIndexManager(); refManager = null; StringIdManagerDispose(); if (!IsSharedReference && InputStream != null) { InputStream.Close(); } InputStream = null; if (!IsSharedReference && OutputStream != null) { OutputStream.Close(); } OutputStream = null; CacheId = DatumIndex.Null; } }
static byte[] GenerateSoundFile(byte[] buffer, byte[] footer) { byte[] sound_file; using (MemoryStream ms = new MemoryStream()) using (IO.EndianWriter write = new IO.EndianWriter(ms)) { write.Write("RIFF", "RIFF".Length); write.Write(uint.MinValue); write.Write("WAVEdata", "WAVEdata".Length); write.Write(uint.MinValue); write.Write(buffer); if (footer != null) { write.Write(footer); } int size = (int)ms.Length; // Write file size to RIFF header write.Seek(4); write.Write(size - 8); // Write data size to WAVE header write.Seek(16); write.Write(buffer.Length); sound_file = ms.ToArray(); } return(sound_file); }
void WriteHeader(IO.EndianWriter s, IO.ITagStream ts) { headerGroupTag.Write(s); s.Write((int)state.Attribute.Version - 1); s.Write(expectedCount); s.Write(state.RuntimeSizes.SizeOf); // sizeof a single block would go here but its not actually required }
/// <summary> /// Writes each tag group's four character code /// </summary> /// <param name="s"></param> public void Write(IO.EndianWriter s) { foreach (TagGroup t in groupTags) { s.WriteTag(t.ID); } }
public void Enum_BinaryStreamerUpCastTest() { using (var ms = new System.IO.MemoryStream()) using (var br = new IO.EndianReader(ms)) using (var bw = new IO.EndianWriter(ms)) { const System.TypeCode kExpectedValue = System.TypeCode.String; var value = kExpectedValue; TypeCodeStreamer64.Write(bw, value); ms.Position = 0; TypeCodeStreamer64.Read(br, out value); Assert.IsTrue(value == kExpectedValue); ////////////////////////////////////////////////////////////////////////// // Test the instance interface var streamer_instance = TypeCodeStreamer64.Instance; ms.Position = 0; streamer_instance.Write(bw, value); ms.Position = 0; streamer_instance.Read(br, out value); Assert.IsTrue(value == kExpectedValue); } }
public void Enum_BinaryStreamerUsingUnderlyingTypeTest() { using (var ms = new System.IO.MemoryStream()) using (var br = new IO.EndianReader(ms)) using (var bw = new IO.EndianWriter(ms)) { const UInt32Enum kExpectedValue = UInt32Enum.DeadBeef; var value = kExpectedValue; UInt32EnumStreamer.Write(bw, value); ms.Position = 0; UInt32EnumStreamer.Read(br, out value); Assert.IsTrue(value == kExpectedValue); ////////////////////////////////////////////////////////////////////////// // Test the instance interface var streamer_instance = UInt32EnumStreamer.Instance; ms.Position = 0; streamer_instance.Write(bw, value); ms.Position = 0; streamer_instance.Read(br, out value); Assert.IsTrue(value == kExpectedValue); } }
/// <summary> /// Stream the field to a buffer /// </summary> /// <param name="output"></param> public override void Write(IO.EndianWriter output) { if (StringType == StringType.Normal) { output.Write(Value, false); } else if (StringType == StringType.Unicode) { output.WriteUnicodeString(Value, Length); } else if (StringType == StringType.Ascii) { output.Write(Value, Length); } else if (StringType == StringType.Halo1Profile) { output.WriteUnicodeString(Value, 12); } else if (StringType == StringType.Halo2Profile) { output.WriteUnicodeString(Value, 16); } else if (StringType == StringType.CString) { output.Write(Value, true); } }
void StreamCompressedContent(IO.EndianStream s) { if (s.IsReading) { using (var cs = new CompressedStream(true)) { Stream(s, EnumFlags.Test(Flags, FileFlags.EncryptContent), cs, userKey: Header.DataCryptKey, streamLeftovers: StreamLeftovers); cs.Decompress(); Content = cs.UncompressedData; } } else if (s.IsWriting) { using (var cs = new CompressedStream(true)) using (var ms = new System.IO.MemoryStream(kMaxContentSize)) using (var sout = new IO.EndianWriter(ms, s.ByteOrder)) { sout.Write(Content); sout.Seek(0); cs.InitializeFromStream(ms); cs.Compress(); Stream(s, EnumFlags.Test(Flags, FileFlags.EncryptContent), cs, userKey: Header.DataCryptKey, streamLeftovers: StreamLeftovers); } } }
public override void Write(IO.EndianWriter stream) { Compiler comp = stream.Owner as Compiler; #region Fields #region Byte swap codes /* * uint fieldBSCodesAddress = stream.PositionUnsigned; * stream.Write(comp.OwnerState.Definition.FieldTypes[comp.TypeIndexArrayStart].ByteSwapCodes[0]); * stream.Write((int)1); // array count * foreach (Import.Field f in fieldSet.Fields) * { * if (f.TypeIndex == comp.TypeIndexUselessPad) continue; * else if (f.TypeIndex == comp.TypeIndexPad || f.TypeIndex == comp.TypeIndexSkip) * stream.Write(f.ToInt()); * else * foreach (int x in comp.OwnerState.Definition.FieldTypes[f.TypeIndex].ByteSwapCodes) * if (x != 0) * stream.Write(x); * } * stream.Write(comp.OwnerState.Definition.FieldTypes[comp.TypeIndexArrayEnd].ByteSwapCodes[0]); */ #endregion uint fieldsAddress = stream.PositionUnsigned; Field temp = new Field(); foreach (Import.Field f in fieldSet.Fields) { temp.Reset(f); temp.Write(stream); } stream.Write(comp.TypeIndexTerminator); stream.Write((int)0); stream.Write((int)0); stream.Write((int)0); #endregion int field_set_size = fieldSet.CalculateSize(comp.OwnerState); stream.WritePointer(fieldsAddress); stream.Write((int)0); stream.Write((int)0); stream.Write((int)0); stream.Write(uint.MaxValue); stream.Write(field_set_size); stream.Write((int)0); stream.Write((int)0); stream.WritePointer(fieldsAddress); stream.Write(comp.Strings.GetNull()); stream.Write(comp.Strings.GetNull()); stream.Write(field_set_size); stream.Write((int)0); //stream.WritePointer(fieldBSCodesAddress); MiscGroups.bysw.Write(stream); stream.Write((int)0 /*1*/); stream.Write((int)0); stream.Write((int)0); stream.Write((int)0); stream.Write((int)0); }
/// <summary> /// Uses <paramref name="name"/> as a key in <see cref="Locations"/> and uses the current <see cref="IO.EndianStream.Position"/> /// in <paramref name="stream"/> to create a new entry in a <see cref="LocationWriteback"/>'s offsets list /// </summary> /// <param name="name">Location lookup key</param> /// <param name="stream">cache stream</param> protected void AddLocationFixup(string name, IO.EndianWriter stream) { if (!this.Locations.ContainsKey(name)) { this.Locations.Add(name, new LocationWriteback()); } this.Locations[name].Offsets.Add(stream.PositionUnsigned); }
/// <summary>Translate a PA to a VA and write it to a stream</summary> /// <param name="s">Stream to write to</param> /// <param name="pa">PA to translate to a VA (ie, PA - <see cref="CurrentAddress"/>)</param> /// <remarks>If <paramref name="pa"/> is a <see cref="PtrHandle.IsInvalidHandle">InvalidHandle</see>, it streamed without fix-up</remarks> public void WritePhysicalAsVirtualAddress(IO.EndianWriter s, Values.PtrHandle pa) { var va = pa.IsInvalidHandle ? pa : pa - CurrentAddress; s.WriteRawPointer(va); }
/// <summary> /// /// </summary> /// <returns></returns> /// <remarks>Caller must call the returned memory stream's <c>Close</c> method</remarks> protected System.IO.MemoryStream InitializeMemoryStream() { System.IO.MemoryStream mem = new System.IO.MemoryStream(); // the memory stream for writing all the data to a fixed base address MemoryStream = new IO.EndianWriter(mem, this); // Endian stream wrapper for memory stream MemoryStream.BaseAddress = OwnerState.Definition.MemoryInfo.BaseAddress; return(mem); }
/// <summary> /// Creates the file and opens /// it for writing /// </summary> /// <remarks>Closes existing file streams</remarks> public void CreateForWrite() { Create(); OutputStream = new BlamLib.IO.EndianWriter(path, endianState, this, true); SetupBaseAddress(); }
/// <summary> /// Opens the file for writing /// </summary> /// <remarks>Closes existing file streams</remarks> public void OpenForWrite() { Close(); OutputStream = new BlamLib.IO.EndianWriter(path, endianState, this); SetupBaseAddress(); }
protected CacheFileBase(string map_name) { InputStream = new IO.EndianReader(map_name, IO.EndianState.Little, this); if (!CacheIsReadonly(map_name)) { OutputStream = new IO.EndianWriter(map_name, IO.EndianState.Little, this); } }
void WriteFloats(IO.EndianWriter s) { Write(s, PlatoonRadius); Write(s, ProjectionTime); Write(s, OverrideGroundIKRange); Write(s, OverrideGroundIKTiltFactor); Write(s, GameSpeed); }
/// <summary> /// Write the header for this pool to a stream for future re-initializing /// and usage, storing things such as the configuration, count, etc /// </summary> /// <param name="s"></param> public void WriteHeader(IO.EndianWriter s) { Contract.Requires(s != null); // Configuration.Write(s); s.Write(Count); s.Write(Size); }
protected Compiler(BlamVersion engine) { Head = new CacheFileHeader(engine); MemoryStream = null; OwnerState = null; DebugStrings = new Util.StringPool(true); RamMemory = new BlamLib.IO.EndianWriter(new System.IO.MemoryStream(1024), this); }
protected void PostprocessHeaderThenStream(IO.EndianWriter stream, uint string_pool_base_address) { Head.BaseAddress = OwnerState.Definition.MemoryInfo.BaseAddress; Head.DataOffset = Compiler.CacheFileHeader.kMaxSize; // currently we have the data coming after the header Head.StringPoolSize = Strings.Size; Head.StringPoolAddress = string_pool_base_address; Head.Write(stream); // write the Header to the cache file }