private void listBox1_SelectedIndexChanged(object sender, EventArgs e) { int n = listBox1.SelectedIndex; if (n == -1) { return; } rtb1.Text = ""; rtb1.Visible = true; hb1.Visible = false; int index = ObjectIndexes[n]; IExportEntry ex = pcc.Exports[index]; if (ex.ClassName == "WwiseStream") { w = new WwiseStream(pcc as ME3Package, index); string s = "#" + index + " WwiseStream : " + ex.ObjectName + "\n\n"; s += "Filename : \"" + w.FileName + "\"\n"; s += "Data size: " + w.DataSize + " bytes\n"; s += "Data offset: 0x" + w.DataOffset.ToString("X8") + "\n"; s += "ID: 0x" + w.Id.ToString("X8") + " = " + w.Id + "\n"; rtb1.Text = s; } if (ex.ClassName == "WwiseBank") { rtb1.Visible = false; hb1.Visible = true; wb = new WwiseBank(pcc as ME3Package, index); hb1.ByteProvider = new DynamicByteProvider(wb.getBinary()); } }
public static ArrayType getArrayType(string className, string propName, IExportEntry export = null) { PropertyInfo p = getPropertyInfo(className, propName, false, containingExport: export); if (p == null) { p = getPropertyInfo(className, propName, true, containingExport: export); } if (p == null && export != null) { if (export.ClassName != "Class" && export.idxClass > 0) { export = export.FileRef.Exports[export.idxClass - 1]; //make sure you get actual class } if (export.ClassName == "Class") { ClassInfo currentInfo = generateClassInfo(export); currentInfo.baseClass = export.ClassParent; p = getPropertyInfo(className, propName, false, currentInfo, containingExport: export); if (p == null) { p = getPropertyInfo(className, propName, true, currentInfo, containingExport: export); } } } return(getArrayType(p)); }
public string GetFullName(int index) { string s = ""; int i = index; if (i < 0) { i = -i - 1; ImportEntry importEntry = pcc.Imports[i]; if (importEntry.PackageFullName != "Class" && importEntry.PackageFullName != "Package") { s += importEntry.PackageFullName + "."; } s += importEntry.ObjectName; } else if (i > 0) { i--; IExportEntry exportEntry = pcc.Exports[i]; if (exportEntry.PackageFullName != "Class" && exportEntry.PackageFullName != "Package") { s += exportEntry.PackageFullName + "."; } s += exportEntry.ObjectName; } return(s); }
private void directAFCReplaceToolStripMenuItem_Click(object sender, EventArgs e) { if (w.IsPCCStored) { MessageBox.Show("Cannot do an afc replace on a pcc-stored sound."); return; } DirectReplace dr = new DirectReplace(); dr.MdiParent = this.MdiParent; dr.Show(); dr.WindowState = FormWindowState.Maximized; int n = listBox1.SelectedIndex; if (n == -1) { return; } int index = ObjectIndexes[n]; IExportEntry ex = pcc.Exports[index]; if (ex.ClassName == "WwiseStream") { dr.textBox3.Text = w.DataOffset.ToString(); dr.textBox2.Text = w.FileName + ".afc"; } }
public void AddLevel(ME3Package pcc) { try { Levelfile l = new Levelfile(); l.path = pcc.FileName; l.pcc = pcc; IReadOnlyList <IExportEntry> Exports = l.pcc.Exports; for (int i = 0; i < Exports.Count; i++) { IExportEntry e = Exports[i]; if (e.ClassName == "Level") { DebugOutput.Clear(); l.level = new Level(l.pcc, i); TreeNode t = new TreeNode(Path.GetFileName(pcc.FileName)); t.Nodes.Add(l.level.ToTree(i)); GlobalTree.Visible = false; GlobalTree.Nodes.Add(t); GlobalTree.Visible = true; //DirectXGlobal.Cam.dir = new Vector3(1.0f, 1.0f, 1.0f); Levels.Add(l); } } } catch (Exception ex) { MessageBox.Show("Error:\n" + ex.Message); } }
private void LoadSkeletalMesh(IExportEntry export) { Loaded = true; MyIndex = export.Index; Owner = export.FileRef; Flags = (int)(export.ObjectFlags >> 32); int start = GetPropertyEnd(); byte[] data = export.Data; byte[] buff = new byte[data.Length - start]; //for (int i = 0; i < data.Length - start; i++) // buff[i] = data[i + start]; Buffer.BlockCopy(data, start, buff, 0, buff.Length); MemoryStream m = new MemoryStream(buff); SerializingContainer Container = new SerializingContainer(m); Container.isLoading = true; Serialize(Container); try { for (int i = 0; i < Materials.Count; i++) { MatInsts.Add(new MaterialInstanceConstant(Owner, Materials[i] - 1)); } } catch { } }
public TreeNode ToTreeSimple(int nr) { TreeNode t = new TreeNode("#" + nr + " Level"); DebugOutput.PrintLn("Generating Tree..."); for (int i = 0; i < Objects.Count(); i++) { int index = Objects[i]; if (index > 0) { IExportEntry e = pcc.Exports[index]; DebugOutput.PrintLn((i + 1) + " / " + Objects.Count + " : \"" + e.ObjectName + "\" - \"" + e.ClassName + "\""); switch (e.ClassName) { default: string s = "#" + index + " : \""; s += e.ObjectName + "\" CLASS : \""; s += e.ClassName + "\""; TreeNode t1 = new TreeNode(s); t.Nodes.Add(t1); break; } } else { TreeNode t1 = new TreeNode("#" + index + " : NOT IMPLEMENTED"); t.Nodes.Add(t1); } } return(t); }
private void CloneAndReplace(bool fromWave) { string result = PromptDialog.Prompt("Enter a new object name for the cloned item.", "Cloned export name"); if (result != null) { SoundplorerExport spExport = (SoundplorerExport)SoundExports_ListBox.SelectedItem; if (spExport != null && spExport.Export.ClassName == "WwiseStream") { IExportEntry clone = spExport.Export.Clone(); clone.idxObjectName = clone.FileRef.FindNameOrAdd(result); spExport.Export.FileRef.addExport(clone); SoundplorerExport newExport = new SoundplorerExport(clone); BindedExportsList.Add(newExport); var reloadList = new List <SoundplorerExport>(); reloadList.Add(newExport); SoundExports_ListBox.ScrollIntoView(newExport); SoundExports_ListBox.UpdateLayout(); var item = SoundExports_ListBox.ItemContainerGenerator.ContainerFromItem(newExport) as ListBoxItem; if (item != null) { item.Focus(); } if (fromWave) { soundPanel.ReplaceAudioFromWwiseOgg(forcedExport: clone); } else { soundPanel.ReplaceAudioFromWave(forcedExport: clone); } LoadObjects(reloadList); } } }
private void playToolStripMenuItem_Click(object sender, EventArgs e) { int n = listBox1.SelectedIndex; if (n == -1) { return; } int index = ObjectIndexes[n]; IExportEntry ex = pcc.Exports[index]; if (ex.ClassName == "WwiseStream") { Stop(); w = new WwiseStream(pcc as ME3Package, index); string path; if (w.IsPCCStored) { path = pcc.FileName; } else { path = getPathToAFC(); } if (path != "") { Status.Text = "Loading..."; w.Play(path); Status.Text = "Ready"; } } }
/// <summary> /// Replaces the audio in the current loaded export, or the forced export. Will prompt user for a Wwise Encoded Ogg file. /// </summary> /// <param name="forcedExport">Export to update. If null, the currently loadedo ne is used instead.</param> public void ReplaceAudioFromWwiseOgg(string oggPath = null, IExportEntry forcedExport = null) { IExportEntry exportToWorkOn = forcedExport ?? CurrentLoadedExport; if (exportToWorkOn != null && exportToWorkOn.ClassName == "WwiseStream") { WwiseStream w = new WwiseStream(exportToWorkOn); if (w.IsPCCStored) { //TODO: enable replacing of PCC-stored sounds MessageBox.Show("Cannot replace pcc-stored sounds yet."); return; } if (oggPath == null) { OpenFileDialog d = new OpenFileDialog(); d.Filter = "Wwise Encoded Ogg|*.ogg"; bool?res = d.ShowDialog(); if (res.HasValue && res.Value) { oggPath = d.FileName; } else { return; } } w.ImportFromFile(oggPath, w.getPathToAFC()); CurrentLoadedExport.Data = w.memory.TypedClone(); MessageBox.Show("Done"); } }
public async void ReplaceAudioFromWave(string sourceFile = null, IExportEntry forcedExport = null) { string wwisePath = GetWwiseCLIPath(false); if (wwisePath == null) { return; } if (sourceFile == null) { OpenFileDialog d = new OpenFileDialog(); d.Filter = "Wave PCM|*.wav"; bool?res = d.ShowDialog(); if (res.HasValue && res.Value) { sourceFile = d.FileName; } else { return; } } //Convert and rpelace ReplaceAudioFromWwiseOgg(await RunWwiseConversion(wwisePath, sourceFile), forcedExport); }
private void reachspecSizeBox_Changed(object sender, EventArgs e) { int n = reachableNodesList.SelectedIndex; if (n < 0 || n >= reachSpecs.Count) { return; } if (AllowChanges) { int selectedIndex = reachSpecSizeSelector.SelectedIndex; IExportEntry reachSpec = export.FileRef.Exports[reachSpecs[n]]; Unreal.PropertyCollection props = reachSpec.GetProperties(); IntProperty radius = props.GetProp <IntProperty>("CollisionRadius"); IntProperty height = props.GetProp <IntProperty>("CollisionHeight"); if (radius != null && height != null) { int radVal = -1; int heightVal = -1; Point size = getDropdownSizePair(selectedIndex); radVal = size.X; heightVal = size.Y; radius.Value = radVal; height.Value = heightVal; reachSpec.WriteProperties(props); reachSpecSelection_Changed(null, null); } } }
public static void SetLocation(IExportEntry export, float x, float y, float z) { StructProperty prop = export.GetProperty <StructProperty>("location"); SetLocation(prop, x, y, z); export.WriteProperty(prop); }
public static Point3D GetLocation(IExportEntry export) { float x = 0, y = 0, z = int.MinValue; var prop = export.GetProperty <StructProperty>("location"); if (prop != null) { foreach (var locprop in prop.Properties) { switch (locprop) { case FloatProperty fltProp when fltProp.Name == "X": x = fltProp; break; case FloatProperty fltProp when fltProp.Name == "Y": y = fltProp; break; case FloatProperty fltProp when fltProp.Name == "Z": z = fltProp; break; } } return(new Point3D(x, y, z)); } return(null); }
/// <summary> /// Sets the reach spec size and commits the results back to the export /// </summary> /// <param name="spec"></param> /// <param name="radius"></param> /// <param name="height"></param> public static void SetReachSpecSize(IExportEntry spec, int radius, int height) { PropertyCollection specProperties = spec.GetProperties(); SetReachSpecSize(specProperties, radius, height); spec.WriteProperties(specProperties); //write it back. }
private void PlaySound(int n) { int index = ObjectIndexes[n]; IExportEntry ex = pcc.Exports[index]; if (ex.ClassName == "WwiseStream") { Stop(); w = new WwiseStream(pcc as ME3Package, index); string path; if (w.IsPCCStored) { path = pcc.FileName; } else { path = getPathToAFC(); } if (path != "") { Status.Text = "Loading..."; w.Play(path); Status.Text = "Ready"; } } }
public CurveEditor(IExportEntry exp) { InitializeComponent(); expEntry = exp; LoadMEPackage(expEntry.FileRef.FileName); Load(); }
public int ExportMorphsToFbx(string targetDir) { int countMorphNotExported = 0; if (Pcc != null) { var morphExpIndexes = Pcc.Exports.Select((value, index) => new { value, index }) .Where(z => z.value.ClassName == "BioMorphFace") .Select(z => z.index); foreach (int morphIndex in morphExpIndexes) { IExportEntry morphExp = Pcc.Exports[morphIndex]; var morph = new MEMeshMorphExporter.Unreal.BioMorphFace(Pcc, morphIndex); if (morph.IsExportable) { string fileDest = System.IO.Path.Combine(targetDir, morph.Name + ".fbx"); var expMesh = morph.Apply(); ExportMeshWithMorph(morph, 0, fileDest); } else { countMorphNotExported++; } } } return(countMorphNotExported); }
//public static string ReadFunction(IExportEntry export) //{ // UnFunction func = ReadInstance(export.FileRef, new BinaryReader(new MemoryStream(export.Data)), export); // TextBuilder tb = new TextBuilder(); // try // { // func.Decompile(tb); // } // catch (Exception e) // { // return "Error reading function: " + e.ToString(); // } // return tb.ToString(); //} /// <summary> /// Reads the function and returns a parsed object contianing information about the function /// Ported from Unhood (Modified by Mgamerz) /// </summary> /// <param name="export"></param> /// <returns></returns> public static UnFunction ReadFunction(IExportEntry export) { using (BinaryReader reader = new BinaryReader(new MemoryStream(export.Data))) { reader.ReadBytes(12); int super = reader.ReadInt32(); int nextCompilingChainItem = reader.ReadInt32(); reader.ReadBytes(12); int line = reader.ReadInt32(); //?? int textPos = reader.ReadInt32(); //?? int scriptSize = reader.ReadInt32(); byte[] bytecode = reader.ReadBytes(scriptSize); int nativeIndex = reader.ReadInt16(); int operatorPrecedence = reader.ReadByte(); int functionFlags = reader.ReadInt32(); if ((functionFlags & _flagSet.GetMask("Net")) != 0) { reader.ReadInt16(); // repOffset } int friendlyNameIndex = reader.ReadInt32(); reader.ReadInt32(); return(new UnFunction(export, export.FileRef.getNameEntry(friendlyNameIndex), new FlagValues(functionFlags, _flagSet), bytecode, nativeIndex, operatorPrecedence)); } }
public CurveEditor(IExportEntry exp) { InitializeComponent(); expEntry = exp; LoadMEPackage(expEntry.FileRef.FileName); Load(); }
public CurveEditorHost(IExportEntry exp) { InitializeComponent(); this.exp = exp; CurveEditor_SubModule.LoadExport(exp); Title = "Curve Editor | " + System.IO.Path.GetFileName(exp.FileRef.FileName) + " | " + exp.Index + ": " + exp.ClassName; }
private void ReadExports(MemoryStream fs) { DebugOutput.PrintLn("Reading Exports..."); fs.Seek(ExportOffset, SeekOrigin.Begin); Exports = new List <ME2ExportEntry>(); for (int i = 0; i < ExportCount; i++) { long start = fs.Position; ME2ExportEntry exp = new ME2ExportEntry(); exp.pccRef = this; exp.infoOffset = (int)start; fs.Seek(40, SeekOrigin.Current); int count = fs.ReadValueS32(); fs.Seek(4 + count * 12, SeekOrigin.Current); count = fs.ReadValueS32(); fs.Seek(4 + count * 4, SeekOrigin.Current); fs.Seek(16, SeekOrigin.Current); long end = fs.Position; fs.Seek(start, SeekOrigin.Begin); exp.info = fs.ReadBytes((int)(end - start)); Exports.Add(exp); fs.Seek(end, SeekOrigin.Begin); if (LastExport == null || exp.DataOffset > LastExport.DataOffset) { LastExport = exp; } } }
public void serializeTLKStrListToExport(IExportEntry export, bool savePackage = false) { if (export.FileRef.Game != MEGame.ME1) { throw new Exception("Cannot save a ME1 TLK to a game that is not Mass Effect 1."); } serializeTalkfileToExport(export.FileRef as ME1Package, export, savePackage); }
public ReachSpecUpdaterUIThreadOptions(IExportEntry reachSpecExport, int calculatedProperDistance, float dirX, float dirY, float dirZ) { this.reachSpecExport = reachSpecExport; this.calculatedProperDistance = calculatedProperDistance; this.dirX = dirX; this.dirY = dirY; this.dirZ = dirZ; }
public WwiseStream(IMEPackage pcc, int index) { Index = index; export = pcc.Exports[Index]; memory = pcc.Exports[Index].Data; memsize = memory.Length; Deserialize(pcc); }
public WwiseStream(IExportEntry export) { this.export = export; Index = export.Index; memory = export.Data; memsize = memory.Length; Deserialize(export.FileRef); }
public static List <Property> getPropList(IExportEntry export) { Application.DoEvents(); byte[] data = export.Data; int start = detectStart(export.FileRef, data, export.ObjectFlags); return(ReadProp(export.FileRef, data, start)); }
internal static ClassInfo generateClassInfo(IExportEntry export) { if (!IsLoaded) { loadfromJSON(); } return(generateClassInfo(export.Index, export.FileRef as UDKPackage)); }
internal UnFunction(IExportEntry export, string name, FlagValues flags, byte[] bytecode, int nativeIndex, int operatorPrecedence) : base(export, bytecode) { _name = name; _flags = flags; _nativeIndex = nativeIndex; _operatorPrecedence = operatorPrecedence; }
private int ClassParser_ReadImplementsTable(IMEPackage importpcc, IExportEntry exp, List <string> relinkFailedReport, ref byte[] data, int offset) { if (importpcc.Game == MEGame.ME3) { int interfaceCount = BitConverter.ToInt32(data, offset); offset += 4; for (int i = 0; i < interfaceCount; i++) { int interfaceIndex = BitConverter.ToInt32(data, offset); int mapped; bool isMapped = crossPCCObjectMap.TryGetValue(interfaceIndex, out mapped); if (isMapped) { mapped = me3ExpIndexingToUnreal(mapped, interfaceIndex < 0); //if the value is 0, it would have an error anyways. WriteMem(offset, data, BitConverter.GetBytes(mapped)); } else { relinkFailedReport.Add("Binary Class Interface Index[" + i + "] could not be remapped during porting: " + interfaceIndex + " is not in the mapping tree"); } offset += 4; //propertypointer interfaceIndex = BitConverter.ToInt32(data, offset); isMapped = crossPCCObjectMap.TryGetValue(interfaceIndex, out mapped); if (isMapped) { mapped = me3ExpIndexingToUnreal(mapped, interfaceIndex < 0); //if the value is 0, it would have an error anyways. WriteMem(offset, data, BitConverter.GetBytes(mapped)); } else { relinkFailedReport.Add("Binary Class Interface Index[" + i + "] could not be remapped during porting: " + interfaceIndex + " is not in the mapping tree"); } offset += 4; } } else { int interfaceTableName = BitConverter.ToInt32(data, offset); //???? NameReference importingName = importpcc.getNameEntry(interfaceTableName); int interfaceName = exp.FileRef.FindNameOrAdd(importingName); WriteMem(offset, data, BitConverter.GetBytes(interfaceName)); offset += 8; int interfaceCount = BitConverter.ToInt32(data, offset); offset += 4; for (int i = 0; i < interfaceCount; i++) { int interfaceNameIndex = BitConverter.ToInt32(data, offset); importingName = importpcc.getNameEntry(interfaceNameIndex); interfaceName = exp.FileRef.FindNameOrAdd(importingName); WriteMem(offset, data, BitConverter.GetBytes(interfaceName)); offset += 8; } } return(offset); }
public static void OpenCurveEditorInWindow(IExportEntry export) { ExportLoaderHostedWindow elhw = new ExportLoaderHostedWindow(new CurveEditor(), export) { Title = $"Curve Editor - {export.UIndex} {export.GetFullPath}_{export.indexValue} - {export.FileRef.FileName}" }; elhw.Show(); }
public ME3FaceFXAnimSet(IMEPackage Pcc, IExportEntry Entry) { pcc = Pcc; export = Entry; List<PropertyReader.Property> props = PropertyReader.getPropList(export); int start = props[props.Count - 1].offend + 4; SerializingContainer Container = new SerializingContainer(new MemoryStream(export.Data.Skip(start).ToArray())); Container.isLoading = true; Serialize(Container); }
protected SObj(int idx, IMEPackage p) { pcc = p; index = idx; export = pcc.getExport(index); comment = new SText(GetComment(), commentColor, false); comment.X = 0; comment.Y = 0 - comment.Height; comment.Pickable = false; this.AddChild(comment); this.Pickable = true; }
public void ReadGUIDs(IExportEntry export) { props = PropertyReader.getPropList(export); byte[] buff = export.Data; int pos = props[props.Count - 1].offend; int count = BitConverter.ToInt32(buff, pos); pos += 4; GUIDs = new List<GuidEntry>(); for (int i = 0; i < count; i++) { GuidEntry g = new GuidEntry(); g.NameIdx = BitConverter.ToInt32(buff, pos); g.Name = pcc.getNameEntry(g.NameIdx); g.GUID = new byte[16]; for (int j = 0; j < 16; j++) g.GUID[j] = buff[pos + j + 8]; GUIDs.Add(g); pos += 24; } }
public void addExport(IExportEntry entry) { throw new NotImplementedException(); }
private void ReadExports(MemoryTributary fs) { DebugOutput.PrintLn("Reading Exports..."); fs.Seek(ExportOffset, SeekOrigin.Begin); Exports = new List<ME2ExportEntry>(); for (int i = 0; i < ExportCount; i++) { long start = fs.Position; ME2ExportEntry exp = new ME2ExportEntry(); exp.pccRef = this; exp.infoOffset = (int)start; fs.Seek(40, SeekOrigin.Current); int count = fs.ReadValueS32(); fs.Seek(4 + count * 12, SeekOrigin.Current); count = fs.ReadValueS32(); fs.Seek(4 + count * 4, SeekOrigin.Current); fs.Seek(16, SeekOrigin.Current); long end = fs.Position; fs.Seek(start, SeekOrigin.Begin); exp.info = fs.ReadBytes((int)(end - start)); Exports.Add(exp); fs.Seek(end, SeekOrigin.Begin); if (LastExport == null || exp.DataOffset > LastExport.DataOffset) LastExport = exp; } }
public static Property getPropOrNull(IExportEntry export, string propName) { List<Property> props = getPropList(export); foreach (Property prop in props) { if (export.FileRef.getNameEntry(prop.Name) == propName) { return prop; } } return null; }
public static List<Property> getPropList(IExportEntry export) { Application.DoEvents(); byte[] data = export.Data; int start = detectStart(export.FileRef, data, export.ObjectFlags); return ReadProp(export.FileRef, data, start); }
private static PropertyInfo getProperty(ME3Package pcc, IExportEntry entry) { PropertyInfo p = new PropertyInfo(); switch (entry.ClassName) { case "IntProperty": p.type = PropertyType.IntProperty; break; case "StringRefProperty": p.type = PropertyType.StringRefProperty; break; case "FloatProperty": p.type = PropertyType.FloatProperty; break; case "BoolProperty": p.type = PropertyType.BoolProperty; break; case "StrProperty": p.type = PropertyType.StrProperty; break; case "NameProperty": p.type = PropertyType.NameProperty; break; case "DelegateProperty": p.type = PropertyType.DelegateProperty; break; case "ObjectProperty": case "ClassProperty": case "ComponentProperty": p.type = PropertyType.ObjectProperty; p.reference = pcc.getObjectName(BitConverter.ToInt32(entry.Data, entry.Data.Length - 4)); break; case "StructProperty": p.type = PropertyType.StructProperty; p.reference = pcc.getObjectName(BitConverter.ToInt32(entry.Data, entry.Data.Length - 4)); break; case "BioMask4Property": case "ByteProperty": p.type = PropertyType.ByteProperty; p.reference = pcc.getObjectName(BitConverter.ToInt32(entry.Data, entry.Data.Length - 4)); break; case "ArrayProperty": p.type = PropertyType.ArrayProperty; PropertyInfo arrayTypeProp = getProperty(pcc, pcc.Exports[BitConverter.ToInt32(entry.Data, 44) - 1]); if (arrayTypeProp != null) { switch (arrayTypeProp.type) { case PropertyType.ObjectProperty: case PropertyType.StructProperty: case PropertyType.ArrayProperty: p.reference = arrayTypeProp.reference; break; case PropertyType.ByteProperty: if (arrayTypeProp.reference == "") p.reference = arrayTypeProp.type.ToString(); else p.reference = arrayTypeProp.reference; break; case PropertyType.IntProperty: case PropertyType.FloatProperty: case PropertyType.NameProperty: case PropertyType.BoolProperty: case PropertyType.StrProperty: case PropertyType.StringRefProperty: case PropertyType.DelegateProperty: p.reference = arrayTypeProp.type.ToString(); break; case PropertyType.None: case PropertyType.Unknown: default: System.Diagnostics.Debugger.Break(); p = null; break; } } else { p = null; } break; case "InterfaceProperty": default: p = null; break; } return p; }
public void addExport(IExportEntry exportEntry) { if (exportEntry.pccRef != this) throw new Exception("you cannot add a new export entry from another pcc file, it has invalid references!"); exportEntry.hasChanged = true; //changing data offset in order to append it at the end of the file ME3ExportEntry lastExport = Exports.Find(export => export.DataOffset == Exports.Max(entry => entry.DataOffset)); int lastOffset = (int)(lastExport.DataOffset + lastExport.Data.Length); exportEntry.DataOffset = (uint)lastOffset; Exports.Add((ME3ExportEntry)exportEntry); }
static void addObjectToSequence(int index, bool removeLinks, IExportEntry sequenceExport) { var seqObjs = sequenceExport.GetProperty<ArrayProperty<ObjectProperty>>("SequenceObjects"); if (seqObjs != null) { seqObjs.Add(new ObjectProperty(index + 1)); sequenceExport.WriteProperty(seqObjs); PropertyCollection props = sequenceExport.GetProperties(); IExportEntry newObject = sequenceExport.FileRef.getExport(index); PropertyCollection newObjectProps = newObject.GetProperties(); newObjectProps.AddOrReplaceProp(new ObjectProperty(sequenceExport.UIndex, "ParentSequence")); if (removeLinks) { var outLinksProp = newObjectProps.GetProp<ArrayProperty<StructProperty>>("OutputLinks"); if (outLinksProp != null) { foreach (var prop in outLinksProp) { prop.GetProp<ArrayProperty<StructProperty>>("Links").Clear(); } } var varLinksProp = newObjectProps.GetProp<ArrayProperty<StructProperty>>("VariableLinks"); if (varLinksProp != null) { foreach (var prop in varLinksProp) { prop.GetProp<ArrayProperty<ObjectProperty>>("LinkedVariables").Clear(); } } } newObject.WriteProperties(newObjectProps); newObject.idxLink = sequenceExport.UIndex; } }
public void GetObjects(IExportEntry export) { CurrentObjects = new List<int>(); listBox1.Items.Clear(); var seqObjs = export.GetProperty<ArrayProperty<ObjectProperty>>("SequenceObjects"); if (seqObjs != null) foreach (ObjectProperty seqObj in seqObjs) { int m = seqObj.Value - 1; CurrentObjects.Add(m); listBox1.Items.Add("#" + m + " :" + pcc.getExport(m).ObjectName + " class: " + pcc.getExport(m).ClassName); } }
public void GetProperties(IExportEntry export) { List<PropertyReader.Property> p; switch (export.ClassName) { default: p = PropertyReader.getPropList(export); break; } pg = new PropGrid(); pg1.SelectedObject = pg; for (int l = 0; l < p.Count; l++) pg.Add(PropertyReader.PropertyToGrid(p[l], pcc)); pg1.Refresh(); }
private void SetupJSON(IExportEntry export) { string objectName = System.Text.RegularExpressions.Regex.Replace(export.ObjectName, @"[<>:""/\\|?*]", ""); bool isClonedSeqRef = false; var defaultViewZoomProp = export.GetProperty<FloatProperty>("DefaultViewZoom"); if (defaultViewZoomProp != null && Math.Abs(defaultViewZoomProp.Value - CLONED_SEQREF_MAGIC) < 1.0E-30f) { isClonedSeqRef = true; } string packageFullName = export.PackageFullName; if (useGlobalSequenceRefSavesToolStripMenuItem.Checked && packageFullName.Contains("SequenceReference") && !isClonedSeqRef) { if (pcc.Game == MEGame.ME3) { JSONpath = ME3ViewsPath + packageFullName.Substring(packageFullName.LastIndexOf("SequenceReference")) + "." + objectName + ".JSON"; } else { string packageName = export.PackageFullName.Substring(export.PackageFullName.LastIndexOf("SequenceReference")); packageName = packageName.Replace("SequenceReference", ""); int idx = export.Index; string ObjName = ""; while (idx > 0) { if (pcc.getExport(pcc.getExport(idx).idxLink - 1).ClassName == "SequenceReference") { var objNameProp = pcc.getExport(idx).GetProperty<StrProperty>("ObjName"); if (objNameProp != null) { ObjName = objNameProp.Value; break; } } idx = pcc.getExport(idx).idxLink - 1; } if (objectName == "Sequence") { objectName = ObjName; packageName = "." + packageName; } else packageName = packageName.Replace("Sequence", ObjName) + "."; if (pcc.Game == MEGame.ME2) { JSONpath = ME2ViewsPath + "SequenceReference" + packageName + objectName + ".JSON"; } else { JSONpath = ME1ViewsPath + "SequenceReference" + packageName + objectName + ".JSON"; } } RefOrRefChild = true; } else { string viewsPath = ME3ViewsPath; if (pcc.Game == MEGame.ME2) { viewsPath = ME2ViewsPath; } else if (pcc.Game == MEGame.ME1) { viewsPath = ME1ViewsPath; } JSONpath = viewsPath + CurrentFile.Substring(CurrentFile.LastIndexOf(@"\") + 1) + ".#" + export.Index + objectName + ".JSON"; RefOrRefChild = false; } }
private void LoadSequence(IExportEntry seqExport, bool fromFile = true) { graphEditor.Enabled = false; graphEditor.UseWaitCursor = true; Sequence = seqExport; toolStripStatusLabel2.Text = "\t#" + Sequence.Index + Sequence.ObjectName; GetProperties(Sequence); GetObjects(Sequence); SetupJSON(Sequence); if(SavedPositions == null) SavedPositions = new List<SaveData>(); if (fromFile && File.Exists(JSONpath)) SavedPositions = JsonConvert.DeserializeObject<List<SaveData>>(File.ReadAllText(JSONpath)); GenerateGraph(); selectedIndex = -1; graphEditor.Enabled = true; graphEditor.UseWaitCursor = false; }
static void cloneSequence(IExportEntry exp, IExportEntry parentSequence) { IMEPackage pcc = exp.FileRef; if (exp.ClassName == "Sequence") { var seqObjs = exp.GetProperty<ArrayProperty<ObjectProperty>>("SequenceObjects"); if (seqObjs == null || seqObjs.Count == 0) { return; } //store original list of sequence objects; List<int> oldObjects = seqObjs.Select(x => x.Value).ToList(); //clear original sequence objects seqObjs.Clear(); exp.WriteProperty(seqObjs); //clone all children for (int i = 0; i < oldObjects.Count; i++) { cloneObject(oldObjects[i] - 1, exp, false); } //re-point children's links to new objects seqObjs = exp.GetProperty<ArrayProperty<ObjectProperty>>("SequenceObjects"); foreach (var seqObj in seqObjs) { IExportEntry obj = pcc.getExport(seqObj.Value - 1); var props = obj.GetProperties(); var outLinksProp = props.GetProp<ArrayProperty<StructProperty>>("OutputLinks"); if (outLinksProp != null) { foreach (var outLinkStruct in outLinksProp) { var links = outLinkStruct.GetProp<ArrayProperty<StructProperty>>("Links"); foreach (var link in links) { var linkedOp = link.GetProp<ObjectProperty>("LinkedOp"); linkedOp.Value = seqObjs[oldObjects.IndexOf(linkedOp.Value)].Value; } } } var varLinksProp = props.GetProp<ArrayProperty<StructProperty>>("VariableLinks"); if (varLinksProp != null) { foreach (var varLinkStruct in varLinksProp) { var links = varLinkStruct.GetProp<ArrayProperty<ObjectProperty>>("LinkedVariables"); foreach (var link in links) { link.Value = seqObjs[oldObjects.IndexOf(link.Value)].Value; } } } var eventLinksProp = props.GetProp<ArrayProperty<StructProperty>>("EventLinks"); if (eventLinksProp != null) { foreach (var eventLinkStruct in eventLinksProp) { var links = eventLinkStruct.GetProp<ArrayProperty<ObjectProperty>>("LinkedEvents"); foreach (var link in links) { link.Value = seqObjs[oldObjects.IndexOf(link.Value)].Value; } } } obj.WriteProperties(props); } //re-point sequence links to new objects int oldObj = 0; int newObj = 0; var propCollection = exp.GetProperties(); var inputLinksProp = propCollection.GetProp<ArrayProperty<StructProperty>>("InputLinks"); if (inputLinksProp != null) { foreach (var inLinkStruct in inputLinksProp) { var linkedOp = inLinkStruct.GetProp<ObjectProperty>("LinkedOp"); oldObj = linkedOp.Value; if (oldObj != 0) { newObj = seqObjs[oldObjects.IndexOf(oldObj)].Value; linkedOp.Value = newObj; NameProperty linkAction = inLinkStruct.GetProp<NameProperty>("LinkAction"); var nameRef = linkAction.Value; nameRef.count = pcc.getExport(newObj - 1).indexValue; linkAction.Value = nameRef; } } } var outputLinksProp = propCollection.GetProp<ArrayProperty<StructProperty>>("OutputLinks"); if (outputLinksProp != null) { foreach (var outLinkStruct in outputLinksProp) { var linkedOp = outLinkStruct.GetProp<ObjectProperty>("LinkedOp"); oldObj = linkedOp.Value; if (oldObj != 0) { newObj = seqObjs[oldObjects.IndexOf(oldObj)].Value; linkedOp.Value = newObj; NameProperty linkAction = outLinkStruct.GetProp<NameProperty>("LinkAction"); var nameRef = linkAction.Value; nameRef.count = pcc.getExport(newObj - 1).indexValue; linkAction.Value = nameRef; } } } exp.WriteProperties(propCollection); } else if (exp.ClassName == "SequenceReference") { //set OSequenceReference to new sequence var oSeqRefProp = exp.GetProperty<ObjectProperty>("oSequenceReference"); if (oSeqRefProp == null || oSeqRefProp.Value == 0) { return; } int oldSeqIndex = oSeqRefProp.Value; oSeqRefProp.Value = exp.UIndex + 1; exp.WriteProperty(oSeqRefProp); //clone sequence cloneObject(oldSeqIndex - 1, parentSequence, false); //remove cloned sequence from SeqRef's parent's sequenceobjects var seqObjs = parentSequence.GetProperty<ArrayProperty<ObjectProperty>>("SequenceObjects"); seqObjs.RemoveAt(seqObjs.Count - 1); parentSequence.WriteProperty(seqObjs); //set SequenceReference's linked name indices List<int> inputIndices = new List<int>(); List<int> outputIndices = new List<int>(); IExportEntry newSequence = pcc.getExport(exp.Index + 1); var props = newSequence.GetProperties(); var inLinksProp = props.GetProp<ArrayProperty<StructProperty>>("InputLinks"); if (inLinksProp != null) { foreach (var inLink in inLinksProp) { inputIndices.Add(inLink.GetProp<NameProperty>("LinkAction").Value.count); } } var outLinksProp = props.GetProp<ArrayProperty<StructProperty>>("OutputLinks"); if (outLinksProp != null) { foreach (var outLinks in outLinksProp) { outputIndices.Add(outLinks.GetProp<NameProperty>("LinkAction").Value.count); } } props = exp.GetProperties(); inLinksProp = props.GetProp<ArrayProperty<StructProperty>>("InputLinks"); if (inLinksProp != null) { for (int i = 0; i < inLinksProp.Count; i++) { NameProperty linkAction = inLinksProp[i].GetProp<NameProperty>("LinkAction"); var nameRef = linkAction.Value; nameRef.count = inputIndices[i]; linkAction.Value = nameRef; } } outLinksProp = props.GetProp<ArrayProperty<StructProperty>>("OutputLinks"); if (outLinksProp != null) { for (int i = 0; i < outLinksProp.Count; i++) { NameProperty linkAction = outLinksProp[i].GetProp<NameProperty>("LinkAction"); var nameRef = linkAction.Value; nameRef.count = outputIndices[i]; linkAction.Value = nameRef; } } exp.WriteProperties(props); //set new Sequence's link and ParentSequence prop to SeqRef newSequence.WriteProperty(new ObjectProperty(exp.UIndex, "ParentSequence")); newSequence.idxLink = exp.UIndex; //set DefaultViewZoom to magic number to flag that this is a cloned Sequence Reference and global saves cannot be used with it //ugly, but it should work newSequence.WriteProperty(new FloatProperty(CLONED_SEQREF_MAGIC, "DefaultViewZoom")); } }
static void cloneObject(int n, IExportEntry sequence, bool topLevel = true) { IMEPackage pcc = sequence.FileRef; IExportEntry exp = pcc.getExport(n).Clone(); //needs to have the same index to work properly if (exp.ClassName == "SeqVar_External") { exp.indexValue = pcc.getExport(n).indexValue; } pcc.addExport(exp); addObjectToSequence(exp.Index, topLevel, sequence); cloneSequence(exp, sequence); }
public void addExport(IExportEntry exportEntry) { if (exportEntry is ME1ExportEntry) { addExport(exportEntry as ME1ExportEntry); } else { throw new FormatException("Cannot add export to an ME1 package that is not from ME1"); } }