コード例 #1
0
        //TODO: make call async because it doesnt matter there is no concurrent problems inside

        //TODO: write function parser in cpp so it can do that natively without any native calls for mvalues (experimental)
        //TODO: register event callbacks to cpp as dynamic function pointers with void** so cpp knows the types it needs to check

        //TODO: add support for nullable args, these are reducing the required length, add support for default values as well
        internal MValue Call(IBaseBaseObjectPool baseBaseObjectPool, MValue[] values)
        {
            var length = values.Length;

            if (length != args.Length)
            {
                return(MValue.Nil);
            }
            //var watch = System.Diagnostics.Stopwatch.StartNew();
            var invokeValues = new object[length];

            for (var i = 0; i < length; i++)
            {
                invokeValues[i] = parsers[i](ref values[i], args[i], baseBaseObjectPool, typeInfos[i]);
            }

            //watch.Stop();
            //var elapsedMs = watch.ElapsedMilliseconds;
            //Alt.Log("ms:" + elapsedMs);

            var result = @delegate.DynamicInvoke(invokeValues);

            if (returnType == FunctionTypes.Void)
            {
                return(MValue.Nil);
            }
            return(MValue.CreateFromObject(result));
        }
コード例 #2
0
ファイル: Function.cs プロジェクト: bozoweed/coreclr-module
        internal MValue Call(IPlayer player, IBaseBaseObjectPool baseBaseObjectPool, MValue[] values)
        {
            var length = values.Length;

            if (length + 1 != args.Length)
            {
                return(MValue.Nil);
            }
            if (!typeInfos[0].IsPlayer)
            {
                return(MValue.Nil);
            }
            var invokeValues = new object[length + 1];

            invokeValues[0] = player;
            for (var i = 0; i < length; i++)
            {
                invokeValues[i + 1] =
                    parsers[i + 1](ref values[i], args[i + 1], baseBaseObjectPool, typeInfos[i + 1]);
            }

            var result = @delegate.DynamicInvoke(invokeValues);

            if (returnType == FunctionTypes.Void)
            {
                return(MValue.Nil);
            }
            return(MValue.CreateFromObject(result));
        }
コード例 #3
0
ファイル: Function.cs プロジェクト: bozoweed/coreclr-module
        //TODO: make call async because it doesnt matter there is no concurrent problems inside

        //TODO: write function parser in cpp so it can do that natively without any native calls for mvalues (experimental)
        //TODO: register event callbacks to cpp as dynamic function pointers with void** so cpp knows the types it needs to check

        //TODO: add support for nullable args, these are reducing the required length, add support for default values as well

        //TODO: maybe cache var invokeValues = new object[length];
        internal MValue Call(IBaseBaseObjectPool baseBaseObjectPool, MValue[] values)
        {
            var length = values.Length;

            if (length < requiredArgsCount)
            {
                return(MValue.Nil);
            }
            var argsLength         = args.Length;
            var invokeValues       = new object[argsLength];
            var parserValuesLength = Math.Min(argsLength, length);

            for (var i = 0; i < parserValuesLength; i++)
            {
                invokeValues[i] = parsers[i](ref values[i], args[i], baseBaseObjectPool, typeInfos[i]);
            }

            for (var i = parserValuesLength; i < argsLength; i++)
            {
                invokeValues[i] = typeInfos[i].DefaultValue;
            }

            //TODO: fill remaining values in event params

            var result = @delegate.DynamicInvoke(invokeValues);

            if (returnType == FunctionTypes.Void)
            {
                return(MValue.Nil);
            }
            return(MValue.CreateFromObject(result));
        }
コード例 #4
0
ファイル: Resource.cs プロジェクト: Tribunal37/coreclr-module
 public virtual Module GetModule(IServer server, CSharpNativeResource cSharpNativeResource,
                                 IBaseBaseObjectPool baseBaseObjectPool,
                                 IBaseEntityPool baseEntityPool, IEntityPool <IPlayer> playerPool, IEntityPool <IVehicle> vehiclePool,
                                 IBaseObjectPool <IBlip> blipPool,
                                 IBaseObjectPool <ICheckpoint> checkpointPool, IBaseObjectPool <IVoiceChannel> voiceChannelPool)
 {
     return(new Module(server, cSharpNativeResource, baseBaseObjectPool, baseEntityPool, playerPool, vehiclePool,
                       blipPool, checkpointPool, voiceChannelPool));
 }
コード例 #5
0
 public AsyncModule(IServer server, CSharpNativeResource cSharpNativeResource,
                    IBaseBaseObjectPool baseBaseObjectPool, IBaseEntityPool baseEntityPool, IEntityPool <IPlayer> playerPool,
                    IEntityPool <IVehicle> vehiclePool,
                    IBaseObjectPool <IBlip> blipPool,
                    IBaseObjectPool <ICheckpoint> checkpointPool,
                    IBaseObjectPool <IVoiceChannel> voiceChannelPool) : base(server, cSharpNativeResource, baseBaseObjectPool,
                                                                             baseEntityPool, playerPool, vehiclePool, blipPool,
                                                                             checkpointPool, voiceChannelPool)
 {
     AltAsync.Setup(this);
 }
コード例 #6
0
 public virtual Module GetModule(IServer server,
                                 AssemblyLoadContext assemblyLoadContext,
                                 INativeResource cSharpNativeResource,
                                 IBaseBaseObjectPool baseBaseObjectPool,
                                 IBaseEntityPool baseEntityPool, IEntityPool <IPlayer> playerPool, IEntityPool <IVehicle> vehiclePool,
                                 IBaseObjectPool <IBlip> blipPool,
                                 IBaseObjectPool <ICheckpoint> checkpointPool, IBaseObjectPool <IVoiceChannel> voiceChannelPool,
                                 IBaseObjectPool <IColShape> colShapePool,
                                 INativeResourcePool nativeResourcePool)
 {
     return(new Module(server, assemblyLoadContext, cSharpNativeResource, baseBaseObjectPool, baseEntityPool, playerPool, vehiclePool,
                       blipPool, checkpointPool, voiceChannelPool, colShapePool, nativeResourcePool));
 }
コード例 #7
0
 public AsyncModule(IServer server, AssemblyLoadContext assemblyLoadContext, INativeResource moduleResource,
                    IBaseBaseObjectPool baseBaseObjectPool, IBaseEntityPool baseEntityPool, IEntityPool <IPlayer> playerPool,
                    IEntityPool <IVehicle> vehiclePool,
                    IBaseObjectPool <IBlip> blipPool,
                    IBaseObjectPool <ICheckpoint> checkpointPool,
                    IBaseObjectPool <IVoiceChannel> voiceChannelPool,
                    IBaseObjectPool <IColShape> colShapePool,
                    INativeResourcePool nativeResourcePool) : base(server, assemblyLoadContext, moduleResource,
                                                                   baseBaseObjectPool,
                                                                   baseEntityPool, playerPool, vehiclePool, blipPool,
                                                                   checkpointPool, voiceChannelPool, colShapePool, nativeResourcePool)
 {
     AltAsync.Setup(this);
 }
コード例 #8
0
 internal MockServer(IntPtr nativePointer, IBaseBaseObjectPool baseBaseObjectPool,
                     IBaseEntityPool baseEntityPool, IEntityPool <IPlayer> playerPool,
                     IEntityPool <IVehicle> vehiclePool,
                     IBaseObjectPool <IBlip> blipPool,
                     IBaseObjectPool <ICheckpoint> checkpointPool,
                     IBaseObjectPool <IVoiceChannel> voiceChannelPool)
 {
     this.nativePointer      = nativePointer;
     this.baseBaseObjectPool = baseBaseObjectPool;
     this.baseEntityPool     = baseEntityPool;
     this.playerPool         = playerPool;
     this.vehiclePool        = vehiclePool;
     this.blipPool           = blipPool;
     this.checkpointPool     = checkpointPool;
     this.voiceChannelPool   = voiceChannelPool;
 }
コード例 #9
0
ファイル: Function.cs プロジェクト: bozoweed/coreclr-module
        internal object[] CalculateInvokeValues(IBaseBaseObjectPool baseBaseObjectPool, MValue[] values)
        {
            var length = values.Length;

            if (length != args.Length)
            {
                return(null);
            }
            var invokeValues = new object[length];

            for (var i = 0; i < length; i++)
            {
                invokeValues[i] = parsers[i](ref values[i], args[i], baseBaseObjectPool, typeInfos[i]);
            }

            return(invokeValues);
        }
コード例 #10
0
ファイル: Module.cs プロジェクト: Tribunal37/coreclr-module
 public Module(IServer server, CSharpNativeResource cSharpNativeResource, IBaseBaseObjectPool baseBaseObjectPool,
               IBaseEntityPool baseEntityPool, IEntityPool <IPlayer> playerPool,
               IEntityPool <IVehicle> vehiclePool,
               IBaseObjectPool <IBlip> blipPool,
               IBaseObjectPool <ICheckpoint> checkpointPool,
               IBaseObjectPool <IVoiceChannel> voiceChannelPool)
 {
     Alt.Init(this);
     Server = server;
     CSharpNativeResource = cSharpNativeResource;
     BaseBaseObjectPool   = baseBaseObjectPool;
     BaseEntityPool       = baseEntityPool;
     PlayerPool           = playerPool;
     VehiclePool          = vehiclePool;
     BlipPool             = blipPool;
     CheckpointPool       = checkpointPool;
     VoiceChannelPool     = voiceChannelPool;
 }
コード例 #11
0
 public static object CreateArray(Type type, MValue[] mValues, IBaseBaseObjectPool baseBaseObjectPool,
     FunctionTypeInfo typeInfo)
 {
     var length = mValues.Length;
     if (type == FunctionTypes.Obj)
     {
         var array = new object[length];
         for (var i = 0; i < length; i++)
         {
             var currMValue = mValues[i];
             if (!TryParseObject(ref currMValue, type, baseBaseObjectPool, typeInfo?.Element, out var obj))
             {
                 array[i] = obj;
                 //return null;
             }
             else
             {
                 array[i] = obj;
             }
         }
コード例 #12
0
        internal object[] CalculateInvokeValues(IPlayer player, IBaseBaseObjectPool baseBaseObjectPool, MValue[] values)
        {
            var length = values.Length;

            if (length + 1 != args.Length)
            {
                return(null);
            }
            if (!typeInfos[0].IsPlayer)
            {
                return(null);
            }
            var invokeValues = new object[length + 1];

            invokeValues[0] = player;
            for (var i = 0; i < length; i++)
            {
                invokeValues[i + 1] = parsers[i](ref values[i], args[i], baseBaseObjectPool, typeInfos[i]);
            }

            return(invokeValues);
        }
コード例 #13
0
 public Server(IntPtr nativePointer, INativeResource resource, IBaseBaseObjectPool baseBaseObjectPool,
               IBaseEntityPool baseEntityPool,
               IEntityPool <IPlayer> playerPool,
               IEntityPool <IVehicle> vehiclePool,
               IBaseObjectPool <IBlip> blipPool,
               IBaseObjectPool <ICheckpoint> checkpointPool,
               IBaseObjectPool <IVoiceChannel> voiceChannelPool,
               IBaseObjectPool <IColShape> colShapePool,
               INativeResourcePool nativeResourcePool)
 {
     NativePointer           = nativePointer;
     this.baseBaseObjectPool = baseBaseObjectPool;
     this.baseEntityPool     = baseEntityPool;
     this.playerPool         = playerPool;
     this.vehiclePool        = vehiclePool;
     this.blipPool           = blipPool;
     this.checkpointPool     = checkpointPool;
     this.voiceChannelPool   = voiceChannelPool;
     this.colShapePool       = colShapePool;
     this.nativeResourcePool = nativeResourcePool;
     Resource = resource;
 }
コード例 #14
0
        public Server(IntPtr nativePointer, CSharpNativeResource resource, IBaseBaseObjectPool baseBaseObjectPool, IBaseEntityPool baseEntityPool,
                      IEntityPool <IPlayer> playerPool,
                      IEntityPool <IVehicle> vehiclePool,
                      IBaseObjectPool <IBlip> blipPool,
                      IBaseObjectPool <ICheckpoint> checkpointPool,
                      IBaseObjectPool <IVoiceChannel> voiceChannelPool,
                      IBaseObjectPool <IColShape> colShapePool)
        {
            NativePointer           = nativePointer;
            this.baseBaseObjectPool = baseBaseObjectPool;
            this.baseEntityPool     = baseEntityPool;
            this.playerPool         = playerPool;
            this.vehiclePool        = vehiclePool;
            this.blipPool           = blipPool;
            this.checkpointPool     = checkpointPool;
            this.voiceChannelPool   = voiceChannelPool;
            this.colShapePool       = colShapePool;
            var ptr = IntPtr.Zero;

            AltNative.Server.Server_GetRootDirectory(nativePointer, ref ptr);
            RootDirectory = Marshal.PtrToStringUTF8(ptr);
            Resource      = resource;
        }
コード例 #15
0
 public Core(IntPtr nativePointer, IntPtr resourcePointer, AssemblyLoadContext assemblyLoadContext, ILibrary library, IBaseBaseObjectPool baseBaseObjectPool,
             IBaseEntityPool baseEntityPool,
             IEntityPool <IPlayer> playerPool,
             IEntityPool <IVehicle> vehiclePool,
             IBaseObjectPool <IBlip> blipPool,
             IBaseObjectPool <ICheckpoint> checkpointPool,
             IBaseObjectPool <IVoiceChannel> voiceChannelPool,
             IBaseObjectPool <IColShape> colShapePool,
             INativeResourcePool nativeResourcePool) : base(nativePointer, library)
 {
     this.assemblyLoadContext   = new WeakReference <AssemblyLoadContext>(assemblyLoadContext);
     this.BaseBaseObjectPool    = baseBaseObjectPool;
     this.BaseEntityPool        = baseEntityPool;
     this.PlayerPool            = playerPool;
     this.VehiclePool           = vehiclePool;
     this.BlipPool              = blipPool;
     this.CheckpointPool        = checkpointPool;
     this.VoiceChannelPool      = voiceChannelPool;
     this.ColShapePool          = colShapePool;
     this.NativeResourcePool    = nativeResourcePool;
     this.vehicleModelInfoCache = new();
     nativeResourcePool.GetOrCreate(this, resourcePointer, out var resource);
     Resource = resource;
 }
コード例 #16
0
ファイル: Function.cs プロジェクト: bozoweed/coreclr-module
 internal MValue Call(IBaseBaseObjectPool baseBaseObjectPool, MValue valueArgs)
 {
     return(valueArgs.type != MValue.Type.LIST ? MValue.Nil : Call(baseBaseObjectPool, valueArgs.GetList()));
 }
コード例 #17
0
ファイル: MValue.cs プロジェクト: bozoweed/coreclr-module
        public object ToObject(IBaseBaseObjectPool baseBaseObjectPool)
        {
            switch (type)
            {
            case Type.NIL:
                return(null);

            case Type.BOOL:
                return(GetBool());

            case Type.INT:
                return(GetInt());

            case Type.UINT:
                return(GetUint());

            case Type.DOUBLE:
                return(GetDouble());

            case Type.STRING:
                return(GetString());

            case Type.LIST:
                var mValueArray = MValueArray.Nil;
                AltNative.MValueGet.MValue_GetList(ref this, ref mValueArray);
                var arrayValue  = mValueArray.data;
                var arrayValues = new object[mValueArray.Size];
                for (var i = 0; i < arrayValues.Length; i++)
                {
                    arrayValues[i] = mValueArray.GetNextWithOffset(ref arrayValue).ToObject(baseBaseObjectPool);
                }

                mValueArray.Dispose();

                return(arrayValues);

            case Type.DICT:
                var stringArray = StringArray.Nil;
                var valueArray  = MValueArray.Nil;
                AltNative.MValueGet.MValue_GetDict(ref this, ref stringArray, ref valueArray);
                var valueArrayPtr      = valueArray.data;
                var stringViewArrayPtr = stringArray.data;
                var size = (int)stringArray.size;
                if (valueArray.Size != (ulong)size)      // Value size != key size should never happen
                {
                    return(null);
                }

                var dictionary = new Dictionary <string, object>();
                for (var i = 0; i < size; i++)
                {
                    var key   = stringArray.GetNextWithOffset(ref stringViewArrayPtr);
                    var value = valueArray.GetNextWithOffset(ref valueArrayPtr);
                    if (key != null)
                    {
                        dictionary[key] = value.ToObject(baseBaseObjectPool);
                    }
                }

                stringArray.Dispose();
                valueArray.Dispose();

                return(dictionary);

            case Type.ENTITY:
                var entityType    = BaseObjectType.Undefined;
                var entityPointer = GetEntityPointer(ref entityType);
                if (entityPointer == IntPtr.Zero)
                {
                    return(null);
                }
                if (baseBaseObjectPool.Get(entityPointer, entityType, out var entity))
                {
                    return(entity);
                }

                return(null);

            case Type.FUNCTION:
                return(GetFunction());

            default:
                return(null);
            }
        }
コード例 #18
0
 public override Core GetCore(IntPtr nativePointer, IntPtr resourcePointer, AssemblyLoadContext assemblyLoadContext, ILibrary library, IBaseBaseObjectPool baseBaseObjectPool,
                              IBaseEntityPool baseEntityPool,
                              IEntityPool <IPlayer> playerPool,
                              IEntityPool <IVehicle> vehiclePool,
                              IBaseObjectPool <IBlip> blipPool,
                              IBaseObjectPool <ICheckpoint> checkpointPool,
                              IBaseObjectPool <IVoiceChannel> voiceChannelPool,
                              IBaseObjectPool <IColShape> colShapePool,
                              INativeResourcePool nativeResourcePool)
 {
     return(new AsyncCore(nativePointer, resourcePointer, assemblyLoadContext, library, baseBaseObjectPool, baseEntityPool, playerPool, vehiclePool, blipPool, checkpointPool, voiceChannelPool, colShapePool, nativeResourcePool));
 }