Пример #1
0
 public ValveFileDifference Compare(ValveFile file)
 {
     if (File == file.File) {
         if (ModDirectory == file.ModDirectory) {
             return ValveFileDifference.Equal;
         } else {
             return ValveFileDifference.EqualFile;
         }
     } else {
         return ValveFileDifference.NotEqual;
     }
 }
Пример #2
0
 public ValveFileDifference Compare(ValveFile file)
 {
     if (File == file.File)
     {
         if (ModDirectory == file.ModDirectory)
         {
             return(ValveFileDifference.Equal);
         }
         else
         {
             return(ValveFileDifference.EqualFile);
         }
     }
     else
     {
         return(ValveFileDifference.NotEqual);
     }
 }
Пример #3
0
        public ValveFile GetFile(string path)
        {
            ValveFile file = null;

            file = new ValveFile(ModDir, path);
            if (FileExists(file))
            {
                return(file);
            }

            file = new ValveFile(ValveDir, path);
            if (FileExists(file))
            {
                return(file);
            }

            return(null);
        }
Пример #4
0
        public ValveFile GetWadFile(ValveFile[] existingFiles, ValveFile file)
        {
            ValveFile potential = null;

            foreach (ValveFile existingFile in existingFiles)
            {
                ValveFileDifference result = file.Compare(existingFile);
                if (result == ValveFileDifference.Equal)
                {
                    return(file);
                }
                else if (result == ValveFileDifference.EqualFile)
                {
                    potential = existingFile;
                }
            }

            return(potential == null ? null : potential);
        }
Пример #5
0
        public VerifierResult VerifyMap(string map)
        {
            VerifierResult res = new VerifierResult();

            ValveFile[] wadfiles = GetWadFiles();

            var fullmap = Path.Combine(ModMapsDirectory, map);

            if (!File.Exists(fullmap))
            {
                throw new Exception(string.Format("Map does not exist: {0}", fullmap));
            }

            BSPParser bp = new BSPParser(File.OpenRead(fullmap));

            if (!bp.LoadDirectoryTables())
            {
                throw new Exception("Malformed file");
            }

            var textureList = bp.LoadMipTexturesArray()
                              .Where(t => t.offset1 == 0 && t.offset2 == 0 && t.offset3 == 0 && t.offset4 == 0)
                              .Select(t => t.name.ToString())
                              .ToList();

            string entities = bp.ReadEntities();

            bp.Close();

            EntityParser ep = new EntityParser(entities);

            var ent = ep.ReadEntities();

            List <ValveFile> existingWads      = new List <ValveFile>();
            List <string>    malformedWadFiles = new List <string>();
            List <string>    misnamedModDirs   = new List <string>();
            List <string>    notExistingFiles  = new List <string>();

            if (ent.ContainsKey("worldspawn"))
            {
                string skyname = ent["worldspawn"][0]["skyname"];
                string wadList = ent["worldspawn"][0]["wad"];
                var    list    = Seperate(wadList);

                foreach (string fullReferencedWadFile in list)
                {
                    string referencedRelevantWadFile = fullReferencedWadFile.GetRelevantPath();

                    ValveFile referencedFile = new ValveFile(referencedRelevantWadFile);
                    ValveFile existingFile   = GetWadFile(wadfiles, referencedFile);

                    if (referencedRelevantWadFile != fullReferencedWadFile)
                    {
                        malformedWadFiles.Add(fullReferencedWadFile);
                    }

                    if (existingFile != null)
                    {
                        if (existingFile.Compare(referencedFile) == ValveFileDifference.EqualFile)
                        {
                            misnamedModDirs.Add(fullReferencedWadFile);
                        }

                        existingWads.Add(existingFile);
                    }
                    else
                    {
                        notExistingFiles.Add(fullReferencedWadFile);
                    }
                }

                res.MalformedWadFiles = malformedWadFiles.ToArray();
                res.MisnamedModDirs   = misnamedModDirs.ToArray();
                res.NotExistingFiles  = notExistingFiles.ToArray();

                #region Textures

                List <string> existingFilenames = new List <string>();
                foreach (var wadFile in existingWads)
                {
                    WADParser wp = new WADParser(File.OpenRead(wadFile.ToString(BaseDirectory)));
                    existingFilenames.AddRange(wp.LoadFileArray().Select(f => f.filename.ToString().ToLower()));
                    wp.Close();
                }

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

                foreach (var item in textureList)
                {
                    if (!existingFilenames.Contains(item.ToLower()))
                    {
                        missingTextures.Add(item);
                    }
                }

                res.MissingTextures = missingTextures.ToArray();

                #endregion

                #region Sprites

                List <string> sprites = new List <string>();
                if (ent.ContainsKey("env_sprite"))
                {
                    foreach (var dict in ent["env_sprite"])
                    {
                        string model = dict["model"];
                        if (!sprites.Contains(model))
                        {
                            sprites.Add(model);
                        }
                    }
                }

                res.UsedSprites = sprites.ToArray();

                List <string> missingSprites = new List <string>();
                foreach (string sprite in sprites)
                {
                    ValveFile file = GetFile(sprite);
                    if (file == null)
                    {
                        missingSprites.Add(sprite);
                    }
                }
                res.MissingSprites = missingSprites.ToArray();

                #endregion

                #region Sounds

                List <string> sounds = new List <string>();
                if (ent.ContainsKey("ambient_generic"))
                {
                    foreach (var ambient in ent["ambient_generic"])
                    {
                        if (ambient.ContainsKey("message"))
                        {
                            string message = Path.Combine(SoundDir, ambient["message"]);
                            if (!sounds.Contains(message))
                            {
                                sounds.Add(message);
                            }
                        }
                    }
                }

                res.UsedSounds = sounds.ToArray();

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

                foreach (string sound in sounds)
                {
                    ValveFile file = GetFile(sound);
                    if (file == null)
                    {
                        missingSounds.Add(sound);
                    }
                }

                res.MissingSounds = missingSounds.ToArray();

                #endregion

                #region Models

                List <string> models = new List <string>();
                foreach (var entityPair in ent)
                {
                    foreach (var entity in entityPair.Value)
                    {
                        if (entity.ContainsKey("model"))
                        {
                            string model = entity["model"];
                            if (!model.EndsWith(".mdl"))
                            {
                                continue;
                            }
                            if (!models.Contains(model))
                            {
                                models.Add(model);
                            }
                        }
                    }
                }

                res.UsedModels = models.ToArray();

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

                foreach (var model in models)
                {
                    ValveFile file = GetFile(model);
                    if (file == null)
                    {
                        missingModels.Add(model);
                    }
                }

                res.MissingModels = missingModels.ToArray();

                #endregion
            }

            res.UsedFileList = Sort(res.UsedSprites, res.UsedSounds, res.UsedModels);

            res.MissingFileList = Sort(res.MissingSprites, res.MissingSounds, res.MissingModels);

            return(res);
        }
Пример #6
0
        public bool FileExists(ValveFile file)
        {
            string path = Path.Combine(BaseDirectory, file.ToString());

            return(File.Exists(path));
        }
Пример #7
0
        public VerifierResult VerifyMap(string map)
        {
            VerifierResult res = new VerifierResult();

            ValveFile[] wadfiles = GetWadFiles();

            var fullmap = Path.Combine(ModMapsDirectory, map);

            if (!File.Exists(fullmap)) {
                throw new Exception(string.Format("Map does not exist: {0}", fullmap));
            }

            BSPParser bp = new BSPParser(File.OpenRead(fullmap));

            if (!bp.LoadDirectoryTables()) {
                throw new Exception("Malformed file");
            }

            List<string> textureList = new List<string>();
            bp.LoadMipTextureOffsets();
            bp.OnLoadMipTexture += (texture) => {
                if ((texture.offset1 == 0) && (texture.offset2 == 0) && (texture.offset3 == 0) && (texture.offset4 == 0)) {
                    textureList.Add(texture.Name);
                }
            };
            bp.LoadMipTextures();

            string entities = bp.ReadEntities();

            bp.Close();

            EntityParser ep = new EntityParser(entities);

            var ent = ep.ReadEntities();

            List<ValveFile> existingWads = new List<ValveFile>();
            List<string> malformedWadFiles = new List<string>();
            List<string> misnamedModDirs = new List<string>();
            List<string> notExistingFiles = new List<string>();

            if (ent.ContainsKey("worldspawn")) {
                string skyname = ent["worldspawn"][0]["skyname"];
                string wadList = ent["worldspawn"][0]["wad"];
                var list = Seperate(wadList);

                foreach (string fullReferencedWadFile in list) {

                    string referencedRelevantWadFile = fullReferencedWadFile.GetRelevantPath();

                    ValveFile referencedFile = new ValveFile(referencedRelevantWadFile);
                    ValveFile existingFile = GetWadFile(wadfiles, referencedFile);

                    if (referencedRelevantWadFile != fullReferencedWadFile) {
                        malformedWadFiles.Add(fullReferencedWadFile);
                    }

                    if (existingFile != null) {
                        if (existingFile.Compare(referencedFile) == ValveFileDifference.EqualFile) {
                            misnamedModDirs.Add(fullReferencedWadFile);
                        }

                        existingWads.Add(existingFile);
                    } else {
                        notExistingFiles.Add(fullReferencedWadFile);
                    }
                }

                res.MalformedWadFiles = malformedWadFiles.ToArray();
                res.MisnamedModDirs   =   misnamedModDirs.ToArray();
                res.NotExistingFiles  =  notExistingFiles.ToArray();

                #region Textures

                List<string> existingFilenames = new List<string>();
                foreach (var wadFile in existingWads) {
                    WADParser wp = new WADParser(File.OpenRead(wadFile.ToString(BaseDirectory)));
                    wp.OnLoadFile += (file) => {
                        existingFilenames.Add(file.Filename.ToLower());
                    };
                    wp.LoadFiles();
                    wp.Close();
                }

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

                foreach (var item in textureList) {
                    if (!existingFilenames.Contains(item.ToLower())) {
                        missingTextures.Add(item);
                    }
                }

                res.MissingTextures = missingTextures.ToArray();

                #endregion

                #region Sprites

                List<string> sprites = new List<string>();
                if (ent.ContainsKey("env_sprite")) {
                    foreach (var dict in ent["env_sprite"]) {
                        string model = dict["model"];
                        if (!sprites.Contains(model)) {
                            sprites.Add(model);
                        }
                    }
                }

                res.UsedSprites = sprites.ToArray();

                List<string> missingSprites = new List<string>();
                foreach (string sprite in sprites) {
                    ValveFile file = GetFile(sprite);
                    if (file == null) {
                        missingSprites.Add(sprite);
                    }
                }
                res.MissingSprites = missingSprites.ToArray();

                #endregion

                #region Sounds

                List<string> sounds = new List<string>();
                if (ent.ContainsKey("ambient_generic")) {
                    foreach (var ambient in ent["ambient_generic"]) {
                        if (ambient.ContainsKey("message")) {
                            string message = Path.Combine(SoundDir, ambient["message"]);
                            if (!sounds.Contains(message)) {
                                sounds.Add(message);
                            }
                        }
                    }
                }

                res.UsedSounds = sounds.ToArray();

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

                foreach (string sound in sounds) {
                    ValveFile file = GetFile(sound);
                    if (file == null) {
                        missingSounds.Add(sound);
                    }
                }

                res.MissingSounds = missingSounds.ToArray();

                #endregion

                #region Models

                List<string> models = new List<string>();
                foreach (var entityPair in ent) {
                    foreach (var entity in entityPair.Value) {
                        if (entity.ContainsKey("model")) {
                            string model = entity["model"];
                            if (!model.EndsWith(".mdl")) {
                                continue;
                            }
                            if (!models.Contains(model)) {
                                models.Add(model);
                            }
                        }
                    }
                }

                res.UsedModels = models.ToArray();

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

                foreach (var model in models) {
                    ValveFile file = GetFile(model);
                    if (file == null) {
                        missingModels.Add(model);
                    }
                }

                res.MissingModels = missingModels.ToArray();

                #endregion
            }

            List<string> usedFileList = new List<string>();
            usedFileList.AddRange(res.UsedSprites);
            usedFileList.AddRange(res.UsedSounds);
            usedFileList.AddRange(res.UsedModels);
            usedFileList.Sort();
            res.UsedFileList = usedFileList.ToArray();

            List<string> missingFileList = new List<string>();
            missingFileList.AddRange(res.MissingSprites);
            missingFileList.AddRange(res.MissingSounds);
            missingFileList.AddRange(res.MissingModels);
            missingFileList.Sort();
            res.MissingFileList = missingFileList.ToArray();

            return res;
        }
Пример #8
0
        public ValveFile GetWadFile(ValveFile[] existingFiles, ValveFile file)
        {
            ValveFile potential = null;
            foreach (ValveFile existingFile in existingFiles) {
                ValveFileDifference result = file.Compare(existingFile);
                if (result == ValveFileDifference.Equal) {
                    return file;
                } else if (result == ValveFileDifference.EqualFile) {
                    potential = existingFile;
                }
            }

            return (potential == null ? null : potential);
        }
Пример #9
0
        public ValveFile GetFile(string path)
        {
            ValveFile file = null;

            file = new ValveFile(ModDir, path);
            if (FileExists(file)) {
                return file;
            }

            file = new ValveFile(ValveDir, path);
            if (FileExists(file)) {
                return file;
            }

            return null;
        }
Пример #10
0
 public bool FileExists(ValveFile file)
 {
     string path = Path.Combine(BaseDirectory, file.ToString());
     return File.Exists(path);
 }