using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("GameTweaks")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.3")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("GameTweaks")]
[assembly: AssemblyTitle("GameTweaks")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.3.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
internal sealed class RefSafetyRulesAttribute : Attribute
{
public readonly int Version;
public RefSafetyRulesAttribute(int P_0)
{
Version = P_0;
}
}
}
namespace GameTweaks
{
[BepInPlugin("Mhz.PeakGameTweaks", "GameTweaks", "1.0.3")]
[BepInProcess("PEAK.exe")]
public class GameTweaksMod : BaseUnityPlugin
{
[HarmonyPatch(typeof(Vector3), "Lerp")]
public static class Vector3LerpPatch
{
private static bool Prepare()
{
return _enableCameraTweaks.Value;
}
private static void Prefix(ref float t)
{
if (!InCharacterCam)
{
return;
}
float num = Time.deltaTime * 5f;
if (Math.Abs(t - num) < 0.05f)
{
t *= _cameraLerpRate.Value / 5f;
if (_debugMode.Value && ++_debugLogCounter >= 500)
{
_debugLogCounter = 0;
SafeLog($"✓ 优化摄像头跟随 (倍数={_cameraLerpRate.Value / 5f:F2})", (LogLevel)16);
}
}
}
}
[HarmonyPatch(typeof(Quaternion), "Lerp")]
public static class QuaternionLerpPatch
{
private static bool Prepare()
{
return _enableCameraTweaks.Value;
}
private static void Prefix(ref float t)
{
if (InCharacterCam)
{
float num = Time.deltaTime * 10f;
if (Math.Abs(t - num) < 0.001f)
{
t *= 1f - _physicsInfluenceReduction.Value * 0.3f;
}
else if (t > 0.01f)
{
t *= 1f - _physicsInfluenceReduction.Value;
}
if (_debugMode.Value && ++_debugLogCounter >= 1000)
{
_debugLogCounter = 0;
SafeLog($"✓ 减少摄像头晃动 (程度={_physicsInfluenceReduction.Value:F2})", (LogLevel)16);
}
}
}
}
private static ConfigEntry<bool> _debugMode;
private static ConfigEntry<bool> _enableCameraTweaks;
private static ConfigEntry<float> _cameraLerpRate;
private static ConfigEntry<float> _physicsInfluenceReduction;
private static ConfigEntry<bool> _enablePauseFeature;
private static ConfigEntry<KeyCode> _pauseKey;
private static ConfigEntry<bool> _pauseAudio;
private static ConfigEntry<bool> _enablePersistentEmote;
private static ConfigEntry<KeyCode> _emoteStopKey;
private static ManualLogSource _logger;
private Harmony _harmony;
private const float ORIGINAL_CAMERA_LERP_RATE = 5f;
private const float ORIGINAL_PHYSICS_LERP_RATE = 10f;
private static int _debugLogCounter;
public static bool InCharacterCam { get; private set; }
private void Awake()
{
//IL_0019: Unknown result type (might be due to invalid IL or missing references)
//IL_0023: Expected O, but got Unknown
//IL_005b: Unknown result type (might be due to invalid IL or missing references)
//IL_0074: Unknown result type (might be due to invalid IL or missing references)
//IL_0081: Expected O, but got Unknown
//IL_0081: Expected O, but got Unknown
_logger = ((BaseUnityPlugin)this).Logger;
InitializeConfig();
_harmony = new Harmony("Mhz.PeakGameTweaks");
if (_enableCameraTweaks.Value)
{
_harmony.Patch((MethodBase)AccessTools.Method("MainCameraMovement:CharacterCam", (Type[])null, (Type[])null), new HarmonyMethod(typeof(GameTweaksMod).GetMethod("CharacterCam_Prefix")), new HarmonyMethod(typeof(GameTweaksMod).GetMethod("CharacterCam_Postfix")), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
_harmony.PatchAll(typeof(Vector3LerpPatch));
_harmony.PatchAll(typeof(QuaternionLerpPatch));
SafeLog("✓ 摄像头优化补丁已应用", (LogLevel)16);
}
if (_enablePauseFeature.Value)
{
_harmony.PatchAll(typeof(GUIManager_LateUpdate_Patch));
SafeLog("✓ 暂停功能补丁已应用", (LogLevel)16);
}
if (_enablePersistentEmote.Value)
{
_harmony.PatchAll(typeof(CharacterAnimations_Update_Patch));
_harmony.PatchAll(typeof(CharacterAnimations_PlayEmote_Patch));
SafeLog("✓ 持续表情功能补丁已应用", (LogLevel)16);
}
SafeLog("=== GameTweaks 已加载 ===", (LogLevel)16);
}
private void Start()
{
//IL_0015: Unknown result type (might be due to invalid IL or missing references)
//IL_005b: Unknown result type (might be due to invalid IL or missing references)
if (_enablePauseFeature.Value)
{
PauseManager.Initialize(_pauseKey.Value, _pauseAudio.Value, _debugMode.Value, _logger);
SafeLog("✓ 暂停管理器已初始化", (LogLevel)16);
}
if (_enablePersistentEmote.Value)
{
PersistentEmoteManager.Initialize(_emoteStopKey.Value, _debugMode.Value, _logger);
SafeLog("✓ 持续表情管理器已初始化", (LogLevel)16);
}
}
private void OnDestroy()
{
Harmony harmony = _harmony;
if (harmony != null)
{
harmony.UnpatchSelf();
}
}
private static void SafeLog(string message, LogLevel level = 16)
{
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
try
{
if (_logger != null)
{
_logger.Log(level, (object)message);
}
else
{
Debug.Log((object)("[GameTweaks] " + message));
}
}
catch
{
Debug.Log((object)("[GameTweaks] " + message));
}
}
private void InitializeConfig()
{
//IL_001d: Unknown result type (might be due to invalid IL or missing references)
//IL_0027: Expected O, but got Unknown
//IL_0048: Unknown result type (might be due to invalid IL or missing references)
//IL_0052: Expected O, but got Unknown
//IL_0085: Unknown result type (might be due to invalid IL or missing references)
//IL_008f: Expected O, but got Unknown
//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
//IL_00cc: Expected O, but got Unknown
//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
//IL_00f7: Expected O, but got Unknown
//IL_0119: Unknown result type (might be due to invalid IL or missing references)
//IL_0123: Expected O, but got Unknown
//IL_0144: Unknown result type (might be due to invalid IL or missing references)
//IL_014e: Expected O, but got Unknown
//IL_016f: Unknown result type (might be due to invalid IL or missing references)
//IL_0179: Expected O, but got Unknown
//IL_019e: Unknown result type (might be due to invalid IL or missing references)
//IL_01a8: Expected O, but got Unknown
_debugMode = ((BaseUnityPlugin)this).Config.Bind<bool>("Debug | 调试设置", "Debug Mode | 调试模式", false, new ConfigDescription("Show debug information | 显示调试信息", (AcceptableValueBase)null, Array.Empty<object>()));
_enableCameraTweaks = ((BaseUnityPlugin)this).Config.Bind<bool>("Camera | 摄像头设置", "Enable Tweaks | 启用摄像头优化", true, new ConfigDescription("Enable camera optimization features | 启用摄像头优化功能", (AcceptableValueBase)null, Array.Empty<object>()));
_cameraLerpRate = ((BaseUnityPlugin)this).Config.Bind<float>("Camera | 摄像头设置", "Camera Follow Speed | 摄像头跟随速率", 15f, new ConfigDescription("Camera position follow rate (Default: 15, Recommended: 10-20) | 摄像头位置跟随速率 (默认: 15, 推荐: 10-20)", (AcceptableValueBase)(object)new AcceptableValueRange<float>(5f, 30f), Array.Empty<object>()));
_physicsInfluenceReduction = ((BaseUnityPlugin)this).Config.Bind<float>("Camera | 摄像头设置", "Reduce Shake | 减少晃动", 1f, new ConfigDescription("Reduce camera shake (0=No reduction, 1=Complete elimination) | 减少摄像头晃动 (0=无减少, 1=完全消除)", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>()));
_enablePauseFeature = ((BaseUnityPlugin)this).Config.Bind<bool>("Pause | 暂停功能", "Enable Pause Feature | 启用暂停功能", true, new ConfigDescription("Enable real game pause functionality | 启用真正的游戏暂停功能", (AcceptableValueBase)null, Array.Empty<object>()));
_pauseKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Pause | 暂停功能", "Pause Key | 暂停按键", (KeyCode)112, new ConfigDescription("Key to pause/unpause the game | 暂停/恢复游戏的按键", (AcceptableValueBase)null, Array.Empty<object>()));
_pauseAudio = ((BaseUnityPlugin)this).Config.Bind<bool>("Pause | 暂停功能", "Pause Audio | 暂停音频", true, new ConfigDescription("Also pause audio when game is paused | 暂停游戏时也暂停音频", (AcceptableValueBase)null, Array.Empty<object>()));
_enablePersistentEmote = ((BaseUnityPlugin)this).Config.Bind<bool>("Emote | 持续表情", "Enable Persistent Emote | 启用持续表情功能", false, new ConfigDescription("Enable persistent emote functionality | 启用持续表情功能", (AcceptableValueBase)null, Array.Empty<object>()));
_emoteStopKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Emote | 持续表情", "Emote Stop Key | 停止表情按键", (KeyCode)284, new ConfigDescription("Key to stop the current emote | 停止当前表情的按键", (AcceptableValueBase)null, Array.Empty<object>()));
}
public static void CharacterCam_Prefix()
{
if (_enableCameraTweaks.Value)
{
InCharacterCam = true;
}
}
public static void CharacterCam_Postfix()
{
InCharacterCam = false;
}
}
public static class PluginInfo
{
public const string PLUGIN_GUID = "Mhz.PeakGameTweaks";
public const string PLUGIN_NAME = "GameTweaks";
public const string PLUGIN_VERSION = "1.0.3";
}
public static class PauseManager
{
private static bool _isPaused = false;
private static KeyCode _pauseKey = (KeyCode)112;
private static bool _pauseAudio = true;
private static bool _debugMode = false;
private static float _originalAudioVolume = 1f;
private static bool _wasKeyPressed = false;
private static ManualLogSource _logger;
public static bool IsPaused => _isPaused;
public static void Initialize(KeyCode pauseKey, bool pauseAudio, bool debugMode, ManualLogSource logger)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
_pauseKey = pauseKey;
_pauseAudio = pauseAudio;
_debugMode = debugMode;
_logger = logger;
}
public static void HandleCustomPauseInput(GUIManager guiManager)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
try
{
bool key = Input.GetKey(_pauseKey);
if (key && !_wasKeyPressed && ((Object)(object)Character.localCharacter != (Object)null || !PhotonNetwork.InRoom) && (Object)(object)guiManager != (Object)null && !guiManager.windowBlockingInput)
{
if (IsSinglePlayerMode())
{
TogglePause();
}
else if (_debugMode)
{
ManualLogSource logger = _logger;
if (logger != null)
{
logger.LogInfo((object)"多人游戏中不允许暂停游戏");
}
}
}
_wasKeyPressed = key;
}
catch (Exception ex)
{
ManualLogSource logger2 = _logger;
if (logger2 != null)
{
logger2.LogError((object)("处理暂停输入时出错: " + ex.Message));
}
}
}
private static bool IsSinglePlayerMode()
{
try
{
if (PhotonNetwork.OfflineMode)
{
if (_debugMode)
{
ManualLogSource logger = _logger;
if (logger != null)
{
logger.LogInfo((object)"检测到离线单人模式,允许暂停");
}
}
return true;
}
if (PhotonNetwork.InRoom && PhotonNetwork.CurrentRoom != null)
{
if (_debugMode)
{
ManualLogSource logger2 = _logger;
if (logger2 != null)
{
logger2.LogInfo((object)$"检测到多人房间 (玩家数: {PhotonNetwork.CurrentRoom.PlayerCount}),不允许暂停");
}
}
return false;
}
if (_debugMode)
{
if (PhotonNetwork.InRoom && PhotonNetwork.CurrentRoom != null)
{
ManualLogSource logger3 = _logger;
if (logger3 != null)
{
logger3.LogInfo((object)$"检测到多人游戏 (玩家数: {PhotonNetwork.CurrentRoom.PlayerCount}),禁止暂停");
}
}
else
{
ManualLogSource logger4 = _logger;
if (logger4 != null)
{
logger4.LogInfo((object)"检测到网络游戏状态,禁止暂停");
}
}
}
return false;
}
catch (Exception ex)
{
ManualLogSource logger5 = _logger;
if (logger5 != null)
{
logger5.LogWarning((object)("检测游戏模式时出错,默认允许暂停: " + ex.Message));
}
return true;
}
}
public static void TogglePause()
{
_isPaused = !_isPaused;
if (_isPaused)
{
PauseGame();
}
else
{
ResumeGame();
}
}
private static void PauseGame()
{
try
{
Time.timeScale = 0f;
if (_pauseAudio)
{
_originalAudioVolume = AudioListener.volume;
AudioListener.volume = 0f;
}
ManualLogSource logger = _logger;
if (logger != null)
{
logger.LogInfo((object)"游戏已暂停");
}
}
catch (Exception ex)
{
ManualLogSource logger2 = _logger;
if (logger2 != null)
{
logger2.LogWarning((object)("暂停游戏时出错: " + ex.Message));
}
}
}
private static void ResumeGame()
{
try
{
Time.timeScale = 1f;
if (_pauseAudio)
{
AudioListener.volume = _originalAudioVolume;
}
ManualLogSource logger = _logger;
if (logger != null)
{
logger.LogInfo((object)"游戏已恢复");
}
}
catch (Exception ex)
{
ManualLogSource logger2 = _logger;
if (logger2 != null)
{
logger2.LogWarning((object)("恢复游戏时出错: " + ex.Message));
}
}
}
}
[HarmonyPatch(typeof(GUIManager), "LateUpdate")]
public class GUIManager_LateUpdate_Patch
{
private static void Postfix()
{
PauseManager.HandleCustomPauseInput(GUIManager.instance);
}
}
public static class PersistentEmoteManager
{
private static KeyCode _emoteStopKey = (KeyCode)284;
public static bool _debugMode = false;
private static bool _wasKeyPressed = false;
public static ManualLogSource _logger;
public static bool _userWantsToStopEmote = false;
public static KeyCode EmoteStopKey => _emoteStopKey;
public static void Initialize(KeyCode emoteStopKey, bool debugMode, ManualLogSource logger)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
_emoteStopKey = emoteStopKey;
_debugMode = debugMode;
_logger = logger;
}
public static void HandleEmoteStopInput()
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
try
{
bool key = Input.GetKey(_emoteStopKey);
if (key && !_wasKeyPressed && (Object)(object)Character.localCharacter != (Object)null)
{
CharacterAnimations animations = Character.localCharacter.refs.animations;
if ((Object)(object)animations != (Object)null)
{
StopCurrentEmote(animations);
}
}
_wasKeyPressed = key;
}
catch (Exception ex)
{
ManualLogSource logger = _logger;
if (logger != null)
{
logger.LogError((object)("处理停止表情输入时出错: " + ex.Message));
}
}
}
private static void StopCurrentEmote(CharacterAnimations animations)
{
//IL_004f: Unknown result type (might be due to invalid IL or missing references)
//IL_0056: Expected O, but got Unknown
try
{
FieldInfo fieldInfo = AccessTools.Field(typeof(CharacterAnimations), "emoting");
if (!(bool)fieldInfo.GetValue(animations))
{
return;
}
_userWantsToStopEmote = true;
FieldInfo fieldInfo2 = AccessTools.Field(typeof(CharacterAnimations), "character");
Character val = (Character)fieldInfo2.GetValue(animations);
if ((Object)(object)val != (Object)null && (Object)(object)val.refs.view != (Object)null)
{
try
{
val.refs.view.RPC("RPCA_PlayRemove", (RpcTarget)0, new object[1] { "STOP_EMOTE" });
if (_debugMode)
{
ManualLogSource logger = _logger;
if (logger != null)
{
logger.LogInfo((object)"通过F3键手动停止表情(已同步到所有玩家)");
}
}
return;
}
catch (Exception ex)
{
Character.localCharacter.refs.animator.SetBool("Emote", false);
fieldInfo.SetValue(animations, false);
if (_debugMode)
{
ManualLogSource logger2 = _logger;
if (logger2 != null)
{
logger2.LogWarning((object)("RPC发送失败,回退到本地停止: " + ex.Message));
}
}
return;
}
}
Character.localCharacter.refs.animator.SetBool("Emote", false);
fieldInfo.SetValue(animations, false);
if (_debugMode)
{
ManualLogSource logger3 = _logger;
if (logger3 != null)
{
logger3.LogInfo((object)"通过F3键手动停止表情(仅本地)");
}
}
}
catch (Exception ex2)
{
ManualLogSource logger4 = _logger;
if (logger4 != null)
{
logger4.LogError((object)("停止表情时出错: " + ex2.Message));
}
}
}
public static void OnNewEmoteStarted()
{
_userWantsToStopEmote = false;
if (_debugMode)
{
ManualLogSource logger = _logger;
if (logger != null)
{
logger.LogInfo((object)"新表情开始,重置停止标记");
}
}
}
}
[HarmonyPatch(typeof(CharacterAnimations), "Update")]
public class CharacterAnimations_Update_Patch
{
private static void Prefix()
{
PersistentEmoteManager.HandleEmoteStopInput();
}
private static void Postfix(CharacterAnimations __instance)
{
//IL_0055: Unknown result type (might be due to invalid IL or missing references)
//IL_005c: Expected O, but got Unknown
try
{
FieldInfo fieldInfo = AccessTools.Field(typeof(CharacterAnimations), "emoting");
FieldInfo fieldInfo2 = AccessTools.Field(typeof(CharacterAnimations), "sinceEmoteStart");
FieldInfo fieldInfo3 = AccessTools.Field(typeof(CharacterAnimations), "character");
bool flag = (bool)fieldInfo.GetValue(__instance);
Character val = (Character)fieldInfo3.GetValue(__instance);
bool flag2 = (Object)(object)val == (Object)(object)Character.localCharacter;
bool flag3 = flag2 && PersistentEmoteManager._userWantsToStopEmote;
if (flag2 && !flag && PersistentEmoteManager._userWantsToStopEmote)
{
PersistentEmoteManager._userWantsToStopEmote = false;
if (PersistentEmoteManager._debugMode)
{
ManualLogSource logger = PersistentEmoteManager._logger;
if (logger != null)
{
logger.LogInfo((object)"表情已停止,重置停止标记");
}
}
}
if (!flag || flag3)
{
return;
}
float num = (float)fieldInfo2.GetValue(__instance);
if (!(num >= 0.35f))
{
return;
}
fieldInfo2.SetValue(__instance, 0f);
if (!(PersistentEmoteManager._debugMode && flag2))
{
return;
}
string arg = "未知";
try
{
Animator animator = val.refs.animator;
if ((Object)(object)animator != (Object)null)
{
AnimatorClipInfo[] currentAnimatorClipInfo = animator.GetCurrentAnimatorClipInfo(0);
if (currentAnimatorClipInfo.Length != 0 && (Object)(object)((AnimatorClipInfo)(ref currentAnimatorClipInfo[0])).clip != (Object)null)
{
arg = ((Object)((AnimatorClipInfo)(ref currentAnimatorClipInfo[0])).clip).name;
}
}
}
catch
{
arg = "获取失败";
}
ManualLogSource logger2 = PersistentEmoteManager._logger;
if (logger2 != null)
{
logger2.LogInfo((object)$"重置表情时间为0(原时间:{num:F2}秒,表情:{arg})");
}
}
catch (Exception ex)
{
Debug.LogError((object)("[GameTweaks] Update Postfix出错: " + ex.Message));
}
}
}
[HarmonyPatch(typeof(CharacterAnimations), "RPCA_PlayRemove")]
public class CharacterAnimations_PlayEmote_Patch
{
private static void Postfix(CharacterAnimations __instance, string emoteName)
{
//IL_001e: Unknown result type (might be due to invalid IL or missing references)
//IL_0024: Expected O, but got Unknown
try
{
FieldInfo fieldInfo = AccessTools.Field(typeof(CharacterAnimations), "character");
Character val = (Character)fieldInfo.GetValue(__instance);
if (emoteName == "STOP_EMOTE")
{
FieldInfo fieldInfo2 = AccessTools.Field(typeof(CharacterAnimations), "emoting");
val.refs.animator.SetBool("Emote", false);
fieldInfo2.SetValue(__instance, false);
if (PersistentEmoteManager._debugMode)
{
ManualLogSource logger = PersistentEmoteManager._logger;
if (logger != null)
{
logger.LogInfo((object)"收到RPC停止表情请求");
}
}
}
else if ((Object)(object)val == (Object)(object)Character.localCharacter && emoteName != "A_Scout_Emote_Flex")
{
PersistentEmoteManager.OnNewEmoteStarted();
}
}
catch (Exception ex)
{
Debug.LogError((object)("[GameTweaks] PlayEmote Patch出错: " + ex.Message));
}
}
}
}