Иконка ресурса

FREE UberTool : 1.3.4 1.3.4

Нет прав для скачивания
C#:
// Все права принадлежат дискорд сообществу https://discord.gg/VgNHPpNrz6
using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Globalization;
using System.Reflection;
using Oxide.Core;
using Oxide.Core.Plugins;
using Oxide.Core.Libraries.Covalence;
using UnityEngine;
using Network;
using Facepunch;
using System.Text.RegularExpressions;
using ProtoBuf;
using Oxide.Game.Rust.Cui;
using static System.Math;
using Newtonsoft.Json;
using BTN = BUTTON;
namespace Oxide.Plugins {
    [Info("UberTool", "FuJiCuRa", "1.3.4", ResourceId = 78)]
    class UberTool : RustPlugin {
        StrdDt plyrPrfs = new StrdDt();
        class StrdDt {
            public Dictionary<ulong, Plyrnf> PlyData = new Dictionary<ulong, Plyrnf>();
            public StrdDt() {
            }
        }
        class Plyrnf {
            public float SF;
            public Plyrnf() {
            }
        }
        public class EPlanner : MonoBehaviour {
            BasePlayer player;
            InputState stt;
            uint ctvtm;
            Construction.Target target;
            Construction.Target mvTrgt;
            BaseEntity mvTrgtSnp;
            Construction construction;
            Construction mvCnstrctn;
            Construction ryDfntn;
            Vector3 rttnOffst;
            Vector3 mvOffst;
            string lstCrsshr;
            Planner plnnr;
            bool sPlnnr;
            bool sHmmr;
            HeldEntity hldItm;
            bool sRmvr;
            Item ctvtmLnk;
            bool sTpDplybl;
            int dfltGrd;
            uint lstPrfb;
            bool initialized;
            bool ctvTrgt;
            bool sPlcng;
            float tkDist;
            RaycastHit rayHit;
            BaseEntity rayEntity;
            IPlayer rayEntityOwner;
            string rayEntityName;
            Vector3 lastAimAngles;
            Socket_Base lastSocketBase;
            Vector3 lastSocketPos;
            BaseEntity lastSocketEntity;
            Construction.Placement lastPlacement;
            Ray lastRay;
            bool plannerInfoStatus;
            bool removerInfoStatus;
            bool hammerInfoStatus;
            bool lastSocketForce;
            int cuiFontSize = 14;
            string cuiFontColor = "1 1 1 1";
            string fontType = r3("EbobgbPbaqrafrq-Erthyne.ggs");
            float lastPosRotUpdate = 0f;
            void Awake() {
                player = GetComponent<BasePlayer>();
                stt = player.serverInput;
                UnEqp();
                dfltGrd = 4;
                lstPrfb = 72949757u;
                ctvtm = 0;
                construction = new Construction();
                ryDfntn = new Construction();
                construction.canBypassBuildingPermission = true;
                lastAimAngles = player.lastReceivedTick.inputState.aimAngles;
                lastSocketBase = default(Socket_Base);
                lastSocketPos = Vector3.zero;
                lastSocketEntity = default(BaseEntity);
                lastPlacement = default(Construction.Placement);
                rayEntity = default(BaseEntity);
                rttnOffst = Vector3.zero;
                mvOffst = Vector3.zero;
            }
            void Start() {
                if (hideTips) player.SendConsoleCommand(r3("tnzrgvc.uvqrtnzrgvc"));
                initialized = true;
            }
            void UnEqp() {
                foreach (var item in player.inventory.containerBelt.itemList.Where(x => x.IsValid() && x.GetHeldEntity()).ToList()) {
                    var slot = item.position;
                    if ((item.info.shortname == "rock" && item.skin == 0uL) || item.info.shortname == "torch") {
                        item.Remove(0f);
                        continue;
                    }
                    else item.RemoveFromContainer();
                    player.inventory.UpdateContainer(0f, PlayerInventory.Type.Belt, player.inventory.containerBelt, false, 0f);
                    uTs.timer.Once(0.15f, () => {
                        if (item == null) return;
                        item.MoveToContainer(player.inventory.containerBelt, slot, true);
                        item.MarkDirty();
                    }
                    );
                    ItemManager.DoRemoves();
                }
                var woodDef = ItemManager.FindItemDefinition("wood");
                if (woodDef && player.inventory.GetAmount(woodDef.itemid) < 50 ) {
                    var w = ItemManager.CreateByItemID(woodDef.itemid, 50);
                    player.inventory.GiveItem(w);
                }
                if (player.inventory.containerWear.itemList.Count == 0) {
                    var hz = ItemManager.CreateByName("hazmatsuit_scientist", 1);
                    player.inventory.GiveItem(hz, player.inventory.containerWear);
                }
                uTs.timer.Once(0.3f, CrtTls);
            }
            void GetTool(object[] tool) {
                var itemDef = ItemManager.FindItemDefinition((string)tool[1]);
                if (!itemDef) return;
                var p1 = player.inventory.FindItemID(itemDef.itemid);
                ulong skin = Convert.ToUInt64(tool[2]);
                if (p1 != null) {
                    p1.skin = skin;
                    p1.GetHeldEntity().skinID = skin;
                    p1.name = (string)tool[0];
                    if (p1.CanMoveTo(player.inventory.containerBelt, -1, true)) {
                        p1.MoveToContainer(player.inventory.containerBelt, -1, true);
                        p1.MarkDirty();
                    }
                }
                else {
                    var p2 = ItemManager.CreateByItemID(itemDef.itemid, 1, skin);
                    if (p2 != null) {
                        p2.name = (string)tool[0];
                        player.inventory.GiveItem(p2, player.inventory.containerBelt);
                        p2.MarkDirty();
                    }
                }
            }
            void CrtTls() {
                if (crtTlPlnnr) GetTool(uTs.playerTools[0]);
                if (crtTlRmvr) GetTool(uTs.playerTools[1]);
                if (crtTlHmmr) GetTool(uTs.playerTools[2]);
            }
            bool GtCrrntTl() {
                sPlnnr = false;
                sRmvr = false;
                sHmmr = false;
                DestroyInfo();
                if (hldItm is Planner) {
                    plnnr = hldItm as Planner;
                    sPlnnr = true;
                    sTpDplybl = plnnr.isTypeDeployable;
                    DoPlannerInfo();
                    return true;
                }
                if (hldItm is BaseProjectile && ctvtmLnk.skin == Convert.ToUInt64(uTs.playerTools[1][2])) {
                    sRmvr = true;
                    return true;
                }
                if (hldItm is Hammer && ctvtmLnk.skin == Convert.ToUInt64(uTs.playerTools[2][2])) {
                    sHmmr = true;
                    DoHammerInfo();
                    return true;
                }
                return false;
            }
            void ChkRmvr() {
                bool hsLsr = false;
                if (ctvtmLnk.info.shortname != (string)uTs.playerTools[1][1]) {
                    sRmvr = false;
                    hldItm = null;
                    return;
                }
                ctvtmLnk.contents.flags = (ItemContainer.Flag)64;
                ctvtmLnk.contents.MarkDirty();
                if (ctvtmLnk.contents != null && ctvtmLnk.contents.itemList.Count > 0) foreach (var mod in ctvtmLnk.contents.itemList) if (mod.info.shortname == r3("jrncba.zbq.ynfrefvtug")) {
                    hsLsr = true;
                    break;
                }
                if (!hsLsr) {
                    var lMod = ItemManager.CreateByName(r3("jrncba.zbq.ynfrefvtug"), 1);
                    if (lMod != null) if(lMod.MoveToContainer(ctvtmLnk.contents, -1, true)) hsLsr = true;
                    else {
                        sRmvr = false;
                        hldItm = null;
                        return;
                    }
                }
                (hldItm as BaseProjectile).UnloadAmmo(ctvtmLnk, player);
                hldItm.SetLightsOn(true);
                DoRemoverInfo();
            }
            public void StHldItm(uint uid) {
                if (!initialized || uid == ctvtm) return;
                if (uid == 0u) {
                    ctvtm = 0u;
                    sPlnnr = false;
                    sRmvr = false;
                    sHmmr = false;
                    sTpDplybl = false;
                    construction = null;
                    DestroyInfo();
                    return;
                }
                if (uid != ctvtm) {
                    ctvtmLnk = player.inventory.containerBelt.FindItemByUID(uid);
                    if (ctvtmLnk == null) return;
                    ctvtm = uid;
                    hldItm = ctvtmLnk.GetHeldEntity() as HeldEntity;
                    if (hldItm == null) return;
                    if (!GtCrrntTl()) return;
                    if (sRmvr) {
                        CuiHelper.DestroyUi(player, r3("HgPebffUnveHV"));
                        ChkRmvr();
                    }
                    else {
                        construction = PrefabAttribute.server.Find<Construction>(sPlnnr && sTpDplybl && plnnr.GetDeployable() != null ? plnnr.GetDeployable().prefabID : lstPrfb);
                        rttnOffst = Vector3.zero;
                        if (sPlnnr) {
                            if (sTpDplybl) DPlnnrUpdt(PType.Mode, ctvtmLnk.info.displayName.english);
                            else DPlnnrUpdt(PType.Mode, $"{construction.info.name.english} ({((BuildingGrade.Enum)dfltGrd).ToString()})");
                        }
                        else DPlnnrUpdt(PType.Mode);
                    }
                }
            }
            public void TckUpd(PlayerTick tick) {
                if (!initialized) return;
                bool changedInput = tick.inputState.aimAngles != lastAimAngles || tick.inputState.buttons != stt.previous.buttons || lastSocketForce;
                if (lastSocketForce) lastSocketForce = false;
                if (changedInput && !ctvTrgt) {
                    rayHit = default(RaycastHit);
                    lastAimAngles = tick.inputState.aimAngles;
                    int layer = sRmvr && rmvrTlbjcts ? 1143089921 : 2097921;
                    float range = 24f;
                    if (sRmvr) range = rmvrTlDstnc;
                    else if (sHmmr) range = hmmrTlDstnc;
                    lastRay = new Ray(tick.position + new Vector3(0f, 1.5f, 0f), Quaternion.Euler(tick.inputState.aimAngles) * Vector3.forward);
                    if (UnityEngine.Physics.Raycast(lastRay, out rayHit, range, layer, QueryTriggerInteraction.Ignore)) {
                        var ent = rayHit.GetEntity();
                        if (ent != null && ent != rayEntity) {
                            rayEntity = ent;
                            ryDfntn = PrefabAttribute.server.Find<Construction>(rayEntity.prefabID);
                            if (rayEntity.OwnerID > 0uL) rayEntityOwner = uTs.covalence.Players.FindPlayerById(rayEntity.OwnerID.ToString());
                            else rayEntityOwner = null;
                            rayEntityName = "";
                            if (ryDfntn) rayEntityName = ryDfntn.info.name.english;
                            if (rayEntityName.Length == 0) {
                                if (rayEntity is BaseCombatEntity) {
                                    rayEntityName = (rayEntity as BaseCombatEntity).repair.itemTarget?.displayName.english;
                                    if (rayEntityName == null || rayEntityName.Length == 0) rayEntityName = rayEntity.ShortPrefabName;
                                }
                                else rayEntityName = rayEntity.ShortPrefabName;
                            }
                            if (ryDfntn == null && rayEntity.PrefabName.EndsWith("static.prefab")) {
                                ryDfntn = new Construction();
                                ryDfntn.rotationAmount = new Vector3(0, 90f, 0);
                                ryDfntn.fullName = rayEntity.PrefabName;
                                ryDfntn.maxplaceDistance = 8f;
                            }
                        }
                        else if(ent == null) {
                            rayEntity = null;
                            ryDfntn = null;
                            rayEntityOwner = null;
                            rayEntityName = "";
                        }
                    }
                    else {
                        rayEntity = null;
                        ryDfntn = null;
                        rayEntityOwner = null;
                        rayEntityName = "";
                    }
                    if (sPlnnr) {
                        target = default(Construction.Target);
                        target.player = player;
                        target.ray = lastRay;
                        ChkPlcmnt(ref target, construction);
                        if (target.socket != null && (target.socket != lastSocketBase || target.entity != lastSocketEntity || lastSocketForce)) {
                            if (lastSocketForce) lastSocketForce = false;
                            bool chEnt = false;
                            if (adEffctFndtnsPlcmnt && construction.hierachyName.StartsWith("foundation") && lastSocketEntity != target.entity) {
                                chEnt = true;
                                SendEffectTo(3951505782, target.entity, player);
                            }
                            lastSocketEntity = target.entity;
                            string name = target.entity.ShortPrefabName;
                            if (target.entity is BuildingBlock) DPlnnrUpdt(PType.ConnectTo, $"{rayEntityName} [{target.entity.net.ID}] ({(target.entity as BuildingBlock).currentGrade.gradeBase.type.ToString()})");
                            else DPlnnrUpdt(PType.ConnectTo, $"{rayEntityName} [{target.entity.net.ID}]");
                            if (adEffctFndtnsPlcmnt && !chEnt && construction.hierachyName.StartsWith("foundation") && lastSocketBase != target.socket) SendEffectTo(3389733993, target.entity, player);
                            lastSocketBase = target.socket;
                            lastSocketPos = lastSocketEntity.transform.localToWorldMatrix.MultiplyPoint3x4(lastSocketBase.position);
                            var s1 = lastSocketBase.socketName.Replace($"{target.entity.ShortPrefabName}/sockets/", "").TrimEnd('/', '1', '2', '3', '4').Replace("-", " ").Replace("–", " ");
                            DPlnnrUpdt(PType.ToSocket, $"{Oxide.Core.ExtensionMethods.TitleCase(s1)}");
                            lastPlacement = ChckPlcmnt(target, construction);
                            if (lastPlacement != null) DPlnnrUpdt(PType.PosRot, $"{lastPlacement.position.ToString("N1")} | {lastPlacement.rotation.eulerAngles.y.ToString("N1")}°");
                            else DPlnnrUpdt(PType.PosRot);
                        }
                        if (sTpDplybl) {
                            lastPlacement = ChckPlcmnt(target, construction);
                            if (lastPlacement != null) {
                                DPlnnrUpdt(PType.PosRot, $"{lastPlacement.position.ToString("N1")} | {lastPlacement.rotation.eulerAngles.ToString("N1")}");
                                DPlnnrUpdt(PType.ToSocket, "Terrain");
                                if (rayEntity) DPlnnrUpdt(PType.ConnectTo, $"{rayEntityName} [{rayEntity.net.ID}]");
                            }
                            else {
                                DPlnnrUpdt(PType.ToSocket);
                                DPlnnrUpdt(PType.ConnectTo);
                                DPlnnrUpdt(PType.PosRot);
                            }
                        }
                        if (!sTpDplybl && !target.socket) {
                            lastSocketBase = default(Socket_Base);
                            lastSocketEntity = default(BaseEntity);
                            DPlnnrUpdt(PType.ConnectTo);
                            DPlnnrUpdt(PType.PosRot);
                            DPlnnrUpdt(PType.ToSocket);
                        }
                    }
                    if (sHmmr) {
                        if (!ctvTrgt) {
                            if (rayEntity && rayHit.distance <= hmmrTlDstnc) {
                                if (ryDfntn && rayEntity is BuildingBlock) {
                                    DHmmrUpdt(HType.Target, $"{rayEntityName} [{rayEntity.net.ID}] ({(rayEntity as BuildingBlock).currentGrade.gradeBase.type.ToString()})");
                                    DoCrosshair("0 1 0 0.75");
                                }
                                else if (ryDfntn) {
                                    if(ryDfntn.fullName == StringPool.Get(3424003500)) {
                                        DHmmrUpdt(HType.Target, $"{rayEntityName} [{rayEntity.net.ID}] (Type: {(rayEntity as MiningQuarry).staticType})");
                                    }
                                    else DHmmrUpdt(HType.Target, $"{rayEntityName} [{rayEntity.net.ID}]");
                                    DoCrosshair("1 0.921568632 0.0156862754 0.75");
                                }
                                else DHmmrUpdt(HType.Target, $"{rayEntityName} [{rayEntity.net.ID}]");
                                DHmmrUpdt(HType.Mode, "Modify");
                                DHmmrUpdt(HType.Building, rayEntity is DecayEntity ? $"ID {(rayEntity as DecayEntity).buildingID}" : "None");
                                if (ryDfntn) {
                                    float currentTime = UnityEngine.Time.realtimeSinceStartup;
                                    if (currentTime - lastPosRotUpdate >= 0.25f) {
                                        if (rayEntity is BuildingBlock) DHmmrUpdt(HType.PosRot, $"{rayEntity.transform.position.ToString("N1")} | {rayEntity.transform.rotation.eulerAngles.y.ToString("N1")}°");
                                        else DHmmrUpdt(HType.PosRot, $"{rayEntity.transform.position.ToString("N1")} | {rayEntity.transform.rotation.eulerAngles.ToString("N1")}");
                                        lastPosRotUpdate = currentTime;
                                    }
                                    if (rayEntityOwner != null) DHmmrUpdt(HType.Owner, $"{rayEntityOwner.Name}");
                                    else DHmmrUpdt(HType.Owner, $"{rayEntity.OwnerID}");
                                }
                            }
                            else {
                                DHmmrUpdt(HType.Target);
                                DHmmrUpdt(HType.Building);
                                DHmmrUpdt(HType.Mode, r3("Zbqvsl"));
                                DHmmrUpdt(HType.PosRot);
                                DHmmrUpdt(HType.Owner);
                                DoCrosshair("1 1 1 0.75");
                            }
                        }
                        else {
                            DHmmrUpdt(HType.PosRot, $"{mvTrgt.entity.transform.position.ToString("N1")} | {mvTrgt.entity.transform.rotation.eulerAngles.ToString("N1")}");
                            DoCrosshair("");
                        }
                    }
                    if (sRmvr) {
                        DoCrosshair("");
                        if (rayEntity != null && rayHit.distance <= rmvrTlDstnc && (ryDfntn || (!ryDfntn && rmvrTlbjcts))) {
                            DRmvrUpdt(RType.Remove, $"{rayEntityName} [{rayEntity.net.ID}]");
                            if (rayEntityOwner != null) DRmvrUpdt(RType.Owner, $"{rayEntityOwner.Name}");
                            else DRmvrUpdt(RType.Owner, $"{rayEntity.OwnerID}");
                        }
                        else {
                            DRmvrUpdt(RType.Remove);
                            DRmvrUpdt(RType.Owner);
                        }
                        if (stt.IsDown((BTN)2048) && rayEntity is BuildingBlock) DRmvrUpdt(RType.Mode, r3("Ohvyqvat"));
                        else DRmvrUpdt(RType.Mode, r3("Fvatyr"));
                    }
                }
                else if (changedInput && ctvTrgt) {
                    DHmmrUpdt(HType.PosRot, $"{mvTrgt.entity.transform.position.ToString("N1")} | {mvTrgt.entity.transform.rotation.eulerAngles.ToString("N1")}");
                    DoCrosshair("");
                }
                if (sPlnnr && !sTpDplybl) {
                    if (lastSocketBase != null && lastPlacement != null && lastSocketEntity) {
                        OBB oBB = new OBB(lastPlacement.position, Vector3.one, lastPlacement.rotation, construction.bounds);
                        Vector3 obb_pos = construction.hierachyName.StartsWith(r3("sbhaqngvba")) ? oBB.position + (oBB.extents.y * Vector3.up) : oBB.position;
                        Vector3 sock_pos = construction.hierachyName.StartsWith(r3("sbhaqngvba")) ? new Vector3 (lastSocketPos.x, lastSocketEntity.transform.position.y, lastSocketPos.z) : lastSocketPos;
                        player.SendConsoleCommand("ddraw.box", 0.05f, Color.green, obb_pos, 0.15f);
                        player.SendConsoleCommand("ddraw.box", 0.05f, Color.green, sock_pos, 0.25f);
                        player.SendConsoleCommand("ddraw.line", 0.05f, Color.green, obb_pos, sock_pos);
                    }
                }
            }
            void Update() {
                if (!ctvTrgt) return;
                if (!sPlcng && sHmmr) {
                    bool flag = mvTrgt.entity is SimpleBuildingBlock || mvCnstrctn.allSockets == null;
                    mvTrgt.ray = player.eyes.BodyRay();
                    FndTrrnPlcmnt(ref mvTrgt, mvCnstrctn, tkDist, flag);
                    Vector3 position = mvTrgt.entity.transform.position;
                    Quaternion rotation = mvTrgt.entity.transform.rotation;
                    Vector3 toPos = mvTrgt.position;
                    Quaternion toRot = Quaternion.LookRotation(mvTrgt.entity.transform.up) * Quaternion.Euler(mvOffst);
                    if (flag) {
                        Vector3 direction = mvTrgt.ray.direction;
                        direction.y = 0f;
                        direction.Normalize();
                        toRot = Quaternion.Euler(mvOffst) * Quaternion.LookRotation(direction, Vector3.up);
                    }
                    var check = ChckPlcmnt(mvTrgt, mvCnstrctn);
                    if (check != null) {
                        toPos = check.position;
                        toRot = check.rotation * Quaternion.Euler(mvOffst);
                    }
                    mvTrgt.entity.transform.position = Vector3.Lerp(position, toPos, UnityEngine.Time.deltaTime * 5f);
                    mvTrgt.entity.transform.rotation = Quaternion.Lerp(rotation, toRot, UnityEngine.Time.deltaTime * 10f);
                    DMvmntSnc(mvTrgt.entity);
                    return;
                }
                else if (sPlcng) {
                    if (Vector3.Distance(mvTrgt.entity.transform.position, mvTrgt.position) <= 0.025f) {
                        if (mvTrgtSnp && !(mvTrgtSnp is BuildingBlock)) {
                            mvTrgt.entity.transform.position = mvTrgtSnp.transform.InverseTransformPoint(mvTrgt.position);
                            mvTrgt.entity.transform.rotation = Quaternion.Inverse(mvTrgtSnp.transform.rotation) * Quaternion.Euler(mvTrgt.rotation);
                            mvTrgt.entity.SetParent(mvTrgtSnp, 0u);
                        }
                        if (mvTrgtSnp) {
                            DecayUpdate(mvTrgt.entity, true, mvCnstrctn.isBuildingPrivilege, mvTrgtSnp);
                            mvTrgtSnp = null;
                        }
                        DMvmntSnc(mvTrgt.entity, true);
                        DoCrosshair("1 1 1 0.75");
                        mvTrgt = default(Construction.Target);
                        sPlcng = false;
                        ctvTrgt = false;
                        return;
                    }
                    mvTrgt.entity.transform.position = Vector3.Lerp(mvTrgt.entity.transform.position, mvTrgt.position, UnityEngine.Time.deltaTime * 10f);
                    if (mvTrgtSnp == null || (mvTrgtSnp && !(mvTrgtSnp is BuildingBlock))) mvTrgt.entity.transform.rotation = Quaternion.Lerp(mvTrgt.entity.transform.rotation, Quaternion.Euler(mvTrgt.rotation), UnityEngine.Time.deltaTime * 10f);
                    DMvmntSnc(mvTrgt.entity);
                    return;
                }
                else if (!sPlcng && !sHmmr) {
                    if (mvTrgt.valid) PlcOnTrgt();
                    else TrPlcTrgt();
                }
            }
            void DecayUpdate(BaseEntity entity, bool isAdding, bool isBuildingPrivilege, BaseEntity target = null) {
                DecayEntity dcEnt = entity as DecayEntity;
                if (dcEnt == null) return;
                BuildingManager.Building building = null;
                if (isAdding) {
                    DecayEntity dcTgt = target != null ? target as DecayEntity : null;
                    if (dcTgt != null) building = BuildingManager.server.GetBuilding(dcTgt.buildingID);
                    if (building != null) {
                        building.AddDecayEntity(dcEnt);
                        if (isBuildingPrivilege) building.AddBuildingPrivilege(dcEnt as BuildingPrivlidge);
                        building.Dirty();
                        dcEnt.buildingID = building.ID;
                    }
                }
                else {
                    building = BuildingManager.server.GetBuilding(dcEnt.buildingID);
                    if (building != null) {
                        if (building.decayEntities != null) building.RemoveDecayEntity(dcEnt);
                        if (isBuildingPrivilege && building.buildingPrivileges != null) building.RemoveBuildingPrivilege(dcEnt as BuildingPrivlidge);
                        building.Dirty();
                    }
                    dcEnt.buildingID = 0u;
                }
                dcEnt.SendNetworkUpdate(BasePlayer.NetworkQueue.Update);
                if (entity.children != null) foreach (BaseEntity current in entity.children) DecayUpdate(current, isAdding, isBuildingPrivilege, isAdding ? entity : null);
            }
            void PlcOnTrgt() {
                if (mvTrgtSnp && !(mvTrgtSnp is BuildingBlock)) {
                    mvTrgt.entity.transform.position = mvTrgtSnp.transform.worldToLocalMatrix.MultiplyPoint3x4(mvTrgt.position);
                    mvTrgt.entity.transform.rotation = Quaternion.Inverse(mvTrgtSnp.transform.rotation) * mvTrgt.entity.transform.rotation;
                    mvTrgt.entity.SetParent(mvTrgtSnp, 0u);
                }
                if (mvTrgtSnp) {
                    DecayUpdate(mvTrgt.entity, true, mvCnstrctn.isBuildingPrivilege, mvTrgtSnp);
                    mvTrgtSnp = null;
                }
                DMvmntSnc(mvTrgt.entity, true);
                mvTrgt = default(Construction.Target);
                ctvTrgt = false;
                sPlcng = false;
            }
            void TrPlcTrgt() {
                RaycastHit hit;
                mvTrgtSnp = null;
                int layer = mvCnstrctn.isBuildingPrivilege ? 2097152 : 27328769;
                if (Physics.Raycast(mvTrgt.entity.transform.position, mvTrgt.entity.transform.up * -1.0f, out hit, float.PositiveInfinity, layer)) {
                    mvTrgt.position = hit.point;
                    if (hit.collider is UnityEngine.TerrainCollider) {
                        mvTrgt.rotation = Quaternion.LookRotation(Vector3.Cross(mvTrgt.entity.transform.right, hit.normal)).eulerAngles;
                        DHmmrUpdt(HType.Building, "None");
                    }
                    else {
                        mvTrgtSnp = hit.GetEntity();
                        if (mvTrgtSnp) {
                            mvTrgt.rotation = mvTrgt.entity.transform.rotation.eulerAngles;
                            DHmmrUpdt(HType.Building, rayEntity is DecayEntity ? $"ID {(rayEntity as DecayEntity).buildingID}" : "None");
                        }
                        else DHmmrUpdt(HType.Building, "None");
                    }
                    sPlcng = true;
                    return;
                }
                else {
                    mvTrgt = default(Construction.Target);
                    ctvTrgt = false;
                    sPlcng = false;
                    return;
                }
            }
            void DMvmntSnc(BaseEntity entity, bool force = false) {
                if (BaseEntity.Query.Server != null) BaseEntity.Query.Server.Move(entity);
                if (force || entity.PrefabName == StringPool.Get(2206646561) || entity.PrefabName == StringPool.Get(2335812770)) {
                    if (Net.sv.write.Start()) {
                        Net.sv.write.PacketID(Message.Type.EntityDestroy);
                        Net.sv.write.UInt32(entity.net.ID);
                        Net.sv.write.UInt8(0);
                        Net.sv.write.Send(new SendInfo(entity.net.group.subscribers));
                    }
                    entity.SendNetworkUpdateImmediate(false);
                }
                else {
                    if (Net.sv.write.Start()) {
                        Net.sv.write.PacketID(Message.Type.GroupChange);
                        Net.sv.write.EntityID(entity.net.ID);
                        Net.sv.write.GroupID(entity.net.group.ID);
                        Net.sv.write.Send(new SendInfo(entity.net.group.subscribers));
                    }
                    if (Net.sv.write.Start()) {
                        Net.sv.write.PacketID(Message.Type.EntityPosition);
                        Net.sv.write.EntityID(entity.net.ID);
                        Net.sv.write.Vector3(entity.GetNetworkPosition());
                        Net.sv.write.Vector3(entity.GetNetworkRotation().eulerAngles);
                        Net.sv.write.Float(entity.GetNetworkTime());
                        Write write = Net.sv.write;
                        SendInfo info = new SendInfo(entity.net.group.subscribers);
                        info.method = SendMethod.ReliableUnordered;
                        info.priority = Priority.Immediate;
                        write.Send(info);
                    }
                }
                if (entity.children != null) foreach (BaseEntity current in entity.children) DMvmntSnc(current, force || entity.PrefabName == StringPool.Get(2206646561) || entity.PrefabName == StringPool.Get(2335812770));
            }
            public void DoTi() {
                if (!initialized || !hldItm) return;
                if (sPlnnr) {
                    if (true) {
                        if (stt.WasJustPressed((BTN)1024)) {
                            DoPl();
                            return;
                        }
                        else if (stt.WasJustPressed((BTN)8192)) {
                            Vector3 vector = Vector3.zero;
                            if (construction && construction.canRotate) vector = construction.rotationAmount;
                            rttnOffst.x = Mathf.Repeat(rttnOffst.x + vector.x, 360f);
                            rttnOffst.y = Mathf.Repeat(rttnOffst.y + vector.y, 360f);
                            rttnOffst.z = Mathf.Repeat(rttnOffst.z + vector.z, 360f);
                            return;
                        }
                    }
                    if (!sTpDplybl) {
                        if (stt.WasJustPressed((BTN)2048)) {
                            BldMnUI(uTs.plyrPrfs.PlyData[player.userID].SF);
                            return;
                        }
                        else if ((stt.IsDown((BTN)64) || stt.IsDown((BTN)134217728))) {
                            if (stt.WasJustPressed((BTN)8)) {
                                dfltGrd++;
                                if (dfltGrd > 4) dfltGrd = 0;
                                DPlnnrUpdt(PType.Mode, $"{construction.info.name.english} ({((BuildingGrade.Enum)dfltGrd).ToString()})");
                                return;
                            }
                            else if (stt.WasJustPressed((BTN)16)) {
                                dfltGrd--;
                                if (dfltGrd < 0) dfltGrd = 4;
                                DPlnnrUpdt(PType.Mode, $"{construction.info.name.english} ({((BuildingGrade.Enum)dfltGrd).ToString()})");
                                return;
                            }
                        }
                    }
                    else if (sTpDplybl) {
                    }
                }
                else if (sHmmr) {
                    if (ctvTrgt) {
                        if (sPlcng) {
                        }
                        else if (!sPlcng) {
                            if (stt.WasJustPressed((BTN)2048) || stt.WasJustPressed((BTN)1024)) {
                                if (mvTrgt.valid) PlcOnTrgt();
                                else TrPlcTrgt();
                                return;
                            }
                            else if (stt.WasJustPressed((BTN)8192)) {
                                Vector3 vector = Vector3.zero;
                                if (mvCnstrctn && mvCnstrctn.canRotate) vector = mvCnstrctn.rotationAmount;
                                mvOffst.x = Mathf.Repeat(mvOffst.x + vector.x, 360f);
                                mvOffst.y = Mathf.Repeat(mvOffst.y + vector.y, 360f);
                                mvOffst.z = Mathf.Repeat(mvOffst.z + vector.z, 360f);
                                return;
                            }
                        }
                    }
                    else if (!ctvTrgt) {
                        if (stt.WasJustPressed((BTN)134217728)) {
                            if (rayEntity && rayEntity.IsValid()) {
                                if (rayEntity is BuildingBlock) {
                                    BuildingBlock block = rayEntity as BuildingBlock;
                                    var grade = (int)block.currentGrade.gradeBase.type;
                                    grade++;
                                    if (grade >= block.blockDefinition.grades.Length) grade = 1;
                                    block.SetGrade((BuildingGrade.Enum)grade);
                                    block.SetHealthToMax();
                                    block.SendNetworkUpdate();
                                    Effect.server.Run("assets/bundled/prefabs/fx/build/promote_" + ((BuildingGrade.Enum)grade).ToString().ToLower() + ".prefab", rayEntity, 0u, Vector3.zero, Vector3.zero, null, false);
                                    return;
                                }
                                else {
                                    var r = rayEntity;
                                    if (r is StorageContainer) {
                                        bool isOn = r.HasFlag(BaseEntity.Flags.On);
                                        if (r is SearchLight && !isOn) (r as SearchLight).secondsRemaining = float.PositiveInfinity;
                                        r.SetFlag(BaseEntity.Flags.On, !isOn, false);
                                        r.SendNetworkUpdate();
                                        return;
                                    }
                                    else if (r is MiningQuarry) {
                                        var q = r as MiningQuarry;
                                        q.staticType = (MiningQuarry.QuarryType)(int)q.staticType+1;
                                        if ((int)q.staticType > 3) q.staticType = (MiningQuarry.QuarryType)0;
                                        q.UpdateStaticDeposit();
                                    }
                                    else if(r is EngineSwitch) {
                                        var miningQuarry = r.GetParentEntity() as MiningQuarry;
                                        if (miningQuarry) miningQuarry.EngineSwitch(true);
                                    }
                                }
                            }
                        }
                        else if (stt.WasJustPressed((BTN)8192)) {
                            if (!rayEntity || !rayEntity.IsValid() || ryDfntn == null || ryDfntn.rotationAmount.y == 0f) return;
                            string effectPath = ryDfntn.deployable != null && ryDfntn.deployable.placeEffect.isValid ? ryDfntn.deployable.placeEffect.resourcePath : StringPool.Get(2598153373);
                            rayEntity.transform.Rotate(ryDfntn.rotationAmount);
                            if (rayEntity is StabilityEntity) {
                                rayEntity.RefreshEntityLinks();
                                if (!vrrdStbltWhlBld && !(rayEntity as StabilityEntity).grounded) (rayEntity as StabilityEntity).UpdateSurroundingEntities();
                                if (rayEntity is BuildingBlock) {
                                    var conskin = rayEntity.gameObject.GetComponentInChildren<ConstructionSkin>();
                                    if (conskin) conskin.Refresh(rayEntity as BuildingBlock);
                                    rayEntity.ClientRPC(null, r3("ErserfuFxva"));
                                }
                            }
                            DMvmntSnc(rayEntity, true);
                            Effect.server.Run(effectPath, rayEntity, 0u, Vector3.zero, Vector3.zero, null, false);
                            return;
                        }
                        else if (stt.WasJustPressed((BTN)2048)) {
                            if (mvTrgt.entity != null) {
                                mvTrgt = default(Construction.Target);
                                ctvTrgt = false;
                                sPlcng = false;
                                return;
                            }
                            if (!rayEntity || rayEntity is BuildingBlock || rayEntity.FindLinkedEntity<BuildingBlock>() || rayEntity is AnimatedBuildingBlock) return;
                            mvCnstrctn = PrefabAttribute.server.Find<Construction>(rayEntity.prefabID);
                            if (mvCnstrctn == null) {
                                if (!rayEntity.PrefabName.EndsWith("static.prefab")) return;
                                mvCnstrctn = new Construction();
                                mvCnstrctn.rotationAmount = new Vector3(0, 90f, 0);
                                mvCnstrctn.fullName = rayEntity.PrefabName;
                                mvCnstrctn.maxplaceDistance = rayEntity is MiningQuarry ? 8f : 4f;
                                mvCnstrctn.canRotate = true;
                            }
                            if (rayEntity is DecayEntity) {
                                DecayUpdate(rayEntity, false, mvCnstrctn.isBuildingPrivilege);
                                DHmmrUpdt(HType.Building, "None");
                            }
                            mvTrgt = default(Construction.Target);
                            mvOffst = Vector3.zero;
                            if (rayEntity.HasParent()) {
                                var position = rayEntity.transform.position;
                                var rotation = rayEntity.transform.rotation;
                                rayEntity.SetParent(null, 0u);
                                rayEntity.transform.position = position;
                                rayEntity.transform.rotation = rotation;
                                DMvmntSnc(rayEntity, true);
                            }
                            if (rayEntity.children.Count == 0 || !rayEntity.HasParent()) DMvmntSnc(rayEntity, true);
                            tkDist = Mathf.Clamp(Vector3.Distance(rayEntity.transform.position, lastRay.origin), mvCnstrctn.maxplaceDistance, mvCnstrctn.maxplaceDistance * 3f);
                            mvTrgt.entity = rayEntity;
                            sPlcng = false;
                            ctvTrgt = true;
                            DHmmrUpdt(HType.Mode, r3("Ercbfvgvbavat"));
                            return;
                        }
                    }
                }
                else if (sRmvr) {
                    if (stt.WasJustPressed((BTN)1024)) {
                        if (!stt.IsDown((BTN)2048)) DoRm();
                        else if (stt.IsDown((BTN)2048)) DoRm(true);
                    }
                    rayEntity = null;
                    ryDfntn = null;
                }
            }
            void FndTrrnPlcmnt(ref Construction.Target t, Construction c, float maxDistance, bool isQuarry = false ) {
                int layer = 27328769;
                if (isQuarry) layer = 10551297;
                RaycastHit[] hits = Physics.RaycastAll(t.ray, maxDistance, layer);
                if (hits.Length > 1) {
                    GamePhysics.Sort(hits);
                    for (int i = 0; i < hits.Length; i++) {
                        if (hits[i].collider.transform.root != t.entity.transform.root) {
                            t.position = t.ray.origin + t.ray.direction * hits[i].distance;
                            t.normal = hits[i].normal;
                            t.rotation = Vector3.zero;
                            t.onTerrain = true;
                            t.valid = true;
                            if (!isQuarry) mvTrgtSnp = hits[i].GetEntity();
                            return;
                        }
                    }
                }
                t.position = t.ray.origin + t.ray.direction * maxDistance;
                t.normal = Vector3.up;
                t.rotation = Vector3.zero;
                t.onTerrain = true;
                t.valid = false;
                mvTrgtSnp = null;
            }
            public void StBlckPrfb(uint p) {
                construction = PrefabAttribute.server.Find<Construction>(p);
                rttnOffst = Vector3.zero;
                lstPrfb = p;
                DPlnnrUpdt(PType.Mode, $"{construction.info.name.english} ({((BuildingGrade.Enum)dfltGrd).ToString()})");
                lastPlacement = null;
                lastSocketForce = true;
            }
            public void OnDestroy() {
                foreach (var item in player.inventory.AllItems().Where(x => x.IsValid()).ToList()) {
                    if (item.skin == Convert.ToUInt64(uTs.playerTools[0][2]) || item.skin == Convert.ToUInt64(uTs.playerTools[1][2]) || item.skin == Convert.ToUInt64(uTs.playerTools[2][2])) {
                        item.skin = 0uL;
                        item.GetHeldEntity().skinID = 0uL;
                        item.name = string.Empty;
                        item.MarkDirty();
                    }
                }
                DestroyInfo();
                GameObject.Destroy(this);
            }
            void DoRm(bool remAl = false) {
                if (!rayEntity || (rayEntity is BasePlayer && !(rayEntity is NPCPlayer)) || (!rmvrTlbjcts && !ryDfntn)) return;
                if (rayEntity.IsValid()) {
                    if (rayEntity is BuildingBlock) {
                        if (remAl) {
                            CollRm(rayEntity);
                            return;
                        }
                        else {
                            Effect.server.Run(ffctRmvngBlcks, rayEntity, 0u, Vector3.zero, Vector3.zero, null, false);
                            rayEntity.Kill(BaseNetworkable.DestroyMode.None);
                            rayEntity = null;
                            ryDfntn = null;
                            return;
                        }
                    }
                    else {
                        if (rayEntity is OreResourceEntity) (rayEntity as OreResourceEntity).CleanupBonus();
                        if (rayEntity is BaseNpc || rayEntity is NPCPlayer) (rayEntity as BaseCombatEntity).DieInstantly();
                        else {
                            if (!uTs.entRemoval.Contains(rayEntity.transform.root)) uTs.entRemoval.Add(rayEntity.transform.root);
                            rayEntity.Kill(BaseNetworkable.DestroyMode.Gib);
                        }
                        rayEntity = null;
                        ryDfntn = null;
                    }
                }
                else {
                    GameManager.Destroy(rayEntity.gameObject, 0f);
                    rayEntity = null;
                    ryDfntn = null;
                }
            }
            void CollRm(BaseEntity srcntt) {
                var bldngBlck = srcntt.GetComponent<BuildingBlock>();
                if (bldngBlck == null) return;
                var bldngd = bldngBlck.buildingID;
                var rmvLst = UnityEngine.Object.FindObjectsOfType<BuildingBlock>().Where(x => x.buildingID == bldngd).ToList();
                ServerMgr.Instance.StartCoroutine(DlyRm(rmvLst));
            }
            IEnumerator DlyRm(List<BuildingBlock> bEs) {
                WaitForEndOfFrame wait = new WaitForEndOfFrame();
                for (int i = 0; i < bEs.Count; i++) {
                    if (!bEs[i].IsDestroyed) {
                        if (bEs[i] == rayEntity) {
                            rayEntity = null;
                            ryDfntn = null;
                        }
                        bEs[i].Kill(BaseNetworkable.DestroyMode.None);
                        yield return wait;
                    }
                }
            }
            void DoPl() {
                ChkQrr(construction);
                Deployable dplybl = plnnr.GetDeployable();
                GameObject gameObject = DoPlaG(target, construction);
                if (gameObject != null) {
                    Interface.CallHook(r3("BaRagvglOhvyg"), new object[] {
                        plnnr, gameObject
                    }
                    );
                    if (dplybl != null) {
                        if (dplybl.placeEffect.isValid) {
                            if (target.entity && target.socket) Effect.server.Run(dplybl.placeEffect.resourcePath, target.entity.transform.TransformPoint(target.socket.worldPosition), target.entity.transform.up, null, false);
                            else Effect.server.Run(dplybl.placeEffect.resourcePath, target.position, target.normal, null, false);
                        }
                        BaseEntity bsntt = gameObject.ToBaseEntity();
                        if (!(bsntt is MiningQuarry) &&
// ... [Code preview truncated due to length. Full source in attached file] ...

Автор
15FPS
Скачиваний
0
Просмотры
1
Первый выпуск
Обновление
Оценка
0.00 звёзд 0 оценок
Сверху