Code updates
This commit is contained in:
parent
34e0013ff4
commit
b51696fb45
6 changed files with 203 additions and 76 deletions
|
|
@ -1,16 +1,20 @@
|
||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>netstandard2.1</TargetFramework>
|
<TargetFramework>netstandard2.1</TargetFramework>
|
||||||
<AssemblyName>DisableShelves</AssemblyName>
|
<AssemblyName>DisableShelves</AssemblyName>
|
||||||
<Description>My first plugin</Description>
|
<Description>My first plugin</Description>
|
||||||
<Version>1.0.0</Version>
|
<Version>1.1.0</Version>
|
||||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||||
<LangVersion>latest</LangVersion>
|
<LangVersion>latest</LangVersion>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="BepInEx.Analyzers" Version="1.*" PrivateAssets="all" />
|
<PackageReference Include="BepInEx.Analyzers" Version="1.*" PrivateAssets="all" />
|
||||||
|
<PackageReference Include="BepInEx.AssemblyPublicizer.MSBuild" Version="0.4.3">
|
||||||
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
</PackageReference>
|
||||||
<PackageReference Include="BepInEx.Core" Version="5.*" />
|
<PackageReference Include="BepInEx.Core" Version="5.*" />
|
||||||
<PackageReference Include="BepInEx.PluginInfoProps" Version="1.*" />
|
<PackageReference Include="BepInEx.PluginInfoProps" Version="1.*" />
|
||||||
<PackageReference Include="UnityEngine.Modules" Version="2021.3.3" IncludeAssets="compile" />
|
<PackageReference Include="UnityEngine.Modules" Version="2021.3.3" IncludeAssets="compile" />
|
||||||
|
|
|
||||||
90
Extensions.cs
Normal file
90
Extensions.cs
Normal file
|
|
@ -0,0 +1,90 @@
|
||||||
|
using MyBox;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace DisableShelves
|
||||||
|
{
|
||||||
|
public static class Extensions
|
||||||
|
{
|
||||||
|
public static string GetColor(this Label label)
|
||||||
|
{
|
||||||
|
return label.gameObject.transform.GetChild(0).GetChild(0).GetComponent<MeshRenderer>().material.color.ToHex();
|
||||||
|
}
|
||||||
|
public static object GetField(this object obj, string field)
|
||||||
|
{
|
||||||
|
return obj.GetType().GetField(field, System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance).GetValue(obj);
|
||||||
|
}
|
||||||
|
public static Label GetLabel(this DisplaySlot slot)
|
||||||
|
{
|
||||||
|
return ((Label)typeof(DisplaySlot).GetField("m_Label", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance).GetValue(slot));
|
||||||
|
}
|
||||||
|
public static string ToGUID(this Label label)
|
||||||
|
{
|
||||||
|
return label.transform.position.x.ToString("0.0000") + ":" + label.transform.position.y.ToString("0.0000") + ":" + label.transform.position.z.ToString("0.0000");
|
||||||
|
}
|
||||||
|
public static void Disable(this Label __instance, bool all = false)
|
||||||
|
{
|
||||||
|
if (all)
|
||||||
|
{
|
||||||
|
((DisplaySlot[])__instance.DisplaySlot.Display.GetField("m_DisplaySlots")).ForEach(x => x.GetLabel().Disable(false));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Plugin.StaticLogger.LogInfo("Disabling " + __instance.ToGUID());
|
||||||
|
var cube = __instance.gameObject.transform.GetChild(0).GetChild(0);
|
||||||
|
var canvasbg = __instance.gameObject.transform.GetChild(1).GetChild(0);
|
||||||
|
|
||||||
|
var mat = cube.GetComponent<MeshRenderer>().material;
|
||||||
|
mat.color = Plugin.RedColor.ToUnityColor();
|
||||||
|
|
||||||
|
List<string> disabled = Plugin.DisabledLabelsGUIDs;
|
||||||
|
if (!disabled.Contains(__instance.ToGUID()))
|
||||||
|
disabled.Add(__instance.ToGUID());
|
||||||
|
Plugin.DisabledLabelsGUIDs = disabled;
|
||||||
|
}
|
||||||
|
public static void Enable(this Label __instance, bool all = false)
|
||||||
|
{
|
||||||
|
if (all)
|
||||||
|
{
|
||||||
|
((DisplaySlot[])__instance.DisplaySlot.Display.GetField("m_DisplaySlots")).ForEach(x => x.GetLabel().Enable(false));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Plugin.StaticLogger.LogInfo("Enabling " + __instance.ToGUID());
|
||||||
|
var cube = __instance.gameObject.transform.GetChild(0).GetChild(0);
|
||||||
|
var canvasbg = __instance.gameObject.transform.GetChild(1).GetChild(0);
|
||||||
|
|
||||||
|
var mat = cube.GetComponent<MeshRenderer>().material;
|
||||||
|
mat.color = Plugin.YellowColor.ToUnityColor();
|
||||||
|
|
||||||
|
List<string> disabled = Plugin.DisabledLabelsGUIDs;
|
||||||
|
disabled.Remove(__instance.ToGUID());
|
||||||
|
Plugin.DisabledLabelsGUIDs = disabled;
|
||||||
|
}
|
||||||
|
public static bool IsEnabled(this Label __instance)
|
||||||
|
{
|
||||||
|
var fi_m_DisplaySlot = typeof(Label).GetField("m_DisplaySlot", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
|
||||||
|
var displaySlot = ((DisplaySlot)fi_m_DisplaySlot.GetValue(__instance));
|
||||||
|
if (displaySlot != null)
|
||||||
|
{
|
||||||
|
if (displaySlot.HasProduct)
|
||||||
|
{
|
||||||
|
var cube = __instance.gameObject.transform.GetChild(0).GetChild(0);
|
||||||
|
var canvasbg = __instance.gameObject.transform.GetChild(1).GetChild(0);
|
||||||
|
|
||||||
|
var mat = cube.GetComponent<MeshRenderer>().material;
|
||||||
|
var color = mat.color.ToHex();
|
||||||
|
Plugin.StaticLogger.LogInfo(__instance.ToGUID() + ": Color is " + color);
|
||||||
|
var enabled = color != Plugin.RedColor;
|
||||||
|
if (enabled && Plugin.DisabledLabelsGUIDs.Contains(__instance.ToGUID()))
|
||||||
|
{
|
||||||
|
__instance.Disable();
|
||||||
|
enabled = false;
|
||||||
|
}
|
||||||
|
return enabled;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
18
Patches/DisplayManager_GetLabeledEmptyDisplaySlots_Patch.cs
Normal file
18
Patches/DisplayManager_GetLabeledEmptyDisplaySlots_Patch.cs
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
using HarmonyLib;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
|
namespace DisableShelves
|
||||||
|
{
|
||||||
|
public static partial class ShelfLabelPatch
|
||||||
|
{
|
||||||
|
[HarmonyPatch(typeof(DisplayManager), "GetLabeledEmptyDisplaySlots")]
|
||||||
|
public static class DisplayManager_GetLabeledEmptyDisplaySlots_Patch
|
||||||
|
{
|
||||||
|
public static void Postfix(ref List<DisplaySlot> __result)
|
||||||
|
{
|
||||||
|
__result = __result.Where(x => x.GetLabel().IsEnabled()).ToList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
47
Patches/Label_ClearLabel_Patch.cs
Normal file
47
Patches/Label_ClearLabel_Patch.cs
Normal file
|
|
@ -0,0 +1,47 @@
|
||||||
|
using BepInEx.Configuration;
|
||||||
|
using HarmonyLib;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace DisableShelves
|
||||||
|
{
|
||||||
|
public static partial class ShelfLabelPatch
|
||||||
|
{
|
||||||
|
[HarmonyPatch(typeof(Label), "SetProductIcon")]
|
||||||
|
public static class Label_SetProductIcon_Patch
|
||||||
|
{
|
||||||
|
public static void Prefix(Label __instance, int productID)
|
||||||
|
{
|
||||||
|
__instance.IsEnabled();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
[HarmonyPatch(typeof(Label), "ClearLabel")]
|
||||||
|
[HarmonyPriority(10000)]
|
||||||
|
public static class Label_ClearLabel_Patch
|
||||||
|
{
|
||||||
|
public static bool Prefix(Label __instance)
|
||||||
|
{
|
||||||
|
Plugin.StaticLogger.LogInfo("Label: " + __instance.ToGUID());
|
||||||
|
Plugin.StaticLogger.LogInfo("Running prefix patcher");
|
||||||
|
var fi_m_DisplaySlot = typeof(Label).GetField("m_DisplaySlot", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
|
||||||
|
var displaySlot = ((DisplaySlot)fi_m_DisplaySlot.GetValue(__instance));
|
||||||
|
if (displaySlot != null)
|
||||||
|
{
|
||||||
|
if (displaySlot.HasProduct)
|
||||||
|
{
|
||||||
|
bool all = Plugin.MultiModeShortcut.Value.IsPressed();
|
||||||
|
Plugin.StaticLogger.LogInfo("Multi Mode Shortcut pressed: " + all);
|
||||||
|
Plugin.StaticLogger.LogInfo("Label is shelf");
|
||||||
|
if (__instance.IsEnabled())
|
||||||
|
__instance.Disable(all);
|
||||||
|
else
|
||||||
|
__instance.Enable(all);
|
||||||
|
|
||||||
|
Plugin.StaticLogger.LogWarning("Returning false");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
17
Patches/Restocker_IsDisplaySlotAvailableToRestock_Patch.cs
Normal file
17
Patches/Restocker_IsDisplaySlotAvailableToRestock_Patch.cs
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
using HarmonyLib;
|
||||||
|
|
||||||
|
namespace DisableShelves
|
||||||
|
{
|
||||||
|
public static partial class ShelfLabelPatch
|
||||||
|
{
|
||||||
|
[HarmonyPatch(typeof(Restocker), "IsDisplaySlotAvailableToRestock")]
|
||||||
|
public static class Restocker_IsDisplaySlotAvailableToRestock_Patch
|
||||||
|
{
|
||||||
|
public static void Postfix(DisplaySlot displaySlot, ref bool __result)
|
||||||
|
{
|
||||||
|
if (!__result) return;
|
||||||
|
if (!displaySlot.GetLabel().IsEnabled()) __result = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
99
Plugin.cs
99
Plugin.cs
|
|
@ -1,4 +1,5 @@
|
||||||
using BepInEx;
|
using BepInEx;
|
||||||
|
using BepInEx.Configuration;
|
||||||
using BepInEx.Logging;
|
using BepInEx.Logging;
|
||||||
using HarmonyLib;
|
using HarmonyLib;
|
||||||
using MyBox;
|
using MyBox;
|
||||||
|
|
@ -6,32 +7,43 @@ using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
using UnityEngine.SceneManagement;
|
||||||
using UnityEngine.UI;
|
using UnityEngine.UI;
|
||||||
|
|
||||||
namespace DisableShelves
|
namespace DisableShelves
|
||||||
{
|
{
|
||||||
public static class Extensions
|
|
||||||
{
|
|
||||||
public static string GetColor(this Label label)
|
|
||||||
{
|
|
||||||
return label.gameObject.transform.GetChild(0).GetChild(0).GetComponent<MeshRenderer>().material.color.ToHex();
|
|
||||||
}
|
|
||||||
public static Label GetLabel(this DisplaySlot slot)
|
|
||||||
{
|
|
||||||
return ((Label)typeof(DisplaySlot).GetField("m_Label", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance).GetValue(slot));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
[BepInPlugin(PluginInfo.PLUGIN_GUID, PluginInfo.PLUGIN_NAME, PluginInfo.PLUGIN_VERSION)]
|
[BepInPlugin(PluginInfo.PLUGIN_GUID, PluginInfo.PLUGIN_NAME, PluginInfo.PLUGIN_VERSION)]
|
||||||
public class Plugin : BaseUnityPlugin
|
public class Plugin : BaseUnityPlugin
|
||||||
{
|
{
|
||||||
|
public const string YellowColor = "#FFDF00";
|
||||||
|
public const string RedColor = "#FF0000";
|
||||||
public static List<Label> RedLabels = new();
|
public static List<Label> RedLabels = new();
|
||||||
public static ManualLogSource StaticLogger;
|
public static ManualLogSource StaticLogger;
|
||||||
|
public static ConfigEntry<string> DisabledLabels { get; private set; }
|
||||||
|
public static List<string> DisabledLabelsGUIDs { get => DisabledLabels.Value.Split(';', StringSplitOptions.RemoveEmptyEntries).ToList(); set => DisabledLabels.Value = string.Join(";", value); }
|
||||||
|
public static ConfigEntry<KeyboardShortcut> MultiModeShortcut { get; private set; }
|
||||||
|
private void Dumbass() => Awake();
|
||||||
private void Awake()
|
private void Awake()
|
||||||
{
|
{
|
||||||
Logger.LogInfo($"Plugin {PluginInfo.PLUGIN_GUID} is loaded! Applying patch...");
|
Logger.LogInfo($"Plugin {PluginInfo.PLUGIN_GUID} is loaded! Applying patch...");
|
||||||
Harmony harmony = new Harmony("com.orpticon.DisableShelves");
|
Harmony harmony = new Harmony("com.orpticon.DisableShelves");
|
||||||
harmony.PatchAll();
|
harmony.PatchAll();
|
||||||
StaticLogger = Logger;
|
StaticLogger = Logger;
|
||||||
|
DisabledLabels = Config.Bind("Storage", "Disabled Labels (Do not edit)", "", "Semicolon separated list of labels to disable. This is maintained automatically and should not be manually altered.");
|
||||||
|
MultiModeShortcut = Config.Bind("General", "Multi Mode Shortcut", new KeyboardShortcut(KeyCode.LeftControl), "What key to hold while clicking in order to enable/disable entire shelves at once.");
|
||||||
|
//SceneManager.sceneLoaded += (a, b) =>
|
||||||
|
//{
|
||||||
|
// if (Singleton<DisplayManager>.Instance != null)
|
||||||
|
// {
|
||||||
|
// var disabled = DisabledLabelsGUIDs;
|
||||||
|
// Singleton<DisplayManager>.Instance.DisplayedProducts.Values.SelectMany(x => x).Where(x =>
|
||||||
|
// {
|
||||||
|
// bool disable = disabled.Contains(x.GetLabel().ToGUID());
|
||||||
|
// StaticLogger.LogInfo(x.GetLabel().ToGUID() + ": " + disable);
|
||||||
|
// return disable;
|
||||||
|
// }).ForEach(x => x.GetLabel().Disable());
|
||||||
|
// }
|
||||||
|
//};
|
||||||
}
|
}
|
||||||
public void Update()
|
public void Update()
|
||||||
{
|
{
|
||||||
|
|
@ -40,7 +52,8 @@ namespace DisableShelves
|
||||||
foreach (var label in RedLabels)
|
foreach (var label in RedLabels)
|
||||||
{
|
{
|
||||||
var displaySlot = ((DisplaySlot)fi_m_DisplaySlot.GetValue(label));
|
var displaySlot = ((DisplaySlot)fi_m_DisplaySlot.GetValue(label));
|
||||||
if (!displaySlot.HasProduct) {
|
if (!displaySlot.HasProduct)
|
||||||
|
{
|
||||||
mi_ClearLabel.Invoke(label, null);
|
mi_ClearLabel.Invoke(label, null);
|
||||||
var cube = label.gameObject.transform.GetChild(0).GetChild(0);
|
var cube = label.gameObject.transform.GetChild(0).GetChild(0);
|
||||||
var canvasbg = label.gameObject.transform.GetChild(1).GetChild(0);
|
var canvasbg = label.gameObject.transform.GetChild(1).GetChild(0);
|
||||||
|
|
@ -53,66 +66,4 @@ namespace DisableShelves
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public static class ShelfLabelPatch
|
|
||||||
{
|
|
||||||
[HarmonyPatch(typeof(DisplayManager), "GetLabeledEmptyDisplaySlots")]
|
|
||||||
public static class DisplayManager_GetLabeledEmptyDisplaySlots_Patch
|
|
||||||
{
|
|
||||||
public static void Postfix(ref List<DisplaySlot> __result)
|
|
||||||
{
|
|
||||||
__result = __result.Where(x => x.GetLabel().GetColor() != "#FF0000").ToList();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
[HarmonyPatch(typeof(Restocker), "IsDisplaySlotAvailableToRestock")]
|
|
||||||
public static class Restocker_IsDisplaySlotAvailableToRestock_Patch
|
|
||||||
{
|
|
||||||
public static void Postfix(DisplaySlot displaySlot, ref bool __result)
|
|
||||||
{
|
|
||||||
if (!__result) return;
|
|
||||||
var color = displaySlot.GetLabel().GetColor();
|
|
||||||
//if (!(color == "#FFD53A" || color == "#FFEB04")) Plugin.StaticLogger.LogError("color is " + color);
|
|
||||||
if (color == "#FF0000") __result = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
[HarmonyPatch(typeof(Label), "ClearLabel")]
|
|
||||||
[HarmonyPriority(10000)]
|
|
||||||
public static class Label_ClearLabel_Patch
|
|
||||||
{
|
|
||||||
public static bool Prefix(Label __instance)
|
|
||||||
{
|
|
||||||
//Plugin.StaticLogger.LogInfo("Running prefix patcher");
|
|
||||||
var fi_m_DisplaySlot = typeof(Label).GetField("m_DisplaySlot", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
|
|
||||||
var displaySlot = ((DisplaySlot)fi_m_DisplaySlot.GetValue(__instance));
|
|
||||||
if (displaySlot != null)
|
|
||||||
{
|
|
||||||
if (displaySlot.HasProduct)
|
|
||||||
{
|
|
||||||
//Plugin.StaticLogger.LogInfo("Label is shelf");
|
|
||||||
var cube = __instance.gameObject.transform.GetChild(0).GetChild(0);
|
|
||||||
var canvasbg = __instance.gameObject.transform.GetChild(1).GetChild(0);
|
|
||||||
|
|
||||||
var mat = cube.GetComponent<MeshRenderer>().material;
|
|
||||||
var color = mat.color.ToHex();
|
|
||||||
//Plugin.StaticLogger.LogInfo("Color is " + color);
|
|
||||||
if (color == "#FFD53A" || color == "#FFEB04")
|
|
||||||
{
|
|
||||||
//Plugin.StaticLogger.LogInfo("Making label red");
|
|
||||||
mat.color = Color.red;
|
|
||||||
canvasbg.GetComponent<RawImage>().enabled = false;
|
|
||||||
Plugin.RedLabels.Add(__instance);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
mat.color = Color.yellow;
|
|
||||||
canvasbg.GetComponent<RawImage>().enabled = true;
|
|
||||||
Plugin.RedLabels.Remove(__instance);
|
|
||||||
}
|
|
||||||
//Plugin.StaticLogger.LogWarning("Returning true");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue