Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
BlobHandle.cs
Go to the documentation of this file.
2
4
5public readonly struct BlobHandle : IEquatable<BlobHandle>
6{
16
17 private readonly uint _value;
18
20
21 internal uint RawValue => _value;
22
23 public bool IsNil => _value == 0;
24
25 internal bool IsVirtual => (_value & 0x80000000u) != 0;
26
27 private ushort VirtualValue => (ushort)(_value >> 8);
28
29 private BlobHandle(uint value)
30 {
31 _value = value;
32 }
33
34 internal static BlobHandle FromOffset(int heapOffset)
35 {
36 return new BlobHandle((uint)heapOffset);
37 }
38
39 internal static BlobHandle FromVirtualIndex(VirtualIndex virtualIndex, ushort virtualValue)
40 {
41 return new BlobHandle(0x80000000u | (uint)(virtualValue << 8) | (uint)virtualIndex);
42 }
43
44 internal unsafe void SubstituteTemplateParameters(byte[] blob)
45 {
46 fixed (byte* ptr = &blob[2])
47 {
48 *(int*)ptr = VirtualValue;
49 }
50 }
51
52 public static implicit operator Handle(BlobHandle handle)
53 {
54 return new Handle((byte)(((handle._value & 0x80000000u) >> 24) | 0x71u), (int)(handle._value & 0x1FFFFFFF));
55 }
56
57 public static explicit operator BlobHandle(Handle handle)
58 {
59 if ((handle.VType & 0x7F) != 113)
60 {
62 }
63 return new BlobHandle((uint)(((handle.VType & 0x80) << 24) | handle.Offset));
64 }
65
66 internal int GetHeapOffset()
67 {
68 return (int)_value;
69 }
70
72 {
73 return (VirtualIndex)(_value & 0xFFu);
74 }
75
76 public override bool Equals([NotNullWhen(true)] object? obj)
77 {
78 if (obj is BlobHandle other)
79 {
80 return Equals(other);
81 }
82 return false;
83 }
84
85 public bool Equals(BlobHandle other)
86 {
87 return _value == other._value;
88 }
89
90 public override int GetHashCode()
91 {
92 return (int)_value;
93 }
94
95 public static bool operator ==(BlobHandle left, BlobHandle right)
96 {
97 return left.Equals(right);
98 }
99
100 public static bool operator !=(BlobHandle left, BlobHandle right)
101 {
102 return !left.Equals(right);
103 }
104}
static void InvalidCast()
Definition Throw.cs:12
static BlobHandle FromOffset(int heapOffset)
Definition BlobHandle.cs:34
bool Equals(BlobHandle other)
Definition BlobHandle.cs:85
static bool operator!=(BlobHandle left, BlobHandle right)
static bool operator==(BlobHandle left, BlobHandle right)
Definition BlobHandle.cs:95
static BlobHandle FromVirtualIndex(VirtualIndex virtualIndex, ushort virtualValue)
Definition BlobHandle.cs:39
override bool Equals([NotNullWhen(true)] object? obj)
Definition BlobHandle.cs:76
unsafe void SubstituteTemplateParameters(byte[] blob)
Definition BlobHandle.cs:44