Exemplo n.º 1
0
        public void PatchDirArchive(ModData mod, string archivepath)
        {
            string archive_dir = mod.Path + archivepath;

            // Check if the mod has a directory for wad resources
            if (Directory.Exists(archive_dir))
            {
                Archive archive = new Archive(TempPath + archivepath + ".wad");
                archive.Load();

                int i, j;
                int count = 0;

                // Go through the groups in the archive file.
                for (i = 0; i < archive.Groups.Count; i++)
                {
                    var group = archive.Groups[i];

                    //Check for matching subdirectory and archive group.
                    if (Directory.Exists(archive_dir + "/" + group.Name))
                    {
                        //Go through the entries in the archive file
                        for (j = 0; j < archive.Groups[i].Entries.Count; j++)
                        {
                            var entry = archive.Groups[i].Entries[j];

                            //Check for matching file and archive entry.
                            string filepath = archive_dir + "/" + group.Name + "/" + entry.Name;
                            if (File.Exists(filepath))
                            {
                                Byte[] data = File.ReadAllBytes(filepath);
                                var new_entry = new Entry(entry.Name, data);

                                //Replace entry in the archive.wad with file in mod archive folder.
                                archive.Groups[i].Entries[j] = new_entry;

                                //Msg.Log("Patching '" + group.Name + "/" + entry.Name + "' from " + mod.Name);
                                count++;
                            }
                        }
                    }
                }

                archive.Save();

                if (count > 0) Msg.Log("Patched " + count + " " + archivepath + " resources for " + mod.Name);
            }
        }
Exemplo n.º 2
0
        //LoadMods - Loads mods of given type
        private void LoadMods(string path, string type)
        {            
            string[] mods;
            if (type.Equals("/")) mods = Directory.GetDirectories(path);
            else                  mods = Directory.GetFiles(path, type);

            foreach (string modpath in mods)
            {
                ModData mod;
                string name;
                if (type.Equals("/")) //Mods as directories
                {
                    name = new DirectoryInfo(modpath).Name;
                    mod = new ModData(name, modpath + "/", false);
                }
                else //Zip files
                {
                    name = Path.GetFileNameWithoutExtension(modpath);
                    mod = new ModData(name, modpath, true);
                }

                this.Mods.Add(mod);

                //Msg.Log("Added mod: " + name + ", " + modpath);
            }
        }
Exemplo n.º 3
0
        public void PatchZipArchive(ModData mod, string archivepath)
        {
            ZipFile zip = new ZipFile(mod.Path);

            // Check if the mod has a directory for wad resources
            if (zip.ContainsEntry(archivepath + "/"))
            {
                Archive archive = new Archive(TempPath + archivepath + ".wad");
                archive.Load();

                int i, j;
                int count = 0;

                // Go through the groups in the archive file.
                for (i = 0; i < archive.Groups.Count; i++)
                {
                    var group = archive.Groups[i];

                    //Check for matching subdirectory and archive group.
                    string grouppath = archivepath + "/" + group.Name + "/";
                    if (zip.ContainsEntry(grouppath))
                    {
                        //Go through the entries in the archive file
                        for (j = 0; j < archive.Groups[i].Entries.Count; j++)
                        {
                            var entry = archive.Groups[i].Entries[j];

                            //Check for matching file and archive entry.
                            string entrypath = grouppath + entry.Name;
                            if (zip.ContainsEntry(entrypath))
                            {
                                //Msg.Log("zip: " + mod.Name + ", matching res-entry: " + entrypath);

                                MemoryStream stream = new MemoryStream();
                                zip[entrypath].Extract(stream);

                                Byte[] data = stream.GetBuffer();
                                var new_entry = new Entry(entry.Name, data);

                                //Replace entry in the archive.wad with file in mod archive folder.
                                archive.Groups[i].Entries[j] = new_entry;
                                //Msg.Log("Patching '" + group.Name + "/" + entry.Name + "' from zip " + mod.Name);
                                count++;
                            }
                        }
                    }
                }
                archive.Save();

                if (count > 0) Msg.Log("Patched " + count + " " + archivepath + " resources for " + mod.Name);
            }            
        }
Exemplo n.º 4
0
 // Patches an archive wad file in the temp folder with resources of a mod.
 public void PatchArchive(ModData mod, string archivepath)
 {
     if (mod.IsZip == true)
         PatchZipArchive(mod, archivepath);
     else
         PatchDirArchive(mod, archivepath);
 }
Exemplo n.º 5
0
        public bool PatchDirFiles(ModData mod)
        {
            int count = 0;

            // Only mod files that match the original files are copied.
            foreach (GameFile gmfile in DefaultFiles)
            {
                // The full alltex.wad and allsounds.wad files are intentionally disabled from
                // being used in mods, as including the entire files works against the idea of
                // being able to combine multiple mods that change different resources inside 
                // the wad files. Not to mention that it makes the mods unnecessarily big in  
                // filesize. (although maybe this could be made to work anyways with some kind
                // of hash comparison with the entries of the wad files..)
                //NOTE: Commented this out, so old mods can work.
                //if (gmfile.IsModdable == false)
                //    continue;

                if (File.Exists(mod.Path + gmfile.FilePath) == true)
                {
                    //Try copying over modded file
                    try
                    {
                        string srcfile = mod.Path + gmfile.FilePath;
                        string dstfile = this.TempPath + gmfile.FilePath;
                        File.Copy(srcfile, dstfile, true);
                        //Msg.Log("Patching file '" + gmfile.FilePath + "' from " + mod.Name);
                        count++;
                    }
                    catch (Exception ex)
                    {
                        Msg.MsgBox("Error patching file: " + ex.Message, "Patchlunky Setup");
                        return false; //Stop patching
                    }
                }
            }
            if (count > 0) Msg.Log("Patched " + count + " files for " + mod.Name);
            return true;
        }
Exemplo n.º 6
0
        public bool PatchZipFiles(ModData mod)
        {
            ZipFile zip = new ZipFile(mod.Path);

            int count = 0;

            // Only mod files that match the original files are copied.
            foreach (GameFile gmfile in DefaultFiles)
            {
                if (zip.ContainsEntry(gmfile.FilePath) == true)
                {
                    //Msg.Log("zip: " + mod.Name + ", matching entry: " + gmfile.FilePath);

                    try
                    {
                        zip[gmfile.FilePath].Extract(this.TempPath, ExtractExistingFileAction.OverwriteSilently);
                        count++;
                    }
                    catch (Exception ex)
                    {
                        Msg.MsgBox("Error patching file: " + ex.Message, "Patchlunky Setup");
                        return false; //Stop patching
                    }
                }
            }

            if (count > 0) Msg.Log("Patched " + count + " files for " + mod.Name);
            return true;
        }
Exemplo n.º 7
0
 // Patch game files in the temp folder with files of a mod.
 public bool PatchFiles(ModData mod)
 {
     if (mod.IsZip == true)
         return PatchZipFiles(mod);
     else
         return PatchDirFiles(mod);
 }