diff --git a/SuperBMD/source/BMD/MAT3.cs b/SuperBMD/source/BMD/MAT3.cs index f84095a..b8429f4 100644 --- a/SuperBMD/source/BMD/MAT3.cs +++ b/SuperBMD/source/BMD/MAT3.cs @@ -315,7 +315,7 @@ private void LoadInitData(EndianBinaryReader reader) for (int i = 0; i < 8; i++) { int lightIndex = reader.ReadInt16(); - if (lightIndex == -1) + if ((lightIndex == -1) || (lightIndex > m_LightingColorBlock.Count) || (m_LightingColorBlock.Count == 0)) continue; else mat.LightingColors[i] = m_LightingColorBlock[lightIndex]; @@ -424,7 +424,7 @@ private void LoadInitData(EndianBinaryReader reader) for (int i = 0; i < 16; i++) { int tevSwapModeTableIndex = reader.ReadInt16(); - if (tevSwapModeTableIndex == -1) + if ((tevSwapModeTableIndex < 0) || (tevSwapModeTableIndex > m_SwapTableBlock.Count)) continue; else mat.SwapTables[i] = m_SwapTableBlock[tevSwapModeTableIndex]; diff --git a/SuperBMD/source/Materials/IO/TexCoordGenIO.cs b/SuperBMD/source/Materials/IO/TexCoordGenIO.cs index 82ee67a..012661d 100644 --- a/SuperBMD/source/Materials/IO/TexCoordGenIO.cs +++ b/SuperBMD/source/Materials/IO/TexCoordGenIO.cs @@ -15,7 +15,7 @@ public static List Load(EndianBinaryReader reader, int offset, int List gens = new List(); int count = size / 4; - for (int i = 0; i < 4; i++) + for (int i = 0; i < count; i++) gens.Add(new TexCoordGen(reader)); return gens; diff --git a/SuperBMD/source/Materials/Material.cs b/SuperBMD/source/Materials/Material.cs index c7a9d8b..a5448a2 100644 --- a/SuperBMD/source/Materials/Material.cs +++ b/SuperBMD/source/Materials/Material.cs @@ -72,7 +72,7 @@ public Material() AlphaSels = new KonstAlphaSel[16]; TevOrders = new TevOrder?[16]; - TevOrders[0] = new TevOrder(TexCoordId.TexCoord0, TexMapId.TexMap0, J3DColorChannelId.Color0); + TevOrders[0] = new TevOrder(TexCoordId.TexCoord0, TexMapId.TexMap0, GXColorChannelId.Color0); TevColors = new Color?[16]; TevColors[0] = new Color(1, 1, 1, 1); @@ -85,7 +85,7 @@ public Material() SwapTables = new TevSwapModeTable?[16]; SwapTables[0] = new TevSwapModeTable(0, 1, 2, 3); - AlphCompare = new AlphaCompare(CompareType.Greater, 0, AlphaOp.And, CompareType.Always, 0); + AlphCompare = new AlphaCompare(CompareType.Greater, 127, AlphaOp.And, CompareType.Always, 0); ZMode = new ZMode(true, CompareType.LEqual, true); BMode = new BlendMode(Enums.BlendMode.None, BlendModeControl.SrcAlpha, BlendModeControl.InverseSrcAlpha, LogicOp.NoOp); NBTScale = new NBTScale(0, Vector3.Zero); @@ -124,7 +124,7 @@ public void SetUpTev(bool hasTexture, bool hasVtxColor, int texIndex) // Generate texture stuff AddTexGen(TexGenType.Matrix2x4, TexGenSrc.Tex0, Enums.TexMatrix.Identity); AddTexMatrix(TexGenType.Matrix3x4, 0, OpenTK.Vector3.Zero, OpenTK.Vector2.One, 0, OpenTK.Vector2.Zero, OpenTK.Matrix4.Identity); - AddTevOrder(TexCoordId.TexCoord0, TexMapId.TexMap0, J3DColorChannelId.Null); + AddTevOrder(TexCoordId.TexCoord0, TexMapId.TexMap0, GXColorChannelId.ColorNull); AddTexIndex(texIndex); // Texture + Vertex Color @@ -238,7 +238,7 @@ public void AddTexIndex(int index) } } - public void AddTevOrder(TexCoordId coordId, TexMapId mapId, J3DColorChannelId colorChanId) + public void AddTevOrder(TexCoordId coordId, TexMapId mapId, GXColorChannelId colorChanId) { for (int i = 0; i < 8; i++) { diff --git a/SuperBMD/source/Materials/TevOrder.cs b/SuperBMD/source/Materials/TevOrder.cs index c7421a9..3c3c63b 100644 --- a/SuperBMD/source/Materials/TevOrder.cs +++ b/SuperBMD/source/Materials/TevOrder.cs @@ -12,9 +12,9 @@ public struct TevOrder : IEquatable { public TexCoordId TexCoord; public TexMapId TexMap; - public J3DColorChannelId ChannelId; + public GXColorChannelId ChannelId; - public TevOrder(TexCoordId texCoord, TexMapId texMap, J3DColorChannelId chanID) + public TevOrder(TexCoordId texCoord, TexMapId texMap, GXColorChannelId chanID) { TexCoord = texCoord; TexMap = texMap; @@ -25,7 +25,7 @@ public TevOrder(EndianBinaryReader reader) { TexCoord = (TexCoordId)reader.ReadByte(); TexMap = (TexMapId)reader.ReadByte(); - ChannelId = (J3DColorChannelId)reader.ReadByte(); + ChannelId = (GXColorChannelId)reader.ReadByte(); reader.SkipByte(); }