Finally getting used to how WFP and MVVM work. Now it can load file and display character information. The progress is steady.

This commit is contained in:
secXsQuared1995 2016-10-18 02:56:06 -04:00
parent 99dfb772cd
commit 7ae1cde029
11 changed files with 1262 additions and 50 deletions

View File

@ -0,0 +1,2 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/CodeInspection/CodeAnnotations/NamespacesWithAnnotations/=MHSEC_005FG_002EAnnotations/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>

View File

@ -0,0 +1,59 @@
using System.ComponentModel;
using MHSEC_G.Annotations;
namespace MHSEC_G
{
public class Character : INotifyPropertyChanged
{
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;
private uint _char_level;
public uint char_level
{
get { return _char_level; }
set { _char_level = value; OnPropertyChanged(nameof(char_level)); }
}
private uint _char_exp;
public uint char_exp
{
get { return _char_exp; }
set { _char_exp = value; OnPropertyChanged(nameof(char_exp)); }
}
private uint _char_money;
public uint char_money
{
get { return _char_money; }
set { _char_money = value; OnPropertyChanged(nameof(char_money)); }
}
private string _char_name;
public string char_name
{
get { return _char_name; }
set { _char_name = value; OnPropertyChanged(nameof(char_name)); }
}
public Character(byte[] save_data)
{
_char_level = Model.byte_to_uint(save_data[OFFSETA_CHAR_LEVEL]);
_char_exp = Model.byte_to_uint32_le(save_data, OFFSETA_CHAR_EXP);
_char_money = Model.byte_to_uint32_le(save_data, OFFSETA_CHAR_MONEY);
_char_name = Model.read_unicode_string(save_data, OFFSETA_CHAR_NAME, LENGTH_CHAR_NAME);
}
public event PropertyChangedEventHandler PropertyChanged;
[NotifyPropertyChangedInvocator]
protected virtual void OnPropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
}

View File

@ -2,12 +2,10 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MHSEC_G
{
public interface View
class EggFragment
{
void update();
}
}

11
MHSEC-G/MHSEC-G/Item.cs Normal file
View File

@ -0,0 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace MHSEC_G
{
class Item
{
}
}

View File

@ -36,6 +36,7 @@
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Core" />
@ -53,8 +54,13 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</ApplicationDefinition>
<Compile Include="Character.cs" />
<Compile Include="EggFragment.cs" />
<Compile Include="Item.cs" />
<Compile Include="Model.cs" />
<Compile Include="View.cs" />
<Compile Include="Monster.cs" />
<Compile Include="Properties\Annotations.cs" />
<Compile Include="ViewModel.cs" />
<Page Include="MainWindow.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>

View File

@ -15,10 +15,10 @@
<Label x:Name="label_money" Content="Money" HorizontalAlignment="Left" Margin="10,40,0,0" VerticalAlignment="Top"/>
<Label x:Name="label_leve" Content="Level" HorizontalAlignment="Left" Margin="10,70,0,0" VerticalAlignment="Top"/>
<Label x:Name="label_exp" Content="Exp" HorizontalAlignment="Left" Margin="10,100,0,0" VerticalAlignment="Top"/>
<TextBox x:Name="textbox_name" HorizontalAlignment="Left" Height="22" Margin="61,14,0,0" TextWrapping="NoWrap" VerticalAlignment="Top" Width="120"/>
<TextBox x:Name="textbox_money" HorizontalAlignment="Left" Height="22" Margin="61,44,0,0" TextWrapping="NoWrap" VerticalAlignment="Top" Width="120"/>
<TextBox x:Name="textbox_level" HorizontalAlignment="Left" Height="22" Margin="61,74,0,0" TextWrapping="NoWrap" VerticalAlignment="Top" Width="120"/>
<TextBox x:Name="textbox_exp" HorizontalAlignment="Left" Height="22" Margin="61,104,0,0" TextWrapping="NoWrap" VerticalAlignment="Top" Width="120"/>
<TextBox x:Name="textbox_name" HorizontalAlignment="Left" Height="22" Margin="61,14,0,0" TextWrapping="NoWrap" VerticalAlignment="Top" Width="120" Text="{Binding model.character.char_name}"/>
<TextBox x:Name="textbox_money" HorizontalAlignment="Left" Height="22" Margin="61,44,0,0" TextWrapping="NoWrap" VerticalAlignment="Top" Width="120" Text="{Binding model.character.char_money}"/>
<TextBox x:Name="textbox_level" HorizontalAlignment="Left" Height="22" Margin="61,74,0,0" TextWrapping="NoWrap" VerticalAlignment="Top" Width="120" Text="{Binding model.character.char_level}"/>
<TextBox x:Name="textbox_exp" HorizontalAlignment="Left" Height="22" Margin="61,104,0,0" TextWrapping="NoWrap" VerticalAlignment="Top" Width="120" Text="{Binding model.character.char_exp}"/>
</Grid>
</TabItem>
<TabItem Header="Monsters">

View File

@ -1,39 +1,43 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
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.Navigation;
using System.Windows.Shapes;
using System.Windows.Forms;
namespace MHSEC_G
{
public partial class MainWindow : Window
{
private readonly byte[] dummy_data = new byte[Model.SAVE_FILE_SIZE];
private const string Version = "0.1";
public MainWindow()
{
InitializeComponent();
Array.Clear(dummy_data, 0, dummy_data.Length);
this.Title = "MHSEC-G Ver" + Version;
DataContext = new ViewModel(dummy_data);
}
private void button_load_click(object sender, RoutedEventArgs e)
{
// if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
// {
// System.IO.StreamReader sr = new
// System.IO.StreamReader(openFileDialog1.FileName);
// MessageBox.Show(sr.ReadToEnd());
// sr.Close();
// }
OpenFileDialog dialog = new OpenFileDialog();
dialog.Filter = "MHST Save files|mhr_game0.sav|sav files (*.sav)|*.sav|All files (*.*)|*.*";
dialog.Title = "Please select your save file.";
if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
byte[] buffer = File.ReadAllBytes(dialog.FileName);
if (buffer.Length != Model.SAVE_FILE_SIZE)
{
System.Windows.Forms.MessageBox.Show(
"Wrong save file size! Expected: " + Model.SAVE_FILE_SIZE + ".",
"Error",
MessageBoxButtons.OK,
MessageBoxIcon.Asterisk);
}
else
{
DataContext = new ViewModel(buffer);
}
}
}
}
}

View File

@ -1,51 +1,109 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Dynamic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MHSEC_G.Annotations;
namespace MHSEC_G
{
public class Model
{
public const uint SAVE_FILE_SIZE = 483976;
private readonly byte[] save_file;
private readonly List<View> views;
public Model(byte[] save_file)
private readonly Character _character;
public Character character
{
this.save_file = save_file;
views = new List<View>();
get { return _character; }
}
public byte[] read()
{
byte[] ret = new byte[save_file.Length];
Array.Copy(save_file, ret, save_file.Length);
return ret;
}
private uint cur_monster_selection;
private readonly List<Monster> monsters;
public void write(int offset, byte[] val)
{
private readonly List<Item> items;
notify_view();
}
private void notify_view()
private uint cur_egg_fragment_selection;
private readonly List<EggFragment> egg_fragments;
public Model(byte[] save)
{
for(int i = 0; i < views.Count; i++)
if (save == null || save.Length != SAVE_FILE_SIZE)
{
views.ElementAt(i).update();
throw new SystemException("Invalid save file size.");
}
save_file = save;
_character = new Character(save_file);
cur_monster_selection = 0;
monsters = null;
items = null;
cur_egg_fragment_selection = 0;
egg_fragments = null;
}
public void register_view(View view)
public static uint byte_to_uint(byte b)
{
views.Add(view);
return (uint) (b) & 0xFF;
}
public void deregister_view(View view)
public static uint byte_to_uint16_le(byte[] arr, uint offset)
{
views.Remove(view);
if (arr.Length < offset + 2)
throw new SystemException("Buffer overflowed - Offset " + offset);
return byte_to_uint(arr[offset]) | (byte_to_uint(arr[offset + 1]) << 8);
}
public static void write_uint16_le(byte[] arr, uint offset, uint val)
{
if (arr.Length < offset + 2)
throw new SystemException("Buffer overflowed - Offset " + offset);
arr[offset] = (byte) (val & 0xFF);
arr[offset + 1] = (byte) ((val >> 8) & 0xFF);
}
public static uint byte_to_uint32_le(byte[] arr, uint offset)
{
if (arr.Length < offset + 4)
throw new SystemException("Buffer overflowed - Offset " + offset);
return byte_to_uint(arr[offset]) | (byte_to_uint(arr[offset + 1]) << 8) |
(byte_to_uint(arr[offset + 2]) << 16) | (byte_to_uint(arr[offset + 3]) << 24);
}
public static void write_uint32_le(byte[] arr, uint offset, uint val)
{
if (arr.Length < offset + 4)
throw new SystemException("Buffer overflowed - Offset " + offset);
arr[offset] = (byte) (val & 0xFF);
arr[offset + 1] = (byte) ((val >> 8) & 0xFF);
arr[offset + 2] = (byte) ((val >> 16) & 0xFF);
arr[offset + 3] = (byte) ((val >> 24) & 0xFF);
}
public static string read_unicode_string(byte[] arr, uint offset, uint max_char)
{
StringBuilder name = new StringBuilder();
uint read_char = 0;
for (uint i = offset; i < arr.Length; i += 2)
{
if (read_char < max_char)
{
uint each_char = byte_to_uint16_le(arr, i);
if (each_char == 0)
break;
name.Append(Convert.ToChar(each_char));
read_char++;
}
else
{
break;
}
}
return name.ToString();
}
}
}

View File

@ -0,0 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace MHSEC_G
{
class Monster
{
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace MHSEC_G
{
public class ViewModel
{
private Model _model;
public Model model
{
get { return _model; }
set { _model = model; }
}
public ViewModel(byte[] data)
{
_model = new Model(data);
}
}
}