Пример #1
0
        public void Apply(string working_dir)
        {
            foreach (FilePatch p in Files)
            {
                string file_name = Path.Combine(working_dir, p.FileName);
                if (!File.Exists(file_name))
                {
                    Console.WriteLine("Could not apply patch \"{}\" to file \"{}\"! The file does not exist!");
                    continue;
                }

                using (FileStream strm = new FileStream(file_name, FileMode.Open, FileAccess.ReadWrite))
                {
                    EndianBinaryWriter writer = new EndianBinaryWriter(strm, Endian.Big);
                    EndianBinaryReader reader = new EndianBinaryReader(strm, Endian.Big);

                    foreach (Patchlet plet in p.Patchlets)
                    {
                        long offset = plet.Offset;
                        if (file_name.EndsWith(".dol"))
                        {
                            offset = DOL.AddressToOffset(plet.Offset, reader);
                        }
                        writer.BaseStream.Seek(offset, SeekOrigin.Begin);
                        writer.Write(plet.Data.ToArray());
                    }

                    strm.Flush();
                }
            }
        }
Пример #2
0
        private void UpdateModel()
        {
            // Loads the necessary information about which figurine model to load dynamically from the REL and the DOL.

            m_actorMeshes = WResourceManager.LoadActorResource("Figurine Stand");

            int modelFileID;
            int modelArcIndex;

            int figurineIndex = (int)WhichFigurine;

            string       figurine_rel_path = Path.Combine(WSettingsManager.GetSettings().RootDirectoryPath, "files", "rels/d_a_obj_figure.rel");
            MemoryStream figurine_rel_data = null;

            using (EndianBinaryReader reader = new EndianBinaryReader(File.ReadAllBytes(figurine_rel_path), Endian.Big))
            {
                figurine_rel_data = Yaz0.Decode(reader);
            }
            using (EndianBinaryReader reader = new EndianBinaryReader(figurine_rel_data, Endian.Big))
            {
                int l_figure_dat_entry_offset = l_figure_dat_tbl_offset + figurineIndex * 0xC;
                modelFileID   = reader.ReadInt32At(l_figure_dat_entry_offset + 0x00);
                modelArcIndex = reader.ReadInt32At(l_figure_dat_entry_offset + 0x08);
            }

            if (modelArcIndex == -1)
            {
                string main_dol_path = Path.Combine(WSettingsManager.GetSettings().RootDirectoryPath, "sys", "main.dol");
                using (FileStream strm = new FileStream(main_dol_path, FileMode.Open, FileAccess.Read))
                {
                    EndianBinaryReader reader      = new EndianBinaryReader(strm, Endian.Big);
                    long l_CharaData_entry_address = l_CharaData_address + figurineIndex * 0x12;
                    long l_CharaData_entry_offset  = DOL.AddressToOffset(l_CharaData_entry_address, reader);
                    modelArcIndex = reader.ReadByteAt(l_CharaData_entry_offset + 0x10);
                }
            }

            var    arc_name = l_arcname_tbl[modelArcIndex];
            string arc_path = Path.Combine(WSettingsManager.GetSettings().RootDirectoryPath, "files", "res/Object/", arc_name + ".arc");

            if (File.Exists(arc_path))
            {
                VirtualFilesystemDirectory model_arc = ArchiveUtilities.LoadArchive(arc_path);
                if (model_arc.FindByID((ushort)modelFileID) != null)
                {
                    var figurine_model = WResourceManager.LoadModelFromVFS(model_arc, fileID: (ushort)modelFileID);
                    figurine_model.SetOffsetTranslation(new Vector3(0, 100, 0));
                    m_actorMeshes.Add(figurine_model);
                }
            }
        }