using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using UnityEngine;
using UnityEngine.SceneManagement;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: AssemblyVersion("0.0.0.0")]
namespace RaftAdminMenu;
public static class FileLog
{
private static string p1;
private static string p2;
private static bool inited;
public static string DesktopLog
{
get
{
Init();
return p2;
}
}
public static string PluginLog
{
get
{
Init();
return p1;
}
}
public static void Init()
{
if (inited)
{
return;
}
inited = true;
try
{
string folderPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
if (!string.IsNullOrEmpty(folderPath))
{
p2 = Path.Combine(folderPath, "RaftAdminMenu_log.txt");
}
}
catch (Exception)
{
}
try
{
string location = Assembly.GetExecutingAssembly().Location;
if (!string.IsNullOrEmpty(location))
{
p1 = Path.Combine(Path.GetDirectoryName(location), "RaftAdminMenu.log");
}
}
catch (Exception)
{
}
}
public static void Write(string s)
{
Init();
string contents = DateTime.Now.ToString("HH:mm:ss") + " " + s + "\r\n";
try
{
if (p1 != null)
{
File.AppendAllText(p1, contents);
}
}
catch (Exception)
{
}
try
{
if (p2 != null)
{
File.AppendAllText(p2, contents);
}
}
catch (Exception)
{
}
}
}
[BepInPlugin("com.raftadmin.menu", "Raft Admin Menu", "1.4.0")]
public class AdminMenuPlugin : BaseUnityPlugin
{
public const string Version = "1.4.0";
internal static ManualLogSource Log;
private static ConfigEntry<KeyCode> cfgKey;
private static ConfigEntry<bool> cfgButton;
private static ConfigEntry<float> cfgDist;
private static ConfigEntry<float> cfgSpread;
private static ConfigEntry<float> cfgHeight;
private static ConfigEntry<float> cfgSpeed;
private GameObject host;
internal static KeyCode MenuKey
{
get
{
//IL_000f: Unknown result type (might be due to invalid IL or missing references)
if (cfgKey == null)
{
return (KeyCode)112;
}
return cfgKey.Value;
}
}
internal static bool ShowButton
{
get
{
if (cfgButton == null)
{
return true;
}
return cfgButton.Value;
}
}
internal static float Distance
{
get
{
if (cfgDist == null)
{
return 18f;
}
return cfgDist.Value;
}
}
internal static float Spread
{
get
{
if (cfgSpread == null)
{
return 8f;
}
return cfgSpread.Value;
}
}
internal static float Height
{
get
{
if (cfgHeight == null)
{
return 0.5f;
}
return cfgHeight.Value;
}
}
internal static float Speed
{
get
{
if (cfgSpeed == null)
{
return 3f;
}
return cfgSpeed.Value;
}
}
private void Awake()
{
Log = ((BaseUnityPlugin)this).Logger;
FileLog.Write("=== Raft Admin Menu 1.4.0 Awake() ran. Unity " + Application.unityVersion + " ===");
try
{
cfgKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("General", "MenuKey", (KeyCode)112, "Key that opens/closes the menu (F7 and Insert always work too)");
cfgButton = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "ShowButton", true, "Show a small ADMIN MENU button in the top-left corner");
cfgDist = ((BaseUnityPlugin)this).Config.Bind<float>("Spawn", "Distance", 18f, "How far in front of you items appear (meters)");
cfgSpread = ((BaseUnityPlugin)this).Config.Bind<float>("Spawn", "Spread", 8f, "Random left/right spread (meters)");
cfgHeight = ((BaseUnityPlugin)this).Config.Bind<float>("Spawn", "HeightOffset", 0.5f, "Spawn height relative to your feet. Raise it if items spawn under water");
cfgSpeed = ((BaseUnityPlugin)this).Config.Bind<float>("Spawn", "DriftSpeed", 3f, "Speed items float toward you (m/s)");
}
catch (Exception ex)
{
FileLog.Write("Config bind failed (using defaults): " + ex.Message);
}
try
{
CreateHost();
Log.LogInfo((object)"Raft Admin Menu 1.4.0 loaded. Press P, F7 or Insert, or click the ADMIN MENU button.");
}
catch (Exception ex2)
{
FileLog.Write("CreateHost FAILED: " + ex2);
Log.LogError((object)ex2);
}
}
private void Update()
{
if ((Object)(object)host == (Object)null)
{
try
{
CreateHost();
}
catch (Exception ex)
{
FileLog.Write("Re-create host failed: " + ex.Message);
}
}
}
private void CreateHost()
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_0010: Expected O, but got Unknown
host = new GameObject("RaftAdminMenuHost");
((Object)host).hideFlags = (HideFlags)61;
Object.DontDestroyOnLoad((Object)(object)host);
host.AddComponent<AdminMenu>();
FileLog.Write("Menu host object created.");
}
}
public class AdminMenu : MonoBehaviour
{
private class ItemEntry
{
public string Name;
public string Display;
public object Item;
}
private bool open;
private bool placed;
private Rect win = new Rect(60f, 40f, 920f, 580f);
private int tab;
private Vector2 itemScroll;
private Vector2 playerScroll;
private string search = "";
private string lastSearch = "\u0001";
private string amountText = "10";
private string status = "Ready.";
private string focusName = "";
private List<ItemEntry> items = new List<ItemEntry>();
private List<ItemEntry> filtered = new List<ItemEntry>();
private int itemsVersion;
private int lastVersion = -1;
private ItemEntry selected;
private bool godMode;
private float lastLoadTry = -100f;
private float lastGod;
private float lastToggle = -10f;
private float lastPlayers;
private float bannerUntil;
private Object[] playersCache = (Object[])(object)new Object[0];
private bool firstUpdate;
private bool firstGui;
private HashSet<string> logged = new HashSet<string>();
private MethodInfo cursorMethod;
private bool cursorSearched;
private bool stylesReady;
private GUIStyle sWindow;
private GUIStyle sTitleBar;
private GUIStyle sSide;
private GUIStyle sPanel;
private GUIStyle sTitle;
private GUIStyle sH;
private GUIStyle sLabel;
private GUIStyle sSmall;
private GUIStyle sBanner;
private GUIStyle sStatus;
private GUIStyle sBtn;
private GUIStyle sBtnBlue;
private GUIStyle sBtnGreen;
private GUIStyle sBtnRed;
private GUIStyle sBtnGrey;
private GUIStyle sTab;
private GUIStyle sTabOn;
private GUIStyle sItem;
private GUIStyle sItemOn;
private GUIStyle sField;
private GUIStyle sFieldC;
private object localCache;
private float localAt = -10f;
private string localSrc = "not found";
private List<GameObject> hiddenCross = new List<GameObject>();
private CursorLockMode prevLock;
private bool prevVisible = true;
private void Start()
{
bannerUntil = Time.realtimeSinceStartup + 25f;
FileLog.Write("Menu behaviour started (Start).");
}
private void LogOnce(string key, Exception ex)
{
if (!logged.Contains(key))
{
logged.Add(key);
FileLog.Write("ERROR in " + key + ": " + ex);
}
}
private static bool Alive(object o)
{
Object val = (Object)((o is Object) ? o : null);
return val != (Object)null;
}
private object LocalPlayer()
{
float realtimeSinceStartup = Time.realtimeSinceStartup;
if (realtimeSinceStartup - localAt < 0.25f)
{
if (!Alive(localCache))
{
return null;
}
return localCache;
}
localAt = realtimeSinceStartup;
localCache = null;
localSrc = "not found";
try
{
object obj = R.CM("Raft_Network");
if (obj != null && R.TryCall(obj, null, "GetLocalPlayer", out var result) && Alive(result))
{
localCache = result;
localSrc = "Raft_Network.GetLocalPlayer()";
return result;
}
object obj2 = R.GetStatic("Player", "LocalPlayer");
if (Alive(obj2))
{
localCache = obj2;
localSrc = "Player.LocalPlayer";
return obj2;
}
Type type = R.T("Network_Player");
if (type != null)
{
Object[] array = Object.FindObjectsOfType(type);
for (int i = 0; i < array.Length; i++)
{
object obj3 = R.Get(array[i], "IsLocalPlayer");
if (obj3 is bool && (bool)obj3)
{
localCache = array[i];
localSrc = "Network_Player.IsLocalPlayer";
return array[i];
}
}
if (array.Length == 1)
{
localCache = array[0];
localSrc = "only Network_Player in scene";
return array[0];
}
}
}
catch (Exception ex)
{
LogOnce("LocalPlayer", ex);
}
return null;
}
private bool InWorld()
{
return LocalPlayer() != null;
}
private bool IsHost()
{
object obj = R.GetStatic("Raft_Network", "IsHost");
if (obj is bool)
{
return (bool)obj;
}
obj = R.Get(R.CM("Raft_Network"), "IsHost");
if (obj is bool)
{
return (bool)obj;
}
return true;
}
private bool CanAct()
{
if (!InWorld())
{
status = "Could not find your player. Be inside the game world, then see the INFO tab.";
return false;
}
if (!IsHost())
{
status = "Only the host can use this.";
return false;
}
return true;
}
private static object Net(object player)
{
object obj = R.Get(player, "Network");
if (obj == null)
{
return player;
}
return obj;
}
private int Amount()
{
if (!int.TryParse(amountText, out var result))
{
result = 1;
}
if (result < 1)
{
result = 1;
}
if (result > 9999)
{
result = 9999;
}
return result;
}
private static string Digits(string s)
{
StringBuilder stringBuilder = new StringBuilder();
for (int i = 0; i < s.Length; i++)
{
if (s[i] >= '0' && s[i] <= '9')
{
stringBuilder.Append(s[i]);
}
}
return stringBuilder.ToString();
}
private bool TypingInField()
{
if (!(focusName == "search"))
{
return focusName == "amount";
}
return true;
}
private void Toggle(string why)
{
if (!(Time.realtimeSinceStartup - lastToggle < 0.25f))
{
lastToggle = Time.realtimeSinceStartup;
open = !open;
FileLog.Write("Menu " + (open ? "OPENED" : "closed") + " via " + why);
if (open)
{
OnOpened();
}
else
{
OnClosed();
}
}
}
private void OnOpened()
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
prevLock = Cursor.lockState;
prevVisible = Cursor.visible;
HideCrosshair();
}
private void OnClosed()
{
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
//IL_0053: Unknown result type (might be due to invalid IL or missing references)
GUI.FocusControl("");
RestoreCrosshair();
try
{
Cursor.lockState = prevLock;
Cursor.visible = prevVisible;
if (cursorMethod != null)
{
cursorMethod.Invoke(null, new object[2] { prevVisible, prevLock });
}
}
catch (Exception ex)
{
LogOnce("OnClosed", ex);
}
}
private void HideCrosshair()
{
//IL_005f: Unknown result type (might be due to invalid IL or missing references)
//IL_0064: Unknown result type (might be due to invalid IL or missing references)
try
{
hiddenCross.Clear();
Object[] array = Resources.FindObjectsOfTypeAll(typeof(Transform));
foreach (Object obj in array)
{
Transform val = (Transform)(object)((obj is Transform) ? obj : null);
if ((Object)(object)val == (Object)null)
{
continue;
}
string text = ((Object)val).name.ToLowerInvariant();
if (text.IndexOf("crosshair") >= 0 || text.IndexOf("reticle") >= 0)
{
Scene scene = ((Component)val).gameObject.scene;
if (((Scene)(ref scene)).IsValid() && ((Component)val).gameObject.activeSelf)
{
((Component)val).gameObject.SetActive(false);
hiddenCross.Add(((Component)val).gameObject);
}
}
}
FileLog.Write("Hid " + hiddenCross.Count + " crosshair object(s).");
}
catch (Exception ex)
{
LogOnce("HideCrosshair", ex);
}
}
private void RestoreCrosshair()
{
try
{
for (int i = 0; i < hiddenCross.Count; i++)
{
if ((Object)(object)hiddenCross[i] != (Object)null)
{
hiddenCross[i].SetActive(true);
}
}
hiddenCross.Clear();
}
catch (Exception ex)
{
LogOnce("RestoreCrosshair", ex);
}
}
private void Update()
{
//IL_0019: Unknown result type (might be due to invalid IL or missing references)
//IL_0033: Unknown result type (might be due to invalid IL or missing references)
if (!firstUpdate)
{
firstUpdate = true;
FileLog.Write("First Update() tick - Unity is running our menu.");
}
try
{
if (Input.GetKeyDown(AdminMenuPlugin.MenuKey) && !TypingInField())
{
Toggle("key " + AdminMenuPlugin.MenuKey);
}
if (Input.GetKeyDown((KeyCode)288) || Input.GetKeyDown((KeyCode)277))
{
Toggle("F7/Insert");
}
}
catch (Exception ex)
{
LogOnce("Update.input", ex);
}
try
{
if (open && godMode && Time.time - lastGod > 0.4f)
{
lastGod = Time.time;
object obj = LocalPlayer();
if (obj != null)
{
Heal(obj);
}
}
if (open && tab == 0 && items.Count == 0 && InWorld() && Time.realtimeSinceStartup - lastLoadTry > 3f)
{
LoadItems();
}
if (open && tab == 2 && Time.realtimeSinceStartup - lastPlayers > 0.5f)
{
lastPlayers = Time.realtimeSinceStartup;
Type type = R.T("Network_Player");
playersCache = (Object[])((type != null) ? ((Array)Object.FindObjectsOfType(type)) : ((Array)new Object[0]));
}
if (search != lastSearch || itemsVersion != lastVersion)
{
RebuildFilter();
}
}
catch (Exception ex2)
{
LogOnce("Update.logic", ex2);
}
}
private void LateUpdate()
{
if (!open)
{
return;
}
try
{
Cursor.visible = true;
Cursor.lockState = (CursorLockMode)0;
if (!cursorSearched)
{
cursorSearched = true;
Type type = R.T("Helper");
if (type != null)
{
MethodInfo[] methods = type.GetMethods(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
for (int i = 0; i < methods.Length; i++)
{
if (methods[i].Name.IndexOf("Cursor") >= 0)
{
ParameterInfo[] parameters = methods[i].GetParameters();
if (parameters.Length == 2 && parameters[0].ParameterType == typeof(bool) && parameters[1].ParameterType == typeof(CursorLockMode))
{
cursorMethod = methods[i];
break;
}
}
}
}
FileLog.Write("Cursor helper method: " + ((cursorMethod != null) ? cursorMethod.Name : "none (using Unity Cursor only)"));
}
if (cursorMethod != null)
{
cursorMethod.Invoke(null, new object[2]
{
true,
(object)(CursorLockMode)0
});
}
for (int j = 0; j < hiddenCross.Count; j++)
{
if ((Object)(object)hiddenCross[j] != (Object)null && hiddenCross[j].activeSelf)
{
hiddenCross[j].SetActive(false);
}
}
}
catch (Exception ex)
{
LogOnce("LateUpdate.cursor", ex);
}
}
private void RebuildFilter()
{
lastSearch = search;
lastVersion = itemsVersion;
filtered.Clear();
string text = search.ToLowerInvariant();
for (int i = 0; i < items.Count; i++)
{
ItemEntry itemEntry = items[i];
if (text.Length <= 0 || itemEntry.Name.ToLowerInvariant().IndexOf(text) >= 0 || itemEntry.Display.ToLowerInvariant().IndexOf(text) >= 0)
{
filtered.Add(itemEntry);
}
}
}
private Texture2D Tex(Color c)
{
//IL_0004: Unknown result type (might be due to invalid IL or missing references)
//IL_000a: Expected O, but got Unknown
//IL_000d: Unknown result type (might be due to invalid IL or missing references)
Texture2D val = new Texture2D(1, 1, (TextureFormat)4, false);
val.SetPixel(0, 0, c);
val.Apply();
((Object)val).hideFlags = (HideFlags)61;
return val;
}
private static void TextCol(GUIStyle s, Color c)
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
//IL_001e: Unknown result type (might be due to invalid IL or missing references)
//IL_002a: Unknown result type (might be due to invalid IL or missing references)
//IL_0036: Unknown result type (might be due to invalid IL or missing references)
//IL_0042: Unknown result type (might be due to invalid IL or missing references)
//IL_004e: Unknown result type (might be due to invalid IL or missing references)
//IL_005a: Unknown result type (might be due to invalid IL or missing references)
s.normal.textColor = c;
s.hover.textColor = c;
s.active.textColor = c;
s.focused.textColor = c;
s.onNormal.textColor = c;
s.onHover.textColor = c;
s.onActive.textColor = c;
s.onFocused.textColor = c;
}
private void BgAll(GUIStyle s, Texture2D n, Texture2D h, Texture2D a)
{
s.normal.background = n;
s.hover.background = h;
s.active.background = a;
s.focused.background = n;
s.onNormal.background = n;
s.onHover.background = h;
s.onActive.background = a;
s.onFocused.background = n;
}
private GUIStyle MkBtn(Color n, Color h, Color a, int fs, TextAnchor al)
{
//IL_000a: Unknown result type (might be due to invalid IL or missing references)
//IL_0010: Expected O, but got Unknown
//IL_0013: Unknown result type (might be due to invalid IL or missing references)
//IL_001a: Unknown result type (might be due to invalid IL or missing references)
//IL_0021: Unknown result type (might be due to invalid IL or missing references)
//IL_002d: Unknown result type (might be due to invalid IL or missing references)
//IL_0047: Unknown result type (might be due to invalid IL or missing references)
//IL_0053: Unknown result type (might be due to invalid IL or missing references)
//IL_005d: Expected O, but got Unknown
//IL_0064: Unknown result type (might be due to invalid IL or missing references)
//IL_006e: Expected O, but got Unknown
//IL_0073: Unknown result type (might be due to invalid IL or missing references)
//IL_007d: Expected O, but got Unknown
GUIStyle val = new GUIStyle(GUI.skin.button);
BgAll(val, Tex(n), Tex(h), Tex(a));
TextCol(val, Color.white);
val.fontSize = fs;
val.fontStyle = (FontStyle)1;
val.alignment = al;
val.border = new RectOffset(0, 0, 0, 0);
val.padding = new RectOffset(10, 10, 4, 4);
val.margin = new RectOffset(3, 3, 3, 3);
return val;
}
private GUIStyle MkBox(Color c)
{
//IL_000a: Unknown result type (might be due to invalid IL or missing references)
//IL_0010: Expected O, but got Unknown
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
//IL_0023: Unknown result type (might be due to invalid IL or missing references)
//IL_0032: Unknown result type (might be due to invalid IL or missing references)
//IL_003c: Expected O, but got Unknown
//IL_0041: Unknown result type (might be due to invalid IL or missing references)
//IL_004b: Expected O, but got Unknown
//IL_0050: Unknown result type (might be due to invalid IL or missing references)
//IL_005a: Expected O, but got Unknown
GUIStyle val = new GUIStyle(GUI.skin.box);
Texture2D val2 = Tex(c);
BgAll(val, val2, val2, val2);
TextCol(val, Color.white);
val.border = new RectOffset(0, 0, 0, 0);
val.padding = new RectOffset(0, 0, 0, 0);
val.margin = new RectOffset(0, 0, 0, 0);
return val;
}
private void EnsureStyles()
{
//IL_0026: Unknown result type (might be due to invalid IL or missing references)
//IL_004b: Unknown result type (might be due to invalid IL or missing references)
//IL_0070: Unknown result type (might be due to invalid IL or missing references)
//IL_0095: Unknown result type (might be due to invalid IL or missing references)
//IL_00af: Unknown result type (might be due to invalid IL or missing references)
//IL_00b9: Expected O, but got Unknown
//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
//IL_0103: Expected O, but got Unknown
//IL_0136: Unknown result type (might be due to invalid IL or missing references)
//IL_014b: Unknown result type (might be due to invalid IL or missing references)
//IL_0155: Expected O, but got Unknown
//IL_0188: Unknown result type (might be due to invalid IL or missing references)
//IL_019d: Unknown result type (might be due to invalid IL or missing references)
//IL_01a7: Expected O, but got Unknown
//IL_01da: Unknown result type (might be due to invalid IL or missing references)
//IL_01ef: Unknown result type (might be due to invalid IL or missing references)
//IL_01f9: Expected O, but got Unknown
//IL_022c: Unknown result type (might be due to invalid IL or missing references)
//IL_0241: Unknown result type (might be due to invalid IL or missing references)
//IL_024b: Expected O, but got Unknown
//IL_027e: Unknown result type (might be due to invalid IL or missing references)
//IL_029e: Unknown result type (might be due to invalid IL or missing references)
//IL_02b7: Unknown result type (might be due to invalid IL or missing references)
//IL_02d0: Unknown result type (might be due to invalid IL or missing references)
//IL_02f8: Unknown result type (might be due to invalid IL or missing references)
//IL_0311: Unknown result type (might be due to invalid IL or missing references)
//IL_032a: Unknown result type (might be due to invalid IL or missing references)
//IL_0352: Unknown result type (might be due to invalid IL or missing references)
//IL_036b: Unknown result type (might be due to invalid IL or missing references)
//IL_0384: Unknown result type (might be due to invalid IL or missing references)
//IL_03ac: Unknown result type (might be due to invalid IL or missing references)
//IL_03c5: Unknown result type (might be due to invalid IL or missing references)
//IL_03de: Unknown result type (might be due to invalid IL or missing references)
//IL_0406: Unknown result type (might be due to invalid IL or missing references)
//IL_041f: Unknown result type (might be due to invalid IL or missing references)
//IL_0438: Unknown result type (might be due to invalid IL or missing references)
//IL_0460: Unknown result type (might be due to invalid IL or missing references)
//IL_0479: Unknown result type (might be due to invalid IL or missing references)
//IL_0492: Unknown result type (might be due to invalid IL or missing references)
//IL_04ba: Unknown result type (might be due to invalid IL or missing references)
//IL_04d3: Unknown result type (might be due to invalid IL or missing references)
//IL_04ec: Unknown result type (might be due to invalid IL or missing references)
//IL_0514: Unknown result type (might be due to invalid IL or missing references)
//IL_052d: Unknown result type (might be due to invalid IL or missing references)
//IL_0546: Unknown result type (might be due to invalid IL or missing references)
//IL_057a: Unknown result type (might be due to invalid IL or missing references)
//IL_0593: Unknown result type (might be due to invalid IL or missing references)
//IL_05ac: Unknown result type (might be due to invalid IL or missing references)
//IL_05c9: Unknown result type (might be due to invalid IL or missing references)
//IL_05d3: Expected O, but got Unknown
//IL_05e8: Unknown result type (might be due to invalid IL or missing references)
//IL_0608: Unknown result type (might be due to invalid IL or missing references)
//IL_064a: Unknown result type (might be due to invalid IL or missing references)
//IL_066b: Unknown result type (might be due to invalid IL or missing references)
//IL_0675: Expected O, but got Unknown
//IL_068b: Unknown result type (might be due to invalid IL or missing references)
//IL_0695: Expected O, but got Unknown
//IL_069c: Unknown result type (might be due to invalid IL or missing references)
//IL_06a6: Expected O, but got Unknown
if (!stylesReady)
{
stylesReady = true;
sWindow = MkBox(new Color(0.07f, 0.08f, 0.1f, 1f));
sTitleBar = MkBox(new Color(0.1f, 0.45f, 0.8f, 1f));
sSide = MkBox(new Color(0.1f, 0.11f, 0.14f, 1f));
sPanel = MkBox(new Color(0.13f, 0.15f, 0.19f, 1f));
sTitle = new GUIStyle(GUI.skin.label);
sTitle.fontSize = 20;
sTitle.fontStyle = (FontStyle)1;
sTitle.alignment = (TextAnchor)3;
TextCol(sTitle, Color.white);
sH = new GUIStyle(GUI.skin.label);
sH.fontSize = 13;
sH.fontStyle = (FontStyle)1;
TextCol(sH, new Color(0.45f, 0.75f, 1f, 1f));
sLabel = new GUIStyle(GUI.skin.label);
sLabel.fontSize = 15;
sLabel.wordWrap = true;
TextCol(sLabel, new Color(0.92f, 0.94f, 0.97f, 1f));
sSmall = new GUIStyle(GUI.skin.label);
sSmall.fontSize = 12;
sSmall.wordWrap = true;
TextCol(sSmall, new Color(0.65f, 0.7f, 0.78f, 1f));
sBanner = new GUIStyle(GUI.skin.label);
sBanner.fontSize = 14;
sBanner.fontStyle = (FontStyle)1;
TextCol(sBanner, new Color(1f, 0.92f, 0.3f, 1f));
sStatus = new GUIStyle(GUI.skin.label);
sStatus.fontSize = 13;
sStatus.alignment = (TextAnchor)3;
TextCol(sStatus, new Color(0.6f, 1f, 0.7f, 1f));
sBtn = MkBtn(new Color(0.2f, 0.24f, 0.32f, 1f), new Color(0.28f, 0.33f, 0.43f, 1f), new Color(0.15f, 0.18f, 0.25f, 1f), 15, (TextAnchor)4);
sBtnBlue = MkBtn(new Color(0.13f, 0.5f, 0.9f, 1f), new Color(0.2f, 0.6f, 1f, 1f), new Color(0.08f, 0.38f, 0.72f, 1f), 15, (TextAnchor)4);
sBtnGreen = MkBtn(new Color(0.12f, 0.6f, 0.3f, 1f), new Color(0.18f, 0.72f, 0.38f, 1f), new Color(0.08f, 0.46f, 0.22f, 1f), 16, (TextAnchor)4);
sBtnRed = MkBtn(new Color(0.75f, 0.18f, 0.18f, 1f), new Color(0.9f, 0.25f, 0.25f, 1f), new Color(0.58f, 0.12f, 0.12f, 1f), 15, (TextAnchor)4);
sBtnGrey = MkBtn(new Color(0.25f, 0.28f, 0.34f, 1f), new Color(0.34f, 0.38f, 0.46f, 1f), new Color(0.18f, 0.2f, 0.26f, 1f), 14, (TextAnchor)4);
sTab = MkBtn(new Color(0.1f, 0.11f, 0.14f, 1f), new Color(0.18f, 0.21f, 0.28f, 1f), new Color(0.14f, 0.16f, 0.22f, 1f), 16, (TextAnchor)3);
sTabOn = MkBtn(new Color(0.13f, 0.5f, 0.9f, 1f), new Color(0.13f, 0.5f, 0.9f, 1f), new Color(0.13f, 0.5f, 0.9f, 1f), 16, (TextAnchor)3);
sItem = MkBtn(new Color(0.15f, 0.17f, 0.22f, 1f), new Color(0.22f, 0.26f, 0.34f, 1f), new Color(0.12f, 0.14f, 0.18f, 1f), 14, (TextAnchor)3);
sItem.fontStyle = (FontStyle)0;
sItemOn = MkBtn(new Color(0.12f, 0.55f, 0.85f, 1f), new Color(0.12f, 0.55f, 0.85f, 1f), new Color(0.12f, 0.55f, 0.85f, 1f), 14, (TextAnchor)3);
sField = new GUIStyle(GUI.skin.textField);
Texture2D val = Tex(new Color(0.05f, 0.06f, 0.08f, 1f));
Texture2D val2 = Tex(new Color(0.09f, 0.11f, 0.15f, 1f));
BgAll(sField, val, val, val2);
sField.focused.background = val2;
sField.onFocused.background = val2;
TextCol(sField, Color.white);
sField.fontSize = 15;
sField.padding = new RectOffset(8, 8, 5, 5);
sField.alignment = (TextAnchor)3;
sField.border = new RectOffset(0, 0, 0, 0);
sFieldC = new GUIStyle(sField);
sFieldC.alignment = (TextAnchor)4;
}
}
private void OnGUI()
{
//IL_0033: Unknown result type (might be due to invalid IL or missing references)
//IL_0039: Invalid comparison between Unknown and I4
//IL_003c: Unknown result type (might be due to invalid IL or missing references)
//IL_0041: Unknown result type (might be due to invalid IL or missing references)
//IL_01dd: Unknown result type (might be due to invalid IL or missing references)
//IL_01e9: Unknown result type (might be due to invalid IL or missing references)
//IL_01fe: Expected O, but got Unknown
//IL_01f9: Unknown result type (might be due to invalid IL or missing references)
//IL_01fe: Unknown result type (might be due to invalid IL or missing references)
//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
//IL_00be: Unknown result type (might be due to invalid IL or missing references)
//IL_0064: Unknown result type (might be due to invalid IL or missing references)
//IL_006e: Invalid comparison between Unknown and I4
//IL_010e: Unknown result type (might be due to invalid IL or missing references)
//IL_0118: Unknown result type (might be due to invalid IL or missing references)
//IL_0071: Unknown result type (might be due to invalid IL or missing references)
//IL_007b: Invalid comparison between Unknown and I4
try
{
if (!firstGui)
{
firstGui = true;
FileLog.Write("First OnGUI() call - drawing works.");
}
GUI.depth = -1000;
EnsureStyles();
Event current = Event.current;
if (current != null && (int)current.type == 4)
{
if (current.keyCode == AdminMenuPlugin.MenuKey && !TypingInField())
{
Toggle("OnGUI key");
current.Use();
}
else if ((int)current.keyCode == 288 || (int)current.keyCode == 277)
{
Toggle("OnGUI F7/Insert");
current.Use();
}
}
if (!open)
{
if (AdminMenuPlugin.ShowButton && GUI.Button(new Rect(8f, 8f, 150f, 28f), string.Concat("ADMIN MENU (", AdminMenuPlugin.MenuKey, ")"), sBtnBlue))
{
Toggle("corner button");
}
if (Time.realtimeSinceStartup < bannerUntil)
{
GUI.Label(new Rect(8f, 40f, 700f, 24f), string.Concat("Raft Admin Menu 1.4.0 is loaded - press ", AdminMenuPlugin.MenuKey, ", F7 or Insert, or click the button."), sBanner);
}
}
else
{
if (!placed)
{
placed = true;
((Rect)(ref win)).width = Mathf.Min(920f, (float)Screen.width - 20f);
((Rect)(ref win)).height = Mathf.Min(580f, (float)Screen.height - 20f);
((Rect)(ref win)).x = ((float)Screen.width - ((Rect)(ref win)).width) * 0.5f;
((Rect)(ref win)).y = ((float)Screen.height - ((Rect)(ref win)).height) * 0.5f;
}
win = GUI.Window(77077, win, new WindowFunction(DrawWindow), "", sWindow);
((Rect)(ref win)).x = Mathf.Clamp(((Rect)(ref win)).x, 0f, Mathf.Max(0f, (float)Screen.width - ((Rect)(ref win)).width));
((Rect)(ref win)).y = Mathf.Clamp(((Rect)(ref win)).y, 0f, Mathf.Max(0f, (float)Screen.height - 40f));
}
focusName = GUI.GetNameOfFocusedControl();
}
catch (ExitGUIException)
{
throw;
}
catch (Exception ex2)
{
LogOnce("OnGUI", ex2);
}
}
private void DrawWindow(int id)
{
//IL_0028: Unknown result type (might be due to invalid IL or missing references)
//IL_0051: Unknown result type (might be due to invalid IL or missing references)
//IL_007c: Unknown result type (might be due to invalid IL or missing references)
//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
//IL_023c: Unknown result type (might be due to invalid IL or missing references)
//IL_0268: Unknown result type (might be due to invalid IL or missing references)
//IL_0119: Unknown result type (might be due to invalid IL or missing references)
//IL_0166: Unknown result type (might be due to invalid IL or missing references)
//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
float width = ((Rect)(ref win)).width;
float height = ((Rect)(ref win)).height;
GUI.Box(new Rect(0f, 0f, width, 40f), GUIContent.none, sTitleBar);
GUI.Label(new Rect(14f, 5f, 600f, 30f), "RAFT ADMIN MENU v1.4.0", sTitle);
if (GUI.Button(new Rect(width - 44f, 5f, 36f, 30f), "X", sBtnRed))
{
Toggle("X button");
}
GUI.Box(new Rect(0f, 40f, 160f, height - 40f), GUIContent.none, sSide);
string[] array = new string[4] { "ITEMS", "ME", "PLAYERS", "INFO" };
for (int i = 0; i < array.Length; i++)
{
if (GUI.Button(new Rect(8f, 54f + (float)i * 50f, 144f, 42f), array[i], (tab == i) ? sTabOn : sTab))
{
tab = i;
}
}
GUI.Label(new Rect(10f, height - 60f, 145f, 50f), "Host only.\nDrag the blue bar to move.", sSmall);
Rect val = default(Rect);
((Rect)(ref val))..ctor(172f, 52f, width - 184f, height - 52f - 38f);
GUILayout.BeginArea(val);
try
{
if (tab == 0)
{
DrawItemsTab(((Rect)(ref val)).width, ((Rect)(ref val)).height);
}
else if (tab == 1)
{
DrawMeTab();
}
else if (tab == 2)
{
DrawPlayersTab(((Rect)(ref val)).height);
}
else
{
DrawInfoTab();
}
}
catch (ExitGUIException)
{
GUILayout.EndArea();
throw;
}
catch (Exception ex2)
{
LogOnce("DrawWindow.tab" + tab, ex2);
}
GUILayout.EndArea();
GUI.Label(new Rect(172f, height - 32f, width - 184f, 26f), status, sStatus);
GUI.DragWindow(new Rect(0f, 0f, width - 52f, 40f));
}
private void DrawItemsTab(float areaW, float areaH)
{
//IL_0154: Unknown result type (might be due to invalid IL or missing references)
//IL_016d: Unknown result type (might be due to invalid IL or missing references)
//IL_0172: Unknown result type (might be due to invalid IL or missing references)
float num = areaH - 108f;
GUILayout.BeginHorizontal((GUILayoutOption[])(object)new GUILayoutOption[0]);
GUILayout.BeginVertical((GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(areaW * 0.52f) });
GUILayout.BeginHorizontal((GUILayoutOption[])(object)new GUILayoutOption[0]);
GUILayout.Label("Search", sLabel, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(62f) });
GUI.SetNextControlName("search");
search = GUILayout.TextField(search, sField, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(30f) });
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal((GUILayoutOption[])(object)new GUILayoutOption[0]);
string[] array = new string[7] { "ALL", "Plank", "Rope", "Plastic", "Scrap", "Nail", "Metal" };
for (int i = 0; i < array.Length; i++)
{
if (GUILayout.Button(array[i], sBtnGrey, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(26f) }))
{
search = ((array[i] == "ALL") ? "" : array[i]);
}
}
GUILayout.EndHorizontal();
itemScroll = GUILayout.BeginScrollView(itemScroll, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(num) });
for (int j = 0; j < filtered.Count; j++)
{
ItemEntry itemEntry = filtered[j];
string text = ((itemEntry.Display.Length > 0 && itemEntry.Display != itemEntry.Name) ? (itemEntry.Name + " (" + itemEntry.Display + ")") : itemEntry.Name);
if (GUILayout.Button(text, (selected == itemEntry) ? sItemOn : sItem, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(28f) }))
{
selected = itemEntry;
}
}
GUILayout.EndScrollView();
GUILayout.BeginHorizontal((GUILayoutOption[])(object)new GUILayoutOption[0]);
GUILayout.Label(filtered.Count + " / " + items.Count + " items", sSmall, (GUILayoutOption[])(object)new GUILayoutOption[0]);
if (GUILayout.Button("Reload list", sBtnGrey, (GUILayoutOption[])(object)new GUILayoutOption[2]
{
GUILayout.Height(24f),
GUILayout.Width(110f)
}))
{
LoadItems();
}
GUILayout.EndHorizontal();
GUILayout.EndVertical();
GUILayout.Space(14f);
GUILayout.BeginVertical((GUILayoutOption[])(object)new GUILayoutOption[0]);
GUILayout.Label("SELECTED ITEM", sH, (GUILayoutOption[])(object)new GUILayoutOption[0]);
GUILayout.Label((selected == null) ? "(click an item on the left)" : (selected.Name + ((selected.Display.Length > 0 && selected.Display != selected.Name) ? (" (" + selected.Display + ")") : "")), sLabel, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(44f) });
GUILayout.Label("AMOUNT", sH, (GUILayoutOption[])(object)new GUILayoutOption[0]);
GUILayout.BeginHorizontal((GUILayoutOption[])(object)new GUILayoutOption[0]);
if (GUILayout.Button("-", sBtn, (GUILayoutOption[])(object)new GUILayoutOption[2]
{
GUILayout.Width(40f),
GUILayout.Height(34f)
}))
{
amountText = Math.Max(1, Amount() - 1).ToString();
}
GUI.SetNextControlName("amount");
amountText = Digits(GUILayout.TextField(amountText, sFieldC, (GUILayoutOption[])(object)new GUILayoutOption[2]
{
GUILayout.Width(100f),
GUILayout.Height(34f)
}));
if (GUILayout.Button("+", sBtn, (GUILayoutOption[])(object)new GUILayoutOption[2]
{
GUILayout.Width(40f),
GUILayout.Height(34f)
}))
{
amountText = Math.Min(9999, Amount() + 1).ToString();
}
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal((GUILayoutOption[])(object)new GUILayoutOption[0]);
int[] array2 = new int[6] { 1, 5, 10, 25, 50, 100 };
for (int k = 0; k < array2.Length; k++)
{
if (GUILayout.Button(array2[k].ToString(), sBtnGrey, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(28f) }))
{
amountText = array2[k].ToString();
}
}
GUILayout.EndHorizontal();
GUILayout.Space(12f);
if (GUILayout.Button("SPAWN FLOATING TO ME", sBtnGreen, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(52f) }))
{
SpawnSelected(atFeet: false);
}
if (GUILayout.Button("Spawn at my feet", sBtnBlue, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(38f) }))
{
SpawnSelected(atFeet: true);
}
if (GUILayout.Button("Give to inventory", sBtn, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(38f) }))
{
GiveSelected();
}
GUILayout.Space(8f);
GUILayout.Label("Floating spawn puts items in the ocean ahead of you and they drift toward you.", sSmall, (GUILayoutOption[])(object)new GUILayoutOption[0]);
GUILayout.EndVertical();
GUILayout.EndHorizontal();
}
private void LoadItems()
{
lastLoadTry = Time.realtimeSinceStartup;
items.Clear();
selected = null;
itemsVersion++;
Type type = R.T("ItemManager");
if (type == null)
{
status = "ItemManager not found (game version changed?). See INFO tab.";
return;
}
if (!R.TryCall(null, type, "GetAllItems", out var result) || result == null)
{
status = "Item list not ready yet. Load into a world.";
return;
}
if (!(result is IEnumerable enumerable))
{
status = "Item list was not readable.";
return;
}
foreach (object item in enumerable)
{
if (item == null)
{
continue;
}
string text = R.Get(item, "UniqueName") as string;
if (!string.IsNullOrEmpty(text))
{
string display = "";
object obj = R.Get(item, "settings_Inventory");
if (obj != null && R.Get(obj, "DisplayName") is string text2)
{
display = text2;
}
ItemEntry itemEntry = new ItemEntry();
itemEntry.Name = text;
itemEntry.Display = display;
itemEntry.Item = item;
items.Add(itemEntry);
}
}
items.Sort((ItemEntry x, ItemEntry y) => string.Compare(x.Name, y.Name, StringComparison.OrdinalIgnoreCase));
itemsVersion++;
status = items.Count + " items loaded.";
FileLog.Write(status);
}
private void GiveSelected()
{
if (selected == null)
{
status = "Select an item first.";
}
else if (CanAct())
{
if (GiveItem(selected, Amount()))
{
status = "Gave " + Amount() + "x " + selected.Name;
}
else
{
status = "Give failed (see log).";
}
}
}
private bool GiveItem(ItemEntry e, int amt)
{
object obj = LocalPlayer();
object obj2 = R.Get(obj, "Inventory");
if (obj2 == null)
{
obj2 = R.Get(Net(obj), "Inventory");
}
if (obj2 == null)
{
return false;
}
object result;
return R.TryCall(obj2, null, "AddItem", out result, e.Name, amt);
}
private void SpawnSelected(bool atFeet)
{
if (selected == null)
{
status = "Select an item first.";
}
else if (CanAct())
{
((MonoBehaviour)this).StartCoroutine(SpawnRoutine(selected, Amount(), atFeet));
}
}
private IEnumerator SpawnRoutine(ItemEntry e, int total, bool atFeet)
{
object local = LocalPlayer();
Component lc = (Component)((local is Component) ? local : null);
if ((Object)(object)lc == (Object)null)
{
status = "No local player.";
yield break;
}
int stacks = Math.Min(total, 12);
int per = total / stacks;
int rem = total - per * stacks;
int ok = 0;
for (int i = 0; i < stacks; i++)
{
if (!Alive(lc))
{
break;
}
int amt = per + ((i < rem) ? 1 : 0);
Vector3 pos = (atFeet ? (lc.transform.position + lc.transform.forward * 2f + Vector3.up * 1.2f) : SpawnPos(lc.transform));
Vector3 val = lc.transform.position - pos;
Vector3 dir = ((Vector3)(ref val)).normalized;
HashSet<int> before = Snapshot(pos);
string err = TryDrop(e, amt, pos, dir);
if (err != null)
{
int num = 0;
for (int j = i; j < stacks; j++)
{
num += per + ((j < rem) ? 1 : 0);
}
bool flag = GiveItem(e, num);
status = "Spawn failed (" + err + "). " + (flag ? ("Gave " + num + "x to your inventory instead.") : "Fallback failed too.");
FileLog.Write(status);
yield break;
}
ok++;
if (!atFeet)
{
((MonoBehaviour)this).StartCoroutine(AttachDrifter(pos, lc.transform, before));
}
yield return (object)new WaitForSeconds(0.2f);
}
status = "Spawned " + total + "x " + e.Name + " in " + ok + " drops." + (atFeet ? "" : " Floating toward you.");
}
private Vector3 SpawnPos(Transform t)
{
//IL_001d: Unknown result type (might be due to invalid IL or missing references)
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
//IL_0022: Unknown result type (might be due to invalid IL or missing references)
//IL_004a: Unknown result type (might be due to invalid IL or missing references)
//IL_004f: Unknown result type (might be due to invalid IL or missing references)
//IL_0050: Unknown result type (might be due to invalid IL or missing references)
//IL_0055: Unknown result type (might be due to invalid IL or missing references)
//IL_007f: Unknown result type (might be due to invalid IL or missing references)
//IL_0084: Unknown result type (might be due to invalid IL or missing references)
//IL_0087: Unknown result type (might be due to invalid IL or missing references)
//IL_008c: Unknown result type (might be due to invalid IL or missing references)
//IL_0091: Unknown result type (might be due to invalid IL or missing references)
//IL_0093: Unknown result type (might be due to invalid IL or missing references)
//IL_0098: Unknown result type (might be due to invalid IL or missing references)
//IL_009d: Unknown result type (might be due to invalid IL or missing references)
//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
//IL_003d: Unknown result type (might be due to invalid IL or missing references)
//IL_0042: Unknown result type (might be due to invalid IL or missing references)
Camera main = Camera.main;
Vector3 val = (((Object)(object)main != (Object)null) ? ((Component)main).transform.forward : t.forward);
val.y = 0f;
if (((Vector3)(ref val)).sqrMagnitude < 0.01f)
{
val = Vector3.forward;
}
((Vector3)(ref val)).Normalize();
Vector3 val2 = Vector3.Cross(Vector3.up, val);
float num = Random.Range(0f - AdminMenuPlugin.Spread, AdminMenuPlugin.Spread);
float num2 = AdminMenuPlugin.Distance + Random.Range(0f, 4f);
Vector3 result = t.position + val * num2 + val2 * num;
result.y = t.position.y + AdminMenuPlugin.Height;
return result;
}
private HashSet<int> Snapshot(Vector3 pos)
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
HashSet<int> hashSet = new HashSet<int>();
Collider[] array = Physics.OverlapSphere(pos, 4f);
for (int i = 0; i < array.Length; i++)
{
hashSet.Add(((Object)((Component)array[i]).gameObject).GetInstanceID());
}
return hashSet;
}
private IEnumerator AttachDrifter(Vector3 pos, Transform target, HashSet<int> before)
{
//IL_000f: Unknown result type (might be due to invalid IL or missing references)
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
yield return (object)new WaitForSeconds(0.5f);
Collider[] cols = Physics.OverlapSphere(pos, 4f);
foreach (Collider val in cols)
{
if (!before.Contains(((Object)((Component)val).gameObject).GetInstanceID()))
{
Rigidbody attachedRigidbody = val.attachedRigidbody;
GameObject val2 = (((Object)(object)attachedRigidbody != (Object)null) ? ((Component)attachedRigidbody).gameObject : ((Component)val).gameObject);
if (!((Object)(object)val2.GetComponent<Drifter>() != (Object)null))
{
Drifter drifter = val2.AddComponent<Drifter>();
drifter.target = target;
drifter.speed = AdminMenuPlugin.Speed;
}
}
}
}
private string TryDrop(ItemEntry e, int amt, Vector3 pos, Vector3 dir)
{
//IL_01f4: Unknown result type (might be due to invalid IL or missing references)
//IL_01f1: Unknown result type (might be due to invalid IL or missing references)
Type type = R.T("Helper");
Type type2 = R.T("ItemInstance");
if (type == null)
{
return "Helper type missing";
}
if (type2 == null)
{
return "ItemInstance type missing";
}
object obj = null;
ConstructorInfo[] constructors = type2.GetConstructors(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
object obj2 = R.Get(e.Item, "MaxUses");
int num = ((!(obj2 is int)) ? 1 : ((int)obj2));
for (int i = 0; i < constructors.Length; i++)
{
if (obj != null)
{
break;
}
ParameterInfo[] parameters = constructors[i].GetParameters();
try
{
if (parameters.Length == 3 && parameters[0].ParameterType.IsAssignableFrom(e.Item.GetType()))
{
obj = constructors[i].Invoke(new object[3] { e.Item, amt, num });
}
else if (parameters.Length == 2 && parameters[0].ParameterType.IsAssignableFrom(e.Item.GetType()))
{
obj = constructors[i].Invoke(new object[2] { e.Item, amt });
}
}
catch (Exception ex)
{
FileLog.Write("ItemInstance ctor: " + ex.Message);
}
}
if (obj == null)
{
return "could not create ItemInstance";
}
string result = "no usable Helper.DropItem overload";
MethodInfo[] methods = type.GetMethods(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
for (int j = 0; j < methods.Length; j++)
{
if (methods[j].Name != "DropItem")
{
continue;
}
ParameterInfo[] parameters2 = methods[j].GetParameters();
object[] array = new object[parameters2.Length];
bool flag = false;
for (int k = 0; k < parameters2.Length; k++)
{
Type type3 = parameters2[k].ParameterType;
if (type3.IsByRef)
{
type3 = type3.GetElementType();
}
if (type3 == type2)
{
array[k] = obj;
}
else if (type3 == typeof(Vector3))
{
array[k] = (flag ? dir : pos);
flag = true;
}
else if (parameters2[k].IsOptional)
{
array[k] = parameters2[k].DefaultValue;
}
else if (type3.IsValueType)
{
array[k] = Activator.CreateInstance(type3);
}
else
{
array[k] = null;
}
}
try
{
methods[j].Invoke(null, array);
return null;
}
catch (Exception ex2)
{
Exception ex3 = ((ex2.InnerException != null) ? ex2.InnerException : ex2);
result = ex3.GetType().Name + ": " + ex3.Message;
FileLog.Write("DropItem overload failed: " + ex3);
}
}
return result;
}
private void DrawMeTab()
{
GUILayout.Label("YOUR CHARACTER", sH, (GUILayoutOption[])(object)new GUILayoutOption[0]);
GUILayout.Label(InWorld() ? "Controls below apply to you." : "No player yet. Load or host a world first.", sLabel, (GUILayoutOption[])(object)new GUILayoutOption[0]);
GUILayout.Space(8f);
if (GUILayout.Button("HEAL ME (health, hunger, thirst)", sBtnGreen, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(46f) }))
{
object obj = LocalPlayer();
if (obj != null && CanAct())
{
Heal(obj);
status = "Healed.";
}
else if (obj == null)
{
status = "Load a world first.";
}
}
if (GUILayout.Button(godMode ? "GOD MODE: ON (click to turn off)" : "GOD MODE: OFF (click to turn on)", godMode ? sBtnGreen : sBtnGrey, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(46f) }))
{
godMode = !godMode;
status = "God mode " + (godMode ? "ON" : "OFF");
}
bool flag = IsCreative();
if (GUILayout.Button(flag ? "CREATIVE MODE: ON (click to turn off)" : "CREATIVE MODE: OFF (click to turn on)", flag ? sBtnGreen : sBtnGrey, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(46f) }))
{
SetCreative(!flag);
}
GUILayout.Space(14f);
if (GUILayout.Button("KILL ME", sBtnRed, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(40f) }))
{
object obj2 = LocalPlayer();
if (obj2 != null)
{
Kill(obj2);
}
else
{
status = "Load a world first.";
}
}
}
private bool IsCreative()
{
object obj = R.GetStatic("GameManager", "GameMode");
if (obj != null)
{
return obj.ToString() == "Creative";
}
return false;
}
private void SetCreative(bool on)
{
if (!CanAct())
{
return;
}
string[] array = (on ? new string[1] { "Creative" } : new string[3] { "Normal", "Survival", "Default" });
for (int i = 0; i < array.Length; i++)
{
if (R.SetMember(null, R.T("GameManager"), "GameMode", array[i]))
{
status = "Creative mode " + (on ? "ON" : "OFF");
return;
}
}
status = "Could not change game mode (GameManager.GameMode missing). See INFO tab.";
}
private void Heal(object player)
{
object o = Net(player);
object obj = R.Get(o, "Stats");
if (obj == null)
{
obj = R.Get(player, "Stats");
}
if (obj == null)
{
return;
}
string[] array = new string[3] { "stat_health", "stat_hunger", "stat_thirst" };
for (int i = 0; i < array.Length; i++)
{
object obj2 = R.Get(obj, array[i]);
if (obj2 != null)
{
MaxStat(obj2);
MaxStat(R.Get(obj2, "Normal"));
}
}
}
private void MaxStat(object s)
{
if (s != null && !R.TryCall(s, null, "SetToMaxValue", out var _))
{
object obj = R.Get(s, "Max");
if (obj != null)
{
R.SetMember(s, null, "Value", obj);
}
}
}
private void Kill(object player)
{
if (!CanAct())
{
return;
}
object obj = Net(player);
if (R.TryCall(obj, null, "Kill", out var _))
{
status = "Killed.";
return;
}
object obj2 = R.Get(obj, "Stats");
if (R.TryDamage(obj2, 99999f))
{
status = "Killed (damage).";
return;
}
object obj3 = R.Get(obj2, "stat_health");
if (obj3 != null && R.SetMember(obj3, null, "Value", 0f))
{
status = "Killed (health set to 0).";
}
else
{
status = "Kill failed. See INFO tab.";
}
}
private void DrawPlayersTab(float areaH)
{
//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
object obj = LocalPlayer();
GUILayout.Label((obj == null) ? "Load or host a world first." : "Players in this world:", sLabel, (GUILayoutOption[])(object)new GUILayoutOption[0]);
if (GUILayout.Button("HEAL EVERYONE", sBtnGreen, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(36f) }) && CanAct())
{
for (int i = 0; i < playersCache.Length; i++)
{
if (playersCache[i] != (Object)null)
{
Heal(playersCache[i]);
}
}
status = "Healed everyone.";
}
Object val = (Object)((obj != null) ? /*isinst with value type is only supported in some contexts*/: null);
playerScroll = GUILayout.BeginScrollView(playerScroll, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(areaH - 90f) });
for (int j = 0; j < playersCache.Length; j++)
{
Object val2 = playersCache[j];
if (!(val2 == (Object)null))
{
bool flag = val != (Object)null && val2 == val;
GUILayout.BeginHorizontal((GUILayoutOption[])(object)new GUILayoutOption[0]);
GUILayout.Label(PlayerName(val2) + (flag ? " (you)" : ""), sLabel, (GUILayoutOption[])(object)new GUILayoutOption[2]
{
GUILayout.Width(250f),
GUILayout.Height(32f)
});
if (GUILayout.Button("Heal", sBtnGreen, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(32f) }) && CanAct())
{
Heal(val2);
status = "Healed " + PlayerName(val2);
}
if (GUILayout.Button("Kill", sBtnRed, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(32f) }) && CanAct())
{
Kill(val2);
}
if (GUILayout.Button("Bring to me", sBtnBlue, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(32f) }) && !flag)
{
BringPlayer(val2, obj);
}
if (GUILayout.Button("Go to", sBtnBlue, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(32f) }) && !flag)
{
GoTo(val2, obj);
}
GUILayout.EndHorizontal();
}
}
GUILayout.EndScrollView();
}
private string PlayerName(Object p)
{
string text = R.Get(R.Get(p, "characterSettings"), "Name") as string;
if (!string.IsNullOrEmpty(text))
{
return text;
}
return p.name;
}
private void BringPlayer(Object p, object me)
{
//IL_0032: Unknown result type (might be due to invalid IL or missing references)
//IL_003d: Unknown result type (might be due to invalid IL or missing references)
//IL_0047: Unknown result type (might be due to invalid IL or missing references)
//IL_004c: Unknown result type (might be due to invalid IL or missing references)
//IL_0051: Unknown result type (might be due to invalid IL or missing references)
//IL_005b: Unknown result type (might be due to invalid IL or missing references)
//IL_0060: Unknown result type (might be due to invalid IL or missing references)
if (CanAct())
{
Component val = (Component)((me is Component) ? me : null);
Component val2 = (Component)(object)((p is Component) ? p : null);
if (!((Object)(object)val == (Object)null) && !((Object)(object)val2 == (Object)null))
{
MoveTo(val2, val.transform.position + val.transform.forward * 2f + Vector3.up * 0.5f);
status = "Moved " + PlayerName(p) + " to you (clients may snap back if they own their position).";
}
}
}
private void GoTo(Object p, object me)
{
//IL_0032: Unknown result type (might be due to invalid IL or missing references)
//IL_0037: Unknown result type (might be due to invalid IL or missing references)
//IL_0041: Unknown result type (might be due to invalid IL or missing references)
//IL_0046: Unknown result type (might be due to invalid IL or missing references)
if (CanAct())
{
Component val = (Component)((me is Component) ? me : null);
Component val2 = (Component)(object)((p is Component) ? p : null);
if (!((Object)(object)val == (Object)null) && !((Object)(object)val2 == (Object)null))
{
MoveTo(val, val2.transform.position + Vector3.up * 0.5f);
status = "Teleported to " + PlayerName(p);
}
}
}
private void MoveTo(Component c, Vector3 pos)
{
//IL_002a: Unknown result type (might be due to invalid IL or missing references)
CharacterController component = c.GetComponent<CharacterController>();
bool flag = (Object)(object)component != (Object)null && ((Collider)component).enabled;
if (flag)
{
((Collider)component).enabled = false;
}
c.transform.position = pos;
if (flag)
{
((Collider)component).enabled = true;
}
}
private string BuildDiag()
{
//IL_0034: Unknown result type (might be due to invalid IL or missing references)
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.AppendLine("Raft Admin Menu 1.4.0");
stringBuilder.AppendLine("Unity " + Application.unityVersion + " key=" + AdminMenuPlugin.MenuKey);
stringBuilder.AppendLine("In world: " + InWorld() + " Host: " + IsHost() + " Items: " + items.Count);
stringBuilder.AppendLine("Local player: " + ((LocalPlayer() != null) ? ("FOUND via " + localSrc) : "NOT FOUND"));
string[] array = new string[8] { "Player", "Network_Player", "Raft_Network", "ItemManager", "Item_Base", "ItemInstance", "Helper", "GameManager" };
for (int i = 0; i < array.Length; i++)
{
stringBuilder.AppendLine(" " + array[i] + ": " + ((R.T(array[i]) != null) ? "OK" : "MISSING"));
}
stringBuilder.AppendLine("Log file: " + FileLog.DesktopLog);
return stringBuilder.ToString();
}
private void DrawInfoTab()
{
GUILayout.Label("DIAGNOSTICS", sH, (GUILayoutOption[])(object)new GUILayoutOption[0]);
GUILayout.Label(BuildDiag(), sLabel, (GUILayoutOption[])(object)new GUILayoutOption[0]);
GUILayout.Space(8f);
GUILayout.BeginHorizontal((GUILayoutOption[])(object)new GUILayoutOption[0]);
if (GUILayout.Button("Copy diagnostics", sBtnBlue, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(36f) }))
{
GUIUtility.systemCopyBuffer = BuildDiag();
status = "Copied to clipboard - paste it into the chat.";
}
if (GUILayout.Button("Open log folder", sBtn, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(36f) }))
{
try
{
Application.OpenURL("file://" + Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory));
}
catch (Exception)
{
}
}
GUILayout.EndHorizontal();
GUILayout.Space(6f);
GUILayout.Label("A log file named RaftAdminMenu_log.txt is written to your Desktop. Settings: BepInEx/config/com.raftadmin.menu.cfg", sSmall, (GUILayoutOption[])(object)new GUILayoutOption[0]);
}
}
public class Drifter : MonoBehaviour
{
public Transform target;
public float speed = 3f;
private float born;
private Rigidbody rb;
private void Start()
{
rb = ((Component)this).GetComponent<Rigidbody>();
born = Time.time;
}
private void FixedUpdate()
{
//IL_002e: Unknown result type (might be due to invalid IL or missing references)
//IL_0039: Unknown result type (might be due to invalid IL or missing references)
//IL_003e: Unknown result type (might be due to invalid IL or missing references)
//IL_0043: Unknown result type (might be due to invalid IL or missing references)
//IL_0067: Unknown result type (might be due to invalid IL or missing references)
//IL_006c: Unknown result type (might be due to invalid IL or missing references)
//IL_0130: Unknown result type (might be due to invalid IL or missing references)
//IL_0135: Unknown result type (might be due to invalid IL or missing references)
//IL_013c: Unknown result type (might be due to invalid IL or missing references)
//IL_0146: Unknown result type (might be due to invalid IL or missing references)
//IL_014b: Unknown result type (might be due to invalid IL or missing references)
//IL_009f: Unknown result type (might be due to invalid IL or missing references)
//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
//IL_0102: Unknown result type (might be due to invalid IL or missing references)
//IL_011e: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)target == (Object)null || Time.time - born > 240f)
{
Object.Destroy((Object)(object)this);
return;
}
Vector3 val = target.position - ((Component)this).transform.position;
val.y = 0f;
if (((Vector3)(ref val)).magnitude < 3f)
{
Object.Destroy((Object)(object)this);
return;
}
Vector3 normalized = ((Vector3)(ref val)).normalized;
if ((Object)(object)rb != (Object)null && !rb.isKinematic)
{
rb.WakeUp();
rb.AddForce(normalized * speed * 2f, (ForceMode)5);
Vector3 velocity = rb.velocity;
Vector3 val2 = default(Vector3);
((Vector3)(ref val2))..ctor(velocity.x, 0f, velocity.z);
if (((Vector3)(ref val2)).magnitude > speed)
{
val2 = ((Vector3)(ref val2)).normalized * speed;
rb.velocity = new Vector3(val2.x, velocity.y, val2.z);
}
}
else
{
Transform transform = ((Component)this).transform;
transform.position += normalized * speed * Time.fixedDeltaTime;
}
}
}
public static class R
{
private const BindingFlags ALL = BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic;
private static Assembly asm;
private static Dictionary<string, Type> cache = new Dictionary<string, Type>();
public static Type T(string name)
{
if (cache.TryGetValue(name, out var value))
{
return value;
}
if (asm == null)
{
Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
for (int i = 0; i < assemblies.Length; i++)
{
if (assemblies[i].GetName().Name == "Assembly-CSharp")
{
asm = assemblies[i];
break;
}
}
}
value = ((asm != null) ? asm.GetType(name) : null);
if (value != null)
{
cache[name] = value;
}
return value;
}
public static object CM(string typeName)
{
Type type = T(typeName);
Type type2 = T("ComponentManager`1");
if (type == null || type2 == null)
{
return null;
}
try
{
return GetFrom(null, type2.MakeGenericType(type), "Value");
}
catch (Exception ex)
{
FileLog.Write("CM " + typeName + ": " + ex.Message);
return null;
}
}
public static bool TryDamage(object target, float dmg)
{
//IL_0095: Unknown result type (might be due to invalid IL or missing references)
if (target == null)
{
return false;
}
MethodInfo[] methods = target.GetType().GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy);
for (int i = 0; i < methods.Length; i++)
{
if (methods[i].Name != "Damage")
{
continue;
}
ParameterInfo[] parameters = methods[i].GetParameters();
object[] array = new object[parameters.Length];
bool flag = true;
for (int j = 0; j < parameters.Length; j++)
{
Type parameterType = parameters[j].ParameterType;
if (parameterType == typeof(float) && flag)
{
array[j] = dmg;
flag = false;
}
else if (parameterType == typeof(Vector3))
{
array[j] = Vector3.up;
}
else if (parameters[j].IsOptional)
{
array[j] = parameters[j].DefaultValue;
}
else if (parameterType.IsValueType)
{
array[j] = Activator.CreateInstance(parameterType);
}
else
{
array[j] = null;
}
}
try
{
methods[i].Invoke(target, array);
return true;
}
catch (Exception ex)
{
FileLog.Write("Damage overload failed: " + ex.Message);
}
}
return false;
}
public static object Get(object o, string name)
{
if (o == null)
{
return null;
}
return GetFrom(o, o.GetType(), name);
}
public static object GetStatic(string typeName, string name)
{
return GetFrom(null, T(typeName), name);
}
private static object GetFrom(object o, Type t, string name)
{
if (t == null)
{
return null;
}
try
{
Type type = t;
while (type != null)
{
FieldInfo field = type.GetField(name, BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
if (field != null)
{
return field.GetValue(field.IsStatic ? null : o);
}
PropertyInfo property = type.GetProperty(name, BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
if (property != null && property.CanRead && property.GetIndexParameters().Length == 0)
{
MethodInfo getMethod = property.GetGetMethod(nonPublic: true);
return getMethod.Invoke(getMethod.IsStatic ? null : o, null);
}
type = type.BaseType;
}
}
catch (Exception ex)
{
FileLog.Write("Get " + name + ": " + ex.Message);
}
return null;
}
public static bool SetMember(object o, Type t, string name, object v)
{
if (t == null && o != null)
{
t = o.GetType();
}
if (t == null)
{
return false;
}
try
{
Type type = t;
while (type != null)
{
FieldInfo field = type.GetField(name, BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
if (field != null)
{
field.SetValue(field.IsStatic ? null : o, Conv(v, field.FieldType));
return true;
}
PropertyInfo property = type.GetProperty(name, BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
if (property != null && property.CanWrite)
{
MethodInfo setMethod = property.GetSetMethod(nonPublic: true);
setMethod.Invoke(setMethod.IsStatic ? null : o, new object[1] { Conv(v, property.PropertyType) });
return true;
}
type = type.BaseType;
}
}
catch (Exception ex)
{
FileLog.Write(string.Concat("Set ", name, "=", v, ": ", ex.Message));
}
return false;
}
private static object Conv(object v, Type to)
{
if (v == null)
{
return null;
}
if (to.IsEnum)
{
if (!(v is string))
{
return Enum.ToObject(to, v);
}
return Enum.Parse(to, (string)v);
}
if (to.IsAssignableFrom(v.GetType()))
{
return v;
}
return Convert.ChangeType(v, to);
}
public static bool TryCall(object target, Type type, string name, out object result, params object[] args)
{
result = null;
if (type == null && target != null)
{
type = target.GetType();
}
if (type == null)
{
return false;
}
MethodInfo[] methods = type.GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy);
foreach (MethodInfo methodInfo in methods)
{
if (methodInfo.Name != name || (!methodInfo.IsStatic && target == null))
{
continue;
}
ParameterInfo[] parameters = methodInfo.GetParameters();
if (parameters.Length < args.Length)
{
continue;
}
object[] array = new object[parameters.Length];
bool flag = true;
for (int j = 0; j < parameters.Length; j++)
{
if (j < args.Length)
{
object obj = args[j];
if (obj == null)
{
if (parameters[j].ParameterType.IsValueType)
{
flag = false;
break;
}
}
else if (!parameters[j].ParameterType.IsAssignableFrom(obj.GetType()))
{
flag = false;
break;
}
array[j] = obj;
}
else
{
if (!parameters[j].IsOptional)
{
flag = false;
break;
}
array[j] = parameters[j].DefaultValue;
}
}
if (flag)
{
try
{
result = methodInfo.Invoke(methodInfo.IsStatic ? null : target, array);
return true;
}
catch (Exception ex)
{
Exception ex2 = ((ex.InnerException != null) ? ex.InnerException : ex);
FileLog.Write(name + " failed: " + ex2.Message);
}
}
}
return false;
}
}