diff --git a/MHSEC-G/MHSEC-G.sln b/MHSEC-G/MHSEC-G.sln index 1edbf58..5d87b81 100644 --- a/MHSEC-G/MHSEC-G.sln +++ b/MHSEC-G/MHSEC-G.sln @@ -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 diff --git a/MHSEC-G/MHSEC-G/BugCheck.cs b/MHSEC-G/MHSEC-G/BugCheck.cs new file mode 100644 index 0000000..c0e3dd8 --- /dev/null +++ b/MHSEC-G/MHSEC-G/BugCheck.cs @@ -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); + } + } +} diff --git a/MHSEC-G/MHSEC-G/Item.cs b/MHSEC-G/MHSEC-G/Item.cs index 854babb..bdd746f 100644 --- a/MHSEC-G/MHSEC-G/Item.cs +++ b/MHSEC-G/MHSEC-G/Item.cs @@ -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 @@ public class Item : INotifyPropertyChanged 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 OFFSET_ID_MAPPING = new Dictionary(); private static readonly Dictionary OFFSET_NAME_MAPPING = new Dictionary(); private readonly uint _offset; + + public uint offset + { + get { return _offset; } + } private readonly Model _model; public string name @@ -91,7 +98,9 @@ public static List read_all_items(Model model) { 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 @@ public static List read_all_items(Model model) 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 @@ public static void read_item_mappings() 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]); diff --git a/MHSEC-G/MHSEC-G/MHSEC-G.csproj b/MHSEC-G/MHSEC-G/MHSEC-G.csproj index 1915125..3a1de4d 100644 --- a/MHSEC-G/MHSEC-G/MHSEC-G.csproj +++ b/MHSEC-G/MHSEC-G/MHSEC-G.csproj @@ -13,6 +13,22 @@ 512 {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 4 + publish\ + true + Disk + false + Foreground + 7 + Days + false + false + true + 0 + 1.0.0.%2a + false + false + true + AnyCPU @@ -23,6 +39,7 @@ DEBUG;TRACE prompt 4 + false AnyCPU @@ -32,24 +49,7 @@ TRACE prompt 4 - - - true - bin\x86\Debug\ - DEBUG;TRACE - full - x86 - prompt - MinimumRecommendedRules.ruleset - - - bin\x86\Release\ - TRACE - true - pdbonly - x86 - prompt - MinimumRecommendedRules.ruleset + false @@ -72,6 +72,7 @@ MSBuild:Compile Designer + @@ -109,7 +110,9 @@ ResXFileCodeGenerator Resources.Designer.cs + Designer + SettingsSingleFileGenerator Settings.Designer.cs @@ -119,6 +122,23 @@ + + + False + Microsoft .NET Framework 4 %28x86 and x64%29 + true + + + False + .NET Framework 3.5 SP1 + false + + + False + Windows Installer 4.5 + true + +