Example #1
0
 private static void LoadVRLoader()
 {
     try
     {
         Assembly.Load(Properties.Resources.VRLoader);
     }
     catch (Exception e)
     {
         VRCModLogger.LogError("[ModComponent] Error while loading VRLoader.dll: " + e);
     }
 }
Example #2
0
 void OnDestroy()
 {
     try
     {
         ModComponent.Create();
     }
     catch (Exception e)
     {
         VRCModLogger.LogError(e.ToString());
     }
 }
Example #3
0
        private static void LoadModsFromAssembly(Assembly assembly)
        {
            try
            {
                foreach (Type t in assembly.GetLoadableTypes())
                {
                    if (t.IsSubclassOf(typeof(VRCMod)))
                    {
                        try
                        {
                            VRCMod modInstance = Activator.CreateInstance(t) as VRCMod;
                            Mods.Add(modInstance);
                            ModControllers.Add(new VRCModController(modInstance));
                            VRCModInfoAttribute modInfoAttribute = modInstance.GetType().GetCustomAttributes(typeof(VRCModInfoAttribute), true).FirstOrDefault() as VRCModInfoAttribute;
                            if (modInfoAttribute != null)
                            {
                                modInstance.Name         = modInfoAttribute.Name;
                                modInstance.Version      = modInfoAttribute.Version;
                                modInstance.Author       = modInfoAttribute.Author;
                                modInstance.DownloadLink = modInfoAttribute.DownloadLink;
                            }
                        }
                        catch (Exception e)
                        {
                            VRCModLogger.Log("[WARN] [ModManager] Could not load mod " + t.FullName + " in " + assembly.GetName() + "! " + e);
                        }
                    }

                    if (t.IsSubclassOf(typeof(VRModule)))
                    {
                        try
                        {
                            ModuleInfoAttribute moduleInfo;
                            if ((moduleInfo = (t.GetCustomAttributes(typeof(ModuleInfoAttribute), true).FirstOrDefault() as ModuleInfoAttribute)) != null)
                            {
                                VRCModLogger.Log("Adding component " + t);
                                VRModule vrmodule = ModComponent.modulesGameObject.gameObject.AddComponent(t) as VRModule;
                                Modules.Add(vrmodule);
                                vrmodule.Initialize(moduleInfo, moduleManager);
                            }
                        }
                        catch (Exception e)
                        {
                            VRCModLogger.Log("[WARN] [ModManager] Could not load module " + t.FullName + " in " + assembly.GetName() + "! " + e);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                VRCModLogger.LogError("[ModManager] Could not load " + assembly.GetName() + "! " + e);
            }
        }
Example #4
0
 private static IEnumerator ShowErrorPopup(string error)
 {
     VRCModLogger.Log("[VRCToolsUpdater] Showing error popup");
     yield return(ShowPopup("VRCTools Updater", error, "Quit", () => Application.Quit(), (popup) => {
         if (popup.popupProgressFillImage != null)
         {
             popup.popupProgressFillImage.enabled = true;
             popup.popupProgressFillImage.fillAmount = 0f;
             downloadProgressFillImage = popup.popupProgressFillImage;
         }
     }));
 }
Example #5
0
 void OnLevelWasLoaded(int level)
 {
     VRCModLogger.Log("[ModComponent] OnLevelWasLoaded called (" + level + ")");
     if (level == 0)
     {
         StartCoroutine(VRCToolsUpdater.UpdateAndRebootIfRequired());
     }
     if (mods != null)
     {
         mods.OnLevelWasLoaded(level);
     }
     freshlyLoaded = true;
 }
Example #6
0
 public void OnLevelWasInitialized(int level)
 {
     foreach (var modController in modControllers)
     {
         try
         {
             modController.OnLevelWasInitialized(level);
         }
         catch (Exception ex)
         {
             VRCModLogger.LogError("{0}: {1}", modController.mod.Name, ex);
         }
     }
 }
Example #7
0
 private void Invoke(CompositeCall callback)
 {
     foreach (var modController in modControllers)
     {
         try
         {
             callback(modController);
         }
         catch (Exception ex)
         {
             VRCModLogger.LogError("{0}: {1}", modController.mod.Name, ex);
         }
     }
 }
Example #8
0
 public static IEnumerable <Type> GetLoadableTypes(this Assembly assembly)
 {
     if (assembly == null)
     {
         throw new ArgumentNullException(nameof(assembly));
     }
     try
     {
         return(assembly.GetTypes());
     }
     catch (ReflectionTypeLoadException e)
     {
         VRCModLogger.LogError("[ModManager] An error occured while getting types from assembly " + assembly.GetName().Name + ". Returning types from error.\n" + e);
         return(e.Types.Where(t => t != null));
     }
 }
Example #9
0
        void Awake()
        {
            VRCModLogger.Log("[ModComponent] Awake called");
            DontDestroyOnLoad(gameObject);
            Instance = this;

            if (VRCToolsUpdater.CheckForVRCToolsUpdate())
            {
                VRCToolsUpdater.SheduleVRCToolsUpdate();
            }
            else
            {
                mods = new CompositeModCaller(ModManager.ModControllers);
                mods.OnApplicationStart();
            }
        }
Example #10
0
        void Awake()
        {
            VRCModLogger.Init();
            VRCModLogger.Log("[VRCModLoader] Logger Initialised");

            if (Environment.CommandLine.Contains("--verbose") || ModPrefs.GetBool("vrctools", "enabledebugconsole", false))
            {
                VRCModLogger.consoleEnabled = true;
                GuiConsole.CreateConsole();
                VRCModLogger.Log("[VRCModLoader] Bootstrapper created");
            }

            if (Environment.CommandLine.Contains("--nomodloader"))
            {
                loadmods = false;
            }
        }
Example #11
0
        private static void LoadMods()
        {
            string tmpmodDirectory = Path.Combine(Path.GetTempPath(), "VRCModLoaderMods");
            string modDirectory    = Path.Combine(Environment.CurrentDirectory, "Mods");

            if (Directory.Exists(tmpmodDirectory))
            {
                Directory.Delete(tmpmodDirectory, true);                                    // delete the temp directory if existing
            }
            // Process.GetCurrentProcess().MainModule crashes the game and Assembly.GetEntryAssembly() is NULL,
            // so we need to resort to P/Invoke
            string exeName = Path.GetFileNameWithoutExtension(AppInfo.StartupPath);

            VRCModLogger.Log(exeName);
            _Mods           = new List <VRCMod>();
            _ModControllers = new List <VRCModController>();

            if (!Directory.Exists(modDirectory))
            {
                return;
            }
            Directory.CreateDirectory(tmpmodDirectory);

            String[] files = Directory.GetFiles(modDirectory, "*.dll");
            foreach (var s in files)
            {
                string newPath = tmpmodDirectory + s.Substring(modDirectory.Length);
                VRCModLogger.Log("Copying " + s + " to " + newPath);
                File.Copy(s, newPath);
                LoadModsFromFile(newPath, exeName);
            }


            // DEBUG
            VRCModLogger.Log("Running on Unity " + UnityEngine.Application.unityVersion);
            VRCModLogger.Log("-----------------------------");
            VRCModLogger.Log("Loading mods from " + tmpmodDirectory + " and found " + _Mods.Count);
            VRCModLogger.Log("-----------------------------");
            foreach (var mod in _Mods)
            {
                VRCModLogger.Log(" " + mod.Name + " (" + mod.Version + ") by " + mod.Author + (mod.DownloadLink != null ? " (" + mod.DownloadLink + ")" : ""));
            }
            VRCModLogger.Log("-----------------------------");
        }
Example #12
0
 private static IEnumerator ShowUpdatePopup()
 {
     /*
      * uiManagerInstance.HideScreen("SCREEN");
      * //uiManagerInstance.ShowScreen("UserInterface/MenuContent/Screens/UpdateRequired");
      * //uiManagerInstance.ShowScreen("UserInterface/MenuContent/Screens/Title");
      * //uiManagerInstance.ShowScreen("UserInterface/MenuContent/Popups/LoadingPopup");
      * //uiManagerInstance.ShowScreen("UserInterface/MenuContent/Backdrop/Backdrop");
      */
     VRCModLogger.Log("[VRCToolsUpdater] Showing update popup");
     yield return(ShowPopup("VRCTools Updater", "Updating VRCTools", "Quit", () => Application.Quit(), (popup) => {
         if (popup.popupProgressFillImage != null)
         {
             popup.popupProgressFillImage.enabled = true;
             popup.popupProgressFillImage.fillAmount = 0f;
             downloadProgressFillImage = popup.popupProgressFillImage;
         }
     }));
 }
Example #13
0
        private static void LoadModsFromFile(string file, string exeName)
        {
            List <VRCMod> mods = new List <VRCMod>();

            if (!File.Exists(file) || !file.EndsWith(".dll", true, null))
            {
                return;
            }

            try
            {
                Assembly assembly = Assembly.LoadFrom(file);

                foreach (Type t in assembly.GetLoadableTypes())
                {
                    if (t.IsSubclassOf(typeof(VRCMod)))
                    {
                        try
                        {
                            VRCMod modInstance = Activator.CreateInstance(t) as VRCMod;
                            _Mods.Add(modInstance);
                            _ModControllers.Add(new VRCModController(modInstance));
                            VRCModInfoAttribute modInfoAttribute = modInstance.GetType().GetCustomAttributes(typeof(VRCModInfoAttribute), true).FirstOrDefault() as VRCModInfoAttribute;
                            if (modInfoAttribute != null)
                            {
                                modInstance.Name         = modInfoAttribute.Name;
                                modInstance.Version      = modInfoAttribute.Version;
                                modInstance.Author       = modInfoAttribute.Author;
                                modInstance.DownloadLink = modInfoAttribute.DownloadLink;
                            }
                        }
                        catch (Exception e)
                        {
                            VRCModLogger.Log("[WARN] [ModManager] Could not load mod " + t.FullName + " in " + Path.GetFileName(file) + "! " + e);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                VRCModLogger.LogError("[ModManager] Could not load " + Path.GetFileName(file) + "! " + e);
            }
        }
Example #14
0
        void Awake()
        {
            VRCModLogger.Init();
            VRCModLogger.Log("[VRCModLoader] Logger Initialised");

            if (Environment.CommandLine.Contains("--verbose") || ModPrefs.GetBool("vrctools", "enabledebugconsole", false))
            {
                VRCModLogger.consoleEnabled = true;
                if (Application.platform == RuntimePlatform.WindowsPlayer)
                {
                    CreateConsole();
                }
                VRCModLogger.Log("[VRCModLoader] Bootstrapper created");
            }

            if (Environment.CommandLine.Contains("--nomodloader"))
            {
                loadmods = false;
            }
        }
Example #15
0
 void Start()
 {
     VRCModLogger.Log("[ModComponent] Start called");
     OnLevelWasLoaded(Application.loadedLevel);
 }
Example #16
0
        internal static void LoadMods()
        {
            VRCModLogger.Log("Looking for mods");
            string modDirectory = Path.Combine(Environment.CurrentDirectory, "Mods");

            string exeName = Path.GetFileNameWithoutExtension(AppInfo.StartupPath);

            VRCModLogger.Log(exeName);
            Mods           = new List <VRCMod>();
            ModControllers = new List <VRCModController>();
            Modules        = new List <VRModule>();
            if (moduleManager == null)
            {
                moduleManager = new ModuleManager();
                ModComponent.Instance.gameObject.AddComponent <VRLoader.VRLoader>();
            }
            if (!Directory.Exists(modDirectory))
            {
                return;
            }

            string[] files = Directory.GetFiles(modDirectory, "*.dll");

            foreach (string s in files)
            {
                if (!File.Exists(s) || !s.EndsWith(".dll", true, null))
                {
                    return;
                }

                VRCModLogger.Log("Loading " + s);
                try
                {
                    byte[]   data = File.ReadAllBytes(s);
                    Assembly a    = Assembly.Load(data);
                    loadedAssemblies.Add(a);
                }
                catch (Exception e)
                {
                    VRCModLogger.LogError("Unable to load assembly " + s + ":\n" + e);
                }
            }

            foreach (Assembly a in loadedAssemblies)
            {
                VRCModLogger.Log("Loading mods from " + a.GetName());
                LoadModsFromAssembly(a);
            }


            // DEBUG
            VRCModLogger.Log("Running on Unity " + Application.unityVersion + ", using VRCModLoader " + VERSION);
            VRCModLogger.Log("-----------------------------");
            VRCModLogger.Log("Loading mods from " + modDirectory + " and found " + Mods.Count + " VRCMods and " + Modules.Count + " VRModules.");
            VRCModLogger.Log("-----------------------------");
            foreach (var mod in Mods)
            {
                VRCModLogger.Log(" " + mod.Name + " (" + mod.Version + ") by " + mod.Author + (mod.DownloadLink != null ? " (" + mod.DownloadLink + ")" : ""));
            }

            VRCModLogger.Log("-----------------------------");

            foreach (var mod in Modules)
            {
                VRCModLogger.Log(" " + mod.Name + " (" + mod.Version + ") by " + mod.Author);
            }

            VRCModLogger.Log("-----------------------------");
        }
Example #17
0
        internal static IEnumerator UpdateAndRebootIfRequired()
        {
            if (needUpdate || errored)
            {
                bool goForUpdate = needUpdate;
                needUpdate = false;
                VRCModLogger.Log("[VRCToolsUpdater] Looking for VRCFlowManager");
                VRCFlowManager[] flowManagers = Resources.FindObjectsOfTypeAll <VRCFlowManager>();
                foreach (VRCFlowManager flowManager in flowManagers)
                {
                    flowManager.enabled = false;
                }
                VRCModLogger.Log("[VRCToolsUpdater] Disabled " + flowManagers.Length + " VRCFlowManager");


                if (GameObject.Find("UserInterface") == null)
                {
                    VRCModLogger.Log("[VRCToolsUpdater] Loading additive scene \"ui\"");
                    AssetManagement.LoadLevelAdditive("ui");
                }

                if (goForUpdate)
                {
                    needUpdate = false;

                    bool choiceDone = false;
                    bool update     = false;
                    yield return(ShowPopup("VRCTools Updater", "A VRCTools update is available", "Update", () => {
                        choiceDone = true;
                        update = true;
                    }, "Ignore", () => {
                        choiceDone = true;
                    }));

                    yield return(new WaitUntil(() => choiceDone));

                    if (update)
                    {
                        yield return(ShowUpdatePopup());

                        VRCModLogger.Log("[VRCToolsUpdater] Update popup shown");

                        WWW vrctoolsDownload = new WWW("https://vrchat.survival-machines.fr/vrcmod/VRCTools.dll");
                        yield return(vrctoolsDownload);

                        while (!vrctoolsDownload.isDone)
                        {
                            VRCModLogger.Log("[VRCToolsUpdater] Download progress: " + vrctoolsDownload.progress);
                            downloadProgressFillImage.fillAmount = vrctoolsDownload.progress;
                            yield return(null);
                        }

                        int responseCode = getResponseCode(vrctoolsDownload);
                        VRCModLogger.Log("[VRCToolsUpdater] Download done ! response code: " + responseCode);
                        VRCModLogger.Log("[VRCToolsUpdater] File size: " + vrctoolsDownload.bytes.Length);

                        if (responseCode == 200)
                        {
                            yield return(ShowPopup("VRCTools Updater", "Saving VRCTools"));

                            VRCModLogger.Log("[VRCToolsUpdater] Saving file");
                            File.WriteAllBytes(vrctoolsPath, vrctoolsDownload.bytes);

                            VRCModLogger.Log("[VRCToolsUpdater] Showing restart dialog");
                            choiceDone = false;
                            yield return(ShowPopup("VRCTools Updater", "Update downloaded", "Restart", () => {
                                choiceDone = true;
                            }));

                            yield return(new WaitUntil(() => choiceDone));

                            yield return(ShowPopup("VRCTools Updater", "Restarting game"));

                            VRCModLogger.Log("[VRCToolsUpdater] Rebooting game");
                            string args  = "";
                            bool   first = true;
                            foreach (string arg in Environment.GetCommandLineArgs())
                            {
                                if (first)
                                {
                                    first = false;
                                }
                                else
                                {
                                    args = args + arg + " ";
                                }
                            }

                            Thread t = new Thread(() =>
                            {
                                Thread.Sleep(1000);
                                System.Diagnostics.Process.Start(Path.GetDirectoryName(Path.GetDirectoryName(vrctoolsPath)) + "\\VRChat.exe", args);
                                Thread.Sleep(100);
                            });
                            t.Start();

                            Application.Quit();
                        }
                        else
                        {
                            yield return(ShowErrorPopup("Unable to update VRCTools: Server returned code " + responseCode));
                        }
                    }
                    else
                    {
                        uiPopupManagerInstance.HideCurrentPopup();
                        foreach (VRCFlowManager flowManager in flowManagers)
                        {
                            flowManager.enabled = true;
                        }
                        VRCModLogger.Log("[VRCToolsUpdater] Enabled " + flowManagers.Length + " VRCFlowManager");
                    }
                }
                else if (errored)
                {
                    yield return(ShowErrorPopup("Unable to check VRCTools validity: Server returned code " + errorCode));
                }
            }
        }
Example #18
0
 public static ModComponent Create()
 {
     VRCModLogger.Log("[ModComponent] Creating component");
     return(new GameObject("IPA_ModManager").AddComponent <ModComponent>());
 }