Skip to content

Commit a4e0f2f

Browse files
committed
add support for .fxc effect files
1 parent 9217cc0 commit a4e0f2f

File tree

11 files changed

+344
-187
lines changed

11 files changed

+344
-187
lines changed

TRRM/TRData/ChunkFile/Chunk.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ public enum ChunkType
2323
// EFF
2424
effEffect,
2525
effVertexDecl,
26+
effCompiledEffect,
27+
effPrecompiledFXData,
28+
effShaderData,
2629
// ANM
2730
anmAnimEventsImpl,
2831
anmAnim,
@@ -138,6 +141,9 @@ public class ChunkUtils
138141
{ ChunkType.effEffect, "EFCT" },
139142
{ ChunkType.pfxParameter, "PARM" },
140143
{ ChunkType.gfxUSDA, "USDA" },
144+
{ ChunkType.effCompiledEffect, "CPFX" },
145+
{ ChunkType.effPrecompiledFXData, "PFXD" },
146+
{ ChunkType.effShaderData, "BIFX" },
141147
};
142148

143149
static public string Tag( ChunkType type )
@@ -170,6 +176,8 @@ static public Chunk Instance( ChunkType type )
170176
return new GPCEChunk();
171177
case ChunkType.gfxGeometryPieceSkinned:
172178
return new GSKNChunk();
179+
case ChunkType.effCompiledEffect:
180+
return new CPFXChunk();
173181
}
174182

175183
Debugger.Break();

TRRM/TRData/ChunkFile/GBODChunk.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ public override bool Load( BinaryReader reader )
8484
for ( Int32 i = 0; i < morphCount; i++ )
8585
{
8686
// TODO gfxMorphWeightArray
87-
throw new NotImplementedException();
87+
return false;
88+
//throw new NotImplementedException();
8889
}
8990

9091
Int32 piecesCount = reader.ReadInt32();
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using System.Linq;
5+
using System.Text;
6+
7+
namespace TRRM
8+
{
9+
public class BIFXChunk : Chunk
10+
{
11+
public Int32 Size;
12+
public byte[] Data;
13+
14+
public override bool Load( BinaryReader reader )
15+
{
16+
Start( reader );
17+
if ( !ReadHeader( reader ) || !IsValidVersion( 1, 3 ) )
18+
{
19+
return false;
20+
}
21+
22+
Size = reader.ReadInt32();
23+
Data = reader.ReadBytes( Size );
24+
25+
LogInfo( "size: " + Size + " bytes" );
26+
27+
End( reader );
28+
return true;
29+
}
30+
31+
public override ChunkType Type()
32+
{
33+
return ChunkType.effShaderData;
34+
}
35+
}
36+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using System.Linq;
5+
using System.Text;
6+
7+
namespace TRRM
8+
{
9+
public class CPFXChunk : Chunk
10+
{
11+
public PFXDChunk PrecompiledFXData;
12+
public BIFXChunk ShaderData;
13+
14+
public override bool Load( BinaryReader reader )
15+
{
16+
Start( reader );
17+
if ( !ReadHeader( reader ) || !IsValidVersion( 1, 3 ) )
18+
{
19+
return false;
20+
}
21+
22+
PrecompiledFXData = new PFXDChunk();
23+
if ( !PrecompiledFXData.Load( reader ) )
24+
{
25+
return false;
26+
}
27+
28+
ShaderData = new BIFXChunk();
29+
if ( !ShaderData.Load( reader ) )
30+
{
31+
return false;
32+
}
33+
34+
End( reader );
35+
return true;
36+
}
37+
38+
public override ChunkType Type()
39+
{
40+
return ChunkType.effCompiledEffect;
41+
}
42+
}
43+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using System.Linq;
5+
using System.Text;
6+
7+
namespace TRRM
8+
{
9+
public class PFXDChunk : Chunk
10+
{
11+
public UInt32 Hash;
12+
public List<assIDChunk> Entries;
13+
14+
public override bool Load( BinaryReader reader )
15+
{
16+
Entries = new List<assIDChunk>();
17+
18+
Start( reader );
19+
if ( !ReadHeader( reader ) || !IsValidVersion( 1, 2 ) )
20+
{
21+
return false;
22+
}
23+
24+
Hash = reader.ReadUInt32();
25+
26+
UInt32 count = reader.ReadUInt32();
27+
for ( UInt32 i = 0; i < count; i++ )
28+
{
29+
assIDChunk idChunk = new assIDChunk();
30+
if ( !idChunk.Load( reader ) )
31+
{
32+
return false;
33+
}
34+
35+
if ( Header.Version == 2 )
36+
{
37+
UInt32 hash = reader.ReadUInt32();
38+
LogInfo( "hash: " + hash );
39+
}
40+
41+
Entries.Add( idChunk );
42+
}
43+
44+
End( reader );
45+
return true;
46+
}
47+
48+
public override ChunkType Type()
49+
{
50+
return ChunkType.effPrecompiledFXData;
51+
}
52+
}
53+
}
Lines changed: 86 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -1,86 +1,86 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Diagnostics;
4-
using System.IO;
5-
using System.Linq;
6-
using System.Text;
7-
8-
namespace TRRM
9-
{
10-
public class BDATChunk : Chunk
11-
{
12-
public string BoneName;
13-
public float[] Unknown1;
14-
public float[] Unknown2;
15-
public float[] Unknown3;
16-
public float[,] BoneMatrix;
17-
public Chunk BoundingVolume;
18-
19-
public override bool Load( BinaryReader reader )
20-
{
21-
BoundingVolume = null;
22-
23-
Start( reader );
24-
if ( !ReadHeader( reader ) || !IsValidVersion( 1, 2 ) )
25-
{
26-
return false;
27-
}
28-
29-
BoneName = reader.ReadCString();
30-
Unknown1 = reader.ReadFloatArray( 4 );
31-
Unknown2 = reader.ReadFloatArray( 3 );
32-
if (Header.Version == 2)
33-
{
34-
Unknown3 = reader.ReadFloatArray( 3 );
35-
}
36-
37-
BoneMatrix = reader.ReadMatrix( 4, 4 );
38-
39-
LogInfo( "name: " + BoneName );
40-
41-
ChunkType nextChunk = ChunkUtils.PeekNextChunk( reader );
42-
switch( nextChunk )
43-
{
44-
case ChunkType.phyBone:
45-
break;
46-
case ChunkType.phyBVSphere:
47-
BoundingVolume = new BVSPChunk();
48-
break;
49-
case ChunkType.phyBVBox:
50-
BoundingVolume = new BVBXChunk();
51-
break;
52-
case ChunkType.phyBVAlignedCylinder:
53-
BoundingVolume = new BVACChunk();
54-
break;
55-
case ChunkType.phyBVCapsule:
56-
BoundingVolume = new BVCPChunk();
57-
break;
58-
case ChunkType.phyBVSurface:
59-
BoundingVolume = new BVSFChunk();
60-
break;
61-
case ChunkType.phyBVWalkableSurface:
62-
BoundingVolume = new BVWSChunk();
63-
break;
64-
default:
65-
//Debugger.Break();
66-
break;
67-
}
68-
69-
if ( BoundingVolume != null )
70-
{
71-
if ( !BoundingVolume.Load( reader ) )
72-
{
73-
return false;
74-
}
75-
}
76-
77-
End( reader );
78-
return true;
79-
}
80-
81-
public override ChunkType Type()
82-
{
83-
return ChunkType.phyBoneSharedData;
84-
}
85-
}
86-
}
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Diagnostics;
4+
using System.IO;
5+
using System.Linq;
6+
using System.Text;
7+
8+
namespace TRRM
9+
{
10+
public class BDATChunk : Chunk
11+
{
12+
public string BoneName;
13+
public float[] Unknown1;
14+
public float[] Unknown2;
15+
public float[] Unknown3;
16+
public float[,] BoneMatrix;
17+
public Chunk BoundingVolume;
18+
19+
public override bool Load( BinaryReader reader )
20+
{
21+
BoundingVolume = null;
22+
23+
Start( reader );
24+
if ( !ReadHeader( reader ) || !IsValidVersion( 1, 2 ) )
25+
{
26+
return false;
27+
}
28+
29+
BoneName = reader.ReadCString();
30+
Unknown1 = reader.ReadFloatArray( 4 );
31+
Unknown2 = reader.ReadFloatArray( 3 );
32+
if (Header.Version == 2)
33+
{
34+
Unknown3 = reader.ReadFloatArray( 3 );
35+
}
36+
37+
BoneMatrix = reader.ReadMatrix( 4, 4 );
38+
39+
LogInfo( "name: " + BoneName );
40+
41+
ChunkType nextChunk = ChunkUtils.PeekNextChunk( reader );
42+
switch( nextChunk )
43+
{
44+
case ChunkType.phyBone:
45+
break;
46+
case ChunkType.phyBVSphere:
47+
BoundingVolume = new BVSPChunk();
48+
break;
49+
case ChunkType.phyBVBox:
50+
BoundingVolume = new BVBXChunk();
51+
break;
52+
case ChunkType.phyBVAlignedCylinder:
53+
BoundingVolume = new BVACChunk();
54+
break;
55+
case ChunkType.phyBVCapsule:
56+
BoundingVolume = new BVCPChunk();
57+
break;
58+
case ChunkType.phyBVSurface:
59+
BoundingVolume = new BVSFChunk();
60+
break;
61+
case ChunkType.phyBVWalkableSurface:
62+
BoundingVolume = new BVWSChunk();
63+
break;
64+
default:
65+
//Debugger.Break();
66+
break;
67+
}
68+
69+
if ( BoundingVolume != null )
70+
{
71+
if ( !BoundingVolume.Load( reader ) )
72+
{
73+
return false;
74+
}
75+
}
76+
77+
End( reader );
78+
return true;
79+
}
80+
81+
public override ChunkType Type()
82+
{
83+
return ChunkType.phyBoneSharedData;
84+
}
85+
}
86+
}

0 commit comments

Comments
 (0)