Nullreference drawingplayers с C# для ESP
Привет, с Новым годом всех :) а теперь к проблеме может ли кто-нибудь сказать мне сначала, что означает nullreference, но легкий путь.
Во-вторых, почему это nullreference проблема meaking меня когда я в игру и экран начинает блинки черный, мой лосс ЭСП цвет и т. д..
КОД ОТ ESP:
using System; using System.Collections.Generic; using System.Runtime.InteropServices; using System.IO; using UnityEngine; using EFT; using EFT.Interactive; namespace Absolutly { public class Abso : MonoBehaviour { public Abso() { } #region variable private GameObject GameObjectHolder; private IEnumerable<Player> _playerInfo; private IEnumerable<ExfiltrationPoint> _extractPoints; private IEnumerable<LootItem> _item; private float _playNextUpdateTime; private float _evaNextUpdateTime; protected float _infoUpdateInterval = 15f; private bool _isInfoMenuActive = true; private bool _showItems; private bool _pInfor; private bool _showExtractInfo; private float _viewdistance = 300f; private float _lootItemDistance = 50f; private float _espUpdateInterval = 50f; private float _itemsNextUpdateTime; private Player _localPlayer; private Vector3 camPos; #endregion #region import [DllImport("user32.dll")] static extern bool GetCursorPos(out POINT lpPoint); [DllImport("user32.dll")] static extern void mouse_event(int dwFlags, int dx, int dy, int dwData, int dwExtraInfo); private const int MOUSEEVENTF_MOVE = 0x0001; public static void Move(int xDelta, int yDelta) { mouse_event(MOUSEEVENTF_MOVE, xDelta, yDelta, 0, 0); } public struct POINT { public int X; public int Y; } #endregion private void Awake() { Debug.logger.logEnabled = false; } private void Start() { Clear(); } private void Clear() { _playerInfo = null; _extractPoints = null; _item = null; _itemsNextUpdateTime = 0; _localPlayer = null; } public void Load() { GameObjectHolder = new GameObject(); GameObjectHolder.AddComponent<Abso>(); DontDestroyOnLoad(GameObjectHolder); } public void Unload() { Clear(); Destroy(GameObjectHolder); Destroy(GameObjectHolder.GetComponent<Abso>()); Destroy(this); DestroyObject(this); } private void OnDisable() { Clear(); } private void OnDestroy() { Clear(); } private void Update() { if (Input.GetKeyDown(KeyCode.F1)) { Unload(); } if (Input.GetKeyDown(KeyCode.F11)) { _isInfoMenuActive = !_isInfoMenuActive; } } private void OnGUI() { if (_isInfoMenuActive) { GUIOverlay(); } if ((_pInfor && Time.time >= _playNextUpdateTime) || ( Time.time >= _playNextUpdateTime)) { _playerInfo = FindObjectsOfType<Player>(); _playNextUpdateTime = Time.time + _infoUpdateInterval; } if (_pInfor) { DrawPlayers(); } if (_showExtractInfo && Time.time >= _evaNextUpdateTime) { _extractPoints = FindObjectsOfType<ExfiltrationPoint>(); _evaNextUpdateTime = Time.time + _infoUpdateInterval; } if (_showExtractInfo) { DrawExtractInfo(); } if (_showItems) { if (Time.time >= _itemsNextUpdateTime) { _item = FindObjectsOfType<LootItem>(); _itemsNextUpdateTime = Time.time + _espUpdateInterval; } ShowItemESP(); } } private void GetLocalPlayer() { foreach (Player player in FindObjectsOfType<Player>()) { if (player == null) continue; if (EPointOfView.FirstPerson == player.PointOfView && player != null) { _localPlayer = player; } } } private void DrawExtractInfo() { try { foreach (var point in _extractPoints) { float distanceToObject = Vector3.Distance(Camera.main.transform.position, point.transform.position); var exfilContainerBoundingVector = new Vector3( Camera.main.WorldToScreenPoint(point.transform.position).x, Camera.main.WorldToScreenPoint(point.transform.position).y, Camera.main.WorldToScreenPoint(point.transform.position).z); if (exfilContainerBoundingVector.z > 0.01) { Color guiBackup = GUI.color; GUI.color = Color.green; int distance = (int)distanceToObject; String exfilName = point.name; string boxText = $"{exfilName} - {distance} M"; GUI.Label(new Rect(exfilContainerBoundingVector.x - 50f, (float)Screen.height - exfilContainerBoundingVector.y, 100f, 50f), boxText); GUI.color = guiBackup; } } } catch (NullReferenceException ex) { File.AppendAllText ( @"C:\EFT\EXITS.txt", $"{ex.Message}\r\n{ex.StackTrace}\r\n" ); } } private void ShowItemESP() { foreach (var Item in _item) { if (Item == null) continue; float distance = Vector3.Distance(Camera.main.transform.position, Item.transform.position); Vector3 ItemBoundingVector = new Vector3(Camera.main.WorldToScreenPoint(Item.transform.position).x, Camera.main.WorldToScreenPoint(Item.transform.position).y, Camera.main.WorldToScreenPoint(Item.transform.position).z); if (ItemBoundingVector.z > 0.01 && Item != null && (Item.name.Contains("key") || Item.name.Contains("tetriz") || Item.name.Contains("prokill") || Item.name.Contains("ssd") || Item.name.Contains("virtexprocessor") || Item.name.Contains("video_card") || Item.name.Contains("transilluminator")) && distance <= _lootItemDistance) { name = Item.name; string text = string.Format($"{Item.name} - [{distance}]M"); Color guiBackup = GUI.color; GUI.color = Color.cyan; GUI.Label(new Rect(ItemBoundingVector.x - 50f, (float)Screen.height - ItemBoundingVector.y, 100f, 50f), text); GUI.color = guiBackup; } } } private void DrawPlayers() { foreach (var player in _playerInfo) { try { if (player == null) { break; } if (player.Profile.Info.Nickname == string.Empty) { continue; } if (!player.IsVisible) continue; Vector3 playerPos = player.Transform.position; float distanceToObject = Vector3.Distance(camPos, player.Transform.position); Vector3 playerBoundingVector = Camera.main.WorldToScreenPoint(playerPos); if (distanceToObject <= _viewdistance && playerBoundingVector.z > 0.01) { Vector3 playerHeadVector = Camera.main.WorldToScreenPoint(player.PlayerBones.Head.position); Gizmos.DrawCube(playerPos, new Vector3(1, 1, 2)); float boxVectorX = playerBoundingVector.x; float boxVectorY = playerHeadVector.y + 10f; float boxHeight = Math.Abs(playerHeadVector.y - playerBoundingVector.y) + 10f; float boxWidth = boxHeight * 0.65f; var IsAI = player.Profile.Info.RegistrationDate <= 0; var playerColor = player.HealthController.IsAlive ? GetPlayerColor(player.Side) : Color.gray; Utility.DrawBox(boxVectorX - boxWidth / 2f, Screen.height - boxVectorY, boxWidth, boxHeight, playerColor); Utility.DrawLine(new Vector2(playerHeadVector.x - 2f, Screen.height - playerHeadVector.y), new Vector2(playerHeadVector.x + 2f, Screen.height - playerHeadVector.y), playerColor); Utility.DrawLine(new Vector2(playerHeadVector.x, Screen.height - playerHeadVector.y - 2f), new Vector2(playerHeadVector.x, Screen.height - playerHeadVector.y + 2f), playerColor); var playerName = IsAI ? "[BOT]" : player.Profile.Info.Nickname; string playerText = player.HealthController.IsAlive ? playerName : (playerName + " [MRTAV]"); string playerTextDraw = string.Format("{0} [{1}]", playerText, (int)distanceToObject); var playerTextVector = GUI.skin.GetStyle(playerText).CalcSize(new GUIContent(playerText)); GUI.Label(new Rect(playerBoundingVector.x - playerTextVector.x / 2f, Screen.height - boxVectorY - 20f, 300f, 50f), playerTextDraw); } } catch (NullReferenceException ex) { File.AppendAllText ( @"C:\EFT\DrawPlay.txt", $"{ex.Message}\r\n{ex.StackTrace}\r\n" ); } } } private Color GetPlayerColor(EPlayerSide side) { switch (side) { case EPlayerSide.Bear: return Color.red; case EPlayerSide.Usec: return Color.blue; case EPlayerSide.Savage: return Color.yellow; default: return Color.yellow; /* case EPlayerSide.Bear: return ColorUtility.TryParseHtmlString(_bearColor); case EPlayerSide.Usec: return ColorUtility.TryParseHtmlString(_usecColor); case EPlayerSide.Savage: return ColorUtility.TryParseHtmlString(_scavColor); default: return Color.white; */ } } private void GUIOverlay() { GUI.color = Color.gray; GUI.Box(new Rect(100f, 100f, 400f, 500f), ""); GUI.color = Color.white; GUI.Label(new Rect(180f, 110f, 150f, 20f), "CITESKI MENI"); _pInfor = GUI.Toggle(new Rect(110f, 140f, 120f, 20f), _pInfor, "IGRACI ESP"); // Display player _showExtractInfo = GUI.Toggle(new Rect(110f, 160f, 120f, 20f), _showExtractInfo, "EXSTRAKTI"); //Display extraction _showItems = GUI.Toggle(new Rect(110f, 280f, 120f, 20f), _showItems, "LOOT STVARI"); //Show items on map if (_showItems) { GUI.Label(new Rect(110f, 320f, 150f, 20f), "LOOT DISTANCA"); _lootItemDistance = GUI.HorizontalSlider(new Rect(210f, 320f, 120f, 20f), _lootItemDistance, 0.0F, 1500.0F); } } private double GetDistance(double x1, double y1, double x2, double y2) { return Math.Sqrt(Math.Pow(x2 - x1, 2.0) + Math.Pow(y2 - y1, 2.0)); } private void Circle(int X, int Y, int radius) { float boxXOffset = X; float boxYOffset = Y; float boxHeight = radius; float boxwidth = radius; Vlcrpc.DrawBox(boxXOffset - (radius / 2), boxYOffset - (radius / 2), radius, radius, Color.yellow); Vlcrpc.DrawLine(new Vector2(960, 1080), new Vector2(960, 0), Color.white); Vlcrpc.DrawLine(new Vector2(0, 540), new Vector2(1920, 540), Color.white); } } }
Что я уже пробовал:
Заменить весь код
Обновление графического интерфейса пользователя
Добавлен цвет резервной копии графического интерфейса пользователя
добавлена нулевая ссылка
вообще ничего не получалось