Skip to content

Commit

Permalink
DlgEd: fixed #125
Browse files Browse the repository at this point in the history
  • Loading branch information
SirCxyrtyx committed May 20, 2019
1 parent 6687fbc commit 6d6511a
Show file tree
Hide file tree
Showing 15 changed files with 114 additions and 116 deletions.
2 changes: 1 addition & 1 deletion ME3Explorer/BinaryInterpreter/BinaryInterpreterWPF.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6825,7 +6825,7 @@ private List<object> StartGenericScan(byte[] data, ref int binarystart)

public override void UnloadExport()
{
BinaryInterpreter_Hexbox.ByteProvider = new DynamicByteProvider(new byte[] { });
BinaryInterpreter_Hexbox.ByteProvider = new DynamicByteProvider();
TreeViewItems.ClearEx();
if (CurrentLoadedExport != null && CurrentLoadedExport.Data.Length > 20480)
{
Expand Down
26 changes: 16 additions & 10 deletions ME3Explorer/DialogEditor/DialogEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ public void RefreshTabs()
foreach (ME3BioConversation.ReplyListStruct r in Dialog.ReplyList)
replyListTreeView.Nodes.Add(r.ToTree(count++, Pcc as ME3Package));
count = 0;
foreach (int i in Dialog.SpeakerList)
speakerListBox.Items.Add((count++) + " : " + i + " , " + Pcc.getNameEntry(i));
foreach (NameReference name in Dialog.SpeakerList)
speakerListBox.Items.Add($"{count++} : {name.InstancedString}");
count = 0;
foreach (ME3BioConversation.StageDirectionStruct sd in Dialog.StageDirections)
stageDirectionsListBox.Items.Add((count++) + " : " + sd.Text.Substring(0, sd.Text.Length - 1) + " , " + sd.StringRef + " , " + ME3TalkFiles.findDataById(sd.StringRef));
Expand Down Expand Up @@ -147,12 +147,15 @@ private void listBox2_DoubleClick(object sender, EventArgs e)
int n;
if (Pcc == null || Dialog == null || (n = speakerListBox.SelectedIndex) == -1)
return;
string result = PromptDialog.Prompt(null, "Please enter new name entry", "ME3Explorer", Dialog.SpeakerList[n].ToString(), true);
if (result == "")
string nameResult = PromptDialog.Prompt(null, "Please enter new name", "ME3Explorer", Dialog.SpeakerList[n].Name, true);
if (nameResult == "")
return;
string numberResult = PromptDialog.Prompt(null, "Please enter new name index", "ME3Explorer", Dialog.SpeakerList[n].Number.ToString(), true);
if (numberResult == "")
return;
if (int.TryParse(result, out int i) && Pcc.isName(i))
if (int.TryParse(numberResult, out int i) && i >= 0)
{
Dialog.SpeakerList[n] = i;
Dialog.SpeakerList[n] = new NameReference(nameResult, i);
Dialog.Save();
}
}
Expand Down Expand Up @@ -205,12 +208,15 @@ private void toSpeakerListToolStripMenuItem_Click(object sender, EventArgs e)
{
if (Pcc == null || Dialog == null)
return;
string result = PromptDialog.Prompt(null, "Please enter new value", "ME3Explorer", "", true);
if (result == "")
string nameResult = PromptDialog.Prompt(null, "Please enter new name", "ME3Explorer", "", true);
if (nameResult == "")
return;
string numberResult = PromptDialog.Prompt(null, "Please enter new name index", "ME3Explorer", "", true);
if (numberResult == "")
return;
if (int.TryParse(result, out int i) && Pcc.isName(i))
if (int.TryParse(numberResult, out int i) && i >= 0)
{
Dialog.SpeakerList.Add(i);
Dialog.SpeakerList.Add(new NameReference(nameResult, i));
Dialog.Save();
}
}
Expand Down
18 changes: 13 additions & 5 deletions ME3Explorer/DialogEditor/ME3BioConversation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class ME3BioConversation
List<PropertyReader.Property> Props;

public List<int> StartingList;
public List<int> SpeakerList;
public List<NameReference> SpeakerList;
public List<int> MaleFaceSets;
public List<int> FemaleFaceSets;
public List<StageDirectionStruct> StageDirections;
Expand Down Expand Up @@ -434,14 +434,18 @@ void ReadReplyList()

void ReadSpeakerList()
{
SpeakerList = new List<int>();
SpeakerList = new List<NameReference>();
int f = FindPropByName("m_aSpeakerList");
if (f == -1)
return;
byte[] buff = Props[f].raw;
int count = BitConverter.ToInt32(buff, 0x18);
for (int i = 0; i < count; i++)
SpeakerList.Add(BitConverter.ToInt32(buff, 0x1C + i * 8));
{
string nameEntry = pcc.getNameEntry(BitConverter.ToInt32(buff, 0x1C + i * 8));
int number = BitConverter.ToInt32(buff, 0x1C + 4 + i * 8);
SpeakerList.Add(new NameReference(nameEntry, number));
}
}

void ReadStageDirections()
Expand Down Expand Up @@ -726,8 +730,12 @@ public void Save()
m.Write(BitConverter.GetBytes(SpeakerList.Count * 8 + 4), 0, 4);
m.Write(BitConverter.GetBytes(0), 0, 4);
m.Write(BitConverter.GetBytes(SpeakerList.Count), 0, 4);
foreach (int i in SpeakerList)
m.Write(BitConverter.GetBytes((long)i), 0, 8);
foreach (NameReference name in SpeakerList)
{
m.Write(BitConverter.GetBytes(pcc.FindNameOrAdd(name.Name)), 0, 4);
m.Write(BitConverter.GetBytes(name.Number), 0, 4);
}

break;
case "m_aFemaleFaceSets":
m.Write(p.raw, 0, 0x10);
Expand Down
4 changes: 2 additions & 2 deletions ME3Explorer/FaceFXAnimSetEditor/FaceFXAnimSetEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ public override void handleUpdate(List<PackageUpdate> updates)
FaceFX = null;
treeView1.Nodes.Clear();
treeView2.Nodes.Clear();
hb1.ByteProvider = new DynamicByteProvider(new List<byte>());
hb1.ByteProvider = new DynamicByteProvider();
ListRefresh();
}
else
Expand All @@ -343,7 +343,7 @@ public override void handleUpdate(List<PackageUpdate> updates)
}
updatedExports.Remove(index);
}
if (updatedExports.Intersect(Objects).Count() > 0)
if (updatedExports.Intersect(Objects).Any())
{
ListRefresh();
}
Expand Down
2 changes: 1 addition & 1 deletion ME3Explorer/Interpreter/InterpreterWPF.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1363,7 +1363,7 @@ private void Interpreter_Loaded(object sender, RoutedEventArgs e)
Interpreter_Hexbox = (HexBox)Interpreter_Hexbox_Host.Child;
if (Interpreter_Hexbox.ByteProvider == null)
{
Interpreter_Hexbox.ByteProvider = new DynamicByteProvider(new byte[] { });
Interpreter_Hexbox.ByteProvider = new DynamicByteProvider();
}
//remove in the event this object is reloaded again
Interpreter_Hexbox.ByteProvider.Changed -= Interpreter_Hexbox_BytesChanged;
Expand Down
46 changes: 24 additions & 22 deletions ME3Explorer/ME1/DialogEditor/DialogEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using ME3Explorer;
using ME3Explorer.SharedUI;
using ME3Explorer.TlkManagerNS;
using ME3Explorer.Unreal;

namespace ME1Explorer
{
Expand Down Expand Up @@ -113,10 +114,10 @@ public void RefreshTabs()
treeView2.Nodes.Add(r.ToTree(count++, tlkFile, Pcc as ME1Package));
count = 0;
foreach (ME1BioConversation.SpeakerListStruct sp in Dialog.SpeakerList)
listBox2.Items.Add((count++) + " : " + sp.SpeakerTag + " , " + sp.Text);
listBox2.Items.Add((count++) + " : " + sp.SpeakerTag.InstancedString);
count = 0;
foreach (ME1BioConversation.ScriptListStruct sd in Dialog.ScriptList)
listBox3.Items.Add((count++) + " : " + sd.ScriptTag + " , " + sd.Text);
listBox3.Items.Add((count++) + " : " + sd.ScriptTag.InstancedString);
count = 0;
foreach (int i in Dialog.MaleFaceSets)
listBox4.Items.Add((count++) + " : " + i);
Expand Down Expand Up @@ -155,15 +156,16 @@ private void listBox2_DoubleClick(object sender, EventArgs e)
int n;
if (Pcc == null || Dialog == null || (n = listBox2.SelectedIndex) == -1)
return;
string result = PromptDialog.Prompt(null, "Please enter new name entry", "ME1Explorer", Dialog.SpeakerList[n].SpeakerTag.ToString(), true);
if (result == "")
string nameResult = PromptDialog.Prompt(null, "Please enter new name", "ME1Explorer", Dialog.SpeakerList[n].SpeakerTag.Name, true);
if (nameResult == "")
return;
int i = 0;
if (int.TryParse(result, out i) && Pcc.isName(i))
string numberResult = PromptDialog.Prompt(null, "Please enter new name index", "ME1Explorer", Dialog.SpeakerList[n].SpeakerTag.Number.ToString(), true);
if (numberResult == "")
return;
if (int.TryParse(numberResult, out int i) && i >= 0)
{
ME1BioConversation.SpeakerListStruct sp = new ME1BioConversation.SpeakerListStruct();
sp.SpeakerTag = i;
sp.Text = Pcc.getNameEntry(i);
sp.SpeakerTag = new NameReference(nameResult, i);
Dialog.SpeakerList[n] = sp;
Dialog.Save();
}
Expand Down Expand Up @@ -220,15 +222,16 @@ private void toSpeakerListToolStripMenuItem_Click(object sender, EventArgs e)
{
if (Pcc == null || Dialog == null)
return;
string result = PromptDialog.Prompt(null, "Please enter new value", "ME1Explorer", "", true);
if (result == "")
string nameResult = PromptDialog.Prompt(null, "Please enter new name", "ME1Explorer", "", true);
if (nameResult == "")
return;
int i = 0;
if (int.TryParse(result, out i) && Pcc.isName(i))
string numberResult = PromptDialog.Prompt(null, "Please enter new name index", "ME1Explorer", "", true);
if (numberResult == "")
return;
if (int.TryParse(numberResult, out int i) && i >= 0)
{
ME1BioConversation.SpeakerListStruct sp = new ME1BioConversation.SpeakerListStruct();
sp.SpeakerTag = i;
sp.Text = Pcc.getNameEntry(i);
sp.SpeakerTag = new NameReference(nameResult, i);
Dialog.SpeakerList.Add(sp);
Dialog.Save();
}
Expand Down Expand Up @@ -305,16 +308,16 @@ private void listBox3_DoubleClick(object sender, EventArgs e)
int n;
if (Pcc == null || Dialog == null || (n = listBox3.SelectedIndex) == -1)
return;
ME1BioConversation.ScriptListStruct sd = Dialog.ScriptList[n];
string result = PromptDialog.Prompt(null, "Please enter new name entry", "ME1Explorer", Dialog.ScriptList[n].ScriptTag.ToString(), true);
if (result == "")
string nameResult = PromptDialog.Prompt(null, "Please enter new name", "ME1Explorer", Dialog.ScriptList[n].ScriptTag.Name, true);
if (nameResult == "")
return;
int i = 0;
if (int.TryParse(result, out i) && Pcc.isName(i))
string numberResult = PromptDialog.Prompt(null, "Please enter new name index", "ME1Explorer", Dialog.ScriptList[n].ScriptTag.Number.ToString(), true);
if (numberResult == "")
return;
if (int.TryParse(numberResult, out int i) && i >= 0)
{
ME1BioConversation.ScriptListStruct sp = new ME1BioConversation.ScriptListStruct();
sp.ScriptTag = i;
sp.Text = Pcc.getNameEntry(i);
sp.ScriptTag = new NameReference(nameResult, i);
Dialog.ScriptList[n] = sp;
Dialog.Save();
}
Expand All @@ -327,7 +330,6 @@ private void scriptListToolStripMenuItem_Click(object sender, EventArgs e)
return;
ME1BioConversation.ScriptListStruct sc = new ME1BioConversation.ScriptListStruct();
sc.ScriptTag = Dialog.ScriptList[n].ScriptTag;
sc.Text = Pcc.getNameEntry(sc.ScriptTag);
Dialog.ScriptList.Add(sc);
Dialog.Save();
}
Expand Down
25 changes: 8 additions & 17 deletions ME3Explorer/ME1/HuffmanCompression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Linq;
using System.Xml;
using ME3Explorer.Packages;
using ME3Explorer.Unreal;
using static ME1Explorer.Unreal.Classes.TalkFile;

namespace ME1Explorer
Expand Down Expand Up @@ -83,10 +84,6 @@ public void LoadInputData(string fileName)
PrepareHuffmanCoding();
}

/// <summary>
/// Loads a file into memory and prepares for compressing it to TLK
/// </summary>
/// <param name="fileName"></param>
public void LoadInputData(List<TLKStringRef> tlkEntries)
{
_inputData = tlkEntries;
Expand All @@ -99,15 +96,15 @@ public void serializeTLKStrListToExport(IExportEntry export, bool savePackage =
{
throw new Exception("Cannot save a ME1 TLK to a game that is not Mass Effect 1.");
}
serializeTalkfileToExport(export.FileRef as ME1Package, export.Index, savePackage);
serializeTalkfileToExport(export.FileRef as ME1Package, export, savePackage);
}

public void serializeTalkfileToExport(ME1Package pcc, int Index, bool savePackage = false)
public void serializeTalkfileToExport(ME1Package pcc, IExportEntry export, bool savePackage = false)
{
/* converts Huffmann Tree to binary form */
byte[] treeBuffer = ConvertHuffmanTreeToBuffer();

List<EncodedString> encodedStrings = new List<EncodedString>();
var encodedStrings = new List<EncodedString>();
int i = 0;
foreach (var entry in _inputData)
{
Expand All @@ -122,7 +119,7 @@ public void serializeTalkfileToExport(ME1Package pcc, int Index, bool savePackag
{
entry.Index = i;
i++;
List<BitArray> binaryData = new List<BitArray>();
var binaryData = new List<BitArray>();
int binaryLength = 0;

/* for every character in a string, put it's binary code into data array */
Expand All @@ -136,17 +133,11 @@ public void serializeTalkfileToExport(ME1Package pcc, int Index, bool savePackag
}
}

/* 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);
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)
Expand All @@ -169,7 +160,7 @@ public void serializeTalkfileToExport(ME1Package pcc, int Index, bool savePackag
}

byte[] buff = m.ToArray();
pcc.Exports[Index].Data = buff;
export.setBinaryData(buff);
if (savePackage)
{
pcc.save(pcc.FileName);
Expand Down
20 changes: 8 additions & 12 deletions ME3Explorer/ME1/Unreal/Classes/ME1BioConversation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,12 @@ public class ME1BioConversation

public struct ScriptListStruct
{
public string Text;
public int ScriptTag;
public NameReference ScriptTag;
}

public struct SpeakerListStruct
{
public string Text;
public int SpeakerTag;
public NameReference SpeakerTag;
}

public struct EntryListReplyListStruct
Expand Down Expand Up @@ -433,8 +431,7 @@ private void ReadSpeakerList()
{
List<PropertyReader.Property> p = PropertyReader.ReadProp(pcc, buff, pos);
SpeakerListStruct sp = new SpeakerListStruct();
sp.SpeakerTag = p[0].Value.IntValue;
sp.Text = pcc.getNameEntry(sp.SpeakerTag);
sp.SpeakerTag = p[0].Value.NameValue;
SpeakerList.Add(sp);
pos = p[p.Count - 1].offend;
}
Expand All @@ -453,8 +450,7 @@ private void ReadScriptList()
{
List<PropertyReader.Property> p = PropertyReader.ReadProp(pcc, buff, pos);
ScriptListStruct sd = new ScriptListStruct();
sd.ScriptTag = p[0].Value.IntValue;
sd.Text = pcc.getNameEntry(sd.ScriptTag);
sd.ScriptTag = p[0].Value.NameValue;
ScriptList.Add(sd);
pos = p[p.Count - 1].offend;
}
Expand Down Expand Up @@ -526,7 +522,7 @@ public int WriteIntProperty(MemoryStream m, string name, int value, string type
return 28;
}

public int WriteNameProperty(MemoryStream m, string name, int value)
public int WriteNameProperty(MemoryStream m, string name, NameReference value)
{
int NAME_name = FindName(name);
int NAME_type = FindName("NameProperty");
Expand All @@ -536,8 +532,8 @@ public int WriteNameProperty(MemoryStream m, string name, int value)
m.Write(BitConverter.GetBytes(0), 0, 4);
m.Write(BitConverter.GetBytes(4), 0, 4);
m.Write(BitConverter.GetBytes(0), 0, 4);
m.Write(BitConverter.GetBytes(value), 0, 4);
m.Write(BitConverter.GetBytes(0), 0, 4);
m.Write(BitConverter.GetBytes(pcc.FindNameOrAdd(value.Name)), 0, 4);
m.Write(BitConverter.GetBytes(value.Number), 0, 4);
return 32;
}

Expand Down Expand Up @@ -740,7 +736,7 @@ public void Save()
m.Write(BitConverter.GetBytes(size), 0, 4);
m.Seek(tmp2, 0);
break;
case "m_aSpeakerList":
case "m_SpeakerList":
tmp1 = (int)m.Position;
m.Write(p.raw, 0, 0x10);
m.Write(new byte[8], 0, 8);//size placeholder
Expand Down
5 changes: 1 addition & 4 deletions ME3Explorer/ME1/Unreal/Classes/TalkFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,7 @@ public override int GetHashCode()
#region Load Data
public void LoadTlkData()
{
BinaryReader r = new BinaryReader(new MemoryStream(pcc.getUExport(uindex).Data), Encoding.Unicode);

//skip properties
r.BaseStream.Seek(40, SeekOrigin.Begin);
BinaryReader r = new BinaryReader(new MemoryStream(pcc.getUExport(uindex).getBinaryData()), Encoding.Unicode);

//hashtable
int entryCount = r.ReadInt32();
Expand Down
Loading

0 comments on commit 6d6511a

Please sign in to comment.