private static FullSpriteSet DoInitPSX(Stream iso, BackgroundWorker worker) { const int numberOfPsxSprites = 134; int tasks = numberOfPsxSprites * 2 + 1; int tasksComplete = 0; var sprites = new List <AbstractSprite>(); XmlDocument doc = new XmlDocument(); doc.LoadXml(Properties.Resources.PSXFiles); foreach (XmlNode node in doc.SelectNodes(string.Format("/PsxFiles/{0}/Sprite", typeof(MonsterSprite).FullName))) { string name = node.SelectSingleNode("@name").InnerText; List <string> filenames = new List <string>(); List <byte[]> bytes = new List <byte[]>(); foreach (XmlNode file in node.SelectNodes("Files/File")) { string filename = file.SelectSingleNode("@name").InnerText; worker.ReportProgress(tasksComplete++ *100 / tasks, "Reading " + filename); filenames.Add(filename); bytes.Add(IsoPatch.ReadFile(IsoPatch.IsoType.Mode2Form1, iso, (int)Enum.Parse(typeof(PsxIso.Sectors), file.SelectSingleNode("@enum").InnerText), 0, Int32.Parse(file.SelectSingleNode("@original_size").InnerText))); } if (bytes.Count > 1) { sprites.Add(new MonsterSprite(name, filenames, bytes[0], bytes.Sub(1).ToArray())); } else { sprites.Add(new MonsterSprite(name, filenames, bytes[0])); } } foreach (Type t in new Type[] { typeof(TYPE1Sprite), typeof(TYPE2Sprite), typeof(ShortSprite), typeof(KANZEN), typeof(CYOKO), typeof(ARUTE) }) { ConstructorInfo constructor = t.GetConstructor(new Type[] { typeof(string), typeof(IList <byte>) }); foreach (XmlNode node in doc.SelectNodes(string.Format("/PsxFiles/{0}/Sprite", t.FullName))) { worker.ReportProgress(tasksComplete++ *100 / tasks, "Reading " + node.SelectSingleNode("Files/File/@name").InnerText); sprites.Add((AbstractSprite)constructor.Invoke(new object[] { node.SelectSingleNode("@name").InnerText, IsoPatch.ReadFile( IsoPatch.IsoType.Mode2Form1, iso, (int)Enum.Parse(typeof(PsxIso.Sectors), node.SelectSingleNode("Files/File/@enum").InnerText), 0, Int32.Parse(node.SelectSingleNode("Files/File/@original_size").InnerText)) })); } } return(new FullSpriteSet(sprites, worker, tasksComplete, tasks)); }
public static void PatchPsxIsoSimple(FFTPatch fftPatch, string filename) { using (FileStream stream = new FileStream(filename, FileMode.Open, FileAccess.ReadWrite)) { List <PatchedByteArray> patches = GetPatches(fftPatch); foreach (PatchedByteArray patch in patches) { IsoPatch.PatchFileAtSector(IsoPatch.IsoType.Mode2Form1, stream, true, patch.Sector, patch.Offset, patch.GetBytes(), true); } } }
public void PatchPsxISO(Stream stream, BackgroundWorker worker, IList <PatchedByteArray> patches) { int totalTasks = patches.Count; int tasksComplete = 0; foreach (PatchedByteArray patch in patches) { if (patch != null) { worker.ReportProgress(tasksComplete++ *100 / totalTasks, "Patching " + patch.SectorEnum.ToString()); IsoPatch.PatchFileAtSector(IsoPatch.IsoType.Mode2Form1, stream, true, patch.Sector, patch.Offset, patch.GetBytes(), true); } else { tasksComplete++; } } }
public static void PatchPsxIso(FFTPatch FFTPatch, BackgroundWorker backgroundWorker, DoWorkEventArgs e, IGeneratePatchList patchList) { string filename = patchList.FileName; int numberOfTasks = patchList.PatchCount * 2; int tasksComplete = 0; List <PatchedByteArray> patches = new List <PatchedByteArray>(); Action <string> sendProgress = delegate(string message) { backgroundWorker.ReportProgress(tasksComplete++ *100 / numberOfTasks, message); }; const Context context = Context.US_PSX; if (patchList.Abilities) { patches.AddRange(FFTPatch.Abilities.GetPatches(context)); sendProgress("Getting Abilities patches"); } if (patchList.AbilityAnimations) { patches.AddRange(FFTPatch.AbilityAnimations.GetPatches(context)); sendProgress("Getting Ability Animations patches"); } if (patchList.AbilityEffects) { patches.AddRange(FFTPatch.Abilities.AllEffects.GetPatches(context)); sendProgress("Getting Ability Effects patches"); } if (patchList.ActionMenus) { patches.AddRange(FFTPatch.ActionMenus.GetPatches(context)); sendProgress("Getting Action Menus patches"); } if (patchList.ENTD.Exists(b => b == true)) { IList <PatchedByteArray> entdPatches = FFTPatch.ENTDs.GetPatches(context); for (int i = 0; i < 4; i++) { if (patchList.ENTD[i]) { patches.Add(entdPatches[i]); sendProgress(string.Format("Getting ENTD {0} patches", i)); } } } if (patchList.InflictStatus) { patches.AddRange(FFTPatch.InflictStatuses.GetPatches(context)); sendProgress("Getting Inflict Status patches"); } if (patchList.ItemAttributes) { patches.AddRange(FFTPatch.ItemAttributes.GetPatches(context)); sendProgress("Getting Item Attributes patches"); } if (patchList.Items) { patches.AddRange(FFTPatch.Items.GetPatches(context)); sendProgress("Getting Item patches"); } if (patchList.JobLevels) { patches.AddRange(FFTPatch.JobLevels.GetPatches(context)); sendProgress("Getting Job Levels patches"); } if (patchList.Jobs) { patches.AddRange(FFTPatch.Jobs.GetPatches(context)); sendProgress("Getting Jobs patches"); } if (patchList.MonsterSkills) { patches.AddRange(FFTPatch.MonsterSkills.GetPatches(context)); sendProgress("Getting Monster Skills patches"); } if (patchList.MoveFindItems) { patches.AddRange(FFTPatch.MoveFind.GetPatches(context)); sendProgress("Getting Move/Find Items patches"); } foreach (PatchedByteArray patch in patchList.OtherPatches) { patches.Add(patch); sendProgress("Getting other patches"); } if (patchList.Poach) { patches.AddRange(FFTPatch.PoachProbabilities.GetPatches(context)); sendProgress("Getting Poach Probabilities patches"); } if (patchList.Skillsets) { patches.AddRange(FFTPatch.SkillSets.GetPatches(context)); sendProgress("Getting Skillsets patches"); } if (patchList.StatusAttributes) { patches.AddRange(FFTPatch.StatusAttributes.GetPatches(context)); sendProgress("Getting Status attributes patches"); } if (patchList.StoreInventory) { patches.AddRange(FFTPatch.StoreInventories.GetPatches(context)); sendProgress("Getting store inventories patches"); } if (patchList.Propositions) { patches.AddRange(FFTPatch.Propositions.GetPatches(context)); sendProgress("Getting errands patches"); } using (FileStream stream = new FileStream(filename, FileMode.Open, FileAccess.ReadWrite)) { foreach (PatchedByteArray patch in patches) { IsoPatch.PatchFileAtSector(IsoPatch.IsoType.Mode2Form1, stream, true, patch.Sector, patch.Offset, patch.GetBytes(), true); sendProgress("Patching ISO"); } //if ( patchList.RegenECC ) //{ // IsoPatch.FixupECC( IsoPatch.IsoType.Mode2Form1, stream ); // sendProgress( "Fixing ECC/EDC" ); //} } }