dev: more 1.4.4 fixes, fix CRLF -> LF

This commit is contained in:
Jack Bond-Preston 2023-08-17 17:44:55 +01:00
parent 278a0d9278
commit 0c6328b39d
Signed by: jack
GPG Key ID: 010071F1482BA852
5 changed files with 172 additions and 162 deletions

View File

@ -1,62 +1,62 @@
using MagicStorage;
using MagicStorage.Components;
using MagicStorageVoidBag.Items;
using System.Linq;
using Terraria;
using Terraria.Audio;
using Terraria.DataStructures;
using Terraria.GameContent.Achievements;
using Terraria.ID;
using Terraria.ModLoader;
namespace MagicStorageVoidBag.Hooks {
internal class GetItemVoidVaultHook {
private static readonly log4net.ILog Logger = MagicStorageVoidBag.Instance.Logger;
public static bool Hook(Terraria.On_Player.orig_GetItem_VoidVault orig, Player player, int plr, Item[] inventory, Item newItem, GetItemSettings settings, Item returnItem) {
var i = player.inventory.FirstOrDefault(i => i.type == ModContent.ItemType<MSVoidBag>(), null);
newItem = newItem.Clone();
if (i == null) goto original;
var bag = (MSVoidBag)i.ModItem;
if (bag.Location.X < 0 || bag.Location.Y < 0) goto original;
Tile tile = Main.tile[bag.Location.X, bag.Location.Y];
if (!tile.HasTile || tile.TileType != ModContent.TileType<StorageHeart>() || tile.TileFrameX != 0 || tile.TileFrameY != 0) goto original;
if (!TileEntity.ByPosition.TryGetValue(bag.Location, out TileEntity te)) goto original;
if (te.type != ModContent.TileEntityType<TEStorageHeart>()) goto original;
TEStorageHeart heart = (TEStorageHeart)te;
heart.TryDeposit(returnItem);
heart.ResetCompactStage();
StorageGUI.needRefresh = true;
if (returnItem.stack != newItem.stack) {
if (newItem.IsACoin) {
SoundEngine.PlaySound(SoundID.CoinPickup, player.position);
} else {
SoundEngine.PlaySound(SoundID.Grab, player.position);
}
if (!settings.NoText) {
PopupText.NewText(PopupTextContext.ItemPickupToVoidContainer, newItem, returnItem.stack, noStack: false, settings.LongText);
}
AchievementsHelper.NotifyItemPickup(player, returnItem);
}
if (returnItem.stack == 0) return true;
original:
if (player.HasItem(ItemID.VoidLens)) {
return orig(player, plr, inventory, newItem, settings, returnItem);
} else {
return false;
}
}
}
}
using MagicStorage;
using MagicStorage.Components;
using MagicStorageVoidBag.Items;
using System.Linq;
using Terraria;
using Terraria.Audio;
using Terraria.DataStructures;
using Terraria.GameContent.Achievements;
using Terraria.ID;
using Terraria.ModLoader;
namespace MagicStorageVoidBag.Hooks {
internal class GetItemVoidVaultHook {
private static readonly log4net.ILog Logger = MagicStorageVoidBag.Instance.Logger;
public static bool Hook(Terraria.On_Player.orig_GetItem_VoidVault orig, Player player, int plr, Item[] inventory, Item newItem, GetItemSettings settings, Item returnItem) {
var i = player.inventory.FirstOrDefault(i => i.type == ModContent.ItemType<MSVoidBag>(), null);
newItem = newItem.Clone();
if (i == null) goto original;
var bag = (MSVoidBag)i.ModItem;
if (bag.Location.X < 0 || bag.Location.Y < 0) goto original;
Tile tile = Main.tile[bag.Location.X, bag.Location.Y];
if (!tile.HasTile || tile.TileType != ModContent.TileType<StorageHeart>() || tile.TileFrameX != 0 || tile.TileFrameY != 0) goto original;
if (!TileEntity.ByPosition.TryGetValue(bag.Location, out TileEntity te)) goto original;
if (te.type != ModContent.TileEntityType<TEStorageHeart>()) goto original;
TEStorageHeart heart = (TEStorageHeart)te;
heart.TryDeposit(returnItem);
heart.ResetCompactStage();
StorageGUI.SetRefresh();
if (returnItem.stack != newItem.stack) {
if (newItem.IsACoin) {
SoundEngine.PlaySound(SoundID.CoinPickup, player.position);
} else {
SoundEngine.PlaySound(SoundID.Grab, player.position);
}
if (!settings.NoText) {
PopupText.NewText(PopupTextContext.ItemPickupToVoidContainer, newItem, returnItem.stack, noStack: false, settings.LongText);
}
AchievementsHelper.NotifyItemPickup(player, returnItem);
}
if (returnItem.stack == 0) return true;
original:
if (player.HasItem(ItemID.VoidLens)) {
return orig(player, plr, inventory, newItem, settings, returnItem);
} else {
return false;
}
}
}
}

View File

@ -1,45 +1,45 @@
using MagicStorage.Components;
using MagicStorageVoidBag.Items;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Terraria;
using Terraria.DataStructures;
using Terraria.ModLoader;
using MagicStorage;
using Terraria.ID;
namespace MagicStorageVoidBag.Hooks {
internal class ItemSpaceForCofveveHook {
private static readonly log4net.ILog Logger = MagicStorageVoidBag.Instance.Logger;
// Despite the constant negative press cofveve
public static bool Hook(Terraria.On_Player.orig_ItemSpaceForCofveve orig, Player player, Item newItem) {
var i = player.inventory.FirstOrDefault(i => i.type == ModContent.ItemType<MSVoidBag>(), null);
if (i == null) goto original;
newItem = newItem.Clone();
var bag = (MSVoidBag)i.ModItem;
if (bag.Location.X < 0 || bag.Location.Y < 0) goto original;
Tile tile = Main.tile[bag.Location.X, bag.Location.Y];
if (!tile.HasTile || tile.TileType != ModContent.TileType<StorageHeart>() || tile.TileFrameX != 0 || tile.TileFrameY != 0) goto original;
if (!TileEntity.ByPosition.TryGetValue(bag.Location, out TileEntity te)) goto original;
if (te.type != ModContent.TileEntityType<TEStorageHeart>()) goto original;
if (Utility.HeartHasSpaceFor(newItem, (TEStorageHeart)te)) return true;
original:
if (player.HasItem(ItemID.VoidLens)) {
return orig(player, newItem);
} else {
return false;
}
}
}
}
using MagicStorage.Components;
using MagicStorageVoidBag.Items;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Terraria;
using Terraria.DataStructures;
using Terraria.ModLoader;
using MagicStorage;
using Terraria.ID;
namespace MagicStorageVoidBag.Hooks {
internal class ItemSpaceForCofveveHook {
private static readonly log4net.ILog Logger = MagicStorageVoidBag.Instance.Logger;
// Despite the constant negative press cofveve
public static bool Hook(Terraria.On_Player.orig_ItemSpaceForCofveve orig, Player player, Item newItem) {
var i = player.inventory.FirstOrDefault(i => i.type == ModContent.ItemType<MSVoidBag>(), null);
if (i == null) goto original;
newItem = newItem.Clone();
var bag = (MSVoidBag)i.ModItem;
if (bag.Location.X < 0 || bag.Location.Y < 0) goto original;
Tile tile = Main.tile[bag.Location.X, bag.Location.Y];
if (!tile.HasTile || tile.TileType != ModContent.TileType<StorageHeart>() || tile.TileFrameX != 0 || tile.TileFrameY != 0) goto original;
if (!TileEntity.ByPosition.TryGetValue(bag.Location, out TileEntity te)) goto original;
if (te.type != ModContent.TileEntityType<TEStorageHeart>()) goto original;
if (Utility.HeartHasSpaceFor(newItem, (TEStorageHeart)te)) return true;
original:
if (player.HasItem(ItemID.VoidLens)) {
return orig(player, newItem);
} else {
return false;
}
}
}
}

View File

@ -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!");
}
}
}

View File

@ -1,15 +1,17 @@
Mods: {
Mods: {
MagicStorageVoidBag: {
ItemName: {
MSVoidBag: Magic Void Bag
}
ItemTooltip: {
MSVoidBag:
ItemName.MSVoidBag: Magic Void Bag
ItemTooltip.MSVoidBag:
'''
<right> Storage Heart to store location
Currently not set to any location
'''
Items: {
MSVoidBag: {
DisplayName: M S Void Bag
Tooltip: ""
}
}
}
}

View File

@ -1,29 +1,29 @@
using Terraria.ModLoader;
using MagicStorageVoidBag.ILPatches;
using MagicStorageVoidBag.Hooks;
namespace MagicStorageVoidBag {
public class MagicStorageVoidBag : Mod {
public static MagicStorageVoidBag Instance => ModContent.GetInstance<MagicStorageVoidBag>();
// IL Patches
private PlayerUpdatePatch playerUpdatePatch = new();
public override void Load() {
Terraria.IL_Player.Update += playerUpdatePatch.Patch;
Terraria.On_Player.GetItem_VoidVault += GetItemVoidVaultHook.Hook;
Terraria.On_Player.ItemSpaceForCofveve += ItemSpaceForCofveveHook.Hook;
}
public override void Unload() {
Terraria.IL_Player.Update -= playerUpdatePatch.Patch;
Terraria.On_Player.GetItem_VoidVault -= GetItemVoidVaultHook.Hook;
Terraria.On_Player.ItemSpaceForCofveve -= ItemSpaceForCofveveHook.Hook;
base.Unload();
}
}
using Terraria.ModLoader;
using MagicStorageVoidBag.ILPatches;
using MagicStorageVoidBag.Hooks;
namespace MagicStorageVoidBag {
public class MagicStorageVoidBag : Mod {
public static MagicStorageVoidBag Instance => ModContent.GetInstance<MagicStorageVoidBag>();
// IL Patches
private PlayerUpdatePatch playerUpdatePatch = new();
public override void Load() {
Terraria.IL_Player.Update += playerUpdatePatch.Patch;
Terraria.On_Player.GetItem_VoidVault += GetItemVoidVaultHook.Hook;
Terraria.On_Player.ItemSpaceForCofveve += ItemSpaceForCofveveHook.Hook;
}
public override void Unload() {
Terraria.IL_Player.Update -= playerUpdatePatch.Patch;
Terraria.On_Player.GetItem_VoidVault -= GetItemVoidVaultHook.Hook;
Terraria.On_Player.ItemSpaceForCofveve -= ItemSpaceForCofveveHook.Hook;
base.Unload();
}
}
}