Skip to content

Commit

Permalink
Merge pull request #12 from aglab2/master
Browse files Browse the repository at this point in the history
Sanity Checks for more ROMs compatibility
  • Loading branch information
DavidSM64 authored Jul 8, 2018
2 parents 6086067 + 5e916c6 commit a3298f7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
17 changes: 16 additions & 1 deletion src/ROM.cs
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ public void setSegment(uint index, uint segmentStart, uint segmentEnd, bool isMI

public void setSegment(uint index, uint segmentStart, uint segmentEnd, bool isMIO0, bool fakeMIO0, uint uncompressedOffset)
{
if (segmentStart > segmentEnd)
if (segmentStart > segmentEnd || index > segData.Length)
return;

if (!isMIO0)
Expand Down Expand Up @@ -344,18 +344,27 @@ public byte[] getROMSection(uint start, uint end)

public byte[] cloneSegment(byte segment)
{
if (segment > segData.Length)
return null;

byte[] copy = new byte[segData[segment].Length];
Array.Copy(segData[segment], copy, segData[segment].Length);
return copy;
}

public byte[] getSegment(ushort seg)
{
if (seg > segData.Length)
return null;

return segData[seg];
}

public uint getSegmentStart(ushort seg)
{
if (seg > segData.Length)
return 0;

return segStart[seg];
}

Expand All @@ -371,6 +380,9 @@ public uint decodeSegmentAddress(uint segOffset)

public uint decodeSegmentAddress(byte segment, uint offset)
{
if (segment > segData.Length)
return 0;

if (segIsMIO0[segment])
throw new System.ArgumentException("Cannot decode segment address (0x" + segment.ToString("X2") + offset.ToString("X6") + ") from MIO0 data. (decodeSegmentAddress 2)");
return segStart[segment] + offset;
Expand All @@ -389,6 +401,9 @@ public uint decodeSegmentAddress_safe(uint segOffset)

public uint decodeSegmentAddress_safe(byte segment, uint offset)
{
if (segment > segIsMIO0.Length)
return 0;

if (segIsMIO0[segment])
return 0xFFFFFFFF;
return segStart[segment] + offset;
Expand Down
2 changes: 1 addition & 1 deletion src/Scripts/Fast3DScripts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ private static void switchTextureStatus(ref Model3D mdl, ref TempMaterial temp,
{
if (!mdl.builder.hasTexture(temp.segOff))
{
if (temp.segOff != 0)
if (temp.segOff != 0 && temp.w != 0 && temp.h != 0)
{
mdl.builder.AddTexture(
TextureFormats.decodeTexture(
Expand Down

0 comments on commit a3298f7

Please sign in to comment.