Skip to content

Commit

Permalink
Merge pull request #93 from Vapok/vapok/r1.6.16
Browse files Browse the repository at this point in the history
Vapok/r1.6.16
  • Loading branch information
Vapok authored Mar 29, 2023
2 parents cf2b183 + b2dc00e commit 096ef30
Show file tree
Hide file tree
Showing 26 changed files with 286 additions and 578 deletions.
2 changes: 1 addition & 1 deletion AdventureBackpacks.sln
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Module Files", "Module File
README.md = README.md
manifest.json = manifest.json
icon.png = icon.png
PATCHNOTES.md = PATCHNOTES.md
CHANGELOG.md = CHANGELOG.md
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Translations", "Translations", "{453B1EE0-9980-4B66-93B3-2DDBD21FEE03}"
Expand Down
2 changes: 1 addition & 1 deletion AdventureBackpacks/AdventureBackpacks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class AdventureBackpacks : BaseUnityPlugin, IPluginInfo
//Module Constants
private const string _pluginId = "vapok.mods.adventurebackpacks";
private const string _displayName = "Adventure Backpacks";
private const string _version = "1.6.15";
private const string _version = "1.6.16";

//Interface Properties
public string PluginId => _pluginId;
Expand Down
9 changes: 5 additions & 4 deletions AdventureBackpacks/AdventureBackpacks.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@
<HintPath>..\..\References\BepInEx\5.4.2101\BepInEx\core\0Harmony.dll</HintPath>
</Reference>
<Reference Include="assembly_guiutils">
<HintPath>..\..\References\Valheim\0.214.3\assembly_guiutils_publicized.dll</HintPath>
<HintPath>..\..\References\Valheim\0.214.300\assembly_guiutils_publicized.dll</HintPath>
</Reference>
<Reference Include="assembly_utils">
<HintPath>..\..\References\Valheim\0.214.3\assembly_utils_publicized.dll</HintPath>
<HintPath>..\..\References\Valheim\0.214.300\assembly_utils_publicized.dll</HintPath>
</Reference>
<Reference Include="assembly_valheim">
<HintPath>..\..\References\Valheim\0.214.3\assembly_valheim_publicized.dll</HintPath>
<HintPath>..\..\References\Valheim\0.214.300\assembly_valheim_publicized.dll</HintPath>
</Reference>
<Reference Include="BepInEx">
<HintPath>..\..\References\BepInEx\5.4.2101\BepInEx\core\BepInEx.dll</HintPath>
Expand Down Expand Up @@ -124,6 +124,7 @@
<Compile Include="Patches\Inventory.cs" />
<Compile Include="Patches\InventoryGui.cs" />
<Compile Include="Patches\ItemDrop.cs" />
<Compile Include="Patches\Player.cs" />
<Compile Include="Patches\SEMan.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="AdventureBackpacks.cs" />
Expand All @@ -146,7 +147,7 @@
<Exec Command="xcopy &quot;M:\Code\VapokModBase\AdventureBackpacks\Translations\*.json&quot; &quot;M:\Code\VapokModBase\Releases\AdventureBackpacks-Vapok\plugins\Translations\&quot; /q /y /i" />
<Exec Command="xcopy &quot;M:\Code\VapokModBase\AdventureBackpacks\LICENSE.md&quot; &quot;M:\Code\VapokModBase\Releases\AdventureBackpacks-Vapok\&quot; /q /y /i" />
<Exec Command="xcopy &quot;M:\Code\VapokModBase\AdventureBackpacks\manifest.json&quot; &quot;M:\Code\VapokModBase\Releases\AdventureBackpacks-Vapok\&quot; /q /y /i" />
<Exec Command="xcopy &quot;M:\Code\VapokModBase\AdventureBackpacks\PATCHNOTES.md&quot; &quot;M:\Code\VapokModBase\Releases\AdventureBackpacks-Vapok\&quot; /q /y /i" />
<Exec Command="xcopy &quot;M:\Code\VapokModBase\AdventureBackpacks\CHANGELOG.md&quot; &quot;M:\Code\VapokModBase\Releases\AdventureBackpacks-Vapok\&quot; /q /y /i" />
<Exec Command="xcopy &quot;M:\Code\VapokModBase\AdventureBackpacks\README.md&quot; &quot;M:\Code\VapokModBase\Releases\AdventureBackpacks-Vapok\&quot; /q /y /i" />
<Exec Command="xcopy &quot;M:\Code\VapokModBase\AdventureBackpacks\icon.png&quot; &quot;M:\Code\VapokModBase\Releases\AdventureBackpacks-Vapok\&quot; /q /y /i" />
</Target>
Expand Down
Binary file modified AdventureBackpacks/Assets/Bundles/vapokbackpacks
Binary file not shown.
54 changes: 54 additions & 0 deletions AdventureBackpacks/Patches/InventoryGui.cs
Original file line number Diff line number Diff line change
Expand Up @@ -424,4 +424,58 @@ CodeInstruction FindInstructionWithLabel(List<CodeInstruction> codeInstructions,
}
}
}

[HarmonyPatch(typeof(InventoryGui), nameof(InventoryGui.SetupRequirement))]
static class InventoryGuiSetupRequirementPatch
{
public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
{
var instrs = instructions.ToList();

var counter = 0;

CodeInstruction LogMessage(CodeInstruction instruction)
{
AdventureBackpacks.Log.Debug($"IL_{counter}: Opcode: {instruction.opcode} Operand: {instruction.operand}");
return instruction;
}

var ldArgInstruction = new CodeInstruction(OpCodes.Ldarg_2);
var countItemsMethod = AccessTools.DeclaredMethod(typeof(Inventory), "CountItems", new[] { typeof(string), typeof(int) });

for (int i = 0; i < instrs.Count; ++i)
{

yield return LogMessage(instrs[i]);
counter++;

if (i > 5 && instrs[i-1].opcode == OpCodes.Callvirt && instrs[i-1].operand.Equals(countItemsMethod) && instrs[i].opcode == OpCodes.Stloc_S)
{
//Move Any Labels from the instruction position being patched to new instruction.
if (instrs[i].labels.Count > 0)
instrs[i].MoveLabelsTo(ldArgInstruction);

//Player ldArg2
yield return LogMessage(ldArgInstruction);
counter++;

//Piece.Requirement resource
yield return LogMessage(new CodeInstruction(OpCodes.Ldarg_1));
counter++;

//int num
yield return LogMessage(new CodeInstruction(OpCodes.Ldloc_S, instrs[i].operand));
counter++;

//Patch Calling Method
yield return LogMessage(new CodeInstruction(OpCodes.Call, AccessTools.DeclaredMethod(typeof(PlayerPatches), nameof(PlayerPatches.AdjustCountIfEquipped))));
counter++;

//Save output of calling method to local variable 0
yield return LogMessage(new CodeInstruction(OpCodes.Stloc_S, instrs[i].operand));
counter++;
}
}
}
}
}
166 changes: 166 additions & 0 deletions AdventureBackpacks/Patches/Player.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
using System.Collections.Generic;
using System.Linq;
using System.Reflection.Emit;
using HarmonyLib;

namespace AdventureBackpacks.Patches;

public class PlayerPatches
{
public static int AdjustCountIfEquipped(Player player, Piece.Requirement resource, int itemCount)
{
var num = itemCount;

if (num < 1 || !resource.m_resItem.m_itemData.IsEquipable())
return num;

var itemName = resource.m_resItem.m_itemData.m_shared.m_name;
var equippedItems = player.GetInventory().GetEquipedtems();

if (equippedItems.Any(x => x.m_shared.m_name.Equals(itemName)))
{
num -= 1;
}

return num;
}

public static int ConsumeUnEquippedItems(Player player, Piece.Requirement resource, int amount)
{
var num = amount;

if (num < 1 || !resource.m_resItem.m_itemData.IsEquipable())
return num;

var itemName = resource.m_resItem.m_itemData.m_shared.m_name;
var resourceItems = player.m_inventory.GetAllItems().Where(x => x.m_shared.m_name.Equals(itemName)).ToList();

var removedCounter = 0;
for (int i = 0; i < num; i++)
{
foreach (var item in resourceItems)
{
if (item.m_equiped)
continue;

if (removedCounter < amount)
{
player.m_inventory.RemoveItem(item);
removedCounter++;
}
}
}

return num - removedCounter;
}

[HarmonyPatch(typeof(Player), nameof(Player.HaveRequirementItems))]
static class PlayerHaveRequirementItemsPatch
{

public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
{
var instrs = instructions.ToList();

var counter = 0;

CodeInstruction LogMessage(CodeInstruction instruction)
{
AdventureBackpacks.Log.Debug($"IL_{counter}: Opcode: {instruction.opcode} Operand: {instruction.operand}");
return instruction;
}

var ldArgInstruction = new CodeInstruction(OpCodes.Ldarg_0);
var countItemsMethod = AccessTools.DeclaredMethod(typeof(Inventory), "CountItems", new[] { typeof(string), typeof(int) });

for (int i = 0; i < instrs.Count; ++i)
{

yield return LogMessage(instrs[i]);
counter++;

if (i > 5 && instrs[i-1].opcode == OpCodes.Callvirt && instrs[i-1].operand.Equals(countItemsMethod) && instrs[i].opcode == OpCodes.Stloc_S)
{
//Move Any Labels from the instruction position being patched to new instruction.
if (instrs[i].labels.Count > 0)
instrs[i].MoveLabelsTo(ldArgInstruction);

//Player this
yield return LogMessage(ldArgInstruction);
counter++;

//Piece.Requirement resource
yield return LogMessage(new CodeInstruction(OpCodes.Ldloc_2));
counter++;

//int num
yield return LogMessage(new CodeInstruction(OpCodes.Ldloc_S, instrs[i].operand));
counter++;

//Patch Calling Method
yield return LogMessage(new CodeInstruction(OpCodes.Call, AccessTools.DeclaredMethod(typeof(PlayerPatches), nameof(AdjustCountIfEquipped))));
counter++;

//Save output of calling method to local variable 0
yield return LogMessage(new CodeInstruction(OpCodes.Stloc_S, instrs[i].operand));
counter++;
}
}
}
}

[HarmonyPatch(typeof(Player), nameof(Player.ConsumeResources))]
static class PlayerConsumeResourcesPatch
{

public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
{
var instrs = instructions.ToList();

var counter = 0;

CodeInstruction LogMessage(CodeInstruction instruction)
{
AdventureBackpacks.Log.Debug($"IL_{counter}: Opcode: {instruction.opcode} Operand: {instruction.operand}");
return instruction;
}

var ldArgInstruction = new CodeInstruction(OpCodes.Ldarg_0);
var getAmountMethod = AccessTools.DeclaredMethod(typeof(Piece.Requirement), "GetAmount", new[] { typeof(int) });

for (int i = 0; i < instrs.Count; ++i)
{

yield return LogMessage(instrs[i]);
counter++;

if (i > 5 && instrs[i-1].opcode == OpCodes.Callvirt && instrs[i-1].operand.Equals(getAmountMethod) && instrs[i].opcode == OpCodes.Stloc_3)
{
//Move Any Labels from the instruction position being patched to new instruction.
if (instrs[i].labels.Count > 0)
instrs[i].MoveLabelsTo(ldArgInstruction);

//Player this
yield return LogMessage(ldArgInstruction);
counter++;

//Piece.Requirement resource
yield return LogMessage(new CodeInstruction(OpCodes.Ldloc_2));
counter++;

//int amount
yield return LogMessage(new CodeInstruction(OpCodes.Ldloc_3));
counter++;

//Patch Calling Method
yield return LogMessage(new CodeInstruction(OpCodes.Call, AccessTools.DeclaredMethod(typeof(PlayerPatches), nameof(ConsumeUnEquippedItems))));
counter++;

//Save output of calling method to local variable 0
yield return LogMessage(new CodeInstruction(OpCodes.Stloc_3));
counter++;
}
}
}
}
}
4 changes: 2 additions & 2 deletions AdventureBackpacks/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.6.15.0")]
[assembly: AssemblyFileVersion("1.6.15.0")]
[assembly: AssemblyVersion("1.6.16.0")]
[assembly: AssemblyFileVersion("1.6.16.0")]
8 changes: 7 additions & 1 deletion PATCHNOTES.md → CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
# Adventure Backpacks Patchnotes
# 1.6.16 - Various Updates
* Crafting bags will no longer allow you to consume equipped cape's.
* To craft a bag with a cape, and the only one in inventory is equipped, it must be unequipped in order for it to be used.
* Scaled down size and repositioned the Explorer's Wisppack.
* Updated Adventure Backpacks Unity version to 2020.3.45
* Updates codebase to 0.214.300 Valheim References
* Adding CHANGELOG.md to Thunderstore package

# 1.6.15.0 - Controller Support!!!, also some bug fixes.
* Fully Implemented Controller/Gamepad Support.
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ learn how to make your very own, Adventure Backpacks! Go forth and wander, ye w
* *Don't see your language, I'm looking for submissions for additional languages. Please find me on Discord (see link below) or submit a Pull Request!*

## Current Patch Notes
[Adventure Backpack Patchnotes](https://github.com/Vapok/AdventureBackpacks/blob/main/PATCHNOTES.md)
[Adventure Backpack Patchnotes](https://github.com/Vapok/AdventureBackpacks/blob/main/CHANGELOG.md)

## Compatible Mods (Verified)
* Epic Loot 0.9.3+
Expand Down Expand Up @@ -150,4 +150,4 @@ Source: [Github](https://github.com/Vapok/AdventureBackpacks)

Discord: [Vapok's Mod's Community](https://discord.gg/5YAJkRFBXt)

Patch notes: [Github Patchnotes](https://github.com/Vapok/AdventureBackpacks/blob/main/PATCHNOTES.md)
Patch notes: [Github Patchnotes](https://github.com/Vapok/AdventureBackpacks/blob/main/CHANGELOG.md)
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,9 @@
<Reference Include="assembly_utils">
<HintPath>Packages\valheim\assembly_utils.dll</HintPath>
</Reference>
<Reference Include="Fishlabs.Core">
<HintPath>Packages\valheim\Fishlabs.Core.dll</HintPath>
</Reference>
<Reference Include="assembly_valheim">
<HintPath>Packages\valheim\assembly_valheim.dll</HintPath>
</Reference>
Expand All @@ -305,9 +308,15 @@
<Reference Include="assembly_guiutils">
<HintPath>Packages\valheim\assembly_guiutils.dll</HintPath>
</Reference>
<Reference Include="ConnectedStorage">
<HintPath>Packages\valheim\ConnectedStorage.dll</HintPath>
</Reference>
<Reference Include="assembly_googleanalytics">
<HintPath>Packages\valheim\assembly_googleanalytics.dll</HintPath>
</Reference>
<Reference Include="Fishlabs.Common">
<HintPath>Packages\valheim\Fishlabs.Common.dll</HintPath>
</Reference>
<Reference Include="PlayFabParty">
<HintPath>Packages\valheim\PlayFabParty.dll</HintPath>
</Reference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,9 @@
<Reference Include="assembly_utils">
<HintPath>Packages\valheim\assembly_utils.dll</HintPath>
</Reference>
<Reference Include="Fishlabs.Core">
<HintPath>Packages\valheim\Fishlabs.Core.dll</HintPath>
</Reference>
<Reference Include="assembly_valheim">
<HintPath>Packages\valheim\assembly_valheim.dll</HintPath>
</Reference>
Expand All @@ -296,9 +299,15 @@
<Reference Include="assembly_guiutils">
<HintPath>Packages\valheim\assembly_guiutils.dll</HintPath>
</Reference>
<Reference Include="ConnectedStorage">
<HintPath>Packages\valheim\ConnectedStorage.dll</HintPath>
</Reference>
<Reference Include="assembly_googleanalytics">
<HintPath>Packages\valheim\assembly_googleanalytics.dll</HintPath>
</Reference>
<Reference Include="Fishlabs.Common">
<HintPath>Packages\valheim\Fishlabs.Common.dll</HintPath>
</Reference>
<Reference Include="PlayFabParty">
<HintPath>Packages\valheim\PlayFabParty.dll</HintPath>
</Reference>
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ManifestFileVersion: 0
CRC: 2740477329
CRC: 1499047801
AssetBundleManifest:
AssetBundleInfos:
Info_0:
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
ManifestFileVersion: 0
CRC: 2859018536
CRC: 3115447487
Hashes:
AssetFileHash:
serializedVersion: 2
Hash: f2fdd8a572839ecdc8160ae6c766554c
Hash: 6b0398d2d5f2c973733c6a19afc1b6c2
TypeTreeHash:
serializedVersion: 2
Hash: a456979f0e08a52494f2dbe579db1edd
Hash: e8332a6d8fa8fcfcc86e8edfb27851a5
HashAppended: 0
ClassTypes:
- Class: 1
Expand Down
Binary file not shown.
Loading

0 comments on commit 096ef30

Please sign in to comment.