This commit is contained in:
Lachlan Leone
2024-04-01 08:12:01 +11:00
parent 581420da87
commit 35d3fec3de
34 changed files with 336 additions and 448 deletions
+55
View File
@@ -0,0 +1,55 @@
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[] { });
if ((((float)counter / (float)x.Count) * 100) >= Mod.manager.GetPreference<PreferenceInt>("requiredConsentPercentage").Value)
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;
}
}
}
+37
View File
@@ -0,0 +1,37 @@
using HarmonyLib;
using Kitchen;
using KitchenLib.Preferences;
namespace MMOKitchen.Patches
{
[HarmonyPatch(typeof(DifficultyHelpers))]
public class DifficultyHelpersPatch
{
[HarmonyPatch("CustomerPlayersRateModifier")]
[HarmonyPostfix]
static void CustomerPlayersRateModifier_Postfix(ref float __result, int player_count)
{
if (Mod.manager.GetPreference<PreferenceBool>("scaleAbove4Players").Value)
if (player_count > 4)
__result = 1 + (player_count * Mod.manager.GetPreference<PreferenceFloat>("scaleAbove4PlayersMultiplier").Value);
}
[HarmonyPatch("FireSpreadModifier")]
[HarmonyPostfix]
static void FireSpreadModifier_Postfix(ref float __result, int player_count)
{
if (Mod.manager.GetPreference<PreferenceBool>("scaleAbove4Players").Value)
if (player_count > 4)
__result = 0.75f + (player_count * Mod.manager.GetPreference<PreferenceFloat>("scaleAbove4PlayersMultiplier").Value);
}
[HarmonyPatch("PatiencePlayerCountModifier")]
[HarmonyPostfix]
static void PatiencePlayerCountModifier_Postfix(ref float __result, int player_count)
{
if (Mod.manager.GetPreference<PreferenceBool>("scaleAbove4Players").Value)
if (player_count > 4)
__result = 0.75f + (player_count * Mod.manager.GetPreference<PreferenceFloat>("scaleAbove4PlayersMultiplier").Value);
}
}
}
+17
View File
@@ -0,0 +1,17 @@
using HarmonyLib;
using Kitchen;
using KitchenLib.Utils;
using System.Reflection;
namespace MMOKitchen.Patches
{
[HarmonyPatch(typeof(PlayerManager), "GetLeastUnusedIndex")]
public class PlayerManagerPatch
{
static void Prefix(PlayerManager __instance)
{
FieldInfo info = ReflectionUtils.GetField<PlayerManager>("MaxPlayers");
info.SetValue(__instance, Mod.MaxPlayers);
}
}
}
+42
View File
@@ -0,0 +1,42 @@
using HarmonyLib;
using Kitchen.NetworkSupport;
using Steamworks;
using Steamworks.Data;
using System;
using System.Reflection;
using System.Threading.Tasks;
namespace MMOKitchen.Patches
{
/*
* This patch is used to change how many players can join the lobby using Steam.
*/
[HarmonyPatch(typeof(SteamPlatform), "CreateNewLobby")]
public class SteamPlatformPatch
{
public static bool Prefix(SteamPlatform __instance, Action<bool, Lobby> callback)
{
if (__instance.IsReady)
{
SteamMatchmaking.CreateLobbyAsync(Mod.MaxPlayers).ContinueWith(delegate (Task<Lobby?> task)
{
if (task.IsCompleted && task.Result != null)
{
Lobby valueOrDefault = task.Result.GetValueOrDefault();
__instance.CurrentInviteLobby = valueOrDefault;
MethodInfo performSetPermissions = AccessTools.Method(typeof(SteamPlatform), "PerformSetPermissions");
performSetPermissions.Invoke(__instance, new object[] { __instance.Permissions });
callback(true, valueOrDefault);
}
else
{
callback(false, default(Lobby));
}
});
}
return false;
}
}
}