Ejemplo n.º 1
0
 private void WriteByteDataToTestFiles()
 {
     _entryData = _dataHelper.LoadDefaultEntryData();
     System.IO.File.WriteAllBytes("EntryData/TestBattle.bin", _dataHelper.ConditionalSetsToByteArray(CommandType.BattleConditional, _entryData.BattleConditionals));
     System.IO.File.WriteAllBytes("EntryData/TestWorld.bin", _dataHelper.ConditionalSetsToByteArray(CommandType.WorldConditional, _entryData.WorldConditionals));
     System.IO.File.WriteAllBytes("EntryData/TestEvents.bin", _dataHelper.EventsToByteArray(_entryData.Events));
 }
Ejemplo n.º 2
0
 private void menuItem_UseTrimmedDefaults_Click(object sender, EventArgs e)
 {
     menuItem_UseTrimmedDefaults.Checked = !menuItem_UseTrimmedDefaults.Checked;
     SaveFormData();
     _entryDataDefault = menuItem_UseTrimmedDefaults.Checked ? _dataHelper.LoadTrimmedEntryData() : _dataHelper.LoadDefaultEntryData();
     PopulateTabs();
 }
Ejemplo n.º 3
0
 private void SetDefaults()
 {
     menuItem_UseTrimmedDefaults.Checked = false;
     SaveFormData();
     _entryDataDefault = _entryData.Copy();
     PopulateTabs();
 }
Ejemplo n.º 4
0
 private void RestoreDefaults()
 {
     menuItem_UseTrimmedDefaults.Checked = false;
     SaveFormData();
     _entryDataDefault = _dataHelper.LoadDefaultEntryData();
     PopulateTabs();
 }
Ejemplo n.º 5
0
        public static void PatchISO(EntryData entryData, string filepath, Context context, DataHelper dataHelper = null)
        {
            if (!string.IsNullOrEmpty(filepath))
            {
                List <PatchedByteArray> patches = GetISOPatches(entryData, context, dataHelper);

                using (Stream file = File.Open(filepath, FileMode.Open, FileAccess.ReadWrite, FileShare.Read))
                {
                    PsxIso.PatchPsxIso(file, patches);
                }
            }
        }
Ejemplo n.º 6
0
        private void WriteLoadedDataToTestFiles()
        {
            _entryData = _dataHelper.LoadDefaultEntryData();
            _dataHelper.SaveAllConditionalSetScripts(_entryData.BattleConditionals, "./EntryData/scripts/battle/1");
            _dataHelper.SaveAllConditionalSetScripts(_entryData.WorldConditionals, "./EntryData/scripts/world/1");
            _dataHelper.SaveAllEventScripts(_entryData.Events, "./EntryData/scripts/event/1");
            List <ConditionalSet> battleConditionals = _dataHelper.LoadAllConditionalSetScripts(CommandType.BattleConditional, "./EntryData/scripts/battle/1");
            List <ConditionalSet> worldConditionals  = _dataHelper.LoadAllConditionalSetScripts(CommandType.WorldConditional, "./EntryData/scripts/world/1");
            List <Event>          events             = _dataHelper.LoadAllEventScripts(_entryData.Events, "./EntryData/scripts/event/1");

            System.IO.File.WriteAllBytes("EntryData/TestBattle.bin", _dataHelper.ConditionalSetsToByteArray(CommandType.BattleConditional, battleConditionals));
            System.IO.File.WriteAllBytes("EntryData/TestWorld.bin", _dataHelper.ConditionalSetsToByteArray(CommandType.WorldConditional, worldConditionals));
            System.IO.File.WriteAllBytes("EntryData/TestEvents.bin", _dataHelper.EventsToByteArray(events));
        }
Ejemplo n.º 7
0
        private void LoadPatch(string filepath)
        {
            byte[]     bytesBattleConditionals, bytesWorldConditionals, bytesEvents;
            EntryBytes defaultEntryBytes = _dataHelper.LoadDefaultEntryBytes();

            using (ICSharpCode.SharpZipLib.Zip.ZipFile file = new ICSharpCode.SharpZipLib.Zip.ZipFile(filepath))
            {
                bytesBattleConditionals = PatcherLib.Utilities.Utilities.GetZipEntry(file, DataHelper.EntryNameBattleConditionals, false) ?? defaultEntryBytes.BattleConditionals;
                bytesWorldConditionals  = PatcherLib.Utilities.Utilities.GetZipEntry(file, DataHelper.EntryNameWorldConditionals, false) ?? defaultEntryBytes.WorldConditionals;
                bytesEvents             = PatcherLib.Utilities.Utilities.GetZipEntry(file, DataHelper.EntryNameEvents, false) ?? defaultEntryBytes.Events;
            }

            _entryDataDefault = _dataHelper.LoadEntryDataFromBytes(defaultEntryBytes);
            _entryData        = _dataHelper.LoadEntryDataFromBytes(bytesBattleConditionals, bytesWorldConditionals, bytesEvents);
            PopulateTabs();
        }
Ejemplo n.º 8
0
        private void menuItem_LoadISO_Click(object sender, EventArgs e)
        {
            EntryData inputEntryData = _entryData ?? new EntryData(null, null, null);

            if (ISOForm.InitDialog(_dataHelper, inputEntryData, ISOForm.Mode.Load, _context) == DialogResult.OK)
            {
                _entryDataDefault = _entryDataDefault ?? _dataHelper.LoadDefaultEntryData();

                _entryData = _entryData ?? inputEntryData;
                _entryData.BattleConditionals = inputEntryData.BattleConditionals ?? _entryData.BattleConditionals ?? CopyableEntry.CopyList <ConditionalSet>(_entryDataDefault.BattleConditionals);
                _entryData.WorldConditionals  = inputEntryData.WorldConditionals ?? _entryData.WorldConditionals ?? CopyableEntry.CopyList <ConditionalSet>(_entryDataDefault.WorldConditionals);
                _entryData.Events             = inputEntryData.Events ?? _entryData.Events ?? CopyableEntry.CopyList <Event>(_entryDataDefault.Events);

                PopulateTabs();
                EnableMenu();
                tabControl.Enabled = true;
            }
        }
Ejemplo n.º 9
0
        private static bool HandleCommandLinePatch(string[] args)
        {
            System.Collections.Generic.KeyValuePair <string, string> patchFilepaths = PatcherLib.Utilities.Utilities.GetPatchFilepaths(args, ".eepatch");

            if ((string.IsNullOrEmpty(patchFilepaths.Key)) || (string.IsNullOrEmpty(patchFilepaths.Value)))
            {
                return(false);
            }
            else
            {
                System.IO.Directory.SetCurrentDirectory(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location));
                //while (!System.Diagnostics.Debugger.IsAttached) System.Threading.Thread.Sleep(100);

                try
                {
                    Context context = Context.US_PSX;

                    DataHelper dataHelper = new DataHelper(context);
                    EntryData  patchData  = PatchHelper.GetEntryDataFromPatchFile(patchFilepaths.Key, dataHelper);

                    if (patchFilepaths.Value.ToLower().Trim().EndsWith(".psv"))
                    {
                        PatchHelper.PatchPsxSaveState(patchData, patchFilepaths.Value, dataHelper);
                    }
                    else
                    {
                        PatchHelper.PatchISO(patchData, patchFilepaths.Value, context, dataHelper);
                    }
                }
                catch (Exception ex)
                {
                    AttachConsole(ATTACH_PARENT_PROCESS);
                    Console.WriteLine("Error: " + ex.Message);
                }

                return(true);
            }
        }
Ejemplo n.º 10
0
        public static List <PatchedByteArray> GetISOPatches(EntryData entryData, Context context, DataHelper dataHelper = null)
        {
            dataHelper = dataHelper ?? new DataHelper(context);
            List <PatchedByteArray> patches = new List <PatchedByteArray>();

            SettingsData settings = Settings.GetSettings(context);

            Enum battleSector = settings.BattleConditionalsSector;
            int  battleOffset = settings.BattleConditionalsOffset;

            byte[] battleBytes = dataHelper.ConditionalSetsToByteArray(CommandType.BattleConditional, entryData.BattleConditionals);
            patches.Add(new PatchedByteArray(battleSector, battleOffset, battleBytes));

            if ((settings.BattleConditionalsApplyLimitPatch) && (DataHelper.GetMaxBlocks(entryData.BattleConditionals) > 10))
            {
                patches.Add(new PatchedByteArray(settings.BattleConditionalsLimitPatchSector, settings.BattleConditionalsLimitPatchOffset, settings.BattleConditionalsLimitPatchBytes));
            }

            Enum worldSector = settings.WorldConditionalsSector;
            int  worldOffset = settings.WorldConditionalsOffset;

            byte[] worldBytes = dataHelper.ConditionalSetsToByteArray(CommandType.WorldConditional, entryData.WorldConditionals);
            patches.Add(new PatchedByteArray(worldSector, worldOffset, worldBytes));

            if (settings.WorldConditionalsRepoint)
            {
                byte[] patchBytes = (((uint)(ISOHelper.GetRamOffsetUnsigned(worldSector, context, true) + worldOffset))).ToBytes();
                patches.Add(new PatchedByteArray(settings.WorldConditionalsPointerSector, settings.WorldConditionalsPointerOffset, patchBytes));
            }

            Enum eventSector = settings.EventsSector;
            int  eventOffset = settings.EventsOffset;

            byte[] eventBytes = dataHelper.EventsToByteArray(entryData.Events);
            patches.Add(new PatchedByteArray(eventSector, eventOffset, eventBytes));

            return(patches);
        }
Ejemplo n.º 11
0
        private void LoadPatch(string filepath)
        {
            byte[]     bytesBattleConditionals, bytesWorldConditionals, bytesEvents;
            EntryBytes defaultEntryBytes = _dataHelper.LoadDefaultEntryBytes();

            try
            {
                using (ICSharpCode.SharpZipLib.Zip.ZipFile file = new ICSharpCode.SharpZipLib.Zip.ZipFile(filepath))
                {
                    bytesBattleConditionals = PatcherLib.Utilities.Utilities.GetZipEntry(file, DataHelper.EntryNameBattleConditionals, false) ?? defaultEntryBytes.BattleConditionals;
                    bytesWorldConditionals  = PatcherLib.Utilities.Utilities.GetZipEntry(file, DataHelper.EntryNameWorldConditionals, false) ?? defaultEntryBytes.WorldConditionals;
                    bytesEvents             = PatcherLib.Utilities.Utilities.GetZipEntry(file, DataHelper.EntryNameEvents, false) ?? defaultEntryBytes.Events;
                }

                _entryDataDefault = _dataHelper.LoadEntryDataFromBytes(defaultEntryBytes);
                _entryData        = _dataHelper.LoadEntryDataFromBytes(bytesBattleConditionals, bytesWorldConditionals, bytesEvents);
                PopulateTabs();
            }
            catch (Exception ex)
            {
                PatcherLib.MyMessageBox.Show(this, ex.Message, "Error", MessageBoxButtons.OK);
            }
        }
Ejemplo n.º 12
0
 private void LoadNewPatch()
 {
     _entryData        = _dataHelper.LoadDefaultEntryData();
     _entryDataDefault = _entryData.Copy();
     PopulateTabs();
 }
Ejemplo n.º 13
0
 private void RestoreDefaults()
 {
     SaveFormData();
     _entryDataDefault = _dataHelper.LoadDefaultEntryData();
     PopulateTabs();
 }
Ejemplo n.º 14
0
 private void SetDefaults()
 {
     SaveFormData();
     _entryDataDefault = _entryData.Copy();
     PopulateTabs();
 }
Ejemplo n.º 15
0
 public static void SavePatchXML(EntryData entryData, string filepath, Context context, DataHelper dataHelper = null)
 {
     File.WriteAllText(filepath, CreatePatchXML(entryData, context, dataHelper), System.Text.Encoding.UTF8);
 }
Ejemplo n.º 16
0
 public static string CreatePatchXML(EntryData entryData, Context context, DataHelper dataHelper = null)
 {
     return(PatcherLib.Utilities.Utilities.CreatePatchXML(GetISOPatches(entryData, context, dataHelper), Context.US_PSX, true, true, "EntryEdit Edits"));
 }
Ejemplo n.º 17
0
        public static void PatchPsxSaveState(EntryData entryData, string filepath, DataHelper dataHelper)
        {
            SettingsData settings = Settings.PSX;

            Dictionary <uint, byte[]> ramPatches = new Dictionary <uint, byte[]>();
            bool isBattleLoaded         = false;
            bool isWorldLoaded          = false;
            bool saveBattleConditionals = false;
            bool saveWorldConditionals  = false;
            bool saveEvent = false;

            byte[] worldConditionalsBytes  = null;
            int    battleConditionalsIndex = 0;
            int    eventID = 0;

            int worldConditionalsRamLocation = 0;

            if (!string.IsNullOrEmpty(filepath))
            {
                using (BinaryReader reader = new BinaryReader(File.Open(filepath, FileMode.Open)))
                {
                    Stream stream = reader.BaseStream;

                    if (PsxIso.IsSectorInPsxSaveState(stream, PsxIso.Sectors.BATTLE_BIN))
                    {
                        isBattleLoaded = true;

                        saveBattleConditionals = (PsxIso.LoadFromPsxSaveState(reader, (uint)settings.BattleConditionalBlockOffsetsRAMLocation, 4).ToIntLE() != 0);
                        saveEvent = (PsxIso.LoadFromPsxSaveState(reader, (uint)settings.EventRAMLocation, 1).ToIntLE() != 0);

                        eventID = PsxIso.LoadFromPsxSaveState(reader, (uint)settings.EventIDRAMLocation, 2).ToIntLE();
                        if (!((eventID >= 0) && (eventID < entryData.Events.Count)))
                        {
                            saveEvent = false;
                        }

                        if (PsxIso.IsSectorInPsxSaveState(stream, (PsxIso.Sectors)settings.ScenariosSector))
                        {
                            battleConditionalsIndex = PsxIso.LoadFromPsxSaveState(reader, (uint)(settings.ScenariosRAMLocation + (eventID * 24) + 22), 2).ToIntLE();
                        }
                        else
                        {
                            saveBattleConditionals = false;
                        }
                    }
                    else if (PsxIso.IsSectorInPsxSaveState(stream, PsxIso.Sectors.WORLD_WLDCORE_BIN))
                    {
                        isWorldLoaded = true;

                        worldConditionalsRamLocation = settings.WorldConditionalsRepoint
                            ? PsxIso.LoadFromPsxSaveState(reader, (uint)settings.WorldConditionalsWorkingPointerRAMLocation, 3).ToIntLE()
                            : settings.WorldConditionalsCalcRAMLocation;

                        worldConditionalsBytes = dataHelper.ConditionalSetsToByteArray(CommandType.WorldConditional, entryData.WorldConditionals);
                        if (worldConditionalsBytes.Length > settings.WorldConditionalsSize)
                        {
                            saveWorldConditionals = false;
                        }
                    }
                }

                using (BinaryReader reader = new BinaryReader(File.Open(filepath, FileMode.Open)))
                {
                    if (isBattleLoaded)
                    {
                        if (saveBattleConditionals)
                        {
                            int setIndex = battleConditionalsIndex;
                            if (setIndex >= 0)
                            {
                                uint blockRamOffset   = (uint)settings.BattleConditionalBlockOffsetsRAMLocation;
                                uint commandRamOffset = (uint)settings.BattleConditionalsRAMLocation;

                                List <byte[]> byteArrays = dataHelper.ConditionalSetToActiveByteArrays(CommandType.BattleConditional, entryData.BattleConditionals[setIndex]);
                                ramPatches.Add(blockRamOffset, byteArrays[0]);
                                ramPatches.Add(commandRamOffset, byteArrays[1]);

                                if (settings.BattleConditionalsApplyLimitPatch)
                                {
                                    int numBlocks = entryData.BattleConditionals[setIndex].ConditionalBlocks.Count;
                                    if (numBlocks > 10)
                                    {
                                        ramPatches.Add((uint)settings.BattleConditionalsLimitPatchRAMLocation, settings.BattleConditionalsLimitPatchBytes);
                                    }
                                }
                            }
                        }

                        if (saveEvent)
                        {
                            int eventIndex = eventID;
                            if (eventIndex >= 0)
                            {
                                uint   eventRamOffset = (uint)settings.EventRAMLocation;
                                byte[] eventBytes     = dataHelper.EventToByteArray(entryData.Events[eventIndex], true);
                                ramPatches.Add(eventRamOffset, eventBytes);

                                uint eventRamOffsetKSeg0 = eventRamOffset | PsxIso.KSeg0Mask;
                                uint textOffset          = eventBytes.SubLength(0, 4).ToUInt32();
                                if (textOffset != DataHelper.BlankTextOffsetValue)
                                {
                                    ramPatches.Add((uint)settings.TextOffsetRAMLocation, (eventRamOffsetKSeg0 + textOffset).ToBytes().ToArray());
                                }
                            }
                        }
                    }
                    else if (isWorldLoaded)
                    {
                        if (saveWorldConditionals)
                        {
                            uint ramOffset = (uint)worldConditionalsRamLocation;
                            ramPatches.Add(ramOffset, worldConditionalsBytes);
                            uint ramOffsetKSeg0 = ramOffset | PsxIso.KSeg0Mask;
                            if ((settings.WorldConditionalsRepoint) && (ramOffsetKSeg0 != PsxIso.LoadFromPsxSaveState(reader, (uint)settings.WorldConditionalsPointerRAMLocation, 4).ToUInt32()))
                            {
                                ramPatches.Add((uint)settings.WorldConditionalsPointerRAMLocation, ramOffsetKSeg0.ToBytes().ToArray());
                                ramPatches.Add((uint)settings.WorldConditionalsWorkingPointerRAMLocation, ramOffsetKSeg0.ToBytes().ToArray());
                            }
                        }
                    }

                    PsxIso.PatchPsxSaveState(reader, ramPatches);
                }
            }
        }