6 Commits

10 changed files with 77 additions and 69 deletions

View File

@ -23,10 +23,10 @@ pipeline:
wget https://github.com/steviegt6/tml-patcher/releases/latest/download/TML.Patcher.zip wget https://github.com/steviegt6/tml-patcher/releases/latest/download/TML.Patcher.zip
unzip -q TML.Patcher.zip -d TMLPatcher unzip -q TML.Patcher.zip -d TMLPatcher
- | - |
rm -f /root/.steam/steamapps/workshop/content/1281930/2563309347/workshop.json rm -f /root/.steam/SteamApps/workshop/content/1281930/2563309347/workshop.json
YEAR=$(ls /root/.steam/steamapps/workshop/content/1281930/2563309347 | cut -c -4 | sort -nr | head -n 1) YEAR=$(ls /root/.steam/SteamApps/workshop/content/1281930/2563309347 | cut -c -4 | sort -nr | head -n 1)
VER=$(find /root/.steam/steamapps/workshop/content/1281930/2563309347/ -type d -name "$YEAR.*" -printf "%f\n" | cut -c 6- | sort -nr | head -n 1) VER=$(find /root/.steam/SteamApps/workshop/content/1281930/2563309347/ -type d -name "$YEAR.*" -printf "%f\n" | cut -c 6- | sort -nr | head -n 1)
cp /root/.steam/steamapps/workshop/content/1281930/2563309347/$YEAR.$VER/MagicStorage.tmod ./ cp /root/.steam/SteamApps/workshop/content/1281930/2563309347/$YEAR.$VER/MagicStorage.tmod ./
- dotnet TMLPatcher/TML.Patcher.dll extract MagicStorage.tmod - dotnet TMLPatcher/TML.Patcher.dll extract MagicStorage.tmod
- cp MagicStorage/MagicStorage.dll $CI_WORKSPACE/ - cp MagicStorage/MagicStorage.dll $CI_WORKSPACE/
when: when:

View File

@ -1,4 +1,5 @@
using MagicStorage; using MagicStorage;
using MagicStorage.Common.Systems;
using MagicStorage.Components; using MagicStorage.Components;
using MagicStorageVoidBag.Items; using MagicStorageVoidBag.Items;
using System.Linq; using System.Linq;
@ -12,7 +13,7 @@ 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(On.Terraria.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();
@ -33,7 +34,7 @@ namespace MagicStorageVoidBag.Hooks {
heart.TryDeposit(returnItem); heart.TryDeposit(returnItem);
heart.ResetCompactStage(); heart.ResetCompactStage();
StorageGUI.needRefresh = true; MagicUI.SetRefresh();
if (returnItem.stack != newItem.stack) { if (returnItem.stack != newItem.stack) {
if (newItem.IsACoin) { if (newItem.IsACoin) {

View File

@ -16,7 +16,7 @@ namespace MagicStorageVoidBag.Hooks {
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(On.Terraria.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;

View File

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

View File

@ -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: ""
}
} }
} }
}
}

View File

@ -10,18 +10,18 @@ namespace MagicStorageVoidBag {
// IL Patches // IL Patches
private PlayerUpdatePatch playerUpdatePatch = new(); private PlayerUpdatePatch playerUpdatePatch = new();
public override void Load() { public override void Load() {
IL.Terraria.Player.Update += playerUpdatePatch.Patch; Terraria.IL_Player.Update += playerUpdatePatch.Patch;
On.Terraria.Player.GetItem_VoidVault += GetItemVoidVaultHook.Hook; Terraria.On_Player.GetItem_VoidVault += GetItemVoidVaultHook.Hook;
On.Terraria.Player.ItemSpaceForCofveve += ItemSpaceForCofveveHook.Hook; Terraria.On_Player.ItemSpaceForCofveve += ItemSpaceForCofveveHook.Hook;
} }
public override void Unload() { public override void Unload() {
IL.Terraria.Player.Update -= playerUpdatePatch.Patch; Terraria.IL_Player.Update -= playerUpdatePatch.Patch;
On.Terraria.Player.GetItem_VoidVault -= GetItemVoidVaultHook.Hook; Terraria.On_Player.GetItem_VoidVault -= GetItemVoidVaultHook.Hook;
On.Terraria.Player.ItemSpaceForCofveve -= ItemSpaceForCofveveHook.Hook; Terraria.On_Player.ItemSpaceForCofveve -= ItemSpaceForCofveveHook.Hook;
base.Unload(); base.Unload();
} }

View File

@ -1,14 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<!-- Import tModLoader mod properties -->
<Import Project="../tModLoader.targets" /> <Import Project="../tModLoader.targets" />
<PropertyGroup> <PropertyGroup>
<AssemblyName>MagicStorageVoidBag</AssemblyName> <AssemblyName>MagicStorageVoidBag</AssemblyName>
<TargetFramework>net6.0</TargetFramework>
<PlatformTarget>AnyCPU</PlatformTarget>
<LangVersion>latest</LangVersion> <LangVersion>latest</LangVersion>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="tModLoader.CodeAssist" Version="0.1.*" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Reference Include="MagicStorage"> <Reference Include="MagicStorage">

View File

@ -1,16 +1,16 @@
{ {
"profiles": { "profiles": {
"Terraria": { "Terraria": {
"commandName": "Executable", "commandName": "Executable",
"executablePath": "dotnet", "executablePath": "dotnet",
"commandLineArgs": "$(tMLPath)", "commandLineArgs": "$(tMLPath)",
"workingDirectory": "$(tMLSteamPath)" "workingDirectory": "$(tMLSteamPath)"
}, },
"TerrariaServer": { "TerrariaServer": {
"commandName": "Executable", "commandName": "Executable",
"executablePath": "dotnet", "executablePath": "dotnet",
"commandLineArgs": "$(tMLServerPath)", "commandLineArgs": "$(tMLServerPath)",
"workingDirectory": "$(tMLSteamPath)" "workingDirectory": "$(tMLSteamPath)"
} }
} }
} }

View File

@ -1,7 +1,7 @@
displayName = MagicStorage Void Bag displayName = MagicStorage Void Bag
author = jack author = jack
version = 1.6 version = 1.7
modReferences = MagicStorage modReferences = MagicStorage
sortAfter = MagicStorage sortAfter = MagicStorage
includeSource = true includeSource = true
homepage = https://github.com/jackbondpreston/MagicStorageVoidBag homepage = https://git.jackbondpreston.me/jack/MagicStorageVoidBag

View File

@ -1,7 +1,7 @@
Adds an upgraded void bag that combines functionality of the Void Bag and Portable Remote Storage Access, by putting items into a magic storage system when your inventory is full (and allowing remote access as usual). Adds an upgraded void bag that combines functionality of the Void Bag and Portable Remote Storage Access, by putting items into a magic storage system when your inventory is full (and allowing remote access as usual).
This item is crafted by combining a Void Bag with a Portable Remote Storage Access. To link it with your storage system, right click the Storage Heart with the bag equipped. This item is crafted by combining a Void Bag with a Portable Remote Storage Access. To link it with your storage system, right click the Storage Heart with the bag equipped.
GitHub: https://github.com/jackbondpreston/MagicStorageVoidBag Git: https://git.jackbondpreston.me/jack/MagicStorageVoidBag
Discord server if you need support/don't want to report bugs on GitHub: https://discord.gg/Z6V77mbtZQ Discord server if you need support/don't want to report bugs on GitHub: https://discord.gg/Z6V77mbtZQ
Thanks to the original MagicStorage mod for some code and of course the functionality of the original mod! Thanks to the original MagicStorage mod for some code and of course the functionality of the original mod!