protected override async void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            PopulateDetails();

            var msilEditor = new TextEditorControl
            {
                IsReadOnly = true,
                Dock = DockStyle.Fill,
                Text = Decompiler.DecompileToIL(MethodDef.Body)
            };
            msiltab.Controls.Add(msilEditor);

            var codeEditor = new TextEditorControl
            {
                IsReadOnly = true,
                Dock = DockStyle.Fill,
                Text = await Decompiler.GetSourceCode(MethodDef),
                Document = { HighlightingStrategy = HighlightingManager.Manager.FindHighlighter("C#") }
            };
            codetab.Controls.Add(codeEditor);

            if (!MethodDef.HasBody)
            {
                hookbutton.Enabled = false;
                gotohookbutton.Enabled = false;
                return;
            }

            MethodSignature methodsig = Utility.GetMethodSignature(MethodDef);

            bool hookfound = false;
            foreach (var manifest in MainForm.CurrentProject.Manifests)
            {
                foreach (var hook in manifest.Hooks)
                {
                    if (hook.Signature.Equals(methodsig) && hook.TypeName == MethodDef.DeclaringType.FullName)
                    {
                        hookfound = true;
                        methodhook = hook;
                        break;
                    }
                }
            }
            if (hookfound)
            {
                hookbutton.Enabled = false;
                gotohookbutton.Enabled = true;
            }
            else
            {
                hookbutton.Enabled = true;
                gotohookbutton.Enabled = false;
            }
        }
Beispiel #2
0
        /// <summary>
        /// Updates the UI for a hook
        /// </summary>
        /// <param name="hook"></param>
        public void UpdateHook(Hook hook, bool batchUpdate)
        {
            foreach (TabPage tabpage in tabview.TabPages)
            {
                if (tabpage.Tag is HookViewControl && (tabpage.Tag as HookViewControl).Hook == hook)
                {
                    tabpage.Text = hook.Name;
                    if (hook.Flagged)
                    {
                        (tabpage.Tag as HookViewControl).UnflagButton.Enabled = true;
                        (tabpage.Tag as HookViewControl).FlagButton.Enabled = false;
                    }
                    else
                    {
                        (tabpage.Tag as HookViewControl).UnflagButton.Enabled = false;
                        (tabpage.Tag as HookViewControl).FlagButton.Enabled = true;
                    }
                }
            }
            if (!batchUpdate)
            {
                CurrentProject.Save(CurrentProjectFilename);
            }

            TreeNode hooks = null;
            foreach (var node in objectview.Nodes)
                if ((node as TreeNode).Text == "Hooks")
                {
                    hooks = node as TreeNode;
                    break;
                }
            if (hooks == null) return;

            foreach (var node in hooks.Nodes)
            {
                if ((node as TreeNode).Tag == hook)
                {
                    TreeNode treenode = node as TreeNode;

                    treenode.Text = hook.Name;
                    if (hook.Flagged)
                    {
                        treenode.ImageKey = "script_error.png";
                        treenode.SelectedImageKey = "script_error.png";
                    }
                    else
                    {
                        treenode.ImageKey = "script_lightning.png";
                        treenode.SelectedImageKey = "script_lightning.png";
                    }

                    break;
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// Removes a hook from the current project
        /// </summary>
        /// <param name="hook"></param>
        public void RemoveHook(Hook hook)
        {
            Manifest manifest = CurrentProject.GetManifest(hook.AssemblyName);
            manifest.Hooks.Remove(hook);
            CurrentProject.Save(CurrentProjectFilename);

            foreach (TabPage tabpage in tabview.TabPages)
            {
                if (tabpage.Tag is HookViewControl && (tabpage.Tag as HookViewControl).Hook == hook)
                {
                    tabview.TabPages.Remove(tabpage);
                    break;
                }
            }

            TreeNode hooks = null;
            foreach (var node in objectview.Nodes)
                if ((node as TreeNode).Text == "Hooks")
                {
                    hooks = node as TreeNode;
                    break;
                }
            if (hooks == null) return;

            foreach (var node in hooks.Nodes)
            {
                if ((node as TreeNode).Tag == hook)
                {
                    hooks.Nodes.Remove(node as TreeNode);
                    break;
                }
            }
        }
Beispiel #4
0
        /// <summary>
        /// Opens or focuses the specified hook view
        /// </summary>
        /// <param name="hook"></param>
        public void GotoHook(Hook hook)
        {
            // Check if it's already open somewhere
            foreach (TabPage tabpage in tabview.TabPages)
            {
                HookViewControl control = tabpage.Tag as HookViewControl;
                if (control != null && control.Hook == hook)
                {
                    tabview.SelectedTab = tabpage;
                    return;
                }
            }

            // Create
            HookViewControl view = new HookViewControl();
            view.Hook = hook;
            view.MainForm = this;
            view.Dock = DockStyle.Fill;
            AddTab(hook.Name, view, view);
        }
Beispiel #5
0
        /// <summary>
        /// Adds a hook to the current project
        /// </summary>
        /// <param name="hook"></param>
        public void AddHook(Hook hook)
        {
            Manifest manifest = CurrentProject.GetManifest(hook.AssemblyName);
            manifest.Hooks.Add(hook);
            CurrentProject.Save(CurrentProjectFilename);

            TreeNode hooks = null;
            foreach (var node in objectview.Nodes)
                if ((node as TreeNode).Text == "Hooks")
                {
                    hooks = node as TreeNode;
                    break;
                }
            if (hooks == null) return;

            TreeNode hooknode = new TreeNode(hook.Name);
            if (hook.Flagged)
            {
                hooknode.ImageKey = "script_error.png";
                hooknode.SelectedImageKey = "script_error.png";
            }
            else
            {
                hooknode.ImageKey = "script_lightning.png";
                hooknode.SelectedImageKey = "script_lightning.png";
            }
            hooknode.Tag = hook;
            hooks.Nodes.Add(hooknode);
        }
        private void hookbutton_Click(object sender, EventArgs e)
        {
            Type t = Hook.GetDefaultHookType();
            if (t == null) return;

            Hook hook = Activator.CreateInstance(t) as Hook;
            hook.Name = MethodDef.Name;
            if (hook.Name.Substring(0, 2) == "On")
                hook.HookName = hook.Name;
            else
                hook.HookName = "On" + hook.Name;
            hook.TypeName = MethodDef.DeclaringType.FullName;
            hook.AssemblyName = MainForm.rassemblydict[MethodDef.Module.Assembly];
            hook.Signature = Utility.GetMethodSignature(MethodDef);
            hook.MSILHash = new Patching.ILWeaver(MethodDef.Body).Hash;

            MainForm.AddHook(hook);
            MainForm.GotoHook(hook);

            methodhook = hook;

            hookbutton.Enabled = false;
            gotohookbutton.Enabled = true;
        }
        /// <summary>
        /// Removes a hook from the current project
        /// </summary>
        /// <param name="hook"></param>
        public void RemoveHook(Hook hook)
        {
            Manifest manifest = CurrentProject.GetManifest(hook.AssemblyName);
            manifest.Hooks.Remove(hook);
            CurrentProject.Save(CurrentProjectFilename);

            foreach (TabPage tabpage in tabview.TabPages)
            {
                if (tabpage.Tag is HookViewControl && (tabpage.Tag as HookViewControl).Hook == hook)
                {
                    tabview.TabPages.Remove(tabpage);
                    break;
                }
            }

            foreach (TreeNode node in objectview.Nodes["Hooks"].Nodes)
            {
                if (node.Tag == hook)
                {
                    node.Remove();
                    break;
                }

                var tag = node.Tag as string;
                if (string.IsNullOrEmpty(tag)) continue;
                if (tag != "Category") continue;
                foreach (TreeNode subnode in node.Nodes)
                {
                    if (subnode.Tag != hook) continue;
                    subnode.Remove();
                    break;
                }
            }
        }