Skip to content

Commit

Permalink
Merge pull request #276 from DaXcess/dev
Browse files Browse the repository at this point in the history
Update LCVR to v1.3.6
  • Loading branch information
DaXcess authored Oct 31, 2024
2 parents 10295be + 1d8bace commit 1007309
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 8 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
47 changes: 40 additions & 7 deletions 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/LCVR%2520Game%2520Hashes";

private readonly string[] GAME_ASSEMBLY_HASHES =
[
"BFF45683C267F402429049EF7D8095C078D5CD534E5300E56317ACB6056D70FB", // V64
"A6BDE2EB39028B36CB1667DCFB4ED10F688FB3FF72E71491AC25C5CB47A7EF6C", // V64.1
"B0BC7D3392FDAD3BB6515C0769363A51FF3599E67325FAE153948E0B82EB7596", // V66
"B644AD19F3CE1E82071AC5F45D1E96D76B9FC06C11763381E1979BCDC5889607", // V67
];

public new static Config Config { get; private set; }
Expand Down Expand Up @@ -113,7 +117,7 @@ private void Awake()
}
}

if (!LoadEarlyRuntimeDependencies())
if (!PreloadRuntimeDependencies())
{
Logger.LogError("Disabling mod because required runtime dependencies could not be loaded!");
return;
Expand Down Expand Up @@ -163,10 +167,39 @@ private bool VerifyGameVersion()
var location = Path.Combine(Paths.ManagedPath, "Assembly-CSharp.dll");
var hash = BitConverter.ToString(Utils.ComputeHash(File.ReadAllBytes(location))).Replace("-", "");

return GAME_ASSEMBLY_HASHES.Contains(hash);
// Attempt local lookup first
if (GAME_ASSEMBLY_HASHES.Contains(hash))
{
Logger.LogInfo("Game version verified using local hashes");

return true;
}

Logger.LogWarning("Failed to verify game version using local hashes, checking remotely for updated hashes...");

// 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);

if (!hashes.Contains(hash))
return false;

Logger.LogInfo("Game version verified using remote hashes");

return true;
}
catch (Exception ex)
{
Logger.LogWarning($"Failed to verify using remote hashes: {ex.Message}");

return false;
}
}

private bool LoadEarlyRuntimeDependencies()
private bool PreloadRuntimeDependencies()
{
try
{
Expand All @@ -180,22 +213,22 @@ private bool LoadEarlyRuntimeDependencies()
if (filename is "UnityOpenXR.dll" or "openxr_loader.dll")
continue;

Logger.LogDebug($"Early loading {filename}");
Logger.LogDebug($"Preloading '{filename}'...");

try
{
Assembly.LoadFile(file);
}
catch (Exception ex)
{
Logger.LogWarning($"Failed to early load {filename}: {ex.Message}");
Logger.LogWarning($"Failed to preload '{filename}': {ex.Message}");
}
}
}
catch (Exception ex)
{
Logger.LogError(
$"Unexpected error occured while loading early runtime dependencies (incorrect folder structure?): {ex.Message}");
$"Unexpected error occured while preloading runtime dependencies (incorrect folder structure?): {ex.Message}");
return false;
}

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 1007309

Please sign in to comment.