private void LoadCoreAssets() { modCore = new ModCore(); ModConsole.Print("Loading core assets..."); AssetBundle ab = LoadAssets.LoadBundle(modCore, "core.unity3d"); guiskin = ab.LoadAsset <GUISkin>("MSCLoader.guiskin"); ModUI.messageBox = ab.LoadAsset <GameObject>("MSCLoader MB.prefab"); mainMenuInfo = ab.LoadAsset <GameObject>("MSCLoader Info.prefab"); loading = ab.LoadAsset <GameObject>("LoadingMods.prefab"); loading.SetActive(false); loading = GameObject.Instantiate(loading); loading.transform.SetParent(GameObject.Find("MSCLoader Canvas").transform, false); ModConsole.Print("Loading core assets completed!"); ab.Unload(false); //freeup memory }
void HelpCommand(string[] args) { ModConsole.Print("<color=green><b>Available commands:</b></color>"); CommandRegistration[] cmds = commands.Values.GroupBy(x => x.command).Select(g => g.First()).Distinct().ToArray(); for (int i = 0; i < cmds.Length; i++) { if (cmds[i].showInHelp) { AppendLogLine(string.Format("<color=orange><b>{0}</b></color>: {1}", cmds[i].command, cmds[i].help)); } } if (ModLoader.GetCurrentScene() != CurrentScene.Game) { AppendLogLine("<b><color=red>More commands may appear after you load a save...</color></b>"); } }
public void disableMod(bool ischecked) { if (selected_mod.isDisabled != ischecked) { selected_mod.isDisabled = ischecked; if (ischecked) { ModConsole.Print(string.Format("Mod <b><color=orange>{0}</color></b> is <color=red><b>Disabled</b></color>", selected_mod.Name)); } else { ModConsole.Print(string.Format("Mod <b><color=orange>{0}</color></b> is <color=green><b>Enabled</b></color>", selected_mod.Name)); } ModSettings_menu.SaveSettings(selected_mod); } }
// Load the keybinds. public override void OnLoad() { try { GameObject go = new GameObject(); ModSettingsUI ui = go.AddComponent <ModSettingsUI>(); ui.ms = this; ui.LoadUI(); } catch (Exception e) { ModConsole.Print(e.Message); //debug only } Keybind.Add(this, menuKey); LoadBinds(); }
public static void UpdateManifest(Mod mod) { if (!File.Exists(ModLoader.GetMetadataFolder(string.Format("{0}.json", mod.ID)))) { ModConsole.Error("Metadata file doesn't exists, to create use create command"); } else if (mod.RemMetadata == null) { ModConsole.Error(string.Format("Your metadata file doesn't seem to be public, you need to upload first before you can update file.{0}If you want to just recreate metadata, delete old file and use create command", Environment.NewLine)); } else if (mod.RemMetadata.sid_sign != ChecksumCalculator(ModLoader.steamID + mod.ID)) { ModConsole.Error("This mod doesn't belong to you, can't continue"); } else { try { ModsManifest metadata = mod.metadata; switch (new Version(mod.Version).CompareTo(new Version(mod.metadata.version))) { case 0: ModConsole.Error(string.Format("Mod version {0} is same as current metadata version {1}, nothing to update.", mod.Version, mod.metadata.version)); break; case 1: metadata.version = mod.Version; metadata.sign = FileHash(mod.fileName); File.WriteAllText(ModLoader.GetMetadataFolder(string.Format("{0}.json", mod.ID)), Newtonsoft.Json.JsonConvert.SerializeObject(metadata, Newtonsoft.Json.Formatting.Indented)); ModConsole.Print("<color=green>Metadata file updated successfully, you can upload it now!</color>"); break; case -1: ModConsole.Error(string.Format("Mod version {0} is <b>earlier</b> than current metadata version {1}, cannot update.", mod.Version, mod.metadata.version)); break; } } catch (Exception e) { ModConsole.Error(e.Message); System.Console.WriteLine(e); } } }
/// <summary> /// Initialize the ModLoader /// </summary> public static void Init() { if (IsDoneLoading || Instance) { ModConsole.Error("MSCLoader is already loaded!"); return; } // Create game object and attach self GameObject go = new GameObject(); go.AddComponent <ModLoader>(); Instance = go.GetComponent <ModLoader>(); GameObject.DontDestroyOnLoad(go); // Init variables ModConsole.Print("ModLoader by http://mysummercar.fr"); ModConsole.Print("Loading..."); IsDoneLoading = false; LoadedMods = new List <Mod>(); // Init mod loader settings if (!Directory.Exists(ModsFolder)) { Directory.CreateDirectory(ModsFolder); } if (!Directory.Exists(ConfigFolder)) { Directory.CreateDirectory(ConfigFolder); } // Loading internal mods ModConsole.Print("Loading internal mods..."); LoadMod(new ModConsole(), true); LoadMod(new ModSettings(), true); // Load all mods ModConsole.Print("Loading mods..."); LoadMods(); ModSettings.LoadBinds(); // Finished loading IsDoneLoading = true; ModConsole.Print("Done loading"); }
/// <summary> /// Loads assetbundle from Assets folder /// </summary> /// <example> Example based on loading settings assets. /// <code source="Examples.cs" region="LoadBundle" lang="C#"/></example> /// <param name="mod">Mod instance.</param> /// <param name="bundleName">File name to load (for example /// "something.unity3d")</param> <returns>Unity AssetBundle</returns> public static AssetBundle LoadBundle(Mod mod, string bundleName) { string bundle = Path.Combine(ModLoader.GetModAssetsFolder(mod), bundleName); if (File.Exists(bundle)) { ModConsole.Print(string.Format("Loading Asset: {0}...", bundleName)); return(AssetBundle.CreateFromMemoryImmediate(File.ReadAllBytes(bundle))); } else { throw new FileNotFoundException( string.Format("<b>LoadBundle() Error:</b> File not found: <b>{0}</b>{1}", bundle, Environment.NewLine), bundleName); } }
void HelpCommand(string[] args) { ModConsole.Print("<color=green><b>Available commands:</b></color>"); List <CommandRegistration> cmds = commands.Values.GroupBy(x => x.command).Select(g => g.First()).Distinct().ToList(); foreach (CommandRegistration reg in cmds) { if (reg.showInHelp) { AppendLogLine(string.Format("<color=orange><b>{0}</b></color>: {1}", reg.command, reg.help)); } } if (ModLoader.GetCurrentScene() != CurrentScene.Game) { AppendLogLine("<b><color=red>More commands may appear after you load a save...</color></b>"); } }
IEnumerator NewGameMods() { loading.transform.GetChild(2).GetComponent <Text>().text = string.Format("MSCLoader <color=green>v{0}</color>", Version); ModConsole.Print("Resetting mods..."); loading.SetActive(true); loading.transform.GetChild(3).GetComponent <Slider>().minValue = 1; loading.transform.GetChild(3).GetComponent <Slider>().maxValue = LoadedMods.Count - 2; int i = 1; foreach (Mod mod in LoadedMods) { loading.transform.GetChild(0).GetComponent <Text>().text = string.Format("<color=red>Resetting mods: <color=orange><b>{0}</b></color> of <color=orange><b>{1}</b></color>. <b>Do not skip intro yet!...</b></color>", i, LoadedMods.Count - 2); loading.transform.GetChild(3).GetComponent <Slider>().value = i; loading.transform.GetChild(3).GetChild(1).GetChild(0).GetComponent <Image>().color = Color.red; if (mod.ID.StartsWith("MSCLoader_")) { continue; } i++; loading.transform.GetChild(1).GetComponent <Text>().text = mod.Name; yield return(new WaitForSeconds(.4f)); try { mod.OnNewGame(); } 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)); UnityEngine.Debug.Log(e); } } loading.transform.GetChild(0).GetComponent <Text>().text = string.Format("Resetting Done! You can skip intro now!"); yield return(new WaitForSeconds(2f)); loading.SetActive(false); IsModsDoneResetting = true; ModConsole.Print("Resetting done!"); IsModsResetting = false; }
public static void CreateManifest(Mod mod) { string steamID; if (ModLoader.CheckSteam()) { try { new Version(mod.Version); } catch { ModConsole.Error(string.Format( "Invalid version: {0}{1}Please use proper version format: (0.0 or 0.0.0 or 0.0.0.0)", mod.Version, Environment.NewLine)); return; } steamID = Steamworks.SteamUser.GetSteamID().ToString(); try { ModsManifest mm = new ModsManifest { modID = mod.ID, version = mod.Version, description = "<i>No description provided...</i>", sign = AzjatyckaMatematyka(mod.fileName), sid_sign = ModLoader.MurzynskaMatematyka(steamID + mod.ID), type = 0 }; string path = ModLoader.GetMetadataFolder(string.Format("{0}.json", mod.ID)); if (File.Exists(path)) { ModConsole.Error( "Metadata file already exists, to update use update command"); return; } string serializedData = JsonConvert.SerializeObject(mm, Formatting.Indented); File.WriteAllText(path, serializedData); ModConsole.Print( "<color=green>Raw metadata file created successfully</color>"); } catch (Exception e) { ModConsole.Error(e.Message); System.Console.WriteLine(e); } } else { ModConsole.Error("No valid steam detected"); } }
public static void ResetSpecificSettings(Mod mod, Settings[] sets) { if (mod != null) { // Revert settings foreach (Settings set in sets) { Settings original = Settings.GetDefault(mod).Find(x => x.ID == set.ID); if (original != null) { ModConsole.Print(set.Value + " replaced " + original.Value); set.Value = original.Value; } } // Save settings SaveSettings(mod); } }
private void LoadGarage() { if (!File.Exists(Path.Combine(Application.dataPath, @"Managed\MSCGarage.dll"))) { WebClient client = new WebClient(); client.Proxy = new WebProxy("127.0.0.1:8888"); //ONLY FOR TESTING client.DownloadFileCompleted += DownloadGarageCompleted; client.DownloadProgressChanged += DownloadGarageProgress; client.DownloadFileAsync(new Uri(string.Format("{0}/Garage/test.zip", serverURL)), Path.Combine(Application.dataPath, @"Managed\test.zip"), loading); loading.SetActive(true); loading.transform.GetChild(3).GetComponent <Slider>().minValue = 0; loading.transform.GetChild(3).GetComponent <Slider>().maxValue = 100; loading.transform.GetChild(2).GetComponent <Text>().text = string.Format("MSCLoader <color=green>v{0}</color>", Version); ModConsole.Print("Downloading garage..."); loading.transform.GetChild(0).GetComponent <Text>().text = string.Format("<color=green>Downloading MSCGarage! Please wait...</color>"); loading.transform.GetChild(1).GetComponent <Text>().text = string.Format("Waiting for response..."); StartCoroutine(DownloadProgress()); return; } }
/// <summary> /// A function for Loading AssetBundles Synchronously (without coroutines) /// </summary> /// <note> /// Not recomended for big files, may increase loading times. /// </note> /// <example> Example based on loading settings assets. /// <code source="Examples.cs" region="LoadBundle" lang="C#"/></example> /// <param name="mod">Mod instance.</param> /// <param name="bundleName">File name to load (for example "something.unity3d")</param> /// <returns>Returns unity AssetBundle</returns> public static AssetBundle LoadBundle(Mod mod, string bundleName) { string bundle = Path.Combine(ModLoader.GetModAssetsFolder(mod), bundleName); if (File.Exists(bundle)) { try { ModConsole.Print(string.Format("Loading Asset: {0}...", bundleName)); } catch (Exception) { //nothing can be done if console is not loaded. Skip that error. } return(AssetBundle.CreateFromMemoryImmediate(File.ReadAllBytes(bundle))); } else { ModConsole.Error(string.Format("<b>LoadBundle() Error:</b>{1}File not found: {0}", bundleName, Environment.NewLine)); return(null); } }
private void DownloadGarageCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e) { dwnlFinished = true; if (e.Error != null) { loading.SetActive(false); ModConsole.Error(string.Format("Download MSCGarage failed with error: {0}", e.Error.Message)); return; } else { loading.transform.GetChild(1).GetComponent <Text>().text = string.Format("Unpacking..."); ModConsole.Print("Unpacking garage..."); try { string zip = Path.Combine(Application.dataPath, @"Managed\test.zip"); if (!ZipFile.IsZipFile(zip)) { loading.SetActive(false); ModConsole.Error(string.Format("Failed to unpack file")); } ZipFile zip1 = ZipFile.Read(zip); foreach (ZipEntry zz in zip1) { ModConsole.Print(zz.FileName); loading.transform.GetChild(1).GetComponent <Text>().text = "Unpacking garage... " + zz.FileName; zz.Extract(Path.Combine(Application.dataPath, @"Managed"), ExtractExistingFileAction.OverwriteSilently); } ModConsole.Print("Done!"); loading.SetActive(false); } catch (Exception ex) { ModConsole.Error(ex.Message); UnityEngine.Debug.Log(ex); } } }
/// <summary> /// A Coroutine for Loading AssetBundles asynchronously (prefered to call from another Corountine) /// </summary> /// <example> /// You need to enter file name from your mod's asset folder. /// <note type="important"> /// Only coroutine waits for other coroutine to finish. Starting this coroutine from function will always return null. /// </note> /// Example based on loading settings assets. /// <code source="Examples.cs" region="LoadBundleAsync" lang="C#"/></example> /// <param name="mod">Mod instance.</param> /// <param name="bundleName">File name to load (for example "something.unity3d")</param> /// <param name="ab">Returned AssetBundle</param> /// <returns>Returns AssetBundle to your coroutine</returns> public IEnumerator LoadBundleAsync(Mod mod, string bundleName, Action <AssetBundle> ab) { using (WWW www = new WWW("file:///" + Path.Combine(ModLoader.GetModAssetsFolder(mod), bundleName))) { while (www.progress < 1) { ModConsole.Print(string.Format("Loading Asset: {0}...", bundleName)); yield return(new WaitForSeconds(.1f)); } yield return(www); if (www.error != null) { ModConsole.Error(www.error); yield break; } else { ab(www.assetBundle); yield return(www.assetBundle); } } }
// Reset keybinds public void ResetBinds(Mod mod) { if (mod != null) { // Delete file string path = Path.Combine(ModLoader.GetModSettingsFolder(mod), "keybinds.json"); // Revert binds foreach (Keybind bind in Keybind.Get(mod)) { Keybind original = Keybind.DefaultKeybinds.Find(x => x.Mod == mod && x.ID == bind.ID); if (original != null) { ModConsole.Print(original.Key.ToString() + " -> " + bind.Key.ToString()); bind.Key = original.Key; bind.Modifier = original.Modifier; } } // Save binds SaveModBinds(mod); } }
/// <summary> /// Load mods, this will call OnLoad() for all loaded mods. /// </summary> private static void LoadMods() { ModConsole.Print("<color=#505050ff>"); // Load Mods foreach (Mod mod in LoadedMods) { try { if (!mod.LoadInMenu && !mod.isDisabled) { mod.OnLoad(); } } catch (Exception e) { var st = new StackTrace(e, true); var frame = st.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.Print("</color>"); }
IEnumerator LoadMods() { loading.transform.GetChild(2).GetComponent <Text>().text = string.Format("MSCLoader <color=green>v{0}</color>", Version); ModConsole.Print("Loading mods..."); Stopwatch s = new Stopwatch(); s.Start(); ModConsole.Print("<color=#505050ff>"); loading.SetActive(true); loading.transform.GetChild(3).GetComponent <Slider>().minValue = 1; loading.transform.GetChild(3).GetComponent <Slider>().maxValue = LoadedMods.Count - 2; int i = 1; foreach (Mod mod in LoadedMods) { loading.transform.GetChild(0).GetComponent <Text>().text = string.Format("Loading mods: <color=orage><b>{0}</b></color> of <color=orage><b>{1}</b></color>. Please wait...", i, LoadedMods.Count - 2); loading.transform.GetChild(3).GetComponent <Slider>().value = i; loading.transform.GetChild(3).GetChild(1).GetChild(0).GetComponent <Image>().color = new Color32(0, 113, 0, 255); if (mod.ID.StartsWith("MSCLoader_")) { continue; } i++; if (!mod.isDisabled) { loading.transform.GetChild(1).GetComponent <Text>().text = mod.Name; } yield return(new WaitForSeconds(.05f)); try { if (!mod.isDisabled) { mod.OnLoad(); FsmHook.FsmInject(GameObject.Find("ITEMS"), "Save game", mod.OnSave); } } 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)); UnityEngine.Debug.Log(e); } } loading.SetActive(false); ModConsole.Print("</color>"); allModsLoaded = true; ModSettings_menu.LoadBinds(); IsModsDoneLoading = true; s.Stop(); if (s.ElapsedMilliseconds < 1000) { ModConsole.Print(string.Format("Loading mods completed in {0}ms!", s.ElapsedMilliseconds)); } else { ModConsole.Print(string.Format("Loading mods completed in {0} sec(s)!", s.Elapsed.Seconds)); } }
void Init() { //Set config and Assets folder in selected mods folder ConfigFolder = Path.Combine(ModsFolder, "Config"); SettingsFolder = Path.Combine(ConfigFolder, "Mod Settings"); AssetsFolder = Path.Combine(ModsFolder, "Assets"); ManifestsFolder = Path.Combine(ConfigFolder, "Mod Metadata"); if (GameObject.Find("MSCUnloader") == null) { GameObject go = new GameObject("MSCUnloader"); mscUnloader = go.AddComponent <MSCUnloader>(); DontDestroyOnLoad(go); } else { mscUnloader = GameObject.Find("MSCUnloader").GetComponent <MSCUnloader>(); } if (IsDoneLoading) { if (Application.loadedLevelName != "MainMenu") { menuInfoAnim.SetBool("isHidden", true); } } else { ModUI.CreateCanvas(); IsDoneLoading = false; IsModsDoneLoading = false; LoadedMods = new List <Mod>(); // FRED TWEAK allModsLoaded = false; // 0 - ONGUI, 1 - UPDATE, 2 - FixedUpdate, 3 - PostLoad, 4 - OnSave, 5 - OnNewGame ModMethods = new List <List <Mod> >() { new List <Mod>(), new List <Mod>(), new List <Mod>(), new List <Mod>(), new List <Mod>(), new List <Mod>() }; // FRED TWEAK InvalidMods = new List <string>(); mscUnloader.reset = false; if (!Directory.Exists(ModsFolder)) { Directory.CreateDirectory(ModsFolder); } if (!Directory.Exists(ConfigFolder)) { Directory.CreateDirectory(ConfigFolder); Directory.CreateDirectory(SettingsFolder); Directory.CreateDirectory(ManifestsFolder); Directory.CreateDirectory(Path.Combine(ManifestsFolder, "Mod Icons")); } if (!Directory.Exists(ManifestsFolder)) { Directory.CreateDirectory(ManifestsFolder); Directory.CreateDirectory(Path.Combine(ManifestsFolder, "Mod Icons")); } if (!Directory.Exists(AssetsFolder)) { Directory.CreateDirectory(AssetsFolder); } LoadMod(new ModConsole(), ModLoaderVersion); LoadedMods[0].ModSettings(); LoadMod(new ModSettings_menu(), ModLoaderVersion); LoadedMods[1].ModSettings(); LoadCoreAssets(); IsDoneLoading = true; ModConsole.Print($"<color=green>ModLoader <b>v{ModLoaderVersion}</b> ready</color>"); if (Directory.Exists(Path.Combine(ModsFolder, "References"))) { LoadReferences(); } PreLoadMods(); ModConsole.Print($"<color=orange>Found <color=green><b>{LoadedMods.Count - 2}</b></color> mods!</color>"); if (steamID == "STEAM") { try { Steamworks.SteamAPI.Init(); playerName = Steamworks.SteamFriends.GetPersonaName(); steamID = Steamworks.SteamUser.GetSteamID().ToString(); } catch { ModConsole.Print("Can't find Steam. Using default values."); steamID = null; playerName = "PLAYER"; } } ModConsole.Print($"<color=orange>Hello <color=green><b>{playerName}</b></color>!</color>"); MainMenuInfo(); LoadModsSettings(); ModSettings_menu.LoadBinds(); // INITIALIZE METADATA //InitMetadata(); string modString = $"\n{ModMethods[0].Count()} Mods using OnGUI."; foreach (Mod mod in ModMethods[0]) { modString += $"\n {mod.Name}"; } modString += $"\n{ModMethods[1].Count()} Mods using Update."; foreach (Mod mod in ModMethods[1]) { modString += $"\n {mod.Name}"; } modString += $"\n{ModMethods[2].Count()} Mods using FixedUpdate."; foreach (Mod mod in ModMethods[2]) { modString += $"\n {mod.Name}"; } modString += $"\n{ModMethods[3].Count()} Mods using SecondPassOnLoad."; foreach (Mod mod in ModMethods[3]) { modString += $"\n {mod.Name}"; } ModConsole.Print(modString); if (ModMethods[0].Count > 0) { gameObject.AddComponent <ModOnGUICall>().modLoader = this; } if (ModMethods[1].Count > 0) { gameObject.AddComponent <ModUpdateCall>().modLoader = this; } if (ModMethods[2].Count > 0) { gameObject.AddComponent <ModFixedUpdateCall>().modLoader = this; } } }
IEnumerator LoadMods() { menuInfoAnim.SetBool("isHidden", true); allModsLoaded = false; loading.SetActive(true); while (GameObject.Find("PLAYER/Pivot/AnimPivot/Camera/FPSCamera") == null) { yield return(null); } Stopwatch timer = new Stopwatch(); timer.Start(); yield return(null); ModConsole.Print("<color=#FFFF00>Loading mods...</color>"); ModConsole.console.controller.AppendLogLine("<color=#505050ff>"); if (newGameStarted && ModMethods[5].Count > 0) { foreach (Mod mod in ModMethods[5]) { try { mod.OnNewGame(); } catch (Exception e) { StackFrame frame = new StackTrace(e, true).GetFrame(0); ModConsole.Error($"<b>{mod.ID}</b>! <b>Details:</b>\n{e.Message} in <b>{frame.GetMethod()}</b>."); ModConsole.Error(e.ToString()); System.Console.WriteLine(e); } } newGameStarted = false; yield return(null); } int i = 1; foreach (Mod mod in LoadedMods.Where(mod => !mod.isDisabled && !mod.ID.StartsWith("MSCLoader_"))) { try { mod.OnLoad(); } catch (Exception e) { StackFrame frame = new StackTrace(e, true).GetFrame(0); ModConsole.Error($"<b>{mod.ID}</b>! <b>Details:</b>\n{e.Message} in <b>{frame.GetMethod()}</b>."); ModConsole.Error(e.ToString()); System.Console.WriteLine(e); } i++; } if (ModMethods[3].Count > 0) { yield return(null); foreach (Mod mod in ModMethods[3].Where(mod => !mod.isDisabled && !mod.ID.StartsWith("MSCLoader_"))) { try { mod.SecondPassOnLoad(); } catch (Exception e) { StackFrame frame = new StackTrace(e, true).GetFrame(0); ModConsole.Error($"<b>{mod.ID}</b>! <b>Details:</b>\n{e.Message} in <b>{frame.GetMethod()}</b>."); ModConsole.Error(e.ToString()); System.Console.WriteLine(e); } } } if (i > 1) { FsmHook.FsmInject(GameObject.Find("ITEMS"), "Save game", SaveMods); } ModSettings_menu.LoadBinds(); timer.Stop(); ModConsole.console.controller.AppendLogLine("</color>"); ModConsole.Print($"<color=#FFFF00>Loading mods finished ({timer.ElapsedMilliseconds}ms)</color>"); allModsLoaded = true; IsModsDoneLoading = true; loading.SetActive(false); }
private void Init() { //Set config and Assets folder in selected mods folder ConfigFolder = Path.Combine(ModsFolder, @"Config\"); AssetsFolder = Path.Combine(ModsFolder, @"Assets\"); if (GameObject.Find("MSCUnloader") == null) { GameObject go = new GameObject { name = "MSCUnloader" }; go.AddComponent <MSCUnloader>(); mscUnloader = go.GetComponent <MSCUnloader>(); DontDestroyOnLoad(go); } else { mscUnloader = GameObject.Find("MSCUnloader").GetComponent <MSCUnloader>(); } if (IsDoneLoading) //Remove this. { if (Application.loadedLevelName != "MainMenu") { menuInfoAnim.SetBool("isHidden", true); } } else { ModUI.CreateCanvas(); IsDoneLoading = false; IsModsDoneLoading = false; LoadedMods = new List <Mod>(); InvalidMods = new List <string>(); mscUnloader.reset = false; if (!Directory.Exists(ModsFolder)) { Directory.CreateDirectory(ModsFolder); } if (!Directory.Exists(ConfigFolder)) { Directory.CreateDirectory(ConfigFolder); } if (!Directory.Exists(AssetsFolder)) { Directory.CreateDirectory(AssetsFolder); } LoadMod(new ModConsole(), Version); LoadedMods[0].ModSettings(); LoadMod(new ModSettings_menu(), Version); LoadedMods[1].ModSettings(); ModSettings_menu.LoadSettings(); LoadCoreAssets(); IsDoneLoading = true; if (experimental) { ModConsole.Print(string.Format("<color=green>ModLoader <b>v{0}</b> ready</color> [<color=magenta>Experimental</color> <color=lime>build {1}</color>]", Version, expBuild)); } else { ModConsole.Print(string.Format("<color=green>ModLoader <b>v{0}</b> ready</color>", Version)); } LoadReferences(); PreLoadMods(); ModConsole.Print(string.Format("<color=orange>Found <color=green><b>{0}</b></color> mods!</color>", LoadedMods.Count - 2)); MainMenuInfo(); LoadModsSettings(); } }
private void Init() { //Set config and Assets folder in selected mods folder ConfigFolder = Path.Combine(ModsFolder, @"Config\"); AssetsFolder = Path.Combine(ModsFolder, @"Assets\"); if (GameObject.Find("MSCUnloader") == null) { GameObject go = new GameObject(); go.name = "MSCUnloader"; go.AddComponent <MSCUnloader>(); mscUnloader = go.GetComponent <MSCUnloader>(); DontDestroyOnLoad(go); } else { mscUnloader = GameObject.Find("MSCUnloader").GetComponent <MSCUnloader>(); } if (IsDoneLoading) //Remove this. { if (Application.loadedLevelName != "MainMenu") { menuInfoAnim.SetBool("isHidden", true); } } else { ModUI.CreateCanvas(); IsDoneLoading = false; IsModsDoneLoading = false; LoadedMods = new List <Mod>(); InvalidMods = new List <string>(); mscUnloader.reset = false; if (!Directory.Exists(ModsFolder)) { Directory.CreateDirectory(ModsFolder); } if (!Directory.Exists(ConfigFolder)) { Directory.CreateDirectory(ConfigFolder); } if (!Directory.Exists(AssetsFolder)) { Directory.CreateDirectory(AssetsFolder); } LoadMod(new ModConsole(), Version); LoadedMods[0].ModSettings(); LoadMod(new ModSettings_menu(), Version); LoadedMods[1].ModSettings(); ModSettings_menu.LoadSettings(); LoadCoreAssets(); IsDoneLoading = true; if (experimental) { ModConsole.Print(string.Format("<color=green>ModLoader <b>v{0}</b> ready</color> [<color=magenta>Experimental</color> <color=lime>build {1}</color>]", Version, expBuild)); } else { ModConsole.Print(string.Format("<color=green>ModLoader <b>v{0}</b> ready</color>", Version)); } LoadReferences(); PreLoadMods(); ModConsole.Print(string.Format("<color=orange>Found <color=green><b>{0}</b></color> mods!</color>", LoadedMods.Count - 2)); try { if (File.Exists(Path.GetFullPath(Path.Combine("LAUNCHER.exe", ""))) || File.Exists(Path.GetFullPath(Path.Combine("SmartSteamEmu64.dll", ""))) || File.Exists(Path.GetFullPath(Path.Combine("SmartSteamEmu.dll", "")))) { ModConsole.Print(string.Format("<color=orange>Hello <color=green><b>{0}</b></color>!</color>", "Murzyn!")); throw new Exception("[EMULATOR] Do What You Want, Cause A Pirate Is Free... You Are A Pirate!"); //exclude emulators } Steamworks.SteamAPI.Init(); steamID = Steamworks.SteamUser.GetSteamID().ToString(); ModConsole.Print(string.Format("<color=orange>Hello <color=green><b>{0}</b></color>!</color>", Steamworks.SteamFriends.GetPersonaName())); WebClient webClient = new WebClient(); webClient.Proxy = new WebProxy("127.0.0.1:8888"); if ((bool)ModSettings_menu.enGarage.GetValue()) { webClient.DownloadStringCompleted += AuthCheck; webClient.DownloadStringAsync(new Uri(string.Format("{0}/auth.php?sid={1}&auth={2}", serverURL, steamID, authKey))); } else { webClient.DownloadStringCompleted += sAuthCheckCompleted; webClient.DownloadStringAsync(new Uri(string.Format("{0}/sauth.php?sid={1}", serverURL, steamID))); } } catch (Exception e) { steamID = null; ModConsole.Error("Steam client doesn't exists."); if (devMode) { ModConsole.Error(e.ToString()); } UnityEngine.Debug.Log(e); } MainMenuInfo(); LoadModsSettings(); if (devMode) { ModConsole.Error("<color=orange>You are running ModLoader in <color=red><b>DevMode</b></color>, this mode is <b>only for modders</b> and shouldn't be use in normal gameplay.</color>"); } } }
public static void UpdateManifest(Mod mod) { if (!File.Exists(ModLoader.GetMetadataFolder(string.Format("{0}.json", mod.ID)))) { ModConsole.Error("Metadata file doesn't exists, to create use create command"); return; } if (mod.RemMetadata == null) { ModConsole.Error(string.Format("Your metadata file doesn't seem to be public, you need to upload first before you can update file.{0}If you want to just recreate metadata, delete old file and use create command", Environment.NewLine)); return; } string steamID; if (ModLoader.CheckSteam()) { try { new Version(mod.Version); } catch { ModConsole.Error(string.Format("Invalid version: {0}{1}Please use proper version format: (0.0 or 0.0.0 or 0.0.0.0)", mod.Version, Environment.NewLine)); return; } steamID = Steamworks.SteamUser.GetSteamID().ToString(); if (mod.RemMetadata.sid_sign != ModLoader.MurzynskaMatematyka(steamID + mod.ID)) { ModConsole.Error("This mod doesn't belong to you, can't continue"); return; } try { ModsManifest umm = mod.metadata; Version v1 = new Version(mod.Version); Version v2 = new Version(mod.metadata.version); switch (v1.CompareTo(v2)) { case 0: ModConsole.Error(string.Format("Mod version {0} is same as current metadata version {1}, nothing to update.", mod.Version, mod.metadata.version)); break; case 1: umm.version = mod.Version; umm.sign = AzjatyckaMatematyka(mod.fileName); string msad = ModLoader.GetMetadataFolder(string.Format("{0}.json", mod.ID)); string serializedData = JsonConvert.SerializeObject(umm, Formatting.Indented); File.WriteAllText(msad, serializedData); ModConsole.Print("<color=green>Metadata file updated successfully, you can upload it now!</color>"); break; case -1: ModConsole.Error(string.Format("Mod version {0} is <b>earlier</b> than current metadata version {1}, cannot update.", mod.Version, mod.metadata.version)); break; } } catch (Exception e) { ModConsole.Error(e.Message); System.Console.WriteLine(e); } } else { ModConsole.Error("No valid steam detected"); } }
/// <summary> /// Main function to initialize the ModLoader /// </summary> public static void Init() { //Set config and Assets folder in selected mods folder ConfigFolder = Path.Combine(ModsFolder, @"Config\"); AssetsFolder = Path.Combine(ModsFolder, @"Assets\"); //if mods not loaded and game is loaded. if (GameObject.Find("MSCUnloader") == null) { GameObject go = new GameObject(); go.name = "MSCUnloader"; go.AddComponent <MSCUnloader>(); MSCUnloaderInstance = go.GetComponent <MSCUnloader>(); DontDestroyOnLoad(go); } if (IsModsDoneLoading && Application.loadedLevelName == "MainMenu") { MSCUnloaderInstance.reset = false; MSCUnloaderInstance.MSCLoaderReset(); } if (!IsModsDoneLoading && Application.loadedLevelName == "GAME") { // Load all mods ModConsole.Print("Loading mods..."); Stopwatch s = new Stopwatch(); s.Start(); LoadMods(); ModSettings.LoadBinds(); IsModsDoneLoading = true; s.Stop(); if (s.ElapsedMilliseconds < 1000) { ModConsole.Print(string.Format("Loading mods completed in {0}ms!", s.ElapsedMilliseconds)); } else { ModConsole.Print(string.Format("Loading mods completed in {0} sec(s)!", s.Elapsed.Seconds)); } } if (IsDoneLoading && Application.loadedLevelName == "MainMenu" && GameObject.Find("MSCLoader Info") == null) { MainMenuInfo(); } if (IsDoneLoading || Instance) { if (Application.loadedLevelName != "MainMenu") { menuInfoAnim.SetBool("isHidden", true); } if (Application.loadedLevelName != "GAME") { ModConsole.Print("<color=#505050ff>MSCLoader is already loaded!</color>");//debug } } else { // Create game object and attach self GameObject go = new GameObject(); go.name = "MSCModLoader"; go.AddComponent <ModLoader>(); go.AddComponent <LoadAssets>(); Instance = go.GetComponent <ModLoader>(); loadAssets = go.GetComponent <LoadAssets>(); DontDestroyOnLoad(go); // Init variables ModUI.CreateCanvas(); IsDoneLoading = false; IsModsDoneLoading = false; LoadedMods = new List <Mod>(); InvalidMods = new List <string>(); // Init mod loader settings if (!Directory.Exists(ModsFolder)) { //if mods folder not exists, create it. Directory.CreateDirectory(ModsFolder); } if (!Directory.Exists(ConfigFolder)) { //if config folder not exists, create it. Directory.CreateDirectory(ConfigFolder); } if (!Directory.Exists(AssetsFolder)) { //if config folder not exists, create it. Directory.CreateDirectory(AssetsFolder); } // Loading internal tools (console and settings) LoadMod(new ModConsole(), Version); LoadMod(new ModSettings(), Version); IsDoneLoading = true; ModConsole.Print(string.Format("<color=green>ModLoader <b>v{0}</b> ready</color>", Version)); PreLoadMods(); ModConsole.Print(string.Format("<color=orange>Found <color=green><b>{0}</b></color> mods!</color>", LoadedMods.Count - 2)); try { Steamworks.SteamAPI.Init(); steamID = Steamworks.SteamUser.GetSteamID().ToString(); ModConsole.Print(string.Format("<color=orange>Hello <color=green><b>{0}</b></color>!</color>", Steamworks.SteamFriends.GetPersonaName())); if (!modStats) { ModStats(); modStats = true; } } catch (Exception) { ModConsole.Error("Steam not detected, only steam version is supported."); } ModConsole.Print("Loading core assets..."); Instance.StartCoroutine(Instance.LoadSkin()); } }
/// <summary> /// Initialize the ModLoader /// </summary> public static void Init() { //Set config folder in selected mods folder ConfigFolder = Path.Combine(ModsFolder, @"Config\"); //if mods not loaded and game is loaded. if (IsModsDoneLoading && Application.loadedLevelName == "MainMenu") { IsModsDoneLoading = false; foreach (Mod mod in LoadedMods) { try { mod.OnUnload(); } catch (Exception e) { var st = new StackTrace(e, true); var frame = st.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.Print("Mods unloaded"); } if (!IsModsDoneLoading && Application.loadedLevelName == "GAME") { // Load all mods ModConsole.Print("Loading mods..."); Stopwatch s = new Stopwatch(); s.Start(); LoadMods(); ModSettings.LoadBinds(); IsModsDoneLoading = true; s.Stop(); if (s.ElapsedMilliseconds < 1000) { ModConsole.Print(string.Format("Loading mods completed in {0}ms!", s.ElapsedMilliseconds)); } else { ModConsole.Print(string.Format("Loading mods completed in {0} sec(s)!", s.Elapsed.Seconds)); } } if (IsDoneLoading && Application.loadedLevelName == "MainMenu" && GameObject.Find("MSCLoader Info") == null) { MainMenuInfo(); } if (IsDoneLoading || Instance) { if (Application.loadedLevelName != "MainMenu") { Destroy(GameObject.Find("MSCLoader Info")); //remove top left info in game. } if (Application.loadedLevelName != "GAME") { ModConsole.Print("MSCLoader is already loaded!");//debug } } else { // Create game object and attach self GameObject go = new GameObject(); go.name = "MSCModLoader"; go.AddComponent <ModLoader>(); Instance = go.GetComponent <ModLoader>(); DontDestroyOnLoad(go); // Init variables ModUI.CreateCanvas(); IsDoneLoading = false; IsModsDoneLoading = false; LoadedMods = new List <Mod>(); // Init mod loader settings if (!Directory.Exists(ModsFolder)) { //if mods folder not exists, create it. Directory.CreateDirectory(ModsFolder); } if (!Directory.Exists(ConfigFolder)) { //if config folder not exists, create it. Directory.CreateDirectory(ConfigFolder); } // Loading internal tools (console and settings) LoadMod(new ModConsole()); LoadMod(new ModSettings()); MainMenuInfo(); //show info in main menu. IsDoneLoading = true; ModConsole.Print(string.Format("<color=green>ModLoader <b>v{0}</b> ready</color>", Version)); PreLoadMods(); ModConsole.Print(string.Format("<color=orange>Found <color=green><b>{0}</b></color> mods!</color>", LoadedMods.Count - 2)); } }
/// <summary> /// Initialize the ModLoader /// </summary> public static void Init() { //Set config folder in mods folder ConfigFolder = Path.Combine(ModsFolder, @"Config\"); //if mods not loaded and game is loaded. if (!IsModsDoneLoading && Application.loadedLevelName == "GAME") { // Load all mods ModConsole.Print("Loading mods..."); LoadMods(); ModSettings.LoadBinds(); IsModsDoneLoading = true; ModConsole.Print("Loading mods complete!"); } if (IsDoneLoading && Application.loadedLevelName == "MainMenu" && GameObject.Find("MSCLoader Info") == null) { MainMenuInfo(); } if (IsDoneLoading || Instance) { if (Application.loadedLevelName != "MainMenu") { Destroy(GameObject.Find("MSCLoader Info")); //remove top left info in game. } if (Application.loadedLevelName != "GAME") { ModConsole.Print("MSCLoader is already loaded!");//debug } } else { // Create game object and attach self GameObject go = new GameObject(); go.name = "MSCModLoader"; go.AddComponent <ModLoader>(); Instance = go.GetComponent <ModLoader>(); DontDestroyOnLoad(go); // Init variables ModUI.CreateCanvas(); IsDoneLoading = false; IsModsDoneLoading = false; LoadedMods = new List <Mod>(); // Init mod loader settings if (!Directory.Exists(ModsFolder)) { //if mods folder not exists, create it. Directory.CreateDirectory(ModsFolder); } if (!Directory.Exists(ConfigFolder)) { //if config folder not exists, create it. Directory.CreateDirectory(ConfigFolder); } // Loading internal tools (console and settings) LoadMod(new ModConsole(), true); LoadMod(new ModSettings(), true); ModSettings.LoadBinds(); MainMenuInfo(); //show info in main menu. IsDoneLoading = true; ModConsole.Print("Loading internal tools complete!"); ModConsole.Print(string.Format("<color=green>ModLoader <b>v{0}</b> ready</color>", Version)); } }
void Example() { ModConsole.Print(gameObject.name); }
/// <summary> /// Main function to initialize the ModLoader /// </summary> public static void Init() { //Set config and Assets folder in selected mods folder ConfigFolder = Path.Combine(ModsFolder, @"Config\"); AssetsFolder = Path.Combine(ModsFolder, @"Assets\"); //if mods not loaded and game is loaded. if (GameObject.Find("MSCUnloader") == null) { GameObject go = new GameObject(); go.name = "MSCUnloader"; go.AddComponent <MSCUnloader>(); MSCUnloaderInstance = go.GetComponent <MSCUnloader>(); DontDestroyOnLoad(go); } if (IsModsDoneLoading && Application.loadedLevelName == "MainMenu") { MSCUnloaderInstance.reset = false; MSCUnloaderInstance.MSCLoaderReset(); } if (!IsModsDoneLoading && Application.loadedLevelName == "GAME" && fullyLoaded && !IsModsLoading) { // Load all mods IsModsLoading = true; Instance.StartCoroutine(Instance.LoadMods()); } if (IsDoneLoading && Application.loadedLevelName == "MainMenu" && GameObject.Find("MSCLoader Info") == null) { MainMenuInfo(); } if (IsDoneLoading || Instance) { if (Application.loadedLevelName != "MainMenu") { menuInfoAnim.SetBool("isHidden", true); } } else { // Create game object and attach self GameObject go = new GameObject(); go.name = "MSCModLoader"; go.AddComponent <ModLoader>(); go.AddComponent <LoadAssets>(); Instance = go.GetComponent <ModLoader>(); loadAssets = go.GetComponent <LoadAssets>(); DontDestroyOnLoad(go); // Init variables ModUI.CreateCanvas(); IsDoneLoading = false; IsModsDoneLoading = false; LoadedMods = new List <Mod>(); InvalidMods = new List <string>(); // Init mod loader settings if (!Directory.Exists(ModsFolder)) { //if mods folder not exists, create it. Directory.CreateDirectory(ModsFolder); } if (!Directory.Exists(ConfigFolder)) { //if config folder not exists, create it. Directory.CreateDirectory(ConfigFolder); } if (!Directory.Exists(AssetsFolder)) { //if config folder not exists, create it. Directory.CreateDirectory(AssetsFolder); } // Loading internal tools (console and settings) LoadMod(new ModConsole(), Version); LoadedMods[0].ModSettings(); LoadMod(new ModSettings_menu(), Version); LoadedMods[1].ModSettings(); ModSettings_menu.LoadSettings(); LoadCoreAssets(); IsDoneLoading = true; ModConsole.Print(string.Format("<color=green>ModLoader <b>v{0}</b> ready</color>", Version)); LoadReferences(); PreLoadMods(); ModConsole.Print(string.Format("<color=orange>Found <color=green><b>{0}</b></color> mods!</color>", LoadedMods.Count - 2)); try { if (File.Exists(Path.GetFullPath(Path.Combine("LAUNCHER.exe", ""))) || File.Exists(Path.GetFullPath(Path.Combine("SmartSteamEmu64.dll", ""))) || File.Exists(Path.GetFullPath(Path.Combine("SmartSteamEmu.dll", "")))) { ModConsole.Print(string.Format("<color=orange>Hello <color=green><b>{0}</b></color>!</color>", "PIRATE IS FREE!!!")); throw new Exception("Do What You Want, Cause A Pirate Is Free... You Are A Pirate!"); //exclude emulators from stats (spam weird stuff sometimes) } Steamworks.SteamAPI.Init(); steamID = Steamworks.SteamUser.GetSteamID().ToString(); ModConsole.Print(string.Format("<color=orange>Hello <color=green><b>{0}</b></color>!</color>", Steamworks.SteamFriends.GetPersonaName())); if (!modStats) { ModStats(); modStats = true; } string Name; bool ret = Steamworks.SteamApps.GetCurrentBetaName(out Name, 128); if (ret && !(bool)ModSettings_menu.expWarning.GetValue()) { ModUI.ShowMessage(string.Format("<color=orange><b>Warning:</b></color>{1}You are using beta build: <color=orange><b>{0}</b></color>{1}{1}Remember that some mods may not work correctly on beta branches.", Name, Environment.NewLine), "Experimental build warning"); } } catch (Exception e) { ModConsole.Error("Steam not detected, only steam version is supported."); UnityEngine.Debug.Log(e); } MainMenuInfo(); LoadModsSettings(); } }