dev: more 1.4.4 fixes, fix CRLF -> LF
This commit is contained in:
parent
278a0d9278
commit
0c6328b39d
@ -1,62 +1,62 @@
|
|||||||
using MagicStorage;
|
using MagicStorage;
|
||||||
using MagicStorage.Components;
|
using MagicStorage.Components;
|
||||||
using MagicStorageVoidBag.Items;
|
using MagicStorageVoidBag.Items;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Terraria;
|
using Terraria;
|
||||||
using Terraria.Audio;
|
using Terraria.Audio;
|
||||||
using Terraria.DataStructures;
|
using Terraria.DataStructures;
|
||||||
using Terraria.GameContent.Achievements;
|
using Terraria.GameContent.Achievements;
|
||||||
using Terraria.ID;
|
using Terraria.ID;
|
||||||
using Terraria.ModLoader;
|
using Terraria.ModLoader;
|
||||||
|
|
||||||
namespace MagicStorageVoidBag.Hooks {
|
namespace MagicStorageVoidBag.Hooks {
|
||||||
internal class GetItemVoidVaultHook {
|
internal class GetItemVoidVaultHook {
|
||||||
private static readonly log4net.ILog Logger = MagicStorageVoidBag.Instance.Logger;
|
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) {
|
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);
|
var i = player.inventory.FirstOrDefault(i => i.type == ModContent.ItemType<MSVoidBag>(), null);
|
||||||
|
|
||||||
newItem = newItem.Clone();
|
newItem = newItem.Clone();
|
||||||
|
|
||||||
if (i == null) goto original;
|
if (i == null) goto original;
|
||||||
|
|
||||||
var bag = (MSVoidBag)i.ModItem;
|
var bag = (MSVoidBag)i.ModItem;
|
||||||
|
|
||||||
if (bag.Location.X < 0 || bag.Location.Y < 0) goto original;
|
if (bag.Location.X < 0 || bag.Location.Y < 0) goto original;
|
||||||
|
|
||||||
Tile tile = Main.tile[bag.Location.X, bag.Location.Y];
|
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 (!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 (!TileEntity.ByPosition.TryGetValue(bag.Location, out TileEntity te)) goto original;
|
||||||
if (te.type != ModContent.TileEntityType<TEStorageHeart>()) goto original;
|
if (te.type != ModContent.TileEntityType<TEStorageHeart>()) goto original;
|
||||||
|
|
||||||
TEStorageHeart heart = (TEStorageHeart)te;
|
TEStorageHeart heart = (TEStorageHeart)te;
|
||||||
|
|
||||||
heart.TryDeposit(returnItem);
|
heart.TryDeposit(returnItem);
|
||||||
heart.ResetCompactStage();
|
heart.ResetCompactStage();
|
||||||
StorageGUI.needRefresh = true;
|
StorageGUI.SetRefresh();
|
||||||
|
|
||||||
if (returnItem.stack != newItem.stack) {
|
if (returnItem.stack != newItem.stack) {
|
||||||
if (newItem.IsACoin) {
|
if (newItem.IsACoin) {
|
||||||
SoundEngine.PlaySound(SoundID.CoinPickup, player.position);
|
SoundEngine.PlaySound(SoundID.CoinPickup, player.position);
|
||||||
} else {
|
} else {
|
||||||
SoundEngine.PlaySound(SoundID.Grab, player.position);
|
SoundEngine.PlaySound(SoundID.Grab, player.position);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!settings.NoText) {
|
if (!settings.NoText) {
|
||||||
PopupText.NewText(PopupTextContext.ItemPickupToVoidContainer, newItem, returnItem.stack, noStack: false, settings.LongText);
|
PopupText.NewText(PopupTextContext.ItemPickupToVoidContainer, newItem, returnItem.stack, noStack: false, settings.LongText);
|
||||||
}
|
}
|
||||||
|
|
||||||
AchievementsHelper.NotifyItemPickup(player, returnItem);
|
AchievementsHelper.NotifyItemPickup(player, returnItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (returnItem.stack == 0) return true;
|
if (returnItem.stack == 0) return true;
|
||||||
|
|
||||||
original:
|
original:
|
||||||
if (player.HasItem(ItemID.VoidLens)) {
|
if (player.HasItem(ItemID.VoidLens)) {
|
||||||
return orig(player, plr, inventory, newItem, settings, returnItem);
|
return orig(player, plr, inventory, newItem, settings, returnItem);
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,45 +1,45 @@
|
|||||||
using MagicStorage.Components;
|
using MagicStorage.Components;
|
||||||
using MagicStorageVoidBag.Items;
|
using MagicStorageVoidBag.Items;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Terraria;
|
using Terraria;
|
||||||
using Terraria.DataStructures;
|
using Terraria.DataStructures;
|
||||||
using Terraria.ModLoader;
|
using Terraria.ModLoader;
|
||||||
using MagicStorage;
|
using MagicStorage;
|
||||||
using Terraria.ID;
|
using Terraria.ID;
|
||||||
|
|
||||||
namespace MagicStorageVoidBag.Hooks {
|
namespace MagicStorageVoidBag.Hooks {
|
||||||
internal class ItemSpaceForCofveveHook {
|
internal class ItemSpaceForCofveveHook {
|
||||||
private static readonly log4net.ILog Logger = MagicStorageVoidBag.Instance.Logger;
|
private static readonly log4net.ILog Logger = MagicStorageVoidBag.Instance.Logger;
|
||||||
|
|
||||||
// Despite the constant negative press cofveve
|
// Despite the constant negative press cofveve
|
||||||
public static bool Hook(Terraria.On_Player.orig_ItemSpaceForCofveve orig, Player player, Item newItem) {
|
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);
|
var i = player.inventory.FirstOrDefault(i => i.type == ModContent.ItemType<MSVoidBag>(), null);
|
||||||
if (i == null) goto original;
|
if (i == null) goto original;
|
||||||
|
|
||||||
newItem = newItem.Clone();
|
newItem = newItem.Clone();
|
||||||
|
|
||||||
var bag = (MSVoidBag)i.ModItem;
|
var bag = (MSVoidBag)i.ModItem;
|
||||||
|
|
||||||
if (bag.Location.X < 0 || bag.Location.Y < 0) goto original;
|
if (bag.Location.X < 0 || bag.Location.Y < 0) goto original;
|
||||||
|
|
||||||
Tile tile = Main.tile[bag.Location.X, bag.Location.Y];
|
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 (!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 (!TileEntity.ByPosition.TryGetValue(bag.Location, out TileEntity te)) goto original;
|
||||||
if (te.type != ModContent.TileEntityType<TEStorageHeart>()) goto original;
|
if (te.type != ModContent.TileEntityType<TEStorageHeart>()) goto original;
|
||||||
|
|
||||||
if (Utility.HeartHasSpaceFor(newItem, (TEStorageHeart)te)) return true;
|
if (Utility.HeartHasSpaceFor(newItem, (TEStorageHeart)te)) return true;
|
||||||
|
|
||||||
original:
|
original:
|
||||||
if (player.HasItem(ItemID.VoidLens)) {
|
if (player.HasItem(ItemID.VoidLens)) {
|
||||||
return orig(player, newItem);
|
return orig(player, newItem);
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,27 +13,35 @@ namespace MagicStorageVoidBag.ILPatches {
|
|||||||
internal class PlayerUpdatePatch : ILPatch {
|
internal class PlayerUpdatePatch : ILPatch {
|
||||||
private static readonly log4net.ILog Logger = MagicStorageVoidBag.Instance.Logger;
|
private static readonly log4net.ILog Logger = MagicStorageVoidBag.Instance.Logger;
|
||||||
public void Patch(ILContext il) {
|
public void Patch(ILContext il) {
|
||||||
if (il == null) {
|
try {
|
||||||
Logger.Error("ILContext null!");
|
if (il == null) {
|
||||||
return;
|
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!");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,15 +1,17 @@
|
|||||||
Mods: {
|
Mods: {
|
||||||
MagicStorageVoidBag: {
|
MagicStorageVoidBag: {
|
||||||
ItemName: {
|
ItemName.MSVoidBag: Magic Void Bag
|
||||||
MSVoidBag: Magic Void Bag
|
ItemTooltip.MSVoidBag:
|
||||||
}
|
|
||||||
ItemTooltip: {
|
|
||||||
MSVoidBag:
|
|
||||||
'''
|
'''
|
||||||
<right> Storage Heart to store location
|
<right> Storage Heart to store location
|
||||||
Currently not set to any location
|
Currently not set to any location
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
Items: {
|
||||||
|
MSVoidBag: {
|
||||||
|
DisplayName: M S Void Bag
|
||||||
|
Tooltip: ""
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -1,29 +1,29 @@
|
|||||||
|
|
||||||
using Terraria.ModLoader;
|
using Terraria.ModLoader;
|
||||||
using MagicStorageVoidBag.ILPatches;
|
using MagicStorageVoidBag.ILPatches;
|
||||||
using MagicStorageVoidBag.Hooks;
|
using MagicStorageVoidBag.Hooks;
|
||||||
|
|
||||||
namespace MagicStorageVoidBag {
|
namespace MagicStorageVoidBag {
|
||||||
public class MagicStorageVoidBag : Mod {
|
public class MagicStorageVoidBag : Mod {
|
||||||
public static MagicStorageVoidBag Instance => ModContent.GetInstance<MagicStorageVoidBag>();
|
public static MagicStorageVoidBag Instance => ModContent.GetInstance<MagicStorageVoidBag>();
|
||||||
|
|
||||||
// IL Patches
|
// IL Patches
|
||||||
private PlayerUpdatePatch playerUpdatePatch = new();
|
private PlayerUpdatePatch playerUpdatePatch = new();
|
||||||
|
|
||||||
public override void Load() {
|
public override void Load() {
|
||||||
Terraria.IL_Player.Update += playerUpdatePatch.Patch;
|
Terraria.IL_Player.Update += playerUpdatePatch.Patch;
|
||||||
|
|
||||||
Terraria.On_Player.GetItem_VoidVault += GetItemVoidVaultHook.Hook;
|
Terraria.On_Player.GetItem_VoidVault += GetItemVoidVaultHook.Hook;
|
||||||
Terraria.On_Player.ItemSpaceForCofveve += ItemSpaceForCofveveHook.Hook;
|
Terraria.On_Player.ItemSpaceForCofveve += ItemSpaceForCofveveHook.Hook;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Unload() {
|
public override void Unload() {
|
||||||
Terraria.IL_Player.Update -= playerUpdatePatch.Patch;
|
Terraria.IL_Player.Update -= playerUpdatePatch.Patch;
|
||||||
|
|
||||||
Terraria.On_Player.GetItem_VoidVault -= GetItemVoidVaultHook.Hook;
|
Terraria.On_Player.GetItem_VoidVault -= GetItemVoidVaultHook.Hook;
|
||||||
Terraria.On_Player.ItemSpaceForCofveve -= ItemSpaceForCofveveHook.Hook;
|
Terraria.On_Player.ItemSpaceForCofveve -= ItemSpaceForCofveveHook.Hook;
|
||||||
|
|
||||||
base.Unload();
|
base.Unload();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user