Skip to content

Commit

Permalink
Merge pull request #199 from Monitor144hz/text-hotfix
Browse files Browse the repository at this point in the history
[Fix]: String value error on vector4 edits leading to engine failure.
  • Loading branch information
Monitor221hz authored Apr 21, 2024
2 parents 88a62cc + 0cde8ed commit 20507d2
Showing 1 changed file with 4 additions and 12 deletions.
16 changes: 4 additions & 12 deletions PandoraPlus/MVVM/Model/Patch/Patchers/Skyrim/Hkx/PackFileEdits.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,17 @@ namespace Pandora.Patch.Patchers.Skyrim.Hkx
{
public partial class PackFileEditor
{
private static readonly Regex bracketRegex = new Regex(@"(\(|\))+", RegexOptions.Compiled);
private static readonly Regex whiteSpaceRegex = new Regex(@"\s+", RegexOptions.Compiled);
private static readonly char[] trimChars = new char[] {'\t', '\r', '\n', ')', '(' };
private static readonly Regex whiteSpaceRegex = new Regex(@"(?:\s|\(|\)){2,}", RegexOptions.Compiled);
private static string NormalizeElementValue(XElement element)
{
var value = whiteSpaceRegex.Replace(element.Value.Trim(), " ");
if (value.Length > 0 && value[0] == '(')
{
value = bracketRegex.Replace(value, string.Empty);
}
var value = whiteSpaceRegex.Replace(element.Value.Trim(trimChars), " ");
return value;
}

private static string NormalizeStringValue(string value)
{
return whiteSpaceRegex.Replace(value.Trim(), " ");
return whiteSpaceRegex.Replace(value.Trim(trimChars), " ");
}
public static XElement ReplaceElement(PackFile packFile, string path, XElement element) => packFile.Map.ReplaceElement(path, element);

Expand Down Expand Up @@ -72,10 +68,6 @@ public static bool ReplaceText(PackFile packFile, string path, string preValue,
source = NormalizeStringValue(String.Concat(headSpan, " " + newValue + " ", tailSpan)); //pad spaces as bare minimum; don't want array values to be twinned
element.SetValue(source);

if ((sourceLength - oldValue.Length + newValue.Length) != element.Value.Length)
{
return false;
}
return true;

}
Expand Down

0 comments on commit 20507d2

Please sign in to comment.