From 2ec92fb10e6ce91e00a8e97e126ce472cacf3ab2 Mon Sep 17 00:00:00 2001 From: Jonathon Wyza Date: Sat, 28 Oct 2017 18:22:10 -0500 Subject: [PATCH] Cleanup of all the Classes, Methods, Variables to follow C#.Net (ReSharper) standards. Removed Depreciated method of creating socket server in lieu of the newer correct method. Updated Build events to now grab version.txt from $(SolutionDir)/../version.txt and put that into the AssemblyFileVersion. AssemblyFileVersion is now used for the Version variable. Removed unused "using" statements. --- PlayerDataDump/PlayerDataDump.cs | 103 ++++++++-------- PlayerDataDump/PlayerDataDump.csproj | 112 +++++++++++++++--- PlayerDataDump/ProfileStorageServer.cs | 33 +++--- PlayerDataDump/Properties/AssemblyInfo.cs | 32 +++++ PlayerDataDump/SocketServer.cs | 60 +++++----- .../PlayerDataDump.StandAlone.csproj | 95 +++++++++++++++ .../PlayerDataDump.cs | 37 +++--- .../ProfileStorageServer.cs | 29 ++--- .../PlayerDataDump.StandAlone/Program.cs | 8 +- .../Properties/AssemblyInfo.cs | 5 +- .../SaveGameManager.cs | 8 +- .../PlayerDataDump.StandAlone/SocketServer.cs | 53 +++------ .../StringEncrypt.cs | 7 +- version.txt | 2 +- 14 files changed, 382 insertions(+), 202 deletions(-) create mode 100644 PlayerDataDump/Properties/AssemblyInfo.cs diff --git a/PlayerDataDump/PlayerDataDump.cs b/PlayerDataDump/PlayerDataDump.cs index 77c32a3..b6f24c7 100644 --- a/PlayerDataDump/PlayerDataDump.cs +++ b/PlayerDataDump/PlayerDataDump.cs @@ -1,89 +1,96 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.Linq; -using System.Text; -using System.IO; using Modding; -using UnityEngine; -using UnityEngine.UI; -using UnityEngine.SceneManagement; -using HutongGames.PlayMaker; -using System.Reflection; using WebSocketSharp.Server; using System.Net; +using System.Reflection; namespace PlayerDataDump { + + /// + /// Main mod class for PlayerDataDump. Provides the server and version handling. + /// public class PlayerDataDump : Mod { - public WebSocketServer wss = new WebSocketServer(11420); - public static String version = "27/10/17.a (TGT)"; - public static String current; + public WebSocketServer Wss = new WebSocketServer(11420); + + public static string Version = FileVersionInfo.GetVersionInfo(Assembly.GetAssembly(typeof(PlayerDataDump)).Location).FileVersion; + public static string Current; + /// + /// Fetches the list of the current mods installed. + /// public static string GetCurrentMods() { List mods = ModHooks.Instance.loadedMods; - string output = "["; - foreach (string mod in mods) - { - output += String.Format("\"{0}\",", mod); - } + string output = mods.Aggregate("[", (current, mod) => current + $"\"{mod}\","); output = output.TrimEnd(',') + "]"; return output; } + /// + /// Fetches current version from the site + /// + /// Version # public string GetCurrentVersion() { try { - WebClient web = new WebClient(); - web.Headers[HttpRequestHeader.UserAgent] = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.2 (KHTML, like Gecko) Chrome/15.0.874.121 Safari/535.2"; + WebClient web = new WebClient + { + Headers = + { + [HttpRequestHeader.UserAgent] = + "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.2 (KHTML, like Gecko) Chrome/15.0.874.121 Safari/535.2" + }, + + }; + return web.DownloadString("https://iamwyza.github.io/HollowKnightRandomizerTracker/version.txt"); - } catch { - return version; + } catch(Exception e) { + ModHooks.ModLog(e.ToString()); + return Version; } } + /// + /// Fetches and compares the compiled version with the version from the site. + /// + /// Returns the current version. Includes additional text if the current version doesn't match the version of the site. public override string GetVersion() { - if (current == null) - current = GetCurrentVersion(); - if ( current == version ) - return version; - return version + " | UPDATE REQUIRED"; + if (Current == null) + Current = GetCurrentVersion(); + if ( Current == Version ) + return Version; + return Version + " | UPDATE REQUIRED"; } + /// + /// Creates and starts the WebSocket Server instances. + /// public override void Initialize() { ModHooks.ModLog("Initializing PlayerDataDump"); //Setup websockets server - wss.AddWebSocketService( - "/playerData", - () =>{ - SocketServer ss = new SocketServer() - { - IgnoreExtensions = true - }; - - ModHooks.Instance.NewGameHook += ss.NewGame; - ModHooks.Instance.SavegameLoadHook += ss.LoadSave; - ModHooks.Instance.SetPlayerBoolHook += ss.EchoBool; - ModHooks.Instance.SetPlayerIntHook += ss.EchoInt; + Wss.AddWebSocketService("/playerData", ss => + { + ModHooks.Instance.NewGameHook += ss.NewGame; + ModHooks.Instance.SavegameLoadHook += ss.LoadSave; + ModHooks.Instance.SetPlayerBoolHook += ss.EchoBool; + ModHooks.Instance.SetPlayerIntHook += ss.EchoInt; - ModHooks.Instance.ApplicationQuitHook += ss.OnQuit; - return ss; - } - ); - wss.AddWebSocketService("/ProfileStorage", () => { - ProfileStorageServer ss = new ProfileStorageServer() { - IgnoreExtensions = true - }; - return ss; - } - ); + ModHooks.Instance.ApplicationQuitHook += ss.OnQuit; + }); + + //Setup ProfileStorage Server + Wss.AddWebSocketService("/ProfileStorage", ss => { }); - wss.Start(); + Wss.Start(); ModHooks.ModLog("Initialized PlayerDataDump"); } diff --git a/PlayerDataDump/PlayerDataDump.csproj b/PlayerDataDump/PlayerDataDump.csproj index 17af45c..160de00 100644 --- a/PlayerDataDump/PlayerDataDump.csproj +++ b/PlayerDataDump/PlayerDataDump.csproj @@ -64,36 +64,112 @@ + UnityEngine.dll - - - - - - - - - - - - - - - - - <_PostBuildHookTimestamp>@(IntermediateAssembly->'%(FullPath).timestamp') <_PostBuildHookHostPlatform>$(Platform) + + + CommonBuildDefineModifiedAssemblyVersion; + $(CompileDependsOn); + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/PlayerDataDump/ProfileStorageServer.cs b/PlayerDataDump/ProfileStorageServer.cs index 6ed75c5..9713d62 100644 --- a/PlayerDataDump/ProfileStorageServer.cs +++ b/PlayerDataDump/ProfileStorageServer.cs @@ -1,8 +1,6 @@ using Modding; using System; -using System.Collections.Generic; using System.IO; -using System.Linq; using System.Text; using UnityEngine; using WebSocketSharp; @@ -10,9 +8,13 @@ namespace PlayerDataDump { - class ProfileStorageServer : WebSocketBehavior + internal class ProfileStorageServer : WebSocketBehavior { - public void Broadcast(String s) + public ProfileStorageServer() + { + IgnoreExtensions = true; + } + public void Broadcast(string s) { Sessions.Broadcast(s); } @@ -26,15 +28,15 @@ protected override void OnMessage(MessageEventArgs e) string[] temp = e.Data.Split('|'); if (int.TryParse(temp[1], out int profileId)) { - Send(profileId + "|" + getProfile(profileId)); + Send(profileId + "|" + GetProfile(profileId)); } }else if (e.Data.StartsWith("save")) { string[] temp = e.Data.Split('|'); if (int.TryParse(temp[1], out int profileId)) { - saveProfile(profileId, temp[2]); - Broadcast(profileId + "|" + getProfile(profileId)); + SaveProfile(profileId, temp[2]); + Broadcast(profileId + "|" + GetProfile(profileId)); } }else { @@ -42,21 +44,18 @@ protected override void OnMessage(MessageEventArgs e) } } - private string getProfile(int i) + private static string GetProfile(int i) { - String path = Application.persistentDataPath + $"/OverlayProfile.{i}.js"; - if (File.Exists(path)) - { - string data = File.ReadAllText(path); - return Convert.ToBase64String(Encoding.UTF8.GetBytes(data)); - } + string path = Application.persistentDataPath + $"/OverlayProfile.{i}.js"; + if (!File.Exists(path)) return "undefined"; - return "undefined"; + string data = File.ReadAllText(path); + return Convert.ToBase64String(Encoding.UTF8.GetBytes(data)); } - private void saveProfile(int profileId, string base64EncodedJson) + private static void SaveProfile(int profileId, string base64EncodedJson) { - String path = Application.persistentDataPath + $"/OverlayProfile.{profileId}.js"; + string path = Application.persistentDataPath + $"/OverlayProfile.{profileId}.js"; byte[] data = Convert.FromBase64String(base64EncodedJson); string decodedString = Encoding.UTF8.GetString(data); diff --git a/PlayerDataDump/Properties/AssemblyInfo.cs b/PlayerDataDump/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..b243cfb --- /dev/null +++ b/PlayerDataDump/Properties/AssemblyInfo.cs @@ -0,0 +1,32 @@ +using System.Reflection; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("Hollow Knight - Player Data Dumper")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("PlayerDataDump.Properties")] +[assembly: AssemblyCopyright("")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("cc2ef5af-4830-4e83-82bf-b6532469f282")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/PlayerDataDump/SocketServer.cs b/PlayerDataDump/SocketServer.cs index ab2fb65..a5e0dd2 100644 --- a/PlayerDataDump/SocketServer.cs +++ b/PlayerDataDump/SocketServer.cs @@ -1,5 +1,4 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using System.Linq; using System.Text; using WebSocketSharp; @@ -10,12 +9,17 @@ namespace PlayerDataDump { - class SocketServer : WebSocketBehavior + internal class SocketServer : WebSocketBehavior { - - private static HashSet intKeysToSend = new HashSet {"simpleKeys", "nailDamage", "maxHealth", "MPReserveMax", "ore", "rancidEggs", "grubsCollected", "charmSlotsFilled", "charmSlots" }; - public void Broadcast(String s) + public SocketServer() + { + IgnoreExtensions = true; + } + + private static readonly HashSet IntKeysToSend = new HashSet {"simpleKeys", "nailDamage", "maxHealth", "MPReserveMax", "ore", "rancidEggs", "grubsCollected", "charmSlotsFilled", "charmSlots" }; + + public void Broadcast(string s) { Sessions.Broadcast(s); } @@ -38,7 +42,7 @@ protected override void OnMessage(MessageEventArgs e) Send(PlayerDataDump.GetCurrentMods()); break; case "version": - Send(String.Format("{{ \"version\":\"{0}\" }}", PlayerDataDump.version)); + Send(string.Format("{{ \"version\":\"{0}\" }}", PlayerDataDump.Version)); break; case "json": Send(GetJson()); @@ -52,12 +56,12 @@ protected override void OnMessage(MessageEventArgs e) if (e.Data.Split('|')[0] == "bool") { string b = ModHooks.Instance.GetPlayerBool(e.Data.Split('|')[1]).ToString(); - sendMessage(e.Data.Split('|')[1], b); + SendMessage(e.Data.Split('|')[1], b); } if (e.Data.Split('|')[0] == "int") { string i = ModHooks.Instance.GetPlayerInt(e.Data.Split('|')[1]).ToString(); - sendMessage(e.Data.Split('|')[1], i); + SendMessage(e.Data.Split('|')[1], i); } } else @@ -77,12 +81,12 @@ protected override void OnClose(CloseEventArgs e) { base.OnClose(e); - ModHooks.Instance.NewGameHook -= this.NewGame; - ModHooks.Instance.SavegameLoadHook -= this.LoadSave; - ModHooks.Instance.SetPlayerBoolHook -= this.EchoBool; - ModHooks.Instance.SetPlayerIntHook -= this.EchoInt; + ModHooks.Instance.NewGameHook -= NewGame; + ModHooks.Instance.SavegameLoadHook -= LoadSave; + ModHooks.Instance.SetPlayerBoolHook -= EchoBool; + ModHooks.Instance.SetPlayerIntHook -= EchoInt; - ModHooks.Instance.ApplicationQuitHook -= this.OnQuit; + ModHooks.Instance.ApplicationQuitHook -= OnQuit; ModHooks.ModLog("[PlayerDataDump] CLOSE: Code:" + e.Code + ", Reason:" + e.Reason); } @@ -92,37 +96,37 @@ protected override void OnOpen() ModHooks.ModLog("[PlayerDataDump] OPEN"); } - public void sendMessage(string var, string value) + public void SendMessage(string var, string value) { Send(new Row(var, value).ToJsonElementPair); } public void LoadSave(int slot) { - sendMessage("SaveLoaded", "true"); + SendMessage("SaveLoaded", "true"); } public void EchoBool(string var, bool value) { if (var.StartsWith("gotCharm_") || var.StartsWith("brokenCharm_") || var.StartsWith("equippedCharm_") || var.StartsWith("has") || var.StartsWith("maskBroken") || var == "overcharmed") { - sendMessage(var, value.ToString()); + SendMessage(var, value.ToString()); } } public void EchoInt(string var, int value) { - if (intKeysToSend.Contains(var) || var.EndsWith("Level") || var.StartsWith("trinket") ) + if (IntKeysToSend.Contains(var) || var.EndsWith("Level") || var.StartsWith("trinket") ) { - sendMessage(var, value.ToString()); + SendMessage(var, value.ToString()); } } public static string GetJson() { PlayerData playerData = PlayerData.instance; - String json = JsonUtility.ToJson(playerData); + string json = JsonUtility.ToJson(playerData); int randomFireballLevel = ModHooks.Instance.GetPlayerInt("_fireballLevel"); int randomQuakeLevel = ModHooks.Instance.GetPlayerInt("_quakeLevel"); @@ -142,8 +146,8 @@ public static string GetJson() public static string GetRandom() { - String path = Application.persistentDataPath + "/rnd.js"; - String data = File.ReadAllText(path); + string path = Application.persistentDataPath + "/rnd.js"; + string data = File.ReadAllText(path); return data; } @@ -162,24 +166,26 @@ public static string GetRelics() public void NewGame() { - sendMessage("NewSave", "true"); + SendMessage("NewSave", "true"); } public void OnQuit() { - sendMessage("GameExiting", "true"); + SendMessage("GameExiting", "true"); } public struct Row { + // ReSharper disable once InconsistentNaming public string var { get; set; } + // ReSharper disable once InconsistentNaming public object value { get; set; } - public Row(string _var, object _value) + public Row(string var, object value) { - var = _var; - value = _value; + this.var = var; + this.value = value; } public string ToJsonElementPair => " { \"var\" : \"" + var + "\", \"value\" : \"" + value + "\" }"; diff --git a/StandAlonePlayerDataDump/PlayerDataDump.StandAlone/PlayerDataDump.StandAlone.csproj b/StandAlonePlayerDataDump/PlayerDataDump.StandAlone/PlayerDataDump.StandAlone.csproj index a5a5175..5e71c15 100644 --- a/StandAlonePlayerDataDump/PlayerDataDump.StandAlone/PlayerDataDump.StandAlone.csproj +++ b/StandAlonePlayerDataDump/PlayerDataDump.StandAlone/PlayerDataDump.StandAlone.csproj @@ -66,4 +66,99 @@ + + + + + CommonBuildDefineModifiedAssemblyVersion; + $(CompileDependsOn); + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/StandAlonePlayerDataDump/PlayerDataDump.StandAlone/PlayerDataDump.cs b/StandAlonePlayerDataDump/PlayerDataDump.StandAlone/PlayerDataDump.cs index f0d0779..e32be10 100644 --- a/StandAlonePlayerDataDump/PlayerDataDump.StandAlone/PlayerDataDump.cs +++ b/StandAlonePlayerDataDump/PlayerDataDump.StandAlone/PlayerDataDump.cs @@ -2,34 +2,43 @@ using WebSocketSharp.Server; using System.Net; using System.Configuration; +using System.Diagnostics; +using System.Reflection; namespace PlayerDataDump.StandAlone { public class PlayerDataDump { - public WebSocketServer wss = new WebSocketServer(11420); - public static String version = "24/10/17.a"; - public static String current; + public WebSocketServer Wss = new WebSocketServer(11420); + public static string Version = FileVersionInfo.GetVersionInfo(Assembly.GetAssembly(typeof(PlayerDataDump)).Location).FileVersion; + public static string Current; public string GetCurrentVersion() { try { - WebClient web = new WebClient(); - web.Headers[HttpRequestHeader.UserAgent] = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.2 (KHTML, like Gecko) Chrome/15.0.874.121 Safari/535.2"; + WebClient web = new WebClient + { + Headers = + { + [HttpRequestHeader.UserAgent] = + "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.2 (KHTML, like Gecko) Chrome/15.0.874.121 Safari/535.2" + } + }; + return web.DownloadString("https://iamwyza.github.io/HollowKnightRandomizerTracker/version.txt"); } catch { - return version; + return Version; } } public string GetVersion() { - if (current == null) - current = GetCurrentVersion(); - if ( current == version ) - return version; - return version + " | UPDATE REQUIRED"; + if (Current == null) + Current = GetCurrentVersion(); + if ( Current == Version ) + return Version; + return Version + " | UPDATE REQUIRED"; } public void Initialize() @@ -37,16 +46,16 @@ public void Initialize() Console.WriteLine("Initializing PlayerDataDump"); //Setup websockets server - wss.AddWebSocketService("/playerData",(ss) => { + Wss.AddWebSocketService("/playerData",(ss) => { ss.Init(ConfigurationManager.AppSettings["SavePath"]); }); - wss.AddWebSocketService("/ProfileStorage", (ss) => { + Wss.AddWebSocketService("/ProfileStorage", (ss) => { ss.Init(ConfigurationManager.AppSettings["SavePath"]); } ); - wss.Start(); + Wss.Start(); Console.WriteLine("Initialized PlayerDataDump"); } diff --git a/StandAlonePlayerDataDump/PlayerDataDump.StandAlone/ProfileStorageServer.cs b/StandAlonePlayerDataDump/PlayerDataDump.StandAlone/ProfileStorageServer.cs index 8b47468..7745f9a 100644 --- a/StandAlonePlayerDataDump/PlayerDataDump.StandAlone/ProfileStorageServer.cs +++ b/StandAlonePlayerDataDump/PlayerDataDump.StandAlone/ProfileStorageServer.cs @@ -6,14 +6,10 @@ namespace PlayerDataDump.StandAlone { - class ProfileStorageServer : WebSocketBehavior + internal class ProfileStorageServer : WebSocketBehavior { private string _path; - public ProfileStorageServer() - { - } - public void Init(string path) { IgnoreExtensions = true; @@ -34,15 +30,15 @@ protected override void OnMessage(MessageEventArgs e) string[] temp = e.Data.Split('|'); if (int.TryParse(temp[1], out int profileId)) { - Send(profileId + "|" + getProfile(profileId)); + Send(profileId + "|" + GetProfile(profileId)); } }else if (e.Data.StartsWith("save")) { string[] temp = e.Data.Split('|'); if (int.TryParse(temp[1], out int profileId)) { - saveProfile(profileId, temp[2]); - Broadcast(profileId + "|" + getProfile(profileId)); + SaveProfile(profileId, temp[2]); + Broadcast(profileId + "|" + GetProfile(profileId)); } }else { @@ -50,21 +46,18 @@ protected override void OnMessage(MessageEventArgs e) } } - private string getProfile(int i) + private string GetProfile(int i) { - String path = _path + $"/OverlayProfile.{i}.js"; - if (File.Exists(path)) - { - string data = File.ReadAllText(path); - return Convert.ToBase64String(Encoding.UTF8.GetBytes(data)); - } + string path = _path + $"/OverlayProfile.{i}.js"; + if (!File.Exists(path)) return "undefined"; - return "undefined"; + string data = File.ReadAllText(path); + return Convert.ToBase64String(Encoding.UTF8.GetBytes(data)); } - private void saveProfile(int profileId, string base64EncodedJson) + private void SaveProfile(int profileId, string base64EncodedJson) { - String path = _path + $"/OverlayProfile.{profileId}.js"; + string path = _path + $"/OverlayProfile.{profileId}.js"; byte[] data = Convert.FromBase64String(base64EncodedJson); string decodedString = Encoding.UTF8.GetString(data); diff --git a/StandAlonePlayerDataDump/PlayerDataDump.StandAlone/Program.cs b/StandAlonePlayerDataDump/PlayerDataDump.StandAlone/Program.cs index a3db4ab..48abad5 100644 --- a/StandAlonePlayerDataDump/PlayerDataDump.StandAlone/Program.cs +++ b/StandAlonePlayerDataDump/PlayerDataDump.StandAlone/Program.cs @@ -1,14 +1,10 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace PlayerDataDump.StandAlone { - class Program + internal class Program { - static void Main(string[] args) + private static void Main(string[] args) { PlayerDataDump dump = new PlayerDataDump(); dump.Initialize(); diff --git a/StandAlonePlayerDataDump/PlayerDataDump.StandAlone/Properties/AssemblyInfo.cs b/StandAlonePlayerDataDump/PlayerDataDump.StandAlone/Properties/AssemblyInfo.cs index 9811bc2..7913f81 100644 --- a/StandAlonePlayerDataDump/PlayerDataDump.StandAlone/Properties/AssemblyInfo.cs +++ b/StandAlonePlayerDataDump/PlayerDataDump.StandAlone/Properties/AssemblyInfo.cs @@ -1,16 +1,15 @@ using System.Reflection; -using System.Runtime.CompilerServices; using System.Runtime.InteropServices; // General Information about an assembly is controlled through the following // set of attributes. Change these attribute values to modify the information // associated with an assembly. -[assembly: AssemblyTitle("PlayerDataDump.StandAlone")] +[assembly: AssemblyTitle("Hollow Knight - Player Data Dumper")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("PlayerDataDump.StandAlone")] -[assembly: AssemblyCopyright("Copyright © 2017")] +[assembly: AssemblyCopyright("")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] diff --git a/StandAlonePlayerDataDump/PlayerDataDump.StandAlone/SaveGameManager.cs b/StandAlonePlayerDataDump/PlayerDataDump.StandAlone/SaveGameManager.cs index ada6d8f..b7902b6 100644 --- a/StandAlonePlayerDataDump/PlayerDataDump.StandAlone/SaveGameManager.cs +++ b/StandAlonePlayerDataDump/PlayerDataDump.StandAlone/SaveGameManager.cs @@ -1,12 +1,6 @@ using Newtonsoft.Json; -using Newtonsoft.Json.Linq; -using System; -using System.Collections.Generic; using System.IO; -using System.Linq; using System.Runtime.Serialization.Formatters.Binary; -using System.Security.Cryptography; -using System.Text; namespace PlayerDataDump.StandAlone { @@ -21,7 +15,7 @@ public void Load(string path) PlayerData.instance = JsonConvert.DeserializeObject(Decrypt(toDecrypt)).playerData; } - private string Decrypt(string data) + private static string Decrypt(string data) { return StringEncrypt.DecryptData(data); } diff --git a/StandAlonePlayerDataDump/PlayerDataDump.StandAlone/SocketServer.cs b/StandAlonePlayerDataDump/PlayerDataDump.StandAlone/SocketServer.cs index c3ba87f..d6ac234 100644 --- a/StandAlonePlayerDataDump/PlayerDataDump.StandAlone/SocketServer.cs +++ b/StandAlonePlayerDataDump/PlayerDataDump.StandAlone/SocketServer.cs @@ -9,17 +9,12 @@ namespace PlayerDataDump.StandAlone { - class SocketServer : WebSocketBehavior + internal class SocketServer : WebSocketBehavior { private string _path; private SaveGameManager _saveGameManager; private JsonSerializerSettings _jsonSerializerSettings; private FileSystemWatcher _fileSystemWatcher; - private DateTime _lastEventTime; - - public SocketServer() { - - } public void Init(string path) { @@ -41,7 +36,6 @@ public void Init(string path) _fileSystemWatcher.Changed += FileSystemWatcher_Update; _fileSystemWatcher.Created += FileSystemWatcher_Update; - _lastEventTime = DateTime.Now; if(File.Exists(_path + "/user1.dat")) { @@ -52,16 +46,15 @@ public void Init(string path) private void FileSystemWatcher_Update(object sender, FileSystemEventArgs e) { - if (State == WebSocketState.Open) - { - _saveGameManager.Load(e.FullPath); - Send(GetJson()); - } + if (State != WebSocketState.Open) return; + + _saveGameManager.Load(e.FullPath); + Send(GetJson()); } // private static HashSet intKeysToSend = new HashSet {"simpleKeys", "nailDamage", "maxHealth", "MPReserveMax", "ore", "rancidEggs", "grubsCollected", "charmSlotsFilled", "charmSlots" }; - public void Broadcast(String s) + public void Broadcast(string s) { if (State == WebSocketState.Open) { @@ -80,7 +73,7 @@ protected override void OnMessage(MessageEventArgs e) Send("{}"); break; case "version": - Send(String.Format("{{ \"version\":\"{0}\" }}", PlayerDataDump.version)); + Send(string.Format("{{ \"version\":\"{0}\" }}", PlayerDataDump.Version)); break; case "json": Send(GetJson()); @@ -94,12 +87,12 @@ protected override void OnMessage(MessageEventArgs e) if (e.Data.Split('|')[0] == "bool") { string b = PlayerData.instance.GetBool(e.Data.Split('|')[1]).ToString(); - sendMessage(e.Data.Split('|')[1], b); + SendMessage(e.Data.Split('|')[1], b); } if (e.Data.Split('|')[0] == "int") { string i = PlayerData.instance.GetInt(e.Data.Split('|')[1]).ToString(); - sendMessage(e.Data.Split('|')[1], i); + SendMessage(e.Data.Split('|')[1], i); } } else @@ -127,29 +120,11 @@ protected override void OnOpen() Console.WriteLine("[PlayerDataDump] OPEN"); } - public void sendMessage(string var, string value) + public void SendMessage(string var, string value) { Send(new Row(var, value).ToJsonElementPair); } - - //public void EchoBool(string var, bool value) - //{ - // if (var.StartsWith("gotCharm_") || var.StartsWith("brokenCharm_") || var.StartsWith("equippedCharm_") || var.StartsWith("has") || var.StartsWith("maskBroken") || var == "overcharmed") - // { - // sendMessage(var, value.ToString()); - // } - //} - - - //public void EchoInt(string var, int value) - //{ - // if (intKeysToSend.Contains(var) || var.EndsWith("Level") || var.StartsWith("trinket") ) - // { - // sendMessage(var, value.ToString()); - // } - //} - public string GetJson() { return JsonConvert.SerializeObject(PlayerData.instance, _jsonSerializerSettings); @@ -171,13 +146,15 @@ public string GetRelics() public struct Row { + // ReSharper disable once InconsistentNaming public string var { get; set; } + // ReSharper disable once InconsistentNaming public object value { get; set; } - public Row(string _var, object _value) + public Row(string var, object value) { - var = _var; - value = _value; + this.var = var; + this.value = value; } public string ToJsonElementPair => " { \"var\" : \"" + var + "\", \"value\" : \"" + value + "\" }"; diff --git a/StandAlonePlayerDataDump/PlayerDataDump.StandAlone/StringEncrypt.cs b/StandAlonePlayerDataDump/PlayerDataDump.StandAlone/StringEncrypt.cs index 9bf2000..cfd2091 100644 --- a/StandAlonePlayerDataDump/PlayerDataDump.StandAlone/StringEncrypt.cs +++ b/StandAlonePlayerDataDump/PlayerDataDump.StandAlone/StringEncrypt.cs @@ -1,9 +1,6 @@ using System; -using System.Collections.Generic; -using System.Linq; using System.Security.Cryptography; using System.Text; -using System.Threading.Tasks; namespace PlayerDataDump.StandAlone { @@ -16,7 +13,7 @@ public static string EncryptData(string toEncrypt) byte[] bytes = Encoding.UTF8.GetBytes(toEncrypt); ICryptoTransform cryptoTransform = new RijndaelManaged { - Key = StringEncrypt.keyArray, + Key = keyArray, Mode = CipherMode.ECB, Padding = PaddingMode.PKCS7 }.CreateEncryptor(); @@ -30,7 +27,7 @@ public static string DecryptData(string toDecrypt) byte[] array = Convert.FromBase64String(toDecrypt); ICryptoTransform cryptoTransform = new RijndaelManaged { - Key = StringEncrypt.keyArray, + Key = keyArray, Mode = CipherMode.ECB, Padding = PaddingMode.PKCS7 }.CreateDecryptor(); diff --git a/version.txt b/version.txt index 5d07689..c33b7ea 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -22/10/17.b \ No newline at end of file +28/10/17.a \ No newline at end of file