add: now using coroutine for getting the localplayer

This commit is contained in:
ALittlePatate
2022-09-10 21:23:03 +02:00
parent 34fea1a131
commit d8714b627b
3 changed files with 28 additions and 24 deletions

View File

@@ -48,13 +48,13 @@ namespace DevourClient.Hacks
public static void WalkInLobby(bool walk)
{
try {
if (Helpers.LocalPlayer.GetLocalPlayer().GetComponent<UltimateCharacterLocomotionHandler>() == null)
if (Helpers.LocalPlayer.LocalPlayer_.GetComponent<UltimateCharacterLocomotionHandler>() == null)
{
Helpers.LocalPlayer.GetLocalPlayer().AddComponent<UltimateCharacterLocomotionHandler>();
Helpers.LocalPlayer.GetLocalPlayer().GetComponent<UltimateCharacterLocomotionHandler>().enabled = false;
Helpers.LocalPlayer.LocalPlayer_.AddComponent<UltimateCharacterLocomotionHandler>();
Helpers.LocalPlayer.LocalPlayer_.GetComponent<UltimateCharacterLocomotionHandler>().enabled = false;
}
Helpers.LocalPlayer.GetLocalPlayer().GetComponent<UltimateCharacterLocomotionHandler>().enabled = walk;
Helpers.LocalPlayer.LocalPlayer_.GetComponent<UltimateCharacterLocomotionHandler>().enabled = walk;
}
catch { return; }
}

View File

@@ -1,8 +1,9 @@
using UnityEngine;
using Opsive.UltimateCharacterController.Character;
using System.Collections.Generic;
using System.Collections;
namespace DevourClient.Helpers
namespace DevourClient.Helpers
{
public class Player
{
@@ -19,14 +20,12 @@ using System.Collections.Generic;
public static NolanBehaviour GetPlayer()
{
foreach (NolanBehaviour nb in UnityEngine.Object.FindObjectsOfType<NolanBehaviour>())
if (LocalPlayer.LocalPlayer_ == null)
{
if (nb.entity.IsOwner)
{
return nb;
}
return null;
}
return null;
return LocalPlayer.LocalPlayer_.GetComponent<NolanBehaviour>();
}
public static bool IsPlayerCrawling()
@@ -45,22 +44,26 @@ using System.Collections.Generic;
public class LocalPlayer
{
public static GameObject player;
public static GameObject LocalPlayer_;
public static GameObject GetLocalPlayer()
public static IEnumerator GetLocalPlayer()
{
GameObject[] currentPlayers = GameObject.FindGameObjectsWithTag("Player");
for (int i = 0; i < currentPlayers.Length; i++)
for (;;)
{
if (currentPlayers[i].GetComponent<NolanBehaviour>().entity.IsOwner)
{
player = currentPlayers[i];
break;
}
}
GameObject[] currentPlayers = GameObject.FindGameObjectsWithTag("Player");
return player;
for (int i = 0; i < currentPlayers.Length; i++)
{
if (currentPlayers[i].GetComponent<NolanBehaviour>().entity.IsOwner)
{
LocalPlayer_ = currentPlayers[i];
break;
}
}
// Wait 5 seconds before caching objects again.
yield return new WaitForSeconds(5f);
}
}
public static List<GameObject> GetAllPlayers()

View File

@@ -39,6 +39,7 @@ namespace DevourClient
public override void OnApplicationStart()
{
MelonLogger.Msg("For the Queen !");
MelonCoroutines.Start(Helpers.LocalPlayer.GetLocalPlayer());
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
@@ -129,7 +130,7 @@ namespace DevourClient
{
try
{
Helpers.LocalPlayer.GetLocalPlayer().GetComponent<Opsive.UltimateCharacterController.Character.UltimateCharacterLocomotion>().TimeScale = this._PlayerSpeedMultiplier;
Helpers.LocalPlayer.LocalPlayer_.GetComponent<Opsive.UltimateCharacterController.Character.UltimateCharacterLocomotion>().TimeScale = this._PlayerSpeedMultiplier;
}
catch { return; }
}