8 public readonly UInt64
Value;
39 private const string steam64Prefix =
"STEAM64_";
40 private const string steam40Prefix =
"STEAM_";
42 private const UInt64 usualAccountInstance = 1;
43 private const UInt64 usualAccountType = 1;
45 static UInt64 ExtractBits(UInt64
id,
int offset,
int numberOfBits)
46 => (
id >> offset) & ((1ul << numberOfBits) - 1ul);
48 static UInt64 ExtractY(UInt64
id)
49 => ExtractBits(
id, offset: 0, numberOfBits: 1);
50 static UInt64 ExtractAccountNumberRemainder(UInt64
id)
51 => ExtractBits(
id, offset: 1, numberOfBits: 31);
52 static UInt64 ExtractAccountInstance(UInt64
id)
53 => ExtractBits(
id, offset: 32, numberOfBits: 20);
54 static UInt64 ExtractAccountType(UInt64
id)
55 => ExtractBits(
id, offset: 52, numberOfBits: 4);
56 static UInt64 ExtractUniverse(UInt64
id)
57 => ExtractBits(
id, offset: 56, numberOfBits: 8);
63 if (ExtractAccountInstance(
Value) == usualAccountInstance
64 && ExtractAccountType(
Value) == usualAccountType)
66 UInt64 y = ExtractY(
Value);
67 UInt64 accountNumberRemainder = ExtractAccountNumberRemainder(
Value);
68 UInt64 universe = ExtractUniverse(
Value);
83 if (str.StartsWith(steam64Prefix, StringComparison.InvariantCultureIgnoreCase)) { str = str[steam64Prefix.Length..]; }
84 if (UInt64.TryParse(str, out UInt64 retVal) && ExtractAccountInstance(retVal) > 0)
89 if (!str.StartsWith(steam40Prefix, StringComparison.InvariantCultureIgnoreCase)) {
return Option<SteamId>.
None(); }
90 string[] split = str[steam40Prefix.Length..].Split(
':');
95 if (!UInt64.TryParse(split[2], out UInt64 accountNumber)) {
return Option<SteamId>.
None(); }
99 | usualAccountType << 52
100 | usualAccountInstance << 32
101 | (accountNumber << 1)
108 SteamId otherId =>
this == otherId,
113 =>
Value.GetHashCode();
116 => a.Value == b.Value;
static bool operator==(SteamId a, SteamId b)
static new Option< SteamId > Parse(string str)
override string ToString()
override int GetHashCode()
static bool operator!=(SteamId a, SteamId b)
override bool Equals(object? obj)
override string StringRepresentation
static Option< T > Some(T value)
static UnspecifiedNone None