From 3588806971ff9e0e8da9c69fc2b409359f46ec20 Mon Sep 17 00:00:00 2001 From: sy2zhao Date: Sun, 10 Sep 2017 03:16:02 -0400 Subject: [PATCH] Ver 1.10. Supports both JPN and USA/EUR version. --- MHSEC-G/MHSEC-G/Armor.cs | 89 ++-- MHSEC-G/MHSEC-G/Character.cs | 62 +-- MHSEC-G/MHSEC-G/Egg.cs | 51 +- MHSEC-G/MHSEC-G/EggFragment.cs | 121 ++--- MHSEC-G/MHSEC-G/Genes.cs | 69 +-- MHSEC-G/MHSEC-G/{Model.cs => Helper.cs} | 20 +- MHSEC-G/MHSEC-G/InMemoryObject.cs | 48 ++ MHSEC-G/MHSEC-G/Item.cs | 91 +--- MHSEC-G/MHSEC-G/MHSEC-G.csproj | 4 +- MHSEC-G/MHSEC-G/MainWindow.xaml | 25 +- MHSEC-G/MHSEC-G/MainWindow.xaml.cs | 78 +-- MHSEC-G/MHSEC-G/Monster.cs | 139 ++--- MHSEC-G/MHSEC-G/MonsterWindow.xaml | 2 +- MHSEC-G/MHSEC-G/MonsterWindow.xaml.cs | 6 +- MHSEC-G/MHSEC-G/Offsets.cs | 593 +++++++++++++++++++++ MHSEC-G/MHSEC-G/Properties/AssemblyInfo.cs | 4 +- MHSEC-G/MHSEC-G/Resources/gene.txt | Bin 9266 -> 9274 bytes MHSEC-G/MHSEC-G/Talisman.cs | 77 +-- MHSEC-G/MHSEC-G/Weapon.cs | 49 +- 19 files changed, 919 insertions(+), 609 deletions(-) rename MHSEC-G/MHSEC-G/{Model.cs => Helper.cs} (88%) create mode 100644 MHSEC-G/MHSEC-G/InMemoryObject.cs create mode 100644 MHSEC-G/MHSEC-G/Offsets.cs diff --git a/MHSEC-G/MHSEC-G/Armor.cs b/MHSEC-G/MHSEC-G/Armor.cs index e74cc22..056634b 100644 --- a/MHSEC-G/MHSEC-G/Armor.cs +++ b/MHSEC-G/MHSEC-G/Armor.cs @@ -6,29 +6,38 @@ using System.Linq; using System.Text; using System.Windows; using MHSEC_G.Annotations; +using Microsoft.Win32; namespace MHSEC_G { - public class Armor : INotifyPropertyChanged + public class Armor : InMemoryObject { - private const uint OFFSETA_ARM = 0x55F0; - private const uint OFFSETA_ARM_END = 0x720E; - // 200 armors - private const uint SIZE_ARM = 0x24; - private const uint OFFSETR_ARM_ID = 0x2; - private const uint OFFSETR_ARM_LEVEL = 0x4; - private const uint OFFSETR_ARM_14h = 0x14; - private const uint OFFSETR_ARM_18h = 0x18; - private const uint OFFSETR_ARM_1C = 0x1c; + public uint index => (_obj_offset - Offsets.OFFSETA_ARM) / Offsets.SIZE_ARM + 1; - private readonly uint _offset; - private readonly Model _model; - public uint index => (_offset - OFFSETA_ARM) / SIZE_ARM + 1; - - public Armor(Model model, uint offset) + public Armor(byte[] save, uint objOffset) : base(save, objOffset, Offsets.SIZE_ARM) { - _offset = offset; - _model = model; + + } + + public string type + { + set + { + uint parsed; + if (Helper.parse_hex_string(value, out parsed) && parsed <= 0xFFFF) + { + Helper.write_uint16_le(_data, _obj_offset + Offsets.OFFSETR_ARM_TYPE, parsed); + } + else + { + MessageBox.Show("Malformed int - must be at most 0xFFFF", "Error", MessageBoxButton.OK, MessageBoxImage.Error); + } + OnPropertyChanged(nameof(type)); + } + get + { + return Helper.byte_to_uint16_le(_data, _obj_offset + Offsets.OFFSETR_ARM_TYPE).ToString("X4"); + } } public string id @@ -36,9 +45,9 @@ namespace MHSEC_G set { uint parsed; - if (Model.parse_hex_string(value, out parsed) && parsed <= 0xFFFF) + if (Helper.parse_hex_string(value, out parsed) && parsed <= 0xFFFF) { - Model.write_uint16_le(_model.save_file, _offset + OFFSETR_ARM_ID, parsed); + Helper.write_uint16_le(_data, _obj_offset + Offsets.OFFSETR_ARM_ID, parsed); } else { @@ -48,7 +57,7 @@ namespace MHSEC_G } get { - return Model.byte_to_uint16_le(_model.save_file, _offset + OFFSETR_ARM_ID).ToString("X4"); + return Helper.byte_to_uint16_le(_data, _obj_offset + Offsets.OFFSETR_ARM_ID).ToString("X4"); } } @@ -57,9 +66,9 @@ namespace MHSEC_G set { uint parsed; - if (Model.parse_hex_string(value, out parsed) && parsed <= 0xFFFF) + if (Helper.parse_hex_string(value, out parsed) && parsed <= 0xFFFF) { - Model.write_uint16_le(_model.save_file, _offset + OFFSETR_ARM_LEVEL, parsed); + Helper.write_uint16_le(_data, _obj_offset + Offsets.OFFSETR_ARM_LEVEL, parsed); } else { @@ -69,7 +78,7 @@ namespace MHSEC_G } get { - return Model.byte_to_uint16_le(_model.save_file, _offset + OFFSETR_ARM_LEVEL).ToString("X4"); + return Helper.byte_to_uint16_le(_data, _obj_offset + Offsets.OFFSETR_ARM_LEVEL).ToString("X4"); } } @@ -79,9 +88,9 @@ namespace MHSEC_G set { uint parsed; - if (Model.parse_hex_string(value, out parsed)) + if (Helper.parse_hex_string(value, out parsed)) { - Model.write_uint32_le(_model.save_file, _offset + OFFSETR_ARM_14h, parsed); + Helper.write_uint32_le(_data, _obj_offset + Offsets.OFFSETR_ARM_14h, parsed); } else { @@ -91,7 +100,7 @@ namespace MHSEC_G } get { - return Model.byte_to_uint32_le(_model.save_file, _offset + OFFSETR_ARM_14h).ToString("X8"); + return Helper.byte_to_uint32_le(_data, _obj_offset + Offsets.OFFSETR_ARM_14h).ToString("X8"); } } @@ -100,9 +109,9 @@ namespace MHSEC_G set { uint parsed; - if (Model.parse_hex_string(value, out parsed)) + if (Helper.parse_hex_string(value, out parsed)) { - Model.write_uint32_le(_model.save_file, _offset + OFFSETR_ARM_18h, parsed); + Helper.write_uint32_le(_data, _obj_offset + Offsets.OFFSETR_ARM_18h, parsed); } else { @@ -112,7 +121,7 @@ namespace MHSEC_G } get { - return Model.byte_to_uint32_le(_model.save_file, _offset + OFFSETR_ARM_18h).ToString("X8"); + return Helper.byte_to_uint32_le(_data, _obj_offset + Offsets.OFFSETR_ARM_18h).ToString("X8"); } } @@ -121,9 +130,9 @@ namespace MHSEC_G set { uint parsed; - if (Model.parse_hex_string(value, out parsed)) + if (Helper.parse_hex_string(value, out parsed)) { - Model.write_uint32_le(_model.save_file, _offset + OFFSETR_ARM_1C, parsed); + Helper.write_uint32_le(_data, _obj_offset + Offsets.OFFSETR_ARM_1C, parsed); } else { @@ -133,28 +142,18 @@ namespace MHSEC_G } get { - return Model.byte_to_uint32_le(_model.save_file, _offset + OFFSETR_ARM_1C).ToString("X8"); + return Helper.byte_to_uint32_le(_data, _obj_offset + Offsets.OFFSETR_ARM_1C).ToString("X8"); } } - public static ObservableCollection read_all_armors(Model model) + public static ObservableCollection read_all_armors(byte[] save) { ObservableCollection ret = new ObservableCollection(); - for (uint i = OFFSETA_ARM; i < OFFSETA_ARM_END; i += SIZE_ARM) + for (uint i = Offsets.OFFSETA_ARM; i < Offsets.OFFSETA_ARM_END; i += Offsets.SIZE_ARM) { - ret.Add(new Armor(model, i)); + ret.Add(new Armor(save, i)); } return ret; } - - public event PropertyChangedEventHandler PropertyChanged; - - [NotifyPropertyChangedInvocator] - protected virtual void OnPropertyChanged(string propertyName) - { - PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); - } } - - } diff --git a/MHSEC-G/MHSEC-G/Character.cs b/MHSEC-G/MHSEC-G/Character.cs index aa0de25..53ce528 100644 --- a/MHSEC-G/MHSEC-G/Character.cs +++ b/MHSEC-G/MHSEC-G/Character.cs @@ -1,34 +1,24 @@ -using System.ComponentModel; +using System; +using System.ComponentModel; using System.Windows; using MHSEC_G.Annotations; namespace MHSEC_G { - public class Character : INotifyPropertyChanged + public class Character : InMemoryObject { - private const uint OFFSETA_CHAR_NAME = 0x9DA0; - private const uint LENGTH_CHAR_NAME = 6; - private const uint OFFSETA_CHAR_MONEY = 0x5B404; - private const uint OFFSETA_CHAR_EXP = 0x9E68; - private const uint OFFSETA_CHAR_LEVEL = 0x9E64; - public const uint LIMIT_LEVEL = 99; - public const uint LIMIT_MONEY = 9999999; - public const uint LIMIT_EXP = 25165822; - - private readonly Model _model; - public uint level { - get { return Model.byte_to_uint(_model.save_file[OFFSETA_CHAR_LEVEL]); } + get { return Helper.byte_to_uint(_data[Offsets.OFFSETA_CHAR_LEVEL]); } set { - if (value <= LIMIT_LEVEL) + if (value <= Offsets.LIMIT_LEVEL) { - Model.write_byte(_model.save_file, OFFSETA_CHAR_LEVEL, value); + Helper.write_byte(_data, Offsets.OFFSETA_CHAR_LEVEL, value); } else { - MessageBox.Show("Level must be less than " + LIMIT_LEVEL, "Error", MessageBoxButton.OK, MessageBoxImage.Error); + MessageBox.Show("Level must be less than " + Offsets.LIMIT_LEVEL, "Error", MessageBoxButton.OK, MessageBoxImage.Error); } OnPropertyChanged(nameof(level)); } @@ -36,16 +26,16 @@ namespace MHSEC_G public uint exp { - get { return Model.byte_to_uint32_le(_model.save_file, OFFSETA_CHAR_EXP); } + get { return Helper.byte_to_uint32_le(_data, Offsets.OFFSETA_CHAR_EXP); } set { - if (value <= LIMIT_EXP) + if (value <= Offsets.LIMIT_EXP) { - Model.write_uint32_le(_model.save_file, OFFSETA_CHAR_EXP, value); + Helper.write_uint32_le(_data, Offsets.OFFSETA_CHAR_EXP, value); } else { - MessageBox.Show("Exp must be less than " + LIMIT_EXP, "Error", MessageBoxButton.OK, MessageBoxImage.Error); + MessageBox.Show("Exp must be less than " + Offsets.LIMIT_EXP, "Error", MessageBoxButton.OK, MessageBoxImage.Error); } OnPropertyChanged(nameof(exp)); } @@ -53,16 +43,16 @@ namespace MHSEC_G public uint money { - get { return Model.byte_to_uint32_le(_model.save_file, OFFSETA_CHAR_MONEY); } + get { return Helper.byte_to_uint32_le(_data, Offsets.OFFSETA_CHAR_MONEY); } set { - if (value <= LIMIT_MONEY) + if (value <= Offsets.LIMIT_MONEY) { - Model.write_uint32_le(_model.save_file, OFFSETA_CHAR_MONEY, value); + Helper.write_uint32_le(_data, Offsets.OFFSETA_CHAR_MONEY, value); } else { - MessageBox.Show("Money must be less than " + LIMIT_MONEY, "Error", MessageBoxButton.OK, MessageBoxImage.Error); + MessageBox.Show("Money must be less than " + Offsets.LIMIT_MONEY, "Error", MessageBoxButton.OK, MessageBoxImage.Error); } OnPropertyChanged(nameof(money)); } @@ -70,33 +60,33 @@ namespace MHSEC_G public string name { - get { return Model.read_unicode_string(_model.save_file, OFFSETA_CHAR_NAME, LENGTH_CHAR_NAME); } + get { return Helper.read_unicode_string(_data, Offsets.OFFSETA_CHAR_NAME, Offsets.LENGTH_CHAR_NAME); } set { - if (value.Length <= LENGTH_CHAR_NAME && value.Length > 0) + if (value.Length <= Offsets.LENGTH_CHAR_NAME && value.Length > 0) { - Model.write_unicode_string(_model.save_file, OFFSETA_CHAR_NAME, value, LENGTH_CHAR_NAME); + Helper.write_unicode_string(_data, Offsets.OFFSETA_CHAR_NAME, value, Offsets.LENGTH_CHAR_NAME); } else { - MessageBox.Show("Name must be 1-" + LENGTH_CHAR_NAME + " characters.", "Error", MessageBoxButton.OK, MessageBoxImage.Error); + MessageBox.Show("Name must be 1-" + Offsets.LENGTH_CHAR_NAME + " characters.", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } OnPropertyChanged(nameof(name)); } } - public Character(Model model) + public Character(byte[] model) : base(model, Offsets.OFFSETA_CHAR_NAME, 0) { - _model = model; } - public event PropertyChangedEventHandler PropertyChanged; - - [NotifyPropertyChangedInvocator] - protected virtual void OnPropertyChanged(string propertyName) + public override byte[] toByteArray() { - PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); + throw new NotImplementedException(); + } + public override void setByteArray(byte[] data) + { + throw new NotImplementedException(); } } } diff --git a/MHSEC-G/MHSEC-G/Egg.cs b/MHSEC-G/MHSEC-G/Egg.cs index 4509675..91b00a8 100644 --- a/MHSEC-G/MHSEC-G/Egg.cs +++ b/MHSEC-G/MHSEC-G/Egg.cs @@ -6,28 +6,17 @@ using MHSEC_G.Annotations; namespace MHSEC_G { - public class Egg : INotifyPropertyChanged + public class Egg : InMemoryObject { - private const int OFFSETA_EGG_START = 0x53EC0; - private const int OFFSETA_EGG_END = 0x54597; - private const int OFFSETR_EGG_GENE = 0x30; - private const int SIZE_EGG_GENE = 0x2; - private const int SIZE_EGG = 0x92; - private const int OFFSETR_SPE = 0x0; - private const int OFFSETR_WGT = 0x2E; private readonly Genes _genes; public Genes genes => _genes; - private readonly uint _offset; - private readonly Model _model; - public uint index => (_offset - OFFSETA_EGG_START) / SIZE_EGG + 1; + public uint index => (_obj_offset - Offsets.OFFSETA_EGG_START) / Offsets.SIZE_EGG + 1; - public Egg(Model model, uint offset) + public Egg(byte[] model, uint objOffset) : base(model, objOffset, Offsets.SIZE_EGG) { - _offset = offset; - _model = model; - _genes = new Genes(model, offset + OFFSETR_EGG_GENE, SIZE_EGG_GENE); + _genes = new Genes(model, objOffset + Offsets.OFFSETR_EGG_GENE, Offsets.SIZE_EGG_GENE); } public string spe @@ -35,9 +24,9 @@ namespace MHSEC_G set { uint parsed; - if (Model.parse_hex_string(value, out parsed) && parsed <= 0xFF) + if (Helper.parse_hex_string(value, out parsed) && parsed <= 0xFF) { - Model.write_byte(_model.save_file, _offset + OFFSETR_SPE, parsed); + Helper.write_byte(_data, _obj_offset + Offsets.OFFSETR_SPE, parsed); } else { @@ -47,7 +36,7 @@ namespace MHSEC_G } get { - return Model.byte_to_uint(_model.save_file[_offset + OFFSETR_SPE]).ToString("X2"); + return Helper.byte_to_uint(_data[_obj_offset + Offsets.OFFSETR_SPE]).ToString("X2"); } } @@ -56,9 +45,9 @@ namespace MHSEC_G set { uint parsed; - if (Model.parse_hex_string(value, out parsed) && parsed <= 0xFF) + if (Helper.parse_hex_string(value, out parsed) && parsed <= 0xFF) { - Model.write_byte(_model.save_file, _offset + OFFSETR_WGT, parsed); + Helper.write_byte(_data, _obj_offset + Offsets.OFFSETR_WGT, parsed); } else { @@ -68,34 +57,18 @@ namespace MHSEC_G } get { - return Model.byte_to_uint(_model.save_file[_offset + OFFSETR_WGT]).ToString("X2"); + return Helper.byte_to_uint(_data[_obj_offset + Offsets.OFFSETR_WGT]).ToString("X2"); } } - public static ObservableCollection read_all_eggs(Model model) + public static ObservableCollection read_all_eggs(byte[] model) { ObservableCollection ret = new ObservableCollection(); - for (uint i = OFFSETA_EGG_START; i < OFFSETA_EGG_END; i += SIZE_EGG) + for (uint i = Offsets.OFFSETA_EGG_START; i < Offsets.OFFSETA_EGG_END; i += Offsets.SIZE_EGG) { ret.Add(new Egg(model, i)); } return ret; } - - - public void setByteArray(byte[] ret) - { - Array.Copy(ret, 0, _model.save_file, _offset, SIZE_EGG); - OnPropertyChanged(null); - } - - public event PropertyChangedEventHandler PropertyChanged; - - [NotifyPropertyChangedInvocator] - protected virtual void OnPropertyChanged(string propertyName) - { - PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); - } - } } diff --git a/MHSEC-G/MHSEC-G/EggFragment.cs b/MHSEC-G/MHSEC-G/EggFragment.cs index a3fa51e..c32a4a9 100644 --- a/MHSEC-G/MHSEC-G/EggFragment.cs +++ b/MHSEC-G/MHSEC-G/EggFragment.cs @@ -6,43 +6,23 @@ using MHSEC_G.Annotations; namespace MHSEC_G { - public class EggFragment : INotifyPropertyChanged + public class EggFragment : InMemoryObject { - private const uint OFFSETA_EGG_FRAGMENTS = 0x9790; - private const uint OFFSETA_EGG_FRAGMENTS_END = 0x9C3F; - private const uint SIZE_EGG_FRAGMENT = 0xC; - private const uint OFFSETR_EF_SPE = 0x0; - private const uint OFFSETR_EF_POS = 0x1; - private const uint OFFSETR_EF_NEW = 0x2; - private const uint OFFSETR_EF_RAR = 0x3; - private const uint OFFSETR_EF_COL = 0x4; - private const uint OFFSETR_EF_DLC = 0x5; - private const uint OFFSETR_EF_6H = 0x6; - private const uint OFFSETR_EF_7H = 0x7; + public uint idx => (_obj_offset - Offsets.OFFSETA_EGG_FRAGMENTS) / Offsets.SIZE_EGG_FRAGMENT + 1; - private readonly uint _offset; - public uint idx => (_offset - OFFSETA_EGG_FRAGMENTS) / SIZE_EGG_FRAGMENT + 1; - - public uint offset + public EggFragment(byte[] model, uint objOffset) : base(model, objOffset, Offsets.SIZE_EGG_FRAGMENT) { - get { return _offset;} - } - private readonly Model _model; - public EggFragment(uint offset, Model model) - { - _model = model; - _offset = offset; } public string spe { - get { return Model.byte_to_uint(_model.save_file[_offset + OFFSETR_EF_SPE]).ToString("X2"); } + get { return Helper.byte_to_uint(_data[_obj_offset + Offsets.OFFSETR_EF_SPE]).ToString("X2"); } set { uint parsed; - if (Model.parse_hex_string(value, out parsed) && parsed <= 0x0E) + if (Helper.parse_hex_string(value, out parsed) && parsed <= 0x0E) { - Model.write_byte(_model.save_file, _offset + OFFSETR_EF_SPE, parsed); + Helper.write_byte(_data, _obj_offset + Offsets.OFFSETR_EF_SPE, parsed); } else { @@ -54,13 +34,13 @@ namespace MHSEC_G public string pos { - get { return Model.byte_to_uint(_model.save_file[_offset + OFFSETR_EF_POS]).ToString("X2"); } + get { return Helper.byte_to_uint(_data[_obj_offset + Offsets.OFFSETR_EF_POS]).ToString("X2"); } set { uint parsed; - if (Model.parse_hex_string(value, out parsed) && parsed <= 0x08) + if (Helper.parse_hex_string(value, out parsed) && parsed <= 0x08) { - Model.write_byte(_model.save_file, _offset + OFFSETR_EF_POS, parsed); + Helper.write_byte(_data, _obj_offset + Offsets.OFFSETR_EF_POS, parsed); } else { @@ -72,13 +52,13 @@ namespace MHSEC_G public string new_flag { - get { return Model.byte_to_uint(_model.save_file[_offset + OFFSETR_EF_NEW]).ToString("X2"); } + get { return Helper.byte_to_uint(_data[_obj_offset + Offsets.OFFSETR_EF_NEW]).ToString("X2"); } set { uint parsed; - if (Model.parse_hex_string(value, out parsed) && parsed <= 0x01) + if (Helper.parse_hex_string(value, out parsed) && parsed <= 0x01) { - Model.write_byte(_model.save_file, _offset + OFFSETR_EF_NEW, parsed); + Helper.write_byte(_data, _obj_offset + Offsets.OFFSETR_EF_NEW, parsed); } else { @@ -89,13 +69,13 @@ namespace MHSEC_G } public string rarity { - get { return Model.byte_to_uint(_model.save_file[_offset + OFFSETR_EF_RAR]).ToString("X2"); } + get { return Helper.byte_to_uint(_data[_obj_offset + Offsets.OFFSETR_EF_RAR]).ToString("X2"); } set { uint parsed; - if (Model.parse_hex_string(value, out parsed) && parsed <= 0x01) + if (Helper.parse_hex_string(value, out parsed) && parsed <= 0x01) { - Model.write_byte(_model.save_file, _offset + OFFSETR_EF_RAR, parsed); + Helper.write_byte(_data, _obj_offset + Offsets.OFFSETR_EF_RAR, parsed); } else { @@ -107,13 +87,13 @@ namespace MHSEC_G public string color { - get { return Model.byte_to_uint(_model.save_file[_offset + OFFSETR_EF_COL]).ToString("X2"); } + get { return Helper.byte_to_uint(_data[_obj_offset + Offsets.OFFSETR_EF_COL]).ToString("X2"); } set { uint parsed; - if (Model.parse_hex_string(value, out parsed) && parsed <= 0xFF) + if (Helper.parse_hex_string(value, out parsed) && parsed <= 0xFF) { - Model.write_byte(_model.save_file, _offset + OFFSETR_EF_COL, parsed); + Helper.write_byte(_data, _obj_offset + Offsets.OFFSETR_EF_COL, parsed); } else { @@ -125,13 +105,13 @@ namespace MHSEC_G public string dlc { - get { return Model.byte_to_uint(_model.save_file[_offset + OFFSETR_EF_DLC]).ToString("X2"); } + get { return Helper.byte_to_uint(_data[_obj_offset + Offsets.OFFSETR_EF_DLC]).ToString("X2"); } set { uint parsed; - if (Model.parse_hex_string(value, out parsed) && parsed <= 0xFF) + if (Helper.parse_hex_string(value, out parsed) && parsed <= 0xFF) { - Model.write_byte(_model.save_file, _offset + OFFSETR_EF_DLC, parsed); + Helper.write_byte(_data, _obj_offset + Offsets.OFFSETR_EF_DLC, parsed); } else { @@ -143,13 +123,13 @@ namespace MHSEC_G public string unknown_6h { - get { return Model.byte_to_uint(_model.save_file[_offset + OFFSETR_EF_6H]).ToString("X2"); } + get { return Helper.byte_to_uint(_data[_obj_offset + Offsets.OFFSETR_EF_6H]).ToString("X2"); } set { uint parsed; - if (Model.parse_hex_string(value, out parsed) && parsed <= 0xFF) + if (Helper.parse_hex_string(value, out parsed) && parsed <= 0xFF) { - Model.write_byte(_model.save_file, _offset + OFFSETR_EF_6H, parsed); + Helper.write_byte(_data, _obj_offset + Offsets.OFFSETR_EF_6H, parsed); } else { @@ -161,13 +141,13 @@ namespace MHSEC_G public string unknown_7h { - get { return Model.byte_to_uint(_model.save_file[_offset + OFFSETR_EF_7H]).ToString("X2"); } + get { return Helper.byte_to_uint(_data[_obj_offset + Offsets.OFFSETR_EF_7H]).ToString("X2"); } set { uint parsed; - if (Model.parse_hex_string(value, out parsed) && parsed <= 0xFF) + if (Helper.parse_hex_string(value, out parsed) && parsed <= 0xFF) { - Model.write_byte(_model.save_file, _offset + OFFSETR_EF_7H, parsed); + Helper.write_byte(_data, _obj_offset + Offsets.OFFSETR_EF_7H, parsed); } else { @@ -177,55 +157,14 @@ namespace MHSEC_G } } - public static ObservableCollection read_all_egg_fragments(Model model) + public static ObservableCollection read_all_egg_fragments(byte[] model) { ObservableCollection ret = new ObservableCollection(); - byte[] buffer = model.save_file; - for (uint offset = OFFSETA_EGG_FRAGMENTS; offset < OFFSETA_EGG_FRAGMENTS_END; offset += SIZE_EGG_FRAGMENT) + for (uint offset = Offsets.OFFSETA_EGG_FRAGMENTS; offset < Offsets.OFFSETA_EGG_FRAGMENTS_END; offset += Offsets.SIZE_EGG_FRAGMENT) { - ret.Add(new EggFragment(offset, model)); + ret.Add(new EggFragment(model, offset)); } return ret; } - - - private static EggFragment egg_frag_offset_exist(ObservableCollection fragments, uint offset) - { - for (uint i = 0; i < fragments.Count; i++) - { - if(fragments.ElementAt((int)i).offset == offset) - return fragments.ElementAt((int)i); - } - return null; - } - - public static void write_dlc_egg_fragment(ObservableCollection fragments, Model model, uint dlc) - { - for (uint offset = OFFSETA_EGG_FRAGMENTS; offset < OFFSETA_EGG_FRAGMENTS + 9*SIZE_EGG_FRAGMENT ; offset += SIZE_EGG_FRAGMENT) - { - EggFragment each_frag = egg_frag_offset_exist(fragments, offset); - if (each_frag == null) - { - each_frag = new EggFragment(offset, model); - fragments.Insert((int)((offset - OFFSETA_EGG_FRAGMENTS) / SIZE_EGG_FRAGMENT), each_frag); - } - each_frag.new_flag = "0"; - each_frag.spe = "08"; - each_frag.pos = ((offset-OFFSETA_EGG_FRAGMENTS) / SIZE_EGG_FRAGMENT).ToString(); - each_frag.rarity = "0"; - each_frag.color = "0"; - each_frag.dlc = dlc.ToString("X2"); - each_frag.unknown_6h = "0"; - each_frag.unknown_7h = "0"; - } - } - - public event PropertyChangedEventHandler PropertyChanged; - - [NotifyPropertyChangedInvocator] - protected virtual void OnPropertyChanged(string propertyName) - { - PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); - } } } diff --git a/MHSEC-G/MHSEC-G/Genes.cs b/MHSEC-G/MHSEC-G/Genes.cs index 402ccd5..5c0b641 100644 --- a/MHSEC-G/MHSEC-G/Genes.cs +++ b/MHSEC-G/MHSEC-G/Genes.cs @@ -9,40 +9,28 @@ using MHSEC_G.Annotations; namespace MHSEC_G { - public class Genes : INotifyPropertyChanged + public class Genes : InMemoryObject { - public static readonly List GENE_ID = new List(); - public static readonly List GENE_NAME = new List(); - public List gene_name => GENE_NAME; - - private readonly uint _size; - private readonly Model _model; - private readonly uint _offset; - public Genes(Model model, uint offset, uint size) + public List gene_name => Offsets.GENE_NAME; + private readonly uint _gene_size; + public Genes(byte[] model, uint objOffset, uint gene_size) : base(model, objOffset, 9 * gene_size) { - this._size = size; - this._offset = offset; - this._model = model; + _gene_size = gene_size; } - // - // Genes - // - private uint extract_gene(uint gene_idx) { if (gene_idx >= 9) { BugCheck.bug_check(BugCheck.ErrorCode.MON_GENE_IDX_OVERFLOW, "Invalid gene index: " + gene_idx); } - return Model.byte_to_uint16_le(_model.save_file, - _offset + gene_idx * _size); + return Helper.byte_to_uint16_le(_data, _obj_offset + gene_idx * _gene_size); } private void set_gene_str(uint gene_idx, string val) { uint parsed; - if (Model.parse_hex_string(val, out parsed)) + if (Helper.parse_hex_string(val, out parsed)) { set_gene(gene_idx, parsed); } @@ -61,7 +49,7 @@ namespace MHSEC_G } if (val <= 0xFFFF) { - Model.write_uint16_le(_model.save_file, _offset + gene_idx * _size, + Helper.write_uint16_le(_data, _obj_offset + gene_idx * _gene_size, val); } else @@ -74,20 +62,20 @@ namespace MHSEC_G private int extract_gene_idx(uint gene_idx) { uint gene_id = extract_gene(gene_idx); - int idx = GENE_ID.IndexOf(gene_id); + int idx = Offsets.GENE_ID.IndexOf(gene_id); if (idx == -1) { // unknown - return GENE_NAME.Count - 1; + return Offsets.GENE_NAME.Count - 1; } return idx; } private void set_gene_idx(uint gene_idx, int val) { - if (val != -1 && val != GENE_NAME.Count - 1) + if (val != -1 && val != Offsets.GENE_NAME.Count - 1) { - set_gene(gene_idx, GENE_ID.ElementAt(val)); + set_gene(gene_idx, Offsets.GENE_ID.ElementAt(val)); } } @@ -297,38 +285,5 @@ namespace MHSEC_G OnPropertyChanged(nameof(gene9_selected)); } } - - public static void read_gene_mapping() - { - string line; - StringReader file = new StringReader(Properties.Resources.gene); - - while ((line = file.ReadLine()) != null) - { - if (line.Length == 0) - continue; - - string[] eachline = line.Split('\t'); - if (eachline.Length != 2) - { - BugCheck.bug_check(BugCheck.ErrorCode.MON_GENE_MAPPING_CORRUPTED, - "Invalid gene mapping file line:\n" + line); - } - - GENE_ID.Add(uint.Parse(eachline[0], System.Globalization.NumberStyles.HexNumber)); - GENE_NAME.Add(eachline[1]); - } - GENE_NAME.Add("Custom"); - - file.Close(); - } - - public event PropertyChangedEventHandler PropertyChanged; - - [NotifyPropertyChangedInvocator] - protected virtual void OnPropertyChanged(string propertyName) - { - PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); - } } } diff --git a/MHSEC-G/MHSEC-G/Model.cs b/MHSEC-G/MHSEC-G/Helper.cs similarity index 88% rename from MHSEC-G/MHSEC-G/Model.cs rename to MHSEC-G/MHSEC-G/Helper.cs index c01c313..9dbdb18 100644 --- a/MHSEC-G/MHSEC-G/Model.cs +++ b/MHSEC-G/MHSEC-G/Helper.cs @@ -4,26 +4,8 @@ using System.Text; namespace MHSEC_G { - public class Model + public static class Helper { - public const uint SAVE_FILE_SIZE = 483976; - - private readonly byte[] _save_file; - - public byte[] save_file - { - get { return _save_file; } - } - - public Model(byte[] save_file) - { - if (save_file.Length != SAVE_FILE_SIZE) - { - BugCheck.bug_check(BugCheck.ErrorCode.MODEL_INVALID_FILE_SIZE, "Invalid file size.\nExpected: " + SAVE_FILE_SIZE + " Got: " + save_file.Length); - } - _save_file = save_file; - } - public static uint byte_to_uint(byte b) { return (uint) (b) & 0xFF; diff --git a/MHSEC-G/MHSEC-G/InMemoryObject.cs b/MHSEC-G/MHSEC-G/InMemoryObject.cs new file mode 100644 index 0000000..a274102 --- /dev/null +++ b/MHSEC-G/MHSEC-G/InMemoryObject.cs @@ -0,0 +1,48 @@ +using System; +using System.ComponentModel; +using MHSEC_G.Annotations; + +namespace MHSEC_G +{ + public class InMemoryObject : INotifyPropertyChanged + { + protected readonly uint _obj_offset; + protected readonly byte[] _data; + protected readonly uint _obj_size; + + public InMemoryObject(byte[] data, uint objOffset, uint objSize) + { + _obj_offset = objOffset; + _data = data; + _obj_size = objSize; + } + + public virtual byte[] toByteArray() + { + byte[] ret = new byte[_obj_size]; + Array.Copy(_data, _obj_offset, ret, 0, _obj_size); + return ret; + } + + public virtual void setByteArray(byte[] data) + { + if (data.Length != _obj_size) + { + BugCheck.bug_check(BugCheck.ErrorCode.MODEL_INVALID_FILE_SIZE, "Invalid data size in setByteArray."); + } + else + { + Array.Copy(data, 0, _data, _obj_offset, _obj_size); + OnPropertyChanged(null); + } + } + + public event PropertyChangedEventHandler PropertyChanged; + + [NotifyPropertyChangedInvocator] + protected virtual void OnPropertyChanged(string propertyName) + { + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); + } + } +} diff --git a/MHSEC-G/MHSEC-G/Item.cs b/MHSEC-G/MHSEC-G/Item.cs index 2d7b94f..cc5c02f 100644 --- a/MHSEC-G/MHSEC-G/Item.cs +++ b/MHSEC-G/MHSEC-G/Item.cs @@ -8,34 +8,16 @@ using MHSEC_G.Annotations; namespace MHSEC_G { - public class Item : INotifyPropertyChanged + public class Item : InMemoryObject { - private static readonly uint OFFSETA_ITEM_BOX = 0x10; - private static readonly uint SIZE_ITEM = 0x8; - private static readonly uint OFFSETR_ITEM_ID = 0x0; - private static readonly uint OFFSETR_ITEM_COUNT = 0x2; - private static readonly uint OFFSETA_ITEM_BOX_END = 0x2EE7; - public static readonly uint OFFSETA_FIRST_KEY_ITEM = 0x17B0; - - private static readonly Dictionary OFFSET_ID_MAPPING = new Dictionary(); - private static readonly Dictionary OFFSET_NAME_MAPPING = new Dictionary(); - - private readonly uint _offset; - - public uint offset - { - get { return _offset; } - } - - private readonly Model _model; - + public uint offset => _obj_offset; public string name { get { - string name = _offset >= OFFSETA_FIRST_KEY_ITEM ? "Key Item [" + id.ToString("X4") + "]" : "Unknown"; - if (OFFSET_NAME_MAPPING.ContainsKey(_offset)) + string name = _obj_offset >= Offsets.OFFSETA_FIRST_KEY_ITEM ? "Key Item [" + id.ToString("X4") + "]" : "Unknown"; + if (Offsets.OFFSET_NAME_MAPPING.ContainsKey(_obj_offset)) { - name = OFFSET_NAME_MAPPING[_offset]; + name = Offsets.OFFSET_NAME_MAPPING[_obj_offset]; } return name; } @@ -44,12 +26,12 @@ namespace MHSEC_G public uint count { - get { return Model.byte_to_uint16_le(_model.save_file, _offset + OFFSETR_ITEM_COUNT); } + get { return Helper.byte_to_uint16_le(_data, _obj_offset + Offsets.OFFSETR_ITEM_COUNT); } set { if (value <= 999) { - Model.write_uint16_le(_model.save_file, _offset + OFFSETR_ITEM_COUNT, value); + Helper.write_uint16_le(_data, _obj_offset + Offsets.OFFSETR_ITEM_COUNT, value); } else { @@ -61,85 +43,52 @@ namespace MHSEC_G public uint id { - get { return Model.byte_to_uint16_le(_model.save_file, _offset + OFFSETR_ITEM_ID); } + get { return Helper.byte_to_uint16_le(_data, _obj_offset + Offsets.OFFSETR_ITEM_ID); } } - public Item(uint offset, Model model) + public Item(byte[] model, uint objOffset) : base(model, objOffset, Offsets.SIZE_ITEM) { - _offset = offset; - _model = model; } - public static List read_all_items(Model model) + public static List read_all_items(byte[] model) { - byte[] buffer = model.save_file; List ret = new List(); - for (uint offset = OFFSETA_ITEM_BOX; offset < OFFSETA_ITEM_BOX_END; offset += SIZE_ITEM) + for (uint offset = Offsets.OFFSETA_ITEM_BOX; + offset < Offsets.OFFSETA_ITEM_BOX_END; + offset += Offsets.SIZE_ITEM) { - uint item_id = Model.byte_to_uint16_le(buffer, offset + OFFSETR_ITEM_ID); + uint item_id = Helper.byte_to_uint16_le(model, offset + Offsets.OFFSETR_ITEM_ID); if (item_id == 0) { // if not obtained yet - if (!OFFSET_ID_MAPPING.ContainsKey(offset)) + if (!Offsets.OFFSET_ID_MAPPING.ContainsKey(offset)) { // well we dont know the id to this offset either. just ignore! // continue continue; } // if we know the id to the offset, just set it - Model.write_uint16_le(model.save_file, offset + OFFSETR_ITEM_ID, OFFSET_ID_MAPPING[offset]); + Helper.write_uint16_le(model, offset + Offsets.OFFSETR_ITEM_ID, Offsets.OFFSET_ID_MAPPING[offset]); } else { // already obtained // validate - if (OFFSET_ID_MAPPING.ContainsKey(offset)) + if (Offsets.OFFSET_ID_MAPPING.ContainsKey(offset)) { - if (item_id != OFFSET_ID_MAPPING[offset]) + if (item_id != Offsets.OFFSET_ID_MAPPING[offset]) { // correct to the correct id // don't bug_check since too many people's files are broken // TODO: BugCheck.bug_check(BugCheck.ErrorCode.ITEM_NO_CORRESPONDENCE, "Item offset " + offset.ToString("X") + " and item ID " + item_id.ToString("X") + " do not correspond."); - Model.write_uint16_le(model.save_file, offset + OFFSETR_ITEM_ID, OFFSET_ID_MAPPING[offset]); + Helper.write_uint16_le(model, offset + Offsets.OFFSETR_ITEM_ID, Offsets.OFFSET_ID_MAPPING[offset]); } } } // valid offset - ret.Add(new Item(offset, model)); + ret.Add(new Item(model, offset)); } return ret; } - - public static void read_item_mappings() - { - string line; - StringReader file = new StringReader(Properties.Resources.idmap); - - while ((line = file.ReadLine()) != null) - { - if (line.Length == 0) - continue; - - string[] eachline = line.Split('\t'); - if (eachline.Length != 3) - { - - BugCheck.bug_check(BugCheck.ErrorCode.ITEM_MAPPING_CORRUPTED, "Invalid mapping file line:\n" + line); - } - - OFFSET_ID_MAPPING.Add(uint.Parse(eachline[0], System.Globalization.NumberStyles.HexNumber), uint.Parse(eachline[1], System.Globalization.NumberStyles.HexNumber)); - OFFSET_NAME_MAPPING.Add(uint.Parse(eachline[0], System.Globalization.NumberStyles.HexNumber), eachline[2]); - } - - file.Close(); - } - - public event PropertyChangedEventHandler PropertyChanged; - - [NotifyPropertyChangedInvocator] - protected virtual void OnPropertyChanged(string propertyName) - { - PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); - } } } diff --git a/MHSEC-G/MHSEC-G/MHSEC-G.csproj b/MHSEC-G/MHSEC-G/MHSEC-G.csproj index 49de7eb..e948f6c 100644 --- a/MHSEC-G/MHSEC-G/MHSEC-G.csproj +++ b/MHSEC-G/MHSEC-G/MHSEC-G.csproj @@ -90,12 +90,14 @@ GeneWindow.xaml + - + MonsterWindow.xaml + True diff --git a/MHSEC-G/MHSEC-G/MainWindow.xaml b/MHSEC-G/MHSEC-G/MainWindow.xaml index cfedb15..81cd3fe 100644 --- a/MHSEC-G/MHSEC-G/MainWindow.xaml +++ b/MHSEC-G/MHSEC-G/MainWindow.xaml @@ -81,7 +81,7 @@ Header="Index" IsReadOnly="True"/> + Header="Genus" /> @@ -109,8 +109,8 @@ -