Esempio n. 1
0
        public static bool ParseModFile(string modFileData)
        {
            if (SystemsContainer.Get <ModSystem>().ModControl == ModControlMode.Disabled)
            {
                return(true);
            }

            SystemsContainer.Get <ModSystem>().LastModFileData = modFileData; //Save mod file so we can recheck it.

            StringBuilder = new StringBuilder();
            ParseRequired.Clear();
            ParseOptional.Clear();
            WhiteList.Clear();
            BlackList.Clear();
            PartsList.Clear();

            SaveCurrentModConfigurationFile();

            ReadModConfigurationFile(modFileData);

            CheckFiles();

            if (!ModCheckOk)
            {
                SystemsContainer.Get <ModSystem>().FailText = StringBuilder.ToString();
                WindowsContainer.Get <ModWindow>().Display  = true;
                return(false);
            }

            SystemsContainer.Get <ModSystem>().AllowedParts = PartsList;
            LunaLog.Log("[LMP]: Mod check passed!");
            return(true);
        }
Esempio n. 2
0
        public static bool ParseModFile(string modFileData)
        {
            if (ModSystem.Singleton.ModControl == ModControlMode.DISABLED)
            {
                return(true);
            }

            ModSystem.Singleton.LastModFileData = modFileData; //Save mod file so we can recheck it.

            StringBuilder = new StringBuilder();
            ParseRequired.Clear();
            ParseOptional.Clear();
            WhiteList.Clear();
            BlackList.Clear();
            PartsList.Clear();

            SaveCurrentModConfigurationFile();

            ReadModConfigurationFile(modFileData);

            CheckFiles();

            if (!ModCheckOk)
            {
                ModSystem.Singleton.FailText = StringBuilder.ToString();
                ModWindow.Singleton.Display  = true;
                return(false);
            }

            ModSystem.Singleton.AllowedParts = PartsList;
            Debug.Log("[LMP]: Mod check passed!");
            return(true);
        }
Esempio n. 3
0
        private static void CheckFiles()
        {
            var gameFilePaths = Directory.GetFiles(CommonUtil.CombinePaths(Client.KspPath, "GameData"), "*",
                                                   SearchOption.AllDirectories);
            var gameFileRelativePaths =
                gameFilePaths.Select(
                    filePath =>
                    filePath.Substring(filePath.ToLowerInvariant().IndexOf("gamedata", StringComparison.Ordinal) + 9)
                    .Replace('\\', '/')).ToList();

            //Check Required
            foreach (var requiredEntry in ParseRequired)
            {
                if (!requiredEntry.Key.EndsWith("dll"))
                {
                    CheckNonDllFile(gameFileRelativePaths, requiredEntry, true);
                }
                else
                {
                    CheckDllFile(requiredEntry, true);
                }
            }

            //Check Optional
            foreach (var optionalEntry in ParseOptional)
            {
                if (!optionalEntry.Key.EndsWith("dll"))
                {
                    CheckNonDllFile(gameFileRelativePaths, optionalEntry, false);
                }
                else
                {
                    CheckDllFile(optionalEntry, false);
                }
            }

            if (WhiteList.Any() && !BlackList.Any()) //Check Resource whitelist
            {
                var autoAllowed = new List <string>
                {
                    "lunamultiplayer/plugins/lunaclient.dll",
                    "lunamultiplayer/plugins/lunacommon.dll",
                    "lunamultiplayer/plugins/fastmember.dll",
                    "lunamultiplayer/plugins/lidgren.network.dll",
                    "lunamultiplayer/plugins/mono.data.tds.dll",
                    "lunamultiplayer/plugins/system.data.dll",
                    "lunamultiplayer/plugins/system.threading.dll",
                    "lunamultiplayer/plugins/system.transactions.dll"
                };

                //Allow LMP files, Ignore squad plugins, Check required (Required implies whitelist), Check optional (Optional implies whitelist)
                //Check whitelist

                foreach (var dllResource in
                         SystemsContainer.Get <ModSystem>().DllList.Where(
                             dllResource =>
                             !autoAllowed.Contains(dllResource.Key) && !dllResource.Key.StartsWith("squad/plugins") &&
                             !ParseRequired.ContainsKey(dllResource.Key) && !ParseOptional.ContainsKey(dllResource.Key) &&
                             !WhiteList.ContainsKey(dllResource.Key)))
                {
                    ModCheckOk = false;
                    LunaLog.Log($"[LMP]: Non-whitelisted resource {dllResource.Key} exists on client!");
                    StringBuilder.AppendLine($"Non-whitelisted resource {dllResource.Key} exists on client!");
                }
            }

            if (!WhiteList.Any() && BlackList.Any()) //Check Resource blacklist
            {
                foreach (var blacklistEntry in
                         BlackList.Keys.Where(blacklistEntry => SystemsContainer.Get <ModSystem>().DllList.ContainsKey(blacklistEntry)))
                {
                    ModCheckOk = false;
                    LunaLog.Log($"[LMP]: Banned resource {blacklistEntry} exists on client!");
                    StringBuilder.AppendLine($"Banned resource {blacklistEntry} exists on client!");
                }
            }
        }