C#:
// Все права принадлежат дискорд сообществу https://discord.gg/VgNHPpNrz6
using System.Collections.Generic;
using System;
using System.Reflection;
using System.Data;
using UnityEngine;
using Facepunch;
using Oxide.Core;
using Oxide.Core.Libraries;
using Oxide.Core.Plugins;
using System.Linq;
using Oxide.Core.Libraries.Covalence;
using Oxide.Game.Rust.Cui;
using System.Collections;
namespace Oxide.Plugins {
[Info("RemoverTool", "Reneb", "4.0.9", ResourceId = 651)]
class RemoverTool : RustPlugin {
[PluginReference]
Plugin Friends;
static RemoverTool rt = new RemoverTool();
#region Fields
static FieldInfo serverInput = typeof(BasePlayer).GetField("serverInput", (BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance | BindingFlags.NonPublic));
static FieldInfo buildingPrivilege = typeof(BasePlayer).GetField("buildingPrivilege", (BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance | BindingFlags.NonPublic));
static int colliderRemovable = LayerMask.GetMask("Construction", "Deployed", "Default");
static int colliderBuilding = LayerMask.GetMask("Construction");
static int colliderPlayer = LayerMask.GetMask("Player (Server)");
bool RemoveOverride = false;
static string permissionNormal = "removertool.remove";
static string permissionOverride = "removertool.override";
static string permissionAdmin = "removertool.admin";
static string permissionAll = "removertool.all";
static string permissionTarget = "removertool.target";
static int authTarget = 1;
static int authNormal = 0;
static int authAdmin = 2;
static int authAll = 2;
static int authOverride = 1;
static int removeDistanceNormal = 2;
static int removeDistanceAdmin = 20;
static int removeDistanceAll = 100;
static bool removeGibsNormal = true;
static bool removeGibsAdmin = true;
static bool removeGibsAll = false;
static int RemoveDefaultTime = 30;
static int RemoveMaxTime = 300;
static bool RemoveWithToolCupboards = false;
static bool RemoveWithEntityOwners = true;
static bool RemoveWithBuildingOwners = true;
static bool RemoveWithRustIO = true;
static bool RemoveWithFriends = true;
static bool RaidBlocker = true;
static bool RaidBlockerBlockBuildingID = true;
static bool RaidBlockerBlockSurroundingPlayers = true;
static int RaidBlockerRadius = 120;
static int RaidBlockerTime = 300;
static Dictionary<string, object> Price = new Dictionary<string, object>();
static Dictionary<string, object> Refund = new Dictionary<string, object>();
static Dictionary<string, object> ValidEntities = new Dictionary<string, object>();
static string GUIRemoverToolBackgroundColor = "0.1 0.1 0.1 0";
static string GUIRemoverToolAnchorMin = "0.1 0.65";
static string GUIRemoverToolAnchorMax = "0.4 0.95";
static string GUIRemoveBackgroundColor = "0.1 0.1 0.1 0.98";
static string GUIRemoveAnchorMin = "0 0.9";
static string GUIRemoveAnchorMax = "0.55 1";
static string GUIRemoveTextColor = "1 0.1 0.1 0.98";
static int GUIRemoveTextSize = 16;
static string GUIRemoveTextAnchorMin = "0.1 0";
static string GUIRemoveTextAnchorMax = "1 1";
static string GUITimeLeftBackgroundColor = "0.1 0.1 0.1 0.98";
static string GUITimeLeftAnchorMin = "0.55 0.9";
static string GUITimeLeftAnchorMax = "1 1";
static string GUITimeLeftTextColor = "1 1 1 0.98";
static int GUITimeLeftTextSize = 16;
static string GUITimeLeftTextAnchorMin = "0 0";
static string GUITimeLeftTextAnchorMax = "0.9 1";
static string GUIEntityBackgroundColor = "0.1 0.1 0.1 0.98";
static string GUIEntityAnchorMin = "0 0.8";
static string GUIEntityAnchorMax = "1 0.9";
static string GUIEntityTextColor = "1 1 1 0.98";
static int GUIEntityTextSize = 16;
static string GUIEntityTextAnchorMin = "0.05 0";
static string GUIEntityTextAnchorMax = "1 1";
static bool GUIAuthorizations = true;
static string GUIAllowedBackgroundColor = "0.1 1 0.1 0.3";
static string GUIRefusedBackgroundColor = "1 0.1 0.1 0.3";
static string GUIAuthorizationsAnchorMin = "0 0.8";
static string GUIAuthorizationsAnchorMax = "1 0.9";
static string GUIPriceBackgroundColor = "0.1 0.1 0.1 0.98";
static string GUIPriceAnchorMin = "0 0.60";
static string GUIPriceAnchorMax = "1 0.80";
static bool GUIPrices = true;
static string GUIPriceTextColor = "1 1 1 0.98";
static int GUIPriceTextSize = 16;
static string GUIPriceTextAnchorMin = "0.05 0";
static string GUIPriceTextAnchorMax = "0.3 1";
static string GUIPrice2TextColor = "1 1 1 0.98";
static int GUIPrice2TextSize = 16;
static string GUIPrice2TextAnchorMin = "0.35 0";
static string GUIPrice2TextAnchorMax = "1 1";
static string GUIRefundBackgroundColor = "0.1 0.1 0.1 0.98";
static string GUIRefundAnchorMin = "0 0.40";
static string GUIRefundAnchorMax = "1 0.60";
static bool GUIRefund = true;
static string GUIRefundTextColor = "1 1 1 0.98";
static int GUIRefundTextSize = 16;
static string GUIRefundTextAnchorMin = "0.05 0";
static string GUIRefundTextAnchorMax = "0.3 1";
static string GUIRefund2TextColor = "1 1 1 0.98";
static int GUIRefund2TextSize = 16;
static string GUIRefund2TextAnchorMin = "0.35 0";
static string GUIRefund2TextAnchorMax = "1 1";
static Dictionary<string, string> PrefabNameToDeployable = new Dictionary<string, string>();
static Dictionary<string, string> PrefabNameToStructure = new Dictionary<string, string>();
static Dictionary<string, int> ItemNameToItemID = new Dictionary<string, int>();
static Hash<uint, float> LastAttackedBuildings = new Hash<uint, float>();
static Hash<ulong, float> LastBlockedPlayers = new Hash<ulong, float>();
public enum RemoveType {
All, Structure, Admin, Normal
}
#endregion
#region Config
protected override void LoadDefaultConfig() {
}
private void CheckCfg<T>(string Key, ref T var) {
if (Config[Key] is T) var = (T)Config[Key];
else Config[Key] = var;
}
#endregion
#region Oxide Hooks
void LoadConfigs() {
CheckCfg<string>("Remove - Access - Oxide Permissions - Normal", ref permissionNormal);
CheckCfg<string>("Remove - Access - Oxide Permissions - Override", ref permissionOverride);
CheckCfg<string>("Remove - Access - Oxide Permissions - Admin", ref permissionAdmin);
CheckCfg<string>("Remove - Access - Oxide Permissions - All", ref permissionAll);
CheckCfg<string>("Remove - Access - Oxide Permissions - Target", ref permissionTarget);
CheckCfg<int>("Remove - Access - AuthLevel - Normal", ref authNormal);
CheckCfg<int>("Remove - Access - AuthLevel - Override", ref authOverride);
CheckCfg<int>("Remove - Access - AuthLevel - Admin", ref authAdmin);
CheckCfg<int>("Remove - Access - AuthLevel - All", ref authAll);
CheckCfg<int>("Remove - Access - AuthLevel - Target", ref authTarget);
CheckCfg<int>("Remove - Distance - Normal", ref removeDistanceNormal);
CheckCfg<int>("Remove - Distance - Admin", ref removeDistanceAdmin);
CheckCfg<int>("Remove - Distance - All/Structure", ref removeDistanceAll);
CheckCfg<bool>("Remove - Gibs - Normal", ref removeGibsNormal);
CheckCfg<bool>("Remove - Gibs - Admin", ref removeGibsAdmin);
CheckCfg<bool>("Remove - Gibs - All", ref removeGibsAll);
CheckCfg<int>("Remove - Time - Default", ref RemoveDefaultTime);
CheckCfg<int>("Remove - Time - Max", ref RemoveMaxTime);
CheckCfg<bool>("Remove - Normal - Use Tool Cupboards (strongly unrecommended)", ref RemoveWithToolCupboards);
CheckCfg<bool>("Remove - Normal - Use Entity Owners", ref RemoveWithEntityOwners);
CheckCfg<bool>("Remove - Normal - Use Building Owners (You will need Building Owners plugin)", ref RemoveWithBuildingOwners);
CheckCfg<bool>("Remove - Normal - Use Friends (RustIO)", ref RemoveWithRustIO);
CheckCfg<bool>("Remove - Normal - Use Friends (Friends)", ref RemoveWithFriends);
CheckCfg<bool>("Remove - Normal - RaidBlocker", ref RaidBlocker);
CheckCfg<bool>("Remove - Normal - RaidBlocker - By Buildings", ref RaidBlockerBlockBuildingID);
CheckCfg<bool>("Remove - Normal - RaidBlocker - By Surrounding Players", ref RaidBlockerBlockSurroundingPlayers);
CheckCfg<int>("Remove - Normal - RaidBlocker - By Surrounding Players - Radius", ref RaidBlockerRadius);
CheckCfg<int>("Remove - Normal - RaidBlocker - Time", ref RaidBlockerTime);
ValidEntities = DefaultEntities();
Price = DefaultPay();
Refund = DefaultRefund();
CheckCfg<Dictionary<string, object>>("Remove - Normal - Allowed Entities", ref ValidEntities);
CheckCfg<Dictionary<string, object>>("Remove - Normal - Price", ref Price);
CheckCfg<Dictionary<string, object>>("Remove - Normal - Refund", ref Refund);
CheckCfg<string>("Remove - GUI - Main Box - Min Anchor (in Rust Window)", ref GUIRemoverToolAnchorMin);
CheckCfg<string>("Remove - GUI - Main Box - Max Anchor (in Rust Window)", ref GUIRemoverToolAnchorMax);
CheckCfg<string>("Remove - GUI - Main Box - Background Color", ref GUIRemoverToolBackgroundColor);
CheckCfg<string>("Remove - GUI - Remove - Box - Min Anchor (in Main Box)", ref GUIRemoveAnchorMin);
CheckCfg<string>("Remove - GUI - Remove - Box - Max Anchor (in Main Box)", ref GUIRemoveAnchorMax);
CheckCfg<string>("Remove - GUI - Remove - Box - Background Color", ref GUIRemoveBackgroundColor);
CheckCfg<string>("Remove - GUI - Remove - Text - Min Anchor (in Remove Box)", ref GUIRemoveTextAnchorMin);
CheckCfg<string>("Remove - GUI - Remove - Text - Max Anchor (in Remove Box)", ref GUIRemoveTextAnchorMax);
CheckCfg<string>("Remove - GUI - Remove - Text - Text Color", ref GUIRemoveTextColor);
CheckCfg<int>("Remove - GUI - Remove - Text - Text Size", ref GUIRemoveTextSize);
CheckCfg<string>("Remove - GUI - Timeleft - Box - Min Anchor (in Main Box)", ref GUITimeLeftAnchorMin);
CheckCfg<string>("Remove - GUI - Timeleft - Box - Max Anchor (in Main Box)", ref GUITimeLeftAnchorMax);
CheckCfg<string>("Remove - GUI - Timeleft - Box - Background Color", ref GUITimeLeftBackgroundColor);
CheckCfg<string>("Remove - GUI - Timeleft - Text - Min Anchor (in Timeleft Box)", ref GUITimeLeftTextAnchorMin);
CheckCfg<string>("Remove - GUI - Timeleft - Text - Max Anchor (in Timeleft Box)", ref GUITimeLeftTextAnchorMax);
CheckCfg<string>("Remove - GUI - Timeleft - Text - Text Color", ref GUITimeLeftTextColor);
CheckCfg<int>("Remove - GUI - Timeleft - Text - Text Size", ref GUITimeLeftTextSize);
CheckCfg<string>("Remove - GUI - Entity - Box - Min Anchor (in Main Box)", ref GUIEntityAnchorMin);
CheckCfg<string>("Remove - GUI - Entity - Box - Max Anchor (in Main Box)", ref GUIEntityAnchorMax);
CheckCfg<string>("Remove - GUI - Entity - Box - Background Color", ref GUIEntityBackgroundColor);
CheckCfg<string>("Remove - GUI - Entity - Text - Min Anchor (in Entity Box)", ref GUIEntityTextAnchorMin);
CheckCfg<string>("Remove - GUI - Entity - Text - Max Anchor (in Entity Box)", ref GUIEntityTextAnchorMax);
CheckCfg<string>("Remove - GUI - Entity - Text - Text Color", ref GUIEntityTextColor);
CheckCfg<int>("Remove - GUI - Entity - Text - Text Size", ref GUIEntityTextSize);
CheckCfg<bool>("Remove - GUI - Authorization Check Hightlighting Box", ref GUIAuthorizations);
CheckCfg<string>("Remove - GUI - Authorization Check Hightlighting Box - Min Anchor (in Main Box)", ref GUIAuthorizationsAnchorMin);
CheckCfg<string>("Remove - GUI - Authorization Check Hightlighting Box - Max Anchor (in Main Box)", ref GUIAuthorizationsAnchorMax);
CheckCfg<string>("Remove - GUI - Authorization Check Hightlighting Box - Allowed Background", ref GUIAllowedBackgroundColor);
CheckCfg<string>("Remove - GUI - Authorization Check Hightlighting Box - Refused Background", ref GUIRefusedBackgroundColor);
CheckCfg<bool>("Remove - GUI - Price", ref GUIPrices);
CheckCfg<string>("Remove - GUI - Price - Box - Min Anchor (in Main Box)", ref GUIPriceAnchorMin);
CheckCfg<string>("Remove - GUI - Price - Box - Max Anchor (in Main Box)", ref GUIPriceAnchorMax);
CheckCfg<string>("Remove - GUI - Price - Box - Background Color", ref GUIPriceBackgroundColor);
CheckCfg<string>("Remove - GUI - Price - Text - Min Anchor (in Price Box)", ref GUIPriceTextAnchorMin);
CheckCfg<string>("Remove - GUI - Price - Text - Max Anchor (in Price Box)", ref GUIPriceTextAnchorMax);
CheckCfg<string>("Remove - GUI - Price - Text - Text Color", ref GUIPriceTextColor);
CheckCfg<int>("Remove - GUI - Price - Text - Text Size", ref GUIPriceTextSize);
CheckCfg<string>("Remove - GUI - Price - Text2 - Min Anchor (in Price Box)", ref GUIPrice2TextAnchorMin);
CheckCfg<string>("Remove - GUI - Price - Text2 - Max Anchor (in Price Box)", ref GUIPrice2TextAnchorMax);
CheckCfg<string>("Remove - GUI - Price - Text2 - Text Color", ref GUIPrice2TextColor);
CheckCfg<int>("Remove - GUI - Price - Text2 - Text Size", ref GUIPrice2TextSize);
CheckCfg<bool>("Remove - GUI - Refund", ref GUIRefund);
CheckCfg<string>("Remove - GUI - Refund - Box - Min Anchor (in Main Box)", ref GUIRefundAnchorMin);
CheckCfg<string>("Remove - GUI - Refund - Box - Max Anchor (in Main Box)", ref GUIRefundAnchorMax);
CheckCfg<string>("Remove - GUI - Refund - Box - Background Color", ref GUIRefundBackgroundColor);
CheckCfg<string>("Remove - GUI - Refund - Text - Min Anchor (in Refund Box)", ref GUIRefundTextAnchorMin);
CheckCfg<string>("Remove - GUI - Refund - Text - Max Anchor (in Refund Box)", ref GUIRefundTextAnchorMax);
CheckCfg<string>("Remove - GUI - Refund - Text - Text Color", ref GUIRefundTextColor);
CheckCfg<int>("Remove - GUI - Refund - Text - Text Size", ref GUIRefundTextSize);
CheckCfg<string>("Remove - GUI - Refund - Text2 - Min Anchor (in Refund Box)", ref GUIRefund2TextAnchorMin);
CheckCfg<string>("Remove - GUI - Refund - Text2 - Max Anchor (in Refund Box)", ref GUIRefund2TextAnchorMax);
CheckCfg<string>("Remove - GUI - Refund - Text2 - Text Color", ref GUIRefund2TextColor);
CheckCfg<int>("Remove - GUI - Refund - Text2 - Text Size", ref GUIRefund2TextSize);
SaveConfig();
}
void OnServerInitialized() {
InitializeRustIO();
InitializeItems();
InitializeConstruction();
LoadConfigs();
permission.RegisterPermission(permissionNormal, this);
permission.RegisterPermission(permissionAdmin, this);
permission.RegisterPermission(permissionTarget, this);
permission.RegisterPermission(permissionAll, this);
rt = this;
}
void Loaded() {
lang.RegisterMessages(new Dictionary<string, string> {
{
"You don't have access to this command.", "You don't have access to this command."
}
, {
"{0} {1} now has remover tool activated for {2} seconds ({3})", "{0} {1} now has remover tool activated for {2} seconds ({3})"
}
, {
"Couldn't use the RemoverTool: You don't have enough resources.", "Couldn't use the RemoverTool: You don't have enough resources."
}
, {
"RemoverTool from your target has been deactivated.", "RemoverTool from your target has been deactivated."
}
, {
"Couldn't use the RemoverTool: Admin has restricted this entity from being removed.", "Couldn't use the RemoverTool: Admin has restricted this entity from being removed."
}
, {
"Couldn't use the RemoverTool: An external plugin blocked the usage", "Couldn't use the RemoverTool: An external plugin blocked the usage"
}
, {
"Couldn't use the RemoverTool: No valid entity targeted", "Couldn't use the RemoverTool: No valid entity targeted"
}
, {
"Couldn't use the RemoverTool: Paying system crashed! Contact an administrator with the time and date to help him understand what happened.", "Couldn't use the RemoverTool: Paying system crashed! Contact an administrator with the time and date to help him understand what happened."
}
, {
"Couldn't use the RemoverTool: No valid entity targeted, or entity is too far.", "Couldn't use the RemoverTool: No valid entity targeted, or entity is too far."
}
, {
"Refund:", "Refund:"
}
, {
"Nothing", "Nothing"
}
, {
"Price:", "Price:"
}
, {
"Free", "Free"
}
, {
"Timeleft: {0}secs", "Timeleft: {0}secs"
}
, {
"Remover Tool {0}", "Remover Tool {0}"
}
, {
"RemoverTool is currently disabled.\n", "RemoverTool is currently disabled.\n"
}
, {
"You are not allowed to use this command option.\n", "You are not allowed to use this command option.\n"
}
, {
"You are not allowed to use this command.\n", "You are not allowed to use this command.\n"
}
, {
"Couldn't use the RemoverTool: The Remover Tool is blocked for another {0} seconds.", "Couldn't use the RemoverTool: The Remover Tool is blocked for another {0} seconds."
}
, {
"Couldn't find player.Multiple players match: {0}.\n", "Couldn't find player.Multiple players match: {0}.\n"
}
, {
"Couldn't find player.No players match this name: {0}.\n", "Couldn't find player.No players match this name: {0}.\n"
}
, {
"Couldn't use the RemoverTool: You don't have any rights to remove this.", "Couldn't use the RemoverTool: You don't have any rights to remove this."
}
, {
"<size=18>Remover Tool</size> by <color=#ce422b>Reneb</color>\n<color=\"#ffd479\">/remove optional:TimerInSeconds</color> - Activate/Deactivate the Remover Tool, You will need to have no highlighted items in your belt bar.", "<size=18>Remover Tool</size> by <color=#ce422b>Reneb</color>\n<color=\"#ffd479\">/remove optional:TimerInSeconds</color> - Activate/Deactivate the Remover Tool, You will need to have no highlighted items in your belt bar."
}
}
, this);
}
void Unload() {
foreach (ToolRemover toolremover in Resources.FindObjectsOfTypeAll<ToolRemover>()) {
toolremover.Destroy();
}
}
#endregion
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// RustIO Inclusion
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
private static Library RustIO;
private static MethodInfo isInstalled;
private static MethodInfo hasFriend;
private static bool RustIOIsInstalled() {
if (RustIO == null) return false;
return (bool)isInstalled.Invoke(RustIO, new object[] {
}
);
}
private void InitializeRustIO() {
if (!RemoveWithRustIO) {
RustIO = null;
return;
}
RustIO = Interface.GetMod().GetLibrary<Library>("RustIO");
if (RustIO == null || (isInstalled = RustIO.GetFunction("IsInstalled")) == null || (hasFriend = RustIO.GetFunction("HasFriend")) == null) {
RustIO = null;
Puts("{0}: {1}", Title, "Rust:IO is not present.You need to install Rust:IO first in order to use the RustIO option!");
}
}
private static bool HasFriend(string playerId, string friendId) {
if (RustIO == null) return false;
return (bool)hasFriend.Invoke(RustIO, new object[] {
playerId, friendId
}
);
}
#region Initializing
void InitializeItems() {
foreach (var item in ItemManager.GetItemDefinitions()) {
if (!ItemNameToItemID.ContainsKey(item.displayName.english.ToLower())) ItemNameToItemID.Add(item.displayName.english.ToLower(), item.itemid);
var itemdeployable = item?.GetComponent<ItemModDeployable>();
if (itemdeployable == null) continue;
if (!PrefabNameToDeployable.ContainsKey(itemdeployable.entityPrefab.resourcePath)) PrefabNameToDeployable.Add(itemdeployable.entityPrefab.resourcePath, item.displayName.english);
}
}
void InitializeConstruction() {
foreach (var construction in PrefabAttribute.server.GetAll<Construction>()) {
if (construction.deployable == null && construction.info.name.english != string.Empty) if (!PrefabNameToStructure.ContainsKey(construction.fullName)) PrefabNameToStructure.Add(construction.fullName, construction.info.name.english);
}
}
Dictionary<string, object> DefaultPay() {
var d = new Dictionary<string, object> {
{
"Twigs", new Dictionary<string, object> {
{
"wood", 1
}
}
}
, {
"Wood", new Dictionary<string, object> {
{
"wood", 10
}
}
}
, {
"Stone", new Dictionary<string, object> {
{
"stones", 50
}
, {
"wood", 10
}
}
}
, {
"Metal", new Dictionary<string, object> {
{
"metal fragments", 75
}
}
}
, {
"TopTier", new Dictionary<string, object> {
{
"high quality metal", 5
}
}
}
,
}
;
foreach (var itemname in PrefabNameToDeployable.Values) {
d.Add(itemname, new Dictionary<string, object> {
{
"wood", 75
}
, {
"metal fragments", 10
}
}
);
}
return d;
}
Dictionary<string, object> DefaultEntities() {
var d = new Dictionary<string, object> {
{
"Twigs", true
}
, {
"Wood", true
}
, {
"Stone", true
}
, {
"Metal", true
}
, {
"TopTier", true
}
}
;
foreach (var itemname in PrefabNameToStructure.Values) {
d.Add(itemname, true);
}
foreach (var itemname in PrefabNameToDeployable.Values) {
d.Add(itemname, true);
}
return d;
}
Dictionary<string, object> DefaultRefund() {
var d = new Dictionary<string, object> {
{
"Twigs", new Dictionary<string, object> {
{
"wood", 1
}
}
}
, {
"Wood", new Dictionary<string, object> {
{
"wood", 10
}
}
}
, {
"Stone", 50
}
, {
"Metal", new Dictionary<string, object> {
{
"metal fragments", 50
}
}
}
, {
"TopTier", new Dictionary<string, object> {
{
"high quality metal", 2
}
}
}
,
}
;
foreach (var itemname in PrefabNameToDeployable.Values) {
d.Add(itemname, new Dictionary<string, object> {
{
itemname.ToLower(), 1
}
}
);
}
return d;
}
#endregion
#region Methods
static string GetMsg(string key, BasePlayer source = null) {
return rt.lang.GetMessage(key, rt, source == null ? null : source.UserIDString);
}
bool hasPermission(BasePlayer player, string perm, int authlevel) {
if (player == null) return true;
if (player.net.connection.authLevel >= authlevel) return true;
return permission.UserHasPermission(player.userID.ToString(), perm);
}
string ListPlayersToString(List<IPlayer> players) {
var returnstring = string.Empty;
foreach (var player in players) {
returnstring += string.Format("{0} {1}\n", player.Id, player.Name);
}
return returnstring;
}
bool GetParameters(BasePlayer player, string[] args, out RemoveType RemoveType, out BasePlayer Target, out int Time, out string Reason) {
Reason = string.Empty;
Target = player;
RemoveType = RemoveType.Normal;
Time = RemoveDefaultTime;
if (args != null) {
foreach (var arg in args) {
switch (arg.ToLower()) {
case "normal" : RemoveType = RemoveType.Normal;
break;
case "admin" : RemoveType = RemoveType.Admin;
break;
case "all" : RemoveType = RemoveType.All;
break;
case "structure" : RemoveType = RemoveType.Structure;
break;
default : ulong userid = 0L;
int temptime = 0;
if (arg.Length == 17 && ulong.TryParse(arg, out userid)) {
Target = BasePlayer.Find(arg);
}
else if (int.TryParse(arg, out temptime)) {
Time = temptime;
}
else {
var players = covalence.Players.FindPlayers(arg).Where(x => x.IsConnected).ToList();
if (players.Count == 0) {
Reason += string.Format(GetMsg("Couldn't find player.No players match this name: {0}.\n", player), arg);
}
else if (players.Count > 1) {
Reason += string.Format(GetMsg("Couldn't find player.Multiple players match: {0}.\n", player), ListPlayersToString(players));
}
else {
Target = (BasePlayer)players[0]?.Object;
}
}
break;
}
}
}
if (Target != player && !hasPermission(player, permissionTarget, authTarget)) Reason += string.Format(GetMsg("You are not allowed to use this command option.\n", player));
if (RemoveType == RemoveType.Normal && !hasPermission(player, permissionNormal, authNormal)) Reason += string.Format(GetMsg("You are not allowed to use this command.\n", player));
if ((RemoveType == RemoveType.All || RemoveType == RemoveType.Structure) && !hasPermission(player, permissionAll, authAll)) Reason += string.Format(GetMsg("You are not allowed to use this command option.\n", player));
if (RemoveType == RemoveType.Admin && !hasPermission(player, permissionAdmin, authAdmin)) Reason += string.Format(GetMsg("You are not allowed to use this command option.\n", player));
if (RemoveOverride && !hasPermission(player, permissionOverride, authOverride)) Reason += string.Format(GetMsg("RemoverTool is currently disabled.\n", player));
if (Time > RemoveMaxTime) Time = RemoveMaxTime;
return (Reason == string.Empty);
}
static void DoRemove(BaseEntity Entity, bool gibs = true) {
if (Entity != null) {
Interface.Oxide.CallHook("OnRemovedEntity", Entity);
if (!Entity.isDestroyed) Entity.Kill(gibs ? BaseNetworkable.DestroyMode.Gib : BaseNetworkable.DestroyMode.None);
}
}
#endregion
#region UI
public class UI {
static public CuiElementContainer CreateElementContainer(string parent, string panelName, string color, string aMin, string aMax, bool useCursor) {
var NewElement = new CuiElementContainer() {
{
new CuiPanel {
Image = {
Color = color
}
, RectTransform = {
AnchorMin = aMin, AnchorMax = aMax
}
, CursorEnabled = useCursor
}
, new CuiElement().Parent = parent, panelName
}
}
;
return NewElement;
}
static public void CreatePanel(ref CuiElementContainer container, string panel, string color, string aMin, string aMax, bool cursor = false) {
container.Add(new CuiPanel {
Image = {
Color = color
}
, RectTransform = {
AnchorMin = aMin, AnchorMax = aMax
}
, CursorEnabled = cursor
}
, panel);
}
static public void CreateLabel(ref CuiElementContainer container, string panel, string color, string text, int size, string aMin, string aMax, TextAnchor align = TextAnchor.MiddleCenter) {
container.Add(new CuiLabel {
Text = {
Color = color, FontSize = size, Align = align, Text = text
}
, RectTransform = {
AnchorMin = aMin, AnchorMax = aMax
}
}
, panel);
}
static public void CreateButton(ref CuiElementContainer container, string panel, string color, string text, int size, string aMin, string aMax, string command, TextAnchor align = TextAnchor.MiddleCenter) {
container.Add(new CuiButton {
Button = {
Color = color, Command = command, FadeIn = 1.0f
}
, RectTransform = {
AnchorMin = aMin, AnchorMax = aMax
}
, Text = {
Text = text, FontSize = size, Align = align
}
}
, panel);
}
}
public static string GetName(string prefabname) {
if (PrefabNameToStructure.ContainsKey(prefabname)) return PrefabNameToStructure[prefabname];
else if (PrefabNameToDeployable.ContainsKey(prefabname)) return PrefabNameToDeployable[prefabname];
return string.Empty;
}
public static void CreateGUI(BasePlayer player, RemoveType removeType) {
var panelName = "RemoverTool";
CuiHelper.DestroyUi(player, panelName);
var Class_Element = UI.CreateElementContainer("Overlay", panelName, GUIRemoverToolBackgroundColor, GUIRemoverToolAnchorMin, GUIRemoverToolAnchorMax, false);
CuiHelper.AddUi(player, Class_Element);
var panelName2 = "Remove";
CuiHelper.DestroyUi(player, panelName2);
var Class_Element2 = UI.CreateElementContainer(panelName, panelName2, GUIRemoveBackgroundColor, GUIRemoveAnchorMin, GUIRemoveAnchorMax, false);
UI.CreateLabel(ref Class_Element2, panelName2, GUIRemoveTextColor, string.Format(GetMsg("Remover Tool {0}", player), removeType == RemoveType.Normal ? string.Empty : string.Format("({0})", removeType.ToString())), GUIRemoveTextSize, GUIRemoveTextAnchorMin, GUIRemoveTextAnchorMax, TextAnchor.MiddleLeft);
CuiHelper.AddUi(player, Class_Element2);
}
public static void GUITimeLeftUpdate(BasePlayer player, int timeleft) {
var panelName = "RemoverToolTimeLeft";
CuiHelper.DestroyUi(player, panelName);
var Class_Element = UI.CreateElementContainer("RemoverTool", panelName, GUITimeLeftBackgroundColor, GUITimeLeftAnchorMin, GUITimeLeftAnchorMax, false);
UI.CreateLabel(ref Class_Element, panelName, GUITimeLeftTextColor, string.Format(GetMsg("Timeleft: {0}secs", player), timeleft.ToString()), GUITimeLeftTextSize, GUITimeLeftTextAnchorMin, GUITimeLeftTextAnchorMax, TextAnchor.MiddleLeft);
CuiHelper.AddUi(player, Class_Element);
}
public static void GUIEntityUpdate(BasePlayer player, BaseEntity TargetEntity) {
var panelName = "RemoverToolEntity";
CuiHelper.DestroyUi(player, panelName);
if (TargetEntity == null) return;
var Name = GetName(TargetEntity.PrefabName);
var Class_Element = UI.CreateElementContainer("RemoverTool", panelName, GUIEntityBackgroundColor, GUIEntityAnchorMin, GUIEntityAnchorMax, false);
UI.CreateLabel(ref Class_Element, panelName, GUIEntityTextColor, Name, GUIEntityTextSize, GUIEntityTextAnchorMin, GUIEntityTextAnchorMax, TextAnchor.MiddleLeft);
CuiHelper.AddUi(player, Class_Element);
}
public static void GUIPricesUpdate(BasePlayer player, bool usePrice, BaseEntity TargetEntity) {
var panelName = "RemoverToolPrice";
CuiHelper.DestroyUi(player, panelName);
if (TargetEntity == null) return;
Dictionary<string, object> price = new Dictionary<string, object>();
if (usePrice) {
price = GetPrice(TargetEntity);
}
string cost = string.Empty;
if (price.Count == 0) cost = GetMsg("Free", player);
else {
foreach (KeyValuePair<string, object> p in price) {
cost += string.Format("{2}{0} x{1}", p.Key, p.Value.ToString(), cost != string.Empty ? "\n" : string.Empty);
}
}
var Class_Element = UI.CreateElementContainer("RemoverTool", panelName, GUIPriceBackgroundColor, GUIPriceAnchorMin, GUIPriceAnchorMax, false);
UI.CreateLabel(ref Class_Element, panelName, GUIPriceTextColor, GetMsg("Price:", player), GUIPriceTextSize, GUIPriceTextAnchorMin, GUIPriceTextAnchorMax, TextAnchor.MiddleLeft);
UI.CreateLabel(ref Class_Element, panelName, GUIPrice2TextColor, cost, GUIPrice2TextSize, GUIPrice2TextAnchorMin, GUIPrice2TextAnchorMax, TextAnchor.MiddleLeft);
CuiHelper.AddUi(player, Class_Element);
}
public static void GUIRefundUpdate(BasePlayer player, bool useRefund, BaseEntity TargetEntity) {
var panelName = "RemoverToolRefund";
CuiHelper.DestroyUi(player, panelName);
if (TargetEntity == null) return;
Dictionary<string, object> refund = new Dictionary<string, object>();
if (useRefund) {
refund = GetRefund(TargetEntity);
}
string r = string.Empty;
if (refund.Count == 0) r = GetMsg("Nothing", player);
else {
foreach (KeyValuePair<string, object> p in refund) {
r += string.Format("{2}{0} x{1}", p.Key, p.Value.ToString(), r != string.Empty ? "\n" : string.Empty);
}
}
var Class_Element = UI.CreateElementContainer("RemoverTool", panelName, GUIRefundBackgroundColor, GUIRefundAnchorMin, GUIRefundAnchorMax, false);
UI.CreateLabel(ref Class_Element, panelName, GUIRefundTextColor, GetMsg("Refund:", player), GUIRefundTextSize, GUIRefundTextAnchorMin, GUIRefundTextAnchorMax, TextAnchor.MiddleLeft);
UI.CreateLabel(ref Class_Element, panelName, GUIRefund2TextColor, r, GUIRefund2TextSize, GUIRefund2TextAnchorMin, GUIRefund2TextAnchorMax, TextAnchor.MiddleLeft);
CuiHelper.AddUi(player, Class_Element);
}
public static void GUIAuthorizationUpdate(BasePlayer player, RemoveType removeType, BaseEntity TargetEntity, bool shouldPay) {
var panelName = "RemoverToolAuth";
CuiHelper.DestroyUi(player, panelName);
if (TargetEntity == null) return;
string Reason = string.Empty;
string GUIColor = CanRemoveEntity(player, removeType, TargetEntity, shouldPay, out Reason) ? GUIAllowedBackgroundColor : GUIRefusedBackgroundColor;
var Class_Element = UI.CreateElementContainer("RemoverTool", panelName, GUIColor, GUIAuthorizationsAnchorMin, GUIAuthorizationsAnchorMax, false);
CuiHelper.AddUi(player, Class_Element);
}
public static void DestroyGUI(BasePlayer player) {
CuiHelper.DestroyUi(player, "RemoverTool");
}
#endregion
#region ToolRemover Class
class ToolRemover : MonoBehaviour {
public BasePlayer player {
get;
set;
}
public BasePlayer source {
get;
set;
}
public int timeLeft {
get;
set;
}
public float distance {
get;
set;
}
public RemoveType removetype {
get;
set;
}
public bool Pay {
get;
set;
}
public bool Refund {
get;
set;
}
public BaseEntity TargetEntity {
get;
set;
}
RaycastHit RayHit;
InputState state;
float lastUpdate {
get;
set;
}
float lastRemove {
get;
set;
}
void Awake() {
player = GetComponent<BasePlayer>();
lastUpdate = UnityEngine.Time.realtimeSinceStartup;
lastRemove = UnityEngine.Time.realtimeSinceStartup;
}
public void Start() {
state = (InputState)serverInput.GetValue(player);
CreateGUI(player, removetype);
CancelInvoke("RemoveUpdate");
InvokeRepeating("RemoveUpdate", 0f, 1f);
}
void RemoveUpdate() {
timeLeft--;
if (timeLeft <= 0) {
Destroy();
return;
}
GUITimeLeftUpdate(player, timeLeft);
GUIEntityUpdate(player, TargetEntity);
if (removetype == RemoveType.Normal && GUIAuthorizations) GUIAuthorizationUpdate(player, removetype, TargetEntity, Pay);
if (removetype == RemoveType.Normal && GUIPrices) GUIPricesUpdate(player, Pay, TargetEntity);
if (removetype == RemoveType.Normal && GUIRefund) GUIRefundUpdate(player, Refund, TargetEntity);
}
void FixedUpdate() {
if (player.IsSleeping() || !player.IsConnected()) {
Destroy();
return;
}
float currentTime = UnityEngine.Time.realtimeSinceStartup;
if (currentTime - lastUpdate >= 0.5f) {
bool flag1 = Physics.Raycast(player.eyes.HeadRay(), out RayHit, distance, colliderRemovable);
TargetEntity = flag1 ? RayHit.GetEntity() : null;
lastUpdate = currentTime;
}
if (state.IsDown(BUTTON.FIRE_PRIMARY)) {
if (currentTime - lastRemove >= 0.5f) {
var returnmsg = TryRemove(player, removetype, distance, Pay, Refund);
if (returnmsg != string.Empty) player.ChatMessage(returnmsg);
lastRemove = currentTime;
}
}
}
public void Destroy() {
CancelInvoke("RemoveUpdate");
DestroyGUI(player);
GameObject.Destroy(this);
}
}
#endregion
#region Pay
static bool Pay(BasePlayer player, BaseEntity TargetEntity) {
var cost = GetPrice(TargetEntity);
try {
List<Item> collect = new List<Item>();
foreach (KeyValuePair<string, object> p in cost) {
var priceName = p.Key.ToLower();
var amount = (int)p.Value;
if (ItemNameToItemID.ContainsKey(priceName)) {
var itemid = ItemNameToItemID[priceName];
player.inventory.Take(collect, itemid, amount);
player.Command("note.inv", itemid, -amount);
}
else if (priceName == "withdraw") {
var w = Interface.Oxide.CallHook("Withdraw", player.userID, (double)amount);
if (w == null || !(bool)w) return false;
}
}
foreach (Item item in collect) {
item.Remove(0f);
}
}
catch (Exception e) {
Interface.Oxide.LogWarning(string.Format("{0} {1} couldn't pay to remove entity: {2}", player.UserIDString, player.displayName, e.Message));
return false;
}
return true;
}
static Dictionary<string, object> GetPrice(BaseEntity TargetEntity) {
var cost = new Dictionary<string, object>();
var buildingblock = TargetEntity.GetComponent<BuildingBlock>();
if (buildingblock != null) {
var grade = buildingblock.grade.ToString();
if (Price.ContainsKey(grade)) cost = Price[grade] as Dictionary<string, object>;
}
else {
var prefabname = TargetEntity.PrefabName;
if (PrefabNameToDeployable.ContainsKey(prefabname)) {
var deployablename = PrefabNameToDeployable[prefabname];
if (Price.ContainsKey(deployablename)) {
cost = Price[deployablename] as Dictionary<string, object>;
}
}
}
return cost;
}
static bool CanPay(BasePlayer player, BaseEntity TargetEntity) {
var prefabname = TargetEntity.PrefabName;
var cost = GetPrice(TargetEntity);
if (cost.Count == 0) return true;
foreach (KeyValuePair<string, object> p in cost) {
var priceName = p.Key.ToLower();
var amount = (int)p.Value;
if (ItemNameToItemID.ContainsKey(priceName)) {
int c = player.inventory.GetAmount(ItemNameToItemID[priceName]);
if (c < amount) return false;
}
else if (priceName == "withdraw") {
var b = Interface.Oxide.CallHook("GetPlayerMoney", player.userID);
if (b == null) return false;
var balance = (double)b;
if (balance <= amount) return false;
}
}
return true;
}
#endregion
#region Refund
static void GiveRefund(BasePlayer player, BaseEntity TargetEntity) {
var refund = GetRefund(TargetEntity);
foreach (KeyValuePair<string, object> p in refund) {
var itemname = p.Key.ToLower();
if (ItemNameToItemID.ContainsKey(itemname)) {
var itemid = ItemNameToItemID[itemname];
var itemamount = (int)p.Value;
var item = ItemManager.CreateByItemID(itemid, itemamount);
player.inventory.GiveItem(item, null);
player.Command("note.inv", itemid, itemamount);
}
// ... [Code preview truncated due to length. Full source in attached file] ...