diff --git a/MHSEC-G/MHSEC-G/BugCheck.cs b/MHSEC-G/MHSEC-G/BugCheck.cs index c0e3dd8..fb1b649 100644 --- a/MHSEC-G/MHSEC-G/BugCheck.cs +++ b/MHSEC-G/MHSEC-G/BugCheck.cs @@ -22,8 +22,7 @@ namespace MHSEC_G // Faciltiy Item ITEM_NO_CORRESPONDENCE = 0x21, - ITEM_MAPPING_CORRUPTED = 0x22, - ITEM_MAPPING_DNE = 0x23, + ITEM_MAPPING_CORRUPTED = 0x22 } public static void bug_check(ErrorCode error_code, string error_message) diff --git a/MHSEC-G/MHSEC-G/Item.cs b/MHSEC-G/MHSEC-G/Item.cs index bdd746f..53397c4 100644 --- a/MHSEC-G/MHSEC-G/Item.cs +++ b/MHSEC-G/MHSEC-G/Item.cs @@ -27,12 +27,13 @@ namespace MHSEC_G { get { return _offset; } } + private readonly Model _model; public string name { get { - string name = "Unknown"; + string name = _offset >= OFFSETA_FIRST_KEY_ITEM ? "Key Item [" + id.ToString("X4") + "]" : "Unknown"; if (OFFSET_NAME_MAPPING.ContainsKey(_offset)) { name = OFFSET_NAME_MAPPING[_offset]; @@ -76,9 +77,7 @@ namespace MHSEC_G List ret = new List(); for (uint offset = OFFSETA_ITEM_BOX; offset < OFFSETA_ITEM_BOX_END; offset += SIZE_ITEM) { - string name = "Unknown"; uint item_id = Model.byte_to_uint16_le(buffer, offset + OFFSETR_ITEM_ID); - if (item_id == 0) { // if not obtained yet @@ -88,7 +87,8 @@ namespace MHSEC_G // 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]); } else { @@ -99,7 +99,8 @@ namespace MHSEC_G if (item_id != OFFSET_ID_MAPPING[offset]) { // correct to the correct id - // BugCheck.bug_check(BugCheck.ErrorCode.ITEM_NO_CORRESPONDENCE, "Item offset " + offset.ToString("X") + " and item ID " + item_id.ToString("X") + " do not correspond."); + // 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]); } } @@ -113,15 +114,8 @@ namespace MHSEC_G public static void read_item_mappings() { string line; - System.IO.StreamReader file = null; + StringReader file = new StringReader(Properties.Resources.idmap); - if (!File.Exists(ID_MAPPING_FILE_NAME)) - { - BugCheck.bug_check(BugCheck.ErrorCode.ITEM_MAPPING_DNE, - "Cannot find mapping file " + ID_MAPPING_FILE_NAME); - } - - file = new System.IO.StreamReader(ID_MAPPING_FILE_NAME); while ((line = file.ReadLine()) != null) { if (line.Length == 0) @@ -130,11 +124,12 @@ namespace MHSEC_G 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(UInt32.Parse(eachline[0], System.Globalization.NumberStyles.HexNumber), UInt32.Parse(eachline[1], System.Globalization.NumberStyles.HexNumber)); - OFFSET_NAME_MAPPING.Add(UInt32.Parse(eachline[0], System.Globalization.NumberStyles.HexNumber), eachline[2]); + 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(); diff --git a/MHSEC-G/MHSEC-G/MHSEC-G.csproj b/MHSEC-G/MHSEC-G/MHSEC-G.csproj index 3a1de4d..fd27e9a 100644 --- a/MHSEC-G/MHSEC-G/MHSEC-G.csproj +++ b/MHSEC-G/MHSEC-G/MHSEC-G.csproj @@ -51,9 +51,13 @@ 4 false + + Resources\MainIcon.ico + + @@ -79,6 +83,12 @@ + + True + True + Resources.resx + + MSBuild:Compile @@ -97,11 +107,6 @@ Code - - True - True - Resources.resx - True Settings.settings @@ -109,18 +114,21 @@ ResXFileCodeGenerator - Resources.Designer.cs Designer + Resources.Designer.cs - + + Designer + SettingsSingleFileGenerator Settings.Designer.cs + - + @@ -139,6 +147,9 @@ true + + + + @@ -68,9 +69,10 @@ - + + @@ -85,9 +87,10 @@ - + + @@ -109,9 +112,19 @@ 2.0 - System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + ..\Resources\idmap.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-16 + + + ..\Resources\MainIcon.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\monster_null_template.bin;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + \ No newline at end of file diff --git a/MHSEC-G/MHSEC-G/Resources/MainIcon.ico b/MHSEC-G/MHSEC-G/Resources/MainIcon.ico new file mode 100644 index 0000000..7be4251 Binary files /dev/null and b/MHSEC-G/MHSEC-G/Resources/MainIcon.ico differ diff --git a/MHSEC-G/MHSEC-G/Resources/idmap.txt b/MHSEC-G/MHSEC-G/Resources/idmap.txt new file mode 100644 index 0000000..765cfcd Binary files /dev/null and b/MHSEC-G/MHSEC-G/Resources/idmap.txt differ diff --git a/MHSEC-G/MHSEC-G/Resources/monster_null_template.bin b/MHSEC-G/MHSEC-G/Resources/monster_null_template.bin new file mode 100644 index 0000000..65e09a1 Binary files /dev/null and b/MHSEC-G/MHSEC-G/Resources/monster_null_template.bin differ diff --git a/MHSEC-G/MHSEC-G/Talisman.cs b/MHSEC-G/MHSEC-G/Talisman.cs new file mode 100644 index 0000000..0a14ec9 --- /dev/null +++ b/MHSEC-G/MHSEC-G/Talisman.cs @@ -0,0 +1,230 @@ +using System.ComponentModel; + +namespace MHSEC_G +{ + public class Talisman + { +// 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/idmap.txt b/MHSEC-G/MHSEC-G/idmap.txt deleted file mode 100644 index 8a75084..0000000 Binary files a/MHSEC-G/MHSEC-G/idmap.txt and /dev/null differ