From 39dc6d301d50037edbc6f4cc6a936d32a14afe4f Mon Sep 17 00:00:00 2001 From: Dahrkael Date: Fri, 27 Mar 2020 02:31:55 +0100 Subject: [PATCH] add support for .fxc effect files --- TRRM/TRData/ChunkFile/Chunk.cs | 8 + TRRM/TRData/ChunkFile/GBODChunk.cs | 3 +- TRRM/TRData/ChunkFile/Shaders/BIFXChunk.cs | 36 ++++ TRRM/TRData/ChunkFile/Shaders/CPFXChunk.cs | 43 +++++ TRRM/TRData/ChunkFile/Shaders/PFXDChunk.cs | 53 ++++++ .../ChunkFile/{ => Skeleton}/BDATChunk.cs | 172 +++++++++--------- .../ChunkFile/{ => Skeleton}/PBONChunk.cs | 100 +++++----- .../ChunkFile/{ => Skeleton}/PSKEChunk.cs | 90 ++++----- TRRM/TRData/ChunkFile/VERTChunk.cs | 13 +- TRRM/TRData/PackedFile.cs | 4 + 10 files changed, 338 insertions(+), 184 deletions(-) create mode 100644 TRRM/TRData/ChunkFile/Shaders/BIFXChunk.cs create mode 100644 TRRM/TRData/ChunkFile/Shaders/CPFXChunk.cs create mode 100644 TRRM/TRData/ChunkFile/Shaders/PFXDChunk.cs rename TRRM/TRData/ChunkFile/{ => Skeleton}/BDATChunk.cs (96%) rename TRRM/TRData/ChunkFile/{ => Skeleton}/PBONChunk.cs (96%) rename TRRM/TRData/ChunkFile/{ => Skeleton}/PSKEChunk.cs (95%) diff --git a/TRRM/TRData/ChunkFile/Chunk.cs b/TRRM/TRData/ChunkFile/Chunk.cs index 1f3e942..b4cbe99 100644 --- a/TRRM/TRData/ChunkFile/Chunk.cs +++ b/TRRM/TRData/ChunkFile/Chunk.cs @@ -23,6 +23,9 @@ public enum ChunkType // EFF effEffect, effVertexDecl, + effCompiledEffect, + effPrecompiledFXData, + effShaderData, // ANM anmAnimEventsImpl, anmAnim, @@ -138,6 +141,9 @@ public class ChunkUtils { ChunkType.effEffect, "EFCT" }, { ChunkType.pfxParameter, "PARM" }, { ChunkType.gfxUSDA, "USDA" }, + { ChunkType.effCompiledEffect, "CPFX" }, + { ChunkType.effPrecompiledFXData, "PFXD" }, + { ChunkType.effShaderData, "BIFX" }, }; static public string Tag( ChunkType type ) @@ -170,6 +176,8 @@ static public Chunk Instance( ChunkType type ) return new GPCEChunk(); case ChunkType.gfxGeometryPieceSkinned: return new GSKNChunk(); + case ChunkType.effCompiledEffect: + return new CPFXChunk(); } Debugger.Break(); diff --git a/TRRM/TRData/ChunkFile/GBODChunk.cs b/TRRM/TRData/ChunkFile/GBODChunk.cs index c78d10b..b8b571b 100644 --- a/TRRM/TRData/ChunkFile/GBODChunk.cs +++ b/TRRM/TRData/ChunkFile/GBODChunk.cs @@ -84,7 +84,8 @@ public override bool Load( BinaryReader reader ) for ( Int32 i = 0; i < morphCount; i++ ) { // TODO gfxMorphWeightArray - throw new NotImplementedException(); + return false; + //throw new NotImplementedException(); } Int32 piecesCount = reader.ReadInt32(); diff --git a/TRRM/TRData/ChunkFile/Shaders/BIFXChunk.cs b/TRRM/TRData/ChunkFile/Shaders/BIFXChunk.cs new file mode 100644 index 0000000..7ffbad4 --- /dev/null +++ b/TRRM/TRData/ChunkFile/Shaders/BIFXChunk.cs @@ -0,0 +1,36 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; + +namespace TRRM +{ + public class BIFXChunk : Chunk + { + public Int32 Size; + public byte[] Data; + + public override bool Load( BinaryReader reader ) + { + Start( reader ); + if ( !ReadHeader( reader ) || !IsValidVersion( 1, 3 ) ) + { + return false; + } + + Size = reader.ReadInt32(); + Data = reader.ReadBytes( Size ); + + LogInfo( "size: " + Size + " bytes" ); + + End( reader ); + return true; + } + + public override ChunkType Type() + { + return ChunkType.effShaderData; + } + } +} diff --git a/TRRM/TRData/ChunkFile/Shaders/CPFXChunk.cs b/TRRM/TRData/ChunkFile/Shaders/CPFXChunk.cs new file mode 100644 index 0000000..39efd46 --- /dev/null +++ b/TRRM/TRData/ChunkFile/Shaders/CPFXChunk.cs @@ -0,0 +1,43 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; + +namespace TRRM +{ + public class CPFXChunk : Chunk + { + public PFXDChunk PrecompiledFXData; + public BIFXChunk ShaderData; + + public override bool Load( BinaryReader reader ) + { + Start( reader ); + if ( !ReadHeader( reader ) || !IsValidVersion( 1, 3 ) ) + { + return false; + } + + PrecompiledFXData = new PFXDChunk(); + if ( !PrecompiledFXData.Load( reader ) ) + { + return false; + } + + ShaderData = new BIFXChunk(); + if ( !ShaderData.Load( reader ) ) + { + return false; + } + + End( reader ); + return true; + } + + public override ChunkType Type() + { + return ChunkType.effCompiledEffect; + } + } +} \ No newline at end of file diff --git a/TRRM/TRData/ChunkFile/Shaders/PFXDChunk.cs b/TRRM/TRData/ChunkFile/Shaders/PFXDChunk.cs new file mode 100644 index 0000000..ec4e4b1 --- /dev/null +++ b/TRRM/TRData/ChunkFile/Shaders/PFXDChunk.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; + +namespace TRRM +{ + public class PFXDChunk : Chunk + { + public UInt32 Hash; + public List Entries; + + public override bool Load( BinaryReader reader ) + { + Entries = new List(); + + Start( reader ); + if ( !ReadHeader( reader ) || !IsValidVersion( 1, 2 ) ) + { + return false; + } + + Hash = reader.ReadUInt32(); + + UInt32 count = reader.ReadUInt32(); + for ( UInt32 i = 0; i < count; i++ ) + { + assIDChunk idChunk = new assIDChunk(); + if ( !idChunk.Load( reader ) ) + { + return false; + } + + if ( Header.Version == 2 ) + { + UInt32 hash = reader.ReadUInt32(); + LogInfo( "hash: " + hash ); + } + + Entries.Add( idChunk ); + } + + End( reader ); + return true; + } + + public override ChunkType Type() + { + return ChunkType.effPrecompiledFXData; + } + } +} \ No newline at end of file diff --git a/TRRM/TRData/ChunkFile/BDATChunk.cs b/TRRM/TRData/ChunkFile/Skeleton/BDATChunk.cs similarity index 96% rename from TRRM/TRData/ChunkFile/BDATChunk.cs rename to TRRM/TRData/ChunkFile/Skeleton/BDATChunk.cs index 67d52ce..444dfcd 100644 --- a/TRRM/TRData/ChunkFile/BDATChunk.cs +++ b/TRRM/TRData/ChunkFile/Skeleton/BDATChunk.cs @@ -1,86 +1,86 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.IO; -using System.Linq; -using System.Text; - -namespace TRRM -{ - public class BDATChunk : Chunk - { - public string BoneName; - public float[] Unknown1; - public float[] Unknown2; - public float[] Unknown3; - public float[,] BoneMatrix; - public Chunk BoundingVolume; - - public override bool Load( BinaryReader reader ) - { - BoundingVolume = null; - - Start( reader ); - if ( !ReadHeader( reader ) || !IsValidVersion( 1, 2 ) ) - { - return false; - } - - BoneName = reader.ReadCString(); - Unknown1 = reader.ReadFloatArray( 4 ); - Unknown2 = reader.ReadFloatArray( 3 ); - if (Header.Version == 2) - { - Unknown3 = reader.ReadFloatArray( 3 ); - } - - BoneMatrix = reader.ReadMatrix( 4, 4 ); - - LogInfo( "name: " + BoneName ); - - ChunkType nextChunk = ChunkUtils.PeekNextChunk( reader ); - switch( nextChunk ) - { - case ChunkType.phyBone: - break; - case ChunkType.phyBVSphere: - BoundingVolume = new BVSPChunk(); - break; - case ChunkType.phyBVBox: - BoundingVolume = new BVBXChunk(); - break; - case ChunkType.phyBVAlignedCylinder: - BoundingVolume = new BVACChunk(); - break; - case ChunkType.phyBVCapsule: - BoundingVolume = new BVCPChunk(); - break; - case ChunkType.phyBVSurface: - BoundingVolume = new BVSFChunk(); - break; - case ChunkType.phyBVWalkableSurface: - BoundingVolume = new BVWSChunk(); - break; - default: - //Debugger.Break(); - break; - } - - if ( BoundingVolume != null ) - { - if ( !BoundingVolume.Load( reader ) ) - { - return false; - } - } - - End( reader ); - return true; - } - - public override ChunkType Type() - { - return ChunkType.phyBoneSharedData; - } - } -} +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.IO; +using System.Linq; +using System.Text; + +namespace TRRM +{ + public class BDATChunk : Chunk + { + public string BoneName; + public float[] Unknown1; + public float[] Unknown2; + public float[] Unknown3; + public float[,] BoneMatrix; + public Chunk BoundingVolume; + + public override bool Load( BinaryReader reader ) + { + BoundingVolume = null; + + Start( reader ); + if ( !ReadHeader( reader ) || !IsValidVersion( 1, 2 ) ) + { + return false; + } + + BoneName = reader.ReadCString(); + Unknown1 = reader.ReadFloatArray( 4 ); + Unknown2 = reader.ReadFloatArray( 3 ); + if (Header.Version == 2) + { + Unknown3 = reader.ReadFloatArray( 3 ); + } + + BoneMatrix = reader.ReadMatrix( 4, 4 ); + + LogInfo( "name: " + BoneName ); + + ChunkType nextChunk = ChunkUtils.PeekNextChunk( reader ); + switch( nextChunk ) + { + case ChunkType.phyBone: + break; + case ChunkType.phyBVSphere: + BoundingVolume = new BVSPChunk(); + break; + case ChunkType.phyBVBox: + BoundingVolume = new BVBXChunk(); + break; + case ChunkType.phyBVAlignedCylinder: + BoundingVolume = new BVACChunk(); + break; + case ChunkType.phyBVCapsule: + BoundingVolume = new BVCPChunk(); + break; + case ChunkType.phyBVSurface: + BoundingVolume = new BVSFChunk(); + break; + case ChunkType.phyBVWalkableSurface: + BoundingVolume = new BVWSChunk(); + break; + default: + //Debugger.Break(); + break; + } + + if ( BoundingVolume != null ) + { + if ( !BoundingVolume.Load( reader ) ) + { + return false; + } + } + + End( reader ); + return true; + } + + public override ChunkType Type() + { + return ChunkType.phyBoneSharedData; + } + } +} diff --git a/TRRM/TRData/ChunkFile/PBONChunk.cs b/TRRM/TRData/ChunkFile/Skeleton/PBONChunk.cs similarity index 96% rename from TRRM/TRData/ChunkFile/PBONChunk.cs rename to TRRM/TRData/ChunkFile/Skeleton/PBONChunk.cs index 7937ca8..8d30f05 100644 --- a/TRRM/TRData/ChunkFile/PBONChunk.cs +++ b/TRRM/TRData/ChunkFile/Skeleton/PBONChunk.cs @@ -1,50 +1,50 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Text; - -namespace TRRM -{ - public class PBONChunk : Chunk - { - public Int32 ParentBoneID; // not sure - public Int32 Unknown1; - public Int32 Unknown2; - public float Unknown3; - BDATChunk BoneData; - - public override bool Load( BinaryReader reader ) - { - Start( reader ); - if ( !ReadHeader( reader ) || !IsValidVersion( 1 ) ) - { - return false; - } - - ParentBoneID = reader.ReadInt32(); - Unknown1 = reader.ReadInt32(); - Unknown2 = reader.ReadInt32(); - Unknown3 = reader.ReadSingle(); - - LogInfo( "parent id: " + ParentBoneID ); - LogInfo( "unk1: " + Unknown1 ); - LogInfo( "unk2: " + Unknown2 ); - LogInfo( "unk3: " + Unknown3 ); - - BoneData = new BDATChunk(); - if ( !BoneData.Load( reader ) ) - { - return false; - } - - End( reader ); - return true; - } - - public override ChunkType Type() - { - return ChunkType.phyBone; - } - } -} +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; + +namespace TRRM +{ + public class PBONChunk : Chunk + { + public Int32 ParentBoneID; // not sure + public Int32 Unknown1; + public Int32 Unknown2; + public float Unknown3; + BDATChunk BoneData; + + public override bool Load( BinaryReader reader ) + { + Start( reader ); + if ( !ReadHeader( reader ) || !IsValidVersion( 1 ) ) + { + return false; + } + + ParentBoneID = reader.ReadInt32(); + Unknown1 = reader.ReadInt32(); + Unknown2 = reader.ReadInt32(); + Unknown3 = reader.ReadSingle(); + + LogInfo( "parent id: " + ParentBoneID ); + LogInfo( "unk1: " + Unknown1 ); + LogInfo( "unk2: " + Unknown2 ); + LogInfo( "unk3: " + Unknown3 ); + + BoneData = new BDATChunk(); + if ( !BoneData.Load( reader ) ) + { + return false; + } + + End( reader ); + return true; + } + + public override ChunkType Type() + { + return ChunkType.phyBone; + } + } +} diff --git a/TRRM/TRData/ChunkFile/PSKEChunk.cs b/TRRM/TRData/ChunkFile/Skeleton/PSKEChunk.cs similarity index 95% rename from TRRM/TRData/ChunkFile/PSKEChunk.cs rename to TRRM/TRData/ChunkFile/Skeleton/PSKEChunk.cs index 3a542e8..e70bfc1 100644 --- a/TRRM/TRData/ChunkFile/PSKEChunk.cs +++ b/TRRM/TRData/ChunkFile/Skeleton/PSKEChunk.cs @@ -1,45 +1,45 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Text; - -namespace TRRM -{ - public class PSKEChunk : Chunk - { - List Bones; - - public override bool Load( BinaryReader reader ) - { - Bones = new List(); - - Start( reader ); - if ( !ReadHeader( reader ) || !IsValidVersion( 1 ) ) - { - return false; - } - - UInt32 count = reader.ReadUInt32(); - LogInfo( "bone count: " + count ); - - for ( UInt32 i = 0; i < count; i++ ) - { - PBONChunk bone = new PBONChunk(); - if ( !bone.Load( reader ) ) - { - return false; - } - Bones.Add( bone ); - } - - End( reader ); - return true; - } - - public override ChunkType Type() - { - return ChunkType.phySkeleton; - } - } -} +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; + +namespace TRRM +{ + public class PSKEChunk : Chunk + { + List Bones; + + public override bool Load( BinaryReader reader ) + { + Bones = new List(); + + Start( reader ); + if ( !ReadHeader( reader ) || !IsValidVersion( 1 ) ) + { + return false; + } + + UInt32 count = reader.ReadUInt32(); + LogInfo( "bone count: " + count ); + + for ( UInt32 i = 0; i < count; i++ ) + { + PBONChunk bone = new PBONChunk(); + if ( !bone.Load( reader ) ) + { + return false; + } + Bones.Add( bone ); + } + + End( reader ); + return true; + } + + public override ChunkType Type() + { + return ChunkType.phySkeleton; + } + } +} diff --git a/TRRM/TRData/ChunkFile/VERTChunk.cs b/TRRM/TRData/ChunkFile/VERTChunk.cs index 921faea..66d5b04 100644 --- a/TRRM/TRData/ChunkFile/VERTChunk.cs +++ b/TRRM/TRData/ChunkFile/VERTChunk.cs @@ -15,12 +15,15 @@ public class VERTChunk : Chunk public List UVs; public List Colors; + public byte[] RawBuffer; + public override bool Load( BinaryReader reader ) { Vertices = new List(); Normals = new List(); UVs = new List(); Colors = new List(); + RawBuffer = new byte[0]; Start( reader ); if ( !ReadHeader( reader ) || !IsValidVersion( 1, 2, 3 ) ) @@ -45,7 +48,8 @@ public override bool Load( BinaryReader reader ) } Int32 count = reader.ReadInt32(); - LogInfo( "vertices offset: " + reader.BaseStream.Position ); + Int64 verticesOffset = reader.BaseStream.Position; + LogInfo( "vertices offset: " + verticesOffset ); for (Int32 i = 0; i < count; i++ ) { @@ -79,9 +83,14 @@ public override bool Load( BinaryReader reader ) } } } - + LogInfo( "vertex count: " + count ); + // rewind and grab the full buffer + RawBuffer = new byte[ reader.BaseStream.Position - verticesOffset ]; + reader.BaseStream.Seek( verticesOffset, SeekOrigin.Begin ); + reader.ReadBytes( RawBuffer.Length ); + End( reader ); return true; } diff --git a/TRRM/TRData/PackedFile.cs b/TRRM/TRData/PackedFile.cs index 55be26f..9885901 100644 --- a/TRRM/TRData/PackedFile.cs +++ b/TRRM/TRData/PackedFile.cs @@ -43,6 +43,8 @@ public enum TRFileType MP3, OGG, WAV, + XML, + FXC, Other } @@ -78,6 +80,8 @@ public TRFileType GetFileType() if ( Filename.EndsWith( ".mp3" ) ) return TRFileType.MP3; if ( Filename.EndsWith( ".ogg" ) ) return TRFileType.OGG; if ( Filename.EndsWith( ".wav" ) ) return TRFileType.WAV; + if ( Filename.EndsWith( ".xml" ) ) return TRFileType.XML; + if ( Filename.EndsWith( ".fxc" ) ) return TRFileType.FXC; return TRFileType.Other; }