Better avatar setup detection

This commit is contained in:
SDraw 2022-09-02 21:25:40 +03:00
parent 2f9a46e471
commit 0794564563
No known key found for this signature in database
GPG key ID: BB95B4DAB2BB8BB5
5 changed files with 38 additions and 50 deletions

View file

@ -20,11 +20,10 @@ namespace ml_amt
null,
new HarmonyLib.HarmonyMethod(typeof(AvatarMotionTweaker).GetMethod(nameof(OnAvatarClear_Postfix), System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static))
);
HarmonyInstance.Patch(
typeof(PlayerSetup).GetMethod(nameof(PlayerSetup.SetupAvatar)),
typeof(PlayerSetup).GetMethod("SetupAvatarGeneral", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic),
null,
new HarmonyLib.HarmonyMethod(typeof(AvatarMotionTweaker).GetMethod(nameof(OnLocalAvatarSetup_Postfix), System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static))
new HarmonyLib.HarmonyMethod(typeof(AvatarMotionTweaker).GetMethod(nameof(OnSetupAvatarGeneral_Postfix), System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic))
);
MelonLoader.MelonCoroutines.Start(WaitForLocalPlayer());
@ -44,18 +43,18 @@ namespace ml_amt
m_localTweaker.SetCrouchLimit(p_value);
}
static void OnLocalAvatarSetup_Postfix() => ms_instance?.OnLocalAvatarSetup();
void OnLocalAvatarSetup()
{
if((m_localTweaker != null) && !PlayerSetup.Instance._inVr)
m_localTweaker.OnAvatarSetup();
}
static void OnAvatarClear_Postfix() => ms_instance?.OnAvatarClear();
void OnAvatarClear()
{
if(m_localTweaker != null)
m_localTweaker.OnAvatarClear();
}
static void OnSetupAvatarGeneral_Postfix() => ms_instance?.OnSetupAvatarGeneral();
void OnSetupAvatarGeneral()
{
if(m_localTweaker != null)
m_localTweaker.OnSetupAvatarGeneral();
}
}
}

View file

@ -46,12 +46,6 @@ namespace ml_amt
m_parameters = new List<AdditionalParameterInfo>();
}
void Start()
{
if(PlayerSetup.Instance._inVr)
PlayerSetup.Instance.avatarSetupCompleted.AddListener(this.OnAvatarSetup);
}
void Update()
{
if(m_ready)
@ -96,8 +90,8 @@ namespace ml_amt
public void OnAvatarClear()
{
m_vrIk = null;
m_ready = false;
m_vrIk = null;
m_standing = true;
m_parameters.Clear();
m_locomotionWeight = 1f;
@ -107,7 +101,7 @@ namespace ml_amt
m_locomotionOffset = Vector3.zero;
}
public void OnAvatarSetup()
public void OnSetupAvatarGeneral()
{
m_vrIk = PlayerSetup.Instance._avatar.GetComponent<RootMotion.FinalIK.VRIK>();
@ -142,7 +136,7 @@ namespace ml_amt
l_customTransform = PlayerSetup.Instance._avatar.transform.Find("LocomotionOffset");
m_customLocomotionOffset = (l_customTransform != null);
m_locomotionOffset = m_customLocomotionOffset ? Vector3.zero : l_customTransform.localPosition;
m_locomotionOffset = m_customLocomotionOffset ? l_customTransform.localPosition : Vector3.zero;
// Apply VRIK tweaks
if(m_vrIk != null)