-
Notifications
You must be signed in to change notification settings - Fork 110
Expand file tree
/
Copy pathUtility.cs
More file actions
37 lines (30 loc) · 977 Bytes
/
Utility.cs
File metadata and controls
37 lines (30 loc) · 977 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
using Terraria;
using Terraria.ID;
using Terraria.ModLoader.Config;
namespace MagicStorage {
public static partial class Utility {
// The rest of the implementation is found at /Common/Utils
public static void SaveModConfig(ModConfig config) => ConfigManager.Save(config);
public static Item GetItemSample(int item) => ContentSamples.ItemsByType[item];
/// <summary>
/// Generates a hash for a byte array. This method is <b>NOT</b> optimized for <see cref="object.GetHashCode"/> usage!
/// </summary>
public static int ComputeDataHash(byte[] data) {
if (data is not { Length: >0 })
return 0;
// Taken from: https://stackoverflow.com/a/468084
unchecked {
const int p = 16777619;
int hash = (int)2166136261;
for (int i = 0; i < data.Length; i++)
hash = (hash ^ data[i]) * p;
hash += hash << 13;
hash ^= hash >> 7;
hash += hash << 3;
hash ^= hash >> 17;
hash += hash << 5;
return hash;
}
}
}
}