Skip to content

Commit

Permalink
Set the correct maximum to the numeric control in the objectives form…
Browse files Browse the repository at this point in the history
…. Show the value if a objective contains a hashcode but the hashcode is not found.
  • Loading branch information
jmarti856 committed Sep 1, 2023
1 parent acb8434 commit abcefea
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 43 deletions.
5 changes: 5 additions & 0 deletions Forms/ObjectiveProperties.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 20 additions & 3 deletions Forms/ObjectiveProperties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public ObjectiveProperties(ListView.SelectedListViewItemCollection selectedObjec
private void ObjectiveProperties_Load(object sender, EventArgs e)
{
//Read hashcodes
Dictionary<uint, string> hashcodeLabels = HashCodes.Read_Sound_h(Globals.HashCodesFilePath, "HT_Objective");
Dictionary<uint, string> hashcodeLabels = HashCodes.Read_Sound_h(Globals.HashCodesFilePath, "HT_Objective", "HT_Text");
cbxHashCode.Items.AddRange(hashcodeLabels.Values.ToArray());

//Update Text
Expand Down Expand Up @@ -85,7 +85,7 @@ private void ObjectiveProperties_FormClosing(object sender, FormClosingEventArgs
}
else
{
Dictionary<uint, string> HashTable = HashCodes.Read_Sound_h(Globals.HashCodesFilePath, "HT_Objective");
Dictionary<uint, string> HashTable = HashCodes.Read_Sound_h(Globals.HashCodesFilePath, "HT_Objective", "HT_Text_");

//Update UI & Dictionary
SvFile saveGameData = ((FrmMain)Application.OpenForms[nameof(FrmMain)]).fileData;
Expand All @@ -95,16 +95,33 @@ private void ObjectiveProperties_FormClosing(object sender, FormClosingEventArgs
{
objItem.SubItems[2].Text = nudObjectiveValue.Value.ToString();
saveGameData.Objectives[(uint)objItem.Tag] = (uint)nudObjectiveValue.Value;
objItem.SubItems[3].Text = ContainsHashCode((uint)nudObjectiveValue.Value).ToString();
}
if (radioButton2.Checked && cbxHashCode.SelectedItem != null)
{
string selectedLabel = cbxHashCode.SelectedItem.ToString();
objItem.SubItems[2].Text = selectedLabel;
saveGameData.Objectives[(uint)objItem.Tag] = HashTable.FirstOrDefault(x => x.Value.Equals(selectedLabel)).Key;

//Get HashCode Value
uint hashCode = HashTable.FirstOrDefault(x => x.Value.Equals(selectedLabel)).Key;
saveGameData.Objectives[(uint)objItem.Tag] = hashCode;
objItem.SubItems[3].Text = ContainsHashCode(hashCode).ToString();
}
}
}
}

//-------------------------------------------------------------------------------------------------------------------------------
private bool ContainsHashCode(uint hashCodeValue)
{
bool containsHashCode = false;
if ((hashCodeValue & 0xFFFF0000) > 0)
{
containsHashCode = true;
}

return containsHashCode;
}
}

//-------------------------------------------------------------------------------------------------------------------------------
Expand Down
76 changes: 42 additions & 34 deletions Forms/Panels/UserControl_Objectives.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions Forms/Panels/UserControl_Objectives.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,25 +39,26 @@ internal void PrintObjectives(SvFile savegameData)
foreach (KeyValuePair<uint, uint> objective in savegameData.Objectives)
{
//Get Hashcode Label
bool containsHashCode = false;
string hashcodeLabel = "**HASHCODE NOT FOUND**";
if (HashTable.ContainsKey(objective.Key))
{
hashcodeLabel = HashTable[objective.Key];
}

//Check value is a hashcode
//Check value is a hashcode
string valueHashCode = objective.Value.ToString();
if ((objective.Value & 0xFFFF0000) > 0)
{
valueHashCode = "**HASHCODE NOT FOUND**";
containsHashCode = true;
if (HashTable.ContainsKey(objective.Value))
{
valueHashCode = HashTable[objective.Value];
}
}

//Add new item
ListViewItem itemData = new ListViewItem(new[] { hashcodeLabel, "0x" + objective.Key.ToString("X8"), valueHashCode })
ListViewItem itemData = new ListViewItem(new[] { hashcodeLabel, "0x" + objective.Key.ToString("X8"), valueHashCode, containsHashCode.ToString() })
{
Tag = objective.Key
};
Expand Down
8 changes: 6 additions & 2 deletions Reader/HashCodes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace SavegameEditor.Reader
internal static class HashCodes
{
//-------------------------------------------------------------------------------------------------------------------------------
internal static Dictionary<uint, string> Read_Sound_h(string filePath, string sectionA = "", string sectionB = "")
internal static Dictionary<uint, string> Read_Sound_h(string filePath, string sectionA = "", string sectionB = "", string sectionC = "")
{
Dictionary<uint, string> HashTable = new Dictionary<uint, string>();
try
Expand All @@ -32,14 +32,18 @@ internal static Dictionary<uint, string> Read_Sound_h(string filePath, string se
input = input.Replace("#define ", string.Empty);
Match match = Regex.Match(input, "([\\w]+)");
string label = match.ToString().Trim();
if ((sectionA.Length > 0 && label.StartsWith(sectionA, StringComparison.OrdinalIgnoreCase)) || (sectionB.Length > 0 && label.StartsWith(sectionB, StringComparison.OrdinalIgnoreCase)))
if ((sectionA.Length > 0 && label.StartsWith(sectionA, StringComparison.OrdinalIgnoreCase)) || (sectionB.Length > 0 && label.StartsWith(sectionB, StringComparison.OrdinalIgnoreCase)) || (sectionC.Length > 0 && label.StartsWith(sectionC, StringComparison.OrdinalIgnoreCase)))
{
GetAndAddObjectives(input, label, HashTable);
}
else if (sectionA.Length == 0 && sectionB.Length == 0)
{
GetAndAddObjectives(input, label, HashTable);
}
else if (sectionC.Length == 0)
{
GetAndAddObjectives(input, label, HashTable);
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Reader/svReader_PC.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public SvFile ReadFile(string filePath)
//Objectives
binReader.BaseStream.Seek(0xEC, SeekOrigin.Begin);
uint objective_count = binReader.ReadUInt32();
for (int i = 0; i <= objective_count; i++)
for (int i = 0; i < objective_count; i++)
{
fileData.Objectives.Add(binReader.ReadUInt32(), binReader.ReadUInt32());
}
Expand Down

0 comments on commit abcefea

Please sign in to comment.