Skip to content

Commit

Permalink
Added limit to number of G_DL commands that can run to prevent infini…
Browse files Browse the repository at this point in the history
…te loops.
  • Loading branch information
DavidSM64 committed Oct 3, 2018
1 parent 4337e50 commit 742abb5
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
11 changes: 6 additions & 5 deletions src/Scripts/Fast3DScripts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,10 @@ private enum CMD
static TempMaterial tempMaterial = new TempMaterial();
static F3D_Vertex[] vertices = new F3D_Vertex[16];

public static void parse(ref Model3D mdl, ref Level lvl, byte seg, uint off, byte? areaID)
public static void parse(ref Model3D mdl, ref Level lvl, byte seg, uint off, byte? areaID, int current_depth)
{
if (seg == 0) return;
if (seg == 0 || current_depth >= 300)
return; // depth was added to prevent infinite loops with 0x06 command.
ROM rom = ROM.Instance;
byte[] data = rom.getSegment(seg, areaID);
if (data == null) return;
Expand Down Expand Up @@ -127,7 +128,7 @@ public static void parse(ref Model3D mdl, ref Level lvl, byte seg, uint off, byt
desc = "Jump to display list at 0x" + bytesToInt(cmd, 4, 4).ToString("X8");

addF3DCommandToDump(ref mdl, cmd, seg, off, desc, areaID);
F3D_DL(ref mdl, ref lvl, cmd, areaID);
F3D_DL(ref mdl, ref lvl, cmd, areaID, current_depth);
if (cmd[1] == 1)
end = true;
break;
Expand Down Expand Up @@ -296,11 +297,11 @@ private static bool F3D_VTX(F3D_Vertex[] vertices, ref Level lvl, byte[] cmd, re
return true;
}

private static void F3D_DL(ref Model3D mdl, ref Level lvl, byte[] cmd, byte? areaID)
private static void F3D_DL(ref Model3D mdl, ref Level lvl, byte[] cmd, byte? areaID, int current_depth)
{
byte seg = cmd[4];
uint off = bytesToInt(cmd, 5, 3);
parse(ref mdl, ref lvl, seg, off, areaID);
parse(ref mdl, ref lvl, seg, off, areaID, current_depth + 1);
}

private static Vector4 getColor(uint color)
Expand Down
4 changes: 2 additions & 2 deletions src/Scripts/GeoScripts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ private static void CMD_13(ref Model3D mdl, ref Level lvl, byte[] cmd, byte? are
{
if (!mdl.hasGeoDisplayList(off))
{
Fast3DScripts.parse(ref mdl, ref lvl, seg, off, areaID);
Fast3DScripts.parse(ref mdl, ref lvl, seg, off, areaID, 0);
}
lvl.temp_bgInfo.usesFog = mdl.builder.UsesFog;
lvl.temp_bgInfo.fogColor = mdl.builder.FogColor;
Expand All @@ -312,7 +312,7 @@ private static void CMD_15(ref Model3D mdl, ref Level lvl, byte[] cmd, byte? are
// Don't bother processing duplicate display lists.
if (!mdl.hasGeoDisplayList(off))
{
Fast3DScripts.parse(ref mdl, ref lvl, seg, off, areaID);
Fast3DScripts.parse(ref mdl, ref lvl, seg, off, areaID, 0);
}

lvl.temp_bgInfo.usesFog = mdl.builder.UsesFog;
Expand Down
2 changes: 1 addition & 1 deletion src/Scripts/LevelScripts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ private static void CMD_21(ref Level lvl, ref string desc, byte[] cmd, byte? are
lvl.AddObjectCombos(modelID, newModel.GeoDataSegAddress);

if (rom.getSegment(seg, areaID) != null)
Fast3DScripts.parse(ref newModel, ref lvl, seg, off, areaID);
Fast3DScripts.parse(ref newModel, ref lvl, seg, off, areaID, 0);

if (lvl.ModelIDs.ContainsKey(modelID))
lvl.ModelIDs.Remove(modelID);
Expand Down

0 comments on commit 742abb5

Please sign in to comment.