Ejemplo n.º 1
0
        private void OnTransformStructureRequested(CSteamID instigator, byte x, byte y, uint instanceId, // lgtm [cs/too-many-ref-parameters]
                                                   ref Vector3 point, ref byte angleX, ref byte angleY, ref byte angleZ, ref bool shouldAllow)
        {
            if (!StructureManager.tryGetRegion(x, y, out var region))
            {
                return;
            }

            var index = region.structures.FindIndex(k => k.instanceID == instanceId);
            var data  = region.structures[index];
            var drop  = region.drops[index];

            var nativePlayer = PlayerTool.getPlayer(instigator);
            var player       = GetUnturnedPlayer(nativePlayer);

            var rot = Quaternion.Euler(angleX * 2, angleY * 2, angleZ * 2); // lgtm [cs/loss-of-precision]

            var @event = new UnturnedStructureTransformingEvent(
                new UnturnedStructureBuildable(data, drop), player !, instigator, point, rot)
            {
                IsCancelled = !shouldAllow
            };

            Emit(@event);

            shouldAllow = [email protected];
            point       = @event.Point;

            var eulerAngles = @event.Rotation.eulerAngles;

            angleX = MeasurementTool.angleToByte(Mathf.RoundToInt(eulerAngles.x / 2f) * 2); // lgtm [cs/loss-of-precision]
            angleY = MeasurementTool.angleToByte(Mathf.RoundToInt(eulerAngles.y / 2f) * 2); // lgtm [cs/loss-of-precision]
            angleZ = MeasurementTool.angleToByte(Mathf.RoundToInt(eulerAngles.z / 2f) * 2); // lgtm [cs/loss-of-precision]
        }
Ejemplo n.º 2
0
        private void OnDamageStructureRequested(CSteamID instigatorSteamId, Transform structureTransform, ref ushort pendingTotalDamage, ref bool shouldAllow, EDamageOrigin damageOrigin)
        {
            if (!StructureManager.tryGetInfo(structureTransform, out _, out _, out var index,
                                             out var region, out var drop))
            {
                return;
            }
            {
                var data      = region.structures[index];
                var buildable = new UnturnedStructureBuildable(data, drop);

                var nativePlayer = PlayerTool.getPlayer(instigatorSteamId);
                var player       = GetUnturnedPlayer(nativePlayer);

                var @event = pendingTotalDamage >= buildable.State.Health
                    ? (UnturnedBuildableDamagingEvent) new UnturnedStructureDestroyingEvent(buildable,
                                                                                            pendingTotalDamage, damageOrigin, player !, instigatorSteamId)
                    : new UnturnedStructureDamagingEvent(buildable, pendingTotalDamage, damageOrigin, player !,
                                                         instigatorSteamId);

                @event.IsCancelled = !shouldAllow;

                Emit(@event);

                pendingTotalDamage = @event.DamageAmount;
                shouldAllow        = [email protected];
            }
        }
Ejemplo n.º 3
0
            static void Postfix(Transform resource, Vector3 direction, float damage, float times, float drop, ref EPlayerKill kill, ref uint xp, CSteamID instigatorSteamID, EDamageOrigin damageOrigin, bool trackKill)
            {
                if (kill == EPlayerKill.RESOURCE)
                {
                    Player ply = PlayerTool.getPlayer(instigatorSteamID);


                    List <RegionCoordinate> region = new List <RegionCoordinate>();
                    region.Add(new RegionCoordinate(ply.movement.region_x, ply.movement.region_y));

                    List <ItemData> searchResult = new List <ItemData>();

                    getItemsInRadius(ply.transform.position, 500f, region, searchResult);

                    foreach (ItemData item in searchResult)
                    {
                        ItemAsset itemAsset = (ItemAsset)Assets.find(EAssetType.ITEM, item.item.id);

                        byte page;
                        byte x;
                        byte y;
                        byte rot;

                        if (ply.inventory.tryFindSpace(itemAsset.size_x, itemAsset.size_y, out page, out x, out y, out rot))
                        {
                            if (!autoPickupItems.Contains(item.item.id))
                            {
                                return;
                            }

                            ItemManager.instance.askTakeItem(ply.channel.owner.playerID.steamID, ply.movement.region_x, ply.movement.region_y, item.instanceID, x, y, rot, page);
                        }
                    }
                }
            }
        protected override async Task OnExecuteAsync()
        {
            UnturnedUser        user    = (UnturnedUser)Context.Actor;
            InteractableVehicle?vehicle = RaycastHelper.Raycast(user.Player.Player, 6f);

            if (vehicle != null)
            {
                string ownerId = await m_KeysManager.CheckVehicleOwner(vehicle.instanceID);

                if (ownerId != "")
                {
                    await m_KeysManager.TryRemoveKeyFromBunch(ownerId, vehicle.instanceID);

                    await user.PrintMessageAsync(m_StringLocalizer["translations:vehicle_removedkey", new { vehicleID = vehicle.instanceID }]);

                    var player = PlayerTool.getPlayer(new Steamworks.CSteamID(ulong.Parse(ownerId)));
                    if (player != null)
                    {
                        ChatManager.say(player.channel.owner.playerID.steamID, m_StringLocalizer["translations:vehicle_lockpicked", new { vehicle = vehicle.asset.name, vehicleID = vehicle.instanceID }], UnityEngine.Color.red, EChatMode.SAY, true);
                    }
                }
            }
            else
            {
                await user.PrintMessageAsync(m_StringLocalizer["translations:vehicle_notfound"], System.Drawing.Color.Red, false, "");
            }
        }
Ejemplo n.º 5
0
        private void OnPlayerDisconnected(SteamPlayer player)
        {
            if (EscortingPlayers.ContainsKey(player.playerID.steamID))
            {
                CSteamID escorteeID;
                EscortingPlayers.TryGetValue(player.playerID.steamID, out escorteeID);
                if (!EscortingPlayers.TryGetValue(player.playerID.steamID, out escorteeID))
                {
                    return;
                }

                EscortingPlayers.Remove(player.playerID.steamID);
                EscortedPlayers.Remove(escorteeID);
                Player ply = PlayerTool.getPlayer(escorteeID);
            }
            else if (EscortedPlayers.ContainsKey(player.playerID.steamID))
            {
                CSteamID escorterID;
                if (!EscortedPlayers.TryGetValue(player.playerID.steamID, out escorterID))
                {
                    return;
                }

                EscortedPlayers.Remove(player.playerID.steamID);
                EscortingPlayers.Remove(escorterID);
            }
        }
Ejemplo n.º 6
0
            public static bool PreVehicleLock(CSteamID steamID)
            {
                var cancel = false;

                var player = PlayerTool.getPlayer(steamID);

                if (player == null)
                {
                    return(false);
                }

                var vehicle = player.movement.getVehicle();

                if (vehicle == null || vehicle.asset == null)
                {
                    return(false);
                }

                if (!vehicle.checkDriver(steamID))
                {
                    return(false);
                }

                var toLock = !vehicle.isLocked;

                if (toLock && !vehicle.asset.canBeLocked)
                {
                    return(false);
                }

                OnVehicleLockUpdating?.Invoke(vehicle, player, player.quests.groupID, toLock, ref cancel);

                return(!cancel);
            }
Ejemplo n.º 7
0
 public void OnTireDamage(CSteamID instigatorSteamID, InteractableVehicle vehicle, int tireIndex, ref bool shouldAllow, EDamageOrigin damageOrigin)
 {
     if (vehicle.isLocked && PlayerTool.getPlayer(vehicle.lockedOwner) == null)
     {
         shouldAllow = false;
     }
 }
Ejemplo n.º 8
0
        protected override async void execute(CSteamID executor, string parameter)
        {
            Player ply = PlayerTool.getPlayer(executor);

            if (Main.Config.safeZoneOnly && !ply.movement.isSafe)
            {
                UnityThread.executeInUpdate(() =>
                {
                    ChatManager.say(executor, $"Stash can only be accessed inside a safezone", Color.cyan);
                });
                return;
            }

            Items stash = new Items(7);

            stash.resize((byte)Main.Config.width, (byte)Main.Config.height);

            //List<ItemJar> items = AsyncContext.Run(async () => await Task.Run(() => StashDB.GetItemsAsync(executor.ToString())));
            List <ItemJar> items = await Task.Run(() => StashDB.GetItemsAsync(executor.ToString()));

            foreach (ItemJar item in items)
            {
                ItemAsset itemAsset = (ItemAsset)Assets.find(EAssetType.ITEM, item.item.id);

                try
                {
                    stash.addItem(item.x, item.y, item.rot, new Item(item.item.id, item.item.amount, item.item.quality, item.item.metadata));
                }
                catch (Exception ex)
                {
                    UnityThread.executeInUpdate(() =>
                    {
                        ChatManager.say(executor, $"Failed to get {itemAsset.itemName}, not enough free space", Color.cyan);
                    });
                }
            }

            stash.onItemAdded = async(byte page, byte index, ItemJar item) => {
                await Task.Run(() => StashDB.AddItemAsync(executor.ToString(), item));

                //AsyncContext.Run(async () => await Task.Run(() => StashDB.AddItemAsync(executor.ToString(), item)));
            };

            stash.onItemRemoved = async(byte page, byte index, ItemJar item) =>
            {
                await Task.Run(() => StashDB.DeleteItemAsync(executor.ToString(), item));

                //AsyncContext.Run(async () => await Task.Run(() => StashDB.DeleteItemAsync(executor.ToString(), item)));
            };

            stash.onItemUpdated = async(byte page, byte index, ItemJar item) =>
            {
                await Task.Run(() => StashDB.DeleteItemAsync(executor.ToString(), item));

                //AsyncContext.Run(async () => await Task.Run(() => StashDB.UpdateItemAsync(executor.ToString(), item)));
            };

            ply.inventory.updateItems(7, stash);
            ply.inventory.sendStorage();
        }
Ejemplo n.º 9
0
            public static bool PreVehicleLock(VehicleManager __instance, CSteamID steamID)
            {
                var cancel = false;

                var player = PlayerTool.getPlayer(steamID);

                if (player == null)
                {
                    return(false);
                }

                var vehicle = player.movement.getVehicle();

                if (vehicle == null || vehicle.asset == null)
                {
                    return(false);
                }

                if (!vehicle.checkDriver(steamID))
                {
                    return(false);
                }

                var isLocked = vehicle.isLocked;
                var flag     = vehicle.asset.canBeLocked && !isLocked;

                if (isLocked == flag)
                {
                    return(false);
                }

                OnVehicleLockUpdating?.Invoke(vehicle, player, player.quests.groupID, flag, ref cancel);

                return(!cancel);
            }
Ejemplo n.º 10
0
        private void OnDamagePlayerRequested(ref DamagePlayerParameters parameters, ref bool shouldAllow)
        {
            Player killerPlayer = PlayerTool.getPlayer(parameters.killer);

            if (killerPlayer is null)
            {
                return;
            }
            if (killerPlayer.equipment.asset is null)
            {
                return;
            }
            if (killerPlayer.equipment.asset.id != 1447)
            {
                return;
            }

            CSteamID playerId = parameters.player.channel.owner.playerID.steamID;

            parameters.damage = 0;

            if (!TrackedPlayers.ContainsKey(playerId))
            {
                AddTrackedPlayer(playerId);
            }
            else
            {
                TrackedPlayers[playerId] = 30000;
            }
        }
Ejemplo n.º 11
0
            protected override void execute(CSteamID executorID, string parameter)
            {
                SteamPlayer player = PlayerTool.getSteamPlayer(executorID);

                List <InteractableVehicle> nearbyVehicles = new List <InteractableVehicle>();

                VehicleManager.getVehiclesInRadius(player.player.movement.transform.position, 15f, nearbyVehicles);

                foreach (InteractableVehicle v in nearbyVehicles)
                {
                    byte     seat;
                    CSteamID escorteeID;

                    if (EscortingPlayers.TryGetValue(executorID, out escorteeID))
                    {
                        Player ply = PlayerTool.getPlayer(escorteeID);


                        if (v.tryAddPlayer(out seat, ply) && !v.isLocked)
                        {
                            EscortedPlayers.Remove(escorteeID);
                            EscortingPlayers.Remove(executorID);
                            VehicleManager.instance.channel.send("tellEnterVehicle", ESteamCall.ALL, ESteamPacket.UPDATE_RELIABLE_BUFFER, new object[] {
                                v.instanceID,
                                seat,
                                escorteeID
                            });
                        }
                    }
                }
            }
        protected override async Task OnExecuteAsync()
        {
            UnturnedUser user = (UnturnedUser)Context.Actor;
            uint         id   = await Context.Parameters.GetAsync <uint>(1);

            string vic = await Context.Parameters.GetAsync <string>(0);

            Player player = PlayerTool.getPlayer(vic);

            if (player == null)
            {
                await user.PrintMessageAsync(m_StringLocalizer["translations:player_notfound"], System.Drawing.Color.Red, false, "");
            }
#pragma warning disable CS8602
            UnturnedUser?victim = (UnturnedUser?)await m_UserManager.FindUserAsync(KnownActorTypes.Player, player.channel.owner.playerID.steamID.ToString(), UserSearchMode.FindById);

#pragma warning restore CS8602
            if (victim == null)
            {
                await user.PrintMessageAsync(m_StringLocalizer["translations:player_notfound"], System.Drawing.Color.Red, false, "");
            }
            else if (victim == user)
            {
                await user.PrintMessageAsync(m_StringLocalizer["translations:yourself_error"], System.Drawing.Color.Red, false, "");
            }
            else if (victim != null && user != null)
            {
                PlayerBunch?userBunch = await m_KeysManager.TryGetPlayerBunch(user.Id);

                PlayerBunch?victimBunch = await m_KeysManager.TryGetPlayerBunch(victim.Id);

                if (userBunch != null && victimBunch != null)
                {
                    if (!userBunch.VehiclesKey.Any(v => v.InstanceId == id))
                    {
                        if (victimBunch.VehiclesKey.Count >= (victimBunch.MaxKeys - 1))
                        {
                            await user.PrintMessageAsync(m_StringLocalizer["translations:victim_maxkeys"]);
                        }
                        else
                        {
                            var vehicleKey = await m_KeysManager.TransferVehicle(user.Id, victim.Id, id);

                            await user.PrintMessageAsync(m_StringLocalizer["translations:user_vehicle_transfer", new { vehicle = vehicleKey.VehicleName, victim = victim.DisplayName }], System.Drawing.Color.Green);

                            await victim.PrintMessageAsync(m_StringLocalizer["translations:victim_vehicle_transfer", new { vehicle = vehicleKey.VehicleName, user = user.DisplayName }], System.Drawing.Color.Green);
                        }
                    }
                    else
                    {
                        await user.PrintMessageAsync(m_StringLocalizer["translations:no_vehicle", new { vehicleID = id }]);
                    }
                }
            }
            else
            {
                throw new UserFriendlyException("Internal error!");
            }
        }
Ejemplo n.º 13
0
        public static bool AskClaimBed_Prefix(BarricadeManager __instance, CSteamID steamID, byte x, byte y, ushort plant, ushort index)
        {
            BarricadeRegion barricadeRegion;

            if (Provider.isServer && BarricadeManager.tryGetRegion(x, y, plant, out barricadeRegion))
            {
                Player player = PlayerTool.getPlayer(steamID);
                if (player == null)
                {
                    return(false);
                }
                if (player.life.isDead)
                {
                    return(false);
                }
                if (index >= barricadeRegion.drops.Count)
                {
                    return(false);
                }
                if ((barricadeRegion.drops[index].model.transform.position - player.transform.position).sqrMagnitude > 400f)
                {
                    return(false);
                }
                InteractableBed interactableBed = barricadeRegion.drops[index].interactable as InteractableBed;
                if (interactableBed != null && interactableBed.isClaimable && interactableBed.checkClaim(player.channel.owner.playerID.steamID))
                {
                    if (interactableBed.isClaimed)
                    {
                        var home = HomesHelper.GetPlayerHome(steamID, interactableBed);
                        HomesHelper.RemoveHome(steamID, home);
                        home.Unclaim();
                    }
                    else
                    {
                        var playerData = HomesHelper.GetOrCreatePlayer(steamID);
                        int maxHomes   = VipHelper.GetPlayerMaxHomes(steamID.ToString());
                        if (maxHomes == 1 && playerData.Homes.Count == 1)
                        {
                            foreach (var home in playerData.Homes.ToArray())
                            {
                                HomesHelper.RemoveHome(steamID, home);
                                home.Unclaim();
                            }
                        }
                        else if (maxHomes <= playerData.Homes.Count)
                        {
                            UnturnedChat.Say(steamID, MoreHomesPlugin.Instance.Translate("MaxHomesWarn"), MoreHomesPlugin.Instance.MessageColor);
                            return(false);
                        }

                        var playerHome = new PlayerHome(playerData.GetUniqueHomeName(), interactableBed);
                        playerData.Homes.Add(playerHome);
                        playerHome.Claim(steamID);
                        UnturnedChat.Say(steamID, MoreHomesPlugin.Instance.Translate("HomeClaimed", playerHome.Name), MoreHomesPlugin.Instance.MessageColor);
                    }
                }
            }
            return(false);
        }
Ejemplo n.º 14
0
        private async void OnPlayerConnected(SteamPlayer splayer)
        {
            await UniTask.SwitchToMainThread();

            Vote(PlayerTool.getPlayer(splayer.playerID.steamID), false);

            await UniTask.SwitchToThreadPool();
        }
Ejemplo n.º 15
0
        private void DamagePlayerRequested(ref DamagePlayerParameters parameters, ref bool shouldAllow)
        {
            var killerPlayer = PlayerTool.getPlayer(parameters.killer);

            if (!parameters.player.life.isDead && killerPlayer != null && killerPlayer != parameters.player && !Configuration.Instance.AllowCombat)
            {
                this.StartPlayerCombat(parameters.killer);
                this.StartPlayerCombat(parameters.player.channel.owner.playerID.steamID);
            }
        }
Ejemplo n.º 16
0
        private void Events_OnStructureTransformed(StructureData data, StructureDrop drop, CSteamID instigatorSteamId)
        {
            var nativePlayer = PlayerTool.getPlayer(instigatorSteamId);
            var player       = GetUnturnedPlayer(nativePlayer);

            var @event = new UnturnedStructureTransformedEvent(new UnturnedStructureBuildable(data, drop),
                                                               instigatorSteamId, player !);

            Emit(@event);
        }
Ejemplo n.º 17
0
        public string GetLanguage(CSteamID SteamID)
        {
            string GetLang(CSteamID steamID) => (Preferences.FirstOrDefault(x => x.SteamID == SteamID) ?? new PlayerPreferences()).Language;

            var p    = PlayerTool.getPlayer(SteamID);
            var lang = GetLang(SteamID);

            lang = lang ?? p?.channel.owner.language ?? EnglishCode;
            return(lang);
        }
Ejemplo n.º 18
0
        private void OnPlayerDamaged(Player player, ref EDeathCause cause, ref ELimb limb, ref CSteamID killer, ref Vector3 direction, ref float damage, ref float times, ref bool canDamage)
        {
            var killerPlayer = PlayerTool.getPlayer(killer);

            if (!player.life.isDead && killerPlayer != null && killerPlayer != player && !Configuration.Instance.AllowCombat)
            {
                this.StartPlayerCombat(killer);
                this.StartPlayerCombat(player.channel.owner.playerID.steamID);
            }
        }
 private UnturnedPlayer(CSteamID SteamID)
 {
     if (SteamID == Steamworks.CSteamID.Nil)
     {
         throw new PlayerIsConsoleException();
     }
     else
     {
         player = PlayerTool.getPlayer(SteamID);
     }
 }
Ejemplo n.º 20
0
            static bool Prefix(CSteamID steamID, Vector3 velocity)
            {
                Player ply = PlayerTool.getPlayer(steamID);

                if (ply.animator.gesture == EPlayerGesture.ARREST_START && !Main.Config.allowExitArrest)
                {
                    return(false);
                }

                return(true);
            }
Ejemplo n.º 21
0
            static bool Prefix(CSteamID steamID, uint instanceID, byte[] hash, byte engine)
            {
                Player ply = PlayerTool.getPlayer(steamID);

                if (ply.animator.gesture == EPlayerGesture.ARREST_START && !Main.Config.allowEnterArrest)
                {
                    return(false);
                }

                return(true);
            }
Ejemplo n.º 22
0
 private UnturnedPlayer(CSteamID cSteamID)
 {
     if (string.IsNullOrEmpty(cSteamID.ToString()) || cSteamID.ToString() == "0")
     {
         throw new PlayerIsConsoleException();
     }
     else
     {
         player = PlayerTool.getPlayer(cSteamID);
     }
 }
Ejemplo n.º 23
0
            private static void AddPlayer(InteractableVehicle __instance, CSteamID steamID)
            {
                Player player = PlayerTool.getPlayer(steamID);

                if (player == null)
                {
                    return;
                }

                OnVehicleEntered?.Invoke(__instance, player);
            }
 public static UnturnedPlayer FromCSteamID(CSteamID SteamID)
 {
     if (SteamID != Steamworks.CSteamID.Nil)
     {
         var player = PlayerTool.getPlayer(SteamID);
         if (player)
         {
             return(new UnturnedPlayer(player));
         }
     }
     return(null);
 }
Ejemplo n.º 25
0
        public void Revive()
        {
            Player ply   = PlayerTool.getPlayer(SteamID);
            Spawn  spawn = Main.Config.LobbySpawns.First();

            ply.life.channel.send("tellRevive", ESteamCall.ALL, ESteamPacket.UPDATE_RELIABLE_BUFFER, new object[]
            {
                new Vector3(spawn.X, spawn.Y, spawn.Z), // Location
                (byte)0                                 // yaw?
            });
            ply.life.sendRevive();
        }
Ejemplo n.º 26
0
        protected override Task OnExecuteAsync()
        {
            if (Context.Actor.Type == KnownActorTypes.Console && Context.Parameters.Length != 0)
            {
                throw new CommandWrongUsageException(Context);
            }

            if (Context.Parameters.Length == 0)
            {
                m_PluginAccessor.Instance.Vote(PlayerTool.getPlayer(new Steamworks.CSteamID(ulong.Parse(Context.Actor.Id))));
            }

            return(Task.CompletedTask);
        }
Ejemplo n.º 27
0
        public static void dropItem(Item item, Vector3 point, bool playEffect, bool isDropped, CSteamID steamId, bool wideSpread)
        {
            if (steamId != CSteamID.Nil)
            {
                var player = PlayerTool.getPlayer(steamId);

                if (!player.inventory.tryAddItemAuto(item, true, true, true, playEffect))
                {
                    ItemManager.dropItem(item, point, playEffect, isDropped, wideSpread);
                }
            }
            else
            {
                ItemManager.dropItem(item, point, playEffect, isDropped, wideSpread);
            }
        }
Ejemplo n.º 28
0
#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously
        private async Task TrackerGunTick()
        {
            foreach (KeyValuePair <CSteamID, long> pair in TrackedPlayers.Keys.ToDictionary(_ => _, _ => TrackedPlayers[_]))
            {
                TrackedPlayers[pair.Key] -= 500;
                if (pair.Value % 5000 == 0)
                {
                    Player ply = PlayerTool.getPlayer(pair.Key);
                    InterfaceManager.SendEffectLocationUnsafe(107, ply.transform.position);
                }
                if (pair.Value == 0)
                {
                    RemoveTrackedPlayer(pair.Key);
                }
            }
        }
Ejemplo n.º 29
0
        private static IEnumerator DisableHUDCoroutine(CSteamID steamID)
        {
            Player ply = PlayerTool.getPlayer(steamID);

            if (ply is null)
            {
                yield return(null);
            }

            ply.setPluginWidgetFlag(EPluginWidgetFlags.ShowFood, false);
            ply.setPluginWidgetFlag(EPluginWidgetFlags.ShowWater, false);
            ply.setPluginWidgetFlag(EPluginWidgetFlags.ShowVirus, false);
            ply.setPluginWidgetFlag(EPluginWidgetFlags.ShowOxygen, false);
            ply.setPluginWidgetFlag(EPluginWidgetFlags.ShowStatusIcons, false);
            yield return(null);
        }
Ejemplo n.º 30
0
        private static IEnumerator SetSteamGroupEnumerator(CSteamID steamID)
        {
            Player ply = PlayerTool.getPlayer(steamID);

            if (ply is null)
            {
                yield return(null);
            }

            GroupManager.sendGroupInfo(steamID, GroupManager.getGroupInfo((CSteamID)1));
            ply.quests.channel.send("tellSetGroup", ESteamCall.ALL, ESteamPacket.UPDATE_RELIABLE_BUFFER, new object[]
            {
                (CSteamID)1,
                (byte)EPlayerGroupRank.MEMBER
            });
            yield return(null);
        }