public void Write(BinaryWriter bw) { for (var i = 0; i < Pixels.Length; i++) { bw.WriteUInt16Array(Pixels[i]); } }
public void Write(BinaryWriter bw, Engine ver = Engine.Unknown) { bw.WriteUInt16Array(Vertices); bw.Write(Texture); if (ver >= Engine.TR4) bw.Write(Lighting); }
public void Write(BinaryWriter bw, Engine ver = Engine.Unknown) { var arrSize = ver < Engine.TR2 ? 2 : 4; bw.Write(FlyZoneNormal); bw.WriteUInt16Array(GroundZonesNormal.Resize(arrSize)); bw.WriteUInt16Array(GroundZonesAlternate.Resize(arrSize)); bw.Write(FlyZoneAlternate); }
private void Write_TR4() { writer.Write((uint)(WriteIsDemoOrUb ? 0x63345254 : 0x00345254)); writer.Write((ushort)Textures.Length); writer.Write((ushort)0); writer.Write((ushort)0); byte[] buf; using (var ms = new MemoryStream()) { using (var bw = new BinaryWriter(ms)) bw.WriteArray(Textures, x => x.Write(bw)); buf = ms.ToArray(); } writer.Write((uint)buf.Length); // uncompSize var bufComp = Helper.Encompress(buf); writer.Write((uint)bufComp.Length); // compSize writer.Write(bufComp); using (var ms = new MemoryStream()) { using (var bw = new BinaryWriter(ms)) bw.WriteArray(Texture16, x => x.Write(bw)); buf = ms.ToArray(); } writer.Write((uint)buf.Length); // uncompSize bufComp = Helper.Encompress(buf); writer.Write((uint)bufComp.Length); // compSize writer.Write(bufComp); using (var ms = new MemoryStream()) { using (var bw = new BinaryWriter(ms)) bw.WriteArray(Textures.Skip(Textures.Length - 2).Take(2), x => x.Write(bw)); buf = ms.ToArray(); } writer.Write((uint)buf.Length); // uncompSize bufComp = Helper.Encompress(buf); writer.Write((uint)bufComp.Length); // compSize writer.Write(bufComp); // Here be dragons using (var ms = new MemoryStream()) { using (var bw = new BinaryWriter(ms)) { bw.Write((uint)0); // unused bw.Write((ushort)Rooms.Length); bw.WriteArray(Rooms, x => x.Write(bw, Engine.TR4)); bw.Write((uint)FloorData.Length); bw.WriteUInt16Array(FloorData); var tmpw = writer; writer = bw; WriteMeshData(); writer = tmpw; bw.Write((uint)Animations.Length); bw.WriteArray(Animations, x => x.Write(bw, Engine.TR4)); bw.Write((uint)StateChanges.Length); bw.WriteArray(StateChanges, x => x.Write(bw)); bw.Write((uint)AnimDispatches.Length); bw.WriteArray(AnimDispatches, x => x.Write(bw)); bw.Write((uint)AnimCommands.Length); bw.WriteInt16Array(AnimCommands); bw.Write((uint)MeshTreeData.Length); bw.WriteUInt32Array(MeshTreeData); tmpw = writer; writer = bw; WriteFrameMoveableData(); writer = tmpw; bw.Write((uint)StaticMeshes.Length); bw.WriteArray(StaticMeshes, x => x.Write(bw)); bw.Write((sbyte)'S'); bw.Write((sbyte)'P'); bw.Write((sbyte)'R'); bw.Write((uint)SpriteTextures.Length); bw.WriteArray(SpriteTextures, x => x.Write(bw, Engine.TR4)); bw.Write((uint)SpriteSequences.Length); bw.WriteArray(SpriteSequences, x => x.Write(bw)); bw.Write((uint)Cameras.Length); bw.WriteArray(Cameras, x => x.Write(bw)); bw.Write((uint)FlybyCameras.Length); bw.WriteArray(FlybyCameras, x => x.Write(bw)); bw.Write((uint)SoundSources.Length); bw.WriteArray(SoundSources, x => x.Write(bw)); bw.Write((uint)Boxes.Length); bw.WriteArray(Boxes, x => x.Write(bw, Engine.TR2)); bw.Write((uint)Overlaps.Length); bw.WriteUInt16Array(Overlaps); bw.WriteArray(Zones, x => x.Write(bw, Engine.TR2)); bw.Write((uint)AnimatedTextures.Length); bw.WriteUInt16Array(AnimatedTextures); bw.Write((byte)AnimatedTexturesUVCount); bw.Write((sbyte)'T'); bw.Write((sbyte)'E'); bw.Write((sbyte)'X'); bw.Write((uint)ObjectTextures.Length); bw.WriteArray(ObjectTextures, x => x.Write(bw, Engine.TR4)); bw.Write((uint)Items.Length); bw.WriteArray(Items, x => x.Write(bw, Engine.TR4)); bw.Write((uint)AIObjects.Length); bw.WriteArray(AIObjects, x => x.Write(bw)); bw.Write((ushort)DemoData.Length); bw.Write(DemoData); bw.WriteInt16Array(SoundMap.Resize(Constants.TR_AUDIO_MAP_SIZE_TR4)); bw.Write((uint)SoundDetails.Length); bw.WriteArray(SoundDetails, x => x.Write(bw, Engine.TR3)); bw.Write((uint)SampleIndices.Length); bw.WriteUInt32Array(SampleIndices); } buf = ms.ToArray(); } writer.Write((uint)buf.Length); // uncompSize bufComp = Helper.Encompress(buf); writer.Write((uint)bufComp.Length); // compSize writer.Write(bufComp); writer.Write((uint)SamplesCount); writer.Write(SamplesData); }
public void Write(BinaryWriter bw) { bw.Write(NumGenericStrings); bw.Write(NumPSXStrings); bw.Write(NumPCStrings); bw.Write(GenericStrings.Sum(x => Encoding.ASCII.GetByteCount(x) + 1)); bw.Write(PSXStrings.Sum(x => Encoding.ASCII.GetByteCount(x) + 1)); bw.Write(PCStrings.Sum(x => Encoding.ASCII.GetByteCount(x) + 1)); var stringOTpos = bw.BaseStream.Position; var stringOffsetTable = new ushort[StringTable.Length]; var stringStart = bw.BaseStream.Position + StringTable.Length * sizeof (ushort); bw.BaseStream.Position = stringStart; for (var i = 0; i < StringTable.Length; i++) { stringOffsetTable[i] = (ushort) (bw.BaseStream.Position - stringStart); bw.WriteStringASCII(StringTable[i]); bw.Write((byte)0x00); // null-terminator } bw.BaseStream.Position = stringOTpos; bw.WriteUInt16Array(stringOffsetTable); }
public void Write(BinaryWriter bw, bool psx = false) { bw.Write((uint) GameVersion); bw.WriteStringASCII(CopyrightInfo, 256); bw.Write((ushort) 128); // gameflowSize bw.Write(FirstOption); bw.Write(TitleReplace); bw.Write(OnDeathDemoMode); bw.Write(OnDeathInGame); bw.Write(DemoTime); bw.Write(OnDemoInterrupt); bw.Write(OnDemoEnd); bw.Write(new byte[36]); // Unknown2 bw.Write(NumLevels); bw.Write(NumChapterScreens); bw.Write(NumTitles); bw.Write(NumFMVs); bw.Write(NumCutscenes); bw.Write(NumDemoLevels); bw.Write(TitleSoundID); bw.Write(SingleLevel); bw.Write(new byte[32]); // Unknown3 bw.Write((ushort) Flags); bw.Write(new byte[6]); // Unknown4 bw.Write(XORbyte); bw.Write((byte) Language); bw.Write(SecretSoundID); bw.Write(new byte[4]); // Unknown5 var xor = Flags.HasFlag(TOMBPCFlags.UseEncryption) ? XORbyte : (byte)0; bw.WriteStringArray(LevelDisplayNames, xor); bw.WriteStringArray(ChapterScreens, xor); bw.WriteStringArray(TitleFileNames, xor); bw.WriteStringArray(FMVFileNames, xor); bw.WriteStringArray(LevelFileNames, xor); bw.WriteStringArray(CutSceneFileNames, xor); var scrOffsets = new ushort[NumLevels + 1]; ushort totalOffset = 0; for (var i = 0; i <= NumLevels; i++) { scrOffsets[i] = totalOffset; totalOffset += (ushort)(Script[i].Length * 2); } bw.WriteUInt16Array(scrOffsets); bw.Write((ushort)0); var nbPos = bw.BaseStream.Position; foreach (var a in Script.Resize(NumLevels + 1)) bw.WriteUInt16Array(a); var tp = bw.BaseStream.Position; bw.BaseStream.Position = nbPos - 2; bw.Write((ushort)(tp - nbPos)); bw.BaseStream.Position = tp; bw.WriteUInt16Array(DemoLevelIDs); if (psx) { bw.WriteArray(PSXFMVInfo.Resize(NumFMVs), x => x.Write(bw)); } bw.Write((ushort) GameStrings1.Length); bw.WriteStringArray(GameStrings1, xor); bw.WriteStringArray(GameStrings2, xor); foreach (var puz in Puzzles.Resize(4)) bw.WriteStringArray(puz.Resize(NumLevels), xor); foreach (var puz in Pickups.Resize(2)) bw.WriteStringArray(puz.Resize(NumLevels), xor); foreach (var puz in Keys.Resize(4)) bw.WriteStringArray(puz.Resize(NumLevels), xor); }