コード例 #1
0
        internal static void Config_CreateDefault()
        {
            SNLogger.Debug("LaserCannon", "Method call: LaserCannonConfig.Config_CreateDefault()");

            SNLogger.Warn("LaserCannon", "Configuration file is missing or wrong version. Trying to create a new one.");

            try
            {
                ParserHelper.CreateDefaultConfigFile(FILENAME, "LaserCannon", PROGRAM_VERSION, DEFAULT_CONFIG);

                var configParser = new Parser(FILENAME);

                foreach (string language in Languages)
                {
                    if (!configParser.AddNewSection(language))
                    {
                        continue;
                    }

                    foreach (string item in SECTION_LANGUAGE)
                    {
                        configParser.SetKeyValueInSection(language, item, "");
                    }
                }

                SNLogger.Log("LaserCannon", "The new configuration file was successfully created.");
            }
            catch
            {
                SNLogger.Error("LaserCannon", "An error occured while creating the new configuration file!");
            }
        }
コード例 #2
0
        public static void GetResourceMaterial(string gameObjectPath, string meshName, int materialIndex, out Material material)
        {
            GameObject gameObject = Resources.Load <GameObject>(gameObjectPath);

            if (gameObject == null)
            {
                material = null;

                SNLogger.Error(Assembly.GetCallingAssembly().GetName().Name, $"GameObject not found in Resources at path [{gameObjectPath}]");

                return;
            }

            foreach (MeshRenderer meshRenderer in gameObject.GetComponentsInChildren <MeshRenderer>(true))
            {
                if (meshRenderer.name.Equals(meshName, StringComparison.CurrentCultureIgnoreCase))
                {
                    material = UnityEngine.Object.Instantiate(meshRenderer.materials[materialIndex]) as Material;

                    return;
                }
            }

            SNLogger.Error(Assembly.GetCallingAssembly().GetName().Name, $"Mesh not found in gameobject [{meshName}]");

            material = null;
        }
コード例 #3
0
        internal static void ReadConfig()
        {
            try
            {
                program_settings = ParserHelper.GetAllKeyValuesFromSection(FILENAME, "Program", SECTION_PROGRAM);

                for (int i = 0; i < ColorHelper.ColorNames.Length; i++)
                {
                    if (ColorHelper.ColorNames[i].Equals(program_settings["BeamColor"]))
                    {
                        beamColor = i;
                    }
                }

                language_settings = ParserHelper.GetAllKeyValuesFromSection(FILENAME, program_settings["Language"], SECTION_LANGUAGE);

                colorNames.Clear();

                foreach (KeyValuePair <string, string> item in language_settings)
                {
                    if (item.Key.StartsWith("Option_Color_"))
                    {
                        colorNames.Add(item.Value.ToString());
                    }
                }

                SNLogger.Log("LaserCannon", "Configuration loaded.");
            }
            catch
            {
                SNLogger.Error("LaserCannon", "An error occurred while loading the configuration file!");
            }
        }
コード例 #4
0
        private static bool CheckConfig()
        {
            if (!File.Exists(FILENAME))
            {
                SNLogger.Error("Configuration file open error!");
                return(false);
            }

            CONFIG_VERSION = ParserHelper.GetKeyValue(FILENAME, "QuickSlotExtender", "Version");

            if (!CONFIG_VERSION.Equals(PROGRAM_VERSION))
            {
                SNLogger.Error("Configuration file version error!");
                return(false);
            }

            if (!ParserHelper.CheckSectionKeys(FILENAME, SECTIONS[0], SECTION_Hotkeys))
            {
                SNLogger.Error($"Configuration {SECTIONS[0]} section error!");
                return(false);
            }

            if (!ParserHelper.CheckSectionKeys(FILENAME, SECTIONS[1], SECTION_Settings))
            {
                SNLogger.Error($"Configuration {SECTIONS[1]} section error!");
                return(false);
            }

            return(true);
        }
コード例 #5
0
        private static bool Config_Check()
        {
            SNLogger.Debug("Method call: SEConfig.Config_Check()");

            if (!File.Exists(FILENAME))
            {
                SNLogger.Error("Configuration file open error!");
                return(false);
            }

            CONFIG_VERSION = ParserHelper.GetKeyValue(FILENAME, "SlotExtender", "Version");

            if (!CONFIG_VERSION.Equals(PROGRAM_VERSION))
            {
                SNLogger.Error("Configuration file version error!");
                return(false);
            }

            if (!ParserHelper.CheckSectionKeys(FILENAME, "Hotkeys", SECTION_HOTKEYS))
            {
                SNLogger.Error("Configuration file [Hotkeys] section error!");
                return(false);
            }

            if (!ParserHelper.CheckSectionKeys(FILENAME, "Settings", SECTION_SETTINGS))
            {
                SNLogger.Error("Configuration file [Settings] section error!");
                return(false);
            }

            return(true);
        }
コード例 #6
0
        private static bool Config_Check()
        {
            SNLogger.Debug("CyclopsLaserCannon", "Method call: LaserCannonConfig.Config_Check()");

            if (!File.Exists(FILENAME))
            {
                SNLogger.Error("CyclopsLaserCannon", "Configuration file open error!");
                return(false);
            }

            CONFIG_VERSION = ParserHelper.GetKeyValue(FILENAME, "LaserCannon", "Version");

            if (!CONFIG_VERSION.Equals(PROGRAM_VERSION))
            {
                SNLogger.Error("CyclopsLaserCannon", "Configuration file version error!");
                return(false);
            }

            if (!ParserHelper.CheckSectionKeys(FILENAME, "Hotkeys", SECTION_PROGRAM))
            {
                SNLogger.Error("CyclopsLaserCannon", "Configuration file [Program] section error!");
                return(false);
            }

            if (!ParserHelper.CheckSectionKeys(FILENAME, "Settings", SECTION_LANGUAGE))
            {
                SNLogger.Error("CyclopsLaserCannon", "Configuration file [Language] section error!");
                return(false);
            }

            return(true);
        }
コード例 #7
0
        private bool CheckConfig()
        {
            if (!File.Exists(FILENAME))
            {
                SNLogger.Error(ProgramName, "Configuration file does not exists!");
                return(false);
            }

            CONFIG_VERSION = ParserHelper.GetKeyValue(FILENAME, ProgramName, "Version");

            if (!CONFIG_VERSION.Equals(PROGRAM_VERSION))
            {
                SNLogger.Error(ProgramName, "Configuration file version error!");
                return(false);
            }

            foreach (ConfigDataNew configData in DEFAULT_CONFIG)
            {
                if (!ParserHelper.CheckSectionKeys(FILENAME, configData.Section, configData.Keys))
                {
                    SNLogger.Error(ProgramName, $"Configuration file [{configData.Section}] section error!");
                    return(false);
                }
            }

            return(true);
        }
コード例 #8
0
        internal static void ReadConfig()
        {
            try
            {
                program_settings  = ParserHelper.GetAllKeyValuesFromSection(FILENAME, "Program", SECTION_PROGRAM);
                language_settings = ParserHelper.GetAllKeyValuesFromSection(FILENAME, program_settings["Language"], SECTION_LANGUAGE);

                SNLogger.Log("CyclopsLaserCannon", "Configuration loaded.");
            }
            catch
            {
                SNLogger.Error("CyclopsLaserCannon", "An error occurred while loading the configuration file!");
            }
        }
コード例 #9
0
        internal static void CreateDefaultConfigFile()
        {
            SNLogger.Warn("RuntimeHelper", "Configuration file is missing or wrong version. Trying to create a new one.");

            try
            {
                ParserHelper.CreateDefaultConfigFile(FILENAME, "RuntimeHelper", PROGRAM_VERSION, DEFAULT_CONFIG);
                SNLogger.Log("RuntimeHelper", "The new configuration file was successfully created.");
            }
            catch
            {
                SNLogger.Error("RuntimeHelper", "An error occured while creating the new configuration file!");
            }
        }
コード例 #10
0
        internal static void Config_Load()
        {
            SNLogger.Debug("Method call: SEConfig.Config_Load()");

            PROGRAM_VERSION = FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location).FileVersion;

            if (!Config_Check())
            {
                Config_CreateDefault();
            }

            try
            {
                Hotkeys_Config = ParserHelper.GetAllKeyValuesFromSection(FILENAME, "Hotkeys", SECTION_HOTKEYS);

                int.TryParse(ParserHelper.GetKeyValue(FILENAME, "Settings", SECTION_SETTINGS[0]), out int result);
                MAXSLOTS = result < 5 || result > 12 ? 12 : result;

                EXTRASLOTS = SEConfig.MAXSLOTS - 4;

                TEXTCOLOR = ColorHelper.GetColor(ParserHelper.GetKeyValue(FILENAME, "Settings", SECTION_SETTINGS[1]));

                if (ReflectionHelper.IsNamespaceExists("SeamothStorageSlots"))
                {
                    STORAGE_SLOTS_OFFSET = 0; // don't patch storages stuff if SeamothStorageSlots mod is active
                    const string msg = "<i>SeamothStorageSlots</i> mod is now merged into SlotExtender, you can safely delete it.";

                    Type       qmmServices = Type.GetType("QModManager.API.QModServices, QModInstaller", false);
                    MethodInfo qmmMain     = qmmServices?.GetProperty("Main")?.GetGetMethod();
                    qmmServices?.GetMethod("AddCriticalMessage")?.Invoke(qmmMain.Invoke(null, null), new object[] { msg, 25, "yellow", true });
                }
                else
                {
                    int.TryParse(ParserHelper.GetKeyValue(FILENAME, "Settings", SECTION_SETTINGS[2]), out result);
                    STORAGE_SLOTS_OFFSET = result < 3 ? 0 : result > 8 ? 8 : result;
                }

                SLOT_LAYOUT = ParserHelper.GetKeyValue(FILENAME, "Settings", SECTION_SETTINGS[3]) == "Circle"? SlotLayout.Circle : SlotLayout.Grid;

                isSeamothArmsExists = ReflectionHelper.IsNamespaceExists("SeamothArms");

                SNLogger.Log("Configuration loaded.");
            }
            catch
            {
                SNLogger.Error("An error occurred while loading the configuration file!");
            }
        }
コード例 #11
0
        internal static void CreateDefaultConfigFile()
        {
            SNLogger.Warn("Configuration file is missing or wrong version. Trying to create a new one.");

            try
            {
                ParserHelper.CreateDefaultConfigFile(FILENAME, "QuickSlotExtender", PROGRAM_VERSION, DEFAULT_CONFIG);
                ParserHelper.AddInfoText(FILENAME, "TextColor possible values", "LightBlue, Red, Green, Blue, Yellow, White, Magenta, Cyan, Orange, Lime, Amethyst");

                SNLogger.Log("The new configuration file was successfully created.");
            }
            catch
            {
                SNLogger.Error("An error occured while creating the new configuration file!");
            }
        }
コード例 #12
0
ファイル: Main.cs プロジェクト: Senna7608/SennaSubnauticaMods
        public static void Load()
        {
            SNLogger.Debug("Method call: Main.Load()");

            try
            {
                SEConfig.Config_Load();
                SlotHelper.InitSlotIDs();
                SlotHelper.ExpandSlotMapping();

                hInstance = new Harmony("Subnautica.SlotExtender.mod");

                SNLogger.Debug($"Main.Load(): Harmony Instance created, Name = [{hInstance.Id}]");

                hInstance.PatchAll(Assembly.GetExecutingAssembly());

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

                SNLogger.Debug("Main.Load(): Added OnSceneLoaded method to SceneManager.sceneLoaded event.");

                //add console commad for configuration window
                commandRoot = new CommandRoot("SEConfigGO");
                commandRoot.AddCommand <SECommand>();

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

            // check MoreQuickSlots namespace is exists
            if (ReflectionHelper.IsNamespaceExists("MoreQuickSlots"))
            {
                SNLogger.Log("MoreQuickSlots namespace is exist! Trying to install a Cross-MOD patch...");

                // if yes construct a Harmony patch
                if (MQS_Patches.InitPatch(hInstance))
                {
                    SNLogger.Log("MoreQuickSlots Cross-MOD patch installed!");
                }
                else
                {
                    SNLogger.Error("MoreQuickSlots Cross-MOD patch install failed!");
                }
            }
        }
コード例 #13
0
        private static bool Config_Check()
        {
            SNLogger.Debug("CheatManager", "Method call: CmConfig.Config_Check()");

            if (!File.Exists(FILENAME))
            {
                SNLogger.Error("CheatManager", "Configuration file open error!");
                return(false);
            }

            CONFIG_VERSION = ParserHelper.GetKeyValue(FILENAME, "CheatManager", "Version");

            if (!CONFIG_VERSION.Equals(PROGRAM_VERSION))
            {
                SNLogger.Error("CheatManager", "Configuration file version error!");
                return(false);
            }

            if (!ParserHelper.CheckSectionKeys(FILENAME, "Hotkeys", SECTION_HOTKEYS))
            {
                SNLogger.Error("CheatManager", "Configuration file [Hotkeys] section error!");
                return(false);
            }

            if (!ParserHelper.CheckSectionKeys(FILENAME, "Program", SECTION_PROGRAM))
            {
                SNLogger.Error("CheatManager", "Configuration file [Program] section error!");
                return(false);
            }

            if (!ParserHelper.CheckSectionKeys(FILENAME, "Settings", SECTION_SETTINGS))
            {
                SNLogger.Error("CheatManager", "Configuration file [Settings] section error!");
                return(false);
            }

            if (!ParserHelper.CheckSectionKeys(FILENAME, "ToggleButtons", SECTION_TOGGLEBUTTONS))
            {
                SNLogger.Error("CheatManager", "Configuration file [ToggleButtons] section error!");
                return(false);
            }

            return(true);
        }
コード例 #14
0
        internal static void Config_CreateDefault()
        {
            SNLogger.Debug("CheatManager", "Method call: CmConfig.Config_CreateDefault()");

            SNLogger.Warn("CheatManager", "Configuration file is missing or wrong version. Trying to create a new one.");

            try
            {
                ParserHelper.CreateDefaultConfigFile(FILENAME, "CheatManager", PROGRAM_VERSION, DEFAULT_CONFIG);

                ParserHelper.AddInfoText(FILENAME, "OverPowerMultiplier and HungerAndThirstInterval possible values", "1 to 10");

                SNLogger.Log("CheatManager", "The new configuration file was successfully created.");
            }
            catch
            {
                SNLogger.Error("CheatManager", "An error occured while creating the new configuration file!");
            }
        }
コード例 #15
0
ファイル: Main.cs プロジェクト: Senna7608/SennaSubnauticaMods
        private static bool LoadAssets()
        {
            try
            {
                assetBundle = AssetBundle.LoadFromFile($"{modFolder}/Assets/laser_sounds");

                Texture2D cannon_Button = ImageUtils.LoadTextureFromFile($"{modFolder}/Assets/cannon_Button.png");

                buttonSprite = Sprite.Create(cannon_Button, new Rect(0, 0, cannon_Button.width, cannon_Button.height), new Vector2(cannon_Button.width * 0.5f, cannon_Button.height * 0.5f));

                GetResourceMaterial("worldentities/doodads/precursor/precursorteleporter", "precursor_interior_teleporter_02_01", 0, out cannon_material);

                cannon_material.name = "cannon_material";

                return(true);
            }
            catch
            {
                SNLogger.Error("CyclopsLaserCannon", "Loading assets failed!");
                return(false);
            }
        }
コード例 #16
0
        internal static void Config_CreateDefault()
        {
            SNLogger.Debug("Method call: SEConfig.Config_CreateDefault()");

            SNLogger.Warn("Configuration file is missing or wrong version. Trying to create a new one.");

            try
            {
                ParserHelper.CreateDefaultConfigFile(FILENAME, "SlotExtender", PROGRAM_VERSION, DEFAULT_CONFIG);

                ParserHelper.AddInfoText(FILENAME, "MaxSlots possible values", "5 to 12");
                ParserHelper.AddInfoText(FILENAME, "TextColor possible values", "Red, Green, Blue, Yellow, White, Magenta, Cyan, Orange, Lime, Amethyst, LightBlue");
                ParserHelper.AddInfoText(FILENAME, "SeamothStorageSlotsOffset possible values", "0 to 8");
                ParserHelper.AddInfoText(FILENAME, "SlotLayout possible values", "Grid, Circle");


                SNLogger.Log("The new configuration file was successfully created.");
            }
            catch
            {
                SNLogger.Error("An error occured while creating the new configuration file!");
            }
        }
コード例 #17
0
        public virtual void Patch()
        {
            Atlas.Sprite atlasSprite = null;

            if (IconFilePath != null)
            {
                try
                {
                    atlasSprite = ImageUtils.LoadSpriteFromFile(IconFilePath);
                }
                catch
                {
                    SNLogger.Error(NameID, $"File [{IconFilePath}] not Found!");
                }
            }
            else if (IconTechType != TechType.None)
            {
                try
                {
                    atlasSprite = GetResourceIcon(IconTechType);
                }
                catch
                {
                    SNLogger.Error(NameID, $"Resource TechType icon [{IconTechType.ToString()}] not Found!");
                }
            }
            else
            {
                try
                {
                    atlasSprite = GetResourceIcon(PrefabTemplate);
                }
                catch
                {
                    SNLogger.Error(NameID, $"Resource template icon [{PrefabTemplate.ToString()}] not Found!");
                }
            }

            TechType = TechTypeHandler.Main.AddTechType(NameID, FriendlyName, Description, atlasSprite, false);

            PrefabHandler.Main.RegisterPrefab(this);
            CraftDataHandler.Main.SetTechData(TechType, GetRecipe());
            SpriteHandler.Main.RegisterSprite(TechType, atlasSprite);
            CraftDataHandler.Main.SetItemSize(TechType, ItemSize);
            CraftDataHandler.Main.AddToGroup(GroupForPDA, CategoryForPDA, TechType);
            CraftDataHandler.Main.SetEquipmentType(TechType, TypeForEquipment);
            CraftDataHandler.Main.SetQuickSlotType(TechType, TypeForQuickslot);
            CraftDataHandler.Main.SetBackgroundType(TechType, BackgroundType);

            EncyData encyData = GetEncyclopediaData();

            if (encyData != null)
            {
                isEncyExists = true;

                PDAEncyclopedia.EntryData entryData = new PDAEncyclopedia.EntryData()
                {
                    key      = ClassID,
                    path     = EncyHelper.GetEncyPath(encyData.node),
                    nodes    = EncyHelper.GetEncyNodes(encyData.node),
                    unlocked = false,
                    popup    = GetUnitySprite(atlasSprite),
                    image    = encyData.image,
                    audio    = null,
                };

                PDAEncyclopediaHandler.Main.AddCustomEntry(entryData);

                LanguageHandler.Main.SetLanguageLine($"Ency_{ClassID}", encyData.title);
                LanguageHandler.Main.SetLanguageLine($"EncyDesc_{ClassID}", encyData.description);
            }

            if (RequiredForUnlock == TechType.None && _Fragment != null)
            {
                PDAScanner.EntryData scannerEntryData = new PDAScanner.EntryData()
                {
                    key              = _Fragment.TechType,
                    blueprint        = TechType,
                    destroyAfterScan = _Fragment.DestroyAfterScan,
                    encyclopedia     = isEncyExists ? ClassID : null,
                    isFragment       = true,
                    locked           = false,
                    scanTime         = _Fragment.ScanTime,
                    totalFragments   = _Fragment.TotalFragments
                };

                PDAHandler.Main.AddCustomScannerEntry(scannerEntryData);

                KnownTechHandler.Main.SetAnalysisTechEntry(TechType, new TechType[1] {
                    TechType
                }, GetUnitySprite(_Fragment.UnlockSprite));
            }
            else
            {
                KnownTechHandler.Main.SetAnalysisTechEntry(RequiredForUnlock, new TechType[1] {
                    TechType
                }, $"{FriendlyName} blueprint discovered!");
            }

            if (NewTabNode != null)
            {
                CraftTreeHandler.Main.AddTabNode(NewTabNode.craftTree, NewTabNode.uniqueName, NewTabNode.displayName, NewTabNode.sprite);
            }

            for (int i = 0; i < FabricatorTypes.Length; i++)
            {
                if (FabricatorTabs == null)
                {
                    CraftTreeHandler.Main.AddCraftingNode(FabricatorTypes[i], TechType);
                }
                else
                {
                    CraftTreeHandler.Main.AddCraftingNode(FabricatorTypes[i], TechType, FabricatorTabs[i]);
                }
            }
        }
コード例 #18
0
        public virtual void Patch()
        {
            PrefabHandler.Main.RegisterPrefab(this);

            Atlas.Sprite sprite = null;

            if (IconFilePath != null)
            {
                try
                {
                    sprite = ImageUtils.LoadSpriteFromFile(IconFilePath);
                }
                catch
                {
                    SNLogger.Error(NameID, $"File [{IconFilePath}] not Found!");
                }
            }
            else if (IconTechType != TechType.None)
            {
                try
                {
                    sprite = GetResourceIcon(IconTechType);
                }
                catch
                {
                    SNLogger.Error(NameID, $"Resource TechType icon [{IconTechType.ToString()}] not Found!");
                }
            }
            else
            {
                try
                {
                    sprite = GetResourceIcon(PrefabTemplate);
                }
                catch
                {
                    SNLogger.Error(NameID, $"Resource template icon [{PrefabTemplate.ToString()}] not Found!");
                }
            }

            TechType = TechTypeHandler.Main.AddTechType(NameID, FriendlyName, Description, sprite, false);

            SpriteHandler.Main.RegisterSprite(TechType, sprite);

            if (NewTabNode != null)
            {
                CraftTreeHandler.Main.AddTabNode(NewTabNode.craftTree, NewTabNode.uniqueName, NewTabNode.displayName, NewTabNode.sprite);
            }

            for (int i = 0; i < FabricatorTypes.Length; i++)
            {
                if (FabricatorTabs == null)
                {
                    CraftTreeHandler.Main.AddCraftingNode(FabricatorTypes[i], TechType);
                }
                else
                {
                    CraftTreeHandler.Main.AddCraftingNode(FabricatorTypes[i], TechType, FabricatorTabs[i]);
                }
            }

            CraftDataHandler.Main.SetTechData(TechType, GetRecipe());
            CraftDataHandler.Main.AddToGroup(GroupForPDA, CategoryForPDA, TechType);
            CraftDataHandler.Main.SetEquipmentType(TechType, TypeForEquipment);
            CraftDataHandler.Main.SetQuickSlotType(TechType, TypeForQuickslot);
            CraftDataHandler.Main.SetItemSize(TechType, ItemSize);
            CraftDataHandler.Main.SetBackgroundType(TechType, BackgroundType);
            KnownTechHandler.Main.SetAnalysisTechEntry(RequiredForUnlock, new TechType[1] {
                TechType
            }, $"{FriendlyName} blueprint discovered!");
        }