private static void LoadMod(Mod mod, string msver) { // Check if mod already exists if (!LoadedMods.Contains(mod)) { // Create config folder if (!Directory.Exists(ConfigFolder + mod.ID)) { Directory.CreateDirectory(ConfigFolder + mod.ID); } if (mod.UseAssetsFolder) { if (!Directory.Exists(AssetsFolder + mod.ID)) { Directory.CreateDirectory(AssetsFolder + mod.ID); } } if (mod.LoadInMenu) { mod.OnMenuLoad(); ModSettings.LoadBinds(); } mod.compiledVersion = msver; LoadedMods.Add(mod); } else { ModConsole.Print(string.Format("<color=orange><b>Mod already loaded (or duplicated ID):</b></color><color=red><b>{0}</b></color>", mod.ID)); } }
private void LoadMod(Mod mod, string msver) { // Check if mod already exists if (!LoadedMods.Contains(mod)) { // Create config folder if (!Directory.Exists(ConfigFolder + mod.ID)) { Directory.CreateDirectory(ConfigFolder + mod.ID); } if (mod.UseAssetsFolder && !Directory.Exists(AssetsFolder + mod.ID)) { Directory.CreateDirectory(AssetsFolder + mod.ID); } try { if (mod.LoadInMenu) { mod.OnMenuLoad(); ModSettings_menu.LoadBinds(); } } catch (Exception e) { StackFrame frame = new StackTrace(e, true).GetFrame(0); string errorDetails = string.Format("{2}<b>Details: </b>{0} in <b>{1}</b>", e.Message, frame.GetMethod(), Environment.NewLine); ModConsole.Error(string.Format("Mod <b>{0}</b> throw an error!{1}", mod.ID, errorDetails)); ModConsole.Error(e.ToString()); UnityEngine.Debug.Log(e); } mod.compiledVersion = msver; LoadedMods.Add(mod); } else { ModConsole.Error(string.Format("<color=orange><b>Mod already loaded (or duplicated ID):</b></color><color=red><b>{0}</b></color>", mod.ID)); } }
void LoadMod(Mod mod, string msver, string fname = null) { // Check if mod already exists if (!LoadedMods.Contains(mod)) { if (mod.UseAssetsFolder && !Directory.Exists(Path.Combine(AssetsFolder, mod.ID))) { Directory.CreateDirectory(Path.Combine(AssetsFolder, mod.ID)); } mod.compiledVersion = msver; mod.fileName = fname; LoadedMods.Add(mod); // FRED TWEAK // Check if OnGUI, Update, FixedUpdate, SecondPassOnLoad (stupid name), OnSave and OnNewGame are override methods and add them to list if so. if (CheckEmptyMethod(mod, "OnGUI")) { ModMethods[0].Add(mod); } if (CheckEmptyMethod(mod, "Update")) { ModMethods[1].Add(mod); } if (CheckEmptyMethod(mod, "FixedUpdate")) { ModMethods[2].Add(mod); } if (CheckEmptyMethod(mod, "SecondPassOnLoad")) { ModMethods[3].Add(mod); } if (CheckEmptyMethod(mod, "OnSave")) { ModMethods[4].Add(mod); } if (CheckEmptyMethod(mod, "OnNewGame")) { ModMethods[5].Add(mod); } // FRED TWEAK try { if (mod.LoadInMenu && mod.fileName == null) { mod.OnMenuLoad(); } } catch (Exception e) { StackFrame frame = new StackTrace(e, true).GetFrame(0); ModConsole.Error($"Mod <b>{mod.ID}</b> throw an error!\n<b>Details: </b>{e.Message} in <b>{frame.GetMethod()}</b>"); ModConsole.Error(e.ToString()); System.Console.WriteLine(e); } if (File.Exists(GetMetadataFolder($"{mod.ID}.json"))) { mod.metadata = Newtonsoft.Json.JsonConvert.DeserializeObject <ModsManifest>(File.ReadAllText(GetMetadataFolder($"{mod.ID}.json"))); } } else { ModConsole.Error($"<color=orange><b>Mod with ID: <color=red>{mod.ID}</color> already loaded:</color></b>"); } }