Exemplo n.º 1
0
        public bool Read(AssetsFileReader reader, bool prefReplacersInMemory = false)
        {
            reader.bigEndian = false;

            magic = reader.ReadStringLength(4);
            if (magic != "EMIP")
            {
                return(false);
            }

            includesCldb = reader.ReadByte() != 0;

            modName        = reader.ReadCountStringInt16();
            modCreators    = reader.ReadCountStringInt16();
            modDescription = reader.ReadCountStringInt16();

            if (includesCldb)
            {
                addedTypes = new ClassDatabaseFile();
                addedTypes.Read(reader);
                //get past the string table since the reader goes back to the beginning
                reader.Position = addedTypes.header.stringTablePos + addedTypes.header.stringTableLen;
            }
            else
            {
                addedTypes = null;
            }

            int affectedFilesCount = reader.ReadInt32();

            affectedFiles = new List <InstallerPackageAssetsDesc>();
            for (int i = 0; i < affectedFilesCount; i++)
            {
                List <object> replacers         = new List <object>();
                InstallerPackageAssetsDesc desc = new InstallerPackageAssetsDesc()
                {
                    isBundle = reader.ReadByte() != 0,
                    path     = reader.ReadCountStringInt16()
                };
                int replacerCount = reader.ReadInt32();
                for (int j = 0; j < replacerCount; j++)
                {
                    object repObj = ParseReplacer(reader, prefReplacersInMemory);
                    if (repObj is AssetsReplacer repAsset)
                    {
                        replacers.Add(repAsset);
                    }
                    else if (repObj is BundleReplacer repBundle)
                    {
                        replacers.Add(repBundle);
                    }
                }
                desc.replacers = replacers;
                affectedFiles.Add(desc);
            }

            return(true);
        }
Exemplo n.º 2
0
        public void Write(AssetsFileWriter writer)
        {
            writer.bigEndian = false;

            writer.Write(Encoding.ASCII.GetBytes(magic));

            writer.Write(includesCldb);

            writer.WriteCountStringInt16(modName);
            writer.WriteCountStringInt16(modCreators);
            writer.WriteCountStringInt16(modDescription);

            if (includesCldb)
            {
                addedTypes.Write(writer);
                writer.Position = addedTypes.header.stringTablePos + addedTypes.header.stringTableLen;
            }

            writer.Write(affectedFiles.Count);
            for (int i = 0; i < affectedFiles.Count; i++)
            {
                InstallerPackageAssetsDesc desc = affectedFiles[i];
                writer.Write(desc.isBundle);
                writer.WriteCountStringInt16(desc.path);

                writer.Write(desc.replacers.Count);
                for (int j = 0; j < desc.replacers.Count; j++)
                {
                    object repObj = desc.replacers[j];
                    if (repObj is AssetsReplacer repAsset)
                    {
                        repAsset.WriteReplacer(writer);
                    }
                    else if (repObj is BundleReplacer repBundle)
                    {
                        repBundle.WriteReplacer(writer);
                    }
                }
            }
        }
Exemplo n.º 3
0
        private void BuildEmip(string path)
        {
            InstallerPackageFile emip = new InstallerPackageFile
            {
                magic          = "EMIP",
                includesCldb   = false,
                modName        = boxModName.Text ?? "",
                modCreators    = boxCredits.Text ?? "",
                modDescription = boxDesc.Text ?? ""
            };

            emip.affectedFiles = new List <InstallerPackageAssetsDesc>();

            foreach (ModMakerTreeFileInfo file in affectedFiles.Items)
            {
                //hack pls fix thx
                string filePath = file.relPath;
                InstallerPackageAssetsDesc desc = new InstallerPackageAssetsDesc()
                {
                    isBundle = false,
                    path     = filePath
                };
                desc.replacers = new List <object>();
                foreach (ModMakerTreeReplacerInfo change in file.Replacers)
                {
                    desc.replacers.Add(change.assetsReplacer);
                }
                emip.affectedFiles.Add(desc);
            }

            using (FileStream fs = File.OpenWrite(path))
                using (AssetsFileWriter writer = new AssetsFileWriter(fs))
                {
                    emip.Write(writer);
                }
        }