private void hb1_SelectionChanged(object sender, EventArgs e) { int start = (int)Interpreter_Hexbox.SelectionStart; int len = (int)Interpreter_Hexbox.SelectionLength; int size = (int)Interpreter_Hexbox.ByteProvider.Length; try { if (bytes != null && start != -1 && start < size) { string s = $"Byte: {bytes[start]}"; //if selection is same as size this will crash. if (start <= bytes.Length - 4) { int val = BitConverter.ToInt32(bytes, start); s += $", Int: {val}"; s += $", Float: {BitConverter.ToSingle(bytes, start)}"; if (pcc != null) { if (pcc.IsName(val)) { s += $", Name: {pcc.GetNameEntry(val)}"; } if (pcc.GetEntry(val) is ExportEntry exp) { s += $", Export: {exp.ObjectName.Instanced}"; } else if (pcc.GetEntry(val) is ImportEntry imp) { s += $", Import: {imp.ObjectName.Instanced}"; } } } s += $" | Start=0x{start:X8} "; if (len > 0) { s += $"Length=0x{len:X8} "; s += $"End=0x{(start + len - 1):X8}"; } StatusBar_LeftMostText.Text = s; } else { StatusBar_LeftMostText.Text = "Nothing Selected"; } } catch { // ignored } }
public Bio2DA(ExportEntry export) { //Console.WriteLine("Loading " + export.ObjectName); this.export = export; IMEPackage pcc = export.FileRef; byte[] data = export.Data; RowNames = new List <string>(); if (export.ClassName == "Bio2DA") { const string rowLabelsVar = "m_sRowLabel"; var props = export.GetProperty <ArrayProperty <NameProperty> >(rowLabelsVar); if (props != null) { foreach (NameProperty n in props) { RowNames.Add(n.ToString()); } } else { Console.WriteLine("Unable to find row names property!"); Debugger.Break(); return; } } else { var props = export.GetProperty <ArrayProperty <IntProperty> >("m_lstRowNumbers");//Bio2DANumberedRows if (props != null) { foreach (IntProperty n in props) { RowNames.Add(n.Value.ToString()); } } else { Debug.WriteLine("Unable to find row names property (m_lstRowNumbers)!"); //Debugger.Break(); return; } } //Get Columns ColumnNames = new List <string>(); int colcount = BitConverter.ToInt32(data, data.Length - 4); int currentcoloffset = 0; while (colcount >= 0) { currentcoloffset += 4; int colindex = BitConverter.ToInt32(data, data.Length - currentcoloffset); currentcoloffset += 8; //names in this case don't use nameindex values. int nameindex = BitConverter.ToInt32(data, data.Length - currentcoloffset); string name = pcc.GetNameEntry(nameindex); ColumnNames.Insert(0, name); colcount--; } Cells = new Bio2DACell[RowCount, ColumnCount]; currentcoloffset += 4; //column count. int infilecolcount = BitConverter.ToInt32(data, data.Length - currentcoloffset); //start of binary data int binstartoffset = export.propsEnd(); //arrayheader + nonenamesize + number of items in this list int curroffset = binstartoffset; int cellcount = BitConverter.ToInt32(data, curroffset); if (cellcount > 0) { curroffset += 4; for (int rowindex = 0; rowindex < RowCount; rowindex++) { for (int colindex = 0; colindex < ColumnCount && curroffset < data.Length - currentcoloffset; colindex++) { byte dataType = data[curroffset]; curroffset++; int dataSize = dataType == (byte)Bio2DACell.Bio2DADataType.TYPE_NAME ? 8 : 4; byte[] celldata = new byte[dataSize]; Buffer.BlockCopy(data, curroffset, celldata, 0, dataSize); Bio2DACell cell = new Bio2DACell(pcc, curroffset, dataType, celldata); Cells[rowindex, colindex] = cell; curroffset += dataSize; } } PopulatedCellCount = RowCount * ColumnCount; //Required for edits to write correct count if SaveToExport } else { IsIndexed = true; curroffset += 4; //theres a 0 here for some reason cellcount = BitConverter.ToInt32(data, curroffset); curroffset += 4; //curroffset += 4; while (PopulatedCellCount < cellcount) { int index = BitConverter.ToInt32(data, curroffset); int row = index / ColumnCount; int col = index % ColumnCount; curroffset += 4; byte dataType = data[curroffset]; int dataSize = dataType == (byte)Bio2DACell.Bio2DADataType.TYPE_NAME ? 8 : 4; curroffset++; var celldata = new byte[dataSize]; Buffer.BlockCopy(data, curroffset, celldata, 0, dataSize); Bio2DACell cell = new Bio2DACell(pcc, curroffset, dataType, celldata); this[row, col] = cell; curroffset += dataSize; } } //Console.WriteLine("Finished loading " + export.ObjectName); }
internal string ReadName() { return(new NameReference(_package.GetNameEntry(_reader.ReadInt32()), _reader.ReadInt32()).Instanced); }
public static Dictionary <IEntry, List <string> > FindUsagesOfName(this IMEPackage pcc, string name) { var result = new Dictionary <IEntry, List <string> >(); foreach (ExportEntry exp in pcc.Exports) { try { //find header references if (exp.ObjectName.Name == name) { result.AddToListAt(exp, "Header: Object Name"); } if (exp.HasComponentMap && exp.ComponentMap.Any(kvp => kvp.Key.Name == name)) { result.AddToListAt(exp, "Header: ComponentMap"); } if ((!exp.IsDefaultObject && exp.IsA("Component") || pcc.Game == MEGame.UDK && exp.ClassName.EndsWith("Component")) && exp.ParentFullPath.Contains("Default__") && exp.DataSize >= 12 && BitConverter.ToInt32(exp.Data, 4) is int nameIdx && pcc.IsName(nameIdx) && pcc.GetNameEntry(nameIdx) == name) { result.AddToListAt(exp, "Component TemplateName (0x4)"); } //find property references findPropertyReferences(exp.GetProperties(), exp, false, "Property: "); //find binary references if (!exp.IsDefaultObject && ObjectBinary.From(exp) is { } objBin) { if (objBin is BioStage bioStage) { if (bioStage.length > 0 && name == "m_aCameraList") { result.AddToListAt(exp, "(Binary prop: m_aCameraList name)"); } int i = 0; foreach ((NameReference key, PropertyCollection props) in bioStage.CameraList) { if (key.Name == name) { result.AddToListAt(exp, $"(Binary prop: m_aCameraList[{i}])"); } findPropertyReferences(props, exp, false, "Binary prop: m_aCameraList[{i}]."); ++i; } } else if (objBin is UScriptStruct scriptStruct) { findPropertyReferences(scriptStruct.Defaults, exp, false, "Binary Property:"); } else { List <(NameReference, string)> names = objBin.GetNames(exp.FileRef.Game); foreach ((NameReference nameRef, string propName) in names) { if (nameRef.Name == name) { result.AddToListAt(exp, $"(Binary prop: {propName})"); } } } } } catch { result.AddToListAt(exp, "Exception occured while reading this export!"); } } foreach (ImportEntry import in pcc.Imports) { try { if (import.ObjectName.Name == name) { result.AddToListAt(import, "ObjectName"); } if (import.PackageFile == name) { result.AddToListAt(import, "PackageFile"); } if (import.ClassName == name) { result.AddToListAt(import, "Class"); } } catch (Exception e) { result.AddToListAt(import, $"Exception occurred while reading this import: {e.Message}"); } } return(result); void findPropertyReferences(PropertyCollection props, ExportEntry exp, bool isInImmutable = false, string prefix = "") { foreach (Property prop in props) { if (!isInImmutable && prop.Name.Name == name) { result.AddToListAt(exp, $"{prefix}{prop.Name} name"); } switch (prop) { case NameProperty nameProperty: if (nameProperty.Value.Name == name) { result.AddToListAt(exp, $"{prefix}{nameProperty.Name} value"); } break; case DelegateProperty delegateProperty: if (delegateProperty.Value.FunctionName.Name == name) { result.AddToListAt(exp, $"{prefix}{delegateProperty.Name} function name"); } break; case EnumProperty enumProperty: if (pcc.Game >= MEGame.ME3 && !isInImmutable && enumProperty.EnumType.Name == name) { result.AddToListAt(exp, $"{prefix}{enumProperty.Name} enum type"); } if (enumProperty.Value.Name == name) { result.AddToListAt(exp, $"{prefix}{enumProperty.Name} enum value"); } break; case StructProperty structProperty: if (!isInImmutable && structProperty.StructType == name) { result.AddToListAt(exp, $"{prefix}{structProperty.Name} struct type"); } findPropertyReferences(structProperty.Properties, exp, structProperty.IsImmutable, $"{prefix}{structProperty.Name}: "); break; case ArrayProperty <NameProperty> arrayProperty: for (int i = 0; i < arrayProperty.Count; i++) { NameProperty nameProp = arrayProperty[i]; if (nameProp.Value.Name == name) { result.AddToListAt(exp, $"{prefix}{arrayProperty.Name}[{i}]"); } } break; case ArrayProperty <EnumProperty> arrayProperty: for (int i = 0; i < arrayProperty.Count; i++) { EnumProperty enumProp = arrayProperty[i]; if (enumProp.Value.Name == name) { result.AddToListAt(exp, $"{prefix}{arrayProperty.Name}[{i}]"); } } break; case ArrayProperty <StructProperty> arrayProperty: for (int i = 0; i < arrayProperty.Count; i++) { StructProperty structProp = arrayProperty[i]; findPropertyReferences(structProp.Properties, exp, structProp.IsImmutable, $"{prefix}{arrayProperty.Name}[{i}]."); } break; } } } }