Skip to content

Commit

Permalink
- Fixed the camera view locking during the Trapper boss final phase a…
Browse files Browse the repository at this point in the history
…fter choosing a talking card

- Improved fix for the full pack Pack Rat sequence
  • Loading branch information
HumabHatterZed committed Nov 27, 2023
1 parent ac32a50 commit 20bea46
Show file tree
Hide file tree
Showing 8 changed files with 108 additions and 102 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
- Added some null checks
- Added PlayableCard.GetStatIconHealthBuffs()
- Added PlayableCard.TransformIntoCardAboveHand() - variant of TransformIntoCardInHand that incorporates MoveCardAboveHand
- Added FullAbility.SetExtendedProperty for setting an AbilityInfo's custom property during ability creation
- Fixed the camera view locking during the Trapper boss final phase after choosing a talking card
- Fixed DrawCopyOnDeath creating warnings in the console
- Fixed ResourceDrone softlocking during Leshy's goodbye sequence if ConfigDefaultDrone is false
- Improved fix for the full pack Pack Rat sequence

## 2.18.4
- Fixed Sniper sigil targeting the wrong side of the board
Expand Down
14 changes: 13 additions & 1 deletion InscryptionAPI/Card/AbilityExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ public static bool GetHideSingleStacks(this AbilityInfo abilityInfo)
#region ExtendedProperties

/// <summary>
/// Adds a custom property value to the ability.
/// Adds a custom property value to the AbilityInfo.
/// </summary>
/// <param name="info">Ability to access.</param>
/// <param name="propertyName">The name of the property to set.</param>
Expand All @@ -511,6 +511,18 @@ public static AbilityInfo SetExtendedProperty(this AbilityInfo info, string prop
info.GetAbilityExtensionTable()[propertyName] = value?.ToString();
return info;
}
/// <summary>
/// Adds a custom property value to the FullAbility's AbilityInfo - intended as a shorthand for when modders are first adding abilities to the game.
/// </summary>
/// <param name="fullAbility">FullAbility object to access.</param>
/// <param name="propertyName">The name of the property to set.</param>
/// <param name="value">The value of the property.</param>
/// <returns>The same FullAbility so a chain can continue.</returns>
public static FullAbility SetExtendedProperty(this FullAbility fullAbility, string propertyName, object value)
{
fullAbility.Info.GetAbilityExtensionTable()[propertyName] = value?.ToString();
return fullAbility;
}

/// <summary>
/// Gets a custom property value from the card.
Expand Down
22 changes: 11 additions & 11 deletions InscryptionAPI/Card/AbilityManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Text;
using UnityEngine;

namespace InscryptionAPI.Card;
Expand Down Expand Up @@ -411,7 +412,6 @@ private static void CleanUpParsedDescription(ref string __result)
break;

textToCheck = textToCheck.Substring(0, textToCheck.IndexOf("]") + 1);

__result = __result.Replace(textToCheck, textToCheck.Replace("[sigilcost:", "").Replace("]", ""));
}
}
Expand Down Expand Up @@ -462,27 +462,27 @@ internal static string ParseAndUpdateDescription(string description, ExtendedAct
int endIndex = textToChange.IndexOf("]");
textToChange = textToChange.Substring(0, endIndex + 1);

string allCosts = "";
StringBuilder allCosts = new();
if (ability.BonesCost > 0)
{
allCosts += ability.BonesCost.ToString() + " bone";
allCosts.Append(ability.BonesCost.ToString() + " bone");
if (ability.BonesCost != 1)
allCosts += "s";
allCosts.Append("s");
}
if (ability.EnergyCost > 0)
{
if (allCosts != "")
allCosts += ", ";
allCosts += ability.EnergyCost.ToString() + " energy";
if (allCosts.ToString() != "")
allCosts.Append(", ");
allCosts.Append(ability.EnergyCost.ToString() + " energy");
}
if (ability.HealthCost > 0)
{
if (allCosts != "")
allCosts += ", ";
allCosts += ability.HealthCost.ToString() + " health";
if (allCosts.ToString() != "")
allCosts.Append(", ");
allCosts.Append(ability.HealthCost.ToString() + " health");
}

return description.Replace(textToChange, allCosts == "" ? "nothing" : allCosts);
return description.Replace(textToChange, allCosts.ToString() == "" ? "nothing" : allCosts.ToString());
}

string[] blocks = description.Split(' ');
Expand Down
6 changes: 2 additions & 4 deletions InscryptionAPI/Totems/TotemManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,13 @@ internal enum TotemTopState
AllTribes
}

[HarmonyPatch(typeof(BuildTotemSequencer), "GenerateTotemChoices", new System.Type[] { typeof(BuildTotemNodeData), typeof(int) })]
[HarmonyPatch(typeof(BuildTotemSequencer), "GenerateTotemChoices", new Type[] { typeof(BuildTotemNodeData), typeof(int) })]
private class ItemsUtil_AllConsumables
{
public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
{
if (InscryptionAPIPlugin.configCustomTotemTopTypes.Value == TotemTopState.Vanilla)
{
return instructions;
}

// === We want to turn this

Expand Down Expand Up @@ -96,7 +94,7 @@ public static void AddCustomTribesToList(List<Tribe> list)
}
}

[HarmonyPatch(typeof(ResourceBank), "Awake", new System.Type[] { })]
[HarmonyPatch(typeof(ResourceBank), "Awake", new Type[] { })]
private class ResourceBank_Awake
{
public static void Postfix(ResourceBank __instance)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,7 @@ namespace InscryptionCommunityPatch.Card;
[HarmonyPatch]
internal class Act2CuckooFix
{
private static MethodBase TargetMethod()
{
MethodBase baseMethod = AccessTools.Method(typeof(CreateEgg), nameof(CreateEgg.OnResolveOnBoard));
return AccessTools.EnumeratorMoveNext(baseMethod);
}

[HarmonyTranspiler]
[HarmonyTranspiler, HarmonyPatch(typeof(CreateEgg), nameof(CreateEgg.OnResolveOnBoard), MethodType.Enumerator)]
private static IEnumerable<CodeInstruction> FixDialogueSoftlock(IEnumerable<CodeInstruction> instructions)
{
List<CodeInstruction> codes = new(instructions);
Expand Down
14 changes: 7 additions & 7 deletions InscryptionCommunityPatch/ResourceManagers/ActOneEnergyDrone.cs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ private static void Part1ResourcesManager_CleanUp(Part1ResourcesManager __instan
baseResourceManager.PlayerMaxEnergy = 0;
}

if (EnergyConfig.ConfigDrone)
if (EnergyConfig.ConfigDrone && ResourceDrone.m_Instance != null)
{
ResourceDrone.Instance.CloseAllCells(false);
ResourceDrone.Instance.SetOnBoard(false, false);
Expand All @@ -205,11 +205,11 @@ private static void ResourcesManager_Setup(ResourcesManager __instance)
{
if (__instance is Part1ResourcesManager && EnergyConfig.ConfigDrone)
{
ResourceDrone.Instance.SetOnBoard(true, false);
ResourceDrone.Instance?.SetOnBoard(true, false);
if (EnergyConfig.ConfigDroneMox)
{
PatchPlugin.Logger.LogDebug("Setting up extra resources for the drone.");
ResourceDrone.Instance.Gems.SetAllGemsOn(false, true);
ResourceDrone.Instance?.Gems.SetAllGemsOn(false, true);
}
}
}
Expand All @@ -221,7 +221,7 @@ private static IEnumerator ResourcesManager_ShowAddMaxEnergy(IEnumerator result,
if (__instance is Part1ResourcesManager && EnergyConfig.ConfigDrone)
{
int cellsToOpen = __instance.PlayerMaxEnergy - 1;
ResourceDrone.Instance.OpenCell(cellsToOpen);
ResourceDrone.Instance?.OpenCell(cellsToOpen);
yield return new WaitForSeconds(0.4f);
}

Expand All @@ -237,7 +237,7 @@ private static IEnumerator ResourcesManager_ShowAddEnergy(IEnumerator result, in
int num;
for (int i = __instance.PlayerEnergy - amount; i < __instance.PlayerEnergy; i = num + 1)
{
ResourceDrone.Instance.SetCellOn(i, true, false);
ResourceDrone.Instance?.SetCellOn(i, true, false);
yield return new WaitForSeconds(0.05f);
num = i;
}
Expand All @@ -259,7 +259,7 @@ private static IEnumerator ResourcesManager_ShowSpendEnergy(IEnumerator result,
__instance.transform.position, 0.4f, 0f,
new AudioParams.Pitch(0.9f + (float)(__instance.PlayerEnergy + i) * 0.05f), null, null, null,
false);
ResourceDrone.Instance.SetCellOn(i, false, false);
ResourceDrone.Instance?.SetCellOn(i, false, false);
yield return new WaitForSeconds(0.05f);
num = i;
}
Expand Down Expand Up @@ -299,7 +299,7 @@ private static IEnumerator ResourcesManager_ShowLoseGem(IEnumerator result, GemT
private static void ResourcesManager_SetGemOnImmediate(GemType gem, bool on, ResourcesManager __instance)
{
if (__instance is Part1ResourcesManager)
ResourceDrone.Instance.Gems.SetGemOn(gem, on, false);
ResourceDrone.Instance.Gems?.SetGemOn(gem, on, false);
}

[HarmonyPatch(typeof(TurnManager), nameof(TurnManager.DoUpkeepPhase))]
Expand Down
89 changes: 17 additions & 72 deletions InscryptionCommunityPatch/Sequencers/PackRatNodeBackgroundFix.cs
Original file line number Diff line number Diff line change
@@ -1,97 +1,42 @@
using DiskCardGame;
using HarmonyLib;
using InscryptionAPI.Helpers;
using InscryptionCommunityPatch.Card;
using Pixelplacement;
using System.Collections;
using System.Reflection;
using System.Reflection.Emit;
using UnityEngine;

namespace InscryptionCommunityPatch.Sequencers;

// 'fixes' the pack rat card not being rare
[HarmonyPatch]
internal class PackRatNodeBackgroundFix
{
private const string name_RatCard = "DiskCardGame.SelectableCard ratCard";
private const string name_Reward = "DiskCardGame.CardInfo fullConsumablesReward";
private const string name_PixelPlacement = "Pixelplacement.TweenSystem.TweenBase Position(UnityEngine.Transform, UnityEngine.Vector3, Single, Single, UnityEngine.AnimationCurve, LoopType, System.Action, System.Action, Boolean)";
private const string name_GetComponent = "DiskCardGame.SelectableCard GetComponent[SelectableCard]()";
private static MethodBase TargetMethod()
[HarmonyTranspiler, HarmonyPatch(typeof(GainConsumablesSequencer), nameof(GainConsumablesSequencer.FullConsumablesSequence), MethodType.Enumerator)]
private static IEnumerable<CodeInstruction> FixRareBackground(IEnumerable<CodeInstruction> instructions)
{
MethodBase baseMethod = AccessTools.Method(typeof(GainConsumablesSequencer), nameof(GainConsumablesSequencer.FullConsumablesSequence));
return AccessTools.EnumeratorMoveNext(baseMethod);
}
private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
{
List<CodeInstruction> codes = new List<CodeInstruction>(instructions);

object op_RatCard = null;
object op_Reward = null;

// we want to slowly narrow our search until we find exactly where we want to insert our code
List<CodeInstruction> codes = new(instructions);

// a part of the code block we want to remove can't be removed without breaking the ienum
// so we cut around it
for (int i = 0; i < codes.Count; i++)
{
// get the ratCard operand
if (codes[i].opcode == OpCodes.Ldfld && codes[i].operand.ToString() == name_RatCard)
op_RatCard = codes[i].operand;

if (codes[i].opcode == OpCodes.Ldfld && codes[i].operand.ToString() == name_Reward)
op_Reward = codes[i].operand;

// look for the original code for `component`
if (codes[i].opcode == OpCodes.Callvirt && codes[i].operand.ToString() == name_GetComponent)
if (codes[i].opcode == OpCodes.Callvirt && codes[i].operand.ToString() == "DiskCardGame.SelectableCard GetComponent[SelectableCard]()")
{
int startIndex = -1, endIndex = -1;
for (int j = i; j > 0; j--)
int startIndex = i - 3;
for (int j = i + 1; j < codes.Count; j++)
{
// find the startIndex
if (codes[j].opcode == OpCodes.Ldarg_0)
if (codes[j].opcode == OpCodes.Stloc_2)
{
startIndex = j;
codes.RemoveRange(startIndex, j - 3 - startIndex);
break;
}
}

// find the endIndex
for (int k = i; k < codes.Count; k++)
{
if (codes[k].opcode == OpCodes.Stloc_2)
{
for (int l = k; l > 0; l--)
{
if (codes[l].opcode == OpCodes.Callvirt)
{
endIndex = l + 1;
break;
}
}
break;
}
}

MethodInfo customMethod = AccessTools.Method(typeof(PackRatNodeBackgroundFix), nameof(PackRatNodeBackgroundFix.InstantiateSelectableCard), new Type[] { typeof(SelectableCard), typeof(CardInfo) });

// remove all the old code
codes.RemoveRange(startIndex, endIndex - startIndex);

// gainConsumablesSequence.ratCard
codes.Insert(startIndex, new CodeInstruction(OpCodes.Ldloc_1));
codes.Insert(startIndex + 1, new CodeInstruction(OpCodes.Ldfld, op_RatCard));

// gainConsumablesSequence.fullConsumablesReward
codes.Insert(startIndex + 2, new CodeInstruction(OpCodes.Ldloc_1));
codes.Insert(startIndex + 3, new CodeInstruction(OpCodes.Ldfld, op_Reward));

// InstantiateSelectableCard
codes.Insert(startIndex + 4, new CodeInstruction(OpCodes.Call, customMethod));
break;
}
}

return codes;
}

public static void InstantiateSelectableCard(SelectableCard card, CardInfo info)
{
SelectableCard component = UnityObject.Instantiate(card);
component.SetInfo(info);
component.SetInteractionEnabled(false);
UnityObject.Destroy(component);
}
}
53 changes: 53 additions & 0 deletions InscryptionCommunityPatch/Sequencers/TradeableTalkingCardFix.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
using DiskCardGame;
using HarmonyLib;
using InscryptionAPI.Card;
using Pixelplacement;
using System.Collections;
using System.Reflection;
using System.Reflection.Emit;
using UnityEngine;

namespace InscryptionCommunityPatch.Sequencers;

[HarmonyPatch]
internal class TradeableTalkingCardFix
{
[HarmonyPrefix, HarmonyPatch(typeof(TradeCardsForPelts), nameof(TradeCardsForPelts.OnTradableSelected))]
private static bool OnTalkingCardSelected(TradeCardsForPelts __instance, HighlightedInteractable slot, PlayableCard card)
{
if (card != null && card.GetComponent<TalkingCard>() == null)
return true;
// the card we selected is a talking card
// talking cards change the view when drawn - this changes it back
// transpiler would probably be better but feh
if (__instance.PeltInHand())
{
AscensionStatsData.TryIncrementStat(AscensionStat.Type.PeltsTraded);
PlayableCard pelt = Singleton<PlayerHand>.Instance.CardsInHand.Find((PlayableCard x) => x.Info.HasTrait(Trait.Pelt));
Singleton<PlayerHand>.Instance.RemoveCardFromHand(pelt);
pelt.SetEnabled(enabled: false);
pelt.Anim.SetTrigger("fly_off");
Tween.Position(pelt.transform, pelt.transform.position + new Vector3(0f, 3f, 5f), 0.4f, 0f, Tween.EaseInOut, Tween.LoopType.None, null, delegate
{
UnityObject.Destroy(pelt.gameObject);
});
card.UnassignFromSlot();
Tween.Position(card.transform, card.transform.position + new Vector3(0f, 0.25f, -5f), 0.3f, 0f, Tween.EaseInOut, Tween.LoopType.None, null, delegate
{
UnityObject.Destroy(card.gameObject);
});
__instance.StartCoroutine(TradeForTalkingCard(card));
slot.ClearDelegates();
slot.HighlightCursorType = CursorType.Default;
}

return false;
}

public static IEnumerator TradeForTalkingCard(PlayableCard card)
{
yield return Singleton<PlayerHand>.Instance.AddCardToHand(CardSpawner.SpawnPlayableCard(card.Info), new Vector3(0f, 0.5f, -3f), 0f);
ViewManager.Instance.SwitchToView(View.OpponentQueue);
ViewManager.Instance.Controller.SwitchToControlMode(ViewController.ControlMode.TraderCardsForPeltsPhase);
}
}

0 comments on commit 20bea46

Please sign in to comment.