This document is about: QUANTUM 1
SWITCH TO

Separating Build Versions

Article was written against Quantum version 1.2.0

If you want to prevent different game versions connecting to the same room, open UIConnect.cs and replace this line:

C#

PhotonNetwork.ConnectUsingSettings("your_game_version");

What is "your_game_version"?
As a quick hack, you can use the SHA256 sum of the built quantum state and systems dlls:

C#

PhotonNetwork.ConnectUsingSettings(
 "your_game_" + Checksums.quantum_state_dll + "_" + Checksums.quantum_systems_dll
);

Checksums come from a little utility (build it as .NET exe):

C#

using System.IO;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Text.RegularExpressions;

namespace checksum {
  static class Program {
    static void Main(string[] args) {
      var target = args[0];
      
      var re = new Regex("\\W");
      var checksums = string.Join(",\n", args.Skip(1).Select(path => {
        var constName = re.Replace(Path.GetFileName(path), "_");
        var bytes = File.ReadAllBytes(path);
        return $"{constName} = \"{toHex(SHA256.Create().ComputeHash(bytes))}\"";
      }));
      
      var code = $@"
namespace Quantum {{
  public static class Checksums {{
    public const string
{checksums}
      ;
  }}
}}
";
      File.WriteAllText(target, code);
    }
    
    static string toHex(byte[] bytes, bool upperCase = false) {
      var result = new StringBuilder(bytes.Length * 2);

      for (var i = 0; i < bytes.Length; i++)
        result.Append(bytes[i].ToString(upperCase ? "X2" : "x2"));

      return result.ToString();
    }
  }
}

Put the compiled exe into tools_tlp\checksum.exe.
Then, in quantum.systems.csproj, append this to the definition

XML

  <!-- Only 1.1.8 does not use codegen_unity\quantum.codegen.unity.host.exe, just delete that line -->
  <PropertyGroup Condition="'$(OS)' == 'Unix'">
    <PostBuildEvent>mono "$(SolutionDir)..\tools_tlp\checksum.exe" "$(SolutionDir)..\quantum_unity\Assets\Plugins\GeneratedChecksums.cs" "$(TargetDir)\quantum.state.dll" "$(TargetDir)\quantum.systems.dll"
 mono "$(SolutionDir)..\tools\codegen_unity\quantum.codegen.unity.host.exe" "$(TargetDir)\quantum.state.dll" "$(SolutionDir)..\quantum_unity\Assets"
    </PostBuildEvent>
  </PropertyGroup>
  <PropertyGroup Condition="'$(OS)' == 'Windows_NT'">
    <PostBuildEvent>"$(SolutionDir)..\tools_tlp\checksum.exe" "$(SolutionDir)..\quantum_unity\Assets\Plugins\GeneratedChecksums.cs" "$(TargetDir)\quantum.state.dll" "$(TargetDir)\quantum.systems.dll"
 "$(SolutionDir)..\tools\codegen_unity\quantum.codegen.unity.host.exe" "$(TargetDir)\quantum.state.dll" "$(SolutionDir)..\quantum_unity\Assets"
    </PostBuildEvent>
  </PropertyGroup>

Beware that MSBuild is stupid and wants multiple post build commands in same XML tag, in separate lines, with no whitespace.

quantum.systems.csproj screenshot

quantum.systems.csproj screenshot

This will calculate checksums upon build and output them to quantum_unity\Assets\Plugins\GeneratedChecksums.cs

Back to top