Example #1
0
        public static void Main(string[] args)
        {
            //get Path of Scrolls Data Folder
            String installPath = Platform.getGlobalScrollsInstallPath();
            if (installPath == null) return;

            //create modloader folder
            if (!System.IO.Directory.Exists(installPath+"ModLoader")) {
                System.IO.Directory.CreateDirectory(installPath+"ModLoader");
            }

            //backup original assembly
            if (!System.IO.File.Exists(installPath+"ModLoader"+ System.IO.Path.DirectorySeparatorChar +"Assembly-CSharp.dll"))
                System.IO.File.Copy (installPath+"Assembly-CSharp.dll", installPath + "ModLoader"+ System.IO.Path.DirectorySeparatorChar +"Assembly-CSharp.dll");
            else {
            //if a backup already exists, it is much more likely that the current assembly is messed up and the user wants to repatch
                System.IO.File.Delete(installPath+"Assembly-CSharp.dll");
                System.IO.File.Copy(installPath+"ModLoader"+ System.IO.Path.DirectorySeparatorChar +"Assembly-CSharp.dll", installPath+"Assembly-CSharp.dll");
            }

            //copy modloader for patching
            if (System.IO.File.Exists(installPath+"ScrollsModLoader.dll"))
                System.IO.File.Delete(installPath+"ScrollsModLoader.dll");
            System.IO.File.Copy(System.Reflection.Assembly.GetExecutingAssembly().Location, installPath+"ScrollsModLoader.dll");

            //reset ini
            if (System.IO.File.Exists(installPath+"ModLoader"+ System.IO.Path.DirectorySeparatorChar +"mods.ini"))
                System.IO.File.Delete(installPath+"ModLoader"+ System.IO.Path.DirectorySeparatorChar +"mods.ini");

            Console.WriteLine ("Patching...");
            //patch it
            Patcher patcher = new Patcher();
            if (!patcher.patchAssembly()) {
                Console.WriteLine("Patching failed");
                //don't save patch at this point. If the "real" patcher fails, we should tell the user instead
                //save-patching is for installs, that get broken by updates, etc, to keep the install until ScrollsModLoader is updated
                Dialogs.showNotification ("Patching failed", "ScrollsModLoader was unable to prepare your client, you are likely using an incompatible version. More at ScrollsGuide.com");
            }

            byte[] linfucecil = System.Reflection.Assembly.GetExecutingAssembly ().GetManifestResourceStream ("ScrollsModLoader.LinFu.AOP.Cecil.dll").ReadToEnd ();
            System.IO.File.Create (installPath+"LinFu.AOP.Cecil.dll").Write (linfucecil, 0, linfucecil.Length);
            byte[] linfuinterfaces = System.Reflection.Assembly.GetExecutingAssembly ().GetManifestResourceStream ("ScrollsModLoader.LinFu.AOP.Interfaces.dll").ReadToEnd ();
            System.IO.File.Create (installPath+"LinFu.AOP.Interfaces.dll").Write (linfuinterfaces, 0, linfuinterfaces.Length);

            Console.WriteLine ("Done");

            return;
        }
Example #2
0
        public void repatch()
        {
            String installPath   = Platform.getGlobalScrollsInstallPath();
            String modLoaderPath = Platform.getModLoaderPath();

            //save ModList
            File.Delete(modLoaderPath + "mods.ini");
            StreamWriter modOrderWriter = File.CreateText(modLoaderPath + "mods.ini");

            foreach (String modId in modOrder)
            {
                modOrderWriter.WriteLine(modId);
            }
            modOrderWriter.Flush();
            modOrderWriter.Close();



            File.Delete(installPath + "Assembly-CSharp.dll");
            File.Copy(modLoaderPath + System.IO.Path.DirectorySeparatorChar + "Assembly-CSharp.dll", installPath + "Assembly-CSharp.dll");

            Patcher patcher = new Patcher();

            if (!patcher.patchAssembly(installPath))
            {
                //normal patching should never fail at this point
                //because this is no update and we are already patched
                //TO-DO get hook that crashed the patching and deactive mod instead
                //No idea how to do that correctly
                Dialogs.showNotification("Scrolls is broken", "Your Scrolls install appears to be broken or modified by other tools. Scrolls Summoner failed to load and will de-install itself");
                File.Delete(installPath + "Assembly-CSharp.dll");
                File.Copy(modLoaderPath + System.IO.Path.DirectorySeparatorChar + "Assembly-CSharp.dll", installPath + "Assembly-CSharp.dll");
                Application.Quit();
            }

            Platform.RestartGame();
        }
Example #3
0
        public static void standalonePatch()
        {
            bool writetofile = true;             //(Platform.getOS () == Platform.OS.Mac);

            Platform.ErrorLog("stand alone patch");
            Console.WriteLine("Preparing...");
            if (writetofile)
            {
                Platform.ErrorLog("Preparing...");
            }

            //get Path of Scrolls Data Folder
            String installPath   = Platform.getGlobalScrollsInstallPath();
            String modloaderpath = Platform.getModLoaderPath();

            if (installPath == null)
            {
                return;
            }
            Console.WriteLine("installpath: " + installPath);
            if (writetofile)
            {
                Platform.ErrorLog("installpath: " + installPath);
            }
            Console.WriteLine("Creating ModLoader folder...");
            if (writetofile)
            {
                Platform.ErrorLog("Creating ModLoader folder...");
            }
            //create modloader folder
            if (!System.IO.Directory.Exists(modloaderpath))
            {
                System.IO.Directory.CreateDirectory(modloaderpath);
            }

            Console.WriteLine("Backup/Reset assembly...");
            if (writetofile)
            {
                Platform.ErrorLog("Backup/Reset assembly...");
            }

            //backup original assembly
            if (!System.IO.File.Exists(modloaderpath + System.IO.Path.DirectorySeparatorChar + "Assembly-CSharp.dll"))
            {
                System.IO.File.Copy(installPath + "Assembly-CSharp.dll", modloaderpath + System.IO.Path.DirectorySeparatorChar + "Assembly-CSharp.dll");
            }
            else
            {
                //if a backup already exists, it is much more likely that the current assembly is messed up and the user wants to repatch
                System.IO.File.Delete(installPath + "Assembly-CSharp.dll");
                System.IO.File.Copy(modloaderpath + System.IO.Path.DirectorySeparatorChar + "Assembly-CSharp.dll", installPath + "Assembly-CSharp.dll");
            }

            Console.WriteLine("Copying ModLoader.dll...");
            if (writetofile)
            {
                Platform.ErrorLog("Copying ModLoader.dll...");
            }
            //copy modloader for patching
            if (System.IO.File.Exists(installPath + "ScrollsModLoader.dll"))
            {
                System.IO.File.Delete(installPath + "ScrollsModLoader.dll");
            }
            System.IO.File.Copy(System.Reflection.Assembly.GetExecutingAssembly().Location, installPath + "ScrollsModLoader.dll");

            //reset ini
            if (System.IO.File.Exists(modloaderpath + System.IO.Path.DirectorySeparatorChar + "mods.ini"))
            {
                System.IO.File.Delete(modloaderpath + System.IO.Path.DirectorySeparatorChar + "mods.ini");
            }



            Console.WriteLine("Create shortcut...");
            if (writetofile)
            {
                Platform.ErrorLog("Create shortcut...");
            }
            string ddsc = System.IO.Path.DirectorySeparatorChar + "";

            String apppath = "";

            if (Platform.getOS() == Platform.OS.Win)
            {
                apppath = installPath.Split(new string[] { "Scrolls_Data" + System.IO.Path.DirectorySeparatorChar }, StringSplitOptions.RemoveEmptyEntries) [0];
            }
            if (Platform.getOS() == Platform.OS.Mac)
            {
                apppath = installPath.Split(new string[] { "Data" + System.IO.Path.DirectorySeparatorChar }, StringSplitOptions.RemoveEmptyEntries) [0] + "MacOS" + ddsc;
            }
            String fpath = installPath.Split(new string[] { "game" + System.IO.Path.DirectorySeparatorChar + "versions" }, StringSplitOptions.RemoveEmptyEntries) [0];

            if (Platform.getOS() == Platform.OS.Mac)
            {
                fpath = installPath.Split(new string[] { "versions" + System.IO.Path.DirectorySeparatorChar + "version-" }, StringSplitOptions.RemoveEmptyEntries) [0];
            }

            string args = "--assetsDir \"" + fpath + "game" + ddsc + "assets" + ddsc + "objects\" --assetIndex \"" + fpath + "game" + ddsc + "assets" + ddsc + "indexes" + ddsc + "index-" + Platform.getVersionNumber() + "-production-win.json\"";

            if (Platform.getOS() == Platform.OS.Mac)
            {
                args = "--assetsDir \"" + fpath + "assets" + ddsc + "objects\" --assetIndex \"" + fpath + "assets" + ddsc + "indexes" + ddsc + "index-" + Platform.getVersionNumber() + "-production-osx.json\"";
            }

            String filetxt  = "";
            String filetxt2 = "";

            switch (Platform.getOS())
            {
            case Platform.OS.Win:
                apppath += "Scrolls.exe";
                fpath   += "summoner.bat";
                filetxt  = "START \"\" \"" + apppath + "\" " + args;
                break;

            case Platform.OS.Mac:
                apppath += "Scrolls";
                fpath    = System.IO.Directory.GetParent(System.Reflection.Assembly.GetExecutingAssembly().Location).ToString().Replace("Summoner.app" + ddsc + "Contents" + ddsc + "MacOS", "") + "summoner.command";
                filetxt  = "\"" + apppath + "\" " + args;                //+path to scrolls.exe + arguments!
                filetxt2 = "#!/bin/bash\r\n\"" + apppath + "\" " + args; //+path to scrolls.exe + arguments!
                break;

            default:
                break;
            }
            System.IO.File.WriteAllText(fpath, filetxt);

            if (Platform.getOS() == Platform.OS.Mac)              //platform specific patch :D (need this to restart scrolls!)
            {
                //make .command executeable
                new Process {
                    StartInfo = { FileName = "chmod", Arguments = "u+x " + "\"" + fpath + "\"", UseShellExecute = true }
                }.Start();

                fpath = installPath.Split(new string[] { "versions" + System.IO.Path.DirectorySeparatorChar + "version-" }, StringSplitOptions.RemoveEmptyEntries) [0] + "summoner.sh";
                System.IO.File.WriteAllText(fpath, filetxt2);
            }



            Console.WriteLine("Patching...");
            if (writetofile)
            {
                Platform.ErrorLog("Patching...");
            }
            //patch it
            Patcher patcher = new Patcher();

            if (!patcher.patchAssembly(installPath))
            {
                Console.WriteLine("Patching failed");
                if (writetofile)
                {
                    Platform.ErrorLog("Patching failed");
                }
                //don't safe patch at this point. If the "real" patcher fails, we should tell the user instead
                //save-patching is for installs, that get broken by updates, etc, to keep the install until ScrollsModLoader is updated
                Dialogs.showNotification("Patching failed", "Scrolls Summoner was unable to prepare your client, you are likely using an incompatible version. More at scrollsguide.com");
                return;
            }



            Dialogs.showNotification("Patching complete", "Summoner successfully patched your Scrolls installation. Visit scrollsguide.com/summoner for more information. You can now start Scrolls and enjoy the benefits of Summoner. Warning: fullscreen users may have to manually restart the game");
            Console.WriteLine("Done");
            if (writetofile)
            {
                Platform.ErrorLog("Done");
            }
            return;
        }
Example #4
0
        public void repatch()
        {
            //save ModList
                File.Delete (modLoaderPath+"mods.ini");
                StreamWriter modOrderWriter = File.CreateText (modLoaderPath+"mods.ini");
                foreach (String modId in modOrder) {
                    modOrderWriter.WriteLine (modId);
                }
                modOrderWriter.Flush ();
                modOrderWriter.Close ();

                String installPath = Platform.getGlobalScrollsInstallPath ();
                File.Delete(installPath+"Assembly-CSharp.dll");
                File.Copy(installPath+"ModLoader"+ System.IO.Path.DirectorySeparatorChar +"Assembly-CSharp.dll", installPath+"Assembly-CSharp.dll");

                Patcher patcher = new Patcher ();
                if (!patcher.patchAssembly (Platform.getGlobalScrollsInstallPath ())) {
                    //normal patching should never fail at this point
                    //because this is no update and we are already patched
                    //TO-DO get hook that crashed the patching and deactive mod instead
                    //No idea how to do that correctly
                    Dialogs.showNotification ("Scrolls is broken", "Your Scrolls install appears to be broken or modified by other tools. Scrolls Summoner failed to load and will de-install itself");
                    File.Delete(Platform.getGlobalScrollsInstallPath()+"Assembly-CSharp.dll");
                    File.Copy(Platform.getGlobalScrollsInstallPath()+"ModLoader"+ System.IO.Path.DirectorySeparatorChar +"Assembly-CSharp.dll", Platform.getGlobalScrollsInstallPath()+"Assembly-CSharp.dll");
                    Application.Quit();
                }

                Platform.RestartGame ();
        }
        public void PatchScrolls()
        {
            String URL;
            if (Platform.getOS () == Platform.OS.Win) {
                URL = "http://download.scrolls.com/client/windows.zip";
            } else {
                URL = "http://download.scrolls.com/client/mac.zip";
            }

            String gameFolder = Path.GetFullPath(Directory.GetParent(Platform.getGlobalScrollsInstallPath()).Parent.Parent.Parent.FullName)+ Path.DirectorySeparatorChar;

            //wait
            WebClient webClient = new WebClient();
            if (File.Exists (gameFolder + "game.zip"))
                File.Delete (gameFolder + "game.zip");
            webClient.DownloadFile(URL, gameFolder + "game.zip");

            //backup assembly
            String backupPath = gameFolder +"ScrollsModLoader.dll";
            if (File.Exists (backupPath))
                File.Delete (backupPath);
            File.Copy (Platform.getGlobalScrollsInstallPath ()+"ScrollsModLoader.dll", backupPath);

            //backup modloader folder
            String modBackupPath = gameFolder + "ModLoader";
            if (Directory.Exists (modBackupPath))
                Extensions.DeleteDirectory (modBackupPath);
            Directory.Move (Platform.getGlobalScrollsInstallPath ()+"ModLoader", modBackupPath);
            File.Delete (modBackupPath+"mods.ini");
            File.Delete (modBackupPath+"Assembly-CSharp.dll");

            if (Platform.getOS () == Platform.OS.Win) {

            } else {
                Extensions.DeleteDirectory (gameFolder+ "MacScrolls.app");
            }

            //extract
            ZipFile zip = ZipFile.Read(gameFolder + "game.zip");
            foreach (ZipEntry e in zip)
            {
                e.Extract();
            }

            //move assembly
            File.Copy (backupPath, Platform.getGlobalScrollsInstallPath () + "ScrollsModLoader.dll");
            File.Delete (backupPath);

            //move modloader folder back
            Directory.Move (modBackupPath, Platform.getGlobalScrollsInstallPath ()+"ModLoader");

            //make new repatch backup
            File.Copy (Platform.getGlobalScrollsInstallPath () + "Assembly-CSharp.dll", Platform.getGlobalScrollsInstallPath () + "ModLoader" + Path.DirectorySeparatorChar + "Assembly-CSharp.dll");

            //repatch
            Patcher patcher = new Patcher ();
            if (!patcher.patchAssembly ()) {
                if (!patcher.saveModePatchAssembly ()) {
                    //TO-DO implement

                }
            }

            //restart the game
            if (Platform.getOS () == Platform.OS.Win) {
                new Process { StartInfo = { FileName = Platform.getGlobalScrollsInstallPath() + "..\\..\\Scrolls.exe", Arguments = "" } }.Start ();
                Application.Quit ();
            } else if (Platform.getOS () == Platform.OS.Mac) {
                new Process { StartInfo = { FileName = Platform.getGlobalScrollsInstallPath() + "/../../../../../run.sh", Arguments = "", UseShellExecute=true } }.Start ();
                Application.Quit ();
            } else {
                Application.Quit ();
            }

            //} else
            //	return info.TargetMethod.Invoke (info.Target, info.Arguments);
        }
Example #6
0
        public void PatchScrollsWindows()
        {
            String URL;

            if (Platform.getOS() == Platform.OS.Win)
            {
                URL = "http://download.scrolls.com/client/windows.zip";
            }
            else
            {
                URL = "http://download.scrolls.com/client/mac.zip";
            }

            String gameFolder = Path.GetFullPath(Directory.GetParent(Platform.getGlobalScrollsInstallPath()).Parent.Parent.Parent.FullName) + Path.DirectorySeparatorChar;

            //wait
            WebClientTimeOut webClient = new WebClientTimeOut();

            if (File.Exists(gameFolder + "game.zip"))
            {
                File.Delete(gameFolder + "game.zip");
            }
            try
            {
                webClient.DownloadFile(URL, gameFolder + "game.zip");
            }
            catch (WebException)
            {
                App.Popups.KillCurrentPopup();
                App.Popups.ShowOk(null, "info", "Error", "And error occured while downloading the update.", "OK");
                return;
            }

            //backup assembly
            String backupPath = gameFolder + "ScrollsModLoader.dll";

            if (File.Exists(backupPath))
            {
                File.Delete(backupPath);
            }
            File.Copy(Platform.getGlobalScrollsInstallPath() + "ScrollsModLoader.dll", backupPath);

            //backup modloader folder
            String modBackupPath = gameFolder + "ModLoader" + Path.DirectorySeparatorChar;

            if (Directory.Exists(modBackupPath))
            {
                Extensions.DeleteDirectory(modBackupPath);
            }
            Directory.Move(Platform.getGlobalScrollsInstallPath() + "ModLoader", modBackupPath);
            File.Delete(modBackupPath + "mods.ini");
            File.Delete(modBackupPath + "Assembly-CSharp.dll");

            if (Platform.getOS() == Platform.OS.Win)
            {
                Extensions.DeleteDirectory(gameFolder + "game");
            }
            else
            {
                Extensions.DeleteDirectory(gameFolder + "MacScrolls.app");
            }

            //extract
            ZipFile zip = ZipFile.Read(gameFolder + "game.zip");

            foreach (ZipEntry e in zip)
            {
                e.Extract(gameFolder + "game");
            }

            //move assembly
            File.Copy(backupPath, Platform.getGlobalScrollsInstallPath() + "ScrollsModLoader.dll");
            // File.Delete(backupPath);

            //move modloader folder back
            Directory.Move(modBackupPath, Platform.getGlobalScrollsInstallPath() + "ModLoader");

            //make new repatch backup
            File.Copy(Platform.getGlobalScrollsInstallPath() + "Assembly-CSharp.dll", Platform.getGlobalScrollsInstallPath() + "ModLoader" + Path.DirectorySeparatorChar + "Assembly-CSharp.dll");

            //make sure mods get hooks set with new version
            File.Delete(Platform.getGlobalScrollsInstallPath() + "ModLoader" + Path.DirectorySeparatorChar + "mods.ini");
            ScrollsFilter.clearHooks();
            Console.WriteLine("Cleared Hooks");

            //repatch
            Patcher patcher = new Patcher();

            if (!patcher.patchAssembly(Platform.getGlobalScrollsInstallPath()))
            {
                if (!patcher.safeModePatchAssembly())
                {
                    Dialogs.showNotification("Summoner patch failed", "Summoner failed in patch itself into the updated files. It will uninstall itself. For more informations visit scrollsguide.com/summoner");
                    File.Delete(Platform.getGlobalScrollsInstallPath() + "ScrollsModLoader.dll");
                    Extensions.DeleteDirectory(Platform.getGlobalScrollsInstallPath() + "ModLoader");
                }
            }

            Console.WriteLine("Now restarting the game...");

            //restart the game
            Platform.RestartGame();
        }
        public void PatchScrollsMac()
        {
            String URL;
            if (Platform.getOS () == Platform.OS.Win) {
                URL = "http://download.scrolls.com/client/windows.zip";
            } else {
                URL = "http://download.scrolls.com/client/mac.zip";
            }

            String gameFolder = Path.GetFullPath(Directory.GetParent(Platform.getGlobalScrollsInstallPath()).Parent.Parent.Parent.Parent.FullName)+ Path.DirectorySeparatorChar;
            String modLoaderPath = Platform.getModLoaderPath ();
            String globalScrollsInstallPath = Platform.getGlobalScrollsInstallPath ();
            //wait
            WebClientTimeOut webClient = new WebClientTimeOut();
            if (File.Exists (gameFolder + "game.zip"))
            {
                File.Delete (gameFolder + "game.zip");
            }
            try {
                webClient.DownloadFile(URL, gameFolder + "game.zip");
            } catch (WebException) {
                App.Popups.KillCurrentPopup();
                App.Popups.ShowOk (null, "info", "Error", "And error occured while downloading the update.", "OK");
                return;
            }

            //backup assembly
            String backupPath = gameFolder + "ScrollsModLoader.dll";
            if (File.Exists(backupPath)){
                File.Delete (backupPath);
            }
            File.Copy (globalScrollsInstallPath + "ScrollsModLoader.dll", backupPath);

            //backup modloader folder
            String modBackupPath = modLoaderPath+ Path.DirectorySeparatorChar;
            if (Directory.Exists (modBackupPath)){
                Extensions.DeleteDirectory (modBackupPath);
            }
            Directory.Move (modLoaderPath , modBackupPath);
            File.Delete (modBackupPath + "mods.ini");
            File.Delete (modBackupPath + "Assembly-CSharp.dll");

            if (Platform.getOS () == Platform.OS.Win) {
                Extensions.DeleteDirectory (gameFolder + "game" + Path.DirectorySeparatorChar + "Scrolls_Data");
                File.Delete (gameFolder + "game" + Path.DirectorySeparatorChar + "Scrolls.exe");
            } else {
                Extensions.DeleteDirectory (gameFolder + "MacScrolls.app");
            }

            //extract
            String zipLocation = gameFolder + "game.zip";
            if (Platform.getOS() == Platform.OS.Win){
                String newZipLocation = gameFolder + "game" + Path.DirectorySeparatorChar + "game.zip";
                File.Move(zipLocation, newZipLocation);
                zipLocation = newZipLocation;
            }
            ZipFile zip = ZipFile.Read(zipLocation);
            foreach (ZipEntry e in zip)
            {
                e.Extract();
            }

            //move assembly
            File.Copy (backupPath, globalScrollsInstallPath + "ScrollsModLoader.dll");
            File.Delete (backupPath);

            //move modloader folder back
            Directory.Move (modBackupPath, modLoaderPath);

            //make new repatch backup
            File.Copy (globalScrollsInstallPath + "Assembly-CSharp.dll", modLoaderPath + Path.DirectorySeparatorChar + "Assembly-CSharp.dll");

            //make sure mods get hooks set with new version
            File.Delete (modLoaderPath + Path.DirectorySeparatorChar + "mods.ini");
            ScrollsFilter.clearHooks ();

            //repatch
            Patcher patcher = new Patcher ();
            if (!patcher.patchAssembly (globalScrollsInstallPath)) {
                if (!patcher.safeModePatchAssembly ()) {
                    Dialogs.showNotification ("Summoner patch failed", "Summoner failed in patch itself into the updated files. It will uninstall itself. For more informations visit scrollsguide.com/summoner");
                    File.Delete (globalScrollsInstallPath + "ScrollsModLoader.dll");
                    Extensions.DeleteDirectory (modLoaderPath);
                }
            }

            //restart the game
            Platform.RestartGame ();
        }
Example #8
0
        public static void standalonePatch()
        {
            bool writetofile = true; //(Platform.getOS () == Platform.OS.Mac);
            Platform.ErrorLog ("stand alone patch");
            Console.WriteLine ("Preparing...");
            if(writetofile) Platform.ErrorLog ("Preparing...");

            //get Path of Scrolls Data Folder
            String installPath = Platform.getGlobalScrollsInstallPath();
            String modloaderpath = Platform.getModLoaderPath();
            if (installPath == null) return;
            Console.WriteLine ("installpath: " +installPath);
            if(writetofile) Platform.ErrorLog ("installpath: " +installPath);
            Console.WriteLine ("Creating ModLoader folder...");
            if(writetofile) Platform.ErrorLog("Creating ModLoader folder...");
            //create modloader folder
            if (!System.IO.Directory.Exists(modloaderpath)) {
                System.IO.Directory.CreateDirectory(modloaderpath);
            }

            Console.WriteLine ("Backup/Reset assembly...");
            if(writetofile) Platform.ErrorLog("Backup/Reset assembly...");

            //backup original assembly
            if (!System.IO.File.Exists(modloaderpath+ System.IO.Path.DirectorySeparatorChar +"Assembly-CSharp.dll"))
                System.IO.File.Copy (installPath+"Assembly-CSharp.dll", modloaderpath + System.IO.Path.DirectorySeparatorChar +"Assembly-CSharp.dll");
            else {
            //if a backup already exists, it is much more likely that the current assembly is messed up and the user wants to repatch
                System.IO.File.Delete(installPath+"Assembly-CSharp.dll");
                System.IO.File.Copy(modloaderpath + System.IO.Path.DirectorySeparatorChar +"Assembly-CSharp.dll", installPath+"Assembly-CSharp.dll");
            }

            Console.WriteLine ("Copying ModLoader.dll...");
            if(writetofile) Platform.ErrorLog("Copying ModLoader.dll...");
            //copy modloader for patching
            if (System.IO.File.Exists(installPath+"ScrollsModLoader.dll"))
                System.IO.File.Delete(installPath+"ScrollsModLoader.dll");
            System.IO.File.Copy(System.Reflection.Assembly.GetExecutingAssembly().Location, installPath+"ScrollsModLoader.dll");

            //reset ini
            if (System.IO.File.Exists(modloaderpath+ System.IO.Path.DirectorySeparatorChar +"mods.ini"))
                System.IO.File.Delete(modloaderpath+ System.IO.Path.DirectorySeparatorChar +"mods.ini");

            Console.WriteLine("Create shortcut...");
            if(writetofile) Platform.ErrorLog("Create shortcut...");
            string ddsc = System.IO.Path.DirectorySeparatorChar+"";

            String apppath = "";
            if(Platform.getOS() == Platform.OS.Win) apppath = installPath.Split (new string[]{ "Scrolls_Data" +  System.IO.Path.DirectorySeparatorChar}, StringSplitOptions.RemoveEmptyEntries) [0];
            if(Platform.getOS() == Platform.OS.Mac) apppath = installPath.Split (new string[]{ "Data" +  System.IO.Path.DirectorySeparatorChar}, StringSplitOptions.RemoveEmptyEntries) [0] + "MacOS" + ddsc;
            String fpath = installPath.Split (new string[]{ "game" +  System.IO.Path.DirectorySeparatorChar + "versions"}, StringSplitOptions.RemoveEmptyEntries) [0];
            if (Platform.getOS () == Platform.OS.Mac) fpath = installPath.Split (new string[]{ "versions" +  System.IO.Path.DirectorySeparatorChar + "version-"}, StringSplitOptions.RemoveEmptyEntries) [0];

            string args = "--assetsDir \""+ fpath +"game"+ddsc+"assets"+ddsc+"objects\" --assetIndex \""+fpath+ "game"+ddsc+"assets"+ddsc+"indexes"+ddsc+"index-" + Platform.getVersionNumber() + "-production-win.json\"";
            if(Platform.getOS() == Platform.OS.Mac) args = "--assetsDir \""+ fpath + "assets"+ddsc+"objects\" --assetIndex \""+fpath+"assets"+ddsc+"indexes"+ddsc+"index-" + Platform.getVersionNumber() + "-production-osx.json\"";

            String filetxt = "";
            String filetxt2 = "";
            String errorlog = "";
            String errorlogpath = "";
            switch (Platform.getOS ())
            {
            case Platform.OS.Win:
                errorlogpath = fpath + "errorlog.bat";
                errorlog = "START \"\" \"" + apppath +"Scrolls_Data"+ ddsc + "output_log.txt"+ "\"";
                apppath += "Scrolls.exe";
                fpath += "summoner.bat";
                filetxt = "START \"\" \"" + apppath + "\" " + args;
                break;
            case Platform.OS.Mac:
                errorlogpath = System.IO.Directory.GetParent (System.Reflection.Assembly.GetExecutingAssembly ().Location).ToString ().Replace( "Summoner.app" + ddsc + "Contents" + ddsc + "MacOS", "") + "errorlog.command";
                errorlog ="open -a Textedit \"" + System.IO.Directory.GetParent (System.Reflection.Assembly.GetExecutingAssembly ().Location).ToString ().Replace( "Desktop" + ddsc + "Summoner.app" + ddsc + "Contents" + ddsc + "MacOS", "") + "Library" + ddsc + "Logs" + ddsc + "Unity" + ddsc + "Player.log"+ "\"";
                apppath +="Scrolls";
                fpath = System.IO.Directory.GetParent (System.Reflection.Assembly.GetExecutingAssembly ().Location).ToString ().Replace( "Summoner.app" + ddsc + "Contents" + ddsc + "MacOS", "") + "summoner.command";
                filetxt ="\"" + apppath + "\" " + args; //+path to scrolls.exe + arguments!
                filetxt2 ="#!/bin/bash\r\n\"" + apppath + "\" " + args; //+path to scrolls.exe + arguments!

                break;
            default:
                break;
            }
            System.IO.File.WriteAllText (fpath, filetxt);
            System.IO.File.WriteAllText (errorlogpath, errorlog);

            generateBatches(fpath, filetxt, installPath);//genrate login-batches!

            if (Platform.getOS () == Platform.OS.Mac) //platform specific patch :D (need this to restart scrolls!)
            {
                //make .command executeable
                new Process { StartInfo = { FileName = "chmod", Arguments = "u+x " + "\"" +fpath + "\"", UseShellExecute=true } }.Start ();
                new Process { StartInfo = { FileName = "chmod", Arguments = "u+x " + "\"" +errorlogpath + "\"", UseShellExecute=true } }.Start ();

                fpath = installPath.Split (new string[]{ "versions" + System.IO.Path.DirectorySeparatorChar + "version-" }, StringSplitOptions.RemoveEmptyEntries) [0] + "summoner.sh";
                System.IO.File.WriteAllText (fpath, filetxt2);
            }

            Console.WriteLine ("Patching...");
            if(writetofile) Platform.ErrorLog("Patching...");
            //patch it
            Patcher patcher = new Patcher();
            if (!patcher.patchAssembly(installPath)) {
                Console.WriteLine("Patching failed");
                if(writetofile) Platform.ErrorLog("Patching failed");
                //don't safe patch at this point. If the "real" patcher fails, we should tell the user instead
                //save-patching is for installs, that get broken by updates, etc, to keep the install until ScrollsModLoader is updated
                Dialogs.showNotification ("Patching failed", "Scrolls Summoner was unable to prepare your client, you are likely using an incompatible version. More at scrollsguide.com");
                return;
            }

            Dialogs.showNotification ("Patching complete", "Summoner successfully patched your Scrolls installation. Visit scrollsguide.com/summoner for more information. You can now start Scrolls and enjoy the benefits of Summoner. Warning: fullscreen users may have to manually restart the game");
            Console.WriteLine ("Done");
            if(writetofile) Platform.ErrorLog ("Done");
            return;
        }
Example #9
0
        public ModLoader()
        {
            //System.Diagnostics.StackTrace t = new System.Diagnostics.StackTrace();
            //Console.WriteLine (t);

            String installPath = Platform.getGlobalScrollsInstallPath();
            String modLoaderPath = installPath + "ModLoader" + System.IO.Path.DirectorySeparatorChar;
            bool repatchNeeded = false;

            //load mod list
            if (!File.Exists (modLoaderPath+"mods.ini")) {
                File.CreateText (modLoaderPath+"mods.ini").Close();
                //first launch, set hooks for patches
                repatchNeeded = true;
            }
            modList = File.ReadAllLines (modLoaderPath+"mods.ini").ToList();

            //match it with mods avaiable
            if (!Directory.Exists (modLoaderPath+"mods"))
                Directory.CreateDirectory (modLoaderPath+"mods");
            String[] folderList = (from subdirectory in Directory.GetDirectories(modLoaderPath+"mods")
                                    where Directory.GetFiles(subdirectory, "*.mod.dll").Length != 0 ||
                                   		  Directory.GetFiles(subdirectory, "*.Mod.dll").Length != 0
                                    select subdirectory).ToArray();

            ResolveEventHandler resolver = new ResolveEventHandler(CurrentDomainOnAssemblyResolve);
            AppDomain.CurrentDomain.AssemblyResolve += resolver;

            //load mods
            foreach (String folder in folderList) {
                try {
                    String[] modFiles = Directory.GetFiles (folder, "*.mod.dll");
                    if (Platform.getOS() != Platform.OS.Win) modFiles.Concat(Directory.GetFiles (folder, "*.Mod.dll")).ToArray();
                    foreach (String modFile in modFiles) {
                        Assembly mod = Assembly.LoadFile(modFile);
                        Type[] modClasses = (from modClass in mod.GetTypes ()
                                             where modClass.InheritsFrom (typeof(ScrollsModLoader.Interfaces.BaseMod))
                                             select modClass).ToArray();
                        foreach (Type modClass in modClasses) {
                            modInstances.Add((BaseMod)(modClass.GetConstructor (Type.EmptyTypes).Invoke (new object[0])));
                            //Console.WriteLine("added mod");
                        }
                    }
                } catch (ReflectionTypeLoadException exp) {
                    Console.WriteLine(exp.ToString());
                }
            }

            //check mod list
            List<BaseMod> modInstancesCpy = new List<BaseMod>(modInstances);
            foreach (BaseMod mod in modInstancesCpy) {
                if (!modList.Contains (mod.GetName()+"."+mod.GetVersion())) {
                    modList.Add (mod.GetName()+"."+mod.GetVersion());
                    repatchNeeded = true;
                    break;
                } else {
                    //re-sort for mod order calling
                    modInstances.Remove (mod);
                    modInstances.Insert(modList.IndexOf(mod.GetName()+"."+mod.GetVersion()), mod);
                }
            }

            TypeDefinitionCollection types = AssemblyFactory.GetAssembly (modLoaderPath+"Assembly-CSharp.dll").MainModule.Types;
            TypeDefinition[] typeArray = new TypeDefinition[types.Count];
            types.CopyTo(typeArray, 0);

            //get ModAPI
            APIHandler api = new APIHandler ();

            //add Patches
            patches.Add(new PatchUpdater(types));
            //patches.Add(new PatchOffline(types));

            PatchSettingsMenu settingsMenuHook = new PatchSettingsMenu (types);
            api.setSceneCallback (settingsMenuHook);
            patches.Add (settingsMenuHook);

            PatchModsMenu modMenuHook = new PatchModsMenu (types);
            modMenuHook.Initialize (api);
            patches.Add (modMenuHook);

            publicAPI = api;

            foreach (BaseMod mod in modInstances) {
                mod.Initialize (publicAPI);
            }

            //we are loaded, get the hooks
            foreach (BaseMod mod in modInstancesCpy) {

                MethodDefinition[] requestedHooks = new MethodDefinition[] { };

                bool hooksAreValid = true;
                try {
                    requestedHooks = mod.GetHooks (types, SharedConstants.getGameVersion());
                } catch {
                    modInstances.Remove (mod);
                    hooksAreValid = false;
                }

                //check hooks
                foreach (MethodDefinition hook in requestedHooks) {
                    //type does not exists
                    if ((from type in typeArray
                         where type.Equals(hook.DeclaringType)
                         select type).Count() == 0) {
                        //disable mod
                        modInstances.Remove (mod);
                        hooksAreValid = false;
                        break;
                    }
                }
                if (!hooksAreValid)
                    continue;

                //add hooks
                foreach (MethodDefinition hook in requestedHooks) {
                    ScrollsFilter.AddHook(hook);
                }
            }

            //remove old mods from list
            foreach (String modDesc in modList.ToArray()) {
                bool loadedModFound = false;
                foreach (BaseMod mod in modInstances) {
                    if (modDesc.Equals (mod.GetName()+"."+mod.GetVersion()))
                        loadedModFound = true;
                }
                if (!loadedModFound)
                    modList.Remove (modDesc);
            }

            //save ModList
            File.Delete (modLoaderPath+"mods.ini");
            StreamWriter modListWriter = File.CreateText (modLoaderPath+"mods.ini");
            foreach (String modDesc in modList) {
                modListWriter.WriteLine (modDesc);
            }
            modListWriter.Flush ();
            modListWriter.Close ();

            //repatch if necessary
            if (repatchNeeded) {

                Patcher patcher = new Patcher ();
                if (!patcher.patchAssembly ()) {
                    //normal patching should never fail at this point
                    //because this is no update and we are already patched
                    //TO-DO get hook that crashed the patching and deactive mod instead
                    //No idea how to do that correctly however
                    Dialogs.showNotification ("Scrolls is broken", "Your Scrolls install appears to be broken or modified by other tools. ModLoader failed to load and will de-install itself");
                    File.Delete(installPath+"Assembly-CSharp.dll");
                    File.Copy(installPath+"ModLoader"+ System.IO.Path.DirectorySeparatorChar +"Assembly-CSharp.dll", installPath+"Assembly-CSharp.dll");
                    Application.Quit();
                }

                //restart the game
                if (Platform.getOS() == Platform.OS.Win)
                {
                    Console.WriteLine(Platform.getGlobalScrollsInstallPath() + "..\\..\\Scrolls.exe");
                    //try {
                        new Process { StartInfo = { FileName = Platform.getGlobalScrollsInstallPath() + "..\\..\\Scrolls.exe", Arguments = "" } }.Start();
                    //} catch {}
                    Application.Quit();
                }
                else if (Platform.getOS() == Platform.OS.Mac)
                {
                    new Process { StartInfo = { FileName = Platform.getGlobalScrollsInstallPath() + "/../../../../../run.sh", Arguments = "", UseShellExecute=true } }.Start();
                    Application.Quit();
                } else {
                    Application.Quit();
                }
            }
        }
Example #10
0
        public static void standalonePatch()
        {
            Console.WriteLine("Preparing...");

            //get Path of Scrolls Data Folder
            String installPath = Platform.getGlobalScrollsInstallPath();

            if (installPath == null)
            {
                return;
            }

            Console.WriteLine("Creating ModLoader folder...");

            //create modloader folder
            if (!System.IO.Directory.Exists(installPath + "ModLoader"))
            {
                System.IO.Directory.CreateDirectory(installPath + "ModLoader");
            }

            Console.WriteLine("Backup/Reset assembly...");
            //backup original assembly
            if (!System.IO.File.Exists(installPath + "ModLoader" + System.IO.Path.DirectorySeparatorChar + "Assembly-CSharp.dll"))
            {
                System.IO.File.Copy(installPath + "Assembly-CSharp.dll", installPath + "ModLoader" + System.IO.Path.DirectorySeparatorChar + "Assembly-CSharp.dll");
            }
            else
            {
                //if a backup already exists, it is much more likely that the current assembly is messed up and the user wants to repatch
                System.IO.File.Delete(installPath + "Assembly-CSharp.dll");
                System.IO.File.Copy(installPath + "ModLoader" + System.IO.Path.DirectorySeparatorChar + "Assembly-CSharp.dll", installPath + "Assembly-CSharp.dll");
            }

            Console.WriteLine("Copying ModLoader.dll...");
            //copy modloader for patching
            if (System.IO.File.Exists(installPath + "ScrollsModLoader.dll"))
            {
                System.IO.File.Delete(installPath + "ScrollsModLoader.dll");
            }
            System.IO.File.Copy(System.Reflection.Assembly.GetExecutingAssembly().Location, installPath + "ScrollsModLoader.dll");

            //reset ini
            if (System.IO.File.Exists(installPath + "ModLoader" + System.IO.Path.DirectorySeparatorChar + "mods.ini"))
            {
                System.IO.File.Delete(installPath + "ModLoader" + System.IO.Path.DirectorySeparatorChar + "mods.ini");
            }

            Console.WriteLine("Patching...");
            //patch it
            Patcher patcher = new Patcher();

            if (!patcher.patchAssembly(installPath))
            {
                Console.WriteLine("Patching failed");
                //don't safe patch at this point. If the "real" patcher fails, we should tell the user instead
                //save-patching is for installs, that get broken by updates, etc, to keep the install until ScrollsModLoader is updated
                Dialogs.showNotification("Patching failed", "Scrolls Summoner was unable to prepare your client, you are likely using an incompatible version. More at scrollsguide.com");
                return;
            }

            Dialogs.showNotification("Patching complete", "Summoner successfully patched your Scrolls installation. Visit scrollsguide.com/summoner for more information. You can now start Scrolls and enjoy the benefits of Summoner. Warning: fullscreen users may have to manually restart the game");
            Console.WriteLine("Done");
            return;
        }
Example #11
0
        public static void standalonePatch()
        {
            Console.WriteLine ("Preparing...");

            //get Path of Scrolls Data Folder
            String installPath = Platform.getGlobalScrollsInstallPath();
            if (installPath == null) return;

            Console.WriteLine ("Creating ModLoader folder...");

            //create modloader folder
            if (!System.IO.Directory.Exists(installPath+"ModLoader")) {
                System.IO.Directory.CreateDirectory(installPath+"ModLoader");
            }

            Console.WriteLine ("Backup/Reset assembly...");
            //backup original assembly
            if (!System.IO.File.Exists(installPath+"ModLoader"+ System.IO.Path.DirectorySeparatorChar +"Assembly-CSharp.dll"))
                System.IO.File.Copy (installPath+"Assembly-CSharp.dll", installPath + "ModLoader"+ System.IO.Path.DirectorySeparatorChar +"Assembly-CSharp.dll");
            else {
            //if a backup already exists, it is much more likely that the current assembly is messed up and the user wants to repatch
                System.IO.File.Delete(installPath+"Assembly-CSharp.dll");
                System.IO.File.Copy(installPath+"ModLoader"+ System.IO.Path.DirectorySeparatorChar +"Assembly-CSharp.dll", installPath+"Assembly-CSharp.dll");
            }

            Console.WriteLine ("Copying ModLoader.dll...");
            //copy modloader for patching
            if (System.IO.File.Exists(installPath+"ScrollsModLoader.dll"))
                System.IO.File.Delete(installPath+"ScrollsModLoader.dll");
            System.IO.File.Copy(System.Reflection.Assembly.GetExecutingAssembly().Location, installPath+"ScrollsModLoader.dll");

            //reset ini
            if (System.IO.File.Exists(installPath+"ModLoader"+ System.IO.Path.DirectorySeparatorChar +"mods.ini"))
                System.IO.File.Delete(installPath+"ModLoader"+ System.IO.Path.DirectorySeparatorChar +"mods.ini");

            Console.WriteLine ("Patching...");
            //patch it
            Patcher patcher = new Patcher();
            if (!patcher.patchAssembly(installPath)) {
                Console.WriteLine("Patching failed");
                //don't safe patch at this point. If the "real" patcher fails, we should tell the user instead
                //save-patching is for installs, that get broken by updates, etc, to keep the install until ScrollsModLoader is updated
                Dialogs.showNotification ("Patching failed", "Scrolls Summoner was unable to prepare your client, you are likely using an incompatible version. More at scrollsguide.com");
                return;
            }

            Dialogs.showNotification ("Patching complete", "Summoner successfully patched your Scrolls installation. Visit scrollsguide.com/summoner for more information. You can now start Scrolls and enjoy the benefits of Summoner. Warning: fullscreen users may have to manually restart the game");
            Console.WriteLine ("Done");
            return;
        }