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 UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: IgnoresAccessChecksTo("")] [assembly: AssemblyCompany("REPOJP")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0")] [assembly: AssemblyProduct("zabuMod")] [assembly: AssemblyTitle("zabuMod")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.0.0.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 REPOJP.HideFlashlightHand { [BepInPlugin("REPOJP.HideFlashlightHand", "HideFlashlightHand", "4.0.0")] public sealed class HideFlashlightHandPlugin : BaseUnityPlugin { public const string PluginGuid = "REPOJP.HideFlashlightHand"; public const string PluginName = "HideFlashlightHand"; public const string PluginVersion = "4.0.0"; internal static ConfigEntry CfgEnableMod; internal static ConfigEntry CfgHideFirstPersonHalo; internal static ConfigEntry CfgRestoreWhenNotFirstPerson; internal static ConfigEntry CfgShowDebugLog; internal static ManualLogSource Log; private Harmony harmony; private void Awake() { //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Expected O, but got Unknown //IL_0069: Unknown result type (might be due to invalid IL or missing references) //IL_0073: Expected O, but got Unknown //IL_0094: Unknown result type (might be due to invalid IL or missing references) //IL_009e: Expected O, but got Unknown //IL_00bf: Unknown result type (might be due to invalid IL or missing references) //IL_00c9: Expected O, but got Unknown //IL_00d4: Unknown result type (might be due to invalid IL or missing references) //IL_00de: Expected O, but got Unknown try { Log = ((BaseUnityPlugin)this).Logger; ((Component)this).transform.parent = null; Object.DontDestroyOnLoad((Object)(object)((Component)this).gameObject); CfgEnableMod = ((BaseUnityPlugin)this).Config.Bind("General", "EnableMod", true, new ConfigDescription("Enable this mod.このMODを有効化", (AcceptableValueBase)null, Array.Empty())); CfgHideFirstPersonHalo = ((BaseUnityPlugin)this).Config.Bind("Visual", "HideFirstPersonHalo", false, new ConfigDescription("Hide the local first-person halo/flare visual too. The spotlight and flashlight lighting behavior are never disabled.ローカル一人称時のhalo/flare表示も非表示 照射Lightと懐中電灯の照射挙動は無効化しない", (AcceptableValueBase)null, Array.Empty())); CfgRestoreWhenNotFirstPerson = ((BaseUnityPlugin)this).Config.Bind("Visual", "RestoreWhenNotFirstPerson", true, new ConfigDescription("Restore the local flashlight mesh when it is not being rendered as the local first-person hand model.ローカル一人称の手元モデルとして描画されていない場合はローカル懐中電灯メッシュを復元", (AcceptableValueBase)null, Array.Empty())); CfgShowDebugLog = ((BaseUnityPlugin)this).Config.Bind("Debug", "ShowDebugLog", false, new ConfigDescription("Show debug logs.デバッグログを表示", (AcceptableValueBase)null, Array.Empty())); harmony = new Harmony("REPOJP.HideFlashlightHand"); harmony.PatchAll(); WriteDebugLog("Plugin loaded"); } catch (Exception ex) { ((BaseUnityPlugin)this).Logger.LogError((object)("Failure: HideFlashlightHand Awake\n" + ex)); } } private void OnDestroy() { try { if (harmony != null) { harmony.UnpatchSelf(); } } catch (Exception ex) { if (Log != null) { Log.LogError((object)("Failure: HideFlashlightHand OnDestroy\n" + ex)); } } } internal static void WriteDebugLog(string message) { if (Log != null && CfgShowDebugLog != null && CfgShowDebugLog.Value) { Log.LogInfo((object)message); } } } internal static class FlashlightHideCore { private static readonly FieldInfo CurrentStateField = AccessTools.Field(typeof(FlashlightController), "currentState"); private static readonly int TriggersLayer = LayerMask.NameToLayer("Triggers"); internal static void ApplyAfterVanillaUpdate(FlashlightController inst) { try { if ((Object)(object)inst == (Object)null || (Object)(object)inst.PlayerAvatar == (Object)null || (Object)(object)inst.mesh == (Object)null || !inst.PlayerAvatar.isLocal) { return; } if (HideFlashlightHandPlugin.CfgEnableMod == null || !HideFlashlightHandPlugin.CfgEnableMod.Value) { RestoreMeshIfVanillaVisible(inst); RestoreHaloIfNeeded(inst); return; } if (!IsFirstPersonHandView(inst)) { if (HideFlashlightHandPlugin.CfgRestoreWhenNotFirstPerson != null && HideFlashlightHandPlugin.CfgRestoreWhenNotFirstPerson.Value) { RestoreMeshIfVanillaVisible(inst); } RestoreHaloIfNeeded(inst); return; } if (((Renderer)inst.mesh).enabled) { ((Renderer)inst.mesh).enabled = false; HideFlashlightHandPlugin.WriteDebugLog("Local first-person flashlight mesh hidden"); } if (HideFlashlightHandPlugin.CfgHideFirstPersonHalo != null && HideFlashlightHandPlugin.CfgHideFirstPersonHalo.Value && (Object)(object)inst.halo != (Object)null && inst.halo.enabled) { inst.halo.enabled = false; } } catch (Exception ex) { if (HideFlashlightHandPlugin.Log != null) { HideFlashlightHandPlugin.Log.LogError((object)("Failure: ApplyAfterVanillaUpdate\n" + ex)); } } } private static bool IsFirstPersonHandView(FlashlightController inst) { if ((Object)(object)inst == (Object)null || (Object)(object)inst.PlayerAvatar == (Object)null || (Object)(object)inst.mesh == (Object)null) { return false; } if (!inst.PlayerAvatar.isLocal) { return false; } if (!IsVanillaMeshExpectedVisible(inst)) { return false; } if (TriggersLayer >= 0 && ((Component)inst.mesh).gameObject.layer == TriggersLayer) { return false; } if (IsUsingClientFollowTransform(inst)) { return false; } return true; } private static bool IsUsingClientFollowTransform(FlashlightController inst) { //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_0049: Unknown result type (might be due to invalid IL or missing references) //IL_0054: Unknown result type (might be due to invalid IL or missing references) try { if ((Object)(object)inst == (Object)null || (Object)(object)inst.FollowTransformClient == (Object)null) { return false; } float num = Vector3.Distance(((Component)inst).transform.position, inst.FollowTransformClient.position); if (num > 0.03f) { return false; } float num2 = Quaternion.Angle(((Component)inst).transform.rotation, inst.FollowTransformClient.rotation); if (num2 > 2f) { return false; } return true; } catch { return false; } } private static void RestoreMeshIfVanillaVisible(FlashlightController inst) { if (!((Object)(object)inst == (Object)null) && !((Object)(object)inst.mesh == (Object)null) && IsVanillaMeshExpectedVisible(inst) && !((Renderer)inst.mesh).enabled) { ((Renderer)inst.mesh).enabled = true; HideFlashlightHandPlugin.WriteDebugLog("Local flashlight mesh restored"); } } private static void RestoreHaloIfNeeded(FlashlightController inst) { if (!((Object)(object)inst == (Object)null) && !((Object)(object)inst.halo == (Object)null) && HideFlashlightHandPlugin.CfgHideFirstPersonHalo != null && HideFlashlightHandPlugin.CfgHideFirstPersonHalo.Value && inst.LightActive && !inst.halo.enabled) { inst.halo.enabled = true; } } private static bool IsVanillaMeshExpectedVisible(FlashlightController inst) { if ((Object)(object)inst == (Object)null || (Object)(object)inst.PlayerAvatar == (Object)null) { return false; } if (inst.PlayerAvatar.isDisabled) { return false; } string currentStateName = GetCurrentStateName(inst); switch (currentStateName) { default: return currentStateName == "Outro"; case "Intro": case "LightOn": case "Idle": case "LightOff": return true; } } private static string GetCurrentStateName(FlashlightController inst) { try { if (CurrentStateField == null || (Object)(object)inst == (Object)null) { return string.Empty; } object value = CurrentStateField.GetValue(inst); if (value == null) { return string.Empty; } return value.ToString(); } catch { return string.Empty; } } } [HarmonyPatch(typeof(FlashlightController))] internal static class FlashlightControllerPatches { [HarmonyPostfix] [HarmonyPatch("Start")] private static void Start_Postfix(FlashlightController __instance) { FlashlightHideCore.ApplyAfterVanillaUpdate(__instance); } [HarmonyPostfix] [HarmonyPatch("Update")] private static void Update_Postfix(FlashlightController __instance) { FlashlightHideCore.ApplyAfterVanillaUpdate(__instance); } } }