Skip to content

Commit

Permalink
Fix XML-Patcher for V1 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
mgreter committed Jul 29, 2024
1 parent 8c4e1c9 commit ecd037d
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 14 deletions.
21 changes: 8 additions & 13 deletions Library/Utils/ModXmlPatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Xml;
using System.Xml.Linq;
Expand Down Expand Up @@ -181,9 +180,6 @@ private static void ReplaceTemplateOccurences(
kv.Value);
}

// We need to call into the private function to proceed with XML patching
private static readonly MethodInfo MethodSinglePatch = AccessTools.Method(typeof(XmlPatcher), "singlePatch");

// Function to load another XML file and basically call the same PatchXML function again
private static bool IncludeAnotherDocument(XmlFile target, XmlFile parent, XElement element, Mod mod)
{
Expand Down Expand Up @@ -223,7 +219,7 @@ private static bool IncludeAnotherDocument(XmlFile target, XmlFile parent, XElem
continue;
}
result &= XmlPatcher.PatchXml(
target, element, _patchXml, mod);
target, _patchXml.XmlDoc.Root, _patchXml, mod);
}
catch (Exception ex)
{
Expand Down Expand Up @@ -272,7 +268,7 @@ public static bool PatchXml(XmlFile xmlFile,
}
}
// Otherwise try to apply the patches found in child element
else if (!ApplyPatchEntry(xmlFile, child, patchXml, mod, ref stack))
else if (!ApplyPatchEntry(xmlFile, patchXml, child, mod, ref stack))
{
IXmlLineInfo lineInfo = child;
Log.Warning(string.Format("XML patch for \"{0}\" from mod \"{1}\" did not apply: {2} (line {3} at pos {4})",
Expand All @@ -293,8 +289,8 @@ public struct ParserStack

// Entry point instead of (private) `XmlPatcher.singlePatch`
// Implements conditional patching and also allows includes
private static bool ApplyPatchEntry(XmlFile _targetFile, XElement _patchElement,
XmlFile _patchFile, Mod _patchingMod, ref ParserStack stack)
private static bool ApplyPatchEntry(XmlFile _targetFile, XmlFile _patchFile,
XElement _patchElement, Mod _patchingMod, ref ParserStack stack)
{

// Only support root level
Expand Down Expand Up @@ -381,8 +377,8 @@ private static bool ApplyPatchEntry(XmlFile _targetFile, XElement _patchElement,
stack.IfClauseParsed = false;
stack.PreviousResult = true;
// Dispatch to original function
return (bool)MethodSinglePatch.Invoke(null,
new object[] { _targetFile, _patchElement, _patchFile, _patchingMod });
return XmlPatcher.singlePatch(_targetFile,
_patchElement, _patchFile, _patchingMod);
}
}

Expand Down Expand Up @@ -416,9 +412,8 @@ static bool Prefix(
if (int.Parse(version) > 5) return true;
}
// Call out to static helper function
__result = PatchXml(
_xmlFile, _patchFile,
element, _patchingMod);
__result = PatchXml(_xmlFile, _patchFile,
_containerElement, _patchingMod);
// First one wins
_patchFile = null;
return false;
Expand Down
Binary file modified MicroSplat.dll
Binary file not shown.
2 changes: 1 addition & 1 deletion ModInfo.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
<Description value="Replace vanilla MicroSplat shader for better visual fidelity." />
<Website value="https://github.com/OCB7D2D/OcbMicroSplat" />
<Author value="ocbMaurice" />
<Version value="0.9.1" />
<Version value="0.9.2" />
</xml>
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,10 @@ Download from https://github.com/OCB7D2D/OcbMicroSplatHelper/releases

## Changelog

### Version 0.9.2

- Fix XML-Patcher for V1 compatibility

### Version 0.9.1

- Fix potential NRE when unloading textures
Expand Down

0 comments on commit ecd037d

Please sign in to comment.