Skip to content

Commit 2a3c79e

Browse files
Merge pull request #56 from Lhoerion/dev
Fixed resource delegates from being garbage collected & Fixed spelling of Weapons.CompatPwd, Weapons.CarbinRifle and Weapons.Fired
2 parents c599305 + e8d0b5e commit 2a3c79e

File tree

2 files changed

+160
-86
lines changed

2 files changed

+160
-86
lines changed

api/AltV.Net/CSharpResourceImpl.cs

Lines changed: 132 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using AltV.Net.Native;
3+
using System.Runtime.InteropServices;
34

45
namespace AltV.Net
56
{
@@ -30,65 +31,138 @@ public void Unload()
3031
AltNative.Resource.CSharpResourceImpl_Unload(NativePointer);
3132
}
3233

33-
internal void SetDelegates(AltNative.Resource.MainDelegate onStartResource)
34+
internal void SetDelegates(AltNative.Resource.MainDelegate onStart)
3435
{
35-
AltNative.Resource.CSharpResourceImpl_SetMainDelegate(NativePointer,
36-
onStartResource);
37-
AltNative.Resource.CSharpResourceImpl_SetStopDelegate(NativePointer, ModuleWrapper.OnStop);
38-
AltNative.Resource.CSharpResourceImpl_SetTickDelegate(NativePointer, ModuleWrapper.OnTick);
39-
AltNative.Resource.CSharpResourceImpl_SetServerEventDelegate(NativePointer, ModuleWrapper.OnServerEvent);
40-
AltNative.Resource.CSharpResourceImpl_SetCheckpointDelegate(NativePointer, ModuleWrapper.OnCheckpoint);
41-
AltNative.Resource.CSharpResourceImpl_SetClientEventDelegate(NativePointer, ModuleWrapper.OnClientEvent);
42-
AltNative.Resource.CSharpResourceImpl_SetPlayerDamageDelegate(NativePointer,
43-
ModuleWrapper.OnPlayerDamage);
44-
AltNative.Resource.CSharpResourceImpl_SetPlayerConnectDelegate(NativePointer,
45-
ModuleWrapper.OnPlayerConnect);
46-
AltNative.Resource.CSharpResourceImpl_SetPlayerDeathDelegate(NativePointer,
47-
ModuleWrapper.OnPlayerDeath);
48-
AltNative.Resource.CSharpResourceImpl_SetExplosionDelegate(NativePointer,
49-
ModuleWrapper.OnExplosion);
50-
AltNative.Resource.CSharpResourceImpl_SetWeaponDamageDelegate(NativePointer,
51-
ModuleWrapper.OnWeaponDamage);
52-
AltNative.Resource.CSharpResourceImpl_SetPlayerDisconnectDelegate(NativePointer,
53-
ModuleWrapper.OnPlayerDisconnect);
54-
AltNative.Resource.CSharpResourceImpl_SetPlayerRemoveDelegate(NativePointer,
55-
ModuleWrapper.OnPlayerRemove);
56-
AltNative.Resource.CSharpResourceImpl_SetVehicleRemoveDelegate(NativePointer,
57-
ModuleWrapper.OnVehicleRemove);
58-
AltNative.Resource.CSharpResourceImpl_SetPlayerChangeVehicleSeatDelegate(NativePointer,
59-
ModuleWrapper.OnPlayerChangeVehicleSeat);
60-
AltNative.Resource.CSharpResourceImpl_SetPlayerEnterVehicleDelegate(NativePointer,
61-
ModuleWrapper.OnPlayerEnterVehicle);
62-
AltNative.Resource.CSharpResourceImpl_SetPlayerLeaveVehicleDelegate(NativePointer,
63-
ModuleWrapper.OnPlayerLeaveVehicle);
64-
AltNative.Resource.CSharpResourceImpl_SetCreatePlayerDelegate(NativePointer,
65-
ModuleWrapper.OnCreatePlayer);
66-
AltNative.Resource.CSharpResourceImpl_SetRemovePlayerDelegate(NativePointer,
67-
ModuleWrapper.OnRemovePlayer);
68-
AltNative.Resource.CSharpResourceImpl_SetCreateVehicleDelegate(NativePointer,
69-
ModuleWrapper.OnCreateVehicle);
70-
AltNative.Resource.CSharpResourceImpl_SetRemoveVehicleDelegate(NativePointer,
71-
ModuleWrapper.OnRemoveVehicle);
72-
AltNative.Resource.CSharpResourceImpl_SetCreateBlipDelegate(NativePointer, ModuleWrapper.OnCreateBlip);
73-
AltNative.Resource.CSharpResourceImpl_SetRemoveBlipDelegate(NativePointer, ModuleWrapper.OnRemoveBlip);
74-
AltNative.Resource.CSharpResourceImpl_SetCreateCheckpointDelegate(NativePointer,
75-
ModuleWrapper.OnCreateCheckpoint);
76-
AltNative.Resource.CSharpResourceImpl_SetRemoveCheckpointDelegate(NativePointer,
77-
ModuleWrapper.OnRemoveCheckpoint);
78-
AltNative.Resource.CSharpResourceImpl_SetCreateVoiceChannelDelegate(NativePointer,
79-
ModuleWrapper.OnCreateVoiceChannel);
80-
AltNative.Resource.CSharpResourceImpl_SetRemoveVoiceChannelDelegate(NativePointer,
81-
ModuleWrapper.OnRemoveVoiceChannel);
82-
AltNative.Resource.CSharpResourceImpl_SetConsoleCommandDelegate(NativePointer,
83-
ModuleWrapper.OnConsoleCommand);
84-
AltNative.Resource.CSharpResourceImpl_SetMetaChangeDelegate(NativePointer, ModuleWrapper.OnMetaDataChange);
85-
AltNative.Resource.CSharpResourceImpl_SetSyncedMetaChangeDelegate(NativePointer,
86-
ModuleWrapper.OnSyncedMetaDataChange);
87-
AltNative.Resource.CSharpResourceImpl_SetCreateColShapeDelegate(NativePointer,
88-
ModuleWrapper.OnCreateColShape);
89-
AltNative.Resource.CSharpResourceImpl_SetRemoveColShapeDelegate(NativePointer,
90-
ModuleWrapper.OnRemoveColShape);
91-
AltNative.Resource.CSharpResourceImpl_SetColShapeDelegate(NativePointer, ModuleWrapper.OnColShape);
36+
GCHandle.Alloc(onStart);
37+
AltNative.Resource.CSharpResourceImpl_SetMainDelegate(NativePointer, onStart);
38+
39+
AltNative.Resource.StopDelegate onStop = ModuleWrapper.OnStop;
40+
GCHandle.Alloc(onStop);
41+
AltNative.Resource.CSharpResourceImpl_SetStopDelegate(NativePointer, onStop);
42+
43+
AltNative.Resource.TickDelegate onTick = ModuleWrapper.OnTick;
44+
GCHandle.Alloc(onTick);
45+
AltNative.Resource.CSharpResourceImpl_SetTickDelegate(NativePointer, onTick);
46+
47+
AltNative.Resource.ServerEventDelegate onServerEvent = ModuleWrapper.OnServerEvent;
48+
GCHandle.Alloc(onServerEvent);
49+
AltNative.Resource.CSharpResourceImpl_SetServerEventDelegate(NativePointer, onServerEvent);
50+
51+
AltNative.Resource.CheckpointDelegate onCheckpoint = ModuleWrapper.OnCheckpoint;
52+
GCHandle.Alloc(onCheckpoint);
53+
AltNative.Resource.CSharpResourceImpl_SetCheckpointDelegate(NativePointer, onCheckpoint);
54+
55+
AltNative.Resource.ClientEventDelegate onClientEvent = ModuleWrapper.OnClientEvent;
56+
GCHandle.Alloc(onClientEvent);
57+
AltNative.Resource.CSharpResourceImpl_SetClientEventDelegate(NativePointer, onClientEvent);
58+
59+
AltNative.Resource.PlayerDamageDelegate onPlayerDamage = ModuleWrapper.OnPlayerDamage;
60+
GCHandle.Alloc(onPlayerDamage);
61+
AltNative.Resource.CSharpResourceImpl_SetPlayerDamageDelegate(NativePointer, onPlayerDamage);
62+
63+
AltNative.Resource.PlayerConnectDelegate onPlayerConnect = ModuleWrapper.OnPlayerConnect;
64+
GCHandle.Alloc(onPlayerConnect);
65+
AltNative.Resource.CSharpResourceImpl_SetPlayerConnectDelegate(NativePointer, onPlayerConnect);
66+
67+
AltNative.Resource.PlayerDeathDelegate onPlayerDeath = ModuleWrapper.OnPlayerDeath;
68+
GCHandle.Alloc(onPlayerDeath);
69+
AltNative.Resource.CSharpResourceImpl_SetPlayerDeathDelegate(NativePointer, onPlayerDeath);
70+
71+
AltNative.Resource.ExplosionDelegate onExplosion = ModuleWrapper.OnExplosion;
72+
GCHandle.Alloc(onExplosion);
73+
AltNative.Resource.CSharpResourceImpl_SetExplosionDelegate(NativePointer, onExplosion);
74+
75+
AltNative.Resource.WeaponDamageDelegate onWeaponDamage = ModuleWrapper.OnWeaponDamage;
76+
GCHandle.Alloc(onWeaponDamage);
77+
AltNative.Resource.CSharpResourceImpl_SetWeaponDamageDelegate(NativePointer, onWeaponDamage);
78+
79+
AltNative.Resource.PlayerDisconnectDelegate onPlayerDisconnect = ModuleWrapper.OnPlayerDisconnect;
80+
GCHandle.Alloc(onPlayerDisconnect);
81+
AltNative.Resource.CSharpResourceImpl_SetPlayerDisconnectDelegate(NativePointer, onPlayerDisconnect);
82+
83+
AltNative.Resource.PlayerRemoveDelegate onPlayerRemove = ModuleWrapper.OnPlayerRemove;
84+
GCHandle.Alloc(onPlayerRemove);
85+
AltNative.Resource.CSharpResourceImpl_SetPlayerRemoveDelegate(NativePointer, onPlayerRemove);
86+
87+
AltNative.Resource.VehicleRemoveDelegate onVehicleRemove = ModuleWrapper.OnVehicleRemove;
88+
GCHandle.Alloc(onVehicleRemove);
89+
AltNative.Resource.CSharpResourceImpl_SetVehicleRemoveDelegate(NativePointer, onVehicleRemove);
90+
91+
AltNative.Resource.PlayerChangeVehicleSeatDelegate onPlayerChangeVehicleSeat = ModuleWrapper.OnPlayerChangeVehicleSeat;
92+
GCHandle.Alloc(onPlayerChangeVehicleSeat);
93+
AltNative.Resource.CSharpResourceImpl_SetPlayerChangeVehicleSeatDelegate(NativePointer, onPlayerChangeVehicleSeat);
94+
95+
AltNative.Resource.PlayerEnterVehicleDelegate onPlayerEnterVehicle = ModuleWrapper.OnPlayerEnterVehicle;
96+
GCHandle.Alloc(onPlayerEnterVehicle);
97+
AltNative.Resource.CSharpResourceImpl_SetPlayerEnterVehicleDelegate(NativePointer, onPlayerEnterVehicle);
98+
99+
AltNative.Resource.PlayerLeaveVehicleDelegate onPlayerLeaveVehicle = ModuleWrapper.OnPlayerLeaveVehicle;
100+
GCHandle.Alloc(onPlayerLeaveVehicle);
101+
AltNative.Resource.CSharpResourceImpl_SetPlayerLeaveVehicleDelegate(NativePointer, onPlayerLeaveVehicle);
102+
103+
AltNative.Resource.CreatePlayerDelegate onCreatePlayer = ModuleWrapper.OnCreatePlayer;
104+
GCHandle.Alloc(onCreatePlayer);
105+
AltNative.Resource.CSharpResourceImpl_SetCreatePlayerDelegate(NativePointer, onCreatePlayer);
106+
107+
AltNative.Resource.RemovePlayerDelegate onRemovePlayer = ModuleWrapper.OnRemovePlayer;
108+
GCHandle.Alloc(onRemovePlayer);
109+
AltNative.Resource.CSharpResourceImpl_SetRemovePlayerDelegate(NativePointer, onRemovePlayer);
110+
111+
AltNative.Resource.CreateVehicleDelegate onCreateVehicle = ModuleWrapper.OnCreateVehicle;
112+
GCHandle.Alloc(onCreateVehicle);
113+
AltNative.Resource.CSharpResourceImpl_SetCreateVehicleDelegate(NativePointer, onCreateVehicle);
114+
115+
AltNative.Resource.RemoveVehicleDelegate onRemoveVehicle = ModuleWrapper.OnRemoveVehicle;
116+
GCHandle.Alloc(onRemoveVehicle);
117+
AltNative.Resource.CSharpResourceImpl_SetRemoveVehicleDelegate(NativePointer, onRemoveVehicle);
118+
119+
AltNative.Resource.CreateBlipDelegate onCreateBlip = ModuleWrapper.OnCreateBlip;
120+
GCHandle.Alloc(onCreateBlip);
121+
AltNative.Resource.CSharpResourceImpl_SetCreateBlipDelegate(NativePointer, onCreateBlip);
122+
123+
AltNative.Resource.RemoveBlipDelegate onRemoveBlip = ModuleWrapper.OnRemoveBlip;
124+
GCHandle.Alloc(onRemoveBlip);
125+
AltNative.Resource.CSharpResourceImpl_SetRemoveBlipDelegate(NativePointer, onRemoveBlip);
126+
127+
AltNative.Resource.CreateCheckpointDelegate onCreateCheckpoint = ModuleWrapper.OnCreateCheckpoint;
128+
GCHandle.Alloc(onCreateCheckpoint);
129+
AltNative.Resource.CSharpResourceImpl_SetCreateCheckpointDelegate(NativePointer, onCreateCheckpoint);
130+
131+
AltNative.Resource.RemoveCheckpointDelegate onRemoveCheckpoint = ModuleWrapper.OnRemoveCheckpoint;
132+
GCHandle.Alloc(onRemoveCheckpoint);
133+
AltNative.Resource.CSharpResourceImpl_SetRemoveCheckpointDelegate(NativePointer, onRemoveCheckpoint);
134+
135+
AltNative.Resource.CreateVoiceChannelDelegate onCreateVoiceChannel = ModuleWrapper.OnCreateVoiceChannel;
136+
GCHandle.Alloc(onCreateVoiceChannel);
137+
AltNative.Resource.CSharpResourceImpl_SetCreateVoiceChannelDelegate(NativePointer, onCreateVoiceChannel);
138+
139+
AltNative.Resource.RemoveVoiceChannelDelegate onRemoveVoiceChannel = ModuleWrapper.OnRemoveVoiceChannel;
140+
GCHandle.Alloc(onRemoveVoiceChannel);
141+
AltNative.Resource.CSharpResourceImpl_SetRemoveVoiceChannelDelegate(NativePointer, onRemoveVoiceChannel);
142+
143+
AltNative.Resource.ConsoleCommandDelegate onConsoleCommand = ModuleWrapper.OnConsoleCommand;
144+
GCHandle.Alloc(onConsoleCommand);
145+
AltNative.Resource.CSharpResourceImpl_SetConsoleCommandDelegate(NativePointer, onConsoleCommand);
146+
147+
AltNative.Resource.MetaChangeDelegate onMetaDataChange = ModuleWrapper.OnMetaDataChange;
148+
GCHandle.Alloc(onMetaDataChange);
149+
AltNative.Resource.CSharpResourceImpl_SetMetaChangeDelegate(NativePointer, onMetaDataChange);
150+
151+
AltNative.Resource.MetaChangeDelegate onSyncedMetaDataChange = ModuleWrapper.OnSyncedMetaDataChange;
152+
GCHandle.Alloc(onSyncedMetaDataChange);
153+
AltNative.Resource.CSharpResourceImpl_SetSyncedMetaChangeDelegate(NativePointer, onSyncedMetaDataChange);
154+
155+
AltNative.Resource.CreateColShapeDelegate onCreateColShape = ModuleWrapper.OnCreateColShape;
156+
GCHandle.Alloc(onCreateColShape);
157+
AltNative.Resource.CSharpResourceImpl_SetCreateColShapeDelegate(NativePointer, onCreateColShape);
158+
159+
AltNative.Resource.RemoveColShapeDelegate onRemoveColShape = ModuleWrapper.OnRemoveColShape;
160+
GCHandle.Alloc(onRemoveColShape);
161+
AltNative.Resource.CSharpResourceImpl_SetRemoveColShapeDelegate(NativePointer, onRemoveColShape);
162+
163+
AltNative.Resource.ColShapeDelegate onColShape = ModuleWrapper.OnColShape;
164+
GCHandle.Alloc(onColShape);
165+
AltNative.Resource.CSharpResourceImpl_SetColShapeDelegate(NativePointer, onColShape);
92166
}
93167
}
94168
}

api/AltV.Net/Data/Weapons.cs

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
11
namespace AltV.Net.Data
22
{
3-
public static class Weapons
4-
{
5-
public static uint Knife = Alt.Hash("WEAPON_KNIFE");
6-
public static uint Bat = Alt.Hash("WEAPON_BAT");
7-
public static uint Bottle = Alt.Hash("WEAPON_BOTTLE");
8-
public static uint Wrench = Alt.Hash("WEAPON_WRENCH");
9-
public static uint Pistol = Alt.Hash("WEAPON_PISTOL");
10-
public static uint HeavyPistol = Alt.Hash("WEAPON_HEAVYPISTOL");
11-
public static uint Revolver = Alt.Hash("WEAPON_REVOLVER");
12-
public static uint MicroSmg = Alt.Hash("WEAPON_MICROSMG");
13-
public static uint Smg = Alt.Hash("WEAPON_SMG");
14-
public static uint CompatPwd = Alt.Hash("WEAPON_COMBATPDW");
15-
public static uint AssaultRifle = Alt.Hash("WEAPON_ASSAULTRIFLE");
16-
public static uint CarbinRifle = Alt.Hash("WEAPON_CARBINERIFLE");
17-
public static uint PumpShotgun = Alt.Hash("WEAPON_PUMPSHOTGUN");
18-
public static uint Grenade = Alt.Hash("WEAPON_GRENADE");
19-
public static uint RammedByCar = Alt.Hash("WEAPON_RAMMED_BY_CAR");
20-
public static uint RunOverByCar = Alt.Hash("WEAPON_RUN_OVER_BY_CAR");
21-
public static uint Fall = Alt.Hash("WEAPON_FALL");
22-
public static uint Drowning = Alt.Hash("WEAPON_DROWNING");
23-
public static uint DrowningInVehicle = Alt.Hash("WEAPON_DROWNING_IN_VEHICLE");
24-
public static uint Explosion = Alt.Hash("WEAPON_EXPLOSION");
25-
public static uint Fired = Alt.Hash("WEAPON_FIRE");
26-
public static uint Bleeding = Alt.Hash("WEAPON_BLEEDING");
27-
public static uint BarbedWire = Alt.Hash("WEAPON_BARBED_WIRE");
28-
public static uint Exhaustion = Alt.Hash("WEAPON_EXHAUSTION");
29-
public static uint ElectricFence = Alt.Hash("WEAPON_ELECTRIC_FENCE");
30-
}
3+
public static class Weapons
4+
{
5+
public static uint Knife = Alt.Hash("WEAPON_KNIFE");
6+
public static uint Bat = Alt.Hash("WEAPON_BAT");
7+
public static uint Bottle = Alt.Hash("WEAPON_BOTTLE");
8+
public static uint Wrench = Alt.Hash("WEAPON_WRENCH");
9+
public static uint Pistol = Alt.Hash("WEAPON_PISTOL");
10+
public static uint HeavyPistol = Alt.Hash("WEAPON_HEAVYPISTOL");
11+
public static uint Revolver = Alt.Hash("WEAPON_REVOLVER");
12+
public static uint MicroSmg = Alt.Hash("WEAPON_MICROSMG");
13+
public static uint Smg = Alt.Hash("WEAPON_SMG");
14+
public static uint CombatPdw = Alt.Hash("WEAPON_COMBATPDW");
15+
public static uint AssaultRifle = Alt.Hash("WEAPON_ASSAULTRIFLE");
16+
public static uint CarbineRifle = Alt.Hash("WEAPON_CARBINERIFLE");
17+
public static uint PumpShotgun = Alt.Hash("WEAPON_PUMPSHOTGUN");
18+
public static uint Grenade = Alt.Hash("WEAPON_GRENADE");
19+
public static uint RammedByCar = Alt.Hash("WEAPON_RAMMED_BY_CAR");
20+
public static uint RunOverByCar = Alt.Hash("WEAPON_RUN_OVER_BY_CAR");
21+
public static uint Fall = Alt.Hash("WEAPON_FALL");
22+
public static uint Drowning = Alt.Hash("WEAPON_DROWNING");
23+
public static uint DrowningInVehicle = Alt.Hash("WEAPON_DROWNING_IN_VEHICLE");
24+
public static uint Explosion = Alt.Hash("WEAPON_EXPLOSION");
25+
public static uint Fire = Alt.Hash("WEAPON_FIRE");
26+
public static uint Bleeding = Alt.Hash("WEAPON_BLEEDING");
27+
public static uint BarbedWire = Alt.Hash("WEAPON_BARBED_WIRE");
28+
public static uint Exhaustion = Alt.Hash("WEAPON_EXHAUSTION");
29+
public static uint ElectricFence = Alt.Hash("WEAPON_ELECTRIC_FENCE");
30+
}
3131
}

0 commit comments

Comments
 (0)