/// <inheritdoc /> public T AddComponent <T>(EntityId entity) where T : Component { if (!_entities.TryGetValue(entity, out var entityEntry)) { throw new EntityNotFoundException(nameof(entity)); } var component = typeof(NativeComponent).IsAssignableFrom(typeof(T)) ? NativeObjectProxyFactory.CreateInstance <T>() : (T)Activator.CreateInstance(typeof(T), BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance, null, null, null); component.Entity = entity; component.Manager = this; entityEntry.Components.Add(component); _components.Add(component); component.InitializeComponent(); return(component); }
static TextDraw() { Internal = NativeObjectProxyFactory.CreateInstance <TextDrawInternal>(); }
static YSF() { Internal = NativeObjectProxyFactory.CreateInstance <YSFInternal>(); }
static Menu() { Internal = NativeObjectProxyFactory.CreateInstance <MenuInternal>(); }
static TextLabel() { Internal = NativeObjectProxyFactory.CreateInstance <TextLabelInternal>(); }
static Pickup() { Internal = NativeObjectProxyFactory.CreateInstance <PickupInternal>(); }
static FCNPC() { Internal = NativeObjectProxyFactory.CreateInstance <FCNPCInternal>(); }
static GlobalObject() { Internal = NativeObjectProxyFactory.CreateInstance <GlobalObjectInternal>(); }
static MovePath() { Internal = NativeObjectProxyFactory.CreateInstance <MovePathInternal>(); }
static BitStream() { Internal = NativeObjectProxyFactory.CreateInstance <BitStreamInternal>(); }
static Playback() { Internal = NativeObjectProxyFactory.CreateInstance <PlaybackInternal>(); }
static DynamicActor() { Internal = NativeObjectProxyFactory.CreateInstance <DynamicActorInternal>(); }
/// <summary> /// Initializes a new instance of the <see cref="NativeProxy{T}" /> class. /// </summary> public NativeProxy() { Instance = NativeObjectProxyFactory.CreateInstance <T>(); }
static DynamicWorldObject() { WorldInternal = NativeObjectProxyFactory.CreateInstance <DynamicWorldObjectInternal>(); }
static Dialog() { Internal = NativeObjectProxyFactory.CreateInstance <DialogInternal>(); }
static VehicleModelInfo() { Internal = NativeObjectProxyFactory.CreateInstance <VehicleModelInfoInternal>(); }
static BaseVehicle() { Internal = NativeObjectProxyFactory.CreateInstance <VehicleInternal>(); }
static PlayerObject() { Internal = NativeObjectProxyFactory.CreateInstance <PlayerObjectInternal>(); }
public void OnGameModeInit(IWorldService worldService, IEntityManager entityManager, INativeObjectProxyFactory proxyFactory, ITimerService timerService) { // Only test FastNative performance if FastNative is not activated if (proxyFactory is FastNativeBasedNativeObjectProxyFactory) { return; } //timerService.Start(_ => BenchmarkRunTimer(), TimeSpan.FromSeconds(2)); timerService.Start(_ => BenchmarkRunTimerProxy(), TimeSpan.FromSeconds(2)); _nativeGetVehicleParamsEx = Interop.FastNativeFind("GetVehicleParamsEx"); _testVehicleId = worldService.CreateVehicle(VehicleModelType.BMX, Vector3.One, 0, 0, 0).Entity.Handle; var fastFactory = new FastNativeBasedNativeObjectProxyFactory(_client); var handleProxy = NativeObjectProxyFactory.CreateInstance <TestingFastNative>(); var fastProxy = (TestingFastNative)fastFactory.CreateInstance(typeof(TestingFastNative)); _fastProxy = fastProxy; // Call IsPlayerConnected timerService.Start(_ => { Console.WriteLine("RequiresInvoke: " + ((ISynchronizationProvider)_client).InvokeRequired); Console.WriteLine("IsPlayerConnected fast: " + fastProxy.IsPlayerConnected(0)); Console.WriteLine("IsPlayerConnected handle: " + handleProxy.IsPlayerConnected(0)); Task.Run(() => { Console.WriteLine("TASK.RequiresInvoke: " + ((ISynchronizationProvider)_client).InvokeRequired); Console.WriteLine("TASK.IsPlayerConnected fast: " + fastProxy.IsPlayerConnected(0)); Console.WriteLine("TASK.IsPlayerConnected handle: " + handleProxy.IsPlayerConnected(0)); }); }, TimeSpan.FromSeconds(1)); // Call CreateVehicle native var testPosition = new Vector3(65.13f, 123.123f, 555.555f); var fastVehicleId = fastProxy.CreateVehicle((int)VehicleModelType.Landstalker, testPosition.X, testPosition.Y, testPosition.Z, 15, -1, -1, -1, 0); // Create Vehicle entity to verify vehicle position was set properly through the native var entity = SampEntities.GetVehicleId(fastVehicleId); entityManager.Create(entity); entityManager.AddComponent <NativeVehicle>(entity); var fastVehicleComp = entityManager.AddComponent <Vehicle>(entity); Console.WriteLine($"Created vehicle {fastVehicleId} position {fastVehicleComp.Position}; matches? {(fastVehicleComp.Position == testPosition)}"); // Call GetVehiclePos var ret = fastProxy.GetVehiclePos(fastVehicleId, out var x, out var y, out var z); var getPos = new Vector3(x, y, z); Console.WriteLine($"get pos ({ret}): {getPos} matches? {(testPosition == getPos)}"); // Test immediate call to SetGameModeText // var nativeSetGameModeText = Interop.FastNativeFind("SetGameModeText"); // SetGameModeTextCall(nativeSetGameModeText, "TestValue"); // Test via proxy fastProxy.SetGameModeText("TestValueViaProxy"); }
static DynamicMapIcon() { Internal = NativeObjectProxyFactory.CreateInstance <DynamicMapIconInternal>(); }
static BaseMode() { Internal = NativeObjectProxyFactory.CreateInstance <BaseModeInternal>(); }
static GangZone() { Internal = NativeObjectProxyFactory.CreateInstance <GangZoneInternal>(); }
static Streamer() { Internal = NativeObjectProxyFactory.CreateInstance <StreamerInternal>(); }
static MapAndreas() { Internal = NativeObjectProxyFactory.CreateInstance <MapAndreasInternal>(); }
static Sky() { Internal = NativeObjectProxyFactory.CreateInstance <SkyInternal>(); }
static PVarCollection() { Internal = NativeObjectProxyFactory.CreateInstance <PVarCollectionInternal>(); }
static DynamicCheckpoint() { Internal = NativeObjectProxyFactory.CreateInstance <DynamicCheckpointInternal>(); }
static RakNet() { Internal = NativeObjectProxyFactory.CreateInstance <RakNetInternal>(); }