Exemplo n.º 1
0
        public static bool RemoteCertValidator(Object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
        {
            LogOutput.Log("Validating Certificate...");
            bool validated = true;

            if (sslPolicyErrors != SslPolicyErrors.None)
            {
                foreach (var status in chain.ChainStatus)
                {
                    if (status.Status == X509ChainStatusFlags.RevocationStatusUnknown)
                    {
                        continue;
                    }

                    chain.ChainPolicy.RevocationFlag      = X509RevocationFlag.EntireChain;
                    chain.ChainPolicy.RevocationMode      = X509RevocationMode.Online;
                    chain.ChainPolicy.UrlRetrievalTimeout = new TimeSpan(0, 1, 0);
                    chain.ChainPolicy.VerificationFlags   = X509VerificationFlags.AllFlags;
                    bool chainIsValid = chain.Build((X509Certificate2)certificate);
                    if (!chainIsValid)
                    {
                        validated = false;
                        break;
                    }
                }
            }

            return(validated);
        }
Exemplo n.º 2
0
 public static void Exit()
 {
     foreach (Tuple <string, Assembly> mod in Constants.modAssemblies)
     {
         // Call each mod's GameExiting() function
         var exit = mod.Item2.GetType(mod.Item1 + ".Main", true).GetMethod("GameExiting");
         exit.Invoke(new object(), null);
     }
     LogOutput.Log("Exiting Airport CEO...");
     LogOutput.DisposeFirst();
 }
Exemplo n.º 3
0
        // If there is an update to ModLoader, trigger a message dialog to the player
        static void Postfix()
        {
            // Mono SSL validation always fails, this line does NOT solve the problem!
            ServicePointManager.ServerCertificateValidationCallback += (object sender, X509Certificate cert,
                                                                        X509Chain chain, SslPolicyErrors sslPolicyErrors) => true;
            // Get the list of releases from GitHub
            var req = WebRequest.Create(Constants.githubReleaseURL) as HttpWebRequest;
            List <GitHubRelease> releases = new List <GitHubRelease>();

            try
            {
                releases = Newtonsoft.Json.JsonConvert.DeserializeObject <List <GitHubRelease> >(new Func <string>(() =>
                {
                    using (StreamReader r = new StreamReader(req.GetResponse().GetResponseStream()))
                    {
                        string output = r.ReadToEnd();
                        LogOutput.Log("Received response from GitHub: " + output);
                        return(output);
                    }
                })());
            }
            catch (Exception e)
            {
                LogOutput.Log("Something went wrong when connecting to the internet to find ModLoader releases: " + e.Message, LogOutput.LogType.WARNING);
                while (e.InnerException != null)
                {
                    LogOutput.Log("Inner Exception: " + e.Message, LogOutput.LogType.WARNING);
                    e = e.InnerException;
                }
            }
            foreach (GitHubRelease rel in releases)
            {
                try
                {
                    string version   = rel.tag_name;
                    var    verValues = version.Split('.');
                    LogOutput.Log("Checking ver " + verValues[0] + "." + verValues[1] + "." + verValues[2]);
                    if (Convert.ToInt32(verValues[0]) > Constants.verMajor ||  //Major Version
                        Convert.ToInt32(verValues[1]) > Constants.verMinor ||  // Minor Version
                        Convert.ToInt32(verValues[2]) > Constants.verRevision) // Revision
                    {
                        // If any of the above is true, there is a release with a higher version number than what the player is running!
                        DialogPanel.Instance.ShowMessagePanel("There is an update for ModLoader: " + verValues[0] + "." + verValues[1] + "." + verValues[2]);
                        LogOutput.Log("Newer version of ModLoader on the web: " + verValues[0] + "." + verValues[1] + "." + verValues[2]);
                    }
                }
                catch (Exception e)
                {
                    LogOutput.Log("Something went wrong when getting latest ModLoader release: " + e.Message, LogOutput.LogType.WARNING);
                }
            }
        }
Exemplo n.º 4
0
        public static void Entry()
        {
            LogOutput.Initialize();
            LogOutput.Log("Starting ModLoaderLibrary Version " + Constants.verMajor + "." + Constants.verMinor + "." + Constants.verRevision);
            LogOutput.Log("Beginning Patches...");
            try
            {
                var harmony = HarmonyInstance.Create("com.catcherben.modloader");
                harmony.PatchAll(Assembly.GetExecutingAssembly());
            }
            catch (Exception e)
            {
                LogOutput.Log("Exception when patching: " + e.Message, LogOutput.LogType.ERROR);
                while (e.InnerException != null)
                {
                    LogOutput.Log("Internal Exception Message: " + e.InnerException.Message, LogOutput.LogType.ERROR);
                    e = e.InnerException;
                }
            }
            LogOutput.Log("Finished Patching.");
            LogOutput.Log("Searching for mods...");
            if (!Directory.Exists("mods"))
            {
                Directory.CreateDirectory("mods");
            }
            // For every folder in the mods folder, search for a mod library with the same name
            foreach (string modPath in Directory.GetDirectories("mods"))
            {
                string modName = Path.GetFileName(modPath);
                // Since ModLoader does not support any platforms other than Windows at the moment, we're going to assume the
                // library is a .dll file
                string fullPathToLib = Path.Combine(modPath + "\\" + modName + ".dll");
                if (File.Exists(fullPathToLib))
                {
                    LogOutput.Log("Loading mod " + modName);
                    try
                    {
                        var asm = Assembly.LoadFile(fullPathToLib);
                        // Ensure there is a GameInitializing() function in class Main
                        var init = asm.GetType(modName + ".Main", true).GetMethod("GameInitializing");
                        if (init == null)
                        {
                            throw new Exception("Could not find mod initialization function!");
                        }

                        // Ensure there is a GameExiting() function in class Main
                        var exit = asm.GetType(modName + ".Main", true).GetMethod("GameExiting");
                        if (exit == null)
                        {
                            throw new Exception("Could not find mod exit function!");
                        }

                        // Everything's good, add the mod assembly to the list and call the initialize function
                        Constants.modAssemblies.Add(new Tuple <string, Assembly>(modName, asm));
                        init.Invoke(new object(), null);

                        // Increment the mod count number
                        Constants.numMods++;
                    }
                    catch (Exception e)
                    {
                        LogOutput.Log("Mod" + modName + " Failed to Load: " + e.Message, LogOutput.LogType.ERROR);
                    }
                }
            }
        }