diff --git a/MHSEC-G/MHSEC-G.sln b/MHSEC-G/MHSEC-G.sln index e369ece..1edbf58 100644 --- a/MHSEC-G/MHSEC-G.sln +++ b/MHSEC-G/MHSEC-G.sln @@ -10,13 +10,19 @@ EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU + Debug|x86 = Debug|x86 Release|Any CPU = Release|Any CPU + Release|x86 = Release|x86 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {80372081-2D34-424B-93E2-89D5815BF3E8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {80372081-2D34-424B-93E2-89D5815BF3E8}.Debug|Any CPU.Build.0 = Debug|Any CPU + {80372081-2D34-424B-93E2-89D5815BF3E8}.Debug|x86.ActiveCfg = Debug|x86 + {80372081-2D34-424B-93E2-89D5815BF3E8}.Debug|x86.Build.0 = Debug|x86 {80372081-2D34-424B-93E2-89D5815BF3E8}.Release|Any CPU.ActiveCfg = Release|Any CPU {80372081-2D34-424B-93E2-89D5815BF3E8}.Release|Any CPU.Build.0 = Release|Any CPU + {80372081-2D34-424B-93E2-89D5815BF3E8}.Release|x86.ActiveCfg = Release|x86 + {80372081-2D34-424B-93E2-89D5815BF3E8}.Release|x86.Build.0 = Release|x86 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/MHSEC-G/MHSEC-G/Character.cs b/MHSEC-G/MHSEC-G/Character.cs index 3a58683..6b406f7 100644 --- a/MHSEC-G/MHSEC-G/Character.cs +++ b/MHSEC-G/MHSEC-G/Character.cs @@ -7,7 +7,7 @@ namespace MHSEC_G public class Character : INotifyPropertyChanged { private const uint OFFSETA_CHAR_NAME = 0x9DA0; - private const uint LENGTH_CHAR_NAME = 5; + private const uint LENGTH_CHAR_NAME = 4; private const uint OFFSETA_CHAR_MONEY = 0x5B404; private const uint OFFSETA_CHAR_EXP = 0x9E68; private const uint OFFSETA_CHAR_LEVEL = 0x9E64; @@ -70,16 +70,16 @@ namespace MHSEC_G public string name { - get { return Model.read_unicode_string(_model.save_file, OFFSETA_CHAR_NAME, LENGTH_CHAR_NAME); } + get { return Model.read_unicode_string(_model.save_file, OFFSETA_CHAR_NAME, 65536); } set { if (value.Length <= LENGTH_CHAR_NAME && value.Length > 0) { - Model.write_unicode_string(_model.save_file, OFFSETA_CHAR_NAME, value, LENGTH_CHAR_NAME); + Model.write_unicode_string(_model.save_file, OFFSETA_CHAR_NAME, value, LENGTH_CHAR_NAME + 1); } else { - MessageBox.Show("Name must be 1-6 characters.", "Error", MessageBoxButton.OK, MessageBoxImage.Error); + MessageBox.Show("Name must be 1-" + LENGTH_CHAR_NAME + " characters.", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } OnPropertyChanged(nameof(name)); } diff --git a/MHSEC-G/MHSEC-G/EggFragment.cs b/MHSEC-G/MHSEC-G/EggFragment.cs index 567189a..5c0052c 100644 --- a/MHSEC-G/MHSEC-G/EggFragment.cs +++ b/MHSEC-G/MHSEC-G/EggFragment.cs @@ -1,11 +1,233 @@ -using System; -using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.ComponentModel; using System.Linq; -using System.Text; +using System.Windows; +using MHSEC_G.Annotations; namespace MHSEC_G { - class EggFragment + public class EggFragment : INotifyPropertyChanged { + 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; + + private readonly uint _offset; + + public uint offset + { + 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"); } + set + { + uint parsed; + if (Model.parse_hex_string(value, out parsed) && parsed <= 0x0C) + { + Model.write_byte(_model.save_file, _offset + OFFSETR_EF_SPE, parsed); + } + else + { + MessageBox.Show("Malformed Species value - must be at most 0xC", "Error", MessageBoxButton.OK, MessageBoxImage.Error); + } + OnPropertyChanged(nameof(spe)); + } + } + + public string pos + { + get { return Model.byte_to_uint(_model.save_file[_offset + OFFSETR_EF_POS]).ToString("X2"); } + set + { + uint parsed; + if (Model.parse_hex_string(value, out parsed) && parsed <= 0x08) + { + Model.write_byte(_model.save_file, _offset + OFFSETR_EF_POS, parsed); + } + else + { + MessageBox.Show("Malformed Position value - must be at most 0x8", "Error", MessageBoxButton.OK, MessageBoxImage.Error); + } + OnPropertyChanged(nameof(pos)); + } + } + + public string new_flag + { + get { return Model.byte_to_uint(_model.save_file[_offset + OFFSETR_EF_NEW]).ToString("X2"); } + set + { + uint parsed; + if (Model.parse_hex_string(value, out parsed) && parsed <= 0x01) + { + Model.write_byte(_model.save_file, _offset + OFFSETR_EF_NEW, parsed); + } + else + { + MessageBox.Show("Malformed New value - must be 0 or 1", "Error", MessageBoxButton.OK, MessageBoxImage.Error); + } + OnPropertyChanged(nameof(new_flag)); + } + } + public string rarity + { + get { return Model.byte_to_uint(_model.save_file[_offset + OFFSETR_EF_RAR]).ToString("X2"); } + set + { + uint parsed; + if (Model.parse_hex_string(value, out parsed) && parsed <= 0x01) + { + Model.write_byte(_model.save_file, _offset + OFFSETR_EF_RAR, parsed); + } + else + { + MessageBox.Show("Malformed Rarity value - must be 0 or 1", "Error", MessageBoxButton.OK, MessageBoxImage.Error); + } + OnPropertyChanged(nameof(rarity)); + } + } + + public string color + { + get { return Model.byte_to_uint(_model.save_file[_offset + OFFSETR_EF_COL]).ToString("X2"); } + set + { + uint parsed; + if (Model.parse_hex_string(value, out parsed) && parsed <= 0xFF) + { + Model.write_byte(_model.save_file, _offset + OFFSETR_EF_COL, parsed); + } + else + { + MessageBox.Show("Malformed Species value - must be at most 0xFF", "Error", MessageBoxButton.OK, MessageBoxImage.Error); + } + OnPropertyChanged(nameof(color)); + } + } + + public string dlc + { + get { return Model.byte_to_uint(_model.save_file[_offset + OFFSETR_EF_DLC]).ToString("X2"); } + set + { + uint parsed; + if (Model.parse_hex_string(value, out parsed) && parsed <= 0xFF) + { + Model.write_byte(_model.save_file, _offset + OFFSETR_EF_DLC, parsed); + } + else + { + MessageBox.Show("Malformed DLC value - must be at most 0xFF", "Error", MessageBoxButton.OK, MessageBoxImage.Error); + } + OnPropertyChanged(nameof(dlc)); + } + } + + public string unknown_6h + { + get { return Model.byte_to_uint(_model.save_file[_offset + OFFSETR_EF_6H]).ToString("X2"); } + set + { + uint parsed; + if (Model.parse_hex_string(value, out parsed) && parsed <= 0xFF) + { + Model.write_byte(_model.save_file, _offset + OFFSETR_EF_6H, parsed); + } + else + { + MessageBox.Show("Malformed Species value - must be at most 0xFF", "Error", MessageBoxButton.OK, MessageBoxImage.Error); + } + OnPropertyChanged(nameof(unknown_6h)); + } + } + + public string unknown_7h + { + get { return Model.byte_to_uint(_model.save_file[_offset + OFFSETR_EF_7H]).ToString("X2"); } + set + { + uint parsed; + if (Model.parse_hex_string(value, out parsed) && parsed <= 0xFF) + { + Model.write_byte(_model.save_file, _offset + OFFSETR_EF_7H, parsed); + } + else + { + MessageBox.Show("Malformed 7h value - must be at most 0xFF", "Error", MessageBoxButton.OK, MessageBoxImage.Error); + } + OnPropertyChanged(nameof(unknown_7h)); + } + } + + public static ObservableCollection read_all_egg_fragments(Model 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) + { + if(buffer[offset] == 0) + continue; + ret.Add(new EggFragment(offset, model)); + } + 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/Item.cs b/MHSEC-G/MHSEC-G/Item.cs index 4163c26..854babb 100644 --- a/MHSEC-G/MHSEC-G/Item.cs +++ b/MHSEC-G/MHSEC-G/Item.cs @@ -15,7 +15,7 @@ namespace MHSEC_G private static readonly uint OFFSETR_ITEM_COUNT = 0x2; private static readonly uint OFFSETA_ITEM_BOX_END = 0x2EE7; - private static readonly string ID_MAPPING_FILE_NAME = "C:\\Users\\hyper\\Desktop\\idmap.txt"; + private static readonly string ID_MAPPING_FILE_NAME = "idmap.txt"; private static readonly Dictionary OFFSET_ID_MAPPING = new Dictionary(); private static readonly Dictionary OFFSET_NAME_MAPPING = new Dictionary(); diff --git a/MHSEC-G/MHSEC-G/MHSEC-G.csproj b/MHSEC-G/MHSEC-G/MHSEC-G.csproj index 75bc4dd..1915125 100644 --- a/MHSEC-G/MHSEC-G/MHSEC-G.csproj +++ b/MHSEC-G/MHSEC-G/MHSEC-G.csproj @@ -33,6 +33,24 @@ prompt 4 + + true + bin\x86\Debug\ + DEBUG;TRACE + full + x86 + prompt + MinimumRecommendedRules.ruleset + + + bin\x86\Release\ + TRACE + true + pdbonly + x86 + prompt + MinimumRecommendedRules.ruleset + diff --git a/MHSEC-G/MHSEC-G/MainWindow.xaml b/MHSEC-G/MHSEC-G/MainWindow.xaml index cd124a5..83d7b50 100644 --- a/MHSEC-G/MHSEC-G/MainWindow.xaml +++ b/MHSEC-G/MHSEC-G/MainWindow.xaml @@ -25,7 +25,35 @@ - + + + + + + + + + + + + + +