public void TriggerEvent(string eventName, params object[] args) { var argsSerialized = MsgPackSerializer.Serialize(args); unsafe { fixed(byte *serialized = &argsSerialized[0]) { Call(TRIGGER_CLIENT_EVENT_INTERNAL, eventName, m_handle, serialized, argsSerialized.Length); } } }
public void TriggerLatentEvent(string eventName, int bytesPerSecond, params object[] args) { var argsSerialized = MsgPackSerializer.Serialize(args); unsafe { fixed(byte *serialized = &argsSerialized[0]) { Function.Call(Hash.TRIGGER_LATENT_CLIENT_EVENT_INTERNAL, eventName, m_handle, serialized, argsSerialized.Length, bytesPerSecond); } } }
/// <summary> /// Broadcasts an event to all connected players. /// </summary> /// <param name="eventName">The name of the event.</param> /// <param name="args">Arguments to pass to the event.</param> public static void TriggerClientEvent(string eventName, params object[] args) { var argsSerialized = MsgPackSerializer.Serialize(args); unsafe { fixed(byte *serialized = &argsSerialized[0]) { Function.Call(Hash.TRIGGER_CLIENT_EVENT_INTERNAL, eventName, "-1", serialized, argsSerialized.Length); } } }
public static byte[] Invoke(int reference, byte[] arguments) { if (!ms_references.TryGetValue(reference, out var funcRef)) { Debug.WriteLine("No such reference for {0}.", reference); // return nil return(new byte[] { 0xC0 }); } var method = funcRef.m_method; // deserialize the passed arguments var argList = (List <object>)MsgPackDeserializer.Deserialize(arguments); var argArray = argList.ToArray(); // the Lua runtime expects this to be an array, so it be an array. return(MsgPackSerializer.Serialize(new[] { method.DynamicInvoke(argArray) })); }
internal static unsafe void PushObject(ContextType *cxt, object arg) { var ptr = IntPtr.Zero; var b = MsgPackSerializer.Serialize(arg); ptr = Marshal.AllocHGlobal(b.Length); Marshal.Copy(b, 0, ptr, b.Length); ms_finalizers.Enqueue(() => Free(ptr)); unsafe { *(IntPtr *)(&cxt->functionData[8 * cxt->numArguments]) = ptr; *(long *)(&cxt->functionData[8 * (cxt->numArguments + 1)]) = b.Length; } cxt->numArguments += 2; }
static object CreateRemoteFunctionReference(byte[] funcRefData) { var remoteFunctionReference = new RemoteFunctionReference(funcRefData); return(new CallbackDelegate(delegate(object[] args) { var byteData = MsgPackSerializer.Serialize(args); var returnByteData = remoteFunctionReference.InvokeNative(byteData); var returnData = Deserialize(returnByteData) as List <object>; if (returnData == null || returnData.Count == 0) { return null; } if (returnData[0] is IDictionary <string, object> obj) { if (obj.TryGetValue("__cfx_async_retval", out dynamic asyncRef)) { var tcs = new TaskCompletionSource <object>(); asyncRef(new Action <dynamic, dynamic>((res, err) => { if (err != null && err != false) { tcs.SetException(new Exception(err.ToString())); } else { tcs.SetResult(res[0]); } })); return tcs.Task; } } return (returnData)[0]; })); }
static object UnpackExt8(byte a, BinaryReader reader) { var length = reader.ReadByte(); var extType = reader.ReadByte(); if (extType != 1) { throw new InvalidOperationException("Only extension type 1 (Citizen callback) is handled by this class."); } // read the local reference ID var tmpBytes = reader.ReadBytes(4); var reference = BitConverter.ToUInt32(new byte[] { tmpBytes[3], tmpBytes[2], tmpBytes[1], tmpBytes[0] }, 0); // read the environment instance ID tmpBytes = reader.ReadBytes(4); var instance = BitConverter.ToUInt32(new byte[] { tmpBytes[3], tmpBytes[2], tmpBytes[1], tmpBytes[0] }, 0); // read the resource name tmpBytes = reader.ReadBytes(length - 8); var resource = Encoding.UTF8.GetString(tmpBytes, 0, tmpBytes.Length); var remoteFunctionReference = new RemoteFunctionReference(resource, instance, reference); return(new CallbackDelegate(delegate(object[] args) { var byteData = MsgPackSerializer.Serialize(args); var returnByteData = remoteFunctionReference.InvokeNative(byteData); var returnData = Deserialize(returnByteData) as List <object>; if (returnData == null || returnData.Count == 0) { return null; } return (returnData)[0]; })); }
public void WalkStack(byte[] boundaryStart, int boundaryStartLength, byte[] boundaryEnd, int boundaryEndLength, IScriptStackWalkVisitor visitor) { var data = m_intManager?.WalkStack(boundaryStart, boundaryEnd); if (data == null) { return; } var frames = (IEnumerable <object>)MsgPackDeserializer.Deserialize(data); #if !IS_FXSERVER visitor = new DirectVisitor(visitor); #endif foreach (var frame in frames) { var f = MsgPackSerializer.Serialize(frame); visitor.SubmitStackFrame(f, f.Length); } }
public static byte[] Invoke(int reference, byte[] arguments) { if (!ms_references.TryGetValue(reference, out var funcRef)) { Debug.WriteLine("No such reference for {0}.", reference); // return nil return(new byte[] { 0xC0 }); } var method = funcRef.m_method; // deserialize the passed arguments var argList = (List <object>)MsgPackDeserializer.Deserialize(arguments); var argArray = CallUtilities.GetPassArguments(method.Method, argList.ToArray(), string.Empty); // the Lua runtime expects this to be an array, so it be an array. var rv = method.DynamicInvoke(argArray); // is this actually an asynchronous method? if (rv is Task) { dynamic rt = rv; rv = new { __cfx_async_retval = new Action <dynamic>(rvcb => { rt.ContinueWith(new Action <Task>(t => { rvcb(new object[] { rt.Result }, false); })); }) }; } return(MsgPackSerializer.Serialize(new[] { rv })); }
public static void TriggerServerEvent(string eventName, params object[] args) { var argsSerialized = MsgPackSerializer.Serialize(args); TriggerEventInternal(eventName, argsSerialized, true); }
public void Set(string key, object data, bool replicated) { var dataSerialized = MsgPackSerializer.Serialize(data); SetInternal(key, dataSerialized, replicated); }
public static void TriggerLatentServerEvent(string eventName, int bytesPerSecond, params object[] args) { var argsSerialized = MsgPackSerializer.Serialize(args); TriggerLatentServerEventInternal(eventName, argsSerialized, bytesPerSecond); }