-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #93 from Vapok/vapok/r1.6.16
Vapok/r1.6.16
- Loading branch information
Showing
26 changed files
with
286 additions
and
578 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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++; | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file modified
BIN
+16 Bytes
(100%)
UnityProjects/vapoksbackpacks/vapoksbackpacks/Assets/StreamingAssets/StreamingAssets
Binary file not shown.
2 changes: 1 addition & 1 deletion
2
...yProjects/vapoksbackpacks/vapoksbackpacks/Assets/StreamingAssets/StreamingAssets.manifest
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
ManifestFileVersion: 0 | ||
CRC: 2740477329 | ||
CRC: 1499047801 | ||
AssetBundleManifest: | ||
AssetBundleInfos: | ||
Info_0: | ||
|
Binary file modified
BIN
+8.58 KB
(100%)
UnityProjects/vapoksbackpacks/vapoksbackpacks/Assets/StreamingAssets/vapokbackpacks
Binary file not shown.
6 changes: 3 additions & 3 deletions
6
UnityProjects/vapoksbackpacks/vapoksbackpacks/Assets/StreamingAssets/vapokbackpacks.manifest
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file added
BIN
+2 MB
...Projects/vapoksbackpacks/vapoksbackpacks/Assets/vapok/Models/Mistlands Backpack Small.fbx
Binary file not shown.
Oops, something went wrong.