using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using ArmSlider;
using HarmonyLib;
using Il2CppRUMBLE.Interactions.InteractionBase;
using Il2CppRUMBLE.Managers;
using Il2CppRUMBLE.Utilities;
using MelonLoader;
using RumbleModUI;
using RumbleModdingAPI;
using UnityEngine;
using UnityEngine.Events;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: MelonInfo(typeof(Slider), "ArmSlider", "1.0.1", "MasterMischief", null)]
[assembly: MelonGame("Buckethead Entertainment", "RUMBLE")]
[assembly: VerifyLoaderVersion(0, 6, 2, true)]
[assembly: AssemblyTitle("ArmSlider")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ArmSlider")]
[assembly: AssemblyCopyright("Copyright © 2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("21d6496e-1beb-4179-9061-082d7591b23e")]
[assembly: AssemblyFileVersion("1.0.1")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyVersion("1.0.1.0")]
namespace ArmSlider;
public class Slider : MelonMod
{
public class ValueChangedEventArgs : EventArgs
{
public float Value { get; private set; }
public ValueChangedEventArgs(float value)
{
Value = value;
}
}
public class ActiveChangedEventArgs : EventArgs
{
public bool Active { get; private set; }
public ActiveChangedEventArgs(bool active)
{
Active = active;
}
}
public class Setting
{
private float value;
private bool active;
public float Min { get; private set; }
public float Max { get; private set; }
public int DecimalPlaces { get; private set; }
public float Value
{
get
{
return value;
}
set
{
this.value = value;
if (activeOption == settingsReversed[this])
{
MelonCoroutines.Start(LateUpdateSlider(value));
}
this.ValueChanged?.Invoke(this, new ValueChangedEventArgs(value));
}
}
public bool Active
{
get
{
return active;
}
set
{
active = value;
ModSetting val = settingsReversed[this];
val.SavedValueChanged -= SliderChanged;
val.Value = value;
val.SavedValue = value;
if (sliderOptions.GetUIStatus())
{
UI.instance.ForceRefresh();
}
val.SavedValueChanged += SliderChanged;
if (value)
{
activeOption = val;
slider.SetActive(true);
MelonCoroutines.Start(LateUpdateSlider(this.value));
}
else if (activeOption == val)
{
activeOption = null;
if ((Object)(object)slider != (Object)null)
{
slider.SetActive(false);
}
}
this.ActiveChanged?.Invoke(this, new ActiveChangedEventArgs(value));
}
}
public event EventHandler<ValueChangedEventArgs> ValueChanged;
public event EventHandler<ActiveChangedEventArgs> ActiveChanged;
public Setting(float min, float max, int decimalPlaces, float value, bool active)
{
Min = min;
Max = max;
DecimalPlaces = decimalPlaces;
this.value = value;
this.active = active;
}
}
[HarmonyPatch(typeof(InteractionHand), "StartPreInteraction")]
private static class InteractionHand_StartPreInteraction_Patch
{
private static bool Prefix(InteractionHand __instance, InteractionBase interaction)
{
if ((Object)(object)((Component)__instance).gameObject == (Object)(object)((Component)((Component)Singleton<PlayerManager>.instance.localPlayer.Controller).gameObject.transform.GetChild(1).GetChild(1)).gameObject && ((Object)((Component)interaction).transform.parent).name == "SettingSlider")
{
return false;
}
return true;
}
}
private static GameObject templateSlider;
private static GameObject slider;
private static Mod sliderOptions = new Mod();
private static ModSetting activeOption = null;
private static Dictionary<ModSetting, Setting> settings = new Dictionary<ModSetting, Setting>();
private static Dictionary<Setting, ModSetting> settingsReversed = new Dictionary<Setting, ModSetting>();
public override void OnLateInitializeMelon()
{
UI.instance.UI_Initialized += OnUIInit;
}
public override void OnSceneWasLoaded(int buildIndex, string sceneName)
{
sliderOptions.ModName = "ArmSlider";
sliderOptions.ModVersion = "1.0.1";
sliderOptions.SetFolder("ArmSlider");
sliderOptions.SetLinkGroup(1, "");
}
public override void OnFixedUpdate()
{
//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
//IL_01eb: Unknown result type (might be due to invalid IL or missing references)
//IL_020f: Unknown result type (might be due to invalid IL or missing references)
if (Scene.GetSceneName() == "Gym" && (Object)(object)templateSlider == (Object)null)
{
templateSlider = Object.Instantiate<GameObject>(((Component)AudioSlab.GetGameObject().transform.GetChild(0).GetChild(0)).gameObject);
((Object)templateSlider).name = "TemplateSlider";
templateSlider.SetActive(false);
Object.DontDestroyOnLoad((Object)(object)templateSlider);
}
if (!((Object)(object)slider == (Object)null) || !((Object)(object)templateSlider != (Object)null) || !((Object)(object)Singleton<PlayerManager>.instance != (Object)null) || Singleton<PlayerManager>.instance.localPlayer == null || !((Object)(object)Singleton<PlayerManager>.instance.localPlayer.Controller != (Object)null))
{
return;
}
slider = Object.Instantiate<GameObject>(templateSlider, ((Component)Singleton<PlayerManager>.instance.localPlayer.Controller).gameObject.transform.GetChild(5).GetChild(7).GetChild(0)
.GetChild(2)
.GetChild(0)
.GetChild(1)
.GetChild(0)
.GetChild(0));
((Object)slider).name = "SettingSlider";
sliderOptions.GetFromFile();
for (int i = 0; i < sliderOptions.Settings.Count; i++)
{
try
{
if ((bool)sliderOptions.Settings[i].SavedValue)
{
activeOption = sliderOptions.Settings[i];
break;
}
}
catch
{
}
}
slider.SetActive(activeOption != null);
slider.transform.localPosition = new Vector3(0.02f, 0.08f, 0.02f);
slider.transform.localRotation = Quaternion.Euler(355f, 320f, 273f);
slider.transform.localScale = new Vector3(0.5f, 0.5f, 0.5f);
MelonCoroutines.Start(LateUpdateSlider((activeOption == null) ? 0f : settings[activeOption].Value));
InteractionSlider componentInChildren = slider.GetComponentInChildren<InteractionSlider>();
((UnityEvent<float>)(object)((InteractionNumericalBase)componentInChildren).OnNormalizedValueChanged).AddListener(UnityAction<float>.op_Implicit((Action<float>)delegate(float value)
{
if (activeOption != null)
{
Setting setting = settings[activeOption];
setting.Value = (float)Math.Round(setting.Min + value * (setting.Max - setting.Min), setting.DecimalPlaces);
}
}));
((InteractionBase)componentInChildren).interactionDistancePercentage = 0.6f;
((InteractionBase)componentInChildren).usePreInteractionLerps = false;
}
private static void OnUIInit()
{
//IL_002b: Unknown result type (might be due to invalid IL or missing references)
//IL_0030: Unknown result type (might be due to invalid IL or missing references)
//IL_003d: Expected O, but got Unknown
if (sliderOptions.Settings.Count == 0)
{
sliderOptions.AddDescription("No slider options found", "", "No slider-compatible settings were found. Make sure you installed a mod that uses the slider, such as SettingsUI.", new Tags
{
IsSummary = true
});
}
UI.instance.AddMod(sliderOptions);
}
private static void SliderChanged(object sender, EventArgs args)
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_0011: Expected O, but got Unknown
settings[(ModSetting)sender].Active = ((ValueChange<bool>)(object)args).Value;
}
private static IEnumerator LateUpdateSlider(float value)
{
yield return null;
UpdateSlider(value);
}
private static void UpdateSlider(float value)
{
if ((Object)(object)slider != (Object)null && activeOption != null)
{
Setting setting = settings[activeOption];
InteractionSlider componentInChildren = slider.GetComponentInChildren<InteractionSlider>();
((InteractionNumericalBase)componentInChildren).MoveToValue(((InteractionNumericalBase)componentInChildren).ConvertToValue(Math.Min(Math.Max((value - setting.Min) / (setting.Max - setting.Min), 0f), 1f)));
}
}
public static Setting AddSetting(string name, string description, float minValue, float maxValue, float defaultValue, int decimalPlaces = 0)
{
//IL_000a: Unknown result type (might be due to invalid IL or missing references)
//IL_0014: Expected O, but got Unknown
ModSetting<bool> val = sliderOptions.AddToList(name, false, 1, description, new Tags());
((ModSetting)val).SavedValueChanged += SliderChanged;
float num = Math.Min(minValue, maxValue);
float num2 = Math.Max(minValue, maxValue);
decimalPlaces = Math.Max(decimalPlaces, 0);
float value = Math.Min(Math.Max(defaultValue, num), num2);
bool active = false;
Setting setting = new Setting(num, num2, decimalPlaces, value, active);
settings.Add((ModSetting)(object)val, setting);
settingsReversed.Add(setting, (ModSetting)(object)val);
if (sliderOptions.GetUIStatus())
{
UI.instance.ForceRefresh();
}
return setting;
}
}