From 10a70cfe93d0d1ef080a3069863c8ca1f303e441 Mon Sep 17 00:00:00 2001 From: DaXcess Date: Thu, 31 Oct 2024 15:47:04 +0100 Subject: [PATCH] 1.3.6 beginnings - Added remote assembly hash startup functionality --- CHANGELOG.md | 6 ++++++ LCVR.csproj | 2 +- Source/Plugin.cs | 20 +++++++++++++++++++- Source/Utils.cs | 14 ++++++++++++++ 4 files changed, 40 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3f33c8fd..372c8b9c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +# 1.3.6 + +**Additions**: +- Added support for V67 +- Added startup functionality that fetches game versions from a remote resource, allowing easier LCVR compatibility updates with less downtime + # 1.3.5 **Additions**: diff --git a/LCVR.csproj b/LCVR.csproj index f414707f..bd66b01f 100644 --- a/LCVR.csproj +++ b/LCVR.csproj @@ -4,7 +4,7 @@ netstandard2.1 LCVR Collecting Scrap in VR - 1.3.5 + 1.3.6 DaXcess true 12.0 diff --git a/Source/Plugin.cs b/Source/Plugin.cs index e0cd5c3c..d0b20142 100644 --- a/Source/Plugin.cs +++ b/Source/Plugin.cs @@ -6,6 +6,7 @@ using System.Globalization; using System.IO; using System.Linq; +using System.Net; using System.Reflection; using UnityEngine; using UnityEngine.InputSystem; @@ -25,7 +26,7 @@ public class Plugin : BaseUnityPlugin { public const string PLUGIN_GUID = "io.daxcess.lcvr"; public const string PLUGIN_NAME = "LCVR"; - public const string PLUGIN_VERSION = "1.3.5"; + public const string PLUGIN_VERSION = "1.3.6"; #if DEBUG private const string SKIP_CHECKSUM_VAR = $"--lcvr-skip-checksum={PLUGIN_VERSION}-dev"; @@ -33,11 +34,14 @@ public class Plugin : BaseUnityPlugin private const string SKIP_CHECKSUM_VAR = $"--lcvr-skip-checksum={PLUGIN_VERSION}"; #endif + private const string HASHES_OVERRIDE_URL = "https://gist.githubusercontent.com/DaXcess/72c4fbac0f18c76ebc99e6b769f19389/raw/e65b6d68c37244b1909e9d6aa992ae39d9a34922/LCVR%2520Game%2520Hashes"; + private readonly string[] GAME_ASSEMBLY_HASHES = [ "BFF45683C267F402429049EF7D8095C078D5CD534E5300E56317ACB6056D70FB", // V64 "A6BDE2EB39028B36CB1667DCFB4ED10F688FB3FF72E71491AC25C5CB47A7EF6C", // V64.1 "B0BC7D3392FDAD3BB6515C0769363A51FF3599E67325FAE153948E0B82EB7596", // V66 + "TBD", // V67 ]; public new static Config Config { get; private set; } @@ -163,6 +167,20 @@ private bool VerifyGameVersion() var location = Path.Combine(Paths.ManagedPath, "Assembly-CSharp.dll"); var hash = BitConverter.ToString(Utils.ComputeHash(File.ReadAllBytes(location))).Replace("-", ""); + // Attempt to fetch a gist with known working assembly hashes + // This allows me to keep LCVR up and running if the game updates, without code changes + try + { + var contents = new WebClient().DownloadString(HASHES_OVERRIDE_URL); + var hashes = Utils.ParseConfig(contents); + + return hashes.Contains(hash); + } + catch + { + // If anything fails, fall back to local lookup + } + return GAME_ASSEMBLY_HASHES.Contains(hash); } diff --git a/Source/Utils.cs b/Source/Utils.cs index 437b9094..1a9719ed 100644 --- a/Source/Utils.cs +++ b/Source/Utils.cs @@ -10,6 +10,7 @@ using System.Text; using System; using System.Collections; +using System.Linq; using GameNetcodeStuff; namespace LCVR; @@ -31,6 +32,19 @@ public static byte[] ComputeHash(byte[] input) return sha.ComputeHash(input); } + public static string[] ParseConfig(string content) + { + var lines = content.Split("\n", StringSplitOptions.RemoveEmptyEntries); + + return (from line in lines + where !line.TrimStart().StartsWith("#") + let commentIndex = line.IndexOf('#') + select commentIndex >= 0 ? line[..commentIndex].Trim() : line.Trim() + into parsedLine + where !string.IsNullOrEmpty(parsedLine) + select parsedLine).ToArray(); + } + public static string FormatPascalAndAcronym(string input) { var builder = new StringBuilder(input[0].ToString());