Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
gwisp2 committed Jul 12, 2024
0 parents commit 4a4a469
Show file tree
Hide file tree
Showing 6 changed files with 193 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
lib/Assembly-CSharp.dll
.vs
bin
obj
22 changes: 22 additions & 0 deletions Plugin.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;

namespace Puzzleskip
{
[BepInPlugin(MyPluginInfo.PLUGIN_GUID, MyPluginInfo.PLUGIN_NAME, MyPluginInfo.PLUGIN_VERSION)]
public class Plugin : BaseUnityPlugin
{
internal static new ManualLogSource Logger;

private void Awake()
{
// Plugin startup logic
Logger = base.Logger;
Logger.LogInfo($"Plugin {MyPluginInfo.PLUGIN_GUID} is loaded!");
// Patch game code
var harmony = new Harmony("Puzzleskip");
harmony.PatchAll();
}
}
}
39 changes: 39 additions & 0 deletions Puzzleskip.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<AssemblyName>Puzzleskip</AssemblyName>
<Product>Skip puzzles in Mansions of Madness</Product>
<Version>1.0.0</Version>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<LangVersion>latest</LangVersion>
<RestoreAdditionalProjectSources>
https://api.nuget.org/v3/index.json;
https://nuget.bepinex.dev/v3/index.json;
https://nuget.samboy.dev/v3/index.json
</RestoreAdditionalProjectSources>
<RootNamespace>Puzzleskip</RootNamespace>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="BepInEx.Analyzers" Version="1.*" PrivateAssets="all" />
<PackageReference Include="BepInEx.Core" Version="5.*" />
<PackageReference Include="BepInEx.PluginInfoProps" Version="2.*" />
<PackageReference Include="UnityEngine.Modules" Version="2020.3.45" IncludeAssets="compile" />
</ItemGroup>


<ItemGroup>
<Reference Include="MoM">
<HintPath>lib\Assembly-CSharp.dll</HintPath>
</Reference>
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework.TrimEnd(`0123456789`))' == 'net'">
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.2" PrivateAssets="all" />
</ItemGroup>

<ItemGroup>
<Folder Include="lib\" />
</ItemGroup>
</Project>
25 changes: 25 additions & 0 deletions Puzzleskip.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.10.35013.160
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Puzzleskip", "Puzzleskip.csproj", "{3EC53305-2A9E-41FB-A124-0DBD2BDC7FCB}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{3EC53305-2A9E-41FB-A124-0DBD2BDC7FCB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3EC53305-2A9E-41FB-A124-0DBD2BDC7FCB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3EC53305-2A9E-41FB-A124-0DBD2BDC7FCB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3EC53305-2A9E-41FB-A124-0DBD2BDC7FCB}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {287AA528-E116-497E-BE5D-2CA1094F224D}
EndGlobalSection
EndGlobal
51 changes: 51 additions & 0 deletions PuzzleskipPatcher.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using FFG.MoM;
using HarmonyLib;

namespace Puzzleskip
{
[HarmonyPatch(typeof(PuzzleViewBase))]
internal class PuzzleskipPatcher
{
[HarmonyPrefix]
[HarmonyPatch("PuzzleClosedEvent")]
static bool PrePuzzleClosedEvent(PuzzleViewBase __instance, ref bool completed)
{
SkipPuzzleButton skipPuzzleButton = __instance.gameObject.GetComponentInChildren<SkipPuzzleButton>();
if (skipPuzzleButton.SkipEnabled)
{
completed = true;
}
return true;
}


[HarmonyPrefix]
[HarmonyPatch("Show")]
static void PreShow(PuzzleViewBase __instance)
{
UIButton button = FindCloseButton(__instance);
if (button != null)
{
if (button.gameObject.GetComponent<SkipPuzzleButton>() == null)
{
button.gameObject.AddComponent<SkipPuzzleButton>();
}
SkipPuzzleButton skipButton = button.gameObject.GetComponent<SkipPuzzleButton>();
skipButton.SkipEnabled = false;
}
}

private static UIButton FindCloseButton(PuzzleViewBase puzzleViewBase)
{
var buttons = puzzleViewBase.GetComponentsInChildren<UIButton>();
foreach (var button in buttons)
{
if (button.name.Contains("Close"))
{
return button;
}
}
return null;
}
}
}
52 changes: 52 additions & 0 deletions SkipPuzzleButton.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using UnityEngine;

namespace Puzzleskip
{
internal class SkipPuzzleButton : MonoBehaviour
{
private UILabel _label;
private bool _skipEnabled;
private string _originalText;
private float _buttonDownSeconds = 0;

public void Awake()
{
_label = this.gameObject.GetComponentInChildren<UILabel>();
_originalText = _label.text;
}

public void Update()
{
if (Input.GetMouseButton(1))
{
_buttonDownSeconds += Time.deltaTime;
}
else
{
_buttonDownSeconds = 0;
}
if (_buttonDownSeconds > 3)
{
SkipEnabled = !SkipEnabled;
_buttonDownSeconds = 0;
}
}

public bool SkipEnabled
{
get { return _skipEnabled; }
set
{
_skipEnabled = value;
if (_skipEnabled)
{
_label.text = "Skip";
}
else
{
_label.text = _originalText;
}
}
}
}
}

0 comments on commit 4a4a469

Please sign in to comment.