Update to build 2023r171ex7p2

This commit is contained in:
SDraw 2023-06-28 08:16:36 +03:00
parent 6f8fa13c94
commit d210ed4636
No known key found for this signature in database
GPG key ID: BB95B4DAB2BB8BB5
76 changed files with 3349 additions and 1220 deletions

View file

@ -0,0 +1,114 @@
using ABI.CCK.Components;
using ABI_RC.Core.Player;
using ABI_RC.Core.Savior;
using ABI_RC.Systems.MovementSystem;
using System;
using System.Collections;
using System.Reflection;
using UnityEngine;
namespace ml_amt.Fixes
{
static class MovementJumpFix
{
static FieldInfo ms_avatarHeight = typeof(PlayerSetup).GetField("_avatarHeight", BindingFlags.NonPublic | BindingFlags.Instance);
static float ms_playerHeight = 1f;
internal static void Init(HarmonyLib.Harmony p_instance)
{
p_instance.Patch(
typeof(PlayerSetup).GetMethod(nameof(PlayerSetup.SetupAvatar)),
null,
new HarmonyLib.HarmonyMethod(typeof(MovementJumpFix).GetMethod(nameof(OnSetupAvatar_Postfix), BindingFlags.Static | BindingFlags.NonPublic))
);
p_instance.Patch(
typeof(CVRWorld).GetMethod("SetupWorldRules", BindingFlags.NonPublic | BindingFlags.Instance),
null,
new HarmonyLib.HarmonyMethod(typeof(MovementJumpFix).GetMethod(nameof(OnWorldRulesSetup_Postfix), BindingFlags.Static | BindingFlags.NonPublic))
);
p_instance.Patch(
typeof(PlayerSetup).GetMethod("SetupIKScaling", BindingFlags.NonPublic | BindingFlags.Instance),
null,
new HarmonyLib.HarmonyMethod(typeof(MovementJumpFix).GetMethod(nameof(OnSetupIKScaling_Postfix), BindingFlags.Static | BindingFlags.NonPublic))
);
Settings.ScaledJumpChange += OnScaledJumpChange;
MelonLoader.MelonCoroutines.Start(WaitForGameSettings());
}
static IEnumerator WaitForGameSettings()
{
while(MetaPort.Instance == null)
yield return null;
while(MetaPort.Instance.settings == null)
yield return null;
ms_playerHeight = MetaPort.Instance.settings.GetSettingInt("GeneralPlayerHeight") * 0.01f;
MetaPort.Instance.settings.settingIntChanged.AddListener(OnGameSettingIntChange);
}
// Patches
static void OnSetupAvatar_Postfix()
{
try
{
SetScaledJump(Settings.ScaledJump);
}
catch(Exception e)
{
MelonLoader.MelonLogger.Error(e);
}
}
static void OnWorldRulesSetup_Postfix()
{
try
{
SetScaledJump(Settings.ScaledJump);
}
catch(Exception e)
{
MelonLoader.MelonLogger.Error(e);
}
}
static void OnSetupIKScaling_Postfix()
{
try
{
SetScaledJump(Settings.ScaledJump);
}
catch(Exception l_exception)
{
MelonLoader.MelonLogger.Error(l_exception);
}
}
// Mod settings
static void OnScaledJumpChange(bool p_state)
{
SetScaledJump(p_state);
}
// Game settings
static void OnGameSettingIntChange(string p_name, int p_value)
{
if(p_name == "GeneralPlayerHeight")
{
ms_playerHeight = p_value * 0.01f;
}
}
// Arbitrary
static void SetScaledJump(bool p_state)
{
if(Utils.IsWorldSafe())
{
if(p_state)
MovementSystem.Instance.jumpHeight = Mathf.Clamp(Utils.GetWorldJumpHeight() * ((float)ms_avatarHeight.GetValue(PlayerSetup.Instance) / ms_playerHeight), float.MinValue, Utils.GetWorldMovementLimit());
else
MovementSystem.Instance.jumpHeight = Utils.GetWorldJumpHeight();
}
}
}
}