Skip to content

Instantly share code, notes, and snippets.

@luxuia
Created November 1, 2018 08:45
Show Gist options
  • Save luxuia/9daaffa4284ea1440826c9a53b33bbc7 to your computer and use it in GitHub Desktop.
Save luxuia/9daaffa4284ea1440826c9a53b33bbc7 to your computer and use it in GitHub Desktop.
unity 会记录打出来的obb的hash在/assets/bin/Data/settings.xml 。修改obb或者想复用obb就需要修改apk内的hash字段。 用obb的最后65558个字节计算的hash
public static string CalculateObbDigest(string file)
{
byte[] arrayOfByte = null;
using (var localMessageDigest = MD5.Create())
using (var localFileInputStream = File.OpenRead(file))
{
long l1 = localFileInputStream.Length;
localFileInputStream.Seek(l1 - Math.Min(l1, 65558L), SeekOrigin.Current);
arrayOfByte = localMessageDigest.ComputeHash(localFileInputStream);
}
var localStringBuffer = new StringBuilder(32);
for (int i1 = 0; i1 < arrayOfByte.Length; i1++)
{
localStringBuffer.AppendFormat(arrayOfByte[i1].ToString("x2"));
}
return localStringBuffer.ToString();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment