private static IntPtr NativeCall() { if (returnedValue == IntPtr.Zero) { throw new Exception("AsiInterface is not initialized."); } NativeArgument[] args = argsBuffer[argumentsIndex]; for (int i = 0; i < argumentsIndex; i++) { args[i] = new NativeArgument(arguments[i]); } argumentsIndex = 0; try { *(NativeRetVal *)returnedValue = (NativeRetVal)NativeFunction.Call(nativeHash, typeof(NativeRetVal), args); } catch (Exception e) { if (Support.Instance.Config.IgnoreUnknownNatives) { *(NativeRetVal *)returnedValue = new NativeRetVal(); //== 0 } else { throw e; } } return(returnedValue); }
public static void Initialize() { arguments = new ulong[MaxArgs]; argsBuffer = new NativeArgument[MaxArgs + 1][]; for (int i = 0; i < MaxArgs + 1; i++) { argsBuffer[i] = new NativeArgument[i]; } returnedValue = Marshal.AllocHGlobal(sizeof(NativeRetVal)); RegisterHandler(Marshal.GetFunctionPointerForDelegate(createTexture), Marshal.GetFunctionPointerForDelegate(drawTexture), Marshal.GetFunctionPointerForDelegate(presentCallbackRegister), Marshal.GetFunctionPointerForDelegate(presentCallbackUnregister), Marshal.GetFunctionPointerForDelegate(keyboardHandlerRegister), Marshal.GetFunctionPointerForDelegate(keyboardHandlerUnregister), Marshal.GetFunctionPointerForDelegate(scriptWait), Marshal.GetFunctionPointerForDelegate(scriptRegister), Marshal.GetFunctionPointerForDelegate(scriptRegisterAdditionalThread), Marshal.GetFunctionPointerForDelegate(scriptUnregisterByModule), Marshal.GetFunctionPointerForDelegate(scriptUnregisterByMain), Marshal.GetFunctionPointerForDelegate(nativeInit), Marshal.GetFunctionPointerForDelegate(nativePush64), Marshal.GetFunctionPointerForDelegate(nativeCall), Marshal.GetFunctionPointerForDelegate(getGlobalPtr), Marshal.GetFunctionPointerForDelegate(worldGetAllVehicles), Marshal.GetFunctionPointerForDelegate(worldGetAllPeds), Marshal.GetFunctionPointerForDelegate(worldGetAllObjects), Marshal.GetFunctionPointerForDelegate(worldGetAllPickups), Marshal.GetFunctionPointerForDelegate(getScriptHandleBaseAddress), Marshal.GetFunctionPointerForDelegate(getGameVersion)); }
public static bool SetEntityProperty(LocalHandle entity, string key, object value) { var handle = NetEntityHandler.EntityToNet(entity.Value); var item = NetEntityHandler.NetToStreamedItem(handle); var prop = item as EntityProperties; if (prop == null || string.IsNullOrEmpty(key)) { return(false); } if (prop.SyncedProperties == null) { prop.SyncedProperties = new Dictionary <string, NativeArgument>(); } var nativeArg = ParseNativeArguments(value).Single(); NativeArgument oldValue = prop.SyncedProperties.Get(key); prop.SyncedProperties.Set(key, nativeArg); if (!item.LocalOnly) { var delta = new Delta_EntityProperties(); delta.SyncedProperties = new Dictionary <string, NativeArgument>(); delta.SyncedProperties.Add(key, nativeArg); UpdateEntityInfo(handle, EntityType.Prop, delta); } JavascriptHook.InvokeDataChangeEvent(entity, key, DecodeArgumentListPure(oldValue).FirstOrDefault()); return(true); }
public static bool SetWorldData(string key, object value) { if (NetEntityHandler.ServerWorld.SyncedProperties == null) { NetEntityHandler.ServerWorld.SyncedProperties = new Dictionary <string, NativeArgument>(); } var nativeArg = ParseNativeArguments(value).Single(); NativeArgument oldValue = NetEntityHandler.ServerWorld.SyncedProperties.Get(key); NetEntityHandler.ServerWorld.SyncedProperties.Set(key, nativeArg); var delta = new Delta_EntityProperties { SyncedProperties = new Dictionary <string, NativeArgument>() }; delta.SyncedProperties.Add(key, nativeArg); UpdateEntityInfo(1, EntityType.Prop, delta); JavascriptHook.InvokeDataChangeEvent(new LocalHandle(0), key, DecodeArgumentListPure(oldValue).FirstOrDefault()); return(true); }
private ArgumentMarshaller /*!*/ GetMarshaller(Expression /*!*/ expr, object value, int index, object nativeType) { if (nativeType != null) { INativeType nt = nativeType as INativeType; if (nt != null) { return(new CDataMarshaller(expr, CompilerHelpers.GetType(value), nt)); } return(new FromParamMarshaller(expr)); } CData data = value as CData; if (data != null) { return(new CDataMarshaller(expr, CompilerHelpers.GetType(value), data.NativeType)); } NativeArgument arg = value as NativeArgument; if (arg != null) { return(new NativeArgumentMarshaller(expr)); } object val; if (PythonOps.TryGetBoundAttr(value, "_as_parameter_", out val)) { throw new NotImplementedException("_as_parameter"); //return new UserDefinedMarshaller(GetMarshaller(..., value, index)); } // Marshalling primitive or an object return(new PrimitiveMarshaller(expr, CompilerHelpers.GetType(value))); }
public object from_param([NotNull] NativeArgument obj) { return((CData)PythonCalls.Call(this, obj._obj)); }
public void GetNativeCallFromPlayer(Client player, bool safe, uint salt, ulong hash, NativeArgument returnType, Action <object> callback, params object[] arguments) { var obj = new NativeData { Hash = hash, ReturnType = returnType, Id = salt, Arguments = ParseNativeArguments(arguments), Internal = safe }; var bin = SerializeBinary(obj); var msg = Server.CreateMessage(); msg.Write((byte)PacketType.NativeCall); msg.Write(bin.Length); msg.Write(bin); _callbacks.Add(salt, callback); player.NetConnection.SendMessage(msg, NetDeliveryMethod.ReliableOrdered, (int)ConnectionChannel.NativeCall); }