Skip to content

Commit 1a47051

Browse files
committed
Don't crash on treenode for binary parser bio2da on some cases, optimize reading nodes
1 parent 3c72617 commit 1a47051

File tree

4 files changed

+35
-28
lines changed

4 files changed

+35
-28
lines changed

AmaroK86/AmaroK86Lib.csproj

+5-2
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@
3636
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
3737
</PropertyGroup>
3838
<ItemGroup>
39-
<Reference Include="ICSharpCode.SharpZipLib">
40-
<HintPath>..\Libraries\ICSharpCode.SharpZipLib.dll</HintPath>
39+
<Reference Include="ICSharpCode.SharpZipLib, Version=0.86.0.518, Culture=neutral, PublicKeyToken=1b03e6acf1164f73, processorArchitecture=MSIL">
40+
<HintPath>..\packages\SharpZipLib.0.86.0\lib\20\ICSharpCode.SharpZipLib.dll</HintPath>
4141
</Reference>
4242
<Reference Include="System" />
4343
<Reference Include="System.Core" />
@@ -73,6 +73,9 @@
7373
<Name>SevenZip</Name>
7474
</ProjectReference>
7575
</ItemGroup>
76+
<ItemGroup>
77+
<None Include="packages.config" />
78+
</ItemGroup>
7679
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
7780
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
7881
Other similar extension points exist, see Microsoft.Common.targets.

AmaroK86/packages.config

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<packages>
3+
<package id="SharpZipLib" version="0.86.0" targetFramework="net45" />
4+
</packages>

ME3Explorer/BinaryInterpreter/BinaryInterpreter.cs

+24-24
Original file line numberDiff line numberDiff line change
@@ -302,11 +302,17 @@ private void StartScan(string topNodeName = null, string selectedNodeName = null
302302
nodes = treeView1.Nodes.Find(selectedNodeName, true);
303303
if (nodes.Length > 0)
304304
{
305-
treeView1.SelectedNode = nodes[0];
305+
if (treeView1.Nodes.Count > 0)
306+
{
307+
treeView1.SelectedNode = nodes[0];
308+
}
306309
}
307310
else
308311
{
309-
treeView1.SelectedNode = treeView1.Nodes[0];
312+
if (treeView1.Nodes.Count > 0)
313+
{
314+
treeView1.SelectedNode = treeView1.Nodes[0];
315+
}
310316
}
311317
}
312318

@@ -355,7 +361,7 @@ private void StartObjectRedirectorScan(string nodeNameToSelect = null)
355361
private void StartBio2DAScan(string nodeNameToSelect = null)
356362
{
357363
Random random = new Random();
358-
string[] stringRefColumns = { "StringRef", "SaveGameStringRef", "Title", "LabelRef", "Name", "ActiveWorld", "Description", "ButtonLabel" };
364+
string[] stringRefColumns = { "StringRef", "SaveGameStringRef", "Title", "LabelRef", "Name", "ActiveWorld", "Description", "Description1", "Description1", "Description1", "ButtonLabel", "UnlockName", "UnlockBlurb", "DisplayName", "DisplayDescription", "PriAbiDesc", "SecAbiDesc" };
359365

360366
resetPropEditingControls();
361367
treeView1.BeginUpdate();
@@ -375,7 +381,8 @@ private void StartBio2DAScan(string nodeNameToSelect = null)
375381
{
376382
rowNames.Add(n.ToString());
377383
}
378-
} else
384+
}
385+
else
379386
{
380387
return;
381388
}
@@ -390,7 +397,8 @@ private void StartBio2DAScan(string nodeNameToSelect = null)
390397
{
391398
rowNames.Add(n.Value.ToString());
392399
}
393-
} else
400+
}
401+
else
394402
{
395403
return;
396404
}
@@ -402,7 +410,7 @@ private void StartBio2DAScan(string nodeNameToSelect = null)
402410

403411
//Get Columns
404412
List<string> columnNames = new List<string>();
405-
int colcount = BitConverter.ToInt32(data, data.Length - 4);
413+
int colcount = BitConverter.ToInt32(data, data.Length - 4); //this is actually index of last column, but it works the same
406414
int currentcoloffset = 0;
407415
Console.WriteLine("Number of columns: " + colcount);
408416
TreeNode columnsnode = new TreeNode("Columns");
@@ -421,7 +429,7 @@ private void StartBio2DAScan(string nodeNameToSelect = null)
421429
columnNames.Insert(0, name);
422430
colcount--;
423431
}
424-
currentcoloffset += 4; //column count.
432+
currentcoloffset += 4; //real column count
425433
int infilecolcount = BitConverter.ToInt32(data, data.Length - currentcoloffset);
426434
columnsnode.Text = infilecolcount + " columns";
427435
columnsnode.Name = (data.Length - currentcoloffset).ToString();
@@ -463,7 +471,7 @@ private void StartBio2DAScan(string nodeNameToSelect = null)
463471
//int
464472
int ival = BitConverter.ToInt32(data, curroffset);
465473
valueStr = ival.ToString();
466-
if (stringRefColumns.Contains(columnNames[colindex]))
474+
//if (stringRefColumns.Contains(columnNames[colindex]))
467475
{
468476
string tlkVal;
469477
if (ME1_TLK_DICT != null && ME1_TLK_DICT.TryGetValue(valueStr, out tlkVal))
@@ -478,22 +486,12 @@ private void StartBio2DAScan(string nodeNameToSelect = null)
478486
//name
479487
int nval = BitConverter.ToInt32(data, curroffset);
480488
valueStr = pcc.getNameEntry(nval);
489+
valueStr += "_" + BitConverter.ToInt32(data, curroffset + 4);
481490
curroffset += 8;
482491
tag = nodeType.StructLeafName;
483492
break;
484493
case 2:
485494
//float
486-
float f = NextFloat(random);
487-
while (f < 0)
488-
{
489-
f = NextFloat(random);
490-
}
491-
byte[] buff2 = BitConverter.GetBytes(f);
492-
for (int o = 0; o < 4; o++)
493-
{
494-
data[curroffset + o] = buff2[o];
495-
}
496-
497495
float fval = BitConverter.ToSingle(data, curroffset);
498496
valueStr = fval.ToString();
499497
curroffset += 4;
@@ -537,7 +535,8 @@ private void StartBio2DAScan(string nodeNameToSelect = null)
537535
byte dataType = data[curroffset];
538536
int dataSize = dataType == Bio2DACell.TYPE_NAME ? 8 : 4;
539537
curroffset++;
540-
byte[] celldata = data.Skip(curroffset).Take(dataSize).ToArray();
538+
byte[] celldata = new byte[dataSize];
539+
Buffer.BlockCopy(data, curroffset, celldata, 0, dataSize);
541540
Bio2DACell cell = new Bio2DACell(pcc, curroffset, dataType, celldata);
542541
//Console.WriteLine(columnNames[col] + ": " + cell.GetDisplayableValue());
543542
bio2da[row, col] = cell;
@@ -558,11 +557,12 @@ private void StartBio2DAScan(string nodeNameToSelect = null)
558557
if (cell != null)
559558
{
560559
columnNode = new TreeNode(columnname + ": " + cell.GetDisplayableValue());
561-
if (stringRefColumns.Contains(columnname))
560+
if (cell.Type == Bio2DACell.TYPE_INT)
562561
{
563-
string tlkVal;
564-
if (ME1_TLK_DICT != null && ME1_TLK_DICT.TryGetValue(cell.GetDisplayableValue(), out tlkVal))
562+
string tlkVal = " ";
563+
if (ME1_TLK_DICT != null && ME1_TLK_DICT.TryGetValue(BitConverter.ToInt32(cell.Data, 0).ToString(), out tlkVal))
565564
{
565+
tlkVal = tlkVal.Replace("\n", "[NL]");
566566
columnNode.Text += " " + tlkVal;
567567
}
568568
}
@@ -613,7 +613,7 @@ private void StartBio2DAScan(string nodeNameToSelect = null)
613613

614614
treeView1.EndUpdate();
615615
memory = data;
616-
export.Data = data;
616+
//export.Data = data;
617617
memsize = memory.Length;
618618
}
619619

ME3Explorer/BinaryInterpreter/Bio2DAProperty.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ internal class Bio2DACell
99
public const byte TYPE_INT = 0;
1010
public const byte TYPE_NAME = 1;
1111
public const byte TYPE_FLOAT = 2;
12-
byte[] Data { get; set; }
12+
public byte[] Data { get; set; }
1313
public int Offset { get; private set; }
1414
public IMEPackage Pcc { get; private set; }
1515
public byte Type { get; set; }
@@ -29,7 +29,7 @@ public string GetDisplayableValue()
2929
return BitConverter.ToInt32(Data, 0).ToString();
3030
case TYPE_NAME:
3131
int name = BitConverter.ToInt32(Data, 0);
32-
return Pcc.getNameEntry(name);
32+
return Pcc.getNameEntry(name) + "_"+ BitConverter.ToInt32(Data, 4); ;
3333
case TYPE_FLOAT:
3434
return BitConverter.ToSingle(Data, 0).ToString();
3535
}

0 commit comments

Comments
 (0)