Skip to content

immcrab/Lasting-Utilla

Ownership not verified 1
Open on GitHub

Viewing main at commit a6a25ac430“Add files via upload”· 11 months ago

79 lines · 2.6 KBRaw on GitHub
// Decompiled with JetBrains decompiler
// Type: Utilla.Patches.VirtualStumpSelectorPatch
// Assembly: Utilla, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: FDD08D98-E155-49FA-85BC-1930928C3BAA
// Assembly location: C:\Program Files (x86)\Steam\steamapps\common\Gorilla Tag\BepInEx\plugins\Utilla\Utilla.dll

using GorillaTagScripts.VirtualStumpCustomMaps;
using HarmonyLib;
using UnityEngine;
using Utilla.Behaviours;

#nullable disable
namespace Utilla.Patches;

[HarmonyPatch(typeof (CustomMapModeSelector))]
[HarmonyWrapSafe]
internal class VirtualStumpSelectorPatch
{
  [HarmonyPatch("OnEnable")]
  [HarmonyPrefix]
  public static void OnEnablePrefix() => SetGameModePatch.PreventSettingMode = true;

  [HarmonyPatch("OnEnable")]
  [HarmonyPostfix]
  public static void OnEnablePostfix(CustomMapModeSelector __instance)
  {
    SetGameModePatch.PreventSettingMode = false;
    UtillaGamemodeSelector gamemodeSelector;
    if (((Component) __instance).TryGetComponent<UtillaGamemodeSelector>(ref gamemodeSelector))
      gamemodeSelector.CheckGameMode();
    else
      ComponentUtils.AddComponent<UtillaGamemodeSelector>((Component) __instance);
  }

  [HarmonyPatch("SetupButtons")]
  [HarmonyPostfix]
  public static void SetupButtonsPatch(CustomMapModeSelector __instance)
  {
    UtillaGamemodeSelector gamemodeSelector;
    if (!((Component) __instance).TryGetComponent<UtillaGamemodeSelector>(ref gamemodeSelector))
      return;
    gamemodeSelector.OnSelectorSetup();
  }

  [HarmonyPatch("ResetButtons")]
  [HarmonyPrefix]
  public static void ResetButtonsPrefix() => SetGameModePatch.PreventSettingMode = true;

  [HarmonyPatch("ResetButtons")]
  [HarmonyPostfix]
  public static void ResetButtonsPostfix()
  {
    SetGameModePatch.PreventSettingMode = false;
    foreach (Component instance in CustomMapModeSelector.instances)
    {
      UtillaGamemodeSelector gamemodeSelector;
      if (instance.TryGetComponent<UtillaGamemodeSelector>(ref gamemodeSelector))
        gamemodeSelector.CheckGameMode();
    }
  }

  [HarmonyPatch("SetAvailableGameModes")]
  [HarmonyPrefix]
  public static void AvailableModesPrefix() => SetGameModePatch.PreventSettingMode = true;

  [HarmonyPatch("SetAvailableGameModes")]
  [HarmonyPostfix]
  public static void AvailableModesPostfix()
  {
    SetGameModePatch.PreventSettingMode = false;
    foreach (Component instance in CustomMapModeSelector.instances)
    {
      UtillaGamemodeSelector gamemodeSelector;
      if (instance.TryGetComponent<UtillaGamemodeSelector>(ref gamemodeSelector))
        gamemodeSelector.CheckGameMode();
    }
  }
}

Code is shown from GitHub as-is. Linking a repository doesn’t prove that a release file on Canopy was built from it.