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.Closet</AssemblyName>
<Description>Closet</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,69 @@
using HarmonyLib;
using System;
using UnityEngine;

namespace BepInEx5Plugins.Ash.Alisa.Closet.HarmonyPatches
{
[HarmonyPatch(typeof(ButtonSelected), "Awake")]
public class ButtonSelected_Awake
{
// Forcibly assign null fields to appopriate values if possible.
public static void Postfix(ButtonSelected __instance)
{
if (!__instance.slot_Button01)
{
Console.WriteLine("ButtonSelected_Awake.Postfix: Force initialization of slot_Button01");

__instance.slot_Button01 = __instance.buttonSet01?.transform.parent?.Find("SlotButtons")?.Find("Slot01")?.gameObject;
}

if (!__instance.slot_Button02)
{
Console.WriteLine("ButtonSelected_Awake.Postfix: Force initialization of slot_Button02");

__instance.slot_Button02 = __instance.buttonSet02?.transform.parent?.Find("SlotButtons")?.Find("Slot02")?.gameObject;
}

if (!__instance.slot_Button03)
{
Console.WriteLine("ButtonSelected_Awake.Postfix: Force initialization of slot_Button03");

__instance.slot_Button03 = __instance.buttonSet03?.transform.parent?.Find("SlotButtons")?.Find("Slot03")?.gameObject;
}

if (!__instance.myHighlightedBackground)
{
Console.WriteLine("ButtonSelected_Awake.Postfix: Force initialization of myHighlightedBackground");

var target = (GameObject)null;

if (__instance.slotButton01)
{
target = __instance.buttonSet01;
}
else if (__instance.slotButton02)
{
target = __instance.buttonSet02;
}
else if (__instance.slotButton03)
{
target = __instance.buttonSet03;
}

if (target)
{
for (var i = 0; i < target.transform.childCount; ++i)
{
var child = target.transform.GetChild(i);

if (child.name.StartsWith("ClosetSlotBackground"))
{
__instance.myHighlightedBackground = child.gameObject;
break;
}
}
}
}
}
}
}
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.Closet.HarmonyPatches
{
[HarmonyPatch(typeof(ButtonSelected), "OnDeselect", new Type[] { typeof(BaseEventData) })]
public class ButtonSelected_OnDeselect
{
// Enable button selection auto fix.
public static void Prefix(ButtonSelected __instance, BaseEventData eventData)
{
ClosetButtonsSorting_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.Closet.HarmonyPatches
{
[HarmonyPatch(typeof(ButtonSelected), "OnSelect", new Type[] { typeof(BaseEventData) })]
public class ButtonSelected_OnSelect
{
// Disable button selection auto fix.
public static void Prefix(ButtonSelected __instance, BaseEventData eventData)
{
ClosetButtonsSorting_Update.checkPending = false;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
using HarmonyLib;
using System;
using System.Reflection;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
using Object = UnityEngine.Object;

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

public static bool checkPending;

public static float timer;

private static FieldInfo ButtonSelected_selected;

public static bool Prepare(MethodBase original)
{
if (original is null)
{
try
{
ButtonSelected_selected = typeof(ButtonSelected).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(ClosetButtonsSorting __instance)
{
if (!checkPending)
{
return;
}

var equipmentMenu = __instance.GetComponent<EquipmentMenu>();

if (!equipmentMenu || !equipmentMenu.charlotteIsActive)
{
return;
}

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

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

timer += Time.deltaTime;
}

public static bool HasSelection()
{
foreach (var buttonSelected in Object.FindObjectsOfType<ButtonSelected>())
{
if ((bool)ButtonSelected_selected.GetValue(buttonSelected))
{
return true;
}
}

return false;
}

public static void SelectionFix()
{
checkPending = false;

if (!EventSystem.current)
{
return;
}

var selectedObject = EventSystem.current.currentSelectedGameObject;

if (!selectedObject)
{
return;
}

Console.WriteLine("ClosetButtonsSorting_Update.SelectionFix: Forcibly reset selection to game object " + selectedObject);

var buttonSelected = selectedObject.GetComponent<ButtonSelected>();

if (!buttonSelected)
{
return;
}

if (buttonSelected.slotButton01 || buttonSelected.itemButtonSlot01)
{
buttonSelected.slot_Button01?.GetComponent<Button>()?.Select();
}
else if (buttonSelected.slotButton02 || buttonSelected.itemButtonSlot02)
{
buttonSelected.slot_Button02?.GetComponent<Button>()?.Select();
}
else if (buttonSelected.slotButton03 || buttonSelected.itemButtonSlot03)
{
buttonSelected.slot_Button03?.GetComponent<Button>()?.Select();
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using HarmonyLib;

namespace BepInEx5Plugins.Ash.Alisa.Closet.HarmonyPatches
{
[HarmonyPatch(typeof(Interaction), "CloseCharlotte")]
public class Interaction_CloseCharlotte
{
// Disable button selection auto fix.
public static void Prefix(Interaction __instance
, ref EquipmentMenu ___equipmentMenuScript
)
{
if (___equipmentMenuScript
&& !___equipmentMenuScript.buttonLock)
{
ClosetButtonsSorting_Update.checkPending = false;
}
}
}
}
6 changes: 6 additions & 0 deletions BepInEx5Plugins.Ash.Alisa.Closet/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.Closet/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.Closet
{
[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("Closet", "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.ClosetButtonsSorting_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);
}
}
}
}