From 845bb0ecdd9699afde874912013a923a73f29aa7 Mon Sep 17 00:00:00 2001
From: Bob Da Ross <52760019+BobDaRoss@users.noreply.github.com>
Date: Thu, 17 Jun 2021 00:18:08 -0500
Subject: [PATCH 1/5] Removed updater again. Forgot I was in the wrong branch
---
SeamlessClient.cs | 6 -
SeamlessClientPlugin.csproj | 1 -
Utilities/UpdateChecker.cs | 315 ------------------------------------
3 files changed, 322 deletions(-)
delete mode 100644 Utilities/UpdateChecker.cs
diff --git a/SeamlessClient.cs b/SeamlessClient.cs
index c650e20..5f53c77 100644
--- a/SeamlessClient.cs
+++ b/SeamlessClient.cs
@@ -122,12 +122,6 @@ namespace SeamlessClientPlugin
public void Init(object gameInstance)
{
- Utilities.UpdateChecker Checker = new Utilities.UpdateChecker(false);
- Task UpdateChecker = new Task(() => Checker.PingUpdateServer());
- UpdateChecker.Start();
-
-
-
Patches.GetPatches();
TryShow("Running Seamless Client Plugin v[" + Version + "]");
PingTimer.Elapsed += PingTimer_Elapsed;
diff --git a/SeamlessClientPlugin.csproj b/SeamlessClientPlugin.csproj
index 936fa49..943e1bf 100644
--- a/SeamlessClientPlugin.csproj
+++ b/SeamlessClientPlugin.csproj
@@ -167,7 +167,6 @@
-
diff --git a/Utilities/UpdateChecker.cs b/Utilities/UpdateChecker.cs
deleted file mode 100644
index 7cdc29f..0000000
--- a/Utilities/UpdateChecker.cs
+++ /dev/null
@@ -1,315 +0,0 @@
-using ProtoBuf;
-using Sandbox.Graphics.GUI;
-using System;
-using System.Collections.Generic;
-using System.IO;
-using System.IO.Compression;
-using System.Linq;
-using System.Net;
-using System.Net.Sockets;
-using System.Reflection;
-using System.Runtime.Serialization;
-using System.Runtime.Serialization.Json;
-using System.Text;
-using System.Threading.Tasks;
-using System.Windows.Forms;
-using System.Xml.Serialization;
-namespace SeamlessClientPlugin.Utilities
-{
- public class UpdateChecker
- {
- public string PluginFolder;
- public string CurrentVersion;
- public bool DownloadUpdate;
- private string GitHubAPILink = "https://api.github.com/repos/Casimir255/SeamlessClientPlugin/releases/latest";
-
- private WebClient Client;
-
-
-
-
- public UpdateChecker(bool AutoUpdate)
- {
- PluginFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
- Client = new WebClient();
- DeleteOLDFiles();
- }
-
-
-
-
- public void PingUpdateServer()
- {
- try
- {
- //Create new webclient and insert a user-agent
- Client.Headers["User-Agent"] = "SeamlessClientUpdater";
-
- //Grap API data for latest seamless client release
- string data = Client.DownloadString(GitHubAPILink);
-
- //SeamlessClient.TryShow(data);
-
-
- DataContractJsonSerializer s = new DataContractJsonSerializer(typeof(GithubRelease));
-
- GithubRelease Release;
- using (MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(data)))
- {
- Release = (GithubRelease)s.ReadObject(stream);
- }
-
-
- if (Release == null || !TryGetMainRelease(Release.Content, out GitZipFile MainReleaseFile))
- return;
-
-
- //Check if the client needs an update based off of github latest release version
-
- if (!NeedsUpdate(SeamlessClient.Version, Release.LatestVersion))
- return;
-
-
- //Ask client if they want to update!
- ShowDialog(Release, MainReleaseFile);
- }
- catch (Exception Ex)
- {
- SeamlessClient.TryShow(Ex.ToString());
- }
- }
-
-
- private bool TryGetMainRelease(GitZipFile[] Files, out GitZipFile Release)
- {
- Release = null;
-
- //Sanity saftey checks
- if (Files == null || Files.Length <= 0)
- return false;
-
- foreach (GitZipFile File in Files)
- {
- if (File.Name == "SeamlessClientPlugin.zip")
- {
- Release = File;
- return true;
- }
-
- }
-
- return false;
- }
-
-
- private void ShowDialog(GithubRelease Release, GitZipFile MainReleaseFile)
- {
- StringBuilder Response = new StringBuilder();
- Response.AppendLine($"Current version: {SeamlessClient.Version} Latest: {Release.LatestVersion}");
- Response.AppendLine($"Update: {Release.Name}");
- Response.AppendLine($"Description: {Release.Description}");
- Response.AppendLine($"Size: {MainReleaseFile.Size / 1000}kb");
- Response.AppendLine();
- Response.AppendLine("Warning: If you have a version less than latest seamless will be disabled to prevent crashes!");
- Response.AppendLine("(Clicking yes should restart your game)");
-
- DialogResult Result = MessageBox.Show(Response.ToString(), $"Download Seamless Client Plugin Update v{ Release.LatestVersion}?", MessageBoxButtons.YesNo, MessageBoxIcon.None, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly);
- SeamlessClient.TryShow(Response.ToString());
-
- if (Result == DialogResult.Yes)
- {
- SeamlessClient.TryShow("Client wants to update!");
- string DownloadPath = Path.Combine(PluginFolder, MainReleaseFile.Name);
- Client.DownloadFile(new Uri(MainReleaseFile.ZipURL), DownloadPath);
-
- if (!File.Exists(DownloadPath))
- {
- SeamlessClient.TryShow("Failed to download zip!");
- return;
- }
-
- if (ExtractAndReplace(DownloadPath))
- {
- StringBuilder ErrorResponse = new StringBuilder();
- ErrorResponse.AppendLine("There was an error during the extraction proccess! Check your logs for more information!");
- ErrorResponse.AppendLine();
- ErrorResponse.AppendLine("You can download manually here:");
- ErrorResponse.AppendLine(Release.GitHubPage);
- SeamlessClient.TryShow(ErrorResponse.ToString());
- MessageBox.Show(ErrorResponse.ToString(), $"Failed to update plugin to v{ Release.LatestVersion}!", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly);
- return;
- }
-
- }
- else
- {
- SeamlessClient.TryShow("Client skipped Update!");
- return;
- }
-
-
-
-
- }
-
-
-
-
-
- private void DeleteOLDFiles()
- {
- foreach (var OLDFile in Directory.GetFiles(PluginFolder, "*.old"))
- {
- File.Delete(OLDFile);
- }
-
- SeamlessClient.TryShow("Deleted all OLD update files");
-
- }
-
-
- private bool ExtractAndReplace(string ZipPath)
- {
- try
- {
-
- //Start extractor
- using (ZipArchive archive = ZipFile.OpenRead(ZipPath))
- {
- foreach (ZipArchiveEntry entry in archive.Entries)
- {
- string ExsistingFilePath = Path.Combine(PluginFolder, entry.Name);
- string OldFilePath = Path.Combine(PluginFolder, entry.Name + ".old");
-
- //No need to extract to files that dont exsist
- if (!File.Exists(ExsistingFilePath))
- continue;
-
- SeamlessClient.TryShow(ExsistingFilePath + "=>" + OldFilePath);
-
- if (File.Exists(OldFilePath))
- File.Delete(OldFilePath);
-
- File.Move(ExsistingFilePath, OldFilePath);
- entry.ExtractToFile(ExsistingFilePath, false);
- //File.Delete(OldFilePath);
- }
- }
-
- //Delete latest zip
- File.Delete(ZipPath);
-
- //Restart client
- SeamlessClient.TryShow("UpdateComplete!");
- SeamlessClient.RestartClientAfterUpdate();
- return true;
-
- }
- catch (Exception ex)
- {
- SeamlessClient.TryShow(ex.ToString());
- return false;
- }
- }
-
- private bool NeedsUpdate(string ClientVersion, string ServerVersion)
- {
-
-
- Version Client = new Version(ClientVersion);
- Version Latest = new Version(ServerVersion);
-
- var result = Client.CompareTo(Latest);
- if (result > 0)
- {
- //Console.WriteLine("Client is greater");
- SeamlessClient.TryShow("Client version is greater than latest! Wow!");
- return false;
- }
- else if (result < 0)
- {
- //Console.WriteLine("Latest is greater");
- SeamlessClient.TryShow("Client version is out-of-date!");
- return true;
- }
- else
- {
- //Console.WriteLine("versions are equal");
- SeamlessClient.TryShow("Client is up-to-date!");
- return false;
- }
- }
-
- }
-
-
- [ProtoContract]
- public class UpdateMessage
- {
- [ProtoMember(10)]
- public string ClientVersion = "";
-
- [ProtoMember(20)]
- public bool UpToDate = false;
-
- [ProtoMember(30)]
- public bool DownloadNewUpdate = false;
-
- [ProtoMember(40)]
- public string ServerVersion = "";
-
- [ProtoMember(50)]
- public string UpdateNotes = "";
-
-
-
- /* Misc Stuff incase I need it */
- [ProtoMember(60)]
- public byte[] XmlCharactersAsBytes;
-
-
- public UpdateMessage() { }
-
-
- }
-
-
- [DataContract]
- public class GithubRelease
- {
-
- [DataMember(Name = "url")]
- public string GitHubPage { get; set; }
-
- [DataMember(Name = "name")]
- public string Name { get; set; }
-
-
- [DataMember(Name = "tag_name")]
- public string LatestVersion { get; set; }
-
- [DataMember(Name = "prerelease")]
- public bool Beta { get; set; }
-
- [DataMember(Name = "body")]
- public string Description { get; set; }
-
- [DataMember(Name = "assets")]
- public GitZipFile[] Content { get; set; }
-
- }
-
- [DataContract]
- public class GitZipFile
- {
- [DataMember(Name = "name")]
- public string Name { get; set; }
-
- [DataMember(Name = "browser_download_url")]
- public string ZipURL { get; set; }
-
- [DataMember(Name = "size")]
- public int Size { get; set; }
-
- }
-}
From f30eb1b3b962ef64386fdb3b9127f5eb920fd6a0 Mon Sep 17 00:00:00 2001
From: Bob Da Ross <52760019+BobDaRoss@users.noreply.github.com>
Date: Sat, 19 Jun 2021 22:19:44 -0500
Subject: [PATCH 2/5] Revert "Removed updater again. Forgot I was in the wrong
branch"
This reverts commit 845bb0ecdd9699afde874912013a923a73f29aa7.
---
SeamlessClient.cs | 6 +
SeamlessClientPlugin.csproj | 1 +
Utilities/UpdateChecker.cs | 315 ++++++++++++++++++++++++++++++++++++
3 files changed, 322 insertions(+)
create mode 100644 Utilities/UpdateChecker.cs
diff --git a/SeamlessClient.cs b/SeamlessClient.cs
index 5f53c77..c650e20 100644
--- a/SeamlessClient.cs
+++ b/SeamlessClient.cs
@@ -122,6 +122,12 @@ namespace SeamlessClientPlugin
public void Init(object gameInstance)
{
+ Utilities.UpdateChecker Checker = new Utilities.UpdateChecker(false);
+ Task UpdateChecker = new Task(() => Checker.PingUpdateServer());
+ UpdateChecker.Start();
+
+
+
Patches.GetPatches();
TryShow("Running Seamless Client Plugin v[" + Version + "]");
PingTimer.Elapsed += PingTimer_Elapsed;
diff --git a/SeamlessClientPlugin.csproj b/SeamlessClientPlugin.csproj
index 943e1bf..936fa49 100644
--- a/SeamlessClientPlugin.csproj
+++ b/SeamlessClientPlugin.csproj
@@ -167,6 +167,7 @@
+
diff --git a/Utilities/UpdateChecker.cs b/Utilities/UpdateChecker.cs
new file mode 100644
index 0000000..7cdc29f
--- /dev/null
+++ b/Utilities/UpdateChecker.cs
@@ -0,0 +1,315 @@
+using ProtoBuf;
+using Sandbox.Graphics.GUI;
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.IO.Compression;
+using System.Linq;
+using System.Net;
+using System.Net.Sockets;
+using System.Reflection;
+using System.Runtime.Serialization;
+using System.Runtime.Serialization.Json;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+using System.Xml.Serialization;
+namespace SeamlessClientPlugin.Utilities
+{
+ public class UpdateChecker
+ {
+ public string PluginFolder;
+ public string CurrentVersion;
+ public bool DownloadUpdate;
+ private string GitHubAPILink = "https://api.github.com/repos/Casimir255/SeamlessClientPlugin/releases/latest";
+
+ private WebClient Client;
+
+
+
+
+ public UpdateChecker(bool AutoUpdate)
+ {
+ PluginFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
+ Client = new WebClient();
+ DeleteOLDFiles();
+ }
+
+
+
+
+ public void PingUpdateServer()
+ {
+ try
+ {
+ //Create new webclient and insert a user-agent
+ Client.Headers["User-Agent"] = "SeamlessClientUpdater";
+
+ //Grap API data for latest seamless client release
+ string data = Client.DownloadString(GitHubAPILink);
+
+ //SeamlessClient.TryShow(data);
+
+
+ DataContractJsonSerializer s = new DataContractJsonSerializer(typeof(GithubRelease));
+
+ GithubRelease Release;
+ using (MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(data)))
+ {
+ Release = (GithubRelease)s.ReadObject(stream);
+ }
+
+
+ if (Release == null || !TryGetMainRelease(Release.Content, out GitZipFile MainReleaseFile))
+ return;
+
+
+ //Check if the client needs an update based off of github latest release version
+
+ if (!NeedsUpdate(SeamlessClient.Version, Release.LatestVersion))
+ return;
+
+
+ //Ask client if they want to update!
+ ShowDialog(Release, MainReleaseFile);
+ }
+ catch (Exception Ex)
+ {
+ SeamlessClient.TryShow(Ex.ToString());
+ }
+ }
+
+
+ private bool TryGetMainRelease(GitZipFile[] Files, out GitZipFile Release)
+ {
+ Release = null;
+
+ //Sanity saftey checks
+ if (Files == null || Files.Length <= 0)
+ return false;
+
+ foreach (GitZipFile File in Files)
+ {
+ if (File.Name == "SeamlessClientPlugin.zip")
+ {
+ Release = File;
+ return true;
+ }
+
+ }
+
+ return false;
+ }
+
+
+ private void ShowDialog(GithubRelease Release, GitZipFile MainReleaseFile)
+ {
+ StringBuilder Response = new StringBuilder();
+ Response.AppendLine($"Current version: {SeamlessClient.Version} Latest: {Release.LatestVersion}");
+ Response.AppendLine($"Update: {Release.Name}");
+ Response.AppendLine($"Description: {Release.Description}");
+ Response.AppendLine($"Size: {MainReleaseFile.Size / 1000}kb");
+ Response.AppendLine();
+ Response.AppendLine("Warning: If you have a version less than latest seamless will be disabled to prevent crashes!");
+ Response.AppendLine("(Clicking yes should restart your game)");
+
+ DialogResult Result = MessageBox.Show(Response.ToString(), $"Download Seamless Client Plugin Update v{ Release.LatestVersion}?", MessageBoxButtons.YesNo, MessageBoxIcon.None, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly);
+ SeamlessClient.TryShow(Response.ToString());
+
+ if (Result == DialogResult.Yes)
+ {
+ SeamlessClient.TryShow("Client wants to update!");
+ string DownloadPath = Path.Combine(PluginFolder, MainReleaseFile.Name);
+ Client.DownloadFile(new Uri(MainReleaseFile.ZipURL), DownloadPath);
+
+ if (!File.Exists(DownloadPath))
+ {
+ SeamlessClient.TryShow("Failed to download zip!");
+ return;
+ }
+
+ if (ExtractAndReplace(DownloadPath))
+ {
+ StringBuilder ErrorResponse = new StringBuilder();
+ ErrorResponse.AppendLine("There was an error during the extraction proccess! Check your logs for more information!");
+ ErrorResponse.AppendLine();
+ ErrorResponse.AppendLine("You can download manually here:");
+ ErrorResponse.AppendLine(Release.GitHubPage);
+ SeamlessClient.TryShow(ErrorResponse.ToString());
+ MessageBox.Show(ErrorResponse.ToString(), $"Failed to update plugin to v{ Release.LatestVersion}!", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly);
+ return;
+ }
+
+ }
+ else
+ {
+ SeamlessClient.TryShow("Client skipped Update!");
+ return;
+ }
+
+
+
+
+ }
+
+
+
+
+
+ private void DeleteOLDFiles()
+ {
+ foreach (var OLDFile in Directory.GetFiles(PluginFolder, "*.old"))
+ {
+ File.Delete(OLDFile);
+ }
+
+ SeamlessClient.TryShow("Deleted all OLD update files");
+
+ }
+
+
+ private bool ExtractAndReplace(string ZipPath)
+ {
+ try
+ {
+
+ //Start extractor
+ using (ZipArchive archive = ZipFile.OpenRead(ZipPath))
+ {
+ foreach (ZipArchiveEntry entry in archive.Entries)
+ {
+ string ExsistingFilePath = Path.Combine(PluginFolder, entry.Name);
+ string OldFilePath = Path.Combine(PluginFolder, entry.Name + ".old");
+
+ //No need to extract to files that dont exsist
+ if (!File.Exists(ExsistingFilePath))
+ continue;
+
+ SeamlessClient.TryShow(ExsistingFilePath + "=>" + OldFilePath);
+
+ if (File.Exists(OldFilePath))
+ File.Delete(OldFilePath);
+
+ File.Move(ExsistingFilePath, OldFilePath);
+ entry.ExtractToFile(ExsistingFilePath, false);
+ //File.Delete(OldFilePath);
+ }
+ }
+
+ //Delete latest zip
+ File.Delete(ZipPath);
+
+ //Restart client
+ SeamlessClient.TryShow("UpdateComplete!");
+ SeamlessClient.RestartClientAfterUpdate();
+ return true;
+
+ }
+ catch (Exception ex)
+ {
+ SeamlessClient.TryShow(ex.ToString());
+ return false;
+ }
+ }
+
+ private bool NeedsUpdate(string ClientVersion, string ServerVersion)
+ {
+
+
+ Version Client = new Version(ClientVersion);
+ Version Latest = new Version(ServerVersion);
+
+ var result = Client.CompareTo(Latest);
+ if (result > 0)
+ {
+ //Console.WriteLine("Client is greater");
+ SeamlessClient.TryShow("Client version is greater than latest! Wow!");
+ return false;
+ }
+ else if (result < 0)
+ {
+ //Console.WriteLine("Latest is greater");
+ SeamlessClient.TryShow("Client version is out-of-date!");
+ return true;
+ }
+ else
+ {
+ //Console.WriteLine("versions are equal");
+ SeamlessClient.TryShow("Client is up-to-date!");
+ return false;
+ }
+ }
+
+ }
+
+
+ [ProtoContract]
+ public class UpdateMessage
+ {
+ [ProtoMember(10)]
+ public string ClientVersion = "";
+
+ [ProtoMember(20)]
+ public bool UpToDate = false;
+
+ [ProtoMember(30)]
+ public bool DownloadNewUpdate = false;
+
+ [ProtoMember(40)]
+ public string ServerVersion = "";
+
+ [ProtoMember(50)]
+ public string UpdateNotes = "";
+
+
+
+ /* Misc Stuff incase I need it */
+ [ProtoMember(60)]
+ public byte[] XmlCharactersAsBytes;
+
+
+ public UpdateMessage() { }
+
+
+ }
+
+
+ [DataContract]
+ public class GithubRelease
+ {
+
+ [DataMember(Name = "url")]
+ public string GitHubPage { get; set; }
+
+ [DataMember(Name = "name")]
+ public string Name { get; set; }
+
+
+ [DataMember(Name = "tag_name")]
+ public string LatestVersion { get; set; }
+
+ [DataMember(Name = "prerelease")]
+ public bool Beta { get; set; }
+
+ [DataMember(Name = "body")]
+ public string Description { get; set; }
+
+ [DataMember(Name = "assets")]
+ public GitZipFile[] Content { get; set; }
+
+ }
+
+ [DataContract]
+ public class GitZipFile
+ {
+ [DataMember(Name = "name")]
+ public string Name { get; set; }
+
+ [DataMember(Name = "browser_download_url")]
+ public string ZipURL { get; set; }
+
+ [DataMember(Name = "size")]
+ public int Size { get; set; }
+
+ }
+}
From 840421f7afbfc535ccaec866638d7380a0c0bccb Mon Sep 17 00:00:00 2001
From: Bob Da Ross <52760019+BobDaRoss@users.noreply.github.com>
Date: Sat, 19 Jun 2021 22:21:06 -0500
Subject: [PATCH 3/5] Removed updater (Seems to be the only way to do this)
---
SeamlessClient.cs | 6 -
SeamlessClientPlugin.csproj | 1 -
Utilities/UpdateChecker.cs | 341 ------------------------------------
3 files changed, 348 deletions(-)
delete mode 100644 Utilities/UpdateChecker.cs
diff --git a/SeamlessClient.cs b/SeamlessClient.cs
index 1214aec..f49840d 100644
--- a/SeamlessClient.cs
+++ b/SeamlessClient.cs
@@ -122,12 +122,6 @@ namespace SeamlessClientPlugin
public void Init(object gameInstance)
{
- Utilities.UpdateChecker Checker = new Utilities.UpdateChecker(false);
- Task UpdateChecker = new Task(() => Checker.PingUpdateServer());
- UpdateChecker.Start();
-
-
-
Patches.GetPatches();
TryShow("Running Seamless Client Plugin v[" + Version + "]");
PingTimer.Elapsed += PingTimer_Elapsed;
diff --git a/SeamlessClientPlugin.csproj b/SeamlessClientPlugin.csproj
index 936fa49..943e1bf 100644
--- a/SeamlessClientPlugin.csproj
+++ b/SeamlessClientPlugin.csproj
@@ -167,7 +167,6 @@
-
diff --git a/Utilities/UpdateChecker.cs b/Utilities/UpdateChecker.cs
deleted file mode 100644
index 449f5ea..0000000
--- a/Utilities/UpdateChecker.cs
+++ /dev/null
@@ -1,341 +0,0 @@
-using ProtoBuf;
-using Sandbox.Graphics.GUI;
-using System;
-using System.Collections.Generic;
-using System.Diagnostics;
-using System.IO;
-using System.IO.Compression;
-using System.Linq;
-using System.Net;
-using System.Net.Sockets;
-using System.Reflection;
-using System.Runtime.Serialization;
-using System.Runtime.Serialization.Json;
-using System.Text;
-using System.Threading.Tasks;
-using System.Windows.Forms;
-using System.Xml.Serialization;
-namespace SeamlessClientPlugin.Utilities
-{
- public class UpdateChecker
- {
- public string PluginFolder;
- public string CurrentVersion;
- public bool DownloadUpdate;
- private const string GitHubAPILink = "https://api.github.com/repos/Casimir255/SeamlessClientPlugin/releases/latest";
-
- private WebClient Client;
-
-
-
-
- public UpdateChecker(bool AutoUpdate)
- {
- PluginFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
- Client = new WebClient();
- DeleteOLDFiles();
- }
-
- private static void RestartClientAfterUpdate()
- {
- try
- {
- SeamlessClient.TryShow("Restarting Client!");
- string exe = Assembly.GetEntryAssembly().Location;
- Process currentProcess = Process.GetCurrentProcess();
-
- string[] CommandArgs = Environment.GetCommandLineArgs();
- string NewCommandLine = "";
- for (int i = 1; i < CommandArgs.Length; i++)
- {
- NewCommandLine += " " + CommandArgs[i];
- }
-
- SeamlessClient.TryShow(NewCommandLine);
- Process.Start(exe, NewCommandLine);
- currentProcess.Kill();
- }
- catch
- {
- SeamlessClient.TryShow("Restarting Client error!");
- }
- }
-
-
-
-
- public void PingUpdateServer()
- {
- try
- {
- //Create new webclient and insert a user-agent
- Client.Headers["User-Agent"] = "SeamlessClientUpdater";
-
- //Grap API data for latest seamless client release
- string data = Client.DownloadString(GitHubAPILink);
-
- //SeamlessClient.TryShow(data);
-
-
- DataContractJsonSerializer s = new DataContractJsonSerializer(typeof(GithubRelease));
-
- GithubRelease Release;
- using (MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(data)))
- {
- Release = (GithubRelease)s.ReadObject(stream);
- }
-
-
- if (Release == null || !TryGetMainRelease(Release.Content, out GitZipFile MainReleaseFile))
- return;
-
-
- //Check if the client needs an update based off of github latest release version
-
- if (!NeedsUpdate(SeamlessClient.Version, Release.LatestVersion))
- return;
-
-
- //Ask client if they want to update!
- ShowDialog(Release, MainReleaseFile);
- }
- catch (Exception Ex)
- {
- SeamlessClient.TryShow(Ex.ToString());
- }
- }
-
-
- private bool TryGetMainRelease(GitZipFile[] Files, out GitZipFile Release)
- {
- Release = null;
-
- //Sanity saftey checks
- if (Files == null || Files.Length <= 0)
- return false;
-
- foreach (GitZipFile File in Files)
- {
- if (File.Name == "SeamlessClientPlugin.zip")
- {
- Release = File;
- return true;
- }
-
- }
-
- return false;
- }
-
-
- private void ShowDialog(GithubRelease Release, GitZipFile MainReleaseFile)
- {
- StringBuilder Response = new StringBuilder();
- Response.AppendLine($"Current version: {SeamlessClient.Version} Latest: {Release.LatestVersion}");
- Response.AppendLine($"Update: {Release.Name}");
- Response.AppendLine($"Description: {Release.Description}");
- Response.AppendLine($"Size: {MainReleaseFile.Size / 1000}kb");
- Response.AppendLine();
- Response.AppendLine("Warning: If you have a version less than latest seamless will be disabled to prevent crashes!");
- Response.AppendLine("(Clicking yes should restart your game)");
-
- DialogResult Result = MessageBox.Show(Response.ToString(), $"Download Seamless Client Plugin Update v{ Release.LatestVersion}?", MessageBoxButtons.YesNo, MessageBoxIcon.None, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly);
- SeamlessClient.TryShow(Response.ToString());
-
- if (Result == DialogResult.Yes)
- {
- SeamlessClient.TryShow("Client wants to update!");
- string DownloadPath = Path.Combine(PluginFolder, MainReleaseFile.Name);
- Client.DownloadFile(new Uri(MainReleaseFile.ZipURL), DownloadPath);
-
- if (!File.Exists(DownloadPath))
- {
- SeamlessClient.TryShow("Failed to download zip!");
- return;
- }
-
- if (ExtractAndReplace(DownloadPath))
- {
- StringBuilder ErrorResponse = new StringBuilder();
- ErrorResponse.AppendLine("There was an error during the extraction proccess! Check your logs for more information!");
- ErrorResponse.AppendLine();
- ErrorResponse.AppendLine("You can download manually here:");
- ErrorResponse.AppendLine(Release.GitHubPage);
- SeamlessClient.TryShow(ErrorResponse.ToString());
- MessageBox.Show(ErrorResponse.ToString(), $"Failed to update plugin to v{ Release.LatestVersion}!", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly);
- return;
- }
-
- }
- else
- {
- SeamlessClient.TryShow("Client skipped Update!");
- return;
- }
-
-
-
-
- }
-
-
-
-
-
- private void DeleteOLDFiles()
- {
- foreach (var OLDFile in Directory.GetFiles(PluginFolder, "*.old"))
- {
- File.Delete(OLDFile);
- }
-
- SeamlessClient.TryShow("Deleted all OLD update files");
-
- }
-
-
- private bool ExtractAndReplace(string ZipPath)
- {
- try
- {
-
- //Start extractor
- using (ZipArchive archive = ZipFile.OpenRead(ZipPath))
- {
- foreach (ZipArchiveEntry entry in archive.Entries)
- {
- string ExsistingFilePath = Path.Combine(PluginFolder, entry.Name);
- string OldFilePath = Path.Combine(PluginFolder, entry.Name + ".old");
-
- //No need to extract to files that dont exsist
- if (!File.Exists(ExsistingFilePath))
- continue;
-
- SeamlessClient.TryShow(ExsistingFilePath + "=>" + OldFilePath);
-
- if (File.Exists(OldFilePath))
- File.Delete(OldFilePath);
-
- File.Move(ExsistingFilePath, OldFilePath);
- entry.ExtractToFile(ExsistingFilePath, false);
- //File.Delete(OldFilePath);
- }
- }
-
- //Delete latest zip
- File.Delete(ZipPath);
-
- //Restart client
- SeamlessClient.TryShow("UpdateComplete!");
- RestartClientAfterUpdate();
- return true;
-
- }
- catch (Exception ex)
- {
- SeamlessClient.TryShow(ex.ToString());
- return false;
- }
- }
-
- private bool NeedsUpdate(string ClientVersion, string ServerVersion)
- {
-
-
- Version Client = new Version(ClientVersion);
- Version Latest = new Version(ServerVersion);
-
- var result = Client.CompareTo(Latest);
- if (result > 0)
- {
- //Console.WriteLine("Client is greater");
- SeamlessClient.TryShow("Client version is greater than latest! Wow!");
- return false;
- }
- else if (result < 0)
- {
- //Console.WriteLine("Latest is greater");
- SeamlessClient.TryShow("Client version is out-of-date!");
- return true;
- }
- else
- {
- //Console.WriteLine("versions are equal");
- SeamlessClient.TryShow("Client is up-to-date!");
- return false;
- }
- }
-
- }
-
-
- [ProtoContract]
- public class UpdateMessage
- {
- [ProtoMember(10)]
- public string ClientVersion = "";
-
- [ProtoMember(20)]
- public bool UpToDate = false;
-
- [ProtoMember(30)]
- public bool DownloadNewUpdate = false;
-
- [ProtoMember(40)]
- public string ServerVersion = "";
-
- [ProtoMember(50)]
- public string UpdateNotes = "";
-
-
-
- /* Misc Stuff incase I need it */
- [ProtoMember(60)]
- public byte[] XmlCharactersAsBytes;
-
-
- public UpdateMessage() { }
-
-
- }
-
-
- [DataContract]
- public class GithubRelease
- {
-
- [DataMember(Name = "url")]
- public string GitHubPage { get; set; }
-
- [DataMember(Name = "name")]
- public string Name { get; set; }
-
-
- [DataMember(Name = "tag_name")]
- public string LatestVersion { get; set; }
-
- [DataMember(Name = "prerelease")]
- public bool Beta { get; set; }
-
- [DataMember(Name = "body")]
- public string Description { get; set; }
-
- [DataMember(Name = "assets")]
- public GitZipFile[] Content { get; set; }
-
- }
-
- [DataContract]
- public class GitZipFile
- {
- [DataMember(Name = "name")]
- public string Name { get; set; }
-
- [DataMember(Name = "browser_download_url")]
- public string ZipURL { get; set; }
-
- [DataMember(Name = "size")]
- public int Size { get; set; }
-
- }
-}
From 2c12c9658e1f81609fd46822128bc2eeaa2ff45f Mon Sep 17 00:00:00 2001
From: Bob Da Ross <52760019+BobDaRoss@users.noreply.github.com>
Date: Wed, 28 Jul 2021 23:06:02 -0500
Subject: [PATCH 4/5] Patched for Heavy-Industry update
---
Properties/AssemblyInfo.cs | 4 ++--
SeamlessClient.cs | 7 ++++++-
SeamlessTransfer/SwitchServers.cs | 20 +++++++++++++++-----
3 files changed, 23 insertions(+), 8 deletions(-)
diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs
index 6aaef64..94e8e28 100644
--- a/Properties/AssemblyInfo.cs
+++ b/Properties/AssemblyInfo.cs
@@ -33,6 +33,6 @@ using System.Runtime.InteropServices;
// 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.3.0.1")]
-[assembly: AssemblyFileVersion("1.3.0.1")]
+[assembly: AssemblyVersion("1.3.0.3")]
+[assembly: AssemblyFileVersion("1.3.0.3")]
[assembly: NeutralResourcesLanguage("en")]
diff --git a/SeamlessClient.cs b/SeamlessClient.cs
index f49840d..0a0dbfb 100644
--- a/SeamlessClient.cs
+++ b/SeamlessClient.cs
@@ -106,7 +106,7 @@ namespace SeamlessClientPlugin
- public static string Version = "1.3.01";
+ public static string Version = "1.3.03";
public static bool Debug = false;
private static bool Initilized = false;
@@ -139,6 +139,9 @@ namespace SeamlessClientPlugin
TryShow("Initilizing Communications!");
RunInitilizations();
}
+
+
+
//OnNewPlayerRequest
//throw new NotImplementedException();
}
@@ -152,6 +155,8 @@ namespace SeamlessClientPlugin
// Terrible way to make sure server knows we are running seamless client
try
{
+
+
ClientMessage PingServer = new ClientMessage(ClientMessageType.FirstJoin);
MyAPIGateway.Multiplayer?.SendMessageToServer(SeamlessClientNetID, Utilities.Utility.Serialize(PingServer));
}
diff --git a/SeamlessTransfer/SwitchServers.cs b/SeamlessTransfer/SwitchServers.cs
index 7cd7a56..d616365 100644
--- a/SeamlessTransfer/SwitchServers.cs
+++ b/SeamlessTransfer/SwitchServers.cs
@@ -6,6 +6,7 @@ using Sandbox.Game.Entities;
using Sandbox.Game.Gui;
using Sandbox.Game.GUI;
using Sandbox.Game.Multiplayer;
+using Sandbox.Game.SessionComponents;
using Sandbox.Game.World;
using Sandbox.Game.World.Generator;
using Sandbox.ModAPI;
@@ -34,6 +35,8 @@ namespace SeamlessClientPlugin.SeamlessTransfer
public MyGameServerItem TargetServer { get; }
public MyObjectBuilder_World TargetWorld { get; }
+ private string OldArmorSkin { get; set; } = string.Empty;
+
public SwitchServers(MyGameServerItem TargetServer, MyObjectBuilder_World TargetWorld)
{
@@ -44,6 +47,8 @@ namespace SeamlessClientPlugin.SeamlessTransfer
public void BeginSwitch()
{
+ OldArmorSkin = MySession.Static.LocalHumanPlayer.BuildArmorSkin;
+
MySandboxGame.Static.Invoke(delegate
{
//Set camera controller to fixed spectator
@@ -74,6 +79,8 @@ namespace SeamlessClientPlugin.SeamlessTransfer
MyMultiplayer.Static = Utility.CastToReflected(instance, Patches.ClientType);
MyMultiplayer.Static.ExperimentalMode = true;
+
+
// Set the new SyncLayer to the MySession.Static.SyncLayer
Patches.MySessionLayer.SetValue(MySession.Static, MyMultiplayer.Static.SyncLayer);
@@ -122,6 +129,10 @@ namespace SeamlessClientPlugin.SeamlessTransfer
MyModAPIHelper.Initialize();
// Allow the game to start proccessing incoming messages in the buffer
MyMultiplayer.Static.StartProcessingClientMessages();
+
+ //Recreate all controls... Will fix weird gui/paint/crap
+ MyGuiScreenHudSpace.Static.RecreateControls(true);
+ //MySession.Static.LocalHumanPlayer.BuildArmorSkin = OldArmorSkin;
}
@@ -277,7 +288,7 @@ namespace SeamlessClientPlugin.SeamlessTransfer
private void LoadConnectedClients()
{
-
+
Patches.LoadMembersFromWorld.Invoke(MySession.Static, new object[] { TargetWorld, MyMultiplayer.Static });
@@ -320,10 +331,6 @@ namespace SeamlessClientPlugin.SeamlessTransfer
SeamlessClient.TryShow("OnlinePlayers: " + MySession.Static.Players.GetOnlinePlayers().Count);
SeamlessClient.TryShow("Loading Complete!");
-
-
- //Recreate all controls... Will fix weird gui/paint/crap
- MyGuiScreenHudSpace.Static.RecreateControls(true);
}
private void MyMultiplayer_PendingReplicablesDone()
@@ -378,6 +385,9 @@ namespace SeamlessClientPlugin.SeamlessTransfer
if (MyMultiplayer.Static == null)
throw new Exception("MyMultiplayer.Static is null on unloading? dafuq?");
+ //Try and close the quest log
+ MySessionComponentIngameHelp component = MySession.Static.GetComponent();
+ component?.TryCancelObjective();
//Clear all old players and clients.
Sync.Clients.Clear();
From 5d89324b92fe451248735952b8d18d5de7cf72ee Mon Sep 17 00:00:00 2001
From: Bob Da Ross <52760019+BobDaRoss@users.noreply.github.com>
Date: Wed, 28 Jul 2021 23:15:07 -0500
Subject: [PATCH 5/5] Latest version
---
Properties/AssemblyInfo.cs | 4 ++--
SeamlessClient.cs | 2 +-
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs
index 94e8e28..b02e6a9 100644
--- a/Properties/AssemblyInfo.cs
+++ b/Properties/AssemblyInfo.cs
@@ -33,6 +33,6 @@ using System.Runtime.InteropServices;
// 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.3.0.3")]
-[assembly: AssemblyFileVersion("1.3.0.3")]
+[assembly: AssemblyVersion("1.3.0.4")]
+[assembly: AssemblyFileVersion("1.3.0.4")]
[assembly: NeutralResourcesLanguage("en")]
diff --git a/SeamlessClient.cs b/SeamlessClient.cs
index 0a0dbfb..1e616cd 100644
--- a/SeamlessClient.cs
+++ b/SeamlessClient.cs
@@ -106,7 +106,7 @@ namespace SeamlessClientPlugin
- public static string Version = "1.3.03";
+ public static string Version = "1.3.04";
public static bool Debug = false;
private static bool Initilized = false;