From 68f6910f6ed07f119f02bd9f790afa68ea2b04ff Mon Sep 17 00:00:00 2001 From: Emilian Roman Date: Thu, 22 Nov 2018 19:28:24 +0800 Subject: [PATCH] Code code clean up --- Atarashii/Atarashii.API/Profile.cs | 19 ++++- .../Modules/Profile/Configuration.cs | 71 +++++++++++-------- .../Modules/Profile/ConfigurationFactory.cs | 2 +- 3 files changed, 59 insertions(+), 33 deletions(-) diff --git a/Atarashii/Atarashii.API/Profile.cs b/Atarashii/Atarashii.API/Profile.cs index 9d1ad68..d9211fa 100644 --- a/Atarashii/Atarashii.API/Profile.cs +++ b/Atarashii/Atarashii.API/Profile.cs @@ -1,3 +1,4 @@ +using System; using System.IO; using Atarashii.Modules.Profile; @@ -19,7 +20,10 @@ public static class Profile /// public static Configuration Parse(string blamPath) { - return ConfigurationFactory.GetFromStream(File.Open(blamPath, FileMode.Open)); + using (var fs = File.Open(blamPath, FileMode.Open)) + { + return ConfigurationFactory.GetFromStream(fs); + } } /// @@ -33,7 +37,18 @@ public static Configuration Parse(string blamPath) /// public static void Patch(Configuration configuration, string blamPath) { - new ConfigurationPatcher(configuration).PatchTo(File.Open(blamPath, FileMode.Open)); + using (var ms = new MemoryStream()) + using (var fs = File.Open(blamPath, FileMode.Open)) + { + fs.CopyTo(ms); + new ConfigurationPatcher(configuration).PatchTo(ms); + new ConfigurationForger().Forge(ms); + + ms.Position = 0; + fs.Position = 0; + + ms.CopyTo(fs); + } } /// diff --git a/Atarashii/Atarashii/Modules/Profile/Configuration.cs b/Atarashii/Atarashii/Modules/Profile/Configuration.cs index 7c24d3b..3eb477d 100644 --- a/Atarashii/Atarashii/Modules/Profile/Configuration.cs +++ b/Atarashii/Atarashii/Modules/Profile/Configuration.cs @@ -10,36 +10,6 @@ namespace Atarashii.Modules.Profile /// public class Configuration { - /// - /// Player name. - /// - public Name Name { get; set; } = new Name(); - - /// - /// Player colour. - /// - public Colour Colour { get; set; } = new Colour(); - - /// - /// Mouse settings. - /// - public Mouse Mouse { get; set; } = new Mouse(); - - /// - /// Audio settings. - /// - public Audio Audio { get; set; } = new Audio(); - - /// - /// Video settings. - /// - public Video Video { get; set; } = new Video(); - - /// - /// Network settings. - /// - public Network Network { get; set; } = new Network(); - /// /// Length of the blam.sav binary. /// @@ -154,5 +124,46 @@ public class Configuration /// Offset of the network client port property. /// public const int NetworkPortClientOffset = 0x1004; + + /// + /// Offset of the blam.sav integrity hash. + /// + public const int BlamHashOffset = 0x1FFC; + + /// + /// Length of the blam.sav integrity hash. + /// The value is that of a CRC32 length. + /// + public const int BlamHashLength = 0x4; + + /// + /// Player name. + /// + public Name Name { get; set; } = new Name(); + + /// + /// Player colour. + /// + public Colour Colour { get; set; } = new Colour(); + + /// + /// Mouse settings. + /// + public Mouse Mouse { get; set; } = new Mouse(); + + /// + /// Audio settings. + /// + public Audio Audio { get; set; } = new Audio(); + + /// + /// Video settings. + /// + public Video Video { get; set; } = new Video(); + + /// + /// Network settings. + /// + public Network Network { get; set; } = new Network(); } } \ No newline at end of file diff --git a/Atarashii/Atarashii/Modules/Profile/ConfigurationFactory.cs b/Atarashii/Atarashii/Modules/Profile/ConfigurationFactory.cs index e8af4fa..837f8a9 100644 --- a/Atarashii/Atarashii/Modules/Profile/ConfigurationFactory.cs +++ b/Atarashii/Atarashii/Modules/Profile/ConfigurationFactory.cs @@ -139,7 +139,7 @@ public static Configuration GetFromStream(Stream stream) return configuration; } - + /// /// Returns a byte value from the inbound binary reader at the given offset. ///