Compare commits

..

10 Commits
v1.4 ... main

9 changed files with 90 additions and 85 deletions

View File

@ -8,9 +8,9 @@ clone:
pipeline: pipeline:
fetch-deps: fetch-deps:
image: alpine/git:latest image: jackbondpreston/msvb-build-env
commands: commands:
- git clone https://github.com/blushiemagic/MagicStorage.git - steamcmd "+login anonymous" "+workshop_download_item 1281930 2563309347" "+quit"
- wget https://github.com/tModLoader/tModLoader/releases/latest/download/tModLoader.zip - wget https://github.com/tModLoader/tModLoader/releases/latest/download/tModLoader.zip
- unzip -q tModLoader.zip -d tModLoader - unzip -q tModLoader.zip -d tModLoader
- rm tModLoader.zip - rm tModLoader.zip
@ -19,18 +19,26 @@ pipeline:
echo "<Project ToolsVersion=\"14.0\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\"> echo "<Project ToolsVersion=\"14.0\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">
<Import Project=\"$CI_WORKSPACE/tModLoader/tMLMod.targets\" /> <Import Project=\"$CI_WORKSPACE/tModLoader/tMLMod.targets\" />
</Project>" > tModLoader.targets </Project>" > tModLoader.targets
- |
wget https://github.com/steviegt6/tml-patcher/releases/latest/download/TML.Patcher.zip
unzip -q TML.Patcher.zip -d TMLPatcher
- |
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)
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 ./
- dotnet TMLPatcher/TML.Patcher.dll extract MagicStorage.tmod
- cp MagicStorage/MagicStorage.dll $CI_WORKSPACE/
when: when:
event: tag event: tag
build: build:
image: jackbondpreston/fna-alpine image: jackbondpreston/msvb-build-env
commands: commands:
- | - |
echo "Shell: $SHELL" echo "Shell: $SHELL"
echo "CI_WORKSPACE: $CI_WORKSPACE" echo "CI_WORKSPACE: $CI_WORKSPACE"
- cat tModLoader.targets - cat tModLoader.targets
- cd MagicStorage && dotnet build -c Release || true
- cp bin/Release/net6.0/MagicStorage.dll .
- cd $CI_WORKSPACE - cd $CI_WORKSPACE
- cd MagicStorageVoidBag - cd MagicStorageVoidBag
- rm -rf .git - rm -rf .git
@ -54,16 +62,3 @@ pipeline:
when: when:
event: tag event: tag
github-release:
image: plugins/github-release
settings:
api_key:
from_secret: github-api-key
base_url: https://github.com/api/v3/
upload_url: https://github.com/api/uploads
files: release/*
environment:
- DRONE_REPO_OWNER=jackbondpreston
- CI_REPO_OWNER=jackbondpreston
when:
event: tag

View File

@ -12,7 +12,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();
@ -21,19 +21,19 @@ namespace MagicStorageVoidBag.Hooks {
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) {

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;
@ -24,12 +24,12 @@ namespace MagicStorageVoidBag.Hooks {
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;

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

@ -27,10 +27,10 @@ namespace MagicStorageVoidBag.Items {
} }
public override void ModifyTooltips(List<TooltipLine> lines) { public override void ModifyTooltips(List<TooltipLine> lines) {
bool isSet = location.X >= 0 && location.Y >= 0; bool isSet = Location.X >= 0 && Location.Y >= 0;
for (int k = 0; k < lines.Count; k++) for (int k = 0; k < lines.Count; k++)
if (isSet && lines[k].Mod == "Terraria" && lines[k].Name == "Tooltip1") { if (isSet && lines[k].Mod == "Terraria" && lines[k].Name == "Tooltip1") {
lines[k].Text = Language.GetTextValue("Mods.MagicStorage.SetTo", location.X, location.Y); lines[k].Text = Language.GetTextValue("Mods.MagicStorage.SetTo", Location.X, Location.Y);
} else if (!isSet && lines[k].Mod == "Terraria" && lines[k].Name == "Tooltip2") { } else if (!isSet && lines[k].Mod == "Terraria" && lines[k].Name == "Tooltip2") {
lines.RemoveAt(k); lines.RemoveAt(k);
k--; k--;

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,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.4 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