Files
MMOKitchen/Patches/ConsentElementPatch.cs
T

56 lines
2.1 KiB
C#
Raw Permalink Normal View History

2024-04-01 08:12:01 +11:00
using HarmonyLib;
using Kitchen;
using Kitchen.Modules;
using KitchenLib.Preferences;
using KitchenLib.Utils;
using System.Collections.Generic;
using System.Reflection;
using UnityEngine;
namespace MMOKitchen.Patches
{
[HarmonyPatch(typeof(ConsentElement), "Update")]
public class ConsentElementPatch
{
public static bool Prefix(ConsentElement __instance)
{
PlayerManager pm = Unity.Entities.World.DefaultGameObjectInjectionWorld.GetExistingSystem<PlayerManager>();
if (pm == null)
{
return true;
}
MethodInfo updateBar = ReflectionUtils.GetMethod<ConsentElement>("UpdateBar");
MethodInfo getProgressSpeed = ReflectionUtils.GetMethod<ConsentElement>("GetProgressSpeed");
FieldInfo progress = ReflectionUtils.GetField<ConsentElement>("Progress");
PropertyInfo isCompleted = AccessTools.Property(typeof(ConsentElement), "IsCompleted");
FieldInfo consentsSwap = ReflectionUtils.GetField<ConsentElement>("ConsentsSwap");
Dictionary<int, bool> x = (Dictionary<int, bool>)consentsSwap.GetValue(__instance);
int counter = 0;
foreach (int y in x.Keys)
if (x[y])
counter++;
float progressSpeed = (float)getProgressSpeed.Invoke(__instance, new object[] { });
2026-03-05 17:09:17 +11:00
if ((((float)counter / (float)x.Count) * 100) >= Mod.manager.GetPreference<PreferenceInt>(Mod.PREFERENCE_REQUIRED_CONSENT_PERCENTAGE).Value)
2024-04-01 08:12:01 +11:00
progressSpeed = 1f;
if (progressSpeed <= 0f)
progress.SetValue(__instance, (float)progress.GetValue(__instance) - (2f * Time.unscaledDeltaTime));
else
progress.SetValue(__instance, (float)progress.GetValue(__instance) + (progressSpeed * Time.unscaledDeltaTime));
isCompleted.SetValue(__instance, ((float)progress.GetValue(__instance) >= 1f));
progress.SetValue(__instance, Mathf.Clamp01((float)progress.GetValue(__instance)));
updateBar.Invoke(__instance, new object[] { });
return false;
}
}
}