예제 #1
0
        public static void WriteVersionsToConsole()
        {
            try
            {
                var gitVer   = GetGitVerion();
                var bkFolder = GameLoader.GAMEDATA_FOLDER + "Pandaros.bk";

                PandaLogger.Log(ChatColor.green, "Mod version: {0}.", GameLoader.MOD_VER.ToString());
                PandaLogger.Log(ChatColor.green, "Git version: {0}.", gitVer.ToString());

                var versionCompare = GameLoader.MOD_VER.CompareTo(gitVer);

                if (versionCompare < 0)
                {
                    PandaLogger.Log(ChatColor.red, "Settlers! version is out of date. Downloading new version from: {0}",
                                    GIT_URL);

                    var releases  = GetReleases();
                    var iName     = releases.IndexOf(ASSETS);
                    var nameSub   = releases.Substring(iName + ASSETS.Length);
                    var zip       = releases.IndexOf(ZIP);
                    var zipSub    = releases.Substring(zip + ZIP.Length);
                    var iEndName  = zipSub.IndexOf("\"");
                    var verString = zipSub.Substring(0, iEndName);
                    var newVer    = GameLoader.MODS_FOLDER + $"/{gitVer}.zip";
                    var oldVer    = GameLoader.MODS_FOLDER + $"/{GameLoader.MOD_VER}.zip";
                    ServicePointManager.ServerCertificateValidationCallback += (s, ce, ca, p) => true;

                    var webClient = new WebClient();

                    webClient.Headers["User-Agent"] =
                        "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36";

                    webClient.Headers["Content-Type"] = "text";

                    webClient.DownloadFileCompleted += (s, e) =>
                    {
                        if (!NewVer)
                        {
                            NewVer = true;
                            var error = false;

                            try
                            {
                                if (Directory.Exists(bkFolder))
                                {
                                    Directory.Delete(bkFolder, true);
                                }

                                PandaLogger.Log(ChatColor.green,
                                                $"Settlers! update {gitVer} downloaded. Making a backup..");

                                Directory.Move(GameLoader.MODS_FOLDER + "/Pandaros", bkFolder);

                                if (File.Exists(oldVer))
                                {
                                    File.Delete(oldVer);
                                }

                                PandaLogger.Log(ChatColor.green, $"Installing...");

                                try
                                {
                                    var fastZip = new FastZip();
                                    fastZip.ExtractZip(newVer, GameLoader.MODS_FOLDER, null);
                                }
                                catch (Exception ex)
                                {
                                    error = true;

                                    if (Directory.Exists(bkFolder))
                                    {
                                        Directory.Move(bkFolder, GameLoader.MODS_FOLDER + "/Pandaros");
                                    }

                                    PandaLogger.LogError(ex);

                                    PandaLogger.Log(ChatColor.red,
                                                    $"There was an error updating to the latest version of Settlers!");
                                }

                                if (!error)
                                {
                                    PandaLogger.Log(ChatColor.green,
                                                    $"Settlers! update {gitVer} installed. Restart to update!");

                                    PandaChat.SendToAll($"Settlers! update {gitVer} installed. Restart server to update!",
                                                        ChatColor.maroon, ChatStyle.bolditalic);
                                }
                            }
                            catch (Exception)
                            {
                                if (Directory.Exists(bkFolder))
                                {
                                    Directory.Move(bkFolder, GameLoader.MODS_FOLDER + "/Pandaros");
                                }
                            }

                            if (File.Exists(newVer))
                            {
                                File.Delete(newVer);
                            }
                        }
                    };


                    webClient.DownloadFileAsync(new Uri(verString), newVer);
                }
            }
            catch (Exception) { }
        }
예제 #2
0
 public static void AfterWorldLoad()
 {
     WorldLoaded = true;
     PandaLogger.Log(ChatColor.lime, "World load detected. Starting monitor...");
 }
예제 #3
0
        public static void OnAssemblyLoaded(string path)
        {
            MOD_FOLDER            = Path.GetDirectoryName(path);
            Schematic_DEFAULT_LOC = $"{MOD_FOLDER}/Schematics/";
            AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;
            if (!Directory.Exists(Schematic_DEFAULT_LOC))
            {
                Directory.CreateDirectory(Schematic_DEFAULT_LOC);
            }

            PandaLogger.Log("Found mod in {0}", MOD_FOLDER);

            GAME_ROOT       = path.Substring(0, path.IndexOf("gamedata")).Replace("/", "/");
            GAMEDATA_FOLDER = path.Substring(0, path.IndexOf("gamedata") + "gamedata".Length).Replace("/", "/") + "/";

            MODS_FOLDER          = GAMEDATA_FOLDER + "mods/";
            ICON_PATH            = Path.Combine(MOD_FOLDER, "icons").Replace("\\", "/") + "/";
            MESH_PATH            = Path.Combine(MOD_FOLDER, "Meshes").Replace("\\", "/") + "/";
            AUDIO_PATH           = Path.Combine(MOD_FOLDER, "Audio").Replace("\\", "/") + "/";
            TEXTURE_FOLDER_PANDA = Path.Combine(MOD_FOLDER, "Textures").Replace("\\", "/") + "/";
            BLOCKS_ALBEDO_PATH   = Path.Combine(TEXTURE_FOLDER_PANDA, "albedo").Replace("\\", "/") + "/";
            BLOCKS_EMISSIVE_PATH = Path.Combine(TEXTURE_FOLDER_PANDA, "emissive").Replace("\\", "/") + "/";
            BLOCKS_HEIGHT_PATH   = Path.Combine(TEXTURE_FOLDER_PANDA, "height").Replace("\\", "/") + "/";
            BLOCKS_NORMAL_PATH   = Path.Combine(TEXTURE_FOLDER_PANDA, "normal").Replace("\\", "/") + "/";
            BLOCKS_NPC_PATH      = Path.Combine(TEXTURE_FOLDER_PANDA, "npc").Replace("\\", "/") + "/";

            ModInfo = JSON.Deserialize(MOD_FOLDER + "/modInfo.json")[0];

            List <string> allinfos = new List <string>();

            DirSearch(MODS_FOLDER, "*modInfo.json", allinfos);

            foreach (var info in allinfos)
            {
                var modJson = JSON.Deserialize(info)[0];

                if (modJson.TryGetAs("enabled", out bool isEnabled) && isEnabled)
                {
                    PandaLogger.Log("ModInfo Found: {0}", info);
                    AllModInfos[new FileInfo(info).Directory.FullName] = modJson;
                }
            }

            if (!File.Exists(GAME_ROOT + "/colonyserver.exe.config"))
            {
                File.Copy(MOD_FOLDER + "/App.config", GAME_ROOT + "/colonyserver.exe.config");
                FileWasCopied = true;
            }

            foreach (var file in Directory.GetFiles(MOD_FOLDER + "/ZipSupport"))
            {
                var destFile = GAME_ROOT + "colonyserver_Data/Managed/" + new FileInfo(file).Name;

                if (!File.Exists(destFile))
                {
                    FileWasCopied = true;
                    File.Copy(file, destFile);
                }
            }

            GenerateBuiltinBlocks();
            GenerateSettlersBuiltin();

            if (FileWasCopied)
            {
                PandaLogger.Log(ChatColor.red, "For settlers mod to fully be installed the Colony Survival surver needs to be restarted.");
            }
        }