Skip to content

Commit

Permalink
Update version.
Browse files Browse the repository at this point in the history
  • Loading branch information
homothetyhk committed Jan 8, 2022
1 parent 3a3a231 commit dcded33
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
3 changes: 2 additions & 1 deletion ItemChanger/ItemChanger.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
<TargetFramework>net472</TargetFramework>
<RootNamespace>ItemChanger</RootNamespace>
<AssemblyTitle>ItemChanger</AssemblyTitle>
<AssemblyVersion>1.1.0</AssemblyVersion>
<AssemblyVersion>2.0.0</AssemblyVersion>
<FileVersion>2.0.0</FileVersion>
<Deterministic>true</Deterministic>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<LangVersion>latest</LangVersion>
Expand Down
35 changes: 34 additions & 1 deletion ItemChanger/ItemChangerMod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,40 @@ public static void AddPlacements(IEnumerable<AbstractPlacement> placements, Plac

public override string GetVersion()
{
return "1.0.1";
return _version;
}

private static readonly string _sha1;
private static readonly string _version;
static ItemChangerMod()
{
System.Reflection.Assembly a = typeof(ItemChangerMod).Assembly;

using var sha1 = System.Security.Cryptography.SHA1.Create();
using var sr = File.OpenRead(a.Location);
_sha1 = Convert.ToBase64String(sha1.ComputeHash(sr));

int buildHash;
unchecked // stable string hash code
{
int hash1 = 5381;
int hash2 = hash1;
string str = _sha1;

for (int i = 0; i < str.Length && str[i] != '\0'; i += 2)
{
hash1 = ((hash1 << 5) + hash1) ^ str[i];
if (i == str.Length - 1 || str[i + 1] == '\0')
break;
hash2 = ((hash2 << 5) + hash2) ^ str[i + 1];
}

buildHash = hash1 + (hash2 * 1566083941);
buildHash = Math.Abs(buildHash) % 997;
}

Version v = a.GetName().Version;
_version = $"{v.Major}.{v.Minor}.{v.Build}+{buildHash.ToString().PadLeft(3, '0')}";
}

public override int LoadPriority() => -2;
Expand Down

0 comments on commit dcded33

Please sign in to comment.