From dcded33447dd0a69adfc6c4171a4cbc245f56db5 Mon Sep 17 00:00:00 2001 From: homothetyhk Date: Fri, 7 Jan 2022 23:29:25 -0800 Subject: [PATCH] Update version. --- ItemChanger/ItemChanger.csproj | 3 ++- ItemChanger/ItemChangerMod.cs | 35 +++++++++++++++++++++++++++++++++- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/ItemChanger/ItemChanger.csproj b/ItemChanger/ItemChanger.csproj index 91d06bcd..dc29248b 100644 --- a/ItemChanger/ItemChanger.csproj +++ b/ItemChanger/ItemChanger.csproj @@ -4,7 +4,8 @@ net472 ItemChanger ItemChanger - 1.1.0 + 2.0.0 + 2.0.0 true false latest diff --git a/ItemChanger/ItemChangerMod.cs b/ItemChanger/ItemChangerMod.cs index 959d629a..33f5ec28 100644 --- a/ItemChanger/ItemChangerMod.cs +++ b/ItemChanger/ItemChangerMod.cs @@ -158,7 +158,40 @@ public static void AddPlacements(IEnumerable 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;