diff --git a/HsMod/Languages/enUS.json b/HsMod/Languages/enUS.json index 9cd61855..eb803e70 100644 --- a/HsMod/Languages/enUS.json +++ b/HsMod/Languages/enUS.json @@ -354,5 +354,8 @@ "CardState.Disabled": "Disable special effects", "isAutoRedundantNDE.name": "Auto Replace Cards", "isAutoRedundantNDE.label": "Optimization", - "isAutoRedundantNDE.description": "Disable the card replacement window and automatically replace cards" + "isAutoRedundantNDE.description": "Disable the card replacement window and automatically replace cards", + "SaveCardTextures.name": "Card Art Export", + "SaveCardTextures.label": "Hearthstone", + "SaveCardTextures.description": "Save the card artwork locally and avoid enabling it during battles, as it may consume performance and cause lag. The artwork is stored in the path: \\Hearthstone\\CardTexturesDownload" } diff --git a/HsMod/Languages/zhCN.json b/HsMod/Languages/zhCN.json index cebc29c1..3804aaa9 100644 --- a/HsMod/Languages/zhCN.json +++ b/HsMod/Languages/zhCN.json @@ -354,5 +354,8 @@ "CardState.Disabled": "禁用特效", "isAutoRedundantNDE.name": "自动置换卡牌", "isAutoRedundantNDE.label": "优化", - "isAutoRedundantNDE.description": "屏蔽卡牌置换窗口并且自动置换" + "isAutoRedundantNDE.description": "屏蔽卡牌置换窗口并且自动置换", + "SaveCardTextures.name": "卡牌原画导出", + "SaveCardTextures.label": "炉石", + "SaveCardTextures.description": "卡牌原画保存到本地,尽量不要在对战中开启,会耗费一定性能导致卡顿,原画存放路径\\Hearthstone\\CardTexturesDownload" } diff --git a/HsMod/Main.cs b/HsMod/Main.cs index 8a4f4271..0e43753e 100644 --- a/HsMod/Main.cs +++ b/HsMod/Main.cs @@ -10,6 +10,8 @@ namespace HsMod [BepInPlugin(PluginInfo.PLUGIN_GUID, PluginInfo.PLUGIN_NAME, PluginInfo.PLUGIN_VERSION)] public class Plugin : BaseUnityPlugin { + public static Plugin Instance { get; private set; } + private void OnGUI() { if (UtilsArgu.Instance.Exists("hsunitid")) diff --git a/HsMod/Patcher.cs b/HsMod/Patcher.cs index 8c804623..8415be92 100644 --- a/HsMod/Patcher.cs +++ b/HsMod/Patcher.cs @@ -2021,7 +2021,21 @@ public static bool PatchNotifySceneLoadedWhenReady(Hub __instance) } return true; } - + [HarmonyPatch(typeof(Actor), "SetPortraitTexture")] + private static void PatchSetPortraitTexture(Actor __instance, ref Texture texture) + { + try + { + if (SaveCardTextures.Value) + { + Plugin.Instance.StartCoroutine(Utils.SaveLoadCardLocalTextures(__instance, texture)); + } + } + catch (Exception e) + { + Utils.MyLogger(BepInEx.Logging.LogLevel.Error, e); + } + } //// 生成Power.log //[HarmonyPrefix] //[HarmonyPatch(typeof(Log), "get_ConfigPath")] @@ -2077,22 +2091,31 @@ public static void PatchLogPathGetter(string __result) public class PatchFavorite { - // 尝试屏蔽对手的时尚小垃圾。 [HarmonyPrefix] - [HarmonyPatch(typeof(CutsceneManager), "LoadSceneIfNeeded")] - public static void PatchLoadSceneIfNeeded(ref CutsceneSceneDef sceneDef, ref bool forceLoad) + [HarmonyPatch(typeof(CornerSpellReplacementManager), "UpdateCornerReplacements")] + private static void PatchUpdateCornerReplacements(ref CornerReplacementContext friendlyNewContext) { - if (sceneDef != null) + try { if (skinPet.Value != -1) - sceneDef.SetupData.FriendlyPetSkinDbId = skinPet.Value; + { + Player playerBySide2 = GameState.Get()?.GetPlayerBySide(Player.Side.FRIENDLY); + playerBySide2?.SetTag(GAME_TAG.PET_VARIANT_ID, 0); + } + if (skinOpposingPet.Value != -1) - sceneDef.SetupData.OpponentPetSkinDbId = skinOpposingPet.Value; + { + Player playerBySide2 = GameState.Get()?.GetPlayerBySide(Player.Side.OPPOSING); + playerBySide2?.SetTag(GAME_TAG.PET_VARIANT_ID, 0); + } + } + catch (Exception ex) + { + Utils.MyLogger(BepInEx.Logging.LogLevel.Error, ex); } } - //加载处理 [HarmonyPrefix] [HarmonyPatch(typeof(Entity), "LoadCard")] diff --git a/HsMod/PluginConfig.cs b/HsMod/PluginConfig.cs index ef71b6f5..244eae61 100644 --- a/HsMod/PluginConfig.cs +++ b/HsMod/PluginConfig.cs @@ -63,7 +63,8 @@ public static class PluginConfig public static ConfigEntry isPatchAssetLoader; public static ConfigEntry shieldMainBoxLuckyDraw; - + // 卡牌原画导出 + public static ConfigEntry SaveCardTextures; public static ConfigEntry isOpponentGoldenCardShow; public static ConfigEntry isSignatureCardStateEnable; public static ConfigEntry goldenCardState; @@ -241,6 +242,7 @@ public static void ConfigBind(ConfigFile config) isBgsSeasonTicketUnlock = config.Bind(LocalizationManager.GetLangValue("isBgsSeasonTicketUnlock.label"), LocalizationManager.GetLangValue("isBgsSeasonTicketUnlock.name"), false, LocalizationManager.GetLangValue("isBgsSeasonTicketUnlock.description")); isPatchAssetLoader = config.Bind(LocalizationManager.GetLangValue("isPatchAssetLoader.label"), LocalizationManager.GetLangValue("isPatchAssetLoader.name"), false, LocalizationManager.GetLangValue("isPatchAssetLoader.description")); shieldMainBoxLuckyDraw = config.Bind(LocalizationManager.GetLangValue("shieldMainBoxLuckyDraw.label"), LocalizationManager.GetLangValue("shieldMainBoxLuckyDraw.name"), false, LocalizationManager.GetLangValue("shieldMainBoxLuckyDraw.description")); + SaveCardTextures = config.Bind(LocalizationManager.GetLangValue("SaveCardTextures.label"), LocalizationManager.GetLangValue("SaveCardTextures.name"), false, LocalizationManager.GetLangValue("SaveCardTextures.description")); //考虑导出单独配置 skinCoin = config.Bind(LocalizationManager.GetLangValue("skinCoin.label"), LocalizationManager.GetLangValue("skinCoin.name"), -1, LocalizationManager.GetLangValue("skinCoin.description")); skinCardBack = config.Bind(LocalizationManager.GetLangValue("skinCardBack.label"), LocalizationManager.GetLangValue("skinCardBack.name"), -1, LocalizationManager.GetLangValue("skinCardBack.description")); diff --git a/HsMod/PluginInfo.cs b/HsMod/PluginInfo.cs index 7f049709..63520a2f 100644 --- a/HsMod/PluginInfo.cs +++ b/HsMod/PluginInfo.cs @@ -5,6 +5,6 @@ internal class PluginInfo public const string PLUGIN_GUID = "HsMod"; public const string PLUGIN_NAME = "HsMod"; public const string PLUGIN_AUTHOR = "Pik_4"; - public const string PLUGIN_VERSION = "10.0.0.0"; + public const string PLUGIN_VERSION = "10.1.0.0"; } } diff --git a/HsMod/Utils.cs b/HsMod/Utils.cs index 68fd6319..77034db3 100644 --- a/HsMod/Utils.cs +++ b/HsMod/Utils.cs @@ -1,6 +1,7 @@ using BepInEx.Logging; using PegasusUtil; using System; +using System.Collections; using System.Collections.Generic; using System.ComponentModel; using System.Diagnostics; @@ -8,6 +9,7 @@ using System.Linq; using System.Reflection; using System.Text; +using UnityEngine; using static HsMod.PluginConfig; namespace HsMod @@ -1407,5 +1409,86 @@ public static void Skins() } } + + public static IEnumerator SaveLoadCardLocalTextures(Actor __instance, Texture texture) + { + try + { + if (null != texture) + { + string cardId = __instance?.GetEntityDef()?.GetCardId(); + + if (!string.IsNullOrEmpty(cardId)) + { + string cardName = __instance?.GetEntityDef()?.GetName(); + + string type = ""; + if (TAG_PREMIUM.SIGNATURE == __instance.GetPremium()) + { + type = "-SIGNATURE"; + } + + string filePath = Path.Combine( + Application.dataPath.Substring(0, Application.dataPath.LastIndexOf("/")), + "CardTexturesDownload", cardName + type + "-" + cardId + ".png"); + + if (File.Exists(filePath)) + { + yield break; + } + + RenderTexture rt = RenderTexture.GetTemporary( + texture.width, + texture.height, + 0, + RenderTextureFormat.ARGBFloat, + RenderTextureReadWrite.Linear, + 8, + RenderTextureMemoryless.None); + + Material copyMat = new Material(Shader.Find("Unlit/Texture")); + Graphics.Blit(texture, rt, copyMat); + UnityEngine.Object.Destroy(copyMat); + + RenderTexture previous = RenderTexture.active; + RenderTexture.active = rt; + + Texture2D readableTexture = new Texture2D( + texture.width, + texture.height, + TextureFormat.RGBAFloat, + false, + true); + + readableTexture.ReadPixels(new Rect(0, 0, rt.width, rt.height), 0, 0); + readableTexture.Apply(); + + RenderTexture.active = previous; + RenderTexture.ReleaseTemporary(rt); + + File.WriteAllBytes(filePath, readableTexture.EncodeToPNG()); + UnityEngine.Object.Destroy(readableTexture); + } + } + } + catch (Exception e) + { + if (!Directory.Exists(Path.Combine("CardTexturesDownload"))) + { + try + { + Directory.CreateDirectory(Path.Combine("CardTexturesDownload")); + } + catch (Exception e2) + { + MyLogger(LogLevel.Error, e2.Message); + } + } + + MyLogger(LogLevel.Error, e); + } + + yield break; + } } }