Exemplo n.º 1
0
 public ICheckpoint CreateCheckpoint(byte type, Position pos, float radius, float height,
                                     Rgba color)
 {
     unsafe
     {
         CheckIfCallIsValid();
         CheckIfThreadIsValid();
         var ptr = Library.Server.Core_CreateCheckpoint(NativePointer, type, pos, radius, height, color);
         if (ptr == IntPtr.Zero)
         {
             return(null);
         }
         return(CheckpointPool.Create(this, ptr));
     }
 }
        public static void MainWithAssembly(Assembly resourceAssembly, IntPtr resourcePointer, IntPtr corePointer, string dllName)
        {
            DllName = dllName;

            var library = new Library(DllName, true);
            var logger  = new Logger(library, corePointer);

            Alt.Logger = logger;
            Alt.Log("Library initialized");

            unsafe
            {
                if (library.Shared.Core_GetEventEnumSize() != (byte)EventType.SIZE)
                {
                    throw new Exception("Event type enum size doesn't match. Please, update the nuget");
                }
            }

            AppDomain.CurrentDomain.UnhandledException += OnUnhandledException;

            _resourcePointer = resourcePointer;
            _corePointer     = corePointer;

            var type     = typeof(IResource);
            var resource = resourceAssembly.GetTypes().FirstOrDefault(t => t.IsClass && !t.IsAbstract && type.IsAssignableFrom(t));

            if (resource is null)
            {
                throw new Exception("Cannot find resource");
                return;
            }

            _resource = (IResource)Activator.CreateInstance(resource) !;
            Alt.Log("Resource created");

            Alt.Logger = _resource.GetLogger(library, corePointer);

            var playerPool = new PlayerPool(_resource.GetPlayerFactory());

            Alt.Log("Player pool created");

            var vehiclePool = new VehiclePool(_resource.GetVehicleFactory());

            Alt.Log("Vehicle pool created");

            var blipPool = new BlipPool(_resource.GetBlipFactory());

            Alt.Log("Blip pool created");

            var checkpointPool = new CheckpointPool(_resource.GetCheckpointFactory());

            Alt.Log("Checkpoint pool created");

            var audioPool = new AudioPool(_resource.GetAudioFactory());

            Alt.Log("Audio pool created");

            var httpClientPool = new HttpClientPool(_resource.GetHttpClientFactory());

            Alt.Log("Http client pool created");

            var webSocketClientPool = new WebSocketClientPool(_resource.GetWebSocketClientFactory());

            Alt.Log("WebSocket client pool created");

            var webViewPool = new WebViewPool(_resource.GetWebViewFactory());

            Alt.Log("Webview pool created");

            var rmlDocumentPool = new RmlDocumentPool(new RmlDocumentFactory());
            var rmlElementPool  = new RmlElementPool(new RmlElementFactory());

            Alt.Log("Rml pools created");

            var nativeResourcePool = new NativeResourcePool(_resource.GetResourceFactory());

            Alt.Log("Native resource pool created");

            var baseBaseObjectPool = new BaseBaseObjectPool(playerPool, vehiclePool, blipPool, checkpointPool, audioPool, httpClientPool, webSocketClientPool, webViewPool, rmlElementPool, rmlDocumentPool);
            var baseEntityPool     = new BaseEntityPool(playerPool, vehiclePool);
            var timerPool          = new TimerPool();

            var natives = _resource.GetNatives(DllName);

            var client = new Core(
                library,
                corePointer,
                resourcePointer,
                playerPool,
                vehiclePool,
                blipPool,
                checkpointPool,
                audioPool,
                httpClientPool,
                webSocketClientPool,
                webViewPool,
                rmlDocumentPool,
                rmlElementPool,
                baseBaseObjectPool,
                baseEntityPool,
                nativeResourcePool,
                timerPool,
                logger,
                natives
                );

            _core          = client;
            Alt.CoreImpl   = client;
            AltShared.Core = client;
            Alt.Log("Core initialized");

            _core.GetPlayers();
            _core.GetVehicles();
            _core.GetBlips();

            playerPool.InitLocalPlayer(_core);

            _core.Resource.CSharpResourceImpl.SetDelegates();
            Alt.Log("Delegates set");

            _resource.OnStart();
            Alt.Log("Startup finished");
        }