Add files via upload

This commit is contained in:
manafeng
2025-06-08 03:05:16 +10:00
committed by GitHub
parent 360aa1061c
commit d7597b055f
3 changed files with 687 additions and 395 deletions

View File

@@ -1,57 +1,143 @@
using UnityEngine;
using MelonLoader;
using System.Collections.Generic;
namespace DevourClient.Helpers
{
class GUIHelper
public static class GUIHelper // 改为静态类
{
private static Texture2D previewTexture;
private static GUIStyle boxStyle;
private static Dictionary<Color, Texture2D> colorTextureCache = new Dictionary<Color, Texture2D>();
private static Dictionary<int, Texture2D> circularTextureCache = new Dictionary<int, Texture2D>();
// 初始化方法
public static void Initialize()
{
if (previewTexture == null)
{
previewTexture = new Texture2D(1, 1);
boxStyle = new GUIStyle(GUI.skin.box);
}
}
// 清理方法
public static void Cleanup()
{
if (previewTexture != null)
{
UnityEngine.Object.Destroy(previewTexture);
previewTexture = null;
}
foreach (var texture in colorTextureCache.Values)
{
if (texture != null)
{
UnityEngine.Object.Destroy(texture);
}
}
colorTextureCache.Clear();
foreach (var texture in circularTextureCache.Values)
{
if (texture != null)
{
UnityEngine.Object.Destroy(texture);
}
}
circularTextureCache.Clear();
}
private static float R;
private static float G;
private static float B;
public static Color ColorPick(string title, Color color)
{
GUI.Label(new Rect(Settings.Settings.x + 195, Settings.Settings.y + 70, 250, 30), title);
Initialize(); // 确保已初始化
R = GUI.VerticalSlider(new Rect(Settings.Settings.x + 240, Settings.Settings.y + 100, 30, 90), color.r, 0f, 1f);
G = GUI.VerticalSlider(new Rect(Settings.Settings.x + 270, Settings.Settings.y + 100, 30, 90), color.g, 0f, 1f);
B = GUI.VerticalSlider(new Rect(Settings.Settings.x + 300, Settings.Settings.y + 100, 30, 90), color.b, 0f, 1f);
// 使用 GUILayout 来创建更可靠的滑动条
GUILayout.BeginArea(new Rect(Settings.Settings.x + 195, Settings.Settings.y + 70, 250, 250));
GUI.Label(new Rect(Settings.Settings.x + 240, Settings.Settings.y + 190, 30, 30), "R");
GUI.Label(new Rect(Settings.Settings.x + 270, Settings.Settings.y + 190, 30, 30), "G");
GUI.Label(new Rect(Settings.Settings.x + 300, Settings.Settings.y + 190, 30, 30), "B");
GUILayout.Label(title);
GUILayout.Space(10);
color = new Color(R, G, B, 1);
// R 通道
GUILayout.BeginHorizontal();
GUILayout.Label("R", GUILayout.Width(20));
R = GUILayout.HorizontalSlider(color.r, 0f, 1f, GUILayout.Width(150));
GUILayout.Label(((int)(R * 255)).ToString(), GUILayout.Width(30));
GUILayout.EndHorizontal();
void DrawPreview(Rect position, Color color_to_draw)
// G 通道
GUILayout.BeginHorizontal();
GUILayout.Label("G", GUILayout.Width(20));
G = GUILayout.HorizontalSlider(color.g, 0f, 1f, GUILayout.Width(150));
GUILayout.Label(((int)(G * 255)).ToString(), GUILayout.Width(30));
GUILayout.EndHorizontal();
// B 通道
GUILayout.BeginHorizontal();
GUILayout.Label("B", GUILayout.Width(20));
B = GUILayout.HorizontalSlider(color.b, 0f, 1f, GUILayout.Width(150));
GUILayout.Label(((int)(B * 255)).ToString(), GUILayout.Width(30));
GUILayout.EndHorizontal();
GUILayout.Space(10);
// 颜色预览
void DrawPreview(Color color_to_draw)
{
Texture2D texture = new Texture2D(1, 1);
texture.SetPixel(0, 0, color_to_draw);
texture.Apply();
GUIStyle boxStyle = new GUIStyle(GUI.skin.box);
boxStyle.normal.background = texture;
GUI.Box(position, GUIContent.none, boxStyle);
if (previewTexture == null)
{
previewTexture = new Texture2D(1, 1);
}
DrawPreview(new Rect(Settings.Settings.x + 195, Settings.Settings.y + 100, 20, 90), color);
previewTexture.SetPixel(0, 0, color_to_draw);
previewTexture.Apply();
boxStyle.normal.background = previewTexture;
GUILayout.Box(GUIContent.none, boxStyle, GUILayout.Height(30));
}
return color;
DrawPreview(new Color(R, G, B, 1));
GUILayout.EndArea();
return new Color(R, G, B, 1);
}
public static Texture2D MakeTex(int width, int height, Color col)
{
string cacheKey = $"{width}x{height}_{col.r}_{col.g}_{col.b}";
if (colorTextureCache.TryGetValue(col, out Texture2D cachedTexture))
{
return cachedTexture;
}
Texture2D result = new Texture2D(width, height);
Color[] pix = new Color[width * height];
for (int i = 0; i < pix.Length; ++i)
{
pix[i] = col;
}
Texture2D result = new Texture2D(width, height);
result.SetPixels(pix);
result.Apply();
colorTextureCache[col] = result;
return result;
}
public static Texture2D GetCircularTexture(int width, int height)
{
int size = Mathf.Max(width, height);
if (circularTextureCache.TryGetValue(size, out Texture2D cachedTexture))
{
return cachedTexture;
}
Texture2D texture = new Texture2D(width, height);
for (int x = 0; x < texture.width; x++)
{
@@ -70,6 +156,7 @@ namespace DevourClient.Helpers
texture.Apply();
circularTextureCache[size] = texture;
return texture;
}
}

View File

@@ -40,10 +40,12 @@
Il2CppPhoton.Bolt.BoltNetwork.LoadScene(mapName);
MelonLoader.MelonLogger.Warning("Please press the button only once, it may take some time for the map to load.");
Hacks.Misc.ShowMessageBox("Please press the button only once, it may take some time for the map to load.");
}
else
{
MelonLoader.MelonLogger.Warning("You must be the host to use this command!");
Hacks.Misc.ShowMessageBox("You must be the host to use this command!");
}
}
}

View File

@@ -48,6 +48,7 @@ namespace DevourClient.Helpers
if (!BoltNetwork.IsServer)
{
MelonLogger.Msg("You need to be server !");
Hacks.Misc.ShowMessageBox("You need to be server !");
return;
}
@@ -65,6 +66,9 @@ namespace DevourClient.Helpers
sab.OnPickedUpPlayer(sab.gameObject, p_GameObject, false);
MelonLogger.Msg(Name);
Hacks.Misc.ShowMessageBox(Name);
/*
MelonLogger.Msg(Name);
Il2Cpp.JumpScare _jumpscare = UnityEngine.Object.FindObjectOfType<Il2Cpp.JumpScare>();
@@ -110,6 +114,7 @@ namespace DevourClient.Helpers
else
{
MelonLogger.Error("Azazel not found!");
Hacks.Misc.ShowMessageBox("Azazel not found!");
return;
}
}
@@ -119,6 +124,7 @@ namespace DevourClient.Helpers
if (!BoltNetwork.IsServer)
{
MelonLogger.Msg("You need to be server !");
Hacks.Misc.ShowMessageBox("You need to be server !");
return;
}
@@ -174,6 +180,9 @@ namespace DevourClient.Helpers
public class Entities
{
private static bool isRunning = true; // Control coroutine running state
private static List<object> activeCoroutines = new List<object>(); // Track active coroutines
public static int MAX_PLAYERS = 4; //will change by calling CreateCustomizedLobby
public static BasePlayer LocalPlayer_ = new BasePlayer();
@@ -190,183 +199,377 @@ namespace DevourClient.Helpers
public static Il2Cpp.CrowBehaviour[] Crows = default!;
public static Il2Cpp.ManorLumpController[] Lumps = default!;
// Method to stop all coroutines
public static void StopAllCoroutines()
{
isRunning = false;
foreach (var coroutine in activeCoroutines)
{
if (coroutine != null)
{
MelonCoroutines.Stop(coroutine);
}
}
activeCoroutines.Clear();
// Clean up all cached objects
CleanupCachedObjects();
}
// Clean up cached objects
private static void CleanupCachedObjects()
{
if (Players != null)
{
foreach (var player in Players)
{
if (player != null)
{
player.p_GameObject = null;
}
}
Players = null;
}
LocalPlayer_.p_GameObject = null;
GoatsAndRats = null;
SurvivalInteractables = null;
Keys = null;
Demons = null;
Spiders = null;
Ghosts = null;
Azazels = null;
Boars = null;
Corpses = null;
Crows = null;
Lumps = null;
}
// Method to start all coroutines
public static void StartAllCoroutines()
{
isRunning = true;
activeCoroutines.Clear();
// Start all coroutines and save references
activeCoroutines.Add(MelonCoroutines.Start(GetLocalPlayer()));
activeCoroutines.Add(MelonCoroutines.Start(GetAllPlayers()));
activeCoroutines.Add(MelonCoroutines.Start(GetGoatsAndRats()));
activeCoroutines.Add(MelonCoroutines.Start(GetSurvivalInteractables()));
activeCoroutines.Add(MelonCoroutines.Start(GetKeys()));
activeCoroutines.Add(MelonCoroutines.Start(GetDemons()));
activeCoroutines.Add(MelonCoroutines.Start(GetSpiders()));
activeCoroutines.Add(MelonCoroutines.Start(GetGhosts()));
activeCoroutines.Add(MelonCoroutines.Start(GetBoars()));
activeCoroutines.Add(MelonCoroutines.Start(GetCorpses()));
activeCoroutines.Add(MelonCoroutines.Start(GetCrows()));
activeCoroutines.Add(MelonCoroutines.Start(GetLumps()));
activeCoroutines.Add(MelonCoroutines.Start(GetAzazels()));
}
public static IEnumerator GetLocalPlayer()
{
while (true)
while (isRunning)
{
try
{
GameObject[] currentPlayers = GameObject.FindGameObjectsWithTag("Player");
if (currentPlayers != null)
{
for (int i = 0; i < currentPlayers.Length; i++)
{
if (currentPlayers[i].GetComponent<Il2Cpp.NolanBehaviour>().entity.IsOwner)
{
// Clean up old references before updating
if (LocalPlayer_.p_GameObject != currentPlayers[i])
{
LocalPlayer_.p_GameObject = currentPlayers[i];
}
break;
}
}
}
}
catch (System.Exception e)
{
string err = $"GetLocalPlayer coroutine encountered an error: {e.Message}";
MelonLogger.Error(err);
DevourClient.Settings.Settings.errorMessage = err;
DevourClient.Settings.Settings.showErrorMessage = true;
}
// Wait 5 seconds before caching objects again.
yield return new WaitForSeconds(5f);
}
}
public static IEnumerator GetAllPlayers()
{
while (true)
while (isRunning)
{
try
{
GameObject[] players = GameObject.FindGameObjectsWithTag("Player");
Players = new BasePlayer[players.Length];
int i = 0;
foreach (GameObject p in players)
// Clean up old array before creating new one
if (Players != null)
{
string player_name = "";
string player_id = "-1";
Il2Cpp.DissonancePlayerTracking dpt = p.gameObject.GetComponent<Il2Cpp.DissonancePlayerTracking>();
if (dpt != null)
foreach (var player in Players)
{
player_name = dpt.state.PlayerName;
player_id = dpt.state.PlayerId;
if (player != null)
{
player.p_GameObject = null;
}
}
}
// Create new array
Players = new BasePlayer[players.Length];
for (int i = 0; i < players.Length; i++)
{
if (Players[i] == null)
{
Players[i] = new BasePlayer();
}
Players[i].Id = player_id;
Players[i].Name = player_name;
Players[i].p_GameObject = p;
Players[i].p_GameObject = players[i];
i++;
Il2Cpp.DissonancePlayerTracking dpt = players[i].GetComponent<Il2Cpp.DissonancePlayerTracking>();
if (dpt != null)
{
Players[i].Name = dpt.state.PlayerName;
Players[i].Id = dpt.state.PlayerId;
}
}
}
catch (System.Exception e)
{
string err = $"GetAllPlayers coroutine encountered an error: {e.Message}";
MelonLogger.Error(err);
DevourClient.Settings.Settings.errorMessage = err;
DevourClient.Settings.Settings.showErrorMessage = true;
}
// Wait 5 seconds before caching objects again.
yield return new WaitForSeconds(5f);
}
}
public static IEnumerator GetGoatsAndRats()
{
while (true)
while (isRunning)
{
try
{
GoatsAndRats = Il2Cpp.GoatBehaviour.FindObjectsOfType<Il2Cpp.GoatBehaviour>();
}
catch (System.Exception e)
{
string err = $"GetGoatsAndRats coroutine encountered an error: {e.Message}";
MelonLogger.Error(err);
DevourClient.Settings.Settings.errorMessage = err;
DevourClient.Settings.Settings.showErrorMessage = true;
}
// Wait 5 seconds before caching objects again.
yield return new WaitForSeconds(5f);
}
}
public static IEnumerator GetSurvivalInteractables()
{
while (true)
while (isRunning)
{
try
{
SurvivalInteractables = Il2Cpp.SurvivalInteractable.FindObjectsOfType<Il2Cpp.SurvivalInteractable>();
}
catch (System.Exception e)
{
string err = $"GetSurvivalInteractables coroutine encountered an error: {e.Message}";
MelonLogger.Error(err);
DevourClient.Settings.Settings.errorMessage = err;
DevourClient.Settings.Settings.showErrorMessage = true;
}
// Wait 5 seconds before caching objects again.
yield return new WaitForSeconds(5f);
}
}
public static IEnumerator GetKeys()
{
while (true)
while (isRunning)
{
try
{
Keys = Il2Cpp.KeyBehaviour.FindObjectsOfType<Il2Cpp.KeyBehaviour>();
}
catch (System.Exception e)
{
string err = $"GetKeys coroutine encountered an error: {e.Message}";
MelonLogger.Error(err);
DevourClient.Settings.Settings.errorMessage = err;
DevourClient.Settings.Settings.showErrorMessage = true;
}
// Wait 5 seconds before caching objects again.
yield return new WaitForSeconds(5f);
}
}
public static IEnumerator GetDemons()
{
while (true)
while (isRunning)
{
try
{
Demons = Il2Cpp.SurvivalDemonBehaviour.FindObjectsOfType<Il2Cpp.SurvivalDemonBehaviour>();
}
catch (System.Exception e)
{
string err = $"GetDemons coroutine encountered an error: {e.Message}";
MelonLogger.Error(err);
DevourClient.Settings.Settings.errorMessage = err;
DevourClient.Settings.Settings.showErrorMessage = true;
}
// Wait 5 seconds before caching objects again.
yield return new WaitForSeconds(5f);
}
}
public static IEnumerator GetSpiders()
{
while (true)
while (isRunning)
{
try
{
Spiders = Il2Cpp.SpiderBehaviour.FindObjectsOfType<Il2Cpp.SpiderBehaviour>();
}
catch (System.Exception e)
{
string err = $"GetSpiders coroutine encountered an error: {e.Message}";
MelonLogger.Error(err);
DevourClient.Settings.Settings.errorMessage = err;
DevourClient.Settings.Settings.showErrorMessage = true;
}
// Wait 5 seconds before caching objects again.
yield return new WaitForSeconds(5f);
}
}
public static IEnumerator GetGhosts()
{
while (true)
while (isRunning)
{
try
{
Ghosts = Il2Cpp.GhostBehaviour.FindObjectsOfType<Il2Cpp.GhostBehaviour>();
}
catch (System.Exception e)
{
string err = $"GetGhosts coroutine encountered an error: {e.Message}";
MelonLogger.Error(err);
DevourClient.Settings.Settings.errorMessage = err;
DevourClient.Settings.Settings.showErrorMessage = true;
}
// Wait 5 seconds before caching objects again.
yield return new WaitForSeconds(5f);
}
}
public static IEnumerator GetBoars()
{
while (true)
while (isRunning)
{
try
{
Boars = Il2Cpp.BoarBehaviour.FindObjectsOfType<Il2Cpp.BoarBehaviour>();
}
catch (System.Exception e)
{
string err = $"GetBoars coroutine encountered an error: {e.Message}";
MelonLogger.Error(err);
DevourClient.Settings.Settings.errorMessage = err;
DevourClient.Settings.Settings.showErrorMessage = true;
}
// Wait 5 seconds before caching objects again.
yield return new WaitForSeconds(5f);
}
}
public static IEnumerator GetCorpses()
{
while (true)
while (isRunning)
{
try
{
Corpses = Il2Cpp.CorpseBehaviour.FindObjectsOfType<Il2Cpp.CorpseBehaviour>();
}
catch (System.Exception e)
{
string err = $"GetCorpses coroutine encountered an error: {e.Message}";
MelonLogger.Error(err);
DevourClient.Settings.Settings.errorMessage = err;
DevourClient.Settings.Settings.showErrorMessage = true;
}
// Wait 5 seconds before caching objects again.
yield return new WaitForSeconds(5f);
}
}
public static IEnumerator GetCrows()
{
while (true)
while (isRunning)
{
try
{
Crows = Il2Cpp.CrowBehaviour.FindObjectsOfType<Il2Cpp.CrowBehaviour>();
}
catch (System.Exception e)
{
string err = $"GetCrows coroutine encountered an error: {e.Message}";
MelonLogger.Error(err);
DevourClient.Settings.Settings.errorMessage = err;
DevourClient.Settings.Settings.showErrorMessage = true;
}
// Wait 5 seconds before caching objects again.
yield return new WaitForSeconds(5f);
}
}
public static IEnumerator GetLumps()
{
while (true)
while (isRunning)
{
try
{
Lumps = Il2Cpp.ManorLumpController.FindObjectsOfType<Il2Cpp.ManorLumpController>();
}
catch (System.Exception e)
{
string err = $"GetLumps coroutine encountered an error: {e.Message}";
MelonLogger.Error(err);
DevourClient.Settings.Settings.errorMessage = err;
DevourClient.Settings.Settings.showErrorMessage = true;
}
// Wait 5 seconds before caching objects again.
yield return new WaitForSeconds(5f);
}
}
public static IEnumerator GetAzazels()
{
/*
* ikr AzazelS, because in case we spawn multiple we want the esp to render all of them
*/
while (true)
while (isRunning)
{
try
{
Azazels = Il2Cpp.SurvivalAzazelBehaviour.FindObjectsOfType<Il2Cpp.SurvivalAzazelBehaviour>();
}
catch (System.Exception e)
{
string err = $"Error in GetAzazels coroutine: {e.Message}";
MelonLogger.Error(err);
DevourClient.Settings.Settings.errorMessage = err;
DevourClient.Settings.Settings.showErrorMessage = true;
}
// Wait 5 seconds before caching objects again.
yield return new WaitForSeconds(5f);
}
}