Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net35</TargetFramework>
<AssemblyName>BepInEx5Plugins.Ash.Alisa.PuppetShopMenuFix</AssemblyName>
<Description>PuppetShopMenuFix</Description>
<Version>1.0.0</Version>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<LangVersion>9.0</LangVersion>
</PropertyGroup>

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

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

<ItemGroup>
<Reference Include="Assembly-CSharp">
<HintPath>..\lib\SteamRelease\Assembly-CSharp.dll</HintPath>
<Private>false</Private>
</Reference>
<Reference Include="UnityEngine.UI">
<HintPath>..\lib\UnityEngine\UnityEngine.UI.dll</HintPath>
<Private>false</Private>
</Reference>
</ItemGroup>

<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Exec Command="xcopy /Y /Q /C /I &quot;$(OutDir)&quot; &quot;..\$(OutDir)\$(TargetName)\&quot;" />
</Target>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using HarmonyLib;

namespace BepInEx5Plugins.Ash.Alisa.PuppetShopMenuFix.HarmonyPatches
{
[HarmonyPatch(typeof(Interaction), "CloseShopMenu")]
public class Interaction_CloseShopMenu
{
// Disable button selection auto fix.
public static void Prefix(Interaction __instance
//, ref EquipmentMenu ___equipmentMenuScript
)
{
//if (!___equipmentMenuScript.buttonLock)
{
PuppetShopMenu_Update.checkPending = false;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
using HarmonyLib;
using System;
using System.Reflection;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
using Object = UnityEngine.Object;

namespace BepInEx5Plugins.Ash.Alisa.PuppetShopMenuFix.HarmonyPatches
{
[HarmonyPatch(typeof(PuppetShopMenu), "Update")]
public class PuppetShopMenu_Update
{
public static float checkDelay = 1f;

public static bool checkPending;

public static float timer;

private static FieldInfo ShopCancelButton_selected;

public static bool Prepare(MethodBase original)
{
if (original is null)
{
try
{
ShopCancelButton_selected = typeof(ShopCancelButton).GetField("selected", BindingFlags.NonPublic | BindingFlags.Instance);
}
catch (Exception exception)
{
Console.WriteLine(exception);
return false;
}
}

return true;
}

// Auto fix button selection if necessary.
public static void Postfix(PuppetShopMenu __instance)
{
if (!checkPending)
{
return;
}

if (timer >= checkDelay)
{
timer -= checkDelay;

if (!HasSelection())
{
SelectionFix(__instance);
}
}

timer += Time.deltaTime;
}

public static bool HasSelection()
{
foreach (var button in Object.FindObjectsOfType<ShopCancelButton>())
{
if ((bool)ShopCancelButton_selected.GetValue(button))
{
return true;
}
}

return false;
}

public static void SelectionFix(PuppetShopMenu shop)
{
checkPending = false;

if (!EventSystem.current)
{
return;
}

var selectedObject = EventSystem.current.currentSelectedGameObject;

if (!selectedObject)
{
return;
}

Console.WriteLine("PuppetShopMenu_Update.SelectionFix: Forcibly resetting shop selection to game object " + selectedObject);

if (shop.weaponsScreen.activeSelf)
{
Console.WriteLine("Selecting first weapons slot");

shop.firstWeaponsSlot?.GetComponent<Button>()?.Select();
}
else if (shop.dressesScreen.activeSelf)
{
Console.WriteLine("Selecting first dresses slot");

shop.firstDressesSlot?.GetComponent<Button>()?.Select();
}
else if (shop.itemsScreen.activeSelf)
{
Console.WriteLine("Selecting first items slot");

shop.firstItemsSlot?.GetComponent<Button>()?.Select();
}
else if (shop.modScreen.activeSelf)
{
Console.WriteLine("Selecting first mod slot");

shop.firstSlectedMod?.GetComponent<Button>()?.Select();
}
else if (shop.rewardScreen.activeSelf)
{
Console.WriteLine("Selecting first reward slot");

shop.rewardsFirstSelected?[0]?.GetComponent<Button>()?.Select();
}

else if (shop.buttons.activeSelf)
{
Console.WriteLine("Selecting weapons button");

shop.weaponsButton?.GetComponent<Button>()?.Select();
}
else if (shop.buttons2.activeSelf)
{
Console.WriteLine("Selecting weapons button 2");

shop.weaponsButton2?.GetComponent<Button>()?.Select();
}
else if (shop.buttons3.activeSelf)
{
Console.WriteLine("Selecting modifications button");

shop.modificationsButton?.GetComponent<Button>()?.Select();
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using HarmonyLib;
using System;
using UnityEngine.EventSystems;

namespace BepInEx5Plugins.Ash.Alisa.PuppetShopMenuFix.HarmonyPatches
{
[HarmonyPatch(typeof(ShopCancelButton), "OnDeselect", new Type[] { typeof(BaseEventData) })]
public class ShopCancelButton_OnDeselect
{
// Enable button selection auto fix.
public static void Prefix(ShopCancelButton __instance, BaseEventData eventData)
{
PuppetShopMenu_Update.checkPending = true;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using HarmonyLib;
using System;
using UnityEngine.EventSystems;

namespace BepInEx5Plugins.Ash.Alisa.PuppetShopMenuFix.HarmonyPatches
{
[HarmonyPatch(typeof(ShopCancelButton), "OnSelect", new Type[] { typeof(BaseEventData) })]
public class ShopCancelButton_OnSelect
{
// Disable button selection auto fix.
public static void Prefix(ShopCancelButton __instance, BaseEventData eventData)
{
PuppetShopMenu_Update.checkPending = false;
}
}
}
6 changes: 6 additions & 0 deletions BepInEx5Plugins.Ash.Alisa.PuppetShopMenuFix/NuGet.Config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="BepInEx" value="https://nuget.bepinex.dev/v3/index.json" />
</packageSources>
</configuration>
55 changes: 55 additions & 0 deletions BepInEx5Plugins.Ash.Alisa.PuppetShopMenuFix/Plugin.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using System;

namespace BepInEx5Plugins.Ash.Alisa.PuppetShopMenuFix
{
[BepInPlugin(PluginInfo.PLUGIN_GUID, PluginInfo.PLUGIN_NAME, PluginInfo.PLUGIN_VERSION)]
public class Plugin : BaseUnityPlugin
{
private static ConfigEntry<float> checkDelay;

private Plugin()
{
try
{
checkDelay = Config.Bind("PuppetShop", "Check Delay", 1f);

Config.SettingChanged += Config_SettingChanged;

ApplySettings();
}
catch (Exception exception)
{
Console.WriteLine(exception);
}
}

private static void Config_SettingChanged(object sender, EventArgs e)
{
ApplySettings();
}

private static void ApplySettings()
{
HarmonyPatches.PuppetShopMenu_Update.checkDelay = checkDelay.Value;
}

private void Awake()
{
try
{
Logger.LogInfo($"Plugin {PluginInfo.PLUGIN_GUID} is loaded!");

var harmony = new Harmony(Info.Metadata.GUID);

harmony.PatchAll();
}
catch (Exception exception)
{
Console.WriteLine(exception);
}
}
}
}