Skip to content

Commit

Permalink
Ver 1.10. Supports both JPN and USA/EUR version.
Browse files Browse the repository at this point in the history
  • Loading branch information
quackerd committed Sep 10, 2017
1 parent 50f3367 commit 3588806
Show file tree
Hide file tree
Showing 19 changed files with 918 additions and 608 deletions.
87 changes: 43 additions & 44 deletions MHSEC-G/MHSEC-G/Armor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,39 +6,48 @@
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(byte[] save, uint objOffset) : base(save, objOffset, Offsets.SIZE_ARM)
{

}

public Armor(Model model, uint offset)
public string type
{
_offset = offset;
_model = model;
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
{
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
{
Expand All @@ -48,7 +57,7 @@ public string id
}
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");
}
}

Expand All @@ -57,9 +66,9 @@ public string level
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
{
Expand All @@ -69,7 +78,7 @@ public string level
}
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");
}
}

Expand All @@ -79,9 +88,9 @@ public string unknown_14h
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
{
Expand All @@ -91,7 +100,7 @@ public string unknown_14h
}
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");
}
}

Expand All @@ -100,9 +109,9 @@ public string unknown_18h
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
{
Expand All @@ -112,7 +121,7 @@ public string unknown_18h
}
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");
}
}

Expand All @@ -121,9 +130,9 @@ public string unknown_1ch
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
{
Expand All @@ -133,28 +142,18 @@ public string unknown_1ch
}
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<Armor> read_all_armors(Model model)
public static ObservableCollection<Armor> read_all_armors(byte[] save)
{
ObservableCollection<Armor> ret = new ObservableCollection<Armor>();
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));
}
}


}
62 changes: 26 additions & 36 deletions MHSEC-G/MHSEC-G/Character.cs
Original file line number Diff line number Diff line change
@@ -1,102 +1,92 @@
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));
}
}

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));
}
}

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));
}
}

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()
{
throw new NotImplementedException();
}
public override void setByteArray(byte[] data)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
throw new NotImplementedException();
}
}
}
Loading

0 comments on commit 3588806

Please sign in to comment.