Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion HsMod/Languages/enUS.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
5 changes: 4 additions & 1 deletion HsMod/Languages/zhCN.json
Original file line number Diff line number Diff line change
Expand Up @@ -354,5 +354,8 @@
"CardState.Disabled": "禁用特效",
"isAutoRedundantNDE.name": "自动置换卡牌",
"isAutoRedundantNDE.label": "优化",
"isAutoRedundantNDE.description": "屏蔽卡牌置换窗口并且自动置换"
"isAutoRedundantNDE.description": "屏蔽卡牌置换窗口并且自动置换",
"SaveCardTextures.name": "卡牌原画导出",
"SaveCardTextures.label": "炉石",
"SaveCardTextures.description": "卡牌原画保存到本地,尽量不要在对战中开启,会耗费一定性能导致卡顿,原画存放路径\\Hearthstone\\CardTexturesDownload"
}
2 changes: 2 additions & 0 deletions HsMod/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down
39 changes: 31 additions & 8 deletions HsMod/Patcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down Expand Up @@ -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")]
Expand Down
4 changes: 3 additions & 1 deletion HsMod/PluginConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ public static class PluginConfig

public static ConfigEntry<bool> isPatchAssetLoader;
public static ConfigEntry<bool> shieldMainBoxLuckyDraw;

// 卡牌原画导出
public static ConfigEntry<bool> SaveCardTextures;
public static ConfigEntry<bool> isOpponentGoldenCardShow;
public static ConfigEntry<bool> isSignatureCardStateEnable;
public static ConfigEntry<Utils.CardState> goldenCardState;
Expand Down Expand Up @@ -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"));
Expand Down
2 changes: 1 addition & 1 deletion HsMod/PluginInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
}
83 changes: 83 additions & 0 deletions HsMod/Utils.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
using BepInEx.Logging;
using PegasusUtil;
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using UnityEngine;
using static HsMod.PluginConfig;

namespace HsMod
Expand Down Expand Up @@ -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;
}
}
}