public void ResolvePointerReferences() { // Go through PointerReferenceList and resolve all pointers. foreach (var pointerReference in PointerReferenceList) { // Only act if not null. Otherwise placeholder functions already wrote zeroes and that's good enough. if (pointerReference.Reference != null) { // Check if this object was committed so we can resolve the pointer. var objectReference = ObjectReferences.Where(kv => ReferenceEquals(kv.Key, pointerReference.Reference)); if (!objectReference.Any()) { throw new KeyNotFoundException($"Failed to resolve a committed reference to a {pointerReference.Reference.GetType().Name}"); } // Resolve pointer var patchLocation = pointerReference.Location; var objectLocation = objectReference.Single().Value; var relativeOffset = objectLocation - patchLocation; Utility.PushWritePosition(); Utility.SetWritePosition(patchLocation); Utility.Write(relativeOffset); Utility.PopWritePosition(); } } PointerReferenceList.Clear(); }
public void WritePointerPlaceholder(object obj) { PointerReferenceList.Add(new PointerReference { Reference = obj, Location = Utility.GetWritePosition() }); Utility.Write(0u); // Placeholder }