dev: more 1.4.4 fixes, fix CRLF -> LF
This commit is contained in:
@ -13,27 +13,35 @@ namespace MagicStorageVoidBag.ILPatches {
|
||||
internal class PlayerUpdatePatch : ILPatch {
|
||||
private static readonly log4net.ILog Logger = MagicStorageVoidBag.Instance.Logger;
|
||||
public void Patch(ILContext il) {
|
||||
if (il == null) {
|
||||
Logger.Error("ILContext null!");
|
||||
return;
|
||||
try {
|
||||
if (il == null) {
|
||||
Logger.Error("ILContext null!");
|
||||
return;
|
||||
}
|
||||
|
||||
Logger.Debug("Patching Terraria.Player.Update IL...");
|
||||
|
||||
var c = new ILCursor(il);
|
||||
var setterMethod = typeof(Player).GetProperty(nameof(Player.IsVoidVaultEnabled)).GetSetMethod();
|
||||
if (!c.TryGotoNext(i => i.MatchCallOrCallvirt(setterMethod))) {
|
||||
Logger.Error("Failed to go to next call or callvirt! :(");
|
||||
return;
|
||||
}
|
||||
|
||||
c.Emit(OpCodes.Ldarg_0);
|
||||
c.Emit(OpCodes.Ldc_I4, ModContent.ItemType<MSVoidBag>());
|
||||
var hasItemMethod = typeof(Player).GetMethod(nameof(Player.HasItem), new[] { typeof(int) });
|
||||
if (hasItemMethod == null) {
|
||||
Logger.Error("Failed to reflect Player.HasItem(int)! :(");
|
||||
return;
|
||||
}
|
||||
c.Emit(OpCodes.Call, hasItemMethod);
|
||||
c.Emit(OpCodes.Or);
|
||||
|
||||
Logger.Debug("...Complete!");
|
||||
} catch (Exception e) {
|
||||
throw new ILPatchFailureException(MagicStorageVoidBag.Instance, il, e);
|
||||
}
|
||||
|
||||
Logger.Debug("Patching Terraria.Player.Update IL...");
|
||||
|
||||
var c = new ILCursor(il);
|
||||
var setterMethod = typeof(Player).GetProperty(nameof(Player.IsVoidVaultEnabled)).GetSetMethod();
|
||||
if (!c.TryGotoNext(i => i.MatchCallOrCallvirt(setterMethod))) {
|
||||
Logger.Warn("Failed to go to next call or callvirt! :(");
|
||||
return;
|
||||
}
|
||||
|
||||
c.Emit(OpCodes.Ldarg_0);
|
||||
c.Emit(OpCodes.Ldc_I4, ModContent.ItemType<MSVoidBag>());
|
||||
var hasItemMethod = typeof(Player).GetMethod(nameof(Player.HasItem));
|
||||
c.Emit(OpCodes.Call, hasItemMethod);
|
||||
c.Emit(OpCodes.Or);
|
||||
|
||||
Logger.Debug("...Complete!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user