Skip to content

Commit 3c72617

Browse files
committed
fixed a few bugs in bio2da, added basic randomizing concept
1 parent 42071d9 commit 3c72617

File tree

3 files changed

+80
-119
lines changed

3 files changed

+80
-119
lines changed

ME3Explorer/BinaryInterpreter/BinaryInterpreter.cs

+75-114
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
using ME2Explorer.Unreal;
1717
using ME1Explorer.Unreal.Classes;
1818
using System.Xml;
19+
using System.Xml.Linq;
1920

2021
namespace ME3Explorer
2122
{
@@ -117,7 +118,7 @@ public enum nodeType
117118
private Dictionary<string, List<PropertyReader.Property>> defaultStructValues;
118119

119120
int? selectedNodePos = null;
120-
121+
private Dictionary<string, string> ME1_TLK_DICT;
121122
public static readonly string[] ParsableBinaryClasses = { "Level", "StaticMeshCollectionActor", "Class", "ObjectRedirector", "Bio2DA", "Bio2DANumberedRows", "WwiseEvent", "Material", "StaticMesh", "MaterialInstanceConstant", "BioDynamicAnimSet", "StaticMeshComponent", "SkeletalMeshComponent", "SkeletalMesh", "Model", "Polys" }; //classes that have binary parse code
122123

123124

@@ -126,6 +127,20 @@ public BinaryInterpreter()
126127
InitializeComponent();
127128
SetTopLevel(false);
128129
defaultStructValues = new Dictionary<string, List<PropertyReader.Property>>();
130+
131+
//Load ME1TLK
132+
string tlkxmlpath = @"C:\users\mgame\desktop\me1tlk.xml";
133+
if (File.Exists(tlkxmlpath))
134+
{
135+
XDocument xmlDocument = XDocument.Load(tlkxmlpath);
136+
ME1_TLK_DICT =
137+
(from strings in xmlDocument.Descendants("string")
138+
select new
139+
{
140+
ID = strings.Element("id").Value,
141+
Data = strings.Element("data").Value,
142+
}).Distinct().ToDictionary(o => o.ID, o => o.Data);
143+
}
129144
}
130145

131146
/// <summary>
@@ -136,19 +151,7 @@ public BinaryInterpreter(IMEPackage importingPCC, IExportEntry importingExport,
136151
{
137152
//This will make it fairly slow, but will make it so I don't have to change everything.
138153
InitializeComponent();
139-
//Load ME1TLK
140-
string tlkxmlpath = @"C:\users\dev\desktop\tlk1.xml";
141-
if (File.Exists(tlkxmlpath))
142-
{
143-
XmlDocument xmlDocument = new XmlDocument();
144-
xmlDocument.Load(tlkxmlpath);
145-
var configDictionary =
146-
(from configDatum in xmlDocument.Descendents("string")
147-
select new {
148-
Name= configDatum.attribute("name").Value,
149-
Value = configDatum.Attribute("value").Value,
150-
}).ToDictionary(o => o.Name, o => o.Value);
151-
}
154+
152155

153156
SetTopLevel(false);
154157
defaultStructValues = new Dictionary<string, List<PropertyReader.Property>>();
@@ -351,6 +354,9 @@ private void StartObjectRedirectorScan(string nodeNameToSelect = null)
351354

352355
private void StartBio2DAScan(string nodeNameToSelect = null)
353356
{
357+
Random random = new Random();
358+
string[] stringRefColumns = { "StringRef", "SaveGameStringRef", "Title", "LabelRef", "Name", "ActiveWorld", "Description", "ButtonLabel" };
359+
354360
resetPropEditingControls();
355361
treeView1.BeginUpdate();
356362
treeView1.Nodes.Clear();
@@ -363,18 +369,30 @@ private void StartBio2DAScan(string nodeNameToSelect = null)
363369
{
364370
string rowLabelsVar = "m_sRowLabel";
365371
var props = export.GetProperty<ArrayProperty<NameProperty>>(rowLabelsVar);
366-
foreach (NameProperty n in props)
372+
if (props != null)
367373
{
368-
rowNames.Add(n.ToString());
374+
foreach (NameProperty n in props)
375+
{
376+
rowNames.Add(n.ToString());
377+
}
378+
} else
379+
{
380+
return;
369381
}
370382
}
371383
else
372384
{
373385
string rowLabelsVar = "m_lstRowNumbers"; //Bio2DANumberedRows
374386
var props = export.GetProperty<ArrayProperty<IntProperty>>(rowLabelsVar);
375-
foreach (IntProperty n in props)
387+
if (props != null)
376388
{
377-
rowNames.Add(n.Value.ToString());
389+
foreach (IntProperty n in props)
390+
{
391+
rowNames.Add(n.Value.ToString());
392+
}
393+
} else
394+
{
395+
return;
378396
}
379397
}
380398

@@ -416,7 +434,7 @@ private void StartBio2DAScan(string nodeNameToSelect = null)
416434
if (cellcount > 0)
417435
{
418436

419-
TreeNode node = new TreeNode(curroffset.ToString("X4") + " # of cells in this Bio2DA?? : " + cellcount);
437+
TreeNode node = new TreeNode(curroffset.ToString("X4") + " Number of cells in this Bio2DA : " + cellcount);
420438
node.Name = curroffset.ToString();
421439
topLevelTree.Nodes.Add(node);
422440
curroffset += 4;
@@ -445,6 +463,14 @@ private void StartBio2DAScan(string nodeNameToSelect = null)
445463
//int
446464
int ival = BitConverter.ToInt32(data, curroffset);
447465
valueStr = ival.ToString();
466+
if (stringRefColumns.Contains(columnNames[colindex]))
467+
{
468+
string tlkVal;
469+
if (ME1_TLK_DICT != null && ME1_TLK_DICT.TryGetValue(valueStr, out tlkVal))
470+
{
471+
valueStr += " " + tlkVal;
472+
}
473+
}
448474
curroffset += 4;
449475
tag = nodeType.StructLeafInt;
450476
break;
@@ -457,21 +483,22 @@ private void StartBio2DAScan(string nodeNameToSelect = null)
457483
break;
458484
case 2:
459485
//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+
460497
float fval = BitConverter.ToSingle(data, curroffset);
461498
valueStr = fval.ToString();
462499
curroffset += 4;
463500
tag = nodeType.StructLeafFloat;
464501
break;
465-
case 255:
466-
int unval = BitConverter.ToInt32(data, curroffset);
467-
valueStr = unval.ToString();
468-
curroffset += 4;
469-
break;
470-
default:
471-
valueStr = "UNKNOWN DATATYPE " + dataType + " " + BitConverter.ToInt32(data, curroffset);
472-
curroffset += 4;
473-
break;
474-
475502
}
476503

477504
node = new TreeNode(offsetstr + " " + columnNames[colindex] + ": " + valueStr);
@@ -491,10 +518,9 @@ private void StartBio2DAScan(string nodeNameToSelect = null)
491518
}
492519
else
493520
{
494-
string[] stringRefColumns = { "StringRef" };
495521
curroffset += 4; //theres a 0 here for some reason
496522
cellcount = BitConverter.ToInt32(data, curroffset);
497-
TreeNode node = new TreeNode(curroffset.ToString("X4") + " INDEXED # of cells in this Bio2DA?? : " + cellcount);
523+
TreeNode node = new TreeNode(curroffset.ToString("X4") + " Number of indexed cells in this Bio2DA: " + cellcount);
498524
node.Name = curroffset.ToString();
499525
topLevelTree.Nodes.Add(node);
500526
curroffset += 4; //theres a 0 here for some reason
@@ -532,6 +558,14 @@ private void StartBio2DAScan(string nodeNameToSelect = null)
532558
if (cell != null)
533559
{
534560
columnNode = new TreeNode(columnname + ": " + cell.GetDisplayableValue());
561+
if (stringRefColumns.Contains(columnname))
562+
{
563+
string tlkVal;
564+
if (ME1_TLK_DICT != null && ME1_TLK_DICT.TryGetValue(cell.GetDisplayableValue(), out tlkVal))
565+
{
566+
columnNode.Text += " " + tlkVal;
567+
}
568+
}
535569
switch (cell.Type)
536570
{
537571
case Bio2DACell.TYPE_FLOAT:
@@ -541,14 +575,7 @@ private void StartBio2DAScan(string nodeNameToSelect = null)
541575
columnNode.Tag = nodeType.StructLeafName;
542576
break;
543577
case Bio2DACell.TYPE_INT:
544-
if (stringRefColumns.Contains(columnname))
545-
{
546-
columnNode.Tag = nodeType.StringRefProperty;
547-
}
548-
else
549-
{
550-
columnNode.Tag = nodeType.StructLeafInt;
551-
}
578+
columnNode.Tag = nodeType.StructLeafInt;
552579
break;
553580
}
554581
columnNode.Name = cell.Offset.ToString();
@@ -560,81 +587,6 @@ private void StartBio2DAScan(string nodeNameToSelect = null)
560587
rownode.Nodes.Add(columnNode);
561588
}
562589
}
563-
// //TreeNode rownode = new TreeNode(curroffset.ToString("X4") + ": " + rowNames[i]);
564-
// //rownode.Name = curroffset.ToString();
565-
// //topLevelTree.Nodes.Add(rownode);
566-
// curroffset += 4;
567-
//{
568-
// int index = BitConverter.ToInt32(data, curroffset);
569-
// Console.WriteLine("Index difference " + (index - currentindex));
570-
// try
571-
// {
572-
// if (index - currentindex != 1 && currentindex != -1)
573-
// {
574-
// //skip some columns
575-
// for (int x = 0; x < index - currentindex && colindex + x < columnNames.Count(); x++)
576-
// {
577-
// node = new TreeNode(columnNames[colindex + x] + ": Skipped by table");
578-
// rownode.Nodes.Add(node);
579-
// }
580-
// colindex += index - currentindex;
581-
// continue;
582-
// }
583-
// }
584-
// catch (Exception e)
585-
// {
586-
// // Console.WriteLine(e.Message);
587-
// }
588-
// currentindex = index;
589-
// numindexed++;
590-
// curroffset += 4;
591-
// byte dataType = 255;
592-
// //if (cellcount != 0)
593-
// //{
594-
// dataType = data[curroffset];
595-
// curroffset++;
596-
// //}
597-
// string valueStr = "";
598-
// string nodename = curroffset.ToString();
599-
// string offsetstr = curroffset.ToString("X4");
600-
// switch (dataType)
601-
// {
602-
603-
// case 0:
604-
// //int
605-
// int ival = BitConverter.ToInt32(data, curroffset);
606-
// valueStr = ival.ToString();
607-
// curroffset += 4;
608-
// break;
609-
// case 1:
610-
// //name
611-
// int nval = BitConverter.ToInt32(data, curroffset);
612-
// valueStr = pcc.getNameEntry(nval);
613-
// curroffset += 8;
614-
// break;
615-
// case 2:
616-
// //float
617-
// float fval = BitConverter.ToSingle(data, curroffset);
618-
// valueStr = fval.ToString();
619-
// curroffset += 4;
620-
// break;
621-
// case 255:
622-
// int unval = BitConverter.ToInt32(data, curroffset);
623-
// valueStr = unval.ToString();
624-
// curroffset += 4;
625-
// break;
626-
// default:
627-
// valueStr = "UNKNOWN DATATYPE " + dataType + " " + BitConverter.ToInt32(data, curroffset);
628-
// curroffset += 4;
629-
// break;
630-
631-
// }
632-
633-
// node = new TreeNode(offsetstr + " " + columnNames[colindex] + " as index " + index + ": " + valueStr);
634-
// node.Name = nodename;
635-
// rownode.Nodes.Add(node);
636-
// }
637-
//}
638590
TreeNode nodex = new TreeNode("Number of nodes indexed: " + numindexed);
639591
treeView1.Nodes.Add(nodex);
640592
}
@@ -660,9 +612,18 @@ private void StartBio2DAScan(string nodeNameToSelect = null)
660612
topLevelTree.Name = "0";
661613

662614
treeView1.EndUpdate();
615+
memory = data;
616+
export.Data = data;
663617
memsize = memory.Length;
664618
}
665619

620+
static float NextFloat(Random random)
621+
{
622+
double mantissa = (random.NextDouble() * 2.0) - 1.0;
623+
double exponent = Math.Pow(2.0, random.Next(-3, 20));
624+
return (float)(mantissa * exponent);
625+
}
626+
666627
private void StartWWiseEventScan(string nodeNameToSelect = null)
667628
{
668629
resetPropEditingControls();

ME3Explorer/BinaryInterpreter/Bio2DAProperty.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public string GetDisplayableValue()
3636
return "Unknown type " + Type;
3737
}
3838

39-
int GetIntValue()
39+
public int GetIntValue()
4040
{
4141
return BitConverter.ToInt32(Data, 0);
4242
}

ME3Explorer/PackageEditor/PackageEditor.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@ public void Preview(bool isRefresh = false)
493493
packageEditorTabPane.TabPages.Remove(scriptTab);
494494
}
495495

496-
if (BinaryInterpreter.ParsableBinaryClasses.Contains(exportEntry.ClassName) && pcc.Game == MEGame.ME1)
496+
if (BinaryInterpreter.ParsableBinaryClasses.Contains(exportEntry.ClassName))
497497
{
498498
if (!packageEditorTabPane.TabPages.ContainsKey(nameof(binaryEditorTab)))
499499
{
@@ -514,7 +514,7 @@ public void Preview(bool isRefresh = false)
514514
interpreterControl.export = exportEntry;
515515
interpreterControl.InitInterpreter();
516516

517-
if (BinaryInterpreter.ParsableBinaryClasses.Contains(exportEntry.ClassName) && pcc.Game == MEGame.ME1)
517+
if (BinaryInterpreter.ParsableBinaryClasses.Contains(exportEntry.ClassName))
518518
{
519519
binaryInterpreterControl.export = exportEntry;
520520
binaryInterpreterControl.InitInterpreter();
@@ -2197,7 +2197,7 @@ private void reloadTLKsToolStripMenuItem_Click(object sender, EventArgs e)
21972197

21982198
private void dEBUGCopyConfigurablePropsToClipboardToolStripMenuItem_Click(object sender, EventArgs e)
21992199
{
2200-
string fpath = @"C:\Users\Dev\Documents\DataStore\Mass Effect\BIOGame\CookedPC";
2200+
string fpath = @"X:\Mass Effect Games HDD\Mass Effect";
22012201
var ext = new List<string> { "u", "upk", "sfm" };
22022202
var files = Directory.GetFiles(fpath, "*.*", SearchOption.AllDirectories)
22032203
.Where(file => new string[] { ".sfm", ".upk", ".u" }
@@ -2231,7 +2231,7 @@ private string ScanForConfigValues(string file)
22312231
IMEPackage pack = MEPackageHandler.OpenMEPackage(file);
22322232
foreach (IExportEntry exp in pack.Exports)
22332233
{
2234-
if (exp.ReadsFromConfig)
2234+
if (exp.ClassName == "Bio2DA" || exp.ClassName == "Bio2DANumberedRows")
22352235
{
22362236
if (!fileHasConfig)
22372237
{

0 commit comments

Comments
 (0)