Skip to content

Commit

Permalink
feat: Add HeroDeckShow
Browse files Browse the repository at this point in the history
  • Loading branch information
Cherrysaber committed Oct 4, 2022
1 parent 73f4d9a commit abb781e
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 0 deletions.
28 changes: 28 additions & 0 deletions HeroDeckShow/HeroDeckShow.csproj
@@ -0,0 +1,28 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net48</TargetFramework>
<AssemblyName>HeroDeckShow</AssemblyName>
<Description>My first plugin</Description>
<Version>1.0.0</Version>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<LangVersion>latest</LangVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="BepInEx.Analyzers" Version="1.*" PrivateAssets="all" />
<PackageReference Include="BepInEx.Core" Version="5.*" />
<PackageReference Include="BepInEx.PluginInfoProps" Version="1.*" />
<PackageReference Include="UnityEngine.Modules" Version="2021.2.14" IncludeAssets="compile" />
</ItemGroup>

<ItemGroup>
<Reference Include="Assembly-CSharp">
<HintPath>../libs/Assembly-CSharp.dll</HintPath>
</Reference>
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework.TrimEnd(`0123456789`))' == 'net'">
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.2" PrivateAssets="all" />
</ItemGroup>
</Project>
6 changes: 6 additions & 0 deletions HeroDeckShow/NuGet.Config
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="BepInEx" value="https://nuget.bepinex.dev/v3/index.json" />
</packageSources>
</configuration>
52 changes: 52 additions & 0 deletions HeroDeckShow/Plugin.cs
@@ -0,0 +1,52 @@
using BepInEx;
using HarmonyLib;

namespace HeroDeckShow
{
[BepInPlugin(PluginInfo.PLUGIN_GUID, PluginInfo.PLUGIN_NAME, PluginInfo.PLUGIN_VERSION)]
public class Plugin : BaseUnityPlugin
{
private void Awake()
{
// Plugin startup logic
Logger.LogInfo($"Plugin {PluginInfo.PLUGIN_GUID} is loaded!");

Harmony.CreateAndPatchAll(typeof(Plugin));
}

[HarmonyPatch(typeof(DeckWindowUI), "SetCombatCard")]
[HarmonyPrefix]
public static bool SetCombatCardPrefix(DeckWindowUI __instance, Hero hero,ref string cardId, int position, int total){
var heroIndex = GetHeroIndex(hero);
var heroDeck = MatchManager.Instance.GetHeroDeck(heroIndex);

// 抽牌时查看牌堆顺序, 不是线程安全的
// position 可能会超出牌堆数量
if (position < heroDeck.Count)
{
cardId = heroDeck[position];
}
return true;
}


public static int GetHeroIndex(Hero target){
var hero = AtOManager.Instance.GetHero(0);
if (hero == target){
return 0;
}

hero = AtOManager.Instance.GetHero(1);
if (hero == target){
return 1;
}

hero = AtOManager.Instance.GetHero(2);
if (hero == target){
return 2;
}

return 3;
}
}
}
Binary file added libs/Assembly-CSharp.dll
Binary file not shown.

0 comments on commit abb781e

Please sign in to comment.