public static void Load()
        {
            try
            {
                //loading config from file
                Config.LoadConfig();
                SlotHelper.InitSlotIDs();

                hInstance = HarmonyInstance.Create("SubnauticaBelowZero.SlotExtenderZero.mod");

                hInstance.PatchAll(Assembly.GetExecutingAssembly());

                SceneManager.sceneLoaded += new UnityAction <Scene, LoadSceneMode>(OnSceneLoaded);
            }
            catch (Exception ex)
            {
                Debug.LogException(ex);
            }
        }
Ejemplo n.º 2
0
        public static void Load()
        {
            try
            {
                //loading config from file
                SEzConfig.Config_Load();
                SlotHelper.InitSlotIDs();
                SlotHelper.ExpandSlotMapping();

                hInstance = new Harmony("BelowZero.SlotExtenderZero.mod");

                BZLogger.Debug($"Harmony instance created, Name = [{hInstance.Id}]");

                hInstance.Patch(typeof(SeaTruckUpgrades).GetMethod("Start"), null, new HarmonyMethod(typeof(SeaTruckUpgrades_Start_Patch), "Postfix"));

                MethodBase STU_ctor = GetConstructorMethodBase(typeof(SeaTruckUpgrades), ".ctor");

                hInstance.Patch(STU_ctor, new HarmonyMethod(typeof(SeaTruckUpgrades_Constructor_Patch), "Prefix"));

                hInstance.Patch(typeof(DevConsole).GetMethod("SetState"), new HarmonyMethod(typeof(DevConsole_SetState_Patch), "Prefix"));

                MethodBase Exosuit_ctor = GetConstructorMethodBase(typeof(Exosuit), ".ctor");

                hInstance.Patch(Exosuit_ctor, new HarmonyMethod(typeof(Exosuit_Constructor_Patch), "Prefix"));

                /*
                 * MethodBase Hoverbike_ctor = GetConstructorMethodBase(typeof(Hoverbike), ".ctor");
                 *
                 * hInstance.Patch(Hoverbike_ctor, new HarmonyMethod(typeof(Hoverbike_Constructor_Patch), "Prefix"));
                 */
                /*
                 * MethodBase Equipment_ctor_0 = GetConstructorMethodBase(typeof(Equipment), ".ctor");
                 *
                 * hInstance.Patch(Equipment_ctor_0, null, new HarmonyMethod(typeof(Equipment_Constructor_Patch), "Postfix"));
                 */
                /*
                 * hInstance.Patch(typeof(Equipment).GetMethod("GetSlotType"),
                 * new HarmonyMethod(typeof(Equipment_GetSlotType_Patch), "Prefix"));
                 */



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

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

                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(Hoverbike).GetMethod("Awake",
                                                            BindingFlags.NonPublic |
                                                            BindingFlags.Instance |
                                                            BindingFlags.SetField),
                                new HarmonyMethod(typeof(Hoverbike_Awake_Patch), "Prefix"));

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


                hInstance.Patch(typeof(Exosuit).GetMethod("Awake"), null,
                                new HarmonyMethod(typeof(Exosuit_Awake_Patch), "Postfix"));

                hInstance.Patch(typeof(Inventory).GetMethod("UnlockDefaultEquipmentSlots",
                                                            BindingFlags.NonPublic |
                                                            BindingFlags.Instance), null,
                                new HarmonyMethod(typeof(Inventory_UnlockDefaultEquipmentSlots_Patch), "Postfix"));

                SceneManager.sceneLoaded += new UnityAction <Scene, LoadSceneMode>(OnSceneLoaded);

                //BZLogger.Debug("SlotExtenderZero", "Main.Load(): Added action OnSceneLoaded to SceneManager.sceneLoaded event.");

                // add console command for configuration window
                //commandRoot = new CommandRoot("SEzConfigGO");
                //commandRoot.AddCommand<SEzCommand>();

                //CoroutineHost.StartCoroutine(WaitForUGUI());

                IngameMenuHandler.Main.RegisterOnQuitEvent(OnQuitEvent);
            }
            catch (Exception ex)
            {
                Debug.LogException(ex);
            }
        }