public static void OnAssemblyLoaded(string path)
        {
            MOD_FOLDER            = Path.GetDirectoryName(path).Replace("\\", "/");
            Schematic_DEFAULT_LOC = $"{MOD_FOLDER}/Schematics/";
            AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;

            if (!Directory.Exists(Schematic_DEFAULT_LOC))
            {
                Directory.CreateDirectory(Schematic_DEFAULT_LOC);
            }

            GAME_ROOT       = Path.GetDirectoryName(Assembly.GetCallingAssembly().Location) + @"/../../";
            GAMEDATA_FOLDER = Path.Combine(GAME_ROOT, "gamedata").Replace("\\", "/") + "/";
            MODS_FOLDER     = MOD_FOLDER + @"/../../";

            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];

            SettlersLogger.Log("Found mod in {0}", MOD_FOLDER);
            SettlersLogger.Log("GAME_ROOT in {0}", GAME_ROOT);
            SettlersLogger.Log("GAMEDATA_FOLDER in {0}", GAMEDATA_FOLDER);
            SettlersLogger.Log("MODS_FOLDER in {0}", MODS_FOLDER);

            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)
                {
                    SettlersLogger.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;
            }

            GenerateSettlersBuiltin();

            if (FileWasCopied)
            {
                SettlersLogger.Log(ChatColor.red, "For settlers mod to fully be installed the Colony Survival surver needs to be restarted.");
            }
        }
Beispiel #2
0
        private static Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
        {
            SettlersLogger.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"));
                }

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

            return(null);
        }
        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);
                                        SettlersLogger.LogToFile("Getting json configurations {0} from file {1}", fileType, info.Key);
                                    }
                                    else
                                    {
                                        SettlersLogger.Log(ChatColor.red, "Unable to read relativePath for fileType {0} from file {1}", itemsPath, info.Key);
                                    }
                                }
                            }
                            else
                            {
                                SettlersLogger.Log(ChatColor.red, "Unable to read fileType from file {0}", info.Key);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                SettlersLogger.LogError(ex);
            }

            return(retval);
        }