Skip to content

Commit 4030eca

Browse files
committed
fixed cst pointer sizes
1 parent 68abce4 commit 4030eca

3 files changed

Lines changed: 15 additions & 17 deletions

File tree

CathodeLib/Scripts/CATHODE/Materials.cs

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,11 @@ override protected bool LoadInternal()
6060
for (int x = 0; x < 12; x++)
6161
{
6262
Material.Texture texRef = new Material.Texture();
63-
texRef.ShaderIndex = x;
6463
texRef.BinIndex = reader.ReadInt16();
6564
int texTableIndex = reader.ReadInt16();
6665
if (texTableIndex == -1) continue;
6766
texRef.Source = (Material.Texture.TextureSource)texTableIndex;
68-
material.TextureReferences.Add(texRef);
67+
material.TextureReferences[x] = texRef;
6968
}
7069
reader.BaseStream.Position += 8;
7170
List<int> cstIndexes = new List<int>();
@@ -74,7 +73,7 @@ override protected bool LoadInternal()
7473
{
7574
int cstCount = reader.ReadByte();
7675
//TODO: just read the CST data into the material
77-
material.ConstantBuffers.Add(new Material.ConstantBuffer() { Offset = cstIndexes[x], Length = cstCount });
76+
material.ConstantBuffers[x] = new Material.ConstantBuffer() { Offset = cstIndexes[x], Length = cstCount };
7877
}
7978
reader.BaseStream.Position += 7;
8079
material.UnknownValue0 = reader.ReadInt32();
@@ -132,10 +131,10 @@ override protected bool SaveInternal()
132131
int materialOffset = (int)writer.BaseStream.Position;
133132
for (int i = 0; i < Entries.Count; i++)
134133
{
135-
if (Entries[i].TextureReferences.Count > 12) throw new Exception("Too many texture references!");
134+
if (Entries[i].TextureReferences.Length != 12) throw new Exception("Incorrect texture references!");
136135
for (int x = 0; x < 12; x++)
137136
{
138-
Material.Texture tex = Entries[i].TextureReferences.FirstOrDefault(o => o.ShaderIndex == x);
137+
Material.Texture tex = Entries[i].TextureReferences[x];
139138
if (tex == null)
140139
{
141140
writer.Write((Int16)(-1));
@@ -149,16 +148,14 @@ override protected bool SaveInternal()
149148
}
150149
writer.Write(new byte[4]);
151150
writer.Write((Int32)i);
152-
if (Entries[i].ConstantBuffers.Count > 5) throw new Exception("Too many constant buffer definitions!");
151+
if (Entries[i].ConstantBuffers.Length != 5) throw new Exception("Incorrect constant buffer definitions!");
153152
for (int x = 0; x < 5; x++)
154153
{
155-
if (Entries[i].ConstantBuffers.Count <= x) writer.Write(0);
156-
else writer.Write(Entries[i].ConstantBuffers[x].Offset);
154+
writer.Write(Entries[i].ConstantBuffers[x].Offset);
157155
}
158156
for (int x = 0; x < 5; x++)
159157
{
160-
if (Entries[i].ConstantBuffers.Count <= x) writer.Write(0);
161-
else writer.Write((byte)Entries[i].ConstantBuffers[x].Length);
158+
writer.Write((byte)Entries[i].ConstantBuffers[x].Length);
162159
}
163160
writer.Write(new byte[7]);
164161
writer.Write(Entries[i].UnknownValue0);
@@ -207,16 +204,16 @@ public class Material
207204
{
208205
public string Name;
209206

210-
public List<Texture> TextureReferences = new List<Texture>(); //Max of 12
211-
public List<ConstantBuffer> ConstantBuffers = new List<ConstantBuffer>(); //Should always be 5 (1 per CST block) - TODO: maybe just change this to 5 variables?
207+
public Texture[] TextureReferences = new Texture[12]; //Max of 12
208+
public ConstantBuffer[] ConstantBuffers = new ConstantBuffer[5]; //Should always be 5 (1 per CST block) - TODO: maybe just change this to 5 variables?
212209

213210
public int UnknownValue0;
214211
public int UberShaderIndex;
215212

216213
public int UnknownValue1;
217214

218215
public int Unknown4_;
219-
public int Color; // TODO: This is not really color AFAIK.
216+
public int Color; // TODO: This is not color
220217
public int UnknownValue2;
221218

222219
public override string ToString()
@@ -233,7 +230,6 @@ public class ConstantBuffer
233230

234231
public class Texture
235232
{
236-
public int ShaderIndex; // Entry index in the material texture ref write list for shaders to access.
237233
public int BinIndex; // Entry index in texture BIN file.
238234

239235
public TextureSource Source;

CathodeLib/Scripts/LEGACY_DAN/ShadersPAK.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ public ShaderMaterialMetadata GetMaterialMetadataFromShader(Materials.Material I
413413
{
414414
int PairIndex = Shader.TextureLinks[i];
415415
// NOTE: PairIndex == 255 means no index.
416-
if (PairIndex < InMaterial.TextureReferences.Count)
416+
if (PairIndex < InMaterial.TextureReferences.Length)
417417
{
418418
metadata.textures[i].TextureInfo = InMaterial.TextureReferences[PairIndex];
419419
}

CathodeLib/Scripts/Level.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,9 @@ public void Save()
206206
List<Textures.TEX4> materialTextures = new List<Textures.TEX4>();
207207
for (int i = 0; i < Materials.Entries.Count; i++)
208208
{
209-
for (int x = 0; x < Materials.Entries[i].TextureReferences.Count; x++)
209+
for (int x = 0; x < Materials.Entries[i].TextureReferences.Length; x++)
210210
{
211+
if (Materials.Entries[i].TextureReferences[x] == null) continue;
211212
switch (Materials.Entries[i].TextureReferences[x].Source)
212213
{
213214
case Materials.Material.Texture.TextureSource.LEVEL:
@@ -255,8 +256,9 @@ public void Save()
255256
y = 0;
256257
for (int i = 0; i < Materials.Entries.Count; i++)
257258
{
258-
for (int x = 0; x < Materials.Entries[i].TextureReferences.Count; x++)
259+
for (int x = 0; x < Materials.Entries[i].TextureReferences.Length; x++)
259260
{
261+
if (Materials.Entries[i].TextureReferences[x] == null) continue;
260262
switch (Materials.Entries[i].TextureReferences[x].Source)
261263
{
262264
case Materials.Material.Texture.TextureSource.LEVEL:

0 commit comments

Comments
 (0)