Ejemplo n.º 1
0
        private void FirstPass()
        {
            foreach (MethodItem methodItem in (_activeItem as TypeItem).Methods)
            {
                if (CheckWorker())
                {
                    break;
                }

                MethodInfo mi = methodItem.MethodInfo;

                string id = mi.DeclaringType.FullName + " " + RefHelp.GetNameWithParameterList(mi);

                // Add the graph node with a link back to the method.
                if (AddNode(id, mi.Name, _sharedOptions.MethodColor, methodItem) != null)
                {
                    // Hang onto the method and the corresponding graph node.
                    _methodInfos.Add(id, mi);

                    // Make a note of overloaded methods.
                    if (_names.Contains(mi.Name))
                    {
                        _overloads.Add(mi.Name);
                    }
                    else
                    {
                        _names.Add(mi.Name);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public static void Load()
        {
            try
            {
                HarmonyInstance.Create("Subnautica.CheatManager.mod").PatchAll(Assembly.GetExecutingAssembly());
                GameHelper.EnableConsole();
                SceneManager.sceneLoaded += new UnityAction <Scene, LoadSceneMode>(OnSceneLoaded);

                Config.InitConfig();
            }
            catch (Exception ex)
            {
                Debug.LogException(ex);
            }

            isExistsSMLHelperV2 = RefHelp.IsNamespaceExists("SMLHelper.V2");
        }
Ejemplo n.º 3
0
        private MethodInfo[] GetMethods(TypeItem typeItem)
        {
            // better way to sort.. IComparable? todo
            Dictionary <string, MethodInfo> d = new Dictionary <string, MethodInfo>();
            List <string> l = new List <string>();

            string id;

            foreach (MethodInfo mi in typeItem.TypeRef.GetMethods(
                         BindingFlags.NonPublic | BindingFlags.Public |
                         BindingFlags.Instance | BindingFlags.Static |
                         BindingFlags.DeclaredOnly))
            {
                if (mi.IsSpecialName)
                {
                    continue;
                }

                try
                {
                    id = RefHelp.GetNameWithParameterList(mi);
                }
                catch (FileNotFoundException exc)
                {
                    if (!_miWarnedAlready.Contains(typeItem.FullName))
                    {
                        _logView.LogExcStr(exc, "Failed to get methods for " + typeItem.FullName);
                        _miWarnedAlready.Add(typeItem.FullName);
                    }
                    continue;
                }

                d.Add(id, mi);
                l.Add(id);
            }
            l.Sort();

            MethodInfo[] result = new MethodInfo[l.Count];

            for (int i = 0; i < l.Count; i++)
            {
                result[i] = d[l[i]];
            }

            return(result);
        }
Ejemplo n.º 4
0
        public static void Load()
        {
            isExists_SlotExtender = RefHelp.IsNamespaceExists("SlotExtender");

            if (isExists_SlotExtender)
            {
                SNLogger.Log($"[{QSEConfig.PROGRAM_NAME}] SlotExtender found! trying to work together..");
            }

            try
            {
                HarmonyInstance.Create("Subnautica.QuickSlotExtender.mod").PatchAll(Assembly.GetExecutingAssembly());
                SNLogger.Log($"[{QSEConfig.PROGRAM_NAME}] Patches installed");
                SceneManager.sceneLoaded += new UnityAction <Scene, LoadSceneMode>(OnSceneLoaded);
            }
            catch (Exception ex)
            {
                Debug.LogException(ex);
            }
        }
Ejemplo n.º 5
0
        protected void GetInstrDetails(ILInstruction instruction,
                                       out string name, out Type declType, out string calledId)
        {
            name     = null;
            declType = null;
            calledId = null;

            if (instruction.Operand is MethodInfo)
            {
                MethodInfo mOperand = (MethodInfo)instruction.Operand;
                declType = mOperand.DeclaringType;
                name     = mOperand.Name;
                calledId = declType.FullName + " " + RefHelp.GetNameWithParameterList(mOperand);
            }
            else if (instruction.Operand is ConstructorInfo)
            {
                ConstructorInfo mOperand = (ConstructorInfo)instruction.Operand;
                declType = mOperand.DeclaringType;
                name     = mOperand.Name;
                calledId = declType.FullName + " " + RefHelp.GetNameWithParameterList(mOperand);
            }
        }
Ejemplo n.º 6
0
        public static void Load()
        {
            try
            {
                SEConfig.LoadConfig();
                SlotHelper.InitSlotIDs();

                hInstance = HarmonyInstance.Create("Subnautica.SlotExtender.mod");

                //Harmony autopatch not working if MoreQuickSlots mod not installed therefore switch to manual patching mode
                //hInstance.PatchAll(Assembly.GetExecutingAssembly());

                //begin manual patch
                hInstance.Patch(typeof(DevConsole).GetMethod("SetState"),
                                new HarmonyMethod(typeof(DevConsole_SetState_Patch), "Prefix"), null);

                hInstance.Patch(typeof(Equipment).GetMethod("GetSlotType"),
                                new HarmonyMethod(typeof(Equipment_GetSlotType_Patch), "Prefix"), null);

                hInstance.Patch(typeof(Equipment).GetMethod("AllowedToAdd"),
                                new HarmonyMethod(typeof(Equipment_AllowedToAdd_Patch), "Prefix"), null);

                hInstance.Patch(typeof(SeaMoth).GetProperty("slotIDs",
                                                            BindingFlags.Instance |
                                                            BindingFlags.NonPublic |
                                                            BindingFlags.GetProperty).GetGetMethod(true),
                                new HarmonyMethod(typeof(Seamoth_slotIDs_Patch), "Prefix"), null);

                hInstance.Patch(typeof(uGUI_QuickSlots).GetMethod("SetBackground",
                                                                  BindingFlags.NonPublic |
                                                                  BindingFlags.Instance),
                                new HarmonyMethod(typeof(uGUI_QuickSlots_SetBackground_Patch), "Prefix"), null);

                hInstance.Patch(typeof(uGUI_Equipment).GetMethod("Awake",
                                                                 BindingFlags.NonPublic |
                                                                 BindingFlags.Instance |
                                                                 BindingFlags.SetField),
                                new HarmonyMethod(typeof(uGUI_Equipment_Awake_Patch), "Prefix"),
                                new HarmonyMethod(typeof(uGUI_Equipment_Awake_Patch), "Postfix"));

                hInstance.Patch(typeof(SeaMoth).GetMethod("Start"), null,
                                new HarmonyMethod(typeof(SeaMoth_Start_Patch), "Postfix"));

                hInstance.Patch(typeof(Exosuit).GetProperty("slotIDs",
                                                            BindingFlags.Instance |
                                                            BindingFlags.NonPublic |
                                                            BindingFlags.GetProperty).GetGetMethod(true),
                                new HarmonyMethod(typeof(Exosuit_slotIDs_Patch), "Prefix"), null);

                hInstance.Patch(typeof(Exosuit).GetMethod("Start"), null,
                                new HarmonyMethod(typeof(Exosuit_Start_Patch), "Postfix"));



                //end manual patch

                SceneManager.sceneLoaded += new UnityAction <Scene, LoadSceneMode>(OnSceneLoaded);
            }
            catch (Exception ex)
            {
                Debug.LogException(ex);
            }

            //check MoreQuickSlots namespace is exists
            if (RefHelp.IsNamespaceExists("MoreQuickSlots"))
            {
                SNLogger.Log($"[{SEConfig.PROGRAM_NAME}] -> MoreQuickSlots namespace is exist! Trying to install a Cross-MOD patch...");
                //if yes construct a Harmony patch
                MQS_Patches mqs_patcher = new MQS_Patches(hInstance);

                if (mqs_patcher.InitPatch())
                {
                    SNLogger.Log($"[{SEConfig.PROGRAM_NAME}] -> MoreQuickSlots Cross-MOD patch installed!");
                }
                else
                {
                    SNLogger.Log($"[{SEConfig.PROGRAM_NAME}] -> MoreQuickSlots Cross-MOD patch install failed!");
                }
            }
        }
Ejemplo n.º 7
0
        private void AddOutNodes()
        {
            SDILReader.MethodBodyReader mr = new MethodBodyReader((_activeItem as MethodItem).MethodInfo);
            if (mr == null)
            {
                return;
            }

            // Abstract..external, etc
            if (mr.instructions == null)
            {
                AddNullBodyOutNodes();
                return;
            }

            string id       = string.Empty;
            string methodId = _activeItem.GetShortID();

            foreach (ILInstruction instruction in mr.instructions)
            {
                if (CheckWorker())
                {
                    break;
                }

                if (instruction.Code.OperandType != OperandType.InlineMethod)
                {
                    continue;
                }

                Type type = null;
                if (instruction.Operand is MethodInfo)
                {
                    id = string.Format("{0} {1}",
                                       (instruction.Operand as MethodInfo).DeclaringType.ToString(),
                                       RefHelp.GetNameWithParameterList(instruction.Operand as MethodInfo));

                    type = (instruction.Operand as MethodInfo).DeclaringType;
                }
                else if (instruction.Operand is ConstructorInfo)
                {
                    id = string.Format("{0} {1}",
                                       (instruction.Operand as ConstructorInfo).DeclaringType.ToString(),
                                       RefHelp.GetNameWithParameterList(instruction.Operand as ConstructorInfo));

                    type = (instruction.Operand as ConstructorInfo).DeclaringType;
                }
                else
                {
                    _logView.LogStr("Butterfly failed to recognise call instruction :" + instruction.Operand.GetType().ToString());
                }

                // Find the method baseItem we're calling.
                BaseItem item = _projectBrowser.Lookup(id);

                // If the method is not present in our project, then forget about it.
                if (item == null)
                {
                    continue;
                }

                string caption = item.Name;
                if (_methodType != type)
                {
                    caption = type.Name + "\n" + caption;
                }
                AddNode(id, caption, _sharedOptions.MethodColor, item);
                AddEdge(methodId, id, EdgeStyle.NormalArrow);
            }
        }
Ejemplo n.º 8
0
        private void AddLinksFromMethods(TypeItem fromTypeItem, string toMethodId)
        {
            string fromMethodId, id;

            foreach (MethodItem methodItem in fromTypeItem.Methods)
            {
                if (CheckWorker())
                {
                    break;
                }
                fromMethodId = methodItem.GetShortID();

                SDILReader.MethodBodyReader mr = new MethodBodyReader(methodItem.MethodInfo);
                if (mr == null)
                {
                    continue;
                }

                // Abstract..external, etc
                if (mr.instructions == null)
                {
                    continue;
                }

                foreach (ILInstruction instruction in mr.instructions)
                {
                    if (CheckWorker())
                    {
                        break;
                    }
                    id = string.Empty;

                    if (instruction.Code.OperandType != OperandType.InlineMethod)
                    {
                        continue;
                    }

                    if (instruction.Operand is MethodInfo)
                    {
                        id = string.Format("{0} {1}",
                                           (instruction.Operand as MethodInfo).DeclaringType.ToString(),
                                           RefHelp.GetNameWithParameterList(instruction.Operand as MethodInfo));
                    }
                    else if (instruction.Operand is ConstructorInfo)
                    {
                        id = string.Format("{0} {1}",
                                           (instruction.Operand as ConstructorInfo).DeclaringType.ToString(),
                                           RefHelp.GetNameWithParameterList(instruction.Operand as ConstructorInfo));
                    }
                    else if (instruction.Operand == null)
                    {
                        _logView.LogStr("Butterfly failed with null instruction.operand :" + instruction.ToString());
                    }
                    else
                    {
                        _logView.LogStr("Butterfly failed to recognise call instruction (in) :" + instruction.Operand.GetType().ToString());
                    }

                    // We're looking for hits on one specific method.
                    if (id != toMethodId)
                    {
                        continue;
                    }

                    // Only add nodes once.
                    //if (_addedNodes.ContainsKey(fromMethodId)) continue;

                    string caption = fromTypeItem + "\n" + methodItem.Name;

                    AddNode(fromMethodId, caption, _sharedOptions.MethodColor, methodItem);
                    AddEdge(fromMethodId, toMethodId, EdgeStyle.NormalArrow);
                }
            }
        }
Ejemplo n.º 9
0
 public override string GetID()
 {
     return(Parent.GetID() + " " + RefHelp.GetNameWithParameterList(_methodInfo));
 }