Skip to content

Commit

Permalink
Added a sanity check for collision data
Browse files Browse the repository at this point in the history
Should fix loading some levels in Ztar Attack 1.2
  • Loading branch information
DavidSM64 committed Jul 13, 2018
1 parent 4a51385 commit 74e86b9
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions src/Scripts/LevelScripts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public static int parse(ref Level lvl, byte seg, uint off)
//stopWatch.Start();
byte cmdLen = data[off + 1];
byte[] cmd = rom.getSubArray_safe(data, off, cmdLen);
//Console.WriteLine(rom.decodeSegmentAddress_safe(seg, off, null).ToString("X8"));
//rom.printArray(cmd, cmdLen);
string desc = "Unknown command";
bool alreadyAdded = false;
Expand Down Expand Up @@ -417,25 +418,25 @@ private static void CMD_1F(ref Level lvl, ref string desc, byte[] cmd, byte[] da
refAreaID = areaID;

setAreaSegmented0xE(areaID, data);

desc = "Start area " + areaID + "; Load area geo layout from 0x" + seg.ToString("X2") + off.ToString("X6");

Area newArea = new Area(areaID, bytesToInt(cmd, 4, 4), lvl);
GeoScripts.resetNodes();
newArea.AreaModel.GeoDataSegAddress = bytesToInt(cmd, 4, 4);

// Globals.DEBUG_PARSING_LEVEL_AREA = true;
// Stopwatch stopWatch = new Stopwatch();
// stopWatch.Start();
// Globals.DEBUG_PARSING_LEVEL_AREA = true;
// Stopwatch stopWatch = new Stopwatch();
// stopWatch.Start();
GeoScripts.parse(ref newArea.AreaModel, ref lvl, seg, off, areaID);
lvl.setAreaBackgroundInfo(ref newArea);
lvl.Areas.Add(newArea);
lvl.CurrentAreaID = areaID;
// stopWatch.Stop();
// Console.WriteLine("RunTime (GeoScripts.parse): " + stopWatch.Elapsed.Milliseconds + "ms");
// stopWatch.Stop();
// Console.WriteLine("RunTime (GeoScripts.parse): " + stopWatch.Elapsed.Milliseconds + "ms");

//stopWatch = new Stopwatch();
// stopWatch.Start();
// stopWatch.Start();
newArea.AreaModel.buildBuffers();
//if(areaID == 1) newArea.AreaModel.dumpModelToOBJ(1.0f/500.0f);
//stopWatch.Stop();
Expand Down Expand Up @@ -649,6 +650,11 @@ private static void CMD_2E(ref Level lvl, ref string desc, byte[] cmd, byte? are
uint off = bytesToInt(cmd, 5, 3);
byte[] data = rom.getSegment(segment, areaID);
sub_cmd = (ushort)bytesToInt(data, (int)off, 2);

// Check if the data is actually collision data.
if (data[off] != 0x00 || data[off+1] != 0x40)
return;

CollisionMap cmap = lvl.getCurrentArea().collision;
uint num_verts = (ushort)bytesToInt(data, (int)off + 2, 2);

Expand Down

0 comments on commit 74e86b9

Please sign in to comment.