public void CallRef(int refIndex, byte[] argsSerialized, out IntPtr retvalSerialized, out int retvalSize) { var retvalData = FunctionReference.Invoke(refIndex, argsSerialized); if (retvalData != null) { if (m_retvalBuffer == IntPtr.Zero) { m_retvalBuffer = Marshal.AllocHGlobal(32768); m_retvalBufferSize = 32768; } if (m_retvalBufferSize < retvalData.Length) { m_retvalBuffer = Marshal.ReAllocHGlobal(m_retvalBuffer, new IntPtr(retvalData.Length)); } Marshal.Copy(retvalData, 0, m_retvalBuffer, retvalData.Length); retvalSerialized = m_retvalBuffer; retvalSize = retvalData.Length; } else { retvalSerialized = IntPtr.Zero; retvalSize = 0; } }
protected override void PackToCore(Packer packer, Delegate objectTree) { if (objectTree is CallbackDelegate) { var funcRef = objectTree.Method.DeclaringType?.GetFields(BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public | BindingFlags.Static).FirstOrDefault(a => a.FieldType == typeof(RemoteFunctionReference)); if (funcRef == null) { throw new ArgumentException("The CallbackDelegate does not contain a RemoteFunctionReference capture."); } var fr = (RemoteFunctionReference)funcRef.GetValue(objectTree.Target); packer.PackExtendedTypeValue(10, fr.Duplicate()); } else { var funcRefDetails = FunctionReference.Create(objectTree); var refType = InternalManager.CanonicalizeRef(funcRefDetails.Identifier); packer.PackExtendedTypeValue(10, Encoding.UTF8.GetBytes(refType)); } }
public static FunctionReference Create(Delegate method) { var reference = new FunctionReference(method); var referenceId = Register(reference); reference.Identifier = referenceId; return(reference); }
private static int Register(FunctionReference reference) { var thisRefId = ms_referenceId; ms_references[thisRefId] = reference; unchecked { ms_referenceId++; } return(thisRefId); }
public static byte[] CallRef(uint reference, byte[] argsSerialized) { try { return(FunctionReference.Invoke(reference, argsSerialized)); } catch (Exception e) { Debug.WriteLine("Exception while calling native reference: {0}", e.ToString()); return(new byte[] { 0xC0 }); } }
public void CallRef(int refIndex, byte[] argsSerialized, out IntPtr retvalSerialized, out int retvalSize) { // not using using statements here as old Mono on Linux build doesn't know of these #if IS_FXSERVER using (var syncContext = new SyncContextScope()) #endif { if (GameInterface.SnapshotStackBoundary(out var b)) { ScriptHost.SubmitBoundaryStart(b, b.Length); } try { var retvalData = FunctionReference.Invoke(refIndex, argsSerialized); if (retvalData != null) { if (m_retvalBuffer == IntPtr.Zero) { m_retvalBuffer = Marshal.AllocHGlobal(32768); m_retvalBufferSize = 32768; } if (m_retvalBufferSize < retvalData.Length) { m_retvalBuffer = Marshal.ReAllocHGlobal(m_retvalBuffer, new IntPtr(retvalData.Length)); m_retvalBufferSize = retvalData.Length; } Marshal.Copy(retvalData, 0, m_retvalBuffer, retvalData.Length); retvalSerialized = m_retvalBuffer; retvalSize = retvalData.Length; } else { retvalSerialized = IntPtr.Zero; retvalSize = 0; } } catch (Exception e) { retvalSerialized = IntPtr.Zero; retvalSize = 0; PrintError($"reference call", e.InnerException ?? e); } } }
protected override void PackToCore(MsgPack.Packer packer, Delegate objectTree) { if (objectTree is CallbackDelegate) { throw new InvalidOperationException("Resending callback delegates is currently not supported."); } var funcRefDetails = FunctionReference.Create(objectTree); var resourceNameBytes = Encoding.UTF8.GetBytes(funcRefDetails.Resource); var delegateData = new byte[8 + resourceNameBytes.Length]; Array.Copy(BitConverter.GetBytes(funcRefDetails.Identifier).Reverse().ToArray(), 0, delegateData, 0, 4); Array.Copy(BitConverter.GetBytes(funcRefDetails.Instance).Reverse().ToArray(), 0, delegateData, 4, 4); Array.Copy(resourceNameBytes, 0, delegateData, 8, resourceNameBytes.Length); packer.PackExtendedTypeValue(1, delegateData); }
public void CallRef(int refIndex, byte[] argsSerialized, out IntPtr retvalSerialized, out int retvalSize) { if (GameInterface.SnapshotStackBoundary(out var b)) { ScriptHost.SubmitBoundaryStart(b, b.Length); } try { var retvalData = FunctionReference.Invoke(refIndex, argsSerialized); if (retvalData != null) { if (m_retvalBuffer == IntPtr.Zero) { m_retvalBuffer = Marshal.AllocHGlobal(32768); m_retvalBufferSize = 32768; } if (m_retvalBufferSize < retvalData.Length) { m_retvalBuffer = Marshal.ReAllocHGlobal(m_retvalBuffer, new IntPtr(retvalData.Length)); m_retvalBufferSize = retvalData.Length; } Marshal.Copy(retvalData, 0, m_retvalBuffer, retvalData.Length); retvalSerialized = m_retvalBuffer; retvalSize = retvalData.Length; } else { retvalSerialized = IntPtr.Zero; retvalSize = 0; } } catch (Exception e) { retvalSerialized = IntPtr.Zero; retvalSize = 0; PrintError($"reference call", e.InnerException ?? e); } }
public void RemoveRef(int refIndex) { FunctionReference.Remove(refIndex); }
public int DuplicateRef(int refIndex) { return(FunctionReference.Duplicate(refIndex)); }
public static void RemoveRef(uint reference) { FunctionReference.Remove(reference); }