add: now using coroutines with SurvivalInteractable and KeyBehaviour

This commit is contained in:
ALittlePatate
2022-09-10 21:54:11 +02:00
parent d8714b627b
commit 73aa8806ad
3 changed files with 55 additions and 20 deletions

View File

@@ -48,13 +48,13 @@ namespace DevourClient.Hacks
public static void WalkInLobby(bool walk) public static void WalkInLobby(bool walk)
{ {
try { try {
if (Helpers.LocalPlayer.LocalPlayer_.GetComponent<UltimateCharacterLocomotionHandler>() == null) if (Helpers.Entities.LocalPlayer_.GetComponent<UltimateCharacterLocomotionHandler>() == null)
{ {
Helpers.LocalPlayer.LocalPlayer_.AddComponent<UltimateCharacterLocomotionHandler>(); Helpers.Entities.LocalPlayer_.AddComponent<UltimateCharacterLocomotionHandler>();
Helpers.LocalPlayer.LocalPlayer_.GetComponent<UltimateCharacterLocomotionHandler>().enabled = false; Helpers.Entities.LocalPlayer_.GetComponent<UltimateCharacterLocomotionHandler>().enabled = false;
} }
Helpers.LocalPlayer.LocalPlayer_.GetComponent<UltimateCharacterLocomotionHandler>().enabled = walk; Helpers.Entities.LocalPlayer_.GetComponent<UltimateCharacterLocomotionHandler>().enabled = walk;
} }
catch { return; } catch { return; }
} }
@@ -122,10 +122,7 @@ namespace DevourClient.Hacks
{ {
NolanBehaviour Nolan = Player.GetPlayer(); NolanBehaviour Nolan = Player.GetPlayer();
List<SurvivalInteractable> items = new List<SurvivalInteractable>(); foreach (SurvivalInteractable item in Helpers.Entities.SurvivalInteractables)
items = Object.FindObjectsOfType<SurvivalInteractable>().ToList<SurvivalInteractable>();
foreach (SurvivalInteractable item in items)
{ {
item.transform.position = Nolan.transform.position + Nolan.transform.forward * Random.RandomRange(1f, 3f); item.transform.position = Nolan.transform.position + Nolan.transform.forward * Random.RandomRange(1f, 3f);
} }
@@ -215,7 +212,7 @@ namespace DevourClient.Hacks
{ {
NolanBehaviour Nolan = Player.GetPlayer(); //UnityEngine.Object.FindObjectOfType<NolanBehaviour>(); NolanBehaviour Nolan = Player.GetPlayer(); //UnityEngine.Object.FindObjectOfType<NolanBehaviour>();
foreach (KeyBehaviour keyBehaviour in UnityEngine.Object.FindObjectsOfType<KeyBehaviour>()) foreach (KeyBehaviour keyBehaviour in Helpers.Entities.Keys)
{ {
bool flag = keyBehaviour == null; bool flag = keyBehaviour == null;
if (flag) if (flag)

View File

@@ -20,12 +20,12 @@ namespace DevourClient.Helpers
public static NolanBehaviour GetPlayer() public static NolanBehaviour GetPlayer()
{ {
if (LocalPlayer.LocalPlayer_ == null) if (Entities.LocalPlayer_ == null)
{ {
return null; return null;
} }
return LocalPlayer.LocalPlayer_.GetComponent<NolanBehaviour>(); return Entities.LocalPlayer_.GetComponent<NolanBehaviour>();
} }
public static bool IsPlayerCrawling() public static bool IsPlayerCrawling()
@@ -42,9 +42,12 @@ namespace DevourClient.Helpers
} }
public class LocalPlayer public class Entities
{ {
public static GameObject LocalPlayer_; public static GameObject LocalPlayer_;
public static GoatBehaviour[] GoatsAndRats;
public static SurvivalInteractable[] SurvivalInteractables;
public static KeyBehaviour[] Keys;
public static IEnumerator GetLocalPlayer() public static IEnumerator GetLocalPlayer()
{ {
@@ -79,5 +82,38 @@ namespace DevourClient.Helpers
return result; return result;
} }
public static IEnumerator GetGoatsAndRats()
{
for (;;)
{
GoatsAndRats = GoatBehaviour.FindObjectsOfType<GoatBehaviour>();
// Wait 5 seconds before caching objects again.
yield return new WaitForSeconds(5f);
}
}
public static IEnumerator GetSurvivalInteractables()
{
for (;;)
{
SurvivalInteractables = SurvivalInteractable.FindObjectsOfType<SurvivalInteractable>();
// Wait 5 seconds before caching objects again.
yield return new WaitForSeconds(5f);
}
}
public static IEnumerator GetKeys()
{
for (;;)
{
Keys = KeyBehaviour.FindObjectsOfType<KeyBehaviour>();
// Wait 5 seconds before caching objects again.
yield return new WaitForSeconds(5f);
}
}
} }
} }

View File

@@ -39,7 +39,10 @@ namespace DevourClient
public override void OnApplicationStart() public override void OnApplicationStart()
{ {
MelonLogger.Msg("For the Queen !"); MelonLogger.Msg("For the Queen !");
MelonCoroutines.Start(Helpers.LocalPlayer.GetLocalPlayer()); MelonCoroutines.Start(Helpers.Entities.GetLocalPlayer());
MelonCoroutines.Start(Helpers.Entities.GetGoatsAndRats());
MelonCoroutines.Start(Helpers.Entities.GetSurvivalInteractables());
MelonCoroutines.Start(Helpers.Entities.GetKeys());
} }
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
@@ -130,7 +133,7 @@ namespace DevourClient
{ {
try try
{ {
Helpers.LocalPlayer.LocalPlayer_.GetComponent<Opsive.UltimateCharacterController.Character.UltimateCharacterLocomotion>().TimeScale = this._PlayerSpeedMultiplier; Helpers.Entities.LocalPlayer_.GetComponent<Opsive.UltimateCharacterController.Character.UltimateCharacterLocomotion>().TimeScale = this._PlayerSpeedMultiplier;
} }
catch { return; } catch { return; }
} }
@@ -179,12 +182,11 @@ namespace DevourClient
if (this.goat_rat_esp) if (this.goat_rat_esp)
{ {
foreach (GoatBehaviour goat in UnityEngine.Object.FindObjectsOfType<GoatBehaviour>() as UnhollowerBaseLib.Il2CppReferenceArray<GoatBehaviour>) foreach (GoatBehaviour goat in Helpers.Entities.GoatsAndRats)
{ {
if (goat != null) if (goat != null)
{ {
Vector3 pivotPos = goat.transform.position; //Pivot point NOT at the origin, at the center Vector3 pivotPos = goat.transform.position; //Pivot point NOT at the origin, at the center
Vector3 playerFootPos; playerFootPos.x = pivotPos.x; playerFootPos.z = pivotPos.z; playerFootPos.y = pivotPos.y - 2f; //At the feet Vector3 playerFootPos; playerFootPos.x = pivotPos.x; playerFootPos.z = pivotPos.z; playerFootPos.y = pivotPos.y - 2f; //At the feet
Vector3 playerHeadPos; Vector3 playerHeadPos;
@@ -211,7 +213,7 @@ namespace DevourClient
if (this.item_esp) if (this.item_esp)
{ {
foreach (SurvivalInteractable obj in UnityEngine.Object.FindObjectsOfType<SurvivalInteractable>() as UnhollowerBaseLib.Il2CppReferenceArray<SurvivalInteractable>) foreach (SurvivalInteractable obj in Helpers.Entities.SurvivalInteractables)
{ {
if (obj != null) if (obj != null)
{ {
@@ -242,7 +244,7 @@ namespace DevourClient
} }
} }
foreach (KeyBehaviour key in UnityEngine.Object.FindObjectsOfType<KeyBehaviour>() as UnhollowerBaseLib.Il2CppReferenceArray<KeyBehaviour>) foreach (KeyBehaviour key in Helpers.Entities.Keys)
{ {
if (key != null) if (key != null)
{ {