コード例 #1
0
        internal void AddDefaultCommands()
        {
            _LoggerSubscriber = (logger, loglevel, indent, str) => {
                PrintLine(logger.String(loglevel, str, indent: indent), color: _LoggerColors[loglevel]);
            };


            AddCommand("!!", (args, histindex) => {
                if (histindex - 1 < 0)
                {
                    throw new Exception("Can't run previous command (history is empty).");
                }
                return(History.Execute(histindex.Value - 1));
            });

            AddCommand("!'", (args, histindex) => {
                if (histindex - 1 < 0)
                {
                    throw new Exception("Can't run previous command (history is empty).");
                }
                return(History.Entries[histindex.Value - 1]);
            });

            AddCommand("echo", (args) => {
                return(string.Join(" ", args.ToArray()));
            }).WithSubCommand("hello", (args) => {
                return("Hello, world!\nHello, world!\nHello, world!\nHello, world!\nHello, world!\nHello, world!");
            });

            AddGroup("debug")
            .WithSubCommand("spawn-rand-chest", (args) => {
                var chest = GameManager.Instance.RewardManager.SpawnTotallyRandomChest(GameManager.Instance.PrimaryPlayer.CurrentRoom.GetRandomAvailableCellDumb());
                return(chest.name);
            })
            .WithSubCommand("force-dual-wield", (args) => {
                if (args.Count < 1)
                {
                    throw new Exception("At least 1 argument required.");
                }
                var partner_id  = int.Parse(args[0]);
                var player      = GameManager.Instance.PrimaryPlayer;
                var gun         = player.inventory.CurrentGun;
                var partner_gun = PickupObjectDatabase.GetById(partner_id) as Gun;
                player.inventory.AddGunToInventory(partner_gun);
                var forcer          = gun.gameObject.AddComponent <DualWieldForcer>();
                forcer.Gun          = gun;
                forcer.PartnerGunID = partner_gun.PickupObjectId;
                forcer.TargetPlayer = player;
                return("Done");
            })
            .WithSubCommand("unexclude-all-items", (args) => {
                foreach (var ent in PickupObjectDatabase.Instance.Objects)
                {
                    if (ent == null)
                    {
                        continue;
                    }
                    ent.quality = PickupObject.ItemQuality.SPECIAL;
                }
                return("Done");
            })
            .WithSubCommand("activate-all-synergies", (args) => {
                foreach (var ent in GameManager.Instance.SynergyManager.synergies)
                {
                    if (ent == null)
                    {
                        continue;
                    }
                    ent.ActivationStatus = SynergyEntry.SynergyActivation.ACTIVE;
                }
                return("Done");
            })
            .WithSubCommand("character", (args) => {
                if (args.Count < 1)
                {
                    throw new Exception("At least 1 argument required.");
                }
                StartCoroutine(_ChangeCharacter(args[0], args.Count > 1));
                return($"Changed character to {args[0]}");
            })
            .WithSubCommand("parser-bounds-test", (args) => {
                var text           = "echo Hello! \"Hello world!\" This\\ is\\ great \"It\"works\"with\"\\ wacky\" stuff\" \\[\\] \"\\[\\]\" [e[echo c][echo h][echo [echo \"o\"]] \"hel\"[echo lo][echo !]]";
                CurrentCommandText = text;
                return(null);
            })
            .WithSubCommand("giveid", (args) => {
                if (args.Count < 1)
                {
                    throw new Exception("Exactly 1 argument required.");
                }
                var pickup_obj = PickupObjectDatabase.Instance.InternalGetById(int.Parse(args[0]));

                if (pickup_obj == null)
                {
                    return("Item ID {args[0]} doesn't exist!");
                }

                LootEngine.TryGivePrefabToPlayer(pickup_obj.gameObject, GameManager.Instance.PrimaryPlayer, true);
                return(pickup_obj.EncounterNameOrDisplayName);
            });

            AddGroup("pool")
            .WithSubGroup(
                new Group("items")
                .WithSubCommand("idof", (args) => {
                if (args.Count < 1)
                {
                    throw new Exception("Exactly 1 argument required (numeric ID).");
                }
                var id = int.Parse(args[0]);
                foreach (var pair in ETGMod.Items.Pairs)
                {
                    if (pair.Value.PickupObjectId == id)
                    {
                        return(pair.Key);
                    }
                }
                return("Entry not found.");
            })
                .WithSubCommand("nameof", (args) => {
                if (args.Count < 1)
                {
                    throw new Exception("Exactly 1 argument required (ID).");
                }
                var id = args[0];
                foreach (var pair in ETGMod.Items.Pairs)
                {
                    if (pair.Key == id)
                    {
                        return(_GetPickupObjectName(pair.Value));
                    }
                }
                return("Entry not found.");
            })
                .WithSubCommand("numericof", (args) => {
                if (args.Count < 1)
                {
                    throw new Exception("Exactly 1 argument required (ID).");
                }
                var id = args[0];
                foreach (var pair in ETGMod.Items.Pairs)
                {
                    if (pair.Key == id)
                    {
                        return(pair.Value.PickupObjectId.ToString());
                    }
                }
                return("Entry not found.");
            })
                .WithSubCommand("list", (args) => {
                var s     = new StringBuilder();
                var pairs = new List <KeyValuePair <string, PickupObject> >();
                foreach (var pair in ETGMod.Items.Pairs)
                {
                    pairs.Add(pair);
                }
                foreach (var pair in pairs)
                {
                    if (_GetPickupObjectName(pair.Value) == "NO NAME")
                    {
                        s.AppendLine($"[{pair.Key}] {_GetPickupObjectName(pair.Value)}");
                    }
                }
                pairs.Sort((x, y) => string.Compare(_GetPickupObjectName(x.Value), _GetPickupObjectName(y.Value)));
                foreach (var pair in pairs)
                {
                    if (_GetPickupObjectName(pair.Value) == "NO NAME")
                    {
                        continue;
                    }
                    s.AppendLine($"[{pair.Key}] {_GetPickupObjectName(pair.Value)}");
                }
                return(s.ToString());
            })
                .WithSubCommand("random", (args) => {
                return(ETGMod.Items.RandomKey);
            })
                );

            AddCommand("summon", (args) => {
                var player = GameManager.Instance.PrimaryPlayer;
                if (player == null)
                {
                    throw new Exception("No player");
                }
                var cell   = player.CurrentRoom.GetRandomAvailableCellDumb();
                var entity = AIActor.Spawn(ETGMod.Entities[args[0]], cell, player.CurrentRoom, true, AIActor.AwakenAnimationType.Default, true);

                if (ETGMod.Entities.GetType(args[0]) == ETGMod.EntityType.Friendly)
                {
                    entity.CompanionOwner    = player;
                    entity.CompanionSettings = new ActorCompanionSettings();
                    entity.CanTargetPlayers  = false;
                    var companion            = entity.GetComponent <CompanionController>();
                    if (companion != null)
                    {
                        companion.Initialize(player);
                        if (companion.specRigidbody)
                        {
                            PhysicsEngine.Instance.RegisterOverlappingGhostCollisionExceptions(companion.specRigidbody, null, false);
                        }
                    }
                }

                var name = args[0];
                if (entity.encounterTrackable?.journalData?.PrimaryDisplayName != null)
                {
                    name = StringTableManager.GetEnemiesString(entity.encounterTrackable?.journalData?.PrimaryDisplayName);
                }

                return(name);
            });

            AddCommand("listmods", (args) => {
                var s = new StringBuilder();

                s.AppendLine("Loaded mods:");
                foreach (var mod in ETGMod.ModLoader.LoadedMods)
                {
                    _GetModInfo(s, mod);
                }
                return(s.ToString());
            });

            AddCommand("lua", (args) => {
                LuaMode = true;
                return("[entered lua mode]");
            });

            AddCommand("give", (args) => {
                LootEngine.TryGivePrefabToPlayer(ETGMod.Items[args[0]].gameObject, GameManager.Instance.PrimaryPlayer, true);
                return(args[0]);
            });

            AddGroup("dump")
            .WithSubCommand("synergy_chest", (args) => {
                System.Console.WriteLine(ObjectDumper.Dump(GameManager.Instance.RewardManager.Synergy_Chest, depth: 10));
                return("Dumped to log");
            })
            .WithSubCommand("synergies", (args) => {
                var id = 0;
                foreach (var synergy in GameManager.Instance.SynergyManager.synergies)
                {
                    if (synergy.NameKey != null)
                    {
                        var name = StringTableManager.GetSynergyString(synergy.NameKey);
                        System.Console.WriteLine($"== SYNERGY ID {id} NAME {name} ==");
                    }
                    else
                    {
                        System.Console.WriteLine($"== SYNERGY ID {id} ==");
                    }
                    System.Console.WriteLine($"  ACTIVATION STATUS: {synergy.ActivationStatus}");
                    System.Console.WriteLine($"  # OF OBJECTS REQUIRED: {synergy.NumberObjectsRequired}");
                    System.Console.WriteLine($"  ACTIVE WHEN GUN UNEQUIPPED?: {synergy.ActiveWhenGunUnequipped}");
                    System.Console.WriteLine($"  REQUIRES AT LEAST ONE GUN AND ONE ITEM?: {synergy.RequiresAtLeastOneGunAndOneItem}");
                    System.Console.WriteLine($"  MANDATORY GUNS:");
                    foreach (var itemid in synergy.MandatoryGunIDs)
                    {
                        System.Console.WriteLine($"  - {_GetPickupObjectName(PickupObjectDatabase.GetById(itemid))}");
                    }
                    System.Console.WriteLine($"  OPTIONAL GUNS:");
                    foreach (var itemid in synergy.OptionalGunIDs)
                    {
                        System.Console.WriteLine($"  - {_GetPickupObjectName(PickupObjectDatabase.GetById(itemid))}");
                    }
                    System.Console.WriteLine($"  MANDATORY ITEMS:");
                    foreach (var itemid in synergy.MandatoryItemIDs)
                    {
                        System.Console.WriteLine($"  - {_GetPickupObjectName(PickupObjectDatabase.GetById(itemid))}");
                    }
                    System.Console.WriteLine($"  OPTIONAL ITEMS:");
                    foreach (var itemid in synergy.OptionalItemIDs)
                    {
                        System.Console.WriteLine($"  - {_GetPickupObjectName(PickupObjectDatabase.GetById(itemid))}");
                    }
                    System.Console.WriteLine($"  BONUS SYNERGIES:");
                    foreach (var bonus in synergy.bonusSynergies)
                    {
                        System.Console.WriteLine($"  - {bonus}");
                    }
                    System.Console.WriteLine($"  STAT MODIFIERS:");
                    foreach (var statmod in synergy.statModifiers)
                    {
                        System.Console.WriteLine($"  - STAT: {statmod.statToBoost}");
                        System.Console.WriteLine($"    AMOUNT: {statmod.amount}");
                        System.Console.WriteLine($"    MODIFY TYPE: {statmod.modifyType}");
                        System.Console.WriteLine($"    PERSISTS ON COOP DEATH?: {statmod.PersistsOnCoopDeath}");
                        System.Console.WriteLine($"    IGNORED FOR SAVE DATA?: {statmod.ignoredForSaveData}");
                    }
                    id++;
                }
                return("Dumped to log");
            })
            .WithSubCommand("items", (args) => {
                var b  = new StringBuilder();
                var db = PickupObjectDatabase.Instance.Objects;
                for (int i = 0; i < db.Count; i++)
                {
                    PickupObject obj  = null;
                    string nameprefix = "";
                    string name       = null;
                    try {
                        obj = db[i];
                    } catch {
                        name = "[ERROR: failed getting object by index]";
                    }
                    if (obj != null)
                    {
                        try {
                            var displayname = obj.encounterTrackable.journalData.PrimaryDisplayName;
                            name            = StringTableManager.ItemTable[displayname].GetWeightedString();
                        } catch {
                            name = "[ERROR: failed getting ammonomicon name]";
                        }
                        if (name == null)
                        {
                            try {
                                name = obj.EncounterNameOrDisplayName;
                            } catch {
                                name = "[ERROR: failed getting encounter or display name]";
                            }
                        }
                    }
                    if (name == null && obj != null)
                    {
                        name = "[NULL NAME (but object is not null)]";
                    }

                    name = $"{nameprefix} {name}";

                    if (name != null)
                    {
                        b.AppendLine($"{i}: {name}");
                        _Logger.Info($"{i}: {name}");
                    }
                }
                return(b.ToString());
            });

            AddGroup("log")
            .WithSubCommand("sub", (args) => {
                if (_Subscribed)
                {
                    return("Already subscribed.");
                }
                Logger.Subscribe(_LoggerSubscriber);
                _Subscribed = true;
                return("Done.");
            })
            .WithSubCommand("unsub", (args) => {
                if (!_Subscribed)
                {
                    return("Not subscribed yet.");
                }
                Logger.Unsubscribe(_LoggerSubscriber);
                _Subscribed = false;
                return("Done.");
            })
            .WithSubCommand("level", (args) => {
                if (args.Count == 0)
                {
                    return(_LogLevel.ToString().ToLowerInvariant());
                }
                else
                {
                    switch (args[0])
                    {
                    case "debug": _LogLevel = Logger.LogLevel.Debug; break;

                    case "info": _LogLevel = Logger.LogLevel.Info; break;

                    case "warn": _LogLevel = Logger.LogLevel.Warn; break;

                    case "error": _LogLevel = Logger.LogLevel.Error; break;

                    default: throw new Exception($"Unknown log level '{args[0]}");
                    }
                    return("Done.");
                }
            });
            // test commands to dump collection
            AddGroup("texdump")
            .WithSubCommand("collection", (args) =>
            {
                if (args.Count == 0)
                {
                    return("No name specified");
                }
                else
                {
                    string collectionName = args[0];
                    Animation.Collection.Dump(collectionName);
                    return("Successfull");
                }
            });
        }
コード例 #2
0
        internal void AddDefaultCommands()
        {
            _LoggerSubscriber = (logger, loglevel, indent, str) => {
                PrintLine(logger.String(loglevel, str, indent: indent), color: _LoggerColors[loglevel]);
            };


            AddCommand("!!", (args, histindex) => {
                if (histindex - 1 < 0)
                {
                    throw new Exception("Can't run previous command (history is empty).");
                }
                return(History.Execute(histindex.Value - 1));
            });

            AddCommand("!'", (args, histindex) => {
                if (histindex - 1 < 0)
                {
                    throw new Exception("Can't run previous command (history is empty).");
                }
                return(History.Entries[histindex.Value - 1]);
            });

            AddCommand("echo", (args) => {
                return(string.Join(" ", args.ToArray()));
            }).WithSubCommand("hello", (args) => {
                return("Hello, world!\nHello, world!\nHello, world!\nHello, world!\nHello, world!\nHello, world!");
            });

            AddGroup("debug")
            .WithSubCommand("parser-bounds-test", (args) => {
                var text           = "echo Hello! \"Hello world!\" This\\ is\\ great \"It\"works\"with\"\\ wacky\" stuff\" \\[\\] \"\\[\\]\" [e[echo c][echo h][echo [echo \"o\"]] \"hel\"[echo lo][echo !]]";
                CurrentCommandText = text;
                return(null);
            })
            .WithSubCommand("giveid", (args) => {
                if (args.Count < 1)
                {
                    throw new Exception("Exactly 1 argument required.");
                }
                var pickup_obj = PickupObjectDatabase.Instance.InternalGetById(int.Parse(args[0]));

                if (pickup_obj == null)
                {
                    return("Item ID {args[0]} doesn't exist!");
                }

                LootEngine.TryGivePrefabToPlayer(pickup_obj.gameObject, GameManager.Instance.PrimaryPlayer, true);
                return(pickup_obj.EncounterNameOrDisplayName);
            });

            AddGroup("pool")
            .WithSubGroup(
                new Group("items")
                .WithSubCommand("idof", (args) => {
                if (args.Count < 1)
                {
                    throw new Exception("Exactly 1 argument required (numeric ID).");
                }
                var id = int.Parse(args[0]);
                foreach (var pair in ETGMod.Items.Pairs)
                {
                    if (pair.Value.PickupObjectId == id)
                    {
                        return(pair.Key);
                    }
                }
                return("Entry not found.");
            })
                .WithSubCommand("nameof", (args) => {
                if (args.Count < 1)
                {
                    throw new Exception("Exactly 1 argument required (ID).");
                }
                var id = args[0];
                foreach (var pair in ETGMod.Items.Pairs)
                {
                    if (pair.Key == id)
                    {
                        return(_GetPickupObjectName(pair.Value));
                    }
                }
                return("Entry not found.");
            })
                .WithSubCommand("numericof", (args) => {
                if (args.Count < 1)
                {
                    throw new Exception("Exactly 1 argument required (ID).");
                }
                var id = args[0];
                foreach (var pair in ETGMod.Items.Pairs)
                {
                    if (pair.Key == id)
                    {
                        return(pair.Value.PickupObjectId.ToString());
                    }
                }
                return("Entry not found.");
            })
                .WithSubCommand("list", (args) => {
                var s     = new StringBuilder();
                var pairs = new List <KeyValuePair <string, PickupObject> >();
                foreach (var pair in ETGMod.Items.Pairs)
                {
                    pairs.Add(pair);
                }
                foreach (var pair in pairs)
                {
                    if (_GetPickupObjectName(pair.Value) == "NO NAME")
                    {
                        s.AppendLine($"[{pair.Key}] {_GetPickupObjectName(pair.Value)}");
                    }
                }
                pairs.Sort((x, y) => string.Compare(_GetPickupObjectName(x.Value), _GetPickupObjectName(y.Value)));
                foreach (var pair in pairs)
                {
                    if (_GetPickupObjectName(pair.Value) == "NO NAME")
                    {
                        continue;
                    }
                    s.AppendLine($"[{pair.Key}] {_GetPickupObjectName(pair.Value)}");
                }
                return(s.ToString());
            })
                .WithSubCommand("random", (args) => {
                return(ETGMod.Items.RandomKey);
            })
                );

            AddCommand("listmods", (args) => {
                var s = new StringBuilder();

                s.AppendLine("Loaded mods:");
                foreach (var mod in ETGMod.ModLoader.LoadedMods)
                {
                    _GetModInfo(s, mod);
                }
                return(s.ToString());
            });

            AddCommand("give", (args) => {
                LootEngine.TryGivePrefabToPlayer(ETGMod.Items[args[0]].gameObject, GameManager.Instance.PrimaryPlayer, true);
                return(args[0]);
            });

            AddCommand("exec", (args) => {
                var script = args[0];
                try {
                    var result    = ETGMod.ModLoader.LuaState.DoString(script);
                    string output = "[?]";
                    if (result.Count > 0)
                    {
                        var b = new StringBuilder();
                        foreach (var r in result)
                        {
                            b.AppendLine(r.ToString());
                        }
                        output = b.ToString();
                    }
                    else
                    {
                        output = "[ok]";
                    }
                    return(output);
                } catch (Eluant.LuaException e) {
                    return(e.ToString());
                }
            });

            AddGroup("dump")
            .WithSubCommand("synergy_chest", (args) => {
                System.Console.WriteLine(ObjectDumper.Dump(GameManager.Instance.RewardManager.Synergy_Chest, depth: 10));
                return("Dumped to log");
            })
            .WithSubCommand("synergies", (args) => {
                var id = 0;
                foreach (var synergy in GameManager.Instance.SynergyManager.synergies)
                {
                    if (synergy.NameKey != null)
                    {
                        var name = StringTableManager.GetSynergyString(synergy.NameKey);
                        System.Console.WriteLine($"== SYNERGY ID {id} NAME {name} ==");
                    }
                    else
                    {
                        System.Console.WriteLine($"== SYNERGY ID {id} ==");
                    }
                    System.Console.WriteLine($"  ACTIVATION STATUS: {synergy.ActivationStatus}");
                    System.Console.WriteLine($"  # OF OBJECTS REQUIRED: {synergy.NumberObjectsRequired}");
                    System.Console.WriteLine($"  ACTIVE WHEN GUN UNEQUIPPED?: {synergy.ActiveWhenGunUnequipped}");
                    System.Console.WriteLine($"  REQUIRES AT LEAST ONE GUN AND ONE ITEM?: {synergy.RequiresAtLeastOneGunAndOneItem}");
                    System.Console.WriteLine($"  MANDATORY GUNS:");
                    foreach (var itemid in synergy.MandatoryGunIDs)
                    {
                        System.Console.WriteLine($"  - {_GetPickupObjectName(PickupObjectDatabase.GetById(itemid))}");
                    }
                    System.Console.WriteLine($"  OPTIONAL GUNS:");
                    foreach (var itemid in synergy.OptionalGunIDs)
                    {
                        System.Console.WriteLine($"  - {_GetPickupObjectName(PickupObjectDatabase.GetById(itemid))}");
                    }
                    System.Console.WriteLine($"  MANDATORY ITEMS:");
                    foreach (var itemid in synergy.MandatoryItemIDs)
                    {
                        System.Console.WriteLine($"  - {_GetPickupObjectName(PickupObjectDatabase.GetById(itemid))}");
                    }
                    System.Console.WriteLine($"  OPTIONAL ITEMS:");
                    foreach (var itemid in synergy.OptionalItemIDs)
                    {
                        System.Console.WriteLine($"  - {_GetPickupObjectName(PickupObjectDatabase.GetById(itemid))}");
                    }
                    System.Console.WriteLine($"  BONUS SYNERGIES:");
                    foreach (var bonus in synergy.bonusSynergies)
                    {
                        System.Console.WriteLine($"  - {bonus}");
                    }
                    System.Console.WriteLine($"  STAT MODIFIERS:");
                    foreach (var statmod in synergy.statModifiers)
                    {
                        System.Console.WriteLine($"  - STAT: {statmod.statToBoost}");
                        System.Console.WriteLine($"    AMOUNT: {statmod.amount}");
                        System.Console.WriteLine($"    MODIFY TYPE: {statmod.modifyType}");
                        System.Console.WriteLine($"    PERSISTS ON COOP DEATH?: {statmod.PersistsOnCoopDeath}");
                        System.Console.WriteLine($"    IGNORED FOR SAVE DATA?: {statmod.ignoredForSaveData}");
                    }
                    id++;
                }
                return("Dumped to log");
            })
            .WithSubCommand("items", (args) => {
                var b  = new StringBuilder();
                var db = PickupObjectDatabase.Instance.Objects;
                for (int i = 0; i < db.Count; i++)
                {
                    PickupObject obj  = null;
                    string nameprefix = "";
                    string name       = null;
                    try {
                        obj = db[i];
                    } catch {
                        name = "[ERROR: failed getting object by index]";
                    }
                    if (obj != null)
                    {
                        try {
                            var displayname = obj.encounterTrackable.journalData.PrimaryDisplayName;
                            name            = StringTableManager.ItemTable[displayname].GetWeightedString();
                        } catch {
                            name = "[ERROR: failed getting ammonomicon name]";
                        }
                        if (name == null)
                        {
                            try {
                                name = obj.EncounterNameOrDisplayName;
                            } catch {
                                name = "[ERROR: failed getting encounter or display name]";
                            }
                        }
                    }
                    if (name == null && obj != null)
                    {
                        name = "[NULL NAME (but object is not null)]";
                    }

                    name = $"{nameprefix} {name}";

                    if (name != null)
                    {
                        b.AppendLine($"{i}: {name}");
                        _Logger.Info($"{i}: {name}");
                    }
                }
                return(b.ToString());
            });

            AddGroup("log")
            .WithSubCommand("sub", (args) => {
                if (_Subscribed)
                {
                    return("Already subscribed.");
                }
                Logger.Subscribe(_LoggerSubscriber);
                _Subscribed = true;
                return("Done.");
            })
            .WithSubCommand("unsub", (args) => {
                if (!_Subscribed)
                {
                    return("Not subscribed yet.");
                }
                Logger.Unsubscribe(_LoggerSubscriber);
                _Subscribed = false;
                return("Done.");
            })
            .WithSubCommand("level", (args) => {
                if (args.Count == 0)
                {
                    return(_LogLevel.ToString().ToLowerInvariant());
                }
                else
                {
                    switch (args[0])
                    {
                    case "debug": _LogLevel = Logger.LogLevel.Debug; break;

                    case "info": _LogLevel = Logger.LogLevel.Info; break;

                    case "warn": _LogLevel = Logger.LogLevel.Warn; break;

                    case "error": _LogLevel = Logger.LogLevel.Error; break;

                    default: throw new Exception($"Unknown log level '{args[0]}");
                    }
                    return("Done.");
                }
            });
        }
コード例 #3
0
        public InstallerForm()
        {
            Icon = Icon.FromResource("icon");

            KeyDown += (sender, e) => {
                Console.WriteLine($"XXX {e.Key}");
                if (e.Key.HasFlag(Keys.Enter) && e.Modifiers.HasFlag(Keys.Control))
                {
                    Options.Visible = true;
                }
            };

            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler((sender, e) => {
                var ex = (Exception)e.ExceptionObject;
                Log.WriteLine("\nUnhandled error!");
                Log.WriteLine(ex.Message);
            });

            Downloader = new Downloader();
            Installer  = new Installer(Downloader, null);

            Title      = $"Mod the Gungeon Installer {Version} (core {Installer.Version})";
            ClientSize = new Size(640, 400);

            MainLayout = new DynamicLayout();

            MainLayout.BeginHorizontal();

            MainLayout.BeginVertical();
            MainLayout.Add(new Label {
                Text = "Output log"
            });
            MainLayout.Add(Log = new Log());
            MainLayout.Add(new ImageView {
                Image = Bitmap.FromResource("icon")
            }, false, false);
            MainLayout.EndVertical();

            MainLayout.BeginVertical();
            MainLayout.Add(new Label {
                Text = "Path to the Gungeon executable"
            });
            MainLayout.Add(ExeSelector = new ExeSelector());
            Installer.ChangeExePath(ExeSelector.Path);
            ExeSelector.PathChanged += (sender, e) => {
                Installer.ChangeExePath(ExeSelector.Path);
                UpdateInstallButton();
            };

            MainLayout.Add(CheckboxesLayout = new StackLayout {
                Orientation = Orientation.Horizontal,
            });

            ComponentList = new ComponentList(Downloader.Components.Values);
            Options       = new Options {
                Visible = false
            };
            ComponentList.SelectedVersionsChanged += (sender, e) => UpdateInstallButton();

            ShowCheckboxes();

            MainLayout.Add(null, false, true);
            VersionDisplay = new VersionDisplay();
            VersionDisplay.ConnectTo(ComponentList);
            MainLayout.Add(InstallButton = new Button {
                Text = "Install", Enabled = false, Size = new Size(100, -1)
            }, true, false);
            MainLayout.Add(UninstallButton = new Button {
                Text = "Uninstall", Size = new Size(100, -1)
            }, true, false);

            InstallButton.Click   += (sender, e) => Install();
            UninstallButton.Click += (sender, e) => Uninstall();

            MainLayout.EndVertical();

            Content = MainLayout;

            Log.WriteLine("Welcome!");

            var subscriber = new Logger.Subscriber((logger, loglevel, indent, str) => {
                var formatted = logger.String(loglevel, str, indent);
                Application.AsyncInvoke(() => Log.WriteLine(formatted));
            });

            Logger.Subscribe(subscriber);
        }
コード例 #4
0
ファイル: DefaultCommands.cs プロジェクト: jeason1997/ETGMod
        internal void AddDefaultCommands()
        {
            _LoggerSubscriber = (logger, loglevel, indent, str) => {
                PrintLine(logger.String(loglevel, str, indent: indent), color: _LoggerColors[loglevel]);
            };


            AddCommand("!!", (args, histindex) => {
                if (histindex - 1 < 0)
                {
                    throw new Exception("Can't run previous command (history is empty).");
                }
                return(History.Execute(histindex.Value - 1));
            });

            AddCommand("!'", (args, histindex) => {
                if (histindex - 1 < 0)
                {
                    throw new Exception("Can't run previous command (history is empty).");
                }
                return(History.Entries[histindex.Value - 1]);
            });

            AddCommand("echo", (args) => {
                return(string.Join(" ", args.ToArray()));
            }).WithSubCommand("hello", (args) => {
                return("Hello, world!\nHello, world!\nHello, world!\nHello, world!\nHello, world!\nHello, world!");
            });

            AddGroup("debug")
            .WithSubCommand("parser-bounds-test", (args) => {
                var text           = "echo Hello! \"Hello world!\" This\\ is\\ great \"It\"works\"with\"\\ wacky\" stuff\" \\[\\] \"\\[\\]\" [e[echo c][echo h][echo [echo \"o\"]] \"hel\"[echo lo][echo !]]";
                CurrentCommandText = text;
                return(null);
            })
            .WithSubCommand("giveid", (args) => {
                if (args.Count < 1)
                {
                    throw new Exception("Exactly 1 argument required.");
                }
                var pickup_obj = PickupObjectDatabase.Instance.InternalGetById(int.Parse(args[0]));

                if (pickup_obj == null)
                {
                    return("Item ID {args[0]} doesn't exist!");
                }

                LootEngine.TryGivePrefabToPlayer(pickup_obj.gameObject, GameManager.Instance.PrimaryPlayer, true);
                return(pickup_obj.EncounterNameOrDisplayName);
            });

            AddGroup("pool")
            .WithSubGroup(
                new Group("items")
                .WithSubCommand("idof", (args) => {
                if (args.Count < 1)
                {
                    throw new Exception("Exactly 1 argument required (numeric ID).");
                }
                var id = int.Parse(args[0]);
                foreach (var pair in ETGMod.Items.Pairs)
                {
                    if (pair.Value.PickupObjectId == id)
                    {
                        return(pair.Key);
                    }
                }
                return("Entry not found.");
            })
                .WithSubCommand("nameof", (args) => {
                if (args.Count < 1)
                {
                    throw new Exception("Exactly 1 argument required (ID).");
                }
                var id = args[0];
                foreach (var pair in ETGMod.Items.Pairs)
                {
                    if (pair.Key == id)
                    {
                        return(_GetPickupObjectName(pair.Value));
                    }
                }
                return("Entry not found.");
            })
                .WithSubCommand("numericof", (args) => {
                if (args.Count < 1)
                {
                    throw new Exception("Exactly 1 argument required (ID).");
                }
                var id = args[0];
                foreach (var pair in ETGMod.Items.Pairs)
                {
                    if (pair.Key == id)
                    {
                        return(pair.Value.PickupObjectId.ToString());
                    }
                }
                return("Entry not found.");
            })
                .WithSubCommand("list", (args) => {
                var s     = new StringBuilder();
                var pairs = new List <KeyValuePair <string, PickupObject> >();
                foreach (var pair in ETGMod.Items.Pairs)
                {
                    pairs.Add(pair);
                }
                foreach (var pair in pairs)
                {
                    if (_GetPickupObjectName(pair.Value) == "NO NAME")
                    {
                        s.AppendLine($"[{pair.Key}] {_GetPickupObjectName(pair.Value)}");
                    }
                }
                pairs.Sort((x, y) => string.Compare(_GetPickupObjectName(x.Value), _GetPickupObjectName(y.Value)));
                foreach (var pair in pairs)
                {
                    if (_GetPickupObjectName(pair.Value) == "NO NAME")
                    {
                        continue;
                    }
                    s.AppendLine($"[{pair.Key}] {_GetPickupObjectName(pair.Value)}");
                }
                return(s.ToString());
            })
                .WithSubCommand("random", (args) => {
                return(ETGMod.Items.RandomKey);
            })
                );

            AddCommand("listmods", (args) => {
                var s = new StringBuilder();

                s.AppendLine("Loaded mods:");
                foreach (var mod in ETGMod.ModLoader.LoadedMods)
                {
                    _GetModInfo(s, mod);
                }
                return(s.ToString());
            });

            AddCommand("give", (args) => {
                LootEngine.TryGivePrefabToPlayer(ETGMod.Items[args[0]].gameObject, GameManager.Instance.PrimaryPlayer, true);
                return(args[0]);
            });

            AddGroup("dump")
            .WithSubCommand("items", (args) => {
                var b  = new StringBuilder();
                var db = PickupObjectDatabase.Instance.Objects;
                for (int i = 0; i < db.Count; i++)
                {
                    PickupObject obj = null;
                    string name      = null;
                    try {
                        obj = db[i];
                    } catch {
                        name = "[ERROR: failed getting object by index]";
                    }
                    if (obj != null)
                    {
                        try {
                            var displayname = obj.encounterTrackable.journalData.PrimaryDisplayName;
                            name            = StringTableManager.ItemTable[displayname].GetWeightedString();
                        } catch {
                            name = "[ERROR: failed getting ammonomicon name]";
                        }
                        if (name == null)
                        {
                            try {
                                name = obj.EncounterNameOrDisplayName;
                            } catch {
                                name = "[ERROR: failed getting encounter or display name]";
                            }
                        }
                    }
                    if (name == null && obj != null)
                    {
                        name = "[NULL NAME (but object is not null)]";
                    }

                    if (name != null)
                    {
                        b.AppendLine($"{i}: {name}");
                        _Logger.Info($"{i}: {name}");
                    }
                }
                return(b.ToString());
            });

            AddGroup("log")
            .WithSubCommand("sub", (args) => {
                if (_Subscribed)
                {
                    return("Already subscribed.");
                }
                Logger.Subscribe(_LoggerSubscriber);
                _Subscribed = true;
                return("Done.");
            })
            .WithSubCommand("unsub", (args) => {
                if (!_Subscribed)
                {
                    return("Not subscribed yet.");
                }
                Logger.Unsubscribe(_LoggerSubscriber);
                _Subscribed = false;
                return("Done.");
            })
            .WithSubCommand("level", (args) => {
                if (args.Count == 0)
                {
                    return(_LogLevel.ToString().ToLowerInvariant());
                }
                else
                {
                    switch (args[0])
                    {
                    case "debug": _LogLevel = Logger.LogLevel.Debug; break;

                    case "info": _LogLevel = Logger.LogLevel.Info; break;

                    case "warn": _LogLevel = Logger.LogLevel.Warn; break;

                    case "error": _LogLevel = Logger.LogLevel.Error; break;

                    default: throw new Exception($"Unknown log level '{args[0]}");
                    }
                    return("Done.");
                }
            });
        }