From b9be3390f63531fbe3158fa00060e6ae9d9a1512 Mon Sep 17 00:00:00 2001 From: rassi0429 Date: Mon, 13 Jun 2022 15:29:37 +0900 Subject: [PATCH] fix: escape --- SaveExif/SaveExif.cs | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/SaveExif/SaveExif.cs b/SaveExif/SaveExif.cs index 0785146..c6c8ccd 100644 --- a/SaveExif/SaveExif.cs +++ b/SaveExif/SaveExif.cs @@ -17,7 +17,7 @@ public class SaveExif : NeosMod { public override string Name => "SaveExif"; public override string Author => "kka429"; - public override string Version => "1.0.0"; + public override string Version => "1.0.1"; public override string Link => "https://github.com/rassi0429/SaveExif"; // this line is optional and can be omitted // Exif Type: https://github.com/mono/libgdiplus/blob/main/src/gdiplusimaging.h @@ -104,10 +104,11 @@ static bool Prefix(bool ___keepOriginalScreenshotFormat, WindowsPlatformConnecto var locationName = Engine.Current.WorldManager.FocusedWorld.GetSessionInfo().Name; var locationUrl = Engine.Current.WorldManager.FocusedWorld.IsPublic ? Engine.Current.WorldManager.FocusedWorld.CorrespondingRecord?.URL.ToString() : "private"; - var hostUserId = Engine.Current.WorldManager.FocusedWorld.HostUser.UserID; + locationUrl = locationUrl == null ? "" : locationUrl; + var hostUserId = (Engine.Current.WorldManager.FocusedWorld.HostUser.UserID == null ? "" : Engine.Current.WorldManager.FocusedWorld.HostUser.UserID); var hostUserName = Engine.Current.WorldManager.FocusedWorld.HostUser.UserName; var timeTaken = timestamp.ToString(); - var takeUserId = Engine.Current.WorldManager.FocusedWorld.LocalUser.UserID; + var takeUserId = (Engine.Current.WorldManager.FocusedWorld.LocalUser.UserID == null ? "" : Engine.Current.WorldManager.FocusedWorld.LocalUser.UserID); var takeUserName = Engine.Current.WorldManager.FocusedWorld.LocalUser.UserName; var neosVersion = Engine.Version.ToString(); var _presentUser = Engine.Current.WorldManager.FocusedWorld.AllUsers; @@ -115,19 +116,19 @@ static bool Prefix(bool ___keepOriginalScreenshotFormat, WindowsPlatformConnecto List presentUserNameArray = new List(); foreach(var user in _presentUser) { - presentUserIdArray.Add(user.UserID); - presentUserNameArray.Add(user.UserName); + presentUserIdArray.Add(user.UserID?.Replace("\\", "\\\\").Replace("\"", "\\\"")); + presentUserNameArray.Add(user.UserName.Replace("\\", "\\\\").Replace("\"", "\\\"")); } - string str = $"{{\"locationName\":\"{locationName}\",\n" + - $"\"locationUrl\":\"{locationUrl}\",\n" + - $"\"hostUserId\":\"{hostUserId}\",\n" + - $"\"hostUserName\":\"{hostUserName}\",\n" + - $"\"timeTaken\":\"{timeTaken}\",\n" + - $"\"takeUserId\":\"{takeUserId}\",\n" + - $"\"takeUserName\":\"{takeUserName}\",\n" + - $"\"neosVersion\":\"{neosVersion}\",\n" + - $"\"takeUserName\":\"{takeUserName}\",\n" + + string str = $"{{\"locationName\":\"{locationName?.Replace("\\", "\\\\").Replace("\"", "\\\"")}\",\n" + + $"\"locationUrl\":\"{locationUrl?.Replace("\\", "\\\\").Replace("\"", "\\\"")}\",\n" + + $"\"hostUserId\":\"{hostUserId?.Replace("\\", "\\\\").Replace("\"", "\\\"")}\",\n" + + $"\"hostUserName\":\"{hostUserName?.Replace("\\", "\\\\").Replace("\"", "\\\"")}\",\n" + + $"\"timeTaken\":\"{timeTaken?.Replace("\\", "\\\\").Replace("\"", "\\\"")}\",\n" + + $"\"takeUserId\":\"{takeUserId?.Replace("\\", "\\\\").Replace("\"", "\\\"")}\",\n" + + $"\"takeUserName\":\"{takeUserName?.Replace("\\", "\\\\").Replace("\"", "\\\"")}\",\n" + + $"\"neosVersion\":\"{neosVersion?.Replace("\\", "\\\\").Replace("\"", "\\\"")}\",\n" + + $"\"takeUserName\":\"{takeUserName?.Replace("\\", "\\\\").Replace("\"", "\\\"")}\",\n" + $"\"presentUserIdArray\":[\"{String.Join("\",\"", presentUserIdArray)}\"],\n" + $"\"presentUserNameArray\":[\"{String.Join("\",\"", presentUserNameArray)}\"],\n" + $"\"version\":\"1.0.0\"}}";