diff --git a/.gitignore b/.gitignore index 1c9a181..eb1a1f9 100644 --- a/.gitignore +++ b/.gitignore @@ -240,3 +240,4 @@ ModelManifest.xml # FAKE - F# Make .fake/ +MHSEC-G/.idea/ diff --git a/MHSEC-G/MHSEC-G/Armor.cs b/MHSEC-G/MHSEC-G/Armor.cs index 506ab08..e74cc22 100644 --- a/MHSEC-G/MHSEC-G/Armor.cs +++ b/MHSEC-G/MHSEC-G/Armor.cs @@ -9,7 +9,7 @@ using MHSEC_G.Annotations; namespace MHSEC_G { - internal class Armor : INotifyPropertyChanged + public class Armor : INotifyPropertyChanged { private const uint OFFSETA_ARM = 0x55F0; private const uint OFFSETA_ARM_END = 0x720E; @@ -23,6 +23,7 @@ namespace MHSEC_G private readonly uint _offset; private readonly Model _model; + public uint index => (_offset - OFFSETA_ARM) / SIZE_ARM + 1; public Armor(Model model, uint offset) { @@ -80,7 +81,7 @@ namespace MHSEC_G uint parsed; if (Model.parse_hex_string(value, out parsed)) { - Model.write_uint16_le(_model.save_file, _offset + OFFSETR_ARM_14h, parsed); + Model.write_uint32_le(_model.save_file, _offset + OFFSETR_ARM_14h, parsed); } else { @@ -141,10 +142,6 @@ namespace MHSEC_G ObservableCollection ret = new ObservableCollection(); for (uint i = OFFSETA_ARM; i < OFFSETA_ARM_END; i += SIZE_ARM) { - if (Model.byte_to_uint16_le(model.save_file, i) == 0x7FFF) - { - continue; - } ret.Add(new Armor(model, i)); } return ret; diff --git a/MHSEC-G/MHSEC-G/Character.cs b/MHSEC-G/MHSEC-G/Character.cs index a96cc14..aa0de25 100644 --- a/MHSEC-G/MHSEC-G/Character.cs +++ b/MHSEC-G/MHSEC-G/Character.cs @@ -4,7 +4,7 @@ using MHSEC_G.Annotations; namespace MHSEC_G { - internal class Character : INotifyPropertyChanged + public class Character : INotifyPropertyChanged { private const uint OFFSETA_CHAR_NAME = 0x9DA0; private const uint LENGTH_CHAR_NAME = 6; diff --git a/MHSEC-G/MHSEC-G/Egg.cs b/MHSEC-G/MHSEC-G/Egg.cs index c5d1f44..4509675 100644 --- a/MHSEC-G/MHSEC-G/Egg.cs +++ b/MHSEC-G/MHSEC-G/Egg.cs @@ -1,34 +1,35 @@ 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 { - internal class Egg : INotifyPropertyChanged + public class Egg : INotifyPropertyChanged { private const int OFFSETA_EGG_START = 0x53EC0; - private const int OFFSETA_EGG_END = 0x54505; - // 200 weapons + 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 Egg(Model model, uint offset) { _offset = offset; _model = model; + _genes = new Genes(model, offset + OFFSETR_EGG_GENE, SIZE_EGG_GENE); } - public string spe { set @@ -76,15 +77,18 @@ namespace MHSEC_G ObservableCollection ret = new ObservableCollection(); for (uint i = OFFSETA_EGG_START; i < OFFSETA_EGG_END; i += SIZE_EGG) { - if (Model.byte_to_uint(model.save_file[i + OFFSETR_SPE]) == 0xFF) - { - continue; - } 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] diff --git a/MHSEC-G/MHSEC-G/EggFragment.cs b/MHSEC-G/MHSEC-G/EggFragment.cs index 5b0b891..a3fa51e 100644 --- a/MHSEC-G/MHSEC-G/EggFragment.cs +++ b/MHSEC-G/MHSEC-G/EggFragment.cs @@ -6,7 +6,7 @@ using MHSEC_G.Annotations; namespace MHSEC_G { - internal class EggFragment : INotifyPropertyChanged + public class EggFragment : INotifyPropertyChanged { private const uint OFFSETA_EGG_FRAGMENTS = 0x9790; private const uint OFFSETA_EGG_FRAGMENTS_END = 0x9C3F; @@ -21,6 +21,7 @@ namespace MHSEC_G private const uint OFFSETR_EF_7H = 0x7; private readonly uint _offset; + public uint idx => (_offset - OFFSETA_EGG_FRAGMENTS) / SIZE_EGG_FRAGMENT + 1; public uint offset { @@ -182,8 +183,6 @@ namespace MHSEC_G 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; @@ -218,7 +217,6 @@ namespace MHSEC_G each_frag.dlc = dlc.ToString("X2"); each_frag.unknown_6h = "0"; each_frag.unknown_7h = "0"; - } } diff --git a/MHSEC-G/MHSEC-G/GeneWindow.xaml b/MHSEC-G/MHSEC-G/GeneWindow.xaml new file mode 100644 index 0000000..aa88297 --- /dev/null +++ b/MHSEC-G/MHSEC-G/GeneWindow.xaml @@ -0,0 +1,72 @@ + + + + + + + diff --git a/MHSEC-G/MHSEC-G/GeneWindow.xaml.cs b/MHSEC-G/MHSEC-G/GeneWindow.xaml.cs new file mode 100644 index 0000000..bde8934 --- /dev/null +++ b/MHSEC-G/MHSEC-G/GeneWindow.xaml.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Shapes; +using MHSEC_G.Annotations; + +namespace MHSEC_G +{ + /// + /// Interaction logic for GeneWindow.xaml + /// + public partial class GeneWindow : Window, INotifyPropertyChanged + { + private readonly Genes _genes; + public Genes genes => _genes; + + public GeneWindow(Genes genes) + { + this._genes = genes; + DataContext = this; + InitializeComponent(); + } + + 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 new file mode 100644 index 0000000..402ccd5 --- /dev/null +++ b/MHSEC-G/MHSEC-G/Genes.cs @@ -0,0 +1,334 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.IO; +using System.Linq; +using System.Text; +using System.Windows; +using MHSEC_G.Annotations; + +namespace MHSEC_G +{ + public class Genes : INotifyPropertyChanged + { + 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) + { + this._size = size; + this._offset = offset; + this._model = model; + } + + // + // 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); + } + + private void set_gene_str(uint gene_idx, string val) + { + uint parsed; + if (Model.parse_hex_string(val, out parsed)) + { + set_gene(gene_idx, parsed); + } + else + { + MessageBox.Show("Malformed gene value - must be 0x0 to 0xFFFF.", "Error", MessageBoxButton.OK, + MessageBoxImage.Error); + } + } + + private void set_gene(uint gene_idx, uint val) + { + if (gene_idx >= 9) + { + BugCheck.bug_check(BugCheck.ErrorCode.MON_GENE_IDX_OVERFLOW, "Invalid gene index: " + gene_idx); + } + if (val <= 0xFFFF) + { + Model.write_uint16_le(_model.save_file, _offset + gene_idx * _size, + val); + } + else + { + MessageBox.Show("Malformed gene value - must be 0x0 to 0xFFFF.", "Error", MessageBoxButton.OK, + MessageBoxImage.Error); + } + } + + private int extract_gene_idx(uint gene_idx) + { + uint gene_id = extract_gene(gene_idx); + int idx = GENE_ID.IndexOf(gene_id); + if (idx == -1) + { + // unknown + return GENE_NAME.Count - 1; + } + return idx; + } + + private void set_gene_idx(uint gene_idx, int val) + { + if (val != -1 && val != GENE_NAME.Count - 1) + { + set_gene(gene_idx, GENE_ID.ElementAt(val)); + } + } + + public int gene1_selected + { + get => extract_gene_idx(0); + set + { + set_gene_idx(0, value); + OnPropertyChanged(nameof(gene1)); + OnPropertyChanged(nameof(gene1_selected)); + } + } + + public string gene1 + { + get => extract_gene(0).ToString("X4"); + set + { + set_gene_str(0, value); + OnPropertyChanged(nameof(gene1)); + OnPropertyChanged(nameof(gene1_selected)); + } + } + + public int gene2_selected + { + get => extract_gene_idx(1); + set + { + set_gene_idx(1, value); + OnPropertyChanged(nameof(gene2)); + OnPropertyChanged(nameof(gene2_selected)); + } + } + + public string gene2 + { + get => extract_gene(1).ToString("X4"); + set + { + set_gene_str(1, value); + OnPropertyChanged(nameof(gene2)); + OnPropertyChanged(nameof(gene2_selected)); + } + } + + public int gene3_selected + { + get => extract_gene_idx(2); + set + { + set_gene_idx(2, value); + OnPropertyChanged(nameof(gene3)); + OnPropertyChanged(nameof(gene3_selected)); + } + } + + + public string gene3 + { + get => extract_gene(2).ToString("X4"); + set + { + set_gene_str(2, value); + OnPropertyChanged(nameof(gene3)); + OnPropertyChanged(nameof(gene3_selected)); + } + } + + public int gene4_selected + { + get => extract_gene_idx(3); + set + { + set_gene_idx(3, value); + OnPropertyChanged(nameof(gene4)); + OnPropertyChanged(nameof(gene4_selected)); + } + } + + + public string gene4 + { + get => extract_gene(3).ToString("X4"); + set + { + set_gene_str(3, value); + OnPropertyChanged(nameof(gene4)); + OnPropertyChanged(nameof(gene4_selected)); + } + } + + public int gene5_selected + { + get => extract_gene_idx(4); + set + { + set_gene_idx(4, value); + OnPropertyChanged(nameof(gene5)); + OnPropertyChanged(nameof(gene5_selected)); + } + } + + + public string gene5 + { + get => extract_gene(4).ToString("X4"); + set + { + set_gene_str(4, value); + OnPropertyChanged(nameof(gene5)); + OnPropertyChanged(nameof(gene5_selected)); + } + } + + public int gene6_selected + { + get => extract_gene_idx(5); + set + { + set_gene_idx(5, value); + OnPropertyChanged(nameof(gene6)); + OnPropertyChanged(nameof(gene6_selected)); + } + } + + + public string gene6 + { + get => extract_gene(5).ToString("X4"); + set + { + set_gene_str(5, value); + OnPropertyChanged(nameof(gene6)); + OnPropertyChanged(nameof(gene6_selected)); + } + } + + + public int gene7_selected + { + get => extract_gene_idx(6); + set + { + set_gene_idx(6, value); + OnPropertyChanged(nameof(gene7)); + OnPropertyChanged(nameof(gene7_selected)); + } + } + + + public string gene7 + { + get => extract_gene(6).ToString("X4"); + set + { + set_gene_str(6, value); + OnPropertyChanged(nameof(gene7)); + OnPropertyChanged(nameof(gene7_selected)); + } + } + + + public int gene8_selected + { + get => extract_gene_idx(7); + set + { + set_gene_idx(7, value); + OnPropertyChanged(nameof(gene8)); + OnPropertyChanged(nameof(gene8_selected)); + } + } + + + public string gene8 + { + get => extract_gene(7).ToString("X4"); + set + { + set_gene_str(7, value); + OnPropertyChanged(nameof(gene8)); + OnPropertyChanged(nameof(gene8_selected)); + } + } + + + public int gene9_selected + { + get => extract_gene_idx(8); + set + { + set_gene_idx(8, value); + OnPropertyChanged(nameof(gene9)); + OnPropertyChanged(nameof(gene9_selected)); + } + } + + public string gene9 + { + get => extract_gene(8).ToString("X4"); + set + { + set_gene_str(8, value); + OnPropertyChanged(nameof(gene9)); + 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/Item.cs b/MHSEC-G/MHSEC-G/Item.cs index b0dc899..2d7b94f 100644 --- a/MHSEC-G/MHSEC-G/Item.cs +++ b/MHSEC-G/MHSEC-G/Item.cs @@ -8,7 +8,7 @@ using MHSEC_G.Annotations; namespace MHSEC_G { - internal class Item : INotifyPropertyChanged + public class Item : INotifyPropertyChanged { private static readonly uint OFFSETA_ITEM_BOX = 0x10; private static readonly uint SIZE_ITEM = 0x8; diff --git a/MHSEC-G/MHSEC-G/MHSEC-G.csproj b/MHSEC-G/MHSEC-G/MHSEC-G.csproj index 2261a78..49de7eb 100644 --- a/MHSEC-G/MHSEC-G/MHSEC-G.csproj +++ b/MHSEC-G/MHSEC-G/MHSEC-G.csproj @@ -86,9 +86,16 @@ + + + GeneWindow.xaml + + + MonsterWindow.xaml + True @@ -96,8 +103,11 @@ Resources.resx - + + Designer + MSBuild:Compile + MSBuild:Compile Designer @@ -110,6 +120,10 @@ MainWindow.xaml Code + + Designer + MSBuild:Compile + @@ -133,6 +147,8 @@ Settings.Designer.cs + + diff --git a/MHSEC-G/MHSEC-G/MainWindow.xaml b/MHSEC-G/MHSEC-G/MainWindow.xaml index 0ff522b..cfedb15 100644 --- a/MHSEC-G/MHSEC-G/MainWindow.xaml +++ b/MHSEC-G/MHSEC-G/MainWindow.xaml @@ -5,38 +5,42 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:MHSEC_G" mc:Ignorable="d" - Title="" Height="447.855" Width="810.218" ResizeMode="NoResize" Icon="Resources/MainIcon.ico"> - + Title="" Height="447.855" Width="474.968" ResizeMode="NoResize" Icon="Resources/MainIcon.ico"> + - - + + -