internal static void LoadAll(string folderpath, bool is_plugins = false) { string[] filearr = Directory.GetFiles(folderpath).ToArray(); if (filearr.Length <= 0) { return; } MelonLaunchOptions.Core.LoadModeEnum loadMode = is_plugins ? MelonLaunchOptions.Core.LoadMode_Plugins : MelonLaunchOptions.Core.LoadMode_Mods; for (int i = 0; i < filearr.Length; i++) { string filepath = filearr[i]; if (string.IsNullOrEmpty(filepath)) { continue; } if (IsExtensionBlacklisted(filepath)) { MelonLogger.Error($"Invalid File Extension for {filepath}"); continue; } string lowerFilePath = filepath.ToLowerInvariant(); if ((loadMode == MelonLaunchOptions.Core.LoadModeEnum.NORMAL) && !lowerFilePath.EndsWith(".dll")) { continue; } if ((loadMode == MelonLaunchOptions.Core.LoadModeEnum.DEV) && !lowerFilePath.EndsWith(".dev.dll")) { continue; } // To-Do: File Type Check string melonname = MelonUtils.GetFileProductName(filepath); if (string.IsNullOrEmpty(melonname)) { melonname = Path.GetFileNameWithoutExtension(filepath); } if (is_plugins ? MelonHandler.IsPluginAlreadyLoaded(melonname) : MelonHandler.IsModAlreadyLoaded(melonname)) { MelonLogger.Error($"Duplicate File: {filepath}"); continue; } LoadFromFile(filepath); } }
private static void CheckForSceneInitialized() { if (HasFinishedLoading) { MelonHandler.OnLevelWasInitialized(LastSceneIndex); HasFinishedLoading = false; } }
public void PruebaMH3() { bool plugins = false; string directorio = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, (plugins ? "Plugins" : "Mods")); bool verificarDLL = MelonHandler.VerifyDLL(directorio); Console.WriteLine(verificarDLL); Assert.IsTrue(verificarDLL); }
public void PruebaMH4() { bool plugins = false; string directorio = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, (plugins ? "Plugins" : "Mods")); int cantItems = MelonHandler.GetCountFiles(directorio); Console.WriteLine(cantItems); Assert.IsTrue(cantItems > 1); }
public void PruebaMH1() { bool plugins = false; string directorio = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, (plugins ? "Plugins" : "Mods")); bool PuedeCargarZips = MelonHandler.CanLoadZips(directorio); Console.WriteLine(PuedeCargarZips); Assert.IsTrue(PuedeCargarZips); }
private static void CheckForSceneFinishedLoading() { if (IsLoading) { MelonHandler.OnLevelWasLoaded(LastSceneIndex); HasFinishedLoading = true; IsLoading = false; } }
void Update() { transform.SetAsLastSibling(); if (Main.CurrentScene != Application.loadedLevel) { SceneHandler.OnSceneLoad(Application.loadedLevel); Main.CurrentScene = Application.loadedLevel; } MelonHandler.OnUpdate(); }
private bool CheckInfoAttribute(ref MelonInfoAttribute infoAttribute) { infoAttribute = MelonUtils.PullAttributeFromAssembly <MelonInfoAttribute>(Assembly); // Legacy Support if (infoAttribute == null) { infoAttribute = MelonUtils.PullAttributeFromAssembly <MelonModInfoAttribute>(Assembly)?.Convert(); } if (infoAttribute == null) { infoAttribute = MelonUtils.PullAttributeFromAssembly <MelonPluginInfoAttribute>(Assembly)?.Convert(); } if ((infoAttribute == null) || (infoAttribute.SystemType == null)) { MelonLogger.Error($"No {((infoAttribute == null) ? "MelonInfoAttribute Found" : "Type given to MelonInfoAttribute")} in {FilePath}"); return(false); } is_plugin = infoAttribute.SystemType.IsSubclassOf(typeof(MelonPlugin)); bool is_mod_subclass = infoAttribute.SystemType.IsSubclassOf(typeof(MelonMod)); if (!is_plugin && !is_mod_subclass) { MelonLogger.Error($"Type Specified {infoAttribute.SystemType.AssemblyQualifiedName} is not a Subclass of MelonPlugin or MelonMod in {FilePath}"); return(false); } bool nullcheck_name = string.IsNullOrEmpty(infoAttribute.Name); bool nullcheck_version = string.IsNullOrEmpty(infoAttribute.Version); if (nullcheck_name || nullcheck_version) { MelonLogger.Error($"No {(nullcheck_name ? "Name" : (nullcheck_version ? "Version" : ""))} given to MelonInfoAttribute in {FilePath}"); return(false); } if (is_plugin ? MelonHandler.IsPluginAlreadyLoaded(infoAttribute.Name) : MelonHandler.IsModAlreadyLoaded(infoAttribute.Name)) { MelonLogger.Error($"Duplicate {(is_plugin ? "Plugin" : "Mod")} {infoAttribute.Name}: {FilePath}"); return(false); } return(true); }
internal static void LoadFromByteArray(byte[] filedata, byte[] symbolsdata = null, string filepath = null) { if (filedata == null) { return; } // To-Do: File Type Check Assembly melonassembly = null; try { melonassembly = Assembly.Load(filedata, symbolsdata); } catch (Exception ex) { if (string.IsNullOrEmpty(filepath)) { MelonLogger.Error($"Failed to Load Assembly from Byte Array: {ex}"); } else { MelonLogger.Error($"Failed to Load Assembly for {filepath}: {ex}"); } return; } if (melonassembly == null) { if (string.IsNullOrEmpty(filepath)) { MelonLogger.Error("Failed to Load Assembly from Byte Array: Assembly.Load returned null"); } else { MelonLogger.Error($"Failed to Load Assembly for {filepath}: Assembly.Load returned null"); } return; } if (string.IsNullOrEmpty(filepath)) { filepath = melonassembly.GetName().Name; } MelonHandler.LoadFromAssembly(melonassembly, filepath); }
internal static void LoadAll(string folderpath, bool is_plugins = false) { MelonLaunchOptions.Core.LoadModeEnum loadMode = is_plugins ? MelonLaunchOptions.Core.LoadMode_Plugins : MelonLaunchOptions.Core.LoadMode_Mods; string[] filearr = Directory.GetFiles(folderpath).Where(x => Path.GetExtension(x).ToLowerInvariant().Equals(".dll") && ((loadMode == MelonLaunchOptions.Core.LoadModeEnum.DEV) ? x.ToLowerInvariant().EndsWith(".dev.dll") : ((loadMode == MelonLaunchOptions.Core.LoadModeEnum.NORMAL) ? !x.ToLowerInvariant().EndsWith(".dev.dll") : true)) ).ToArray(); if (filearr.Length <= 0) { return; } for (int i = 0; i < filearr.Length; i++) { string filepath = filearr[i]; if (string.IsNullOrEmpty(filepath)) { continue; } string melonname = MelonUtils.GetFileProductName(filepath); if (string.IsNullOrEmpty(melonname)) { melonname = Path.GetFileNameWithoutExtension(filepath); } if (is_plugins ? MelonHandler.IsPluginAlreadyLoaded(melonname) : MelonHandler.IsModAlreadyLoaded(melonname)) { MelonLogger.Error($"Duplicate File: {filepath}"); continue; } LoadFromFile(filepath); } }
internal static void LoadFromFile(string filepath, string symbolspath = null) { if (string.IsNullOrEmpty(filepath)) { return; } if (MelonDebug.IsEnabled()) { Assembly melonassembly = null; try { melonassembly = Assembly.LoadFrom(filepath); } catch (Exception ex) { MelonLogger.Error($"Failed to Load Assembly for {filepath}: {ex}"); return; } if (melonassembly == null) { MelonLogger.Error($"Failed to Load Assembly for {filepath}: Assembly.LoadFrom returned null");; return; } MelonHandler.LoadFromAssembly(melonassembly, filepath); } else { byte[] symbolsdata = new byte[0]; if (string.IsNullOrEmpty(symbolspath)) { symbolspath = Path.Combine(Path.GetDirectoryName(filepath), $"{Path.GetFileNameWithoutExtension(filepath)}.mdb"); } if (!File.Exists(symbolspath)) { symbolspath = $"{filepath}.mdb"; } if (File.Exists(symbolspath)) { try { symbolsdata = File.ReadAllBytes(symbolspath); } catch (Exception ex) { if (MelonDebug.IsEnabled()) { MelonLogger.Warning($"Failed to Load Symbols for {filepath}: {ex}"); } } } byte[] filedata = null; try { filedata = File.ReadAllBytes(filepath); } catch (Exception ex) { MelonLogger.Error($"Failed to Read File Data for {filepath}: {ex}"); return; } LoadFromByteArray(filedata, symbolsdata, filepath); } }
public void FixedUpdate() => MelonHandler.OnFixedUpdate();
public void Update() => MelonHandler.OnUpdate();
public void OnSceneWasUnloaded(int buildIndex, string sceneName) => MelonHandler.OnSceneWasUnloaded(buildIndex, sceneName);
void OnGUI() => MelonHandler.OnGUI();
void FixedUpdate() { MelonHandler.OnFixedUpdate(); MelonCoroutines.ProcessWaitForFixedUpdate(); }
public static void Main(string[] args) { if (IsDebugRelease) { MessageBox.Show("Code messed up somewhere, report this to the devs, PROGRAM RUN IN DEBUG"); } MainWindow.SetupSettings(); if (!ProcessHelpers.IsVC2019x64Installed() && !Storage.Settings.ShownVCScreen) { MessageBox.Show( "You do not have Visual C installed! Continue to install it.\nTHIS WILL NOT BE SHOWN AGAIN!\nDO NOT REPORT THE APP NOT RUNNING IF YOU DIDNT INSTALL THIS"); Process.Start("https://aka.ms/vs/16/release/VC_redist.x64.exe"); Storage.Settings.ShownVCScreen = true; throw new("Need Visual C Installed!"); } var mtr = new List <Mod>(); foreach (var a in (ModManifest.Instance * typeof(Mod))) { if (!File.Exists((ModManifest.Instance ^ a.Name).CanonicalLocation)) { mtr.Add(a); } } foreach (var remove in mtr) { ModManifest.Instance -= remove; } try { SteamClient.Init(960090); Storage.InstallDir = SteamApps.AppInstallDir(); MelonHandler.EnsureMelonInstalled(); FileAssociations.EnsureAssociationsSet(); } catch (Exception e) { MessageBox.Show("ERROR 0x3ef93 PLEASE REPORT IN THE DISCORD" + Environment.NewLine + "Please include this message in your support ticket: " + e.Message); Environment.Exit(1); } _ = Directory.CreateDirectory(Storage.InstallDir + @"\Mods\Inferno"); _ = Directory.CreateDirectory(Storage.InstallDir + @"\Mods\Inferno\Disabled"); _ = Directory.CreateDirectory(Storage.InstallDir + @"\Mods"); _ = Directory.CreateDirectory(Storage.InstallDir + @"\Mods\Disabled"); _ = Directory.CreateDirectory(Environment.ExpandEnvironmentVariables("%AppData%\\InfernoOmnia\\")); if (args.Length != 0) { foreach (var file in args) { if (!file.Contains(@"\Mods\Inferno")) { if (File.Exists(Storage.InstallDir + @"\Mods\Inferno\" + Path.GetFileName(file))) { File.Delete(Storage.InstallDir + @"\Mods\Inferno\" + Path.GetFileName(file)); } File.Move(file, Storage.InstallDir + @"\Mods\Inferno\" + Path.GetFileName(file)); } } } if (Directory.GetFiles(Storage.InstallDir + @"\Mods\Inferno") .Combine(Directory.GetFiles(Storage.InstallDir + @"\Mods\Inferno\Disabled")).Length > 0) { var flag = false; foreach (var file in Directory.GetFiles(Storage.InstallDir + @"\Mods", "*.dll") .Combine(Directory.GetFiles(Storage.InstallDir + @"\Mods\Inferno\Disabled"))) { MelonHandler.GetMelonAttrib(file, out var att); if (att != null) { flag |= att.Name.Equals("Inferno API Injector"); } } if (!flag) { File.Create(Storage.InstallDir + @"\Mods\Inferno API Injector.dll") .Write(Resources.Inferno_API_Injector, 0, Resources.Inferno_API_Injector.Length); } } var app = new App { ShutdownMode = ShutdownMode.OnMainWindowClose }; app.InitializeComponent(); app.Run(); }
void Update() { transform.SetAsLastSibling(); MelonHandler.OnUpdate(); }
private void LoadPlugin(Type plugin_type, string filelocation, ref List <MelonBase> melonTbl) { IPlugin pluginInstance = Activator.CreateInstance(plugin_type) as IPlugin; string[] filter = null; if (pluginInstance is IEnhancedPlugin) { filter = ((IEnhancedPlugin)pluginInstance).Filter; } List <MelonGameAttribute> gamestbl = null; if ((filter != null) && (filter.Count() > 0)) { string exe_name = Path.GetFileNameWithoutExtension(string.Copy(MelonUtils.GetApplicationPath())); gamestbl = new List <MelonGameAttribute>(); bool game_found = false; foreach (string x in filter) { if (string.IsNullOrEmpty(x)) { continue; } gamestbl.Add(new MelonGameAttribute(name: x)); if (x.Equals(exe_name)) { game_found = true; } } if (!game_found) { MelonLogger.Error($"Incompatible Game for {filelocation}"); return; } } string plugin_name = pluginInstance.Name; if (string.IsNullOrEmpty(plugin_name)) { plugin_name = plugin_type.FullName; } if (MelonHandler.IsModAlreadyLoaded(plugin_name)) { MelonLogger.Error($"Duplicate File {plugin_name}: {filelocation}"); return; } string plugin_version = pluginInstance.Version; if (string.IsNullOrEmpty(plugin_version)) { plugin_version = asm.GetName().Version.ToString(); } if (string.IsNullOrEmpty(plugin_version) || plugin_version.Equals("0.0.0.0")) { plugin_version = "1.0.0.0"; } MelonModWrapper wrapper = new MelonCompatibilityLayer.WrapperData() { Assembly = asm, Info = new MelonInfoAttribute(typeof(MelonModWrapper), plugin_name, plugin_version), Games = (gamestbl != null) ? gamestbl.ToArray() : null, Priority = 0, Location = filelocation }.CreateMelon <MelonModWrapper>(); if (wrapper == null) { return; } wrapper.pluginInstance = pluginInstance; melonTbl.Add(wrapper); PluginManager._Plugins.Add(pluginInstance); }
void Update() { transform.SetAsLastSibling(); MelonHandler.OnUpdate(); MelonCoroutines.Process(); }
public void BONEWORKS_OnLoadingScreen() => MelonHandler.BONEWORKS_OnLoadingScreen();
void LateUpdate() => MelonHandler.OnLateUpdate();
public void OnSceneWasInitialized(int buildIndex, string sceneName) => MelonHandler.OnSceneWasInitialized(buildIndex, sceneName);
void OnApplicationQuit() { Destroy(); MelonHandler.OnApplicationQuit(); }
public static void OnSceneLoad(int current_scene) { bool should_run = true; if (Imports.IsIl2CppGame()) { if (MelonLoaderBase._IsBoneworks) { if (!Boneworks_HasGotLoadingSceneIndex) { if (current_scene != 0) { Boneworks_LoadingSceneIndex = current_scene; Boneworks_HasGotLoadingSceneIndex = true; should_run = false; } else { LastSceneIndex = current_scene; IsLoading = true; should_run = false; } } else { if (current_scene == -1) { should_run = false; } else { if (current_scene == Boneworks_LoadingSceneIndex) { ShouldWait = true; } else { LastSceneIndex = current_scene; IsLoading = true; should_run = false; ShouldWait = false; } } } } } if (should_run) { LastSceneIndex = current_scene; if (!ShouldWait) { IsLoading = true; } if (MelonLoaderBase._IsBoneworks) { MelonHandler.OnLevelIsLoading(); } else { CheckForSceneFinishedLoading(); } } }