Files
se-launcher/CringeLauncher/Patches/XmlRootWriterPatch.cs
zznty aa979e9519
All checks were successful
Build / Compute Version (push) Successful in 4s
Build / Build Nuget package (CringeBootstrap.Abstractions) (push) Successful in 2m47s
Build / Build Nuget package (CringePlugins) (push) Successful in 5m31s
Build / Build Nuget package (NuGet) (push) Successful in 6m2s
Build / Build Nuget package (SharedCringe) (push) Successful in 7m25s
Build / Build Launcher (push) Successful in 9m11s
feature: first
2024-10-28 05:21:11 +07:00

36 lines
1.1 KiB
C#

using System.Reflection.Emit;
using System.Xml;
using HarmonyLib;
using VRage;
namespace CringeLauncher.Patches;
[HarmonyPatch(typeof(CustomRootWriter), "Init")]
public class XmlRootWriterPatch
{
private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
{
var ins = instructions.ToList();
var index = ins.FindIndex(b =>
b.opcode == OpCodes.Ldstr && b.operand is "xsi:type");
ins[index].operand = "xsi";
ins.InsertRange(index + 1, new[]
{
new CodeInstruction(OpCodes.Ldstr, "type"),
new CodeInstruction(OpCodes.Ldstr, "http://www.w3.org/2001/XMLSchema-instance")
});
var instruction = ins[ins.FindIndex(b => b.opcode == OpCodes.Callvirt)];
instruction.operand = AccessTools.Method(typeof(XmlWriter), "WriteAttributeString", new[]
{
typeof(string),
typeof(string),
typeof(string),
typeof(string)
});
return ins;
}
}