Skip to content

Commit

Permalink
1.3.6 beginnings
Browse files Browse the repository at this point in the history
- Added remote assembly hash startup functionality
  • Loading branch information
DaXcess committed Oct 31, 2024
1 parent 10295be commit 10a70cf
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 2 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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**:
Expand Down
2 changes: 1 addition & 1 deletion LCVR.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFramework>netstandard2.1</TargetFramework>
<AssemblyName>LCVR</AssemblyName>
<Description>Collecting Scrap in VR</Description>
<Version>1.3.5</Version>
<Version>1.3.6</Version>
<Authors>DaXcess</Authors>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<LangVersion>12.0</LangVersion>
Expand Down
20 changes: 19 additions & 1 deletion Source/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Globalization;
using System.IO;
using System.Linq;
using System.Net;
using System.Reflection;
using UnityEngine;
using UnityEngine.InputSystem;
Expand All @@ -25,19 +26,22 @@ 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";
#else
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; }
Expand Down Expand Up @@ -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);
}

Expand Down
14 changes: 14 additions & 0 deletions Source/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using System.Text;
using System;
using System.Collections;
using System.Linq;
using GameNetcodeStuff;

namespace LCVR;
Expand All @@ -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());
Expand Down

0 comments on commit 10a70cf

Please sign in to comment.