Skip to content

Commit

Permalink
opt
Browse files Browse the repository at this point in the history
  • Loading branch information
Pik-4 committed Dec 22, 2024
1 parent 8efad31 commit afaeda4
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 18 deletions.
8 changes: 7 additions & 1 deletion HsMod/Main.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using BepInEx;
using System;
using System.Diagnostics;
using System.Linq;
using UnityEngine;
using static HsMod.PluginConfig;
Expand Down Expand Up @@ -159,6 +158,13 @@ private void Start()

private void Update()
{
// todo: check game status
if ((autoQuitTimer.Value > 0) && (ConfigValue.Get().RunningTime >= (autoQuitTimer.Value + 1145)))
{
Utils.MyLogger(BepInEx.Logging.LogLevel.Warning, "Force Auto Quit...");
Utils.Quit();
}

if (Input.GetKeyUp(KeyCode.F4))
{
int allPatchNum = 0;
Expand Down
20 changes: 6 additions & 14 deletions HsMod/Patcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
Expand Down Expand Up @@ -53,7 +52,7 @@ public static void LoadPatch(Type loadType)
Utils.MyLogger(BepInEx.Logging.LogLevel.Error, $"{loadType.Name} => {ex.Message} \n{ex.InnerException}");
Utils.MyLogger(BepInEx.Logging.LogLevel.Error, "HsMod patch failed!");
System.Threading.Thread.Sleep(11451);
Application.Quit(114514);
Utils.Quit(114514);
}
}

Expand Down Expand Up @@ -518,7 +517,7 @@ public static bool PatchError()
{
if (isAutoExit.Value)
{
Application.Quit();
Utils.Quit();
return false;
}
else return true;
Expand Down Expand Up @@ -1761,7 +1760,7 @@ public static void PatchEndGameScreenShow(ref TAG_PLAYSTATE playState, ref Spell
}
else
{
switch (GameState.Get().GetFriendlySidePlayer().GetHero().GetRealTimePlayerLeaderboardPlace())
switch (GameState.Get()?.GetFriendlySidePlayer()?.GetHero()?.GetRealTimePlayerLeaderboardPlace())
{
case 1: finalResult = "第一名"; break;
case 2: finalResult = "第二名"; break;
Expand Down Expand Up @@ -1792,7 +1791,8 @@ public static void PatchEndGameScreenShow(ref TAG_PLAYSTATE playState, ref Spell
gameRank = BaconLobbyMgr.Get()?.GetBattlegroundsActiveGameModeRating().ToString();
}
finalResult = $"{String.Join("<br />", DateTime.Now.ToString().Split(' '))},{finalResult},{gameRank},{gameType},{Utils.CacheLastOpponentFullName},";
finalResult += $"High:{Utils.CacheLastOpponentAccountID.High}+Low:{Utils.CacheLastOpponentAccountID.Low}";
//finalResult += $"High:{Utils.CacheLastOpponentAccountID.High}+Low:{Utils.CacheLastOpponentAccountID.Low}";
finalResult += $"Opponent: {Utils.CacheLastOpponentAccountID.Low}, MyPlayer: {BnetPresenceMgr.Get()?.GetMyPlayer()?.GetBestName()?.ToString()}";
if (isAutoReportEnable.Value)
{
finalResult += " => 已举报";
Expand All @@ -1812,15 +1812,7 @@ public static void PatchEndGameScreenShow(ref TAG_PLAYSTATE playState, ref Spell
if (autoQuitTimer.Value > 0 && ConfigValue.Get().RunningTime >= autoQuitTimer.Value)
{
Utils.MyLogger(BepInEx.Logging.LogLevel.Warning, "定时重启!即将退出游戏...");
try
{
Application.Quit();
}
finally
{
System.Threading.Thread.Sleep(11451);
Process.GetCurrentProcess().Kill();
}
Utils.Quit();
}
}

Expand Down
14 changes: 14 additions & 0 deletions HsMod/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
Expand Down Expand Up @@ -1041,6 +1042,19 @@ public static void OnHsLoginCompleted()
}
}

public static void Quit(int exitCode = 0)
{
try
{
UnityEngine.Application.Quit(exitCode);
}
finally
{
System.Threading.Thread.Sleep(11451);
Process.GetCurrentProcess().Kill();
}
}

public static class LeakInfo
{
public static void Mercenaries()
Expand Down
5 changes: 3 additions & 2 deletions HsMod/WebApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ public class WebApi

public static async Task<string> RunShellCommandAsync(string command)
{
if (!isWebshellEnable.Value) {
if (!isWebshellEnable.Value)
{
return string.Empty;
}

var processInfo = new ProcessStartInfo
{
CreateNoWindow = true,
Expand Down
2 changes: 1 addition & 1 deletion HsMod/WebPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ private static string GenerateBtn()
btn += @"<a href=""/lettuce""><button class=""btn_li"">佣兵关卡</button><br/></a><br />";
btn += @"<a href=""/mercenaries""><button class=""btn_li"">佣兵收藏</button><br/></a><br />";
if (System.IO.File.Exists(CommandConfig.hsMatchLogPath)) btn += @"<a href=""/matchlog""><button class=""btn_li"">炉石对局</button><br/></a><br />";
btn += @"<a href=""/config/index.html""><button class=""btn_li"">配置修改</button><br/></a><br />";
if (Directory.Exists(Path.Combine(PluginConfig.HsModWebSite, "config", "index.html"))) btn += @"<a href=""/config/index.html""><button class=""btn_li"">配置修改</button><br/></a><br />";
btn += @"<a href=""/about""><button class=""btn_li"">关&emsp;&emsp;于</button><br/></a><br />";
return btn;
}
Expand Down

0 comments on commit afaeda4

Please sign in to comment.