using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using DarkMachine.UI;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Newtonsoft.Json;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.SceneManagement;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("wk_stamina_hsv")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("Stamina HSV Slider")]
[assembly: AssemblyTitle("wk_stamina_hsv")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Embedded]
[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
internal sealed class RefSafetyRulesAttribute : Attribute
{
public readonly int Version;
public RefSafetyRulesAttribute(int P_0)
{
Version = P_0;
}
}
}
namespace wk_stamina_hsv
{
[BepInPlugin("wk_stamina_hsv", "Stamina HSV Slider", "1.0.0")]
public class Plugin : BaseUnityPlugin
{
internal static ManualLogSource Logger;
private static Harmony harmony;
public void Awake()
{
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
//IL_001b: Expected O, but got Unknown
Logger = ((BaseUnityPlugin)this).Logger;
harmony = new Harmony("wk_stamina_hsv");
Type[] types = Assembly.GetExecutingAssembly().GetTypes();
Type[] array = types;
foreach (Type type in array)
{
try
{
harmony.CreateClassProcessor(type).Patch();
}
catch (Exception ex)
{
Logger.LogError((object)("[Harmony] patch " + type.FullName + " failed: " + ex.Message));
}
}
Logger.LogInfo((object)"wk_stamina_hsv 1.0.0 has loaded!");
}
public void OnDestroy()
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
//IL_0019: Unknown result type (might be due to invalid IL or missing references)
//IL_001e: Unknown result type (might be due to invalid IL or missing references)
Scene val = ((Component)this).gameObject.scene;
if (((Scene)(ref val)).isLoaded)
{
val = SceneManager.GetActiveScene();
Plugin plugin = ((Scene)(ref val)).GetRootGameObjects()[0].AddComponent<Plugin>();
if ((Object)(object)plugin == (Object)null)
{
Logger.LogFatal((object)"Plugin is being destroyed!");
harmony.UnpatchSelf();
}
}
}
}
[HarmonyPatch(typeof(UI_CosmeticInfoPanel), "UpdateSprite")]
public static class StaminaHSVFlag
{
public static GameObject staminaHSVRoot;
public static SubmitSlider staminaHueSlider;
public static SubmitSlider staminaSaturationSlider;
public static SubmitSlider staminaValueSlider;
public static Cosmetic_HandItem cosmetic_handItem;
public static Vector3 hsv;
private static float HSV_BoundsConvert(float v)
{
return (v + 1f) / 2f;
}
private static void SetStaminaColor()
{
//IL_0038: Unknown result type (might be due to invalid IL or missing references)
//IL_003d: Unknown result type (might be due to invalid IL or missing references)
cosmetic_handItem.cosmeticData.customStaminaColor = Color.HSVToRGB(HSV_BoundsConvert(hsv.x), HSV_BoundsConvert(hsv.y), HSV_BoundsConvert(hsv.z));
}
public static void SetHue(float h)
{
ManualLogSource logger = Plugin.Logger;
if (staminaHueSlider == null)
{
if (logger != null)
{
logger.LogFatal((object)"[stamina-hsv-sethue] stamina hue slider is null.");
}
}
else
{
hsv.x = h;
SetStaminaColor();
UpdateCosmeticSaveData();
}
}
public static void SetSaturation(float s)
{
ManualLogSource logger = Plugin.Logger;
if (staminaSaturationSlider == null)
{
if (logger != null)
{
logger.LogFatal((object)"[stamina-hsv-setsaturation] stamina saturation slider is null.");
}
}
else
{
hsv.y = s;
SetStaminaColor();
UpdateCosmeticSaveData();
}
}
public static void SetValue(float v)
{
ManualLogSource logger = Plugin.Logger;
if (staminaValueSlider == null)
{
if (logger != null)
{
logger.LogFatal((object)"[stamina-hsv-setvalue] stamina value slider is null.");
}
}
else
{
hsv.z = v;
SetStaminaColor();
UpdateCosmeticSaveData();
}
}
private static void UpdateCosmeticSaveData()
{
//IL_0016: Unknown result type (might be due to invalid IL or missing references)
//IL_001b: Unknown result type (might be due to invalid IL or missing references)
StaminaPreferences.SetStaminaHSV(cosmetic_handItem.cosmeticData.cosmeticName, new StaminaPreferences.Entry
{
hsv = hsv
});
}
public static void Postfix(UI_CosmeticInfoPanel __instance)
{
//IL_0256: Unknown result type (might be due to invalid IL or missing references)
//IL_025b: Unknown result type (might be due to invalid IL or missing references)
bool active = false;
if (__instance.selectedCosmetic.cosmeticInfo.flags?.Contains("stamina-hsv") ?? false)
{
Cosmetic_Base selectedCosmetic = __instance.selectedCosmetic;
cosmetic_handItem = (Cosmetic_HandItem)(object)((selectedCosmetic is Cosmetic_HandItem) ? selectedCosmetic : null);
active = true;
if ((Object)(object)staminaHSVRoot == (Object)null)
{
ManualLogSource logger = Plugin.Logger;
SubmitSlider[] componentsInChildren = __instance.settingRoot.GetComponentsInChildren<SubmitSlider>();
GameObject val = null;
val = ((Component)__instance.settingRoot.transform.Find("Slider - Stamina HSV")).gameObject;
if ((Object)(object)val == (Object)null)
{
if (logger != null)
{
logger.LogFatal((object)"[stamina-hsv-flag] couldn't find the stamina HSV slider root object.");
}
return;
}
staminaHueSlider = ((Component)val.transform.Find("Slider-Hue")).GetComponent<SubmitSlider>();
staminaSaturationSlider = ((Component)val.transform.Find("Slider-Saturation")).GetComponent<SubmitSlider>();
staminaValueSlider = ((Component)val.transform.Find("Slider-Value")).GetComponent<SubmitSlider>();
staminaHSVRoot = val;
}
((UnityEventBase)staminaHueSlider.onValueChanged).m_Calls.ClearPersistent();
((UnityEventBase)staminaSaturationSlider.onValueChanged).m_Calls.ClearPersistent();
((UnityEventBase)staminaValueSlider.onValueChanged).m_Calls.ClearPersistent();
((UnityEventBase)staminaHueSlider.onValueChanged).m_PersistentCalls.Clear();
((UnityEventBase)staminaSaturationSlider.onValueChanged).m_PersistentCalls.Clear();
((UnityEventBase)staminaValueSlider.onValueChanged).m_PersistentCalls.Clear();
((UnityEventBase)staminaHueSlider.onValueChanged).RemoveAllListeners();
((UnityEvent<float>)(object)staminaHueSlider.onValueChanged).AddListener((UnityAction<float>)SetHue);
((UnityEventBase)staminaSaturationSlider.onValueChanged).RemoveAllListeners();
((UnityEvent<float>)(object)staminaSaturationSlider.onValueChanged).AddListener((UnityAction<float>)SetSaturation);
((UnityEventBase)staminaValueSlider.onValueChanged).RemoveAllListeners();
((UnityEvent<float>)(object)staminaValueSlider.onValueChanged).AddListener((UnityAction<float>)SetValue);
hsv = GetHSV();
staminaHSVRoot.SetActive(true);
staminaHueSlider.value = hsv.x;
staminaSaturationSlider.value = hsv.y;
staminaValueSlider.value = hsv.z;
}
else
{
staminaHSVRoot.SetActive(false);
}
if (!__instance.settingRoot.gameObject.activeSelf)
{
__instance.settingRoot.gameObject.SetActive(active);
}
}
private static Vector3 GetHSV()
{
//IL_0076: Unknown result type (might be due to invalid IL or missing references)
//IL_007d: Unknown result type (might be due to invalid IL or missing references)
//IL_0083: Unknown result type (might be due to invalid IL or missing references)
//IL_0022: Unknown result type (might be due to invalid IL or missing references)
//IL_004a: Unknown result type (might be due to invalid IL or missing references)
//IL_0068: Unknown result type (might be due to invalid IL or missing references)
//IL_006a: Unknown result type (might be due to invalid IL or missing references)
//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
//IL_00be: Unknown result type (might be due to invalid IL or missing references)
//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
//IL_00af: Unknown result type (might be due to invalid IL or missing references)
//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
if (StaminaPreferences.GetStaminaHSV(cosmetic_handItem.cosmeticData.cosmeticName) == null)
{
float x = default(float);
float y = default(float);
float z = default(float);
Color.RGBToHSV(cosmetic_handItem.GetCustomStaminaColor(), ref x, ref y, ref z);
StaminaPreferences.SetStaminaHSV(cosmetic_handItem.cosmeticData.cosmeticName, new StaminaPreferences.Entry
{
hsv = new Vector3
{
x = x,
y = y,
z = z
}
});
}
if (hsv == default(Vector3))
{
hsv = StaminaPreferences.GetStaminaHSV(cosmetic_handItem.cosmeticData.cosmeticName).hsv;
return hsv;
}
return hsv;
}
}
[HarmonyPatch(typeof(CL_CosmeticManager), "Initialize")]
public static class ApplyAutomatically
{
private static float HSV_BoundsConvert(float v)
{
return (v + 1f) / 2f;
}
public static void Postfix(CL_CosmeticManager __instance, ref List<Cosmetic_HandItem> ___cosmeticHands)
{
//IL_0030: Unknown result type (might be due to invalid IL or missing references)
//IL_0035: Unknown result type (might be due to invalid IL or missing references)
//IL_003d: Unknown result type (might be due to invalid IL or missing references)
//IL_0049: Unknown result type (might be due to invalid IL or missing references)
//IL_0055: Unknown result type (might be due to invalid IL or missing references)
//IL_0061: Unknown result type (might be due to invalid IL or missing references)
//IL_0066: Unknown result type (might be due to invalid IL or missing references)
foreach (Cosmetic_HandItem ___cosmeticHand in ___cosmeticHands)
{
StaminaPreferences.Entry staminaHSV = StaminaPreferences.GetStaminaHSV(___cosmeticHand.cosmeticData.cosmeticName);
if (staminaHSV != null)
{
Vector3 hsv = staminaHSV.hsv;
___cosmeticHand.cosmeticData.customStaminaColor = Color.HSVToRGB(HSV_BoundsConvert(hsv.x), HSV_BoundsConvert(hsv.y), HSV_BoundsConvert(hsv.z));
}
}
}
}
public static class StaminaPreferences
{
public class Entry
{
public Vector3 hsv;
}
private static Dictionary<string, Entry> _staminaPreferences;
private const string fileName = "wk_stamina_hsv_state.json";
private static string PathFor()
{
string configPath = Paths.ConfigPath;
Directory.CreateDirectory(configPath);
return Path.Combine(configPath, "wk_stamina_hsv_state.json");
}
private static void EnsureLoaded()
{
if (_staminaPreferences != null)
{
return;
}
try
{
string path = PathFor();
if (File.Exists(path))
{
_staminaPreferences = JsonConvert.DeserializeObject<Dictionary<string, Entry>>(File.ReadAllText(path)) ?? new Dictionary<string, Entry>();
}
else
{
_staminaPreferences = new Dictionary<string, Entry>();
}
}
catch (Exception ex)
{
ManualLogSource logger = Plugin.Logger;
if (logger != null)
{
logger.LogWarning((object)("[stamina-hsv] load failed: " + ex.Message));
}
_staminaPreferences = new Dictionary<string, Entry>();
}
}
private static void Save()
{
//IL_000d: Unknown result type (might be due to invalid IL or missing references)
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
//IL_001f: Expected O, but got Unknown
try
{
File.WriteAllText(PathFor(), JsonConvert.SerializeObject((object)_staminaPreferences, (Formatting)1, new JsonSerializerSettings
{
ReferenceLoopHandling = (ReferenceLoopHandling)1
}));
}
catch (Exception ex)
{
Plugin.Logger.LogWarning((object)("[stamina-hsv] save failed: " + ex.Message));
}
}
public static void SetStaminaHSV(string key, Entry state)
{
EnsureLoaded();
_staminaPreferences[key] = state;
Save();
}
public static Entry GetStaminaHSV(string key)
{
EnsureLoaded();
if (!_staminaPreferences.TryGetValue(key, out var value))
{
return null;
}
return value;
}
}
public static class MyPluginInfo
{
public const string PLUGIN_GUID = "wk_stamina_hsv";
public const string PLUGIN_NAME = "Stamina HSV Slider";
public const string PLUGIN_VERSION = "1.0.0";
}
}