Skip to content

Commit 3def2c2

Browse files
committed
SteelTrapDeathPatch
* Implements the SteelTrapDeathPatch, which is made by Snowi and SpecialAPI. * Change to `netframework4.7.2` (closer to the Runtime netframework.) * Better NoWarns * Implement `GetSteelTrapPelt` and `SetSteelTrapPelt` card extensions * Upgrade to API 2.24.0 * Add a Test Case related to the new patch. * Update README and CHANGELOG
1 parent c2c1d85 commit 3def2c2

10 files changed

Lines changed: 231 additions & 10 deletions

File tree

APIPatcher/APIPatcher.csproj

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>netstandard2.0</TargetFramework>
4+
<TargetFramework>netframework4.7.2</TargetFramework>
55
<ImplicitUsings>enable</ImplicitUsings>
66
<Nullable>disable</Nullable>
77
<LangVersion>latest</LangVersion>
88
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
99
<TargetName>Assembly-CSharp.APIPatcher.mm</TargetName>
1010
</PropertyGroup>
1111

12+
<PropertyGroup>
13+
<NoWarn>$(NoWarn);AD0001;CS0612;CS0618;Publicizer001</NoWarn>
14+
</PropertyGroup>
15+
1216
<ItemGroup>
1317
<PackageReference Include="BepInEx.BaseLib" Version="5.4.19" />
1418
<PackageReference Include="Inscryption.GameLibs" Version="1.9.0-r.0" />
@@ -19,5 +23,4 @@
1923
<ItemGroup>
2024
<ProjectReference Private="false" Include="..\InscryptionAPI\InscryptionAPI.csproj" />
2125
</ItemGroup>
22-
2326
</Project>

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
# 2.24.0
2+
* Implements the SteelTrapDeathPatch, which is made by Snowi and SpecialAPI.
3+
* Change to `netframework4.7.2` (closer to the Runtime netframework.)
4+
* Better NoWarns
5+
* Implement `GetSteelTrapPelt` and `SetSteelTrapPelt` card extensions
6+
* Upgrade to API 2.24.0
7+
* Add a Test Case related to the new patch.
8+
19
# 2.23.7
210
- Fixed log spam due to inverted condition in CardExtensions.GemsCost
311

InscryptionAPI/Card/CardExtensionsProperties.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,4 +243,32 @@ public static List<FullCardCost> GetCustomCosts(this CardInfo info)
243243
}
244244

245245
#endregion
246+
247+
#region SteelTrapPelt
248+
/// <summary>
249+
/// Set the Pelt that should be given when this card is slain by a trap.
250+
/// </summary>
251+
/// <param name="card">The Card this is being applied to.</param>
252+
/// <param name="peltName">The Card to be given to the Player on Death by Trap</param>
253+
public static void SetSteelTrapPelt(this PlayableCard card, string peltName) => SetSteelTrapPelt(card.Info, peltName);
254+
/// <summary>
255+
/// Get the Pelt that should be given when this card is slain by a trap.
256+
/// </summary>
257+
/// <param name="card">The Card this is being applied to.</param>
258+
/// <returns>A string representing the Pelt that should be returned.</returns>
259+
public static string GetSteelTrapPelt(this PlayableCard card) => GetSteelTrapPelt(card.Info);
260+
/// <summary>
261+
/// Set the Pelt that should be given when this card is slain by a trap.
262+
/// </summary>
263+
/// <param name="cardInfo">The CardInfo this is being applied to.</param>
264+
/// <param name="peltName">The Card to be given to the Player on Death by Trap</param>
265+
public static void SetSteelTrapPelt(this CardInfo cardInfo, string peltName) => cardInfo.SetExtendedProperty("SteelTrapPelt", peltName);
266+
/// <summary>
267+
/// Get the Pelt that should be given when this card is slain by a trap.
268+
/// </summary>
269+
/// <param name="cardInfo">The CardInfo this is being applied to.</param>
270+
/// <returns>A string representing the Pelt that should be returned.</returns>
271+
public static string GetSteelTrapPelt(this CardInfo cardInfo) => cardInfo.GetExtendedProperty("SteelTrapPelt");
272+
273+
#endregion
246274
}
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
using System.Collections;
2+
using DiskCardGame;
3+
using HarmonyLib;
4+
using Mono.Cecil.Cil;
5+
using MonoMod.Cil;
6+
using UnityEngine;
7+
8+
namespace InscryptionAPI.Card;
9+
10+
/// <summary>
11+
/// Patches the Steal Trap Death system to drop a differed pelt on the case the opposing card has the "SteelTrapPelt" extended property.
12+
/// </summary>
13+
/// <remarks>This code is provided by Snowi, and SpecialAPI.</remarks>
14+
[HarmonyPatch]
15+
internal static class SteelTrapDeathPatch
16+
{
17+
/// <summary>
18+
/// A Transpiler that patches in two functions into the SteelTrap.OnDie function.
19+
/// </summary>
20+
/// <param name="ctx">The ILContext at the time its being called.</param>
21+
/// <remarks>This code is provided by Snowi, and SpecialAPI.</remarks>
22+
[HarmonyPatch(typeof(SteelTrap), nameof(SteelTrap.OnDie), MethodType.Enumerator)]
23+
[HarmonyILManipulator]
24+
private static void CustomSteelTrapPelts_Transpiler(ILContext ctx)
25+
{
26+
var crs = new ILCursor(ctx);
27+
28+
if (!crs.TryGotoNext(MoveType.Before, x => x.MatchCallOrCallvirt<AbilityBehaviour>(nameof(AbilityBehaviour.PreSuccessfulTriggerSequence))))
29+
return;
30+
31+
// curr: IEnumerator
32+
crs.Emit(OpCodes.Ldloc_1); // SteelTrap
33+
crs.Emit(OpCodes.Call, AccessTools.Method(typeof(SteelTrapDeathPatch), nameof(CustomSteelTrapPelts_SetDyingCard))); // ret: void
34+
35+
if (!crs.TryGotoNext(MoveType.After, x => x.MatchCallOrCallvirt<DrawCreatedCard>(nameof(DrawCreatedCard.CreateDrawnCard))))
36+
return;
37+
38+
// curr: IEnumerator
39+
crs.Emit(OpCodes.Ldloc_1); // SteelTrap
40+
crs.Emit(OpCodes.Call, AccessTools.Method(typeof(SteelTrapDeathPatch), nameof(CustomSteelTrapPelts_CustomDrawCard))); // ret: IEnumerator
41+
}
42+
43+
/// <summary>
44+
/// A function which sets the dying card.
45+
/// </summary>
46+
/// <param name="trap">The SteelTrap ability.</param>
47+
/// <remarks>This code is provided by Snowi, and SpecialAPI.</remarks>
48+
private static void CustomSteelTrapPelts_SetDyingCard(SteelTrap trap)
49+
{
50+
var holder = trap.GetComponent<DyingCardHolder>();
51+
if (holder == null)
52+
holder = trap.gameObject.AddComponent<DyingCardHolder>();
53+
54+
holder.dyingCard = trap?.Card?.Slot?.opposingSlot?.Card?.Info;
55+
}
56+
57+
/// <summary>
58+
/// The functionality that allows you to get a differed card when a Trap dies, and the current card is the one that perished via "SteelTrapPelt".
59+
/// </summary>
60+
/// <param name="orig">The IEnumerator origin.</param>
61+
/// <param name="trap">The Steel Trap Ability</param>
62+
/// <returns>Either the default Wolf Pelt or a custom card if the card that died had a value set for "SteelTrapPelt".</returns>
63+
/// <remarks>This code is provided by Snowi, and SpecialAPI.</remarks>
64+
private static IEnumerator CustomSteelTrapPelts_CustomDrawCard(IEnumerator orig, SteelTrap trap)
65+
{
66+
var holder = trap.GetComponent<DyingCardHolder>();
67+
if (holder == null || holder.dyingCard == null)
68+
{
69+
yield return orig;
70+
yield break;
71+
}
72+
73+
var peltName = holder.dyingCard.GetSteelTrapPelt();
74+
if (string.IsNullOrEmpty(peltName))
75+
{
76+
yield return orig;
77+
yield break;
78+
}
79+
80+
yield return new WaitForSeconds(0.5f);
81+
if (Singleton<ViewManager>.Instance.CurrentView != View.Default)
82+
{
83+
yield return new WaitForSeconds(0.2f);
84+
Singleton<ViewManager>.Instance.SwitchToView(View.Default);
85+
yield return new WaitForSeconds(0.2f);
86+
}
87+
88+
var cardToDraw = CardLoader.GetCardByName(peltName);
89+
yield return Singleton<CardSpawner>.Instance.SpawnCardToHand(cardToDraw, null);
90+
yield return new WaitForSeconds(0.45f);
91+
}
92+
93+
/// <summary>
94+
/// The Holder of the dyingCard.
95+
/// </summary>
96+
/// <remarks>This code is provided by Snowi, and SpecialAPI.</remarks>
97+
private class DyingCardHolder : MonoBehaviour
98+
{
99+
public CardInfo dyingCard;
100+
}
101+
}

InscryptionAPI/InscryptionAPI.csproj

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>netstandard2.0</TargetFramework>
4+
<TargetFramework>netframework4.7.2</TargetFramework>
55
<ImplicitUsings>enable</ImplicitUsings>
66
<Nullable>disable</Nullable>
77
<IsPackable>false</IsPackable>
@@ -14,7 +14,7 @@
1414
</PropertyGroup>
1515

1616
<PropertyGroup>
17-
<NoWarn>Publicizer001</NoWarn>
17+
<NoWarn>$(NoWarn);AD0001;CS0612;CS0618;Publicizer001</NoWarn>
1818
</PropertyGroup>
1919

2020
<ItemGroup>
@@ -40,5 +40,4 @@
4040
<PackageReference Include="Inscryption.GameLibs" Version="1.9.0-r.0" />
4141
<PackageReference Include="UnityEngine.Modules" Version="2019.4.24" />
4242
</ItemGroup>
43-
4443
</Project>

InscryptionAPI/InscryptionAPIPlugin.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public class InscryptionAPIPlugin : BaseUnityPlugin
3131
{
3232
public const string ModGUID = "cyantist.inscryption.api";
3333
public const string ModName = "InscryptionAPI";
34-
public const string ModVer = "2.23.7";
34+
public const string ModVer = "2.24.0";
3535

3636
public static string Directory = "";
3737

InscryptionCommunityPatch/InscryptionCommunityPatch.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>netstandard2.0</TargetFramework>
4+
<TargetFramework>netframework4.7.2</TargetFramework>
55
<ImplicitUsings>enable</ImplicitUsings>
66
<Nullable>disable</Nullable>
77
<IsPackable>false</IsPackable>
@@ -13,7 +13,7 @@
1313
</PropertyGroup>
1414

1515
<PropertyGroup>
16-
<NoWarn>Publicizer001</NoWarn>
16+
<NoWarn>$(NoWarn);AD0001;CS0612;CS0618;Publicizer001</NoWarn>
1717
</PropertyGroup>
1818

1919
<ItemGroup>

InscryptionCommunityPatch/InscryptionCommunityPatchPlugin.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public class PatchPlugin : BaseUnityPlugin
2020
{
2121
public const string ModGUID = "community.inscryption.patch";
2222
public const string ModName = "InscryptionCommunityPatch";
23-
public const string ModVer = "1.0.0";
23+
public const string ModVer = "2.24.0";
2424

2525
internal static PatchPlugin Instance;
2626

@@ -74,6 +74,7 @@ private void OnEnable()
7474
{
7575
ExecuteCommunityPatchTests.PrepareForTests();
7676
TestCost.Init();
77+
DebugCards.CreateTestCards();
7778
}
7879

7980
CommunityArtPatches.PatchCommunityArt();
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
using DiskCardGame;
2+
using InscryptionAPI.Card;
3+
using InscryptionAPI.Guid;
4+
5+
namespace InscryptionCommunityPatch.Tests;
6+
7+
public class DebugCards
8+
{
9+
/// <summary>
10+
/// This is an instantiator for a Test Case related to the Steel Trap Death Patch.
11+
/// </summary>
12+
/// <remarks>This code is provided by Creator/Chaosyr/SaxbyMod/The Stoat Lord.</remarks>
13+
public static void CreateTestCards()
14+
{
15+
CardInfo TestPelt = CreateCardUtil.CreateCard("Test_Pelt", "Test Pelt", 0, 4, new List<Tribe>() { Tribe.Canine });
16+
CardInfo Debugger = CreateCardUtil.CreateCard("Debugger", "This is a Debugger", 0, 2, new List<Tribe>() { Tribe.None });
17+
CardInfo Debugger2 = CreateCardUtil.CreateCard("Debugger", "This is a Debugger", 0, 2, new List<Tribe>() { Tribe.None });
18+
Debugger2.SetExtendedProperty("SteelTrapPelt", PatchPlugin.ModGUID + "_Test_Pelt");
19+
Debugger.AddAbilities(Ability.SteelTrap);
20+
}
21+
22+
/// <summary>
23+
/// A Utility for Creating Cards (this is for debug purposes only, so we're tossing a OBSOLETE to be safe.
24+
/// </summary>
25+
/// <remarks>This code is provided by JamesGames.</remarks>
26+
[Obsolete("DO NOT USE THIS, THIS IS FOR DEBUGGING ONLY.")]
27+
private class CreateCardUtil
28+
{
29+
// Code from JamesGames
30+
public static CardInfo CreateCard(string name, string displayName, int attack, int health, List<Tribe> tribe)
31+
{
32+
CardInfo info = CardManager.New(PatchPlugin.ModGUID, name, displayName, attack, health);
33+
info.cardComplexity = CardComplexity.Simple;
34+
info.AddTraits(Trait.Pelt);
35+
foreach (Tribe currentTribe in tribe)
36+
{
37+
if (currentTribe != Tribe.None)
38+
{
39+
info.AddTribes(currentTribe);
40+
}
41+
}
42+
info.temple = CardTemple.Nature;
43+
info.AddSpecialAbilities(SpecialTriggeredAbility.SpawnLice);
44+
info.AddAppearances(CardAppearanceBehaviour.Appearance.TerrainBackground, CardAppearanceBehaviour.Appearance.TerrainLayout);
45+
46+
return info;
47+
}
48+
}
49+
50+
/// <summary>
51+
/// A Utility for Creating Rare Cards (this is for debug purposes only, so we're tossing a OBSOLETE to be safe.
52+
/// </summary>
53+
/// <remarks>This code is provided by JamesGames.</remarks>
54+
[Obsolete("DO NOT USE THIS, THIS IS FOR DEBUGGING ONLY.")]
55+
private class CreateRareCardUtil
56+
{
57+
// Code from JamesGames
58+
public static CardInfo CreateRareCard(string name, string displayName, int attack, int health, List<Tribe> tribe)
59+
{
60+
CardInfo info = CreateCardUtil.CreateCard(name, displayName, attack, health, tribe);
61+
info.AddAppearances(CardAppearanceBehaviour.Appearance.GoldEmission);
62+
63+
return info;
64+
}
65+
}
66+
67+
/// <summary>
68+
/// A Utility for Fetching Tribes (this is for debug purposes only, so we're tossing a OBSOLETE to be safe.
69+
/// </summary>
70+
/// <remarks>This code is provided by LilySylvee.</remarks>
71+
[Obsolete("DO NOT USE THIS, THIS IS FOR DEBUGGING ONLY.")]
72+
private class GetCustomTribeUtil
73+
{
74+
// Code from Lily
75+
public static Tribe GetCustomTribe(string GUID, string name)
76+
{
77+
return GuidManager.GetEnumValue<Tribe>(GUID, name);
78+
}
79+
}
80+
}

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,4 +263,5 @@ Contributors and builders of API 2.0:
263263
- WhistleWind
264264
- Windows10CE
265265
- Keks307
266-
- ThinCreator3483
266+
- Creator/Chaosyr/SaxbyMod/The Stoat Lord/ThinCreator3483
267+
- stillrinny

0 commit comments

Comments
 (0)