Ejemplo n.º 1
0
        /// <summary>
        /// Saves all Screws for all Parts that should have Screws.
        /// You only call this once for ALL Parts that are in the Screwable[] array
        /// <para>EXAMPLE</para>
        /// <para>Screwable.SaveScrews(this,new Screwable[]{ exhaust_header_screwable, exhaust_muffler_screwable } , "mysave.txt");</para>
        /// </summary>
        /// <param name="mod">Your own mod class (usually "this")</param>
        /// <param name="screwableParts">array of Screwable parts to be save (all screwable from your mod in an array)</param>
        /// <param name="filename">the filename to be used as saveFile (this will be your mods config folder inside Mods + filename) example: Mods\Config\Mod Settings\SatsumaTurboCharger\mysave.txt</param>
        public static void SaveScrews(Mod mod, ScrewablePart[] screwableParts, string filename)
        {
            if (mod != null && screwableParts != null && filename != null)
            {
                SortedList <String, Screws> screwsList = new SortedList <String, Screws>();
                if (filename.Length <= 0)
                {
                    filename = "BOLTSAVE_DEFAULT_CHANGE-FILENAME IN SaveBolts.txt";
                    ModConsole.Warning(
                        "You set an empty filename when you used Bolts.SaveBolts(...).\n" +
                        "The name of the file was set as 'BOLTSAVE_DEFAULT_CHANGE-FILENAME IN SaveBolts.txt'.\n" +
                        "YOU HAVE TO CHANGE THIS, If you are not the mod maker, contact the mod maker and tell him he is dump!"
                        );
                }
                else if (!filename.EndsWith(".txt"))
                {
                    filename = filename + ".txt";
                }
                string savePath = (ModLoader.GetModConfigFolder(mod) + "\\" + filename);

                for (int i = 0; i < screwableParts.Length; i++)
                {
                    screwsList.Add(screwableParts[i].screws.partName, screwableParts[i].screws);
                }

                SaveLoad.SerializeSaveFile <SortedList <String, Screws> >(mod, screwsList, savePath);
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Loads all Screws for all Parts that should have Screws.
 /// You only call this once for ALL Parts that are in your mod
 /// <para>EXAMPLE</para>
 /// <para>Screwable.LoadScrews(this, "mysave.txt");</para>
 /// </summary>
 /// <param name="mod">Your own mod class (usually "this")</param>
 /// <param name="filename">the filename to be used as saveFile (this will be your mods config folder inside Mods + filename) example: Mods\Config\Mod Settings\SatsumaTurboCharger\mysave.txt</param>
 /// <returns>Will return SortedList or if no file has been found with "filename" inside ModsConfig folder will return null</returns>
 public static SortedList <String, Screws> LoadScrews(Mod mod, string filename)
 {
     try
     {
         string savePath = "";
         if (filename.Length <= 0)
         {
             filename = "BOLTSAVE_DEFAULT_CHANGE-FILENAME IN SaveBolts.txt";
             ModConsole.Warning(
                 "You set an empty filename when you used Bolts.SaveBolts(...).\n" +
                 "The name of the file was set as 'BOLTSAVE_DEFAULT_CHANGE-FILENAME IN SaveBolts.txt'.\n" +
                 "YOU HAVE TO CHANGE THIS, If you are not the mod maker, contact the mod maker and tell him he is dump!"
                 );
         }
         else if (!filename.EndsWith(".txt"))
         {
             filename = filename + ".txt";
         }
         savePath = (ModLoader.GetModConfigFolder(mod) + "\\" + filename);
         if (File.Exists(savePath))
         {
             string serializedData = File.ReadAllText(savePath);
             SortedList <String, Screws> screwsListSave = JsonConvert.DeserializeObject <SortedList <String, Screws> >(serializedData);
             return(screwsListSave);
         }
     }
     catch (System.NullReferenceException)
     {
         // error while trying to read SaveFile
         return(null);
     }
     // no save file exists.. //loading default save data.
     return(null);
 }
Ejemplo n.º 3
0
 // The function that's called when executing command
 public override void Run(string[] args)
 {
     if (args.Length == 2)
     {
         if (args[0].ToLower() == "create")
         {
             Mod mod = ModLoader.LoadedMods.Where(w => w.ID == args[1]).FirstOrDefault();
             if (mod != null)
             {
                 ManifestStuff.CreateManifest(mod);
             }
             else
             {
                 ModConsole.Error("Invalid ModID (ModID is case sensitive)");
             }
         }
         else if (args[0].ToLower() == "update")
         {
             Mod mod = ModLoader.LoadedMods.Where(w => w.ID == args[1]).FirstOrDefault();
             if (mod != null)
             {
                 ManifestStuff.UpdateManifest(mod);
             }
             else
             {
                 ModConsole.Error("Invalid ModID (ModID is case sensitive)");
             }
         }
     }
     else
     {
         ModConsole.Warning($"Usage: metadata <create|update> <ModID>");
     }
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Saves all Screws for all Parts that should have Screws.
        /// You only call this once for ALL Parts that are in the Screwable[] array
        /// <para>EXAMPLE</para>
        /// <para>Screwable.SaveScrews(this,new Screwable[]{ exhaust_header_screwable, exhaust_muffler_screwable } , "mysave.txt");</para>
        /// </summary>
        /// <param name="mod">Your own mod class (usually "this")</param>
        /// <param name="screwableParts">array of Screwable parts to be save (all screwable from your mod in an array)</param>
        /// <param name="filename">the filename to be used as saveFile (this will be your mods config folder inside Mods + filename) example: Mods\Config\Mod Settings\SatsumaTurboCharger\mysave.txt</param>
        public static void SaveScrews(Mod mod, ScrewablePart[] screwableParts, string filename)
        {
            if (mod != null && screwableParts != null && filename != null)
            {
                SortedList <String, Screws> screwsList = new SortedList <String, Screws>();
                if (filename.Length <= 0)
                {
                    filename = "SCREWSAVE_DEFAULT_CHANGE_FILENAME.txt";
                    ModConsole.Warning(
                        "You set an empty filename when you used SaveScrews(...).\n" +
                        "YOU HAVE TO CHANGE THIS, If you are not the mod maker, contact the mod maker!"
                        );
                }
                string savePath = (ModLoader.GetModConfigFolder(mod) + "\\" + filename);

                for (int i = 0; i < screwableParts.Length; i++)
                {
                    screwableParts[i].screws = screwableParts[i].screwableLogic.GetSaveInformation();
                    screwsList.Add(screwableParts[i].screws.partName, screwableParts[i].screws);
                }

                SaveLoad.SerializeSaveFile <SortedList <String, Screws> >(mod, screwsList, savePath);
            }
        }
        public override void OnMenuLoad()
        {
            ScrewablePartV2.version = this.Version;
            string availableVersion = this.Version;

            modsFolderFilePath   = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            dllFilePath          = Path.Combine(modsFolderFilePath, $"{ID}.dll");
            xmlFilePath          = Path.Combine(modsFolderFilePath, $"{ID}.xml");
            assetsBundleFilePath = Path.Combine(ModLoader.GetModAssetsFolder(this), assetsFile);

            old_dllFilePath          = dllFilePath.Replace(".dll", ".old_dll");
            old_xmlFilePath          = xmlFilePath.Replace(".xml", ".old_xml");
            old_assetsBundleFilePath = assetsBundleFilePath.Replace(".unity3d", ".old_unity3d");

            LoadSettingsSave();

            CheckForOldFiles();
            try
            {
                interfaceObject = GameObject.Find("Interface");
                interfaceActive = GameObject.Find("Quad 7");
                quad7           = GameObject.Find("InterfaceActive");
            }
            catch {}

            if (!serverReachable)
            {
                ModConsole.Warning($"{ID} could not reach the update server");
                LoadAssets();
                return;
            }

            if (!(bool)ignoreUpdatesSetting.Value)
            {
                try
                {
                    string responseJson = Helper.MakeGetRequest(GetLatestReleaseVersionUrl(Version));
                    UpdateCheckResponse updateCheckResponse = JsonConvert.DeserializeObject <UpdateCheckResponse>(responseJson);
                    availableVersion = updateCheckResponse.available;
                    switch (updateCheckResponse.message)
                    {
                    case "out-dated":
                        ModConsole.Warning($"ScrewablePartAPI outdated. version {updateCheckResponse.available} available");
                        SetMenuVisibility(false);
                        Helper.ShowCustom2ButtonMessage($"ScrewablePartAPI is outdated\n" +
                                                        $"version {updateCheckResponse.available} is available!!\n" +
                                                        $"Do you want to update automatically?\n" +
                                                        $"(Restart will be required)\n" +
                                                        $"This can break mods using outdated versions", "ScrewablePartAPI is outdated",
                                                        new UnityAction(delegate()
                        {
                            SetMenuVisibility(true);
                            LoadAssets();
                        }),
                                                        new UnityAction(delegate()
                        {
                            InstallVersion(updateCheckResponse.available);
                        }));
                        break;

                    case "up-to-date":
                        availableVersion = Version;
                        LoadAssets();
                        break;

                    default:
                        LoadAssets();
                        break;
                    }
                }
                catch (Exception ex)
                {
                    ModConsole.Error(ex.Message);
                    LoadAssets();
                }
            }
            else
            {
                LoadAssets();
            }
            GameObject mscLoaderInfo = GameObject.Find("MSCLoader Info");

            try
            {
                GameObject screwablePartMenuInfoTextObject = GameObject.Instantiate(GameObject.Find("MSCLoader Info Text"));
                screwablePartMenuInfoTextObject.name = "ScrewablePartAPI Info Text";
                screwablePartMenuInfoTextObject.transform.SetParent(mscLoaderInfo.transform);
                Text screwablePartMenuInfoText = screwablePartMenuInfoTextObject.GetComponent <Text>();
                screwablePartMenuInfoText.text =
                    $"{Name} <color=cyan>v{Version}</color> loaded! " +
                    $"({(Version == availableVersion ? "<color=lime>Up to date</color>" : "<color=red>Outdated</color>")})";
            }
            catch { }
        }
Ejemplo n.º 6
0
 /// <summary>
 /// Write warning log message.
 /// </summary>
 /// <param name="message">Message to write.</param>
 public static void Warning(string message)
 {
     _logFile?.WriteLine($"Warning: {message}");
     ModConsole.Warning(message);
 }
Ejemplo n.º 7
0
        /// <summary>
        /// Seeks for rule files (.mopconfig) in MOP config folder.
        /// </summary>
        void GetAndReadRules()
        {
            overrideUpdateCheck = false;

            try
            {
                // Find and .mopconfig files.
                DirectoryInfo   dir   = new DirectoryInfo(MOP.ModConfigPath);
                List <FileInfo> files = dir.GetFiles().Where(d => d.Name.EndsWith(".mopconfig")).ToList();
                // Load custom rule file.
                if (File.Exists($"{dir}/Custom.txt"))
                {
                    files.Add(new FileInfo($"{dir}/Custom.txt"));
                    ModConsole.Print("[MOP] User custom rule file found!");
                }

                if (files.Count == 0)
                {
                    ModConsole.Print($"[MOP] No rule files found.");
                    NewMessage("");
                    return;
                }

                string message = $"[MOP] Found {files.Count} rule file{(files.Count > 1 ? "s" : "")}!";
                if (files.Count == 69)
                {
                    message = message.Rainbowmize();
                }

                ModConsole.Print(message);

                int removed = 0;

                // Read rule files.
                foreach (FileInfo file in files)
                {
                    // Delete rules for mods that don't exist.
                    if (ModLoader.LoadedMods.Find(m => m.ID == Path.GetFileNameWithoutExtension(file.Name)) == null && file.Name != "Custom.txt")
                    {
                        if ((bool)MOP.NoDeleteRuleFiles.GetValue())
                        {
                            ModConsole.Print($"<color=yellow>[MOP] Skipped {file.Name} rule, " +
                                             $"because the corresponding mod is not present.</color>");
                            continue;
                        }
                        File.Delete(file.FullName);
                        ModConsole.Print($"<color=yellow>[MOP] Rule file {file.Name} has been deleted, " +
                                         $"because corresponding mod is not present.</color>");
                        removed++;
                        continue;
                    }

                    // Verify if the servercontent has that rule file.
                    // Some mod makers may include poorly configured rule files,
                    // that's why they have to be only provided by the server.
                    if (serverContent != null && (bool)MOP.VerifyRuleFiles.GetValue() && file.Name != "Custom.txt")
                    {
                        if (serverContent.Find(m => m.ID == Path.GetFileNameWithoutExtension(file.Name)) == null)
                        {
                            File.Delete(file.FullName);
                            ModConsole.Warning($"[MOP] Rule file {file.Name} has been deleted, because it couldn't be verified.");
                            removed++;
                            continue;
                        }
                    }

                    Rules.instance.RuleFileNames.Add(file.Name);
                    ReadRulesFromFile(file.FullName);
                }

                ModConsole.Print("<color=green>[MOP] Loading rule files done!</color>");
                NewMessage($"MOP: Loading {files.Count - removed} rule file{(files.Count - removed > 1 ? "s" : "")} done!");
            }
            catch (Exception ex)
            {
                ExceptionManager.New(ex, "RULE_FILES_READ_ERROR");
            }
        }
Ejemplo n.º 8
0
 public override void Run(string[] args)
 {
     if (args.Length > 0)
     {
         if (!setup)
         {
             setup = true;
             UnityEngine.Application.logMessageReceived += HandleLog;
         }
         if (args[0].ToLower() == "help")
         {
             ModConsole.Print($"<color=green><b>Available settings:</b></color>{Environment.NewLine}" +
                              $"<color=orange><b>mods</b></color>: log all errors from mod class{Environment.NewLine}" +
                              $"<color=orange><b>errors</b></color>: Show all errors from game{Environment.NewLine}" +
                              $"<color=orange><b>warnings</b></color>: Show all warnings from game{Environment.NewLine}" +
                              $"<color=orange><b>messages</b></color>: Show all messages from game{Environment.NewLine}" +
                              $"<color=orange><b>eveything</b></color>: Sets all above settings to [true|false]{Environment.NewLine}");
             return;
         }
         else if (args[0].ToLower() == "mods")
         {
             if (args.Length == 2)
             {
                 if (args[1].ToLower() == "true")
                 {
                     ModLoader.LogAllErrors = true;
                 }
                 else
                 {
                     ModLoader.LogAllErrors = false;
                 }
                 ModConsole.Print(string.Format("<color=orange>Log All errors for mods set to <b>{0}</b></color>", ModLoader.LogAllErrors));
             }
             else
             {
                 ModLoader.LogAllErrors = !ModLoader.LogAllErrors;
                 ModConsole.Print(string.Format("<color=orange>Log All errors for mods set to <b>{0}</b></color>", ModLoader.LogAllErrors));
             }
             return;
         }
         else if (args[0].ToLower() == "errors")
         {
             if (args.Length == 2)
             {
                 if (args[1].ToLower() == "true")
                 {
                     errors = true;
                 }
                 else
                 {
                     errors = false;
                 }
                 ModConsole.Print(string.Format("<color=orange>Log All errors set to <b>{0}</b></color>", errors));
             }
             else
             {
                 errors = !errors;
                 ModConsole.Print(string.Format("<color=orange>Log All errors set to <b>{0}</b></color>", errors));
             }
             return;
         }
         else if (args[0].ToLower() == "warnings")
         {
             if (args.Length == 2)
             {
                 if (args[1].ToLower() == "true")
                 {
                     warnings = true;
                 }
                 else
                 {
                     warnings = false;
                 }
                 ModConsole.Print(string.Format("<color=orange>Log All warnings set to <b>{0}</b></color>", warnings));
             }
             else
             {
                 warnings = !warnings;
                 ModConsole.Print(string.Format("<color=orange>Log All warnings set to <b>{0}</b></color>", warnings));
             }
             return;
         }
         else if (args[0].ToLower() == "messages")
         {
             if (args.Length == 2)
             {
                 if (args[1].ToLower() == "true")
                 {
                     messages = true;
                 }
                 else
                 {
                     messages = false;
                 }
                 ModConsole.Print(string.Format("<color=orange>Log All messages set to <b>{0}</b></color>", messages));
             }
             else
             {
                 messages = !messages;
                 ModConsole.Print(string.Format("<color=orange>Log All messages set to <b>{0}</b></color>", messages));
             }
             return;
         }
         else if (args[0].ToLower() == "everything")
         {
             if (args.Length == 2)
             {
                 if (args[1].ToLower() == "true")
                 {
                     messages = true;
                     warnings = true;
                     errors   = true;
                     ModLoader.LogAllErrors = true;
                     ModConsole.Print(string.Format("<color=orange>Log everything set to <b>true</b></color>"));
                 }
                 else
                 {
                     messages = false;
                     warnings = false;
                     errors   = false;
                     ModLoader.LogAllErrors = false;
                     ModConsole.Print(string.Format("<color=orange>Log everything set to <b>false</b></color>"));
                 }
             }
             else
             {
                 ModConsole.Warning("For <b>everything</b> specify [true|false]");
             }
             return;
         }
         else
         {
             ModConsole.Warning("<b>Usage:</b> log-all <mods|errors|warnings|messages|everything> [true|false]");
             ModConsole.Print("Use <color=orange><b>log-all help</b></color> for more info");
         }
     }
     else
     {
         ModConsole.Warning("<b>Usage:</b> log-all <mods|errors|warnings|messages|everything> [true|false]");
         ModConsole.Print("Use <color=orange><b>log-all help</b></color> for more info");
     }
 }