static void registerCmd(InCmd attr, InCmdDelegate cb) { object catalog = Traverse.Create(console).Field("concommandCatalog").GetValue(); var conCommandType = typeof(RoR2.Console).GetNestedType("ConCommand", BindingFlags.NonPublic); var conCommandCtor = conCommandType.GetConstructor(Type.EmptyTypes); var cmd = conCommandCtor.Invoke(new object[0]); conCommandType.GetField("flags").SetValue(cmd, attr.User ? ConVarFlags.None : ConVarFlags.ExecuteOnServer); conCommandType.GetField("action").SetValue(cmd, (RoR2.Console.ConCommandDelegate)((ConCommandArgs args) => { var res = new InCmdResult(); var cargs = new InCmdArgs() { Args = args.userArgs.ToArray(), Sender = args.sender, Target = args.sender, }; try { cb(res, cargs); } catch (Exception e) { res.Error = e.ToString() + "\n" + e.StackTrace; } if (args.sender.localUser != null) { Debug.Log(res.Result.Join(null, "\n")); if (res.Error != null) { Debug.LogWarning(res.Error); } } else { // TODO: Support clients executing commands } })); conCommandType.GetField("helpText").SetValue(cmd, attr.Hint); catalog.GetType().GetProperty("Item").SetValue(catalog, cmd, new[] { attr.Name.ToLower(System.Globalization.CultureInfo.InvariantCulture) }); }
public override void Init() { foreach (var nm in new[] { "baseMaxHealth", "baseRegen", "baseMaxShield", "baseMoveSpeed", "baseAcceleration", "baseJumpPower", "baseDamage", "baseAttackSpeed", "baseCrit", "baseArmor", }) { var v = new InCmd("stat_" + nm.Substring(4)); v.User = true; Infinity.registerVar(v, new BaseFloatInVar(nm)); } }
public static void registerVar(InCmd attr, InVar var) { registerCmd(attr, (InCmdResult res, InCmdArgs args) => { if (args.Length == 0) { res.Add(attr.Name + " = " + var.Get(args.Sender)); } else { if (args.Length != 1) { res.Add("zero or one arguments expected"); } else { var.Set(args.Target, args[0]); res.Add(attr.Name + " = " + var.Get(args.Target)); } } }); }