1. Better bug check

2. Fixed a mistyped ID-Item mapping
This commit is contained in:
secXsQuared1995 2016-10-19 19:30:55 -04:00
parent ea35663332
commit a684fea1af
13 changed files with 165 additions and 84 deletions

View File

@ -17,12 +17,12 @@ Global
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}.Debug|x86.ActiveCfg = Debug|Any CPU
{80372081-2D34-424B-93E2-89D5815BF3E8}.Debug|x86.Build.0 = Debug|Any CPU
{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
{80372081-2D34-424B-93E2-89D5815BF3E8}.Release|x86.ActiveCfg = Release|Any CPU
{80372081-2D34-424B-93E2-89D5815BF3E8}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

@ -0,0 +1,40 @@
using System;
using System.Windows;
namespace MHSEC_G
{
public class BugCheck
{
public enum ErrorCode
{
// Facility Model
MODEL_INVALID_FILE_SIZE = 0x1,
MODEL_READ_BYTE_OVERFLOW = 0x2,
MODEL_WRITE_BYTE_OVERFLOW = 0x3,
MODEL_READ_UINT16_OVERFLOW = 0x4,
MODEL_WRITE_UINT16_OVERFLOW = 0x5,
MODEL_READ_UINT32_OVERFLOW = 0x6,
MODEL_WRITE_UINT32_OVERFLOW = 0x7,
MODEL_WRITE_UNICODE_OVERFLOW = 0x8,
// Faciltiy ViewModel
VIEWMODEL_NULL_SAVE = 0x11,
// Faciltiy Item
ITEM_NO_CORRESPONDENCE = 0x21,
ITEM_MAPPING_CORRUPTED = 0x22,
ITEM_MAPPING_DNE = 0x23,
}
public static void bug_check(ErrorCode error_code, string error_message)
{
MessageBoxResult result = MessageBox.Show("Error code: 0x" + ((int)error_code).ToString("X4") + "\nMessage: " + error_message, "MHSEC-G Bug Check",
MessageBoxButton.OK, MessageBoxImage.Stop);
if (result == MessageBoxResult.OK)
{
System.Windows.Forms.Application.Exit();
}
Environment.Exit((int)error_code);
}
}
}

View File

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Windows;
using MHSEC_G.Annotations;
@ -14,12 +15,18 @@ namespace MHSEC_G
private static readonly uint OFFSETR_ITEM_ID = 0x0;
private static readonly uint OFFSETR_ITEM_COUNT = 0x2;
private static readonly uint OFFSETA_ITEM_BOX_END = 0x2EE7;
public static readonly uint OFFSETA_FIRST_KEY_ITEM = 0x17B0;
private static readonly string ID_MAPPING_FILE_NAME = "idmap.txt";
private static readonly Dictionary<uint, uint> OFFSET_ID_MAPPING = new Dictionary<uint, uint>();
private static readonly Dictionary<uint, string> OFFSET_NAME_MAPPING = new Dictionary<uint, string>();
private readonly uint _offset;
public uint offset
{
get { return _offset; }
}
private readonly Model _model;
public string name
@ -91,7 +98,9 @@ namespace MHSEC_G
{
if (item_id != OFFSET_ID_MAPPING[offset])
{
throw new SystemException("Item offset and ID do not correspond.");
// 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.");
Model.write_uint16_le(model.save_file, offset + OFFSETR_ITEM_ID, OFFSET_ID_MAPPING[offset]);
}
}
}
@ -104,7 +113,15 @@ namespace MHSEC_G
public static void read_item_mappings()
{
string line;
System.IO.StreamReader file = new System.IO.StreamReader(ID_MAPPING_FILE_NAME);
System.IO.StreamReader file = null;
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)
@ -112,7 +129,9 @@ namespace MHSEC_G
string[] eachline = line.Split('\t');
if (eachline.Length != 3)
throw new SystemException("Item mapping file is corrupted.");
{
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]);

View File

@ -13,6 +13,22 @@
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<WarningLevel>4</WarningLevel>
<PublishUrl>publish\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
<UpdateEnabled>false</UpdateEnabled>
<UpdateMode>Foreground</UpdateMode>
<UpdateInterval>7</UpdateInterval>
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
<UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
@ -23,6 +39,7 @@
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
@ -32,24 +49,7 @@
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x86\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>x86</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
<OutputPath>bin\x86\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x86</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
@ -72,6 +72,7 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</ApplicationDefinition>
<Compile Include="BugCheck.cs" />
<Compile Include="Character.cs" />
<Compile Include="EggFragment.cs" />
<Compile Include="Item.cs" />
@ -109,7 +110,9 @@
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
<SubType>Designer</SubType>
</EmbeddedResource>
<None Include="app.config" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
@ -119,6 +122,23 @@
<ItemGroup>
<Resource Include="idmap.txt" />
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include=".NETFramework,Version=v4.0">
<Visible>False</Visible>
<ProductName>Microsoft .NET Framework 4 %28x86 and x64%29</ProductName>
<Install>true</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1</ProductName>
<Install>false</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Windows.Installer.4.5">
<Visible>False</Visible>
<ProductName>Windows Installer 4.5</ProductName>
<Install>true</Install>
</BootstrapperPackage>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.

View File

@ -12,7 +12,7 @@ namespace MHSEC_G
{
private ViewModel view_model;
private readonly byte[] dummy_data = new byte[Model.SAVE_FILE_SIZE];
private const string Version = "0.1";
private const string Version = "0.11";
public MainWindow()
{
InitializeComponent();
@ -35,10 +35,10 @@ namespace MHSEC_G
if (buffer.Length != Model.SAVE_FILE_SIZE)
{
System.Windows.Forms.MessageBox.Show(
"Wrong save file size! Expected: " + Model.SAVE_FILE_SIZE + ".",
"Wrong save file size! Expected: " + Model.SAVE_FILE_SIZE + " Got: " + buffer.Length,
"Error",
MessageBoxButtons.OK,
MessageBoxIcon.Asterisk);
MessageBoxIcon.Error);
}
else
{
@ -64,7 +64,7 @@ namespace MHSEC_G
List<Item> items = view_model.items;
for (uint i = 0; i < items.Count; i++)
{
if (items.ElementAt((int)i).id == 1227)
if (items.ElementAt((int)i).offset >= Item.OFFSETA_FIRST_KEY_ITEM)
break;
items.ElementAt((int)i).count = 986;
@ -76,7 +76,7 @@ namespace MHSEC_G
List<Item> items = view_model.items;
for (uint i = 0; i < items.Count; i++)
{
if (items.ElementAt((int) i).id == 1227)
if (items.ElementAt((int)i).offset >= Item.OFFSETA_FIRST_KEY_ITEM)
break;
if (items.ElementAt((int)i).count != 0)

View File

@ -17,8 +17,10 @@ namespace MHSEC_G
public Model(byte[] save_file)
{
if(save_file.Length != SAVE_FILE_SIZE)
throw new SystemException("Invalid save file size.");
if (save_file.Length != SAVE_FILE_SIZE)
{
BugCheck.bug_check(BugCheck.ErrorCode.MODEL_INVALID_FILE_SIZE, "Invalid file size.\nExpected: " + SAVE_FILE_SIZE + " Got: " + save_file.Length);
}
_save_file = save_file;
}
@ -33,21 +35,25 @@ namespace MHSEC_G
arr[offset] = (byte)(val&0xFF);
else
{
throw new SystemException("Buffer overflowed - Offset " + offset);
BugCheck.bug_check(BugCheck.ErrorCode.MODEL_WRITE_BYTE_OVERFLOW, "Buffer overflowed.\nBound " + arr.Length + " Offset " + offset);
}
}
public static uint byte_to_uint16_le(byte[] arr, uint offset)
{
if (arr.Length < offset + 2)
throw new SystemException("Buffer overflowed - Offset " + offset);
{
BugCheck.bug_check(BugCheck.ErrorCode.MODEL_READ_UINT16_OVERFLOW, "Buffer overflowed.\nBound " + arr.Length + " 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);
{
BugCheck.bug_check(BugCheck.ErrorCode.MODEL_WRITE_UINT16_OVERFLOW, "Buffer overflowed.\nBound " + arr.Length + " Offset " + offset);
}
arr[offset] = (byte) (val & 0xFF);
arr[offset + 1] = (byte) ((val >> 8) & 0xFF);
}
@ -55,7 +61,9 @@ namespace MHSEC_G
public static uint byte_to_uint32_le(byte[] arr, uint offset)
{
if (arr.Length < offset + 4)
throw new SystemException("Buffer overflowed - Offset " + offset);
{
BugCheck.bug_check(BugCheck.ErrorCode.MODEL_READ_UINT32_OVERFLOW, "Buffer overflowed.\nBound " + arr.Length + " 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);
}
@ -63,7 +71,9 @@ namespace MHSEC_G
public static void write_uint32_le(byte[] arr, uint offset, uint val)
{
if (arr.Length < offset + 4)
throw new SystemException("Buffer overflowed - Offset " + offset);
{
BugCheck.bug_check(BugCheck.ErrorCode.MODEL_WRITE_UINT32_OVERFLOW, "Buffer overflowed.\nBound " + arr.Length + " Offset " + offset);
}
arr[offset] = (byte) (val & 0xFF);
arr[offset + 1] = (byte) ((val >> 8) & 0xFF);
arr[offset + 2] = (byte) ((val >> 16) & 0xFF);
@ -95,7 +105,9 @@ namespace MHSEC_G
public static void write_unicode_string(byte[] arr, uint offset, string str, uint length)
{
if (length < str.Length || arr.Length < offset + length)
throw new SystemException("Unicode string write - potential buffer overflow.");
{
BugCheck.bug_check(BugCheck.ErrorCode.MODEL_WRITE_UNICODE_OVERFLOW, "Buffer overflowed.\nBound " + arr.Length + " Offset " + offset);
}
Array.Clear(arr, (int) offset, (int)length*2);
for (uint i = 0; i < str.Length; i ++)

View File

@ -205,12 +205,12 @@ namespace MHSEC_G
public string name
{
get { return Model.read_unicode_string(_model.save_file, _offset + OFFSETR_MONSTER_NAME, 10); }
get { return Model.read_unicode_string(_model.save_file, _offset + OFFSETR_MONSTER_NAME, LIMIT_MONSTER_NAME); }
set
{
if (value.Length <= 10 && value.Length > 0)
{
Model.write_unicode_string(_model.save_file, _offset + OFFSETR_MONSTER_NAME, value, 10);
Model.write_unicode_string(_model.save_file, _offset + OFFSETR_MONSTER_NAME, value, LIMIT_MONSTER_NAME);
}
else
{

View File

@ -8,7 +8,7 @@ using System.Windows;
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("MHSEC-G")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyDescription("Monster Hunter Stories Save Editor")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("MHSEC-G")]
@ -51,5 +51,5 @@ using System.Windows;
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyVersion("0.1.1.0")]
[assembly: AssemblyFileVersion("0.1.1.0")]

View File

@ -8,10 +8,10 @@
// </auto-generated>
//------------------------------------------------------------------------------
namespace MHSEC_G.Properties
{
namespace MHSEC_G.Properties {
using System;
/// <summary>
/// A strongly-typed resource class, for looking up localized strings, etc.
/// </summary>
@ -22,48 +22,40 @@ namespace MHSEC_G.Properties
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources
{
internal class Resources {
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal Resources()
{
internal Resources() {
}
/// <summary>
/// Returns the cached ResourceManager instance used by this class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager
{
get
{
if ((resourceMan == null))
{
internal static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("MHSEC_G.Properties.Resources", typeof(Resources).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// Overrides the current thread's CurrentUICulture property for all
/// resource lookups using this strongly typed resource class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture
{
get
{
internal static global::System.Globalization.CultureInfo Culture {
get {
return resourceCulture;
}
set
{
set {
resourceCulture = value;
}
}

View File

@ -8,21 +8,17 @@
// </auto-generated>
//------------------------------------------------------------------------------
namespace MHSEC_G.Properties
{
namespace MHSEC_G.Properties {
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase
{
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "14.0.0.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
public static Settings Default
{
get
{
public static Settings Default {
get {
return defaultInstance;
}
}

View File

@ -57,11 +57,10 @@ namespace MHSEC_G
public ViewModel(byte[] save)
{
if (save == null || save.Length != Model.SAVE_FILE_SIZE)
if (save == null)
{
throw new SystemException("Invalid save file size.");
BugCheck.bug_check(BugCheck.ErrorCode.VIEWMODEL_NULL_SAVE, "The save file reference is NULL.");
}
_model = new Model(save);
_character = new Character(_model);
_items = Item.read_all_items(_model);

View File

@ -0,0 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>

Binary file not shown.