Exemple #1
0
        private static void RemovePaint(Vector3i position, Vector3i size, Dictionary <long, Chunk> modifiedChunks)
        {
            const int clrIdx  = 0;
            var       counter = 0;

            for (var j = 0; j < size.y; j++)
            {
                for (var i = 0; i < size.x; i++)
                {
                    for (var k = 0; k < size.z; k++)
                    {
                        var worldPos   = new Vector3i(i + position.x, j + position.y, k + position.z);
                        var worldBlock = GameManager.Instance.World.GetBlock(clrIdx, worldPos);
                        if (worldBlock.Block.shape.IsTerrain() || worldBlock.Equals(BlockValue.Air))
                        {
                            continue;
                        }

                        GameManager.Instance.World.ChunkClusters[clrIdx].SetTextureFull(worldPos, 0L);
                        counter++;
                    }
                }
            }

            SendOutput($"Paint removed from {counter} blocks @ {position} to {BCUtils.GetMaxPos(position, size)}");
            SendOutput("Use bc-undo to revert the changes");
            Reload(modifiedChunks);
        }
Exemple #2
0
        protected override void Process()
        {
            if (!BCUtils.CheckWorld(out var world))
            {
                return;
            }

            if (Options.ContainsKey("all") || Options.ContainsKey("istype") || Options.ContainsKey("type") || Options.ContainsKey("minibike") || Options.ContainsKey("ecname"))
            {
                var count = new Dictionary <string, int>();

                foreach (var key in BCUtils.FilterEntities(world.Entities.dict, Options).Keys)
                {
                    RemoveEntity(world, key, count);
                }

                SendJson(count);
            }
            else if (Params.Count == 1)
            {
                if (!int.TryParse(Params[0], out var entityId))
                {
                    SendOutput("Unable to parse entity id");

                    return;
                }

                RemoveEntity(world, entityId);
            }
            else
            {
                SendOutput(GetHelp());
            }
        }
Exemple #3
0
        private static void FillBlocks(Vector3i position, Vector3i size, BlockValue bv, string search, Dictionary <long, Chunk> modifiedChunks)
        {
            const int clrIdx = 0;

            if (Block.list[bv.type] == null)
            {
                SendOutput("Unable to find block by id or name");

                return;
            }

            SetBlocks(clrIdx, position, size, bv, search == "*");

            if (Options.ContainsKey("delmulti"))
            {
                SendOutput($"Removed multidim blocks @ {position} to {BCUtils.GetMaxPos(position, size)}");
            }
            else
            {
                SendOutput($"Inserting block '{Block.list[bv.type].GetBlockName()}' @ {position} to {BCUtils.GetMaxPos(position, size)}");
                SendOutput("Use bc-undo to revert the changes");
            }

            Reload(modifiedChunks);
        }
Exemple #4
0
        protected static void SendJson(object data)
        {
            var writer = new JsonWriter();

            if (Options.ContainsKey("pp") && !Options.ContainsKey("1l"))
            {
                writer.IndentValue = 2;
                writer.PrettyPrint = true;
            }

            JsonMapper.RegisterExporter <float>((o, w) => w.Write(Convert.ToDouble(o)));

            var f = Options.ContainsKey("strpos") ? "S" : Options.ContainsKey("worldpos") ? "W" : Options.ContainsKey("csvpos") ? "C" : "V";

            JsonMapper.RegisterExporter <Vector3>((v, w) => BCUtils.WriteVector3(v, w, f));
            JsonMapper.RegisterExporter <Vector3i>((v, w) => BCUtils.WriteVector3i(v, w, f));

            var jsonOut = new Dictionary <string, object>();

            if (Options.ContainsKey("tag"))
            {
                jsonOut.Add("tag", Options["tag"]);
                jsonOut.Add("data", data);

                JsonMapper.ToJson(jsonOut, writer);
            }
            else
            {
                JsonMapper.ToJson(data, writer);
            }

            SendOutput(writer.ToString().TrimStart());
        }
Exemple #5
0
        private SortedList <string, object> GetGamePrefs()
        {
            var sortedList = new SortedList <string, object>();

            var enumerator = Enum.GetValues(typeof(EnumGamePrefs)).GetEnumerator();

            while (enumerator.MoveNext())
            {
                if (enumerator.Current == null)
                {
                    continue;
                }

                var enumGamePrefs = (EnumGamePrefs)(int)enumerator.Current;
                if (!IsViewablePref(enumGamePrefs))
                {
                    continue;
                }

                try
                {
                    sortedList.Add(enumGamePrefs.ToString(), GamePrefs.GetObject(enumGamePrefs));
                }
                catch (Exception)
                {
                    //Log.Out("Exception getting object for " + enumGamePrefs);
                }
            }
            (enumerator as IDisposable)?.Dispose();

            sortedList.Add("ServerHostIP", BCUtils.GetIPAddress());

            return(sortedList);
        }
Exemple #6
0
        //todo: load chunk observers async version

        protected override void Process()
        {
            if (!BCUtils.CheckWorld(out var world))
            {
                return;
            }

            var command = new BCMCmdArea(Params, Options, "Export");

            if (!BCUtils.ProcessParams(command, 14))
            {
                SendOutput(GetHelp());

                return;
            }

            if (!BCUtils.GetIds(world, command, out var entity))
            {
                SendOutput("Command requires a position when not run by a player.");

                return;
            }

            if (!command.HasChunkPos && !command.HasPos && !BCUtils.GetEntPos(command, entity))
            {
                SendOutput("Unable to get position.");

                return;
            }

            BCUtils.DoProcess(world, command, this);
        }
Exemple #7
0
        private static void RepairBlocks(Vector3i position, Vector3i size, Dictionary <long, Chunk> modifiedChunks)
        {
            const int clrIdx  = 0;
            var       counter = 0;

            for (var j = 0; j < size.y; j++)
            {
                for (var i = 0; i < size.x; i++)
                {
                    for (var k = 0; k < size.z; k++)
                    {
                        var worldPos   = new Vector3i(i + position.x, j + position.y, k + position.z);
                        var worldBlock = GameManager.Instance.World.GetBlock(clrIdx, worldPos);
                        if (worldBlock.Equals(BlockValue.Air))
                        {
                            continue;
                        }

                        worldBlock.damage = 0;
                        GameManager.Instance.World.ChunkClusters[clrIdx].SetBlock(worldPos, worldBlock, false, false);
                        counter++;
                    }
                }
            }

            SendOutput($"Repairing {counter} blocks @ {position} to {BCUtils.GetMaxPos(position, size)}");
            SendOutput("Use bc-undo to revert the changes");
            Reload(modifiedChunks);
        }
Exemple #8
0
 public BCMMeshDataShort([NotNull] XmlElement uv)
 {
     if (uv.HasAttribute("id"))
     {
         int.TryParse(uv.GetAttribute("id"), out Id);
     }
     if (uv.HasAttribute("color"))
     {
         var rgb = uv.GetAttribute("color").Split(',');
         if (rgb.Length == 3 && float.TryParse(rgb[0], out var r) && float.TryParse(rgb[1], out var g) && float.TryParse(rgb[2], out var b))
         {
             Color = BCUtils.ColorToHex(new Color(r, g, b));
         }
     }
     Material = uv.HasAttribute("material") ? uv.GetAttribute("material") : "";
     Texture  = uv.HasAttribute("texture") ? uv.GetAttribute("texture").Substring(0, uv.GetAttribute("texture").Length - 4) : "";
 }
        protected override void Process()
        {
            if (!BCUtils.CheckWorld())
            {
                return;
            }

            var editMode = GameManager.Instance.GetType().GetField(_editModeField, BindingFlags.NonPublic | BindingFlags.Instance);

            if (editMode == null)
            {
                SendOutput("Error getting editmode field");

                return;
            }

            if (!(editMode.GetValue(GameManager.Instance) is bool mode))
            {
                SendOutput("Error getting current value of editmode");

                return;
            }

            if (Params.Count == 1)
            {
                switch (Params[0])
                {
                case "toggle":
                    editMode.SetValue(GameManager.Instance, !mode);
                    break;

                default:
                    if (!bool.TryParse(Params[0], out var flag))
                    {
                        SendOutput("Unable to parse param as a boolean");

                        return;
                    }
                    editMode.SetValue(GameManager.Instance, flag);
                    break;
                }
            }

            SendOutput($"Edit Mode set to {GameManager.Instance.IsEditMode()}");
        }
Exemple #10
0
        protected override void Process()
        {
            if (!BCUtils.CheckWorld())
            {
                return;
            }

            if (Params.Count != 2)
            {
                SendOutput("Invalid arguments");
                SendOutput(GetHelp());

                return;
            }

            var count = ConsoleHelper.ParseParamPartialNameOrId(Params[0], out string _, out var clientInfo);

            if (count == 1)
            {
                if (clientInfo == null)
                {
                    SendOutput("Unable to locate player.");

                    return;
                }

                if (MultiBuffClass.s_classes.ContainsKey(Params[1]))
                {
                    clientInfo.SendPackage(new NetPackageConsoleCmdClient("buff " + Params[1], true));
                    SendOutput($"Buff {Params[1]} given to player {clientInfo.playerName}");
                }
                else
                {
                    SendOutput($"Unable to find buff {Params[1]}");
                }
            }
            else if (count > 1)
            {
                SendOutput($"{count} matches found, please refine your search text.");
            }
            else
            {
                SendOutput("Player not found.");
            }
        }
Exemple #11
0
        protected override void Process()
        {
            if (!BCUtils.CheckWorld())
            {
                return;
            }

            if (Params.Count != 2)
            {
                SendOutput(GetHelp());

                return;
            }

            var count = ConsoleHelper.ParseParamPartialNameOrId(Params[0], out string _, out var clientInfo);

            if (count == 1)
            {
                if (clientInfo == null)
                {
                    return;
                }

                if (QuestClass.s_Quests.ContainsKey(Params[1].ToLower()))
                {
                    clientInfo.SendPackage(new NetPackageConsoleCmdClient($"removequest {Params[1]}", true));
                    SendOutput($"Quest {Params[1]} removed from player {clientInfo.playerName}");
                }
                else
                {
                    SendOutput($"Unable to find quest {Params[1]}");
                }
            }
            else if (count > 1)
            {
                SendOutput($"{count} matches found, please refine your search text.");
            }
            else
            {
                SendOutput("Unable to find player.");
            }
        }
Exemple #12
0
        private static void SetRotation(Vector3i position, Vector3i size, Dictionary <long, Chunk> modifiedChunks)
        {
            byte rotation = 0;

            if (Options.ContainsKey("rot"))
            {
                if (!byte.TryParse(Options["rot"], out rotation))
                {
                    SendOutput($"Unable to parse rotation '{Options["rot"]}'");

                    return;
                }
            }

            const int clrIdx  = 0;
            var       counter = 0;

            for (var j = 0; j < size.y; j++)
            {
                for (var i = 0; i < size.x; i++)
                {
                    for (var k = 0; k < size.z; k++)
                    {
                        var worldPos   = new Vector3i(i + position.x, j + position.y, k + position.z);
                        var worldBlock = GameManager.Instance.World.GetBlock(clrIdx, worldPos);
                        if (worldBlock.Equals(BlockValue.Air) || worldBlock.ischild || !worldBlock.Block.shape.IsRotatable)
                        {
                            continue;
                        }

                        worldBlock.rotation = rotation;
                        GameManager.Instance.World.ChunkClusters[clrIdx].SetBlock(worldPos, worldBlock, false, false);
                        counter++;
                    }
                }
            }

            SendOutput($"Setting rotation on '{counter}' blocks @ {position} to {BCUtils.GetMaxPos(position, size)}");
            SendOutput("Use bc-undo to revert the changes");
            Reload(modifiedChunks);
        }
Exemple #13
0
        //todo: list subcommand to display previous actions and the undo id
        //todo: ability to undo a specific undo id
        //todo: ability to undo x previous commands in reverse order
        //todo: if chunks not loaded, fail and dont remove undo from history

        protected override void Process()
        {
            if (!BCUtils.CheckWorld(out var world))
            {
                return;
            }

            EntityPlayer sender = null;

            if (SenderInfo.RemoteClientInfo != null)
            {
                sender = world.Entities.dict[SenderInfo.RemoteClientInfo.entityId] as EntityPlayer;
            }

            if (sender == null)
            {
                return;
            }

            SendOutput(BCUtils.UndoSetBlocks(sender) ? "Undoing previous world editing command" : "Undo failed, nothing to undo?");
        }
Exemple #14
0
        public override void Process()
        {
            var world = GameManager.Instance.World;

            if (world == null)
            {
                return;
            }

            if (Options.ContainsKey("all") || Options.ContainsKey("istype") || Options.ContainsKey("type") || Options.ContainsKey("minibike"))
            {
                var count = new Dictionary <string, int>();

                foreach (var key in BCUtils.FilterEntities(world.Entities.dict, Options).Keys)
                {
                    RemoveEntity(key, count);
                }

                SendJson(count);
            }
            else if (Params.Count == 1)
            {
                if (!int.TryParse(Params[0], out var entityId))
                {
                    SendOutput("Unable to parse entity id");

                    return;
                }

                RemoveEntity(entityId);
            }
            else
            {
                SendOutput(GetHelp());
            }
        }
Exemple #15
0
        public override void Process()
        {
            var world = GameManager.Instance.World;

            if (world == null)
            {
                SendOutput("World not initialized.");

                return;
            }

            var command = new BCMCmdArea(Params, Options, "Export");

            if (!BCUtils.ProcessParams(command, 14))
            {
                SendOutput(GetHelp());

                return;
            }

            if (!BCUtils.GetIds(world, command, out var entity))
            {
                SendOutput("Command requires a position when not run by a player.");

                return;
            }

            if (!command.HasChunkPos && !command.HasPos && !BCUtils.GetEntPos(command, entity))
            {
                SendOutput("Unable to get position.");

                return;
            }

            BCUtils.DoProcess(world, command, this);
        }
Exemple #16
0
        protected override void Process()
        {
            if (!BCUtils.CheckWorld(out var world))
            {
                return;
            }

            if (Options.ContainsKey("filters"))
            {
                Filters();

                return;
            }

            if (Options.ContainsKey("index"))
            {
                Indexed();

                return;
            }

            if (Params.Count > 1)
            {
                SendOutput("Wrong number of arguments");
                SendOutput(Config.GetHelp(GetType().Name));

                return;
            }

            if (Params.Count == 1)
            {
                // specific entity
                Entity e = null;
                if (int.TryParse(Params[0], out var entityId))
                {
                    if (world.Entities.dict.ContainsKey(entityId))
                    {
                        e = world.Entities.dict[entityId];
                    }
                }
                if (e == null)
                {
                    SendOutput("Entity id not found.");

                    return;
                }

                var entity = new BCMEntity(e, Options, GetFilters(BCMGameObject.GOTypes.Entities));
                if (Options.ContainsKey("min"))
                {
                    SendJson(new List <List <object> >
                    {
                        entity.Data().Select(d => d.Value).ToList()
                    });
                }
                else
                {
                    SendJson(entity.Data());
                }
            }
            else
            {
                //todo: /entity=id1,id2,id3

                // All entities
                var data = new List <object>();
                foreach (var entity in BCUtils.FilterEntities(world.Entities.dict, Options).Values.Select(en => new BCMEntity(en, Options, GetFilters(BCMGameObject.GOTypes.Entities))))
                {
                    if (Options.ContainsKey("min"))
                    {
                        data.Add(entity.Data().Select(d => d.Value).ToList());
                    }
                    else
                    {
                        data.Add(entity.Data());
                    }
                }

                SendJson(data);
            }
        }
        //todo: count sub command that returns a count of each object type

        protected override void Process()
        {
            if (!BCUtils.CheckWorld())
            {
                return;
            }

            string type;

            switch (Params.Count)
            {
            case 0:
                //LIST OBJECT TYPES
                var o = typeof(BCMGameObject.GOTypes);
                SendJson(
                    o.GetFields()
                    .AsQueryable()
                    .Where(f => f.Name != "Players" && f.Name != "Entities")
                    .ToDictionary(field => field.Name, field => field.GetValue(o).ToString()));
                return;

            case 1:
                //ALL OBJECTS OF A TYPE
                type = Params[0].ToLower();

                if (Options.ContainsKey("filters"))
                {
                    DisplayFilters(type);

                    return;
                }

                if (Options.ContainsKey("index"))
                {
                    DisplayIndex(type);

                    return;
                }

                //if (type == "count")
                //{
                //  CountObjects();
                //  return;
                //}
                GetObjects(type, out var objects);
                ProcessObjects(type, objects, out var data, GetFilters(type));
                SendJson(type == BCMGameObject.GOTypes.Rwg ? data[0] : data);
                return;

            case 2:
                //SPECIFIC OBJECT
                type = Params[0].ToLower();
                if (!GetObject(type, out var obj))
                {
                    return;
                }
                var gameObject = new BCMGameObject(obj, type, Options, GetFilters(type));
                SendObject(gameObject);
                return;

            default:
                SendOutput("Wrong number of arguments");
                SendOutput(Config.GetHelp(GetType().Name));
                return;
            }
        }
Exemple #18
0
        protected override void Process()
        {
            if (!BCUtils.CheckWorld())
            {
                return;
            }

            if (Params.Count == 0)
            {
                SendOutput(GetHelp());

                return;
            }

            switch (Params[0])
            {
            case "save":
                //todo: save current settings to system.xml file
                break;

            case "on":
                if (Heartbeat.IsAlive)
                {
                    SendOutput("Heart is already beating");

                    return;
                }
                Heartbeat.IsAlive = true;
                Heartbeat.Start();
                SendOutput("Heatbeat started");
                break;

            case "off":
                Heartbeat.IsAlive = false;
                SendOutput("Heatbeat stopped");
                break;

            case "bpm":
                if (Params.Count < 2)
                {
                    SendOutput($"Current beats per minute is {Heartbeat.Bpm}");

                    return;
                }

                if (!int.TryParse(Params[1], out var bpm))
                {
                    SendOutput($"Unable to parse bpm from: {Params[1]}");

                    return;
                }

                if (bpm > 300)
                {
                    SendOutput($"Woah, {bpm} is a bit high, are you trying to give the server a heartattack!? Max is 300");

                    return;
                }

                if (bpm <= 0)
                {
                    SendOutput("Check your pulse, you might be dead! Bpm must be greater than 0");

                    return;
                }

                Heartbeat.Bpm = bpm;
                SendOutput($"Bpm now set to {bpm}");

                break;

            case "state":
            case "toggle":
            case "disable":
            case "enable":
            {
                if (Params.Count != 2)
                {
                    SendOutput("Select an event neuron to view/alter the state, * for all");
                    SendOutput(string.Join(",", Brain.Synapses.Select(s => s.Name).ToArray()));

                    return;
                }

                if (Params[1] == "*")
                {
                    foreach (var s in Brain.Synapses)
                    {
                        ProcessSynapseState(s);
                    }

                    return;
                }

                var synapse = Brain.GetSynapse(Params[1]);
                ProcessSynapseState(synapse);

                return;
            }

            case "deadisdead":
                ConfigDeadIsDead();
                return;

            case "pingkicker":
                ConfigPingKicker();
                return;

            case "tracker":
                ConfigTracker();
                return;

            case "spawnmutator":
                ConfigSpawnMutator();
                return;

            case "spawnmanager":
                ConfigSpawnManager();
                return;

            case "logcache":
                ConfigLogCache();
                return;

            default:
                SendOutput($"Unknown neuron name {Params[0]}");
                return;
            }
        }
Exemple #19
0
        protected override void Process()
        {
            if (!BCUtils.CheckWorld())
            {
                return;
            }

            if (Params.Count < 2 && (Params.Count == 0 || Params[0] != "list"))
            {
                SendOutput(GetHelp());

                return;
            }

            switch (Params[0])
            {
            case "list":
                ListPrefabs();
                break;

            case "create":
                CreatePrefab();
                break;

            case "clone":
                ClonePrefab();
                break;

            case "backup":
                BackupPrefab();
                break;

            case "restore":
                RestorePrefab();
                break;

            case "delete":
                DeletePrefab();
                break;

            case "setprop":
                SetProperty();
                break;

            case "insert"://todo
                InsertLayers();
                break;

            case "cut"://todo
                CutLayers();
                break;

            case "add":
                AddLayers();
                break;

            case "trim":
                TrimLayers();
                break;

            case "setsize":
                SetSize();
                break;

            case "swap":
                SwapBlocks();
                break;

            case "swapmap"://todo
                SwapMap();
                break;

            case "copylayer"://todo
                CopyLayer();
                break;

            case "swaplayer"://todo
                SwapLayer();
                break;

            case "setblock"://todo
                SetBlock();
                break;

            case "repair"://todo
                RepairBlocks();
                break;

            case "lock"://todo
                LockSecureBlocks();
                break;

            case "dim":
                GetDimensions();
                break;

            case "blockcount":
                GetBlockCounts();
                break;

            case "blocks":
                GetBlocks();
                break;

            case "paint":
                GetPaint();
                break;

            case "type":
                GetBlocks("type");
                break;

            case "density":
                GetBlocks("density");
                break;

            case "rotation":
                GetBlocks("rotation");
                break;

            case "damage":
                GetBlocks("damage");
                break;

            case "meta":
                GetBlocks("meta");
                break;

            case "meta2":
                GetBlocks("meta2");
                break;

            case "meta3":
                GetBlocks("meta3");
                break;

            case "stats":
                GetStats();
                break;

            case "xml":
                GetXml();
                break;

            default:
                SendOutput($"Unknown sub command {Params[0]}");
                break;
            }
        }
Exemple #20
0
 private void GetColor(BiomeDefinition biome) => Bin.Add("Color", Color = BCUtils.UIntToHex(biome.m_uiColor));
Exemple #21
0
        private static void SwapBlocks(Vector3i position, Vector3i size, BlockValue newbv, string blockname, Dictionary <long, Chunk> modifiedChunks)
        {
            var targetbv = int.TryParse(blockname, out var blockId) ? Block.GetBlockValue(blockId) : Block.GetBlockValue(blockname);

            var block1 = Block.list[targetbv.type];

            if (block1 == null)
            {
                SendOutput("Unable to find target block by id or name");

                return;
            }

            var block2 = Block.list[newbv.type];

            if (block2 == null)
            {
                SendOutput("Unable to find replacement block by id or name");

                return;
            }

            const int clrIdx  = 0;
            var       counter = 0;
            var       world   = GameManager.Instance.World;

            for (var i = 0; i < size.x; i++)
            {
                for (var j = 0; j < size.y; j++)
                {
                    for (var k = 0; k < size.z; k++)
                    {
                        sbyte density = 1;
                        if (Options.ContainsKey("d"))
                        {
                            if (sbyte.TryParse(Options["d"], out density))
                            {
                                SendOutput($"Using density {density}");
                            }
                        }
                        else
                        {
                            if (newbv.Equals(BlockValue.Air))
                            {
                                density = MarchingCubes.DensityAir;
                            }
                            else if (newbv.Block.shape.IsTerrain())
                            {
                                density = MarchingCubes.DensityTerrain;
                            }
                        }

                        var textureFull = 0L;
                        if (Options.ContainsKey("t"))
                        {
                            if (!byte.TryParse(Options["t"], out var texture))
                            {
                                SendOutput("Unable to parse texture index");

                                return;
                            }

                            if (BlockTextureData.list[texture] == null)
                            {
                                SendOutput($"Unknown texture index {texture}");

                                return;
                            }

                            var num = 0L;
                            for (var face = 0; face < 6; face++)
                            {
                                var num2 = face * 8;
                                num &= ~(255L << num2);
                                num |= (long)(texture & 255) << num2;
                            }
                            textureFull = num;
                        }

                        var worldPos = new Vector3i(i + position.x, j + position.y, k + position.z);
                        if (world.GetBlock(worldPos).Block.GetBlockName() != block1.GetBlockName())
                        {
                            continue;
                        }

                        world.ChunkClusters[clrIdx].SetBlock(worldPos, true, newbv, false, density, false, false);
                        world.ChunkClusters[clrIdx].SetTextureFull(worldPos, textureFull);
                        counter++;
                    }
                }
            }

            SendOutput($"Replaced {counter} '{block1.GetBlockName()}' blocks with '{block2.GetBlockName()}' @ {position} to {BCUtils.GetMaxPos(position, size)}");
            SendOutput("Use bc-undo to revert the changes");
            Reload(modifiedChunks);
        }
Exemple #22
0
        protected override void Process()
        {
            if (!BCUtils.CheckWorld(out var world))
            {
                return;
            }

            if (Options.ContainsKey("undo"))
            {
                SendOutput("Please use the bc-undo command to undo changes");

                return;
            }

            var    pos1 = new Vector3i(int.MinValue, 0, int.MinValue);
            var    pos2 = new Vector3i(int.MinValue, 0, int.MinValue);
            string blockname;
            string blockname2 = null;

            //get loc and player current pos
            EntityPlayer sender  = null;
            string       steamId = null;

            if (SenderInfo.RemoteClientInfo != null)
            {
                steamId = SenderInfo.RemoteClientInfo.ownerId;
                sender  = world.Entities.dict[SenderInfo.RemoteClientInfo.entityId] as EntityPlayer;
                if (sender != null)
                {
                    pos2 = new Vector3i((int)Math.Floor(sender.serverPos.x / 32f), (int)Math.Floor(sender.serverPos.y / 32f), (int)Math.Floor(sender.serverPos.z / 32f));
                }
                else
                {
                    SendOutput("Error: unable to get player location");

                    return;
                }
            }

            switch (Params.Count)
            {
            case 2:
            case 3:
                if (steamId != null)
                {
                    pos1 = BCLocation.GetPos(steamId);
                    if (pos1.x == int.MinValue)
                    {
                        SendOutput("No location stored. Use bc-loc to store a location.");

                        return;
                    }

                    blockname = Params[1];
                    if (Params.Count == 3)
                    {
                        blockname2 = Params[2];
                    }
                }
                else
                {
                    SendOutput("Error: unable to get player location");

                    return;
                }
                break;

            case 8:
            case 9:
                //parse params
                if (!int.TryParse(Params[1], out pos1.x) || !int.TryParse(Params[2], out pos1.y) || !int.TryParse(Params[3], out pos1.z) || !int.TryParse(Params[4], out pos2.x) || !int.TryParse(Params[5], out pos2.y) || !int.TryParse(Params[6], out pos2.z))
                {
                    SendOutput("Error: unable to parse coordinates");

                    return;
                }
                blockname = Params[7];
                if (Params.Count == 9)
                {
                    blockname2 = Params[8];
                }
                break;

            default:
                SendOutput("Error: Incorrect command format.");
                SendOutput(GetHelp());

                return;
            }

            var size = BCUtils.GetSize(pos1, pos2);

            var position = new Vector3i(
                pos1.x < pos2.x ? pos1.x : pos2.x,
                pos1.y < pos2.y ? pos1.y : pos2.y,
                pos1.z < pos2.z ? pos1.z : pos2.z
                );

            //**************** GET BLOCKVALUE
            var bvNew = int.TryParse(blockname, out var blockId) ? Block.GetBlockValue(blockId) : Block.GetBlockValue(blockname);

            var modifiedChunks = BCUtils.GetAffectedChunks(new BCMCmdArea("Blocks")
            {
                Position = new BCMVector3(position),
                Size     = new BCMVector3(size),
                HasPos   = true,
                HasSize  = true,

                ChunkBounds = new BCMVector4
                {
                    x = World.toChunkXZ(position.x),
                    y = World.toChunkXZ(position.z),
                    z = World.toChunkXZ(position.x + size.x - 1),
                    w = World.toChunkXZ(position.z + size.z - 1)
                },
                HasChunkPos = true
            }, world);

            //CREATE UNDO
            //create backup of area blocks will insert to
            if (!Options.ContainsKey("noundo"))
            {
                BCUtils.CreateUndo(sender, position, size);
            }

            switch (Params[0])
            {
            case "scan":
                ScanBlocks(position, size, bvNew, blockname);
                break;

            case "fill":
                FillBlocks(position, size, bvNew, blockname, modifiedChunks);
                break;

            case "swap":
                SwapBlocks(position, size, bvNew, blockname2, modifiedChunks);
                break;

            case "repair":
                RepairBlocks(position, size, modifiedChunks);
                break;

            case "damage":
                DamageBlocks(position, size, modifiedChunks);
                break;

            case "upgrade":
                UpgradeBlocks(position, size, modifiedChunks);
                break;

            case "downgrade":
                DowngradeBlocks(position, size, modifiedChunks);
                break;

            case "paint":
                SetPaint(position, size, modifiedChunks);
                break;

            case "paintface":
                SetPaintFace(position, size, modifiedChunks);
                break;

            case "paintstrip":
                RemovePaint(position, size, modifiedChunks);
                break;

            case "density":
                SetDensity(position, size, modifiedChunks);
                break;

            case "rotate":
                SetRotation(position, size, modifiedChunks);
                break;

            case "meta1":
                SetMeta(1, position, size, modifiedChunks);
                break;

            case "meta2":
                SetMeta(2, position, size, modifiedChunks);
                break;

            case "meta3":
                SetMeta(3, position, size, modifiedChunks);
                break;

            default:
                SendOutput(GetHelp());
                break;
            }
        }
Exemple #23
0
        private static void SetPaint(Vector3i position, Vector3i size, Dictionary <long, Chunk> modifiedChunks)
        {
            var texture = 0;

            if (Options.ContainsKey("t"))
            {
                if (!int.TryParse(Options["t"], out texture))
                {
                    SendOutput("Unable to parse texture value");

                    return;
                }
                if (BlockTextureData.list[texture] == null)
                {
                    SendOutput($"Unknown texture index {texture}");

                    return;
                }
            }

            var num = 0L;

            for (var face = 0; face < 6; face++)
            {
                var num2 = face * 8;
                num &= ~(255L << num2);
                num |= (long)(texture & 255) << num2;
            }
            var textureFull = num;

            const int clrIdx  = 0;
            var       counter = 0;

            for (var j = 0; j < size.y; j++)
            {
                for (var i = 0; i < size.x; i++)
                {
                    for (var k = 0; k < size.z; k++)
                    {
                        var worldPos   = new Vector3i(i + position.x, j + position.y, k + position.z);
                        var worldBlock = GameManager.Instance.World.GetBlock(clrIdx, worldPos);
                        if (worldBlock.Block.shape.IsTerrain() || worldBlock.Equals(BlockValue.Air))
                        {
                            continue;
                        }

                        GameManager.Instance.World.ChunkClusters[clrIdx].SetTextureFull(worldPos, textureFull);
                        counter++;
                    }
                }
            }

            SendOutput($"Painting {counter} blocks with texture '{BlockTextureData.GetDataByTextureID(texture)?.Name}' @ {position} to {BCUtils.GetMaxPos(position, size)}");
            SendOutput("Use bc-undo to revert the changes");
            Reload(modifiedChunks);
        }
Exemple #24
0
        private static void SetDensity(Vector3i position, Vector3i size, Dictionary <long, Chunk> modifiedChunks)
        {
            sbyte density = 1;

            if (Options.ContainsKey("d"))
            {
                if (sbyte.TryParse(Options["d"], out density))
                {
                    SendOutput($"Using density {density}");
                }
            }

            const int clrIdx  = 0;
            var       counter = 0;

            for (var j = 0; j < size.y; j++)
            {
                for (var i = 0; i < size.x; i++)
                {
                    for (var k = 0; k < size.z; k++)
                    {
                        var worldPos   = new Vector3i(i + position.x, j + position.y, k + position.z);
                        var worldBlock = GameManager.Instance.World.GetBlock(clrIdx, worldPos);
                        if (worldBlock.Equals(BlockValue.Air) || worldBlock.ischild)
                        {
                            continue;
                        }

                        GameManager.Instance.World.ChunkClusters[clrIdx]
                        .SetBlock(worldPos, false, worldBlock, true, density, false, false, Options.ContainsKey("force"));
                        counter++;
                    }
                }
            }

            SendOutput($"Setting density on {counter} blocks '{density}' @ {position} to {BCUtils.GetMaxPos(position, size)}");
            SendOutput("Use bc-undo to revert the changes");
            Reload(modifiedChunks);
        }
Exemple #25
0
        private static void DamageBlocks(Vector3i position, Vector3i size, Dictionary <long, Chunk> modifiedChunks)
        {
            var damageMin = 0;
            var damageMax = 0;

            if (Options.ContainsKey("d"))
            {
                if (Options["d"].IndexOf(",", StringComparison.InvariantCulture) > -1)
                {
                    var dRange = Options["d"].Split(',');
                    if (dRange.Length != 2)
                    {
                        SendOutput("Unable to parse damage values");

                        return;
                    }

                    if (!int.TryParse(dRange[0], out damageMin))
                    {
                        SendOutput("Unable to parse damage min value");

                        return;
                    }

                    if (!int.TryParse(dRange[1], out damageMax))
                    {
                        SendOutput("Unable to parse damage max value");

                        return;
                    }
                }
                else
                {
                    if (!int.TryParse(Options["d"], out damageMin))
                    {
                        SendOutput("Unable to parse damage value");

                        return;
                    }
                }
            }

            const int clrIdx  = 0;
            var       counter = 0;

            for (var j = 0; j < size.y; j++)
            {
                for (var i = 0; i < size.x; i++)
                {
                    for (var k = 0; k < size.z; k++)
                    {
                        var worldPos   = new Vector3i(i + position.x, j + position.y, k + position.z);
                        var worldBlock = GameManager.Instance.World.GetBlock(clrIdx, worldPos);
                        if (worldBlock.Equals(BlockValue.Air))
                        {
                            continue;
                        }

                        var max    = worldBlock.Block.blockMaterial.MaxDamage;
                        var damage = (damageMax != 0 ? UnityEngine.Random.Range(damageMin, damageMax) : damageMin) + worldBlock.damage;
                        if (Options.ContainsKey("nobreak"))
                        {
                            worldBlock.damage = Math.Min(damage, max - 1);
                        }
                        else if (Options.ContainsKey("overkill"))
                        {
                            while (damage >= max)
                            {
                                var downgradeBlock = worldBlock.Block.DowngradeBlock;
                                damage -= max;
                                max     = downgradeBlock.Block.blockMaterial.MaxDamage;
                                downgradeBlock.rotation = worldBlock.rotation;
                                worldBlock = downgradeBlock;
                            }
                            worldBlock.damage = damage;
                        }
                        else
                        {
                            //needs to downgrade if damage > max, no overflow damage
                            if (damage >= max)
                            {
                                var downgradeBlock = worldBlock.Block.DowngradeBlock;
                                downgradeBlock.rotation = worldBlock.rotation;
                                worldBlock = downgradeBlock;
                            }
                            else
                            {
                                worldBlock.damage = damage;
                            }
                        }

                        GameManager.Instance.World.ChunkClusters[clrIdx].SetBlock(worldPos, worldBlock, false, false);
                        counter++;
                    }
                }
            }

            SendOutput($"Damaging {counter} blocks @ {position} to {BCUtils.GetMaxPos(position, size)}");
            SendOutput("Use bc-undo to revert the changes");
            Reload(modifiedChunks);
        }
        protected override void Process()
        {
            if (!BCUtils.CheckWorld(out var world))
            {
                return;
            }

            if (Options.ContainsKey("undo"))
            {
                SendOutput("Please use the bc-undo command to undo changes");

                return;
            }

            EntityPlayer sender = null;

            if (SenderInfo.RemoteClientInfo != null)
            {
                sender = world.Entities.dict[SenderInfo.RemoteClientInfo.entityId] as EntityPlayer;
            }

            if (Params.Count == 0)
            {
                return;
            }

            var prefab = new Prefab();

            if (!prefab.Load(Params[0]))
            {
                return;
            }

            if (!GetRxyz(prefab, sender, out var r, out var x, out var y, out var z))
            {
                return;
            }

            var pos = Options.ContainsKey("nooffset") ? new Vector3i(x, y, z) : new Vector3i(x, y + prefab.yOffset, z);

            if (Options.ContainsKey("air"))
            {
                prefab.bCopyAirBlocks = true;
            }
            if (Options.ContainsKey("noair"))
            {
                prefab.bCopyAirBlocks = false;
            }

            BlockTranslations(world, prefab, pos);

            //CREATE UNDO
            //create backup of area prefab will insert to
            if (!Options.ContainsKey("noundo"))
            {
                BCUtils.CreateUndo(sender, pos, prefab.size);
            }

            // SPAWN PREFAB
            Log.Out($"{Config.ModPrefix}Spawning prefab {prefab.filename} @ {pos}, size={prefab.size}, rot={r}");
            SendOutput($"Spawning prefab {prefab.filename} @ {pos}, size={prefab.size}, rot={r}");
            if (Options.ContainsKey("sblock") || Options.ContainsKey("editmode") || GameManager.Instance.IsEditMode())
            {
                SendOutput("* with Sleeper Blocks option set");
            }
            else
            {
                SendOutput("* with Sleeper Spawning option set");
            }
            if (Options.ContainsKey("tfill") || Options.ContainsKey("editmode") || GameManager.Instance.IsEditMode())
            {
                SendOutput("* with Terrain Filler option set");
            }
            if (Options.ContainsKey("notrans") || Options.ContainsKey("editmode") || GameManager.Instance.IsEditMode())
            {
                SendOutput("* with No Placeholder Translations option set");
            }
            SendOutput("use bc-undo to revert the changes");

            InsertPrefab(world, prefab, pos);
        }
        protected override void Process()
        {
            if (!BCUtils.CheckWorld())
            {
                return;
            }

            if (Options.ContainsKey("stop"))
            {
                if (_mapVisitor == null)
                {
                    SendOutput("VisitRegion not running.");

                    return;
                }

                if (bcmTask != null)
                {
                    bcmTask.Output  = new { Message = "Visitor was stopped before it completed" };
                    bcmTask.Command = new BCCmd {
                        Command = commandStr
                    };
                    bcmTask.Status     = BCMTaskStatus.Aborted;
                    bcmTask.Completion = DateTime.UtcNow;
                    bcmTask.Duration   = bcmTask.Completion - bcmTask.Timestamp;
                }

                _mapVisitor.Stop();
                _mapVisitor = null;
                SendOutput("VisitRegion stopped.");

                return;
            }

            if (_mapVisitor != null && _mapVisitor.IsRunning())
            {
                SendOutput($"VisitRegion already running ({completePercent}%). You can stop it with \"bc-visitregion /stop\".");

                return;
            }

            if (Params.Count < 2)
            {
                SendOutput("VisitRegion isn't running. Provide some co-ords to explore some regions");

                return;
            }

            if (!int.TryParse(Params[0], out var x))
            {
                SendOutput("The given x1 coordinate is not a valid integer");

                return;
            }
            if (!int.TryParse(Params[1], out var z))
            {
                SendOutput("The given z1 coordinate is not a valid integer");

                return;
            }

            if (x > 19 || x < -20)
            {
                SendOutput("Note: The given x1 coordinate is beyond the recommended range (-20 to 19)");
            }

            if (z > 19 || z < -20)
            {
                SendOutput("Note: The given z1 coordinate is beyond the recommended range (-20 to 19)");
            }

            completePercent = 0;
            var x2 = x;
            var z2 = z;

            switch (Params.Count)
            {
            case 2:
                SendOutput($"Sending a visitor to region {x},{z}");
                break;

            case 3:
                if (!int.TryParse(Params[2], out var r))
                {
                    SendOutput("The given radius is not a valid integer");
                }

                if (r < 0)
                {
                    SendOutput("The given radius can't be less than 0, the recommended range is 0 to 20");

                    return;
                }

                if (r > 20)
                {
                    SendOutput("Note: The given radius is beyond the recommended range (0 to 20)");
                }

                x  -= r;
                z  -= r;
                x2 += r;
                z2 += r;
                SendOutput($"Sending a visitor to regions between {x},{z} and {x2},{z2}");
                break;

            case 4:
                if (!int.TryParse(Params[2], out x2))
                {
                    SendOutput("The given x2 coordinate is not a valid integer");
                }
                else if (!int.TryParse(Params[3], out z2))
                {
                    SendOutput("The given z2 coordinate is not a valid integer");
                }

                if (x2 > 19 || x2 < -20)
                {
                    SendOutput("Note: The given x2 coordinate is beyond the recommended range (-20 to 19)");
                }

                if (z2 > 19 || z2 < -20)
                {
                    SendOutput("Note: The given z2 coordinate is beyond the recommended range (-20 to 19)");
                }

                SendOutput($"Sending a visitor to regions between {x},{z} and {x2},{z2}");
                break;

            default:
                SendOutput("Invalid param count");
                SendOutput(GetHelp());
                break;
            }

            _lastSender = SenderInfo.RemoteClientInfo;

            commandStr = "";
            if (Params.Count > 0 || Options.Count > 0)
            {
                commandStr += string.Join(" ", new[] { GetCommands()[0] }.Concat(
                                              Options.Count > 0
            ? Params.Concat(Options.Select(o => "/" + o.Key + (o.Value != null ? "=" + o.Value : "")))
            : Params
                                              ).ToArray());
            }

            _mapVisitor = new MapVisitor(new Vector3i(x * 512, 0, z * 512), new Vector3i(x2 * 512 + 511, 0, z2 * 512 + 511));

            _hash = _mapVisitor.GetHashCode();
            BCTask.AddTask("MapVisitor", _mapVisitor.GetHashCode(), null);
            bcmTask = BCTask.GetTask("MapVisitor", _hash);
            if (bcmTask != null)
            {
                bcmTask.Command = new BCCmd {
                    Command = commandStr
                };
                bcmTask.Output = new { Count = 0, Total = 0, Perc = 0.00, Time = 0.00 };
            }

            _mapVisitor.OnVisitChunk   += ReportStatus;
            _mapVisitor.OnVisitChunk   += GetMapColors;
            _mapVisitor.OnVisitMapDone += ReportCompletion;
            _mapVisitor.Start();
        }
Exemple #28
0
        private static void SetMeta(int metaIdx, Vector3i position, Vector3i size, Dictionary <long, Chunk> modifiedChunks)
        {
            if (!byte.TryParse(Options["meta"], out var meta))
            {
                SendOutput($"Unable to parse meta '{Options["meta"]}'");

                return;
            }

            const int clrIdx  = 0;
            var       counter = 0;

            for (var j = 0; j < size.y; j++)
            {
                for (var i = 0; i < size.x; i++)
                {
                    for (var k = 0; k < size.z; k++)
                    {
                        var worldPos   = new Vector3i(i + position.x, j + position.y, k + position.z);
                        var worldBlock = GameManager.Instance.World.GetBlock(clrIdx, worldPos);
                        if (worldBlock.Equals(BlockValue.Air) || worldBlock.ischild)
                        {
                            continue;
                        }

                        switch (metaIdx)
                        {
                        case 1:
                            worldBlock.meta = meta;
                            break;

                        case 2:
                            worldBlock.meta2 = meta;
                            break;

                        case 3:
                            worldBlock.meta3 = meta;
                            break;

                        default:
                            return;
                        }

                        GameManager.Instance.World.ChunkClusters[clrIdx].SetBlock(worldPos, worldBlock, false, false);
                        counter++;
                    }
                }
            }

            SendOutput($"Setting meta{metaIdx} on '{counter}' blocks @ {position} to {BCUtils.GetMaxPos(position, size)}");
            SendOutput("Use bc-undo to revert the changes");
            Reload(modifiedChunks);
        }
Exemple #29
0
        protected override void Process()
        {
            if (!BCUtils.CheckWorld())
            {
                return;
            }

            if (Options.ContainsKey("filters"))
            {
                Filters();

                return;
            }

            if (Options.ContainsKey("index"))
            {
                Indexed();

                return;
            }

            if (Params.Count > 1)
            {
                SendOutput("Wrong number of arguments");
                SendOutput(Config.GetHelp(GetType().Name));

                return;
            }

            if (Params.Count == 1)
            {
                //SPECIFIC PLAYER
                if (!PlayerStore.GetId(Params[0], out var steamId, "CON"))
                {
                    return;
                }

                var player = new BCMPlayer(PlayerData.PlayerInfo(steamId), Options, GetFilters(BCMGameObject.GOTypes.Players));
                if (Options.ContainsKey("min"))
                {
                    SendJson(new List <List <object> >
                    {
                        player.Data().Select(d => d.Value).ToList()
                    });
                }
                else
                {
                    SendJson(player.Data());
                }
            }
            else
            {
                //ALL PLAYERS
                var data = new List <object>();
                foreach (var player in PlayerStore.GetAll(Options).Select(s => new BCMPlayer(PlayerData.PlayerInfo(s), Options, GetFilters(BCMGameObject.GOTypes.Players))))
                {
                    if (Options.ContainsKey("min"))
                    {
                        data.Add(player.Data().Select(d => d.Value).ToList());
                    }
                    else
                    {
                        data.Add(player.Data());
                    }
                }

                SendJson(data);
            }
        }
Exemple #30
0
        private static void SetPaintFace(Vector3i position, Vector3i size, Dictionary <long, Chunk> modifiedChunks)
        {
            byte texture = 0;

            if (Options.ContainsKey("t"))
            {
                if (!byte.TryParse(Options["t"], out texture))
                {
                    SendOutput("Unable to parse texture value");

                    return;
                }
                if (BlockTextureData.list[texture] == null)
                {
                    SendOutput($"Unknown texture index {texture}");

                    return;
                }
            }
            uint setFace = 0;

            if (Options.ContainsKey("face"))
            {
                if (!uint.TryParse(Options["face"], out setFace))
                {
                    SendOutput("Unable to parse face value");

                    return;
                }
            }
            if (setFace > 5)
            {
                SendOutput("Face must be between 0 and 5");

                return;
            }

            const int clrIdx  = 0;
            var       counter = 0;

            for (var j = 0; j < size.y; j++)
            {
                for (var i = 0; i < size.x; i++)
                {
                    for (var k = 0; k < size.z; k++)
                    {
                        var worldPos   = new Vector3i(i + position.x, j + position.y, k + position.z);
                        var worldBlock = GameManager.Instance.World.GetBlock(clrIdx, worldPos);
                        if (worldBlock.Equals(BlockValue.Air))
                        {
                            continue;
                        }

                        GameManager.Instance.World.ChunkClusters[clrIdx].SetBlockFaceTexture(worldPos, (BlockFace)setFace, texture);
                        counter++;
                    }
                }
            }

            SendOutput($"Painting {counter} blocks on face '{((BlockFace)setFace).ToString()}' with texture '{BlockTextureData.GetDataByTextureID(texture)?.Name}' @ {position} to {BCUtils.GetMaxPos(position, size)}");
            SendOutput("Use bc-undo to revert the changes");
            Reload(modifiedChunks);
        }