public ME1BioConversation(ME1Package Pcc, int Index) { pcc = Pcc; MyIndex = Index; Memory = pcc.Exports[Index].Data; ReadData(); }
public TalkFile(ME1Package _pcc, int _index) { pcc = _pcc; index = _index; tlkSetIndex = -1; LoadTlkData(); }
public void InitTlkManager(ME1Package pcc, BioTlkFileSet tlkSet, TalkFiles tlks = null) { packages = new List <ME1Package>(); tlkFileSets = new List <BioTlkFileSet>(); selectedTlks = tlks ?? new TalkFiles(); packages.Add(pcc); refreshFileBox(); fileBox.SelectedIndex = 0; Application.DoEvents(); for (int i = 0; i < tlkFileSets.Count; i++) { if (tlkFileSets[i].index == tlkSet.index) { bioTlkSetBox.SelectedIndex = i; Application.DoEvents(); tlkFileBox.SelectedIndex = tlkSet.selectedTLK; break; } } TalkFile tlk = tlkSet.talkFiles[tlkSet.selectedTLK]; if (!selectedTlks.tlkList.Contains(tlk)) { selectedTlks.tlkList.Add(tlk); } foreach (TalkFile tlkFile in selectedTlks.tlkList) { selectedTlkFilesBox.Items.Add(Path.GetFileName(pcc.FileName) + " -> " + tlkFile.BioTlkSetName + tlkFile.Name); } }
private static ClassInfo generateClassInfo(int index, ME1Package pcc) { ClassInfo info = new ClassInfo { baseClass = pcc.Exports[index].ClassParent, exportIndex = index }; if (pcc.FileName.Contains("BioGame")) { info.pccPath = new string(pcc.FileName.Skip(pcc.FileName.LastIndexOf("BioGame") + 8).ToArray()); } else { info.pccPath = pcc.FileName; //used for dynamic resolution of files outside the game directory. } foreach (IExportEntry entry in pcc.Exports) { if (entry.idxLink - 1 == index && entry.ClassName != "ScriptStruct" && entry.ClassName != "Enum" && entry.ClassName != "Function" && entry.ClassName != "Const" && entry.ClassName != "State") { //Skip if property is transient (only used during execution, will never be in game files) if ((BitConverter.ToUInt64(entry.Data, 24) & 0x0000000000002000) == 0 && !info.properties.ContainsKey(entry.ObjectName)) { PropertyInfo p = getProperty(pcc, entry); if (p != null) { info.properties.Add(entry.ObjectName, p); } } } } return(info); }
public TreeNode ToTree(int MyIndex, ITalkFile talk, ME1Package pcc) { string s = ""; if (Text.Length != 0) { s = Text.Substring(0, Text.Length - 1); } TreeNode res = new TreeNode(MyIndex + " : " + s + " " + talk.findDataById(refText)); TreeNode t = new TreeNode("Entry List"); for (int i = 0; i < EntryList.Count; i++) { t.Nodes.Add(i + " : " + EntryList[i]); } res.Nodes.Add(t); res.Nodes.Add("Listener Index : " + ListenerIndex); res.Nodes.Add("Unskippable : " + Unskippable); res.Nodes.Add("ReplyType : " + pcc.getNameEntry(ReplyTypeValue)); res.Nodes.Add("Text : " + Text); res.Nodes.Add("refText : " + refText + " " + talk.findDataById(refText, true)); res.Nodes.Add("ConditionalFunc : " + ConditionalFunc); res.Nodes.Add("ConditionalParam : " + ConditionalParam); res.Nodes.Add("StateTransition : " + StateTransition); res.Nodes.Add("StateTransitionParam : " + StateTransitionParam); res.Nodes.Add("ExportID : " + ExportID); res.Nodes.Add("ScriptIndex : " + ScriptIndex); res.Nodes.Add("CameraIntimacy : " + CameraIntimacy); res.Nodes.Add("FireConditional : " + FireConditional); res.Nodes.Add("Ambient : " + Ambient); res.Nodes.Add("NonTextline : " + NonTextLine); res.Nodes.Add("IgnoreBodyGestures : " + IgnoreBodyGestures); res.Nodes.Add("GUIStyle : " + pcc.getNameEntry(GUIStyleValue)); return(res); }
public void LoadData() { Save.ExtractME1Package(0, "load.upk"); ME1Package pcc = MEPackageHandler.OpenME1Package("load.upk"); File.Delete("load.upk"); byte[] buff = pcc.Exports[1].Data; List <PropertyReader.Property> props = PropertyReader.getPropList(pcc.Exports[1]); foreach (PropertyReader.Property p in props) { string name = pcc.getNameEntry(p.Name); switch (name) { case "m_nResourceCredits": textBox1.Text = BitConverter.ToInt32(buff, p.offend - 4).ToString(); break; case "m_nResourceGrenades": textBox2.Text = BitConverter.ToInt32(buff, p.offend - 4).ToString(); break; case "m_fResourceMedigel": textBox3.Text = BitConverter.ToSingle(buff, p.offend - 4).ToString(); break; case "m_fResourceSalvage": textBox4.Text = BitConverter.ToSingle(buff, p.offend - 4).ToString(); break; } } textBox5.Text = BitConverter.ToInt32(Save.Files[1].memory.ToArray(), 0x4A7).ToString(); //Paragon textBox6.Text = BitConverter.ToInt32(Save.Files[1].memory.ToArray(), 0x4A3).ToString(); //Renegade }
public Function(byte[] raw, ME1Package Pcc) { pcc = Pcc; memory = raw; memsize = raw.Length; flagint = GetFlagInt(); nativeindex = GetNatIdx(); Deserialize(); }
public TalkFile(ME1Package _pcc, int _index, bool _male, int _langRef, int _tlkSetIndex) { pcc = _pcc; index = _index; LangRef = _langRef; male = _male; tlkSetIndex = _tlkSetIndex; LoadTlkData(); }
public TreeNode ToTree(int MyIndex, ITalkFile talk, ME1Package pcc) { string s = ""; if (Text.Length != 0) { s = Text.Substring(0, Text.Length - 1); } TreeNode res = new TreeNode(MyIndex + " : " + s + " " + talk.findDataById(refText)); TreeNode t = new TreeNode("Reply List"); for (int i = 0; i < ReplyList.Count; i++) { EntryListReplyListStruct e = ReplyList[i]; string par = e.Paraphrase; if (par.Length != 0 && par[par.Length - 1] == '\0') { par = par.Substring(0, par.Length - 1); } t.Nodes.Add(i + " : " + par + " " + e.refParaphrase + " " + talk.findDataById(e.refParaphrase) + " " + e.Index + " " + pcc.getNameEntry(e.CategoryValue)); } res.Nodes.Add(t); TreeNode t2 = new TreeNode("Speaker List"); for (int i = 0; i < SpeakerList.Count; i++) { t2.Nodes.Add(i + " : " + SpeakerList[i]); } res.Nodes.Add(t2); res.Nodes.Add("SpeakerIndex : " + SpeakerIndex); res.Nodes.Add("ListenerIndex : " + ListenerIndex); res.Nodes.Add("ConditionalFunc : " + ConditionalFunc); res.Nodes.Add("ConditionalParam : " + ConditionalParam); res.Nodes.Add("StateTransition : " + StateTransition); res.Nodes.Add("StateTransitionParam : " + StateTransitionParam); res.Nodes.Add("ExportID : " + ExportID); res.Nodes.Add("ScriptIndex : " + ScriptIndex); res.Nodes.Add("CameraIntimacy : " + CameraIntimacy); res.Nodes.Add("Skippable : " + Skippable); res.Nodes.Add("FireConditional : " + FireConditional); res.Nodes.Add("Ambient : " + Ambient); res.Nodes.Add("NonTextline : " + NonTextline); res.Nodes.Add("IgnoreBodyGestures : " + IgnoreBodyGestures); res.Nodes.Add("Text : " + Text); res.Nodes.Add("refText : " + refText + " " + talk.findDataById(refText, true)); res.Nodes.Add("GUIStyle : " + pcc.getNameEntry(GUIStyleValue)); return(res); }
public static void LoadTlkData(string fileName, int index) { if (File.Exists(fileName)) { ME1Package pcc = MEPackageHandler.OpenME1Package(fileName); TalkFile tlk = new TalkFile(pcc, index); tlk.LoadTlkData(); tlkList.Add(tlk); } }
public TalkFile(IExportEntry export) { if (export.FileRef.Game != MEGame.ME1) { throw new Exception("ME1 Unreal TalkFile cannot be initialized with a non-ME1 file"); } pcc = export.FileRef as ME1Package; index = export.Index; tlkSetIndex = -1; LoadTlkData(); }
public void LoadGlobalTlk() { string path = ME1Directory.cookedPath + @"Packages\Dialog\GlobalTlk.upk"; try { ME1Package pcc = MEPackageHandler.OpenME1Package(path); tlkList.Add(new TalkFile(pcc, 0)); } catch (Exception) { return; } }
public void SaveData() { Save.ExtractME1Package(0, "save.upk"); ME1Package pcc = MEPackageHandler.OpenME1Package("save.upk"); File.Delete("save.upk"); byte[] buff = pcc.Exports[1].Data; List <PropertyReader.Property> props = PropertyReader.getPropList(pcc.Exports[1]); int v; float f; foreach (PropertyReader.Property p in props) { string name = pcc.getNameEntry(p.Name); switch (name) { case "m_nResourceCredits": v = Convert.ToInt32(textBox1.Text); buff = WriteInt(buff, p.offend - 4, v); break; case "m_nResourceGrenades": v = Convert.ToInt32(textBox2.Text); buff = WriteInt(buff, p.offend - 4, v); break; case "m_fResourceMedigel": f = Convert.ToSingle(textBox3.Text); buff = WriteFloat(buff, p.offend - 4, f); break; case "m_fResourceSalvage": f = Convert.ToSingle(textBox4.Text); buff = WriteFloat(buff, p.offend - 4, f); break; } } pcc.Exports[1].Data = buff; pcc.save(); Save.ImportME1Package(0, "save.upk"); File.Delete("save.upk"); v = Convert.ToInt32(textBox5.Text); buff = Save.Files[1].memory.ToArray(); buff = WriteInt(buff, 0x4A7, v); //Paragon v = Convert.ToInt32(textBox6.Text); buff = WriteInt(buff, 0x4A3, v); //Renegade SaveGame.SaveFileEntry e = Save.Files[1]; e.memory = new MemoryStream(buff); Save.Files[1] = e; }
private static void generateEnumValues(int index, ME1Package pcc) { string enumName = pcc.Exports[index].ObjectName; if (!Enums.ContainsKey(enumName)) { List <string> values = new List <string>(); byte[] buff = pcc.Exports[index].Data; int count = BitConverter.ToInt32(buff, 20); for (int i = 0; i < count; i++) { values.Add(pcc.Names[BitConverter.ToInt32(buff, 24 + i * 8)]); } Enums.Add(enumName, values); } }
private static void generateEnumValues(int index, ME1Package pcc) { string enumName = pcc.Exports[index].ObjectName; if (!Enums.ContainsKey(enumName)) { var values = new List <NameReference>(); byte[] buff = pcc.Exports[index].Data; int count = BitConverter.ToInt32(buff, 20); for (int i = 0; i < count; i++) { int enumValIndex = 24 + i * 8; values.Add(new NameReference(pcc.Names[BitConverter.ToInt32(buff, enumValIndex)], BitConverter.ToInt32(buff, enumValIndex + 4))); } Enums.Add(enumName, values); } }
private void fileBox_SelectedIndexChanged(object sender, EventArgs e) { bioTlkSetBox.Items.Clear(); tlkFileBox.Items.Clear(); int n = fileBox.SelectedIndex; if (n == -1) { return; } ME1Package pcc = packages[n]; tlkFileSets.Clear(); IReadOnlyList <IExportEntry> Exports = pcc.Exports; for (int i = 0; i < Exports.Count; i++) { if (Exports[i].ClassName == "BioTlkFileSet") { BioTlkFileSet b = new BioTlkFileSet(pcc, i); tlkFileSets.Add(b); bioTlkSetBox.Items.Add(b.Name); } } //No BioTlkSets, look for loose BioTlkFiles if (tlkFileSets.Count == 0) { BioTlkFileSet tlkSet = new BioTlkFileSet(pcc); for (int i = 0; i < Exports.Count; i++) { if (Exports[i].ClassName == "BioTlkFile") { TalkFile tlk = new TalkFile(pcc, i); tlkSet.talkFiles.Add(tlk); } } if (tlkSet.talkFiles.Count != 0) { tlkFileSets.Add(tlkSet); bioTlkSetBox.Items.Add("Misc TlkFiles"); } } }
public BioTlkFileSet(ME1Package _pcc) { pcc = _pcc; index = -1; IReadOnlyList <IExportEntry> Exports = pcc.Exports; for (int i = 0; i < Exports.Count; i++) { if (Exports[i].ClassName == "BioTlkFileSet") { index = i; } } if (index != -1) { loadData(index); } else { talkFiles = new List <TalkFile>(); } }
private static ClassInfo generateClassInfo(int index, ME1Package pcc) { ClassInfo info = new ClassInfo(); IReadOnlyList <IExportEntry> Exports = pcc.Exports; info.baseClass = Exports[index].ClassParent; foreach (IExportEntry entry in Exports) { if (entry.idxLink - 1 == index && entry.ClassName != "ScriptStruct" && entry.ClassName != "Enum" && entry.ClassName != "Function" && entry.ClassName != "Const" && entry.ClassName != "State") { //Skip if property is transient (only used during execution, will never be in game files) if ((BitConverter.ToUInt64(entry.Data, 24) & 0x0000000000002000) == 0 && !info.properties.ContainsKey(entry.ObjectName)) { PropertyInfo p = getProperty(pcc, entry); if (p != null) { info.properties.Add(entry.ObjectName, p); } } } } return(info); }
public static void LoadSavedTlkList() { if (File.Exists(LoadedTLKsPath)) { List <(int, string)> files = JsonConvert.DeserializeObject <List <(int, string)> >(File.ReadAllText(LoadedTLKsPath)); foreach ((int exportnum, string filename) in files) { LoadTlkData(filename, exportnum); } } else { string path = ME1Directory.cookedPath + @"Packages\Dialog\GlobalTlk.upk"; try { ME1Package pcc = MEPackageHandler.OpenME1Package(path); tlkList.Add(new TalkFile(pcc, 1)); } catch (Exception) { return; } } }
public BioTlkFileSet(ME1Package _pcc, int _index) { pcc = _pcc; index = _index; loadData(); }
//call this method to regenerate ME1ObjectInfo.json //Takes a long time (10 to 20 minutes maybe?). Application will be completely unresponsive during that time. public static void generateInfo() { Classes = new Dictionary <string, ClassInfo>(); Structs = new Dictionary <string, ClassInfo>(); Enums = new Dictionary <string, List <NameReference> >(); string path = ME1Directory.gamePath; string[] files = Directory.GetFiles(path, "*", SearchOption.AllDirectories); string objectName; foreach (string file in files) { if (Path.GetExtension(file) == ".upk" || Path.GetExtension(file) == ".sfm" || Path.GetExtension(file) == ".u") { Debug.WriteLine("File: " + file); using (ME1Package pcc = MEPackageHandler.OpenME1Package(file)) { IReadOnlyList <IExportEntry> Exports = pcc.Exports; for (int j = 0; j < Exports.Count; j++) { IExportEntry exportEntry = Exports[j]; if (exportEntry.ClassName == "Enum") { generateEnumValues(j, pcc); } else if (exportEntry.ClassName == "Class") { objectName = exportEntry.ObjectName; Debug.WriteLine("Generating information for " + exportEntry.ObjectName); if (!Classes.ContainsKey(exportEntry.ObjectName)) { Classes.Add(objectName, generateClassInfo(j, pcc)); } } else if (exportEntry.ClassName == "ScriptStruct") { objectName = exportEntry.ObjectName; if (!Structs.ContainsKey(exportEntry.ObjectName)) { Structs.Add(objectName, generateClassInfo(j, pcc)); } } } } } } //CUSTOM ADDITIONS ClassInfo info = new ClassInfo { baseClass = "Texture2D", exportIndex = 0, pccPath = "ME3Explorer_CustomNativeAdditions" }; Classes.Add("LightMapTexture2D", info); File.WriteAllText(jsonPath, JsonConvert.SerializeObject(new { Classes = Classes, Structs = Structs, Enums = Enums }, Formatting.Indented)); MessageBox.Show("Done"); }
public void replaceTlkwithFile(ME1Package pcc, int Index) { /* converts Huffmann Tree to binary form */ byte[] treeBuffer = ConvertHuffmanTreeToBuffer(); List <EncodedString> encodedStrings = new List <EncodedString>(); int i = 0; foreach (var entry in _inputData) { if (entry.Flags == 0) { if (entry.StringID > 0) { entry.index = -1; } else { entry.index = 0; } } else { entry.index = i; i++; List <BitArray> binaryData = new List <BitArray>(); int binaryLength = 0; /* for every character in a string, put it's binary code into data array */ foreach (char c in entry.data) { binaryData.Add(_huffmanCodes[c]); binaryLength += _huffmanCodes[c].Count; } byte[] buffer = BitArrayListToByteArray(binaryData, binaryLength); encodedStrings.Add(new EncodedString(entry.data.Length, buffer.Length, buffer)); } } /* get properties from object we're replacing*/ byte[] properties = pcc.Exports[Index].Data.Take(40).ToArray(); MemoryStream m = new MemoryStream(); /* writing properties */ m.Write(properties, 0, 40); m.Seek(0x1C, SeekOrigin.Begin); m.Write(BitConverter.GetBytes(_inputData.Count), 0, 4); m.Seek(0, SeekOrigin.End); /* writing entries */ m.Write(BitConverter.GetBytes(_inputData.Count), 0, 4); foreach (TLKEntry entry in _inputData) { m.Write(BitConverter.GetBytes(entry.StringID), 0, 4); m.Write(BitConverter.GetBytes(entry.Flags), 0, 4); m.Write(BitConverter.GetBytes(entry.index), 0, 4); } /* writing HuffmanTree */ m.Write(treeBuffer, 0, treeBuffer.Length); /* writing data */ m.Write(BitConverter.GetBytes(encodedStrings.Count), 0, 4); foreach (EncodedString enc in encodedStrings) { m.Write(BitConverter.GetBytes(enc.stringLength), 0, 4); m.Write(BitConverter.GetBytes(enc.encodedLength), 0, 4); m.Write(enc.binaryData, 0, enc.encodedLength); } byte[] buff = m.ToArray(); pcc.Exports[Index].Data = buff; pcc.save(pcc.FileName); }
private static PropertyInfo getProperty(ME1Package 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": 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 "ClassProperty": case "InterfaceProperty": case "ComponentProperty": default: p = null; break; } return(p); }
public void serializeTalkfileToExport(ME1Package pcc, IExportEntry export, bool savePackage = false) { /* converts Huffmann Tree to binary form */ byte[] treeBuffer = ConvertHuffmanTreeToBuffer(); var encodedStrings = new List <EncodedString>(); int i = 0; foreach (var entry in _inputData) { if (entry.Flags == 0) { if (entry.StringID > 0) { entry.Index = -1; } else { entry.Index = 0; } } else { entry.Index = i; i++; var binaryData = new List <BitArray>(); int binaryLength = 0; /* for every character in a string, put it's binary code into data array */ foreach (char c in entry.ASCIIData) { binaryData.Add(_huffmanCodes[c]); binaryLength += _huffmanCodes[c].Count; } byte[] buffer = BitArrayListToByteArray(binaryData, binaryLength); encodedStrings.Add(new EncodedString(entry.ASCIIData.Length, buffer.Length, buffer)); } } /* writing properties */ export.WriteProperty(new IntProperty(_inputData.Count, "m_nHashTableSize")); MemoryStream m = new MemoryStream(); /* writing entries */ m.Write(BitConverter.GetBytes(_inputData.Count), 0, 4); foreach (TLKStringRef entry in _inputData) { m.Write(BitConverter.GetBytes(entry.StringID), 0, 4); m.Write(BitConverter.GetBytes(entry.Flags), 0, 4); m.Write(BitConverter.GetBytes(entry.Index), 0, 4); } /* writing HuffmanTree */ m.Write(treeBuffer, 0, treeBuffer.Length); /* writing data */ m.Write(BitConverter.GetBytes(encodedStrings.Count), 0, 4); foreach (EncodedString enc in encodedStrings) { m.Write(BitConverter.GetBytes(enc.stringLength), 0, 4); m.Write(BitConverter.GetBytes(enc.encodedLength), 0, 4); m.Write(enc.binaryData, 0, enc.encodedLength); } byte[] buff = m.ToArray(); export.setBinaryData(buff); if (savePackage) { pcc.save(pcc.FileName); } }