예제 #1
0
        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);
            }
        }
예제 #2
0
 private static void CheckForSceneInitialized()
 {
     if (HasFinishedLoading)
     {
         MelonHandler.OnLevelWasInitialized(LastSceneIndex);
         HasFinishedLoading = false;
     }
 }
예제 #3
0
        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);
        }
예제 #4
0
        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);
        }
예제 #5
0
        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);
        }
예제 #6
0
 private static void CheckForSceneFinishedLoading()
 {
     if (IsLoading)
     {
         MelonHandler.OnLevelWasLoaded(LastSceneIndex);
         HasFinishedLoading = true;
         IsLoading          = false;
     }
 }
예제 #7
0
 void Update()
 {
     transform.SetAsLastSibling();
     if (Main.CurrentScene != Application.loadedLevel)
     {
         SceneHandler.OnSceneLoad(Application.loadedLevel);
         Main.CurrentScene = Application.loadedLevel;
     }
     MelonHandler.OnUpdate();
 }
예제 #8
0
        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);
        }
예제 #9
0
        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);
        }
예제 #10
0
        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);
            }
        }
예제 #11
0
        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);
            }
        }
예제 #12
0
 public void FixedUpdate() => MelonHandler.OnFixedUpdate();
예제 #13
0
 public void Update() => MelonHandler.OnUpdate();
예제 #14
0
 public void OnSceneWasUnloaded(int buildIndex, string sceneName) => MelonHandler.OnSceneWasUnloaded(buildIndex, sceneName);
예제 #15
0
 void OnGUI() => MelonHandler.OnGUI();
예제 #16
0
 void FixedUpdate()
 {
     MelonHandler.OnFixedUpdate();
     MelonCoroutines.ProcessWaitForFixedUpdate();
 }
예제 #17
0
        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();
        }
예제 #18
0
 void Update()
 {
     transform.SetAsLastSibling(); MelonHandler.OnUpdate();
 }
예제 #19
0
        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);
        }
예제 #20
0
 void Update()
 {
     transform.SetAsLastSibling();
     MelonHandler.OnUpdate();
     MelonCoroutines.Process();
 }
예제 #21
0
 public void BONEWORKS_OnLoadingScreen() => MelonHandler.BONEWORKS_OnLoadingScreen();
예제 #22
0
 void LateUpdate() => MelonHandler.OnLateUpdate();
예제 #23
0
 public void OnSceneWasInitialized(int buildIndex, string sceneName) => MelonHandler.OnSceneWasInitialized(buildIndex, sceneName);
예제 #24
0
 void OnApplicationQuit()
 {
     Destroy(); MelonHandler.OnApplicationQuit();
 }
예제 #25
0
        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();
                }
            }
        }