Esempio n. 1
0
        public static void CheckStackQuality(Console __instance)
        {
            __instance.AddString("CheckStackQuality");
            if (ObjectDB.instance == null)
            {
                __instance.AddString("> ObjectDB is null");
                return;
            }

            var count = 0;

            foreach (var itemObject in ObjectDB.instance.m_items)
            {
                var itemDrop = itemObject.GetComponent <ItemDrop>();
                if (itemDrop == null)
                {
                    continue;
                }

                var itemData = itemDrop.m_itemData;

                if (itemData.m_shared.m_maxStackSize > 1 && itemData.m_shared.m_maxQuality > 1)
                {
                    count++;
                    __instance.AddString($"> {itemDrop.name}");
                }
            }

            if (count == 0)
            {
                __instance.AddString("> (none)");
            }
        }
Esempio n. 2
0
 private static void Postfix(ref Console __instance)
 {
     __instance.AddString("ValheimPlus [" + ValheimPlusPlugin.version + "] is loaded.");
     if (!ValheimPlusPlugin.isUpToDate && ValheimPlusPlugin.newestVersion != "Unknown")
     {
         __instance.AddString("ValheimPlus [" + ValheimPlusPlugin.version + "] is outdated, version [" + ValheimPlusPlugin.newestVersion + "] is available.");
         __instance.AddString("Please visit " + ValheimPlusPlugin.Repository + ".");
     }
     else
     {
         __instance.AddString("ValheimPlus [" + ValheimPlusPlugin.version + "] is up to date.");
     }
     __instance.AddString("");
 }
        private static bool Pre_Console_InputText(Console __instance)
        {
            if (!Player.m_localPlayer)
            {
                return(true);
            }
            string text = __instance.m_input.text;

            if (text == "spoilers")
            {
                var toRemove = new List <string>()
                {
                    "$item_chest_pcuirass",
                    "$item_legs_pgreaves",
                    "$item_atgeir_blackmetal",
                    "$item_axe_blackmetal",
                    "$item_cape_lox",
                    "$item_knife_blackmetal",
                    "$item_mace_needle",
                    "$item_mace_silver",
                    "$item_shield_blackmetal",
                    "$item_shield_blackmetal_tower",
                    "$item_shield_serpentscale",
                    "$item_sword_blackmetal"
                };
                int removed = Player.m_localPlayer.m_knownMaterial.RemoveWhere(i => toRemove.Contains(i));
                __instance.AddString($"Removed {removed} known items.");
                if (removed > 0)
                {
                    PlayerDataSyncManager.SendKnown(Player.m_localPlayer);
                }
                return(false);
            }
            return(true);
        }
Esempio n. 4
0
        public static void InjectCommandExecution(Console instance)
        {
            var temp = instance.m_input.text;

            // if help is issued, add list of our commands here
            if (string.Equals(temp.Trim(), "help", StringComparison.InvariantCultureIgnoreCase))
            {
                instance.AddString("");
                instance.AddString("Veilheim console commands:");
                foreach (var cmd in BaseConsoleCommand.consoleCommandInstances)
                {
                    instance.AddString(cmd.HelpText);
                }
            }

            if (!BaseConsoleCommand.TryExecuteCommand(ref temp))
            {
                // Output something if command could not execute? not at this time.
            }
        }
    void OnGoTo(Console console, params string[] args)
    {
        string output;

        if (args.Length != 3)
        {
            console.AddString("Error: /goto x,y,z");
            return;
        }

        if (player)
        {
            output = "Teleport to " + args[1] + ", " + args[2];
            console.AddString(output);

            float newX = float.Parse(args[1]);
            float newZ = float.Parse(args[2]);

            Vector3 position = new Vector3(newX, 0f, newZ);
            position.y = Terrain.activeTerrain.SampleHeight(position) + Terrain.activeTerrain.GetPosition().y + 1.0f;
            player.transform.position = position;
        }
    }
Esempio n. 6
0
        public static void SpawnMagicItemWithEffect(Console __instance, string[] args)
        {
            if (args.Length < 3)
            {
                EpicLoot.LogError("Specify effect and item name");
                return;
            }

            if (Player.m_localPlayer == null)
            {
                return;
            }

            var effectArg         = args[1];
            var itemPrefabNameArg = args[2];

            __instance.AddString($"magicitem - {itemPrefabNameArg} with effect: {effectArg}");

            var magicItemEffectDef = MagicItemEffectDefinitions.Get(effectArg);

            if (magicItemEffectDef == null)
            {
                __instance.AddString($"> Could not find effect: {effectArg}");
                return;
            }

            var itemPrefab = ObjectDB.instance.GetItemPrefab(itemPrefabNameArg);

            if (itemPrefab == null)
            {
                __instance.AddString($"> Could not find item: {itemPrefabNameArg}");
                return;
            }

            var fromItemData = itemPrefab.GetComponent <ItemDrop>().m_itemData;

            if (!EpicLoot.CanBeMagicItem(fromItemData))
            {
                __instance.AddString($"> Can't be magic item: {itemPrefabNameArg}");
                return;
            }

            var effectRequirements = magicItemEffectDef.Requirements;
            var itemRarity         = effectRequirements.AllowedRarities.Count == 0 ? ItemRarity.Legendary : effectRequirements.AllowedRarities.First();
            var rarityTable        = GetRarityTable(itemRarity.ToString());
            var loot = new LootTable
            {
                Object = "Console",
                Drops  = new[] { new[] { 1, 1 } },
                Loot   = new[]
                {
                    new LootDrop
                    {
                        Item   = itemPrefab.name,
                        Rarity = rarityTable
                    }
                }
            };

            var randomOffset = UnityEngine.Random.insideUnitSphere;
            var dropPoint    = Player.m_localPlayer.transform.position + Player.m_localPlayer.transform.forward * 3 + Vector3.up * 1.5f + randomOffset;

            // TODO add better hook for desired effect - currently effect will be discarded on next game load
            // if effect was added when magicItem had maximum of available effect
            // however still good for debug
            LootRoller.CheatForceMagicEffect = true;
            LootRoller.ForcedMagicEffect     = effectArg;
            LootRoller.RollLootTableAndSpawnObjects(loot, 1, loot.Object, dropPoint);
            LootRoller.CheatForceMagicEffect = false;
            LootRoller.ForcedMagicEffect     = string.Empty;
        }
Esempio n. 7
0
        public static void MagicItem(Console __instance, string[] args)
        {
            var rarityArg   = args.Length >= 2 ? args[1] : "random";
            var itemArg     = args.Length >= 3 ? args[2] : "random";
            var count       = args.Length >= 4 ? int.Parse(args[3]) : 1;
            var effectCount = args.Length >= 5 ? int.Parse(args[4]) : -1;

            __instance.AddString($"magicitem - rarity:{rarityArg}, item:{itemArg}, count:{count}");

            var allItemNames = ObjectDB.instance.m_items
                               .Where(x => EpicLoot.CanBeMagicItem(x.GetComponent <ItemDrop>().m_itemData))
                               .Where(x => x.name != "HelmetDverger" && x.name != "BeltStrength" && x.name != "Wishbone")
                               .Select(x => x.name)
                               .ToList();

            if (Player.m_localPlayer == null)
            {
                return;
            }

            LootRoller.CheatEffectCount = effectCount;
            for (var i = 0; i < count; i++)
            {
                int[] rarityTable = GetRarityTable(rarityArg);

                var item = itemArg;
                if (item == "random")
                {
                    var weightedRandomTable = new WeightedRandomCollection <string>(_random, allItemNames, x => 1);
                    item = weightedRandomTable.Roll();
                }

                if (ObjectDB.instance.GetItemPrefab(item) == null)
                {
                    __instance.AddString($"> Could not find item: {item}");
                    break;
                }

                __instance.AddString($">  {i + 1} - rarity: [{string.Join(", ", rarityTable)}], item: {item}");

                var loot = new LootTable()
                {
                    Object = "Console",
                    Drops  = new[] { new[] { 1, 1 } },
                    Loot   = new[]
                    {
                        new LootDrop()
                        {
                            Item   = item,
                            Rarity = rarityTable,
                            Weight = 1
                        }
                    }
                };

                var randomOffset = UnityEngine.Random.insideUnitSphere;
                var dropPoint    = Player.m_localPlayer.transform.position + Player.m_localPlayer.transform.forward * 3 + Vector3.up * 1.5f + randomOffset;
                LootRoller.RollLootTableAndSpawnObjects(loot, 1, loot.Object, dropPoint);
            }
            LootRoller.CheatEffectCount = -1;
        }
Esempio n. 8
0
 private static void ToggleAlwaysDrop(Console __instance)
 {
     EpicLoot.AlwaysDropCheat = !EpicLoot.AlwaysDropCheat;
     __instance.AddString($"> Always Drop: {EpicLoot.AlwaysDropCheat}");
 }
Esempio n. 9
0
        public static bool Prefix(Console __instance)
        {
            var input = __instance.m_input.text;
            var args  = input.Split(' ');

            if (args.Length == 0)
            {
                return(true);
            }

            var player = Player.m_localPlayer;

            var command = args[0];

            if (CheatCommand(command, "magicitem", "mi"))
            {
                MagicItem(__instance, args);
            }
            else if (CheatCommand(command, "magicitemwitheffect", "mieffect"))
            {
                SpawnMagicItemWithEffect(__instance, args);
            }
            else if (Command(command, "checkstackquality"))
            {
                CheckStackQuality(__instance);
            }
            else if (CheatCommand(command, "magicmats"))
            {
                SpawnMagicCraftingMaterials();
            }
            else if (CheatCommand(command, "alwaysdrop"))
            {
                ToggleAlwaysDrop(__instance);
            }
            else if (CheatCommand(command, "cheatgating"))
            {
                LootRoller.CheatDisableGating = !LootRoller.CheatDisableGating;
                __instance.AddString($"> Disable gating for magic item drops: {LootRoller.CheatDisableGating}");
            }
            else if (CheatCommand(command, "testtreasuremap", "testtm"))
            {
                TestTreasureMap(args);
            }
            else if (Command(command, "resettreasuremap", "resettm"))
            {
                var saveData = player.GetAdventureSaveData();
                saveData.TreasureMaps.Clear();
                saveData.NumberOfTreasureMapsOrBountiesStarted = 0;
                player.SaveAdventureSaveData();
            }
            else if (Command(command, "debugtreasuremap", "debugtm"))
            {
                Minimap_Patch.DebugMode = !Minimap_Patch.DebugMode;
                __instance.AddString($"> Treasure Map Debug Mode: {Minimap_Patch.DebugMode}");
            }
            else if (Command(command, "resetbounties"))
            {
                var saveData = player.GetAdventureSaveData();
                saveData.Bounties.Clear();
                player.SaveAdventureSaveData();
            }
            else if (Command(command, "testbountynames"))
            {
                var random = new Random();
                var count  = (args.Length >= 2) ? int.Parse(args[1]) : 10;
                for (var i = 0; i < count; ++i)
                {
                    var name = BountiesAdventureFeature.GenerateTargetName(random);
                    __instance.AddString(name);
                }
            }
            else if (Command(command, "resetadventure"))
            {
                var adventureComponent = player.GetComponent <AdventureComponent>();
                adventureComponent.SaveData = new AdventureSaveDataList();
                player.SaveAdventureSaveData();
            }
            else if (Command(command, "bounties"))
            {
                var interval          = (args.Length >= 2) ? int.Parse(args[1]) : AdventureDataManager.Bounties.GetCurrentInterval();
                var availableBounties = AdventureDataManager.Bounties.GetAvailableBounties(interval, false);
                BountiesAdventureFeature.PrintBounties($"Bounties for Interval {interval}:", availableBounties);
            }
            else if (Command(command, "playerbounties"))
            {
                var availableBounties = player.GetAdventureSaveData().Bounties;
                BountiesAdventureFeature.PrintBounties($"Player Bounties:", availableBounties);
            }
            else if (CheatCommand(command, "timescale", "ts"))
            {
                var timeScale = (args.Length >= 2) ? float.Parse(args[1]) : 1;
                Time.timeScale = timeScale;
            }
            else if (CheatCommand(command, "gotomerchant", "gotom"))
            {
                if (ZoneSystem.instance.FindClosestLocation("Vendor_BlackForest", player.transform.position, out var location))
                {
                    player.TeleportTo(location.m_position + Vector3.right * 5, player.transform.rotation, true);
                }
            }
            else if (Command(command, "globalkeys"))
            {
                if (ZoneSystem.instance != null)
                {
                    __instance.AddString("> Print Global Keys:");
                    foreach (var globalKey in ZoneSystem.instance.GetGlobalKeys())
                    {
                        __instance.AddString("> " + globalKey);
                    }
                }
            }

            return(true);
        }
Esempio n. 10
0
        public static void MagicItem(Console __instance, string[] args)
        {
            var rarityArg = args.Length >= 2 ? args[1] : "random";
            var itemArg   = args.Length >= 3 ? args[2] : "random";
            var count     = args.Length >= 4 ? int.Parse(args[3]) : 1;

            __instance.AddString($"magicitem - rarity:{rarityArg}, item:{itemArg}, count:{count}");

            var items        = new List <GameObject>();
            var allItemNames = ObjectDB.instance.m_items
                               .Where(x => EpicLoot.CanBeMagicItem(x.GetComponent <ItemDrop>().m_itemData))
                               .Select(x => x.name)
                               .ToList();

            if (Player.m_localPlayer == null)
            {
                return;
            }

            for (var i = 0; i < count; i++)
            {
                var rarityTable = new[] { 1, 1, 1, 1 };
                switch (rarityArg.ToLowerInvariant())
                {
                case "magic":
                    rarityTable = new[] { 1, 0, 0, 0, };
                    break;

                case "rare":
                    rarityTable = new[] { 0, 1, 0, 0, };
                    break;

                case "epic":
                    rarityTable = new[] { 0, 0, 1, 0, };
                    break;

                case "legendary":
                    rarityTable = new[] { 0, 0, 0, 1, };
                    break;
                }

                var item = itemArg;
                if (item == "random")
                {
                    var weightedRandomTable = new WeightedRandomCollection <string>(_random, allItemNames, x => 1);
                    item = weightedRandomTable.Roll();
                }

                if (ObjectDB.instance.GetItemPrefab(item) == null)
                {
                    __instance.AddString($"> Could not find item: {item}");
                    break;
                }

                __instance.AddString($"  {i + 1} - rarity: [{string.Join(", ", rarityTable)}], item: {item}");

                var loot = new LootTable()
                {
                    Object = "Console",
                    Drops  = new[] { new[] { 1, 1 } },
                    Loot   = new[]
                    {
                        new LootDrop()
                        {
                            Item   = item,
                            Rarity = rarityTable
                        }
                    }
                };

                var randomOffset = UnityEngine.Random.insideUnitSphere;
                var dropPoint    = Player.m_localPlayer.transform.position + Player.m_localPlayer.transform.forward * 3 + Vector3.up * 1.5f + randomOffset;
                items.AddRange(LootRoller.RollLootTableAndSpawnObjects(loot, loot.Object, dropPoint));
            }
        }
Esempio n. 11
0
            public static bool Prefix()
            {
                Console console = Console.instance;
                var     input   = console.m_input.text;

                if (!input.StartsWith("call", true, CultureInfo.InvariantCulture))
                {
                    return(true);
                }
                var parts = CommandParser.Parse(input).ToArray();

                if (parts.Length < 3)
                {
                    console.AddString(
                        "call command requires at least 3 arguments: call <class> <methodName> [arg1] [arg2]");
                    return(false);
                }
                console.AddString(input);
                Type targetClass = typeof(Console).Assembly.GetTypes()
                                   .FirstOrDefault(t => t.Name.Equals(parts[1].Text, StringComparison.InvariantCultureIgnoreCase));

                if (targetClass == null)
                {
                    console.AddString($"Could not find class with name '{parts[1]}'");
                    return(false);
                }
                MethodInfo method = targetClass.GetMethods(BindingFlags.Public |
                                                           BindingFlags.Static |
                                                           BindingFlags.NonPublic |
                                                           BindingFlags.Instance |
                                                           BindingFlags.InvokeMethod)
                                    .FirstOrDefault(m => m.Name.Equals(parts[2].Text, StringComparison.InvariantCultureIgnoreCase));

                if (method == null)
                {
                    console.AddString($"Could not find method '{parts[2].Text}' on class '{targetClass.FullName}'");
                    return(false);
                }
                // Parameters must match target method.
                var methodParams = method.GetParameters();

                if (methodParams.Length != parts.Length - 3) // -3 for command, class and method name args
                {
                    console.AddString(
                        $"Command does not match method parameters. Expected parameter types: {string.Join(", ", methodParams.Select(p => p.ParameterType.Name))}");
                    return(false);
                }
                var methodArgsToSupply = new object[methodParams.Length];

                for (var i = 0; i < methodParams.Length; i++)
                {
                    var  argText   = parts[i + 3].Text;
                    Type paramType = methodParams[i].ParameterType;
                    try
                    {
                        methodArgsToSupply[i] = TypeDescriptor.GetConverter(paramType).ConvertFrom(argText);
                    }
                    catch (NotSupportedException)
                    {
                        console.AddString(
                            $"Cannot convert argument {i + 1} '{argText}' to type of '{paramType.FullName}'");
                        return(false);
                    }
                }
                // Handle instance method calls by getting singleton instance (if possible).
                object targetInstance = null;

                if (!method.IsStatic)
                {
                    targetInstance = targetClass == typeof(Player)
                        ? Player.m_localPlayer
                        : targetClass.GetField("m_instance", BindingFlags.Static | BindingFlags.NonPublic)
                                     ?.GetValue(null);
                    if (targetInstance == null)
                    {
                        console.AddString(
                            $"Could not call method '{method.Name}' because it's an instance method and no static instance field is defined on it");
                        return(false);
                    }
                }

                // Call method, print result.
                var result = method.Invoke(targetInstance, methodArgsToSupply);

                if (result != null)
                {
                    console.AddString(string.Join(", ", ArrayUtils.ToStringArray(result)));
                }
                return(false);
            }