public static void AfterSelectedWorld()
 {
     WorldLoaded = true;
     SAVE_LOC    = GAMEDATA_FOLDER + "savegames/" + ServerManager.WorldName + "/";
     MachineManager.MACHINE_JSON = $"{SAVE_LOC}/{NAMESPACE}.Machines.json";
     PandaLogger.Log(ChatColor.lime, "World load detected. Starting monitor...");
 }
 public static void OnAssemblyLoaded(string path)
 {
     MOD_FOLDER = Path.GetDirectoryName(path);
     PandaLogger.Log("Found mod in {0}", MOD_FOLDER);
     LOCALIZATION_FOLDER_PANDA = Path.Combine(MOD_FOLDER, "localization").Replace("\\", "/");
     ICON_FOLDER_PANDA         = Path.Combine(MOD_FOLDER, "icons").Replace("\\", "/");
     MESH_FOLDER_PANDA         = Path.Combine(MOD_FOLDER, "Meshes").Replace("\\", "/");
     TEXTURE_FOLDER_PANDA      = Path.Combine(MOD_FOLDER, "Textures").Replace("\\", "/");
     AUDIO_FOLDER_PANDA        = Path.Combine(MOD_FOLDER, "Audio").Replace("\\", "/");
 }
 private static void ActivateMagicItems()
 {
     foreach (var item in _magicITems)
     {
         if (Activator.CreateInstance(item) is IMagicItem magicItem &&
             !string.IsNullOrEmpty(magicItem.Name))
         {
             PandaLogger.Log($"Magic Item {magicItem.Name} Loaded!");
         }
     }
 }
        public static void AfterStartup()
        {
            PandaLogger.Log(ChatColor.lime, "Active. Version {0}", MOD_VER);
            RUNNING = true;
            ChatCommands.CommandManager.RegisterCommand(new GameDifficultyChatCommand());
            ChatCommands.CommandManager.RegisterCommand(new AI.CalltoArms());
            ChatCommands.CommandManager.RegisterCommand(new Items.ArmorCommand());
#if Debug
            ChatCommands.CommandManager.RegisterCommand(new Research.PandaResearchCommand());
#endif
        }
 private static void ActivateBosses()
 {
     foreach (var monster in _monsters)
     {
         if (Activator.CreateInstance(monster) is IPandaBoss pandaBoss &&
             !string.IsNullOrEmpty(pandaBoss.Name))
         {
             PandaLogger.Log($"Boss {pandaBoss.Name} Loaded!");
             MonsterManager.AddBoss(pandaBoss);
         }
     }
 }
 private static void ActivateMachine()
 {
     foreach (var s in _machineSettings)
     {
         if (Activator.CreateInstance(s) is IMachineSettings machineSettings &&
             !string.IsNullOrEmpty(machineSettings.Name))
         {
             PandaLogger.Log($"Machine {machineSettings.Name} Loaded!");
             MachineManager.RegisterMachineType(machineSettings);
         }
     }
 }
        public static Vector3Int GetBlockOffset(this Vector3Int vector, BlockSide blockSide)
        {
            var vectorValues = blockSide.GetAttribute <BlockSideVectorValuesAttribute>();

            if (vectorValues != null)
            {
                return(vector.Add(vectorValues.X, vectorValues.Y, vectorValues.Z));
            }
            else
            {
                PandaLogger.Log(ChatColor.yellow, "Unable to find BlockSideVectorValuesAttribute for {0}", blockSide.ToString());
                return(vector);
            }
        }
        private static void ActivateSeasons()
        {
            foreach (var s in _season)
            {
                if (Activator.CreateInstance(s) is ISeason season &&
                    !string.IsNullOrEmpty(season.Name))
                {
                    PandaLogger.Log($"Season {season.Name} Loaded.");
                    SeasonsFactory.AddSeason(season);
                }
            }

            SeasonsFactory.ResortSeasons();
        }
        public static Dictionary <string, List <string> > GetJSONSettingPaths(string fileType)
        {
            Dictionary <string, List <string> > retval = new Dictionary <string, List <string> >();

            try
            {
                foreach (var info in GameLoader.AllModInfos)
                {
                    if (info.Value.TryGetAs(GameLoader.NAMESPACE + ".jsonFiles", out JSONNode jsonFilles))
                    {
                        foreach (var jsonNode in jsonFilles.LoopArray())
                        {
                            if (jsonNode.TryGetAs("fileType", out string jsonFileType))
                            {
                                if (jsonFileType == fileType)
                                {
                                    if (jsonNode.TryGetAs("relativePath", out string itemsPath))
                                    {
                                        if (!retval.ContainsKey(info.Key))
                                        {
                                            retval.Add(info.Key, new List <string>());
                                        }

                                        retval[info.Key].Add(itemsPath);
                                        PandaLogger.LogToFile("Getting json configurations {0} from file {1}", fileType, info.Key);
                                    }
                                    else
                                    {
                                        PandaLogger.Log(ChatColor.red, "Unable to read relativePath for fileType {0} from file {1}", itemsPath, info.Key);
                                    }
                                }
                            }
                            else
                            {
                                PandaLogger.Log(ChatColor.red, "Unable to read fileType from file {0}", info.Key);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                PandaLogger.LogError(ex);
            }

            return(retval);
        }
        private static Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
        {
            PandaLogger.Log(args.Name);
            try
            {
                if (args.Name.Contains("System.Xml.Linq"))
                {
                    return(Assembly.LoadFile(MOD_FOLDER + "/System.Xml.Linq.dll"));
                }

                if (args.Name.Contains("System.ComponentModel.DataAnnotations"))
                {
                    return(Assembly.LoadFile(MOD_FOLDER + "/System.ComponentModel.DataAnnotations.dll"));
                }

                if (args.Name.Contains("System.Numerics"))
                {
                    return(Assembly.LoadFile(MOD_FOLDER + "/System.Numerics.dll"));
                }

                if (args.Name.Contains("System.Runtime.Serialization"))
                {
                    return(Assembly.LoadFile(MOD_FOLDER + "/System.Runtime.Serialization.dll"));
                }

                if (args.Name.Contains("System.Transactions"))
                {
                    return(Assembly.LoadFile(MOD_FOLDER + "/System.Transactions.dll"));
                }

                if (args.Name.Contains("System.Data.SQLite"))
                {
                    return(Assembly.LoadFile(MOD_FOLDER + "/System.Data.SQLite.dll"));
                }

                if (args.Name.Contains("System.Data"))
                {
                    return(Assembly.LoadFile(MOD_FOLDER + "/System.Data.dll"));
                }
            }
            catch (Exception ex)
            {
                PandaLogger.LogError(ex);
            }

            return(null);
        }
Exemple #11
0
        public static bool TryGetGuardJobSettings(this BlockEntities.BlockEntityCallbacks callbacks, string name, out GuardJobSettings guardJobSettings)
        {
            guardJobSettings = null;

            var guardJobInstance = callbacks.AutoLoadedInstances.Where(o => o is BlockJobManager <GuardJobInstance> manager && manager.Settings is GuardJobSettings set && set.NPCTypeKey == name).FirstOrDefault() as BlockJobManager <GuardJobInstance>;

            if (guardJobInstance == null)
            {
                PandaLogger.Log(ChatColor.yellow, "Unable to find guard job settings for {0}", name);
            }
            else
            {
                guardJobSettings = guardJobInstance.Settings as GuardJobSettings;
            }

            return(guardJobSettings != null);
        }
Exemple #12
0
        public static bool TryGetCraftJobSettings(this BlockEntities.BlockEntityCallbacks callbacks, string name, out CraftingJobSettings craftingJobSettings)
        {
            craftingJobSettings = null;

            var craftJobInstance = callbacks.AutoLoadedInstances.FirstOrDefault(o => o is BlockJobManager <CraftingJobInstance> manager && manager.Settings is CraftingJobSettings set && set.NPCTypeKey == name) as BlockJobManager <CraftingJobInstance>;

            if (craftJobInstance == null)
            {
                PandaLogger.Log(ChatColor.yellow, "Unable to find craft job settings for {0}", name);
            }
            else
            {
                craftingJobSettings = craftJobInstance.Settings as CraftingJobSettings;
            }

            return(craftingJobSettings != null);
        }
Exemple #13
0
        public static Version GetGitVerion()
        {
            Version version  = null;
            var     releases = GetReleases();

            if (!string.IsNullOrEmpty(releases))
            {
                var iName     = releases.IndexOf(NAME);
                var nameSub   = releases.Substring(iName + NAME.Length);
                var iEndName  = nameSub.IndexOf("\"");
                var verString = nameSub.Substring(0, iEndName);

                PandaLogger.Log(verString);
                version = new Version(verString);
            }

            return(version);
        }
        public static void Localize()
        {
            PandaLogger.Log("Localization directory: {0}", LOCALIZATION_FOLDER_PANDA);
            try
            {
                string[] array = new string[]
                {
                    "translation.json"
                };
                for (int i = 0; i < array.Length; i++)
                {
                    string   text   = array[i];
                    string[] files  = Directory.GetFiles(LOCALIZATION_FOLDER_PANDA, text, SearchOption.AllDirectories);
                    string[] array2 = files;
                    for (int j = 0; j < array2.Length; j++)
                    {
                        string text2 = array2[j];
                        try
                        {
                            JSONNode jsonFromMod;
                            if (JSON.Deserialize(text2, out jsonFromMod, false))
                            {
                                string name = Directory.GetParent(text2).Name;

                                if (!string.IsNullOrEmpty(name) && !string.IsNullOrEmpty(text))
                                {
                                    PandaLogger.Log("Found mod localization file for '{0}' localization", name);
                                    localize(name, text, jsonFromMod);
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            PandaLogger.Log("Exception reading localization from {0}; {1}", text2, ex.Message);
                        }
                    }
                }
            }
            catch (DirectoryNotFoundException)
            {
                PandaLogger.Log("Localization directory not found at {0}", LOCALIZATION_FOLDER_PANDA);
            }
        }
        public static void OnAssemblyLoaded(string path)
        {
            MOD_FOLDER = Path.GetDirectoryName(path);
            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("\\", "/") + "/";

            var fileWasCopied = false;

            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);
                }
            }

            if (fileWasCopied)
            {
                PandaLogger.Log(ChatColor.red,
                                "For settlers mod to fully be installed the Colony Survival surver needs to be restarted.");
            }
        }
        public static void localize(string locName, string locFilename, JSONNode jsonFromMod)
        {
            try
            {
                if (Server.Localization.Localization.LoadedTranslation == null)
                {
                    PandaLogger.Log("Unable to localize. Server.Localization.Localization.LoadedTranslation is null.");
                }
                else
                {
                    if (Server.Localization.Localization.LoadedTranslation.TryGetValue(locName, out JSONNode jsn))
                    {
                        if (jsn != null)
                        {
                            foreach (KeyValuePair <string, JSONNode> modNode in jsonFromMod.LoopObject())
                            {
                                PandaLogger.Log("Adding localization for '{0}' from '{1}'.", modNode.Key, Path.Combine(locName, locFilename));
                                AddRecursive(jsn, modNode);
                            }
                        }
                        else
                        {
                            PandaLogger.Log("Unable to localize. Localization '{0}' not found and is null.", locName);
                        }
                    }
                    else
                    {
                        PandaLogger.Log("Localization '{0}' not supported", locName);
                    }
                }

                PandaLogger.Log("Patched mod localization file '{0}/{1}'", locName, locFilename);
            }
            catch (Exception ex)
            {
                PandaLogger.LogError(ex, "Exception while localizing {0}", Path.Combine(locName, locFilename));
            }
        }
        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.");
            }
        }
 public static void AfterWorldLoad()
 {
     WorldLoaded = true;
     PandaLogger.Log(ChatColor.lime, "World load detected. Starting monitor...");
 }
Exemple #19
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) { }
        }