Skip to content

Commit c599305

Browse files
Rewrite delegate handling
1 parent 766d32b commit c599305

File tree

4 files changed

+493
-217
lines changed

4 files changed

+493
-217
lines changed

api/AltV.Net/CSharpResourceImpl.cs

Lines changed: 60 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -17,55 +17,78 @@ internal CSharpResourceImpl(IntPtr nativePointer)
1717

1818
public void Reload()
1919
{
20-
AltNative.Resource.CSharpResource_Reload(NativePointer);
20+
AltNative.Resource.CSharpResourceImpl_Reload(NativePointer);
2121
}
2222

2323
public void Load()
2424
{
25-
AltNative.Resource.CSharpResource_Load(NativePointer);
25+
AltNative.Resource.CSharpResourceImpl_Load(NativePointer);
2626
}
2727

2828
public void Unload()
2929
{
30-
AltNative.Resource.CSharpResource_Unload(NativePointer);
30+
AltNative.Resource.CSharpResourceImpl_Unload(NativePointer);
3131
}
3232

3333
internal void SetDelegates(AltNative.Resource.MainDelegate onStartResource)
3434
{
35-
AltNative.Resource.CSharpResource_SetMain(NativePointer,
36-
onStartResource,
37-
ModuleWrapper.OnStop,
38-
ModuleWrapper.OnTick,
39-
ModuleWrapper.OnServerEvent,
40-
ModuleWrapper.OnCheckpoint,
41-
ModuleWrapper.OnClientEvent,
42-
ModuleWrapper.OnPlayerDamage,
43-
ModuleWrapper.OnPlayerConnect,
44-
ModuleWrapper.OnPlayerDeath,
45-
ModuleWrapper.OnExplosion,
46-
ModuleWrapper.OnWeaponDamage,
47-
ModuleWrapper.OnPlayerDisconnect,
48-
ModuleWrapper.OnPlayerRemove,
49-
ModuleWrapper.OnVehicleRemove,
50-
ModuleWrapper.OnPlayerChangeVehicleSeat,
51-
ModuleWrapper.OnPlayerEnterVehicle,
52-
ModuleWrapper.OnPlayerLeaveVehicle,
53-
ModuleWrapper.OnCreatePlayer,
54-
ModuleWrapper.OnRemovePlayer,
55-
ModuleWrapper.OnCreateVehicle,
56-
ModuleWrapper.OnRemoveVehicle,
57-
ModuleWrapper.OnCreateBlip,
58-
ModuleWrapper.OnRemoveBlip,
59-
ModuleWrapper.OnCreateCheckpoint,
60-
ModuleWrapper.OnRemoveCheckpoint,
61-
ModuleWrapper.OnCreateVoiceChannel,
62-
ModuleWrapper.OnRemoveVoiceChannel,
63-
ModuleWrapper.OnConsoleCommand,
64-
ModuleWrapper.OnMetaDataChange,
65-
ModuleWrapper.OnSyncedMetaDataChange,
66-
ModuleWrapper.OnCreateColShape,
67-
ModuleWrapper.OnRemoveColShape,
68-
ModuleWrapper.OnColShape);
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);
6992
}
7093
}
7194
}

api/AltV.Net/Native/AltV.Resource.cs

Lines changed: 134 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,13 @@ internal static partial class AltNative
1111
internal static class Resource
1212
{
1313
[DllImport(DllName, CallingConvention = NativeCallingConvention)]
14-
internal static extern ushort
15-
CSharpResource_SetExport(IntPtr resourcePointer, string key, ref MValue value);
14+
internal static extern void CSharpResourceImpl_Reload(IntPtr resourcePointer);
1615

1716
[DllImport(DllName, CallingConvention = NativeCallingConvention)]
18-
internal static extern void CSharpResource_Reload(IntPtr resourcePointer);
17+
internal static extern void CSharpResourceImpl_Load(IntPtr resourcePointer);
1918

2019
[DllImport(DllName, CallingConvention = NativeCallingConvention)]
21-
internal static extern void CSharpResource_Load(IntPtr resourcePointer);
22-
23-
[DllImport(DllName, CallingConvention = NativeCallingConvention)]
24-
internal static extern void CSharpResource_Unload(IntPtr resourcePointer);
20+
internal static extern void CSharpResourceImpl_Unload(IntPtr resourcePointer);
2521

2622
[DllImport(DllName, CallingConvention = NativeCallingConvention)]
2723
internal static extern ushort Resource_GetExports(IntPtr resourcePointer, ref StringViewArray keys,
@@ -127,7 +123,7 @@ internal delegate void ColShapeDelegate(IntPtr colShapePointer, IntPtr targetEnt
127123

128124
internal delegate void ConsoleCommandDelegate(string name, ref StringViewArray args);
129125

130-
internal delegate void MetaDataChange(IntPtr entityPointer, BaseObjectType entityType, string key,
126+
internal delegate void MetaChangeDelegate(IntPtr entityPointer, BaseObjectType entityType, string key,
131127
ref MValue value);
132128

133129
internal delegate void ExplosionDelegate(IntPtr playerPointer, ExplosionType explosionType,
@@ -137,41 +133,136 @@ internal delegate void WeaponDamageDelegate(IntPtr playerPointer, IntPtr entityP
137133
BaseObjectType entityType, uint weapon, ushort damage, Position shotOffset, BodyPart bodyPart);
138134

139135
[DllImport(DllName, CallingConvention = NativeCallingConvention)]
140-
internal static extern void CSharpResource_SetMain(IntPtr resourcePointer,
141-
MainDelegate mainDelegate,
142-
StopDelegate stopDelegate,
143-
TickDelegate tickDelegate,
144-
ServerEventDelegate serverEventDelegate,
145-
CheckpointDelegate checkpointDelegate,
146-
ClientEventDelegate clientEventDelegate,
147-
PlayerDamageDelegate playerDamageDelegate,
148-
PlayerConnectDelegate playerConnectDelegate,
149-
PlayerDeathDelegate playerDeathDelegate,
150-
ExplosionDelegate explosionDelegate,
151-
WeaponDamageDelegate weaponDamageDelegate,
152-
PlayerDisconnectDelegate playerDisconnectDelegate,
153-
PlayerRemoveDelegate playerRemoveDelegate,
154-
VehicleRemoveDelegate vehicleRemoveDelegate,
155-
PlayerChangeVehicleSeatDelegate playerChangeVehicleSeatDelegate,
156-
PlayerEnterVehicleDelegate playerEnterVehicleDelegate,
157-
PlayerLeaveVehicleDelegate playerLeaveVehicleDelegate,
158-
CreatePlayerDelegate createPlayerDelegate,
159-
RemovePlayerDelegate removePlayerDelegate,
160-
CreateVehicleDelegate createVehicleDelegate,
161-
RemoveVehicleDelegate removeVehicleDelegate,
162-
CreateBlipDelegate createBlipDelegate,
163-
RemoveBlipDelegate removeBlipDelegate,
164-
CreateCheckpointDelegate createCheckpointDelegate,
165-
RemoveCheckpointDelegate removeCheckpointDelegate,
166-
CreateVoiceChannelDelegate createVoiceChannelDelegate,
167-
RemoveVoiceChannelDelegate removeVoiceChannelDelegate,
168-
ConsoleCommandDelegate consoleCommandDelegate,
169-
MetaDataChange metaDataChange,
170-
MetaDataChange syncedMetaDataChange,
171-
CreateColShapeDelegate createColShapeDelegate,
172-
RemoveColShapeDelegate removeColShapeDelegate,
173-
ColShapeDelegate colShapeDelegate
174-
);
136+
internal static extern void CSharpResourceImpl_SetMainDelegate(IntPtr resource,
137+
MainDelegate @delegate);
138+
139+
[DllImport(DllName, CallingConvention = NativeCallingConvention)]
140+
internal static extern void CSharpResourceImpl_SetStopDelegate(IntPtr resource,
141+
StopDelegate @delegate);
142+
143+
[DllImport(DllName, CallingConvention = NativeCallingConvention)]
144+
internal static extern void CSharpResourceImpl_SetTickDelegate(IntPtr resource,
145+
TickDelegate @delegate);
146+
147+
[DllImport(DllName, CallingConvention = NativeCallingConvention)]
148+
internal static extern void CSharpResourceImpl_SetServerEventDelegate(IntPtr resource,
149+
ServerEventDelegate @delegate);
150+
151+
[DllImport(DllName, CallingConvention = NativeCallingConvention)]
152+
internal static extern void CSharpResourceImpl_SetCheckpointDelegate(IntPtr resource,
153+
CheckpointDelegate @delegate);
154+
155+
[DllImport(DllName, CallingConvention = NativeCallingConvention)]
156+
internal static extern void CSharpResourceImpl_SetClientEventDelegate(IntPtr resource,
157+
ClientEventDelegate @delegate);
158+
159+
[DllImport(DllName, CallingConvention = NativeCallingConvention)]
160+
internal static extern void CSharpResourceImpl_SetPlayerDamageDelegate(IntPtr resource,
161+
PlayerDamageDelegate @delegate);
162+
163+
[DllImport(DllName, CallingConvention = NativeCallingConvention)]
164+
internal static extern void CSharpResourceImpl_SetPlayerConnectDelegate(IntPtr resource,
165+
PlayerConnectDelegate @delegate);
166+
167+
[DllImport(DllName, CallingConvention = NativeCallingConvention)]
168+
internal static extern void CSharpResourceImpl_SetPlayerDeathDelegate(IntPtr resource,
169+
PlayerDeathDelegate @delegate);
170+
171+
[DllImport(DllName, CallingConvention = NativeCallingConvention)]
172+
internal static extern void CSharpResourceImpl_SetExplosionDelegate(IntPtr resource,
173+
ExplosionDelegate @delegate);
174+
175+
[DllImport(DllName, CallingConvention = NativeCallingConvention)]
176+
internal static extern void CSharpResourceImpl_SetWeaponDamageDelegate(IntPtr resource,
177+
WeaponDamageDelegate @delegate);
178+
179+
[DllImport(DllName, CallingConvention = NativeCallingConvention)]
180+
internal static extern void CSharpResourceImpl_SetPlayerDisconnectDelegate(IntPtr resource,
181+
PlayerDisconnectDelegate @delegate);
182+
183+
[DllImport(DllName, CallingConvention = NativeCallingConvention)]
184+
internal static extern void CSharpResourceImpl_SetPlayerRemoveDelegate(IntPtr resource,
185+
PlayerRemoveDelegate @delegate);
186+
187+
[DllImport(DllName, CallingConvention = NativeCallingConvention)]
188+
internal static extern void CSharpResourceImpl_SetVehicleRemoveDelegate(IntPtr resource,
189+
VehicleRemoveDelegate @delegate);
190+
191+
[DllImport(DllName, CallingConvention = NativeCallingConvention)]
192+
internal static extern void CSharpResourceImpl_SetPlayerChangeVehicleSeatDelegate(IntPtr resource,
193+
PlayerChangeVehicleSeatDelegate @delegate);
194+
195+
[DllImport(DllName, CallingConvention = NativeCallingConvention)]
196+
internal static extern void CSharpResourceImpl_SetPlayerEnterVehicleDelegate(IntPtr resource,
197+
PlayerEnterVehicleDelegate @delegate);
198+
199+
[DllImport(DllName, CallingConvention = NativeCallingConvention)]
200+
internal static extern void CSharpResourceImpl_SetPlayerLeaveVehicleDelegate(IntPtr resource,
201+
PlayerLeaveVehicleDelegate @delegate);
202+
203+
[DllImport(DllName, CallingConvention = NativeCallingConvention)]
204+
internal static extern void CSharpResourceImpl_SetCreatePlayerDelegate(IntPtr resource,
205+
CreatePlayerDelegate @delegate);
206+
207+
[DllImport(DllName, CallingConvention = NativeCallingConvention)]
208+
internal static extern void CSharpResourceImpl_SetRemovePlayerDelegate(IntPtr resource,
209+
RemovePlayerDelegate @delegate);
210+
211+
[DllImport(DllName, CallingConvention = NativeCallingConvention)]
212+
internal static extern void CSharpResourceImpl_SetCreateVehicleDelegate(IntPtr resource,
213+
CreateVehicleDelegate @delegate);
214+
215+
[DllImport(DllName, CallingConvention = NativeCallingConvention)]
216+
internal static extern void CSharpResourceImpl_SetRemoveVehicleDelegate(IntPtr resource,
217+
RemoveVehicleDelegate @delegate);
218+
219+
[DllImport(DllName, CallingConvention = NativeCallingConvention)]
220+
internal static extern void CSharpResourceImpl_SetCreateBlipDelegate(IntPtr resource,
221+
CreateBlipDelegate @delegate);
222+
223+
[DllImport(DllName, CallingConvention = NativeCallingConvention)]
224+
internal static extern void CSharpResourceImpl_SetRemoveBlipDelegate(IntPtr resource,
225+
RemoveBlipDelegate @delegate);
226+
227+
[DllImport(DllName, CallingConvention = NativeCallingConvention)]
228+
internal static extern void CSharpResourceImpl_SetCreateCheckpointDelegate(IntPtr resource,
229+
CreateCheckpointDelegate @delegate);
230+
231+
[DllImport(DllName, CallingConvention = NativeCallingConvention)]
232+
internal static extern void CSharpResourceImpl_SetRemoveCheckpointDelegate(IntPtr resource,
233+
RemoveCheckpointDelegate @delegate);
234+
235+
[DllImport(DllName, CallingConvention = NativeCallingConvention)]
236+
internal static extern void CSharpResourceImpl_SetCreateVoiceChannelDelegate(IntPtr resource,
237+
CreateVoiceChannelDelegate @delegate);
238+
239+
[DllImport(DllName, CallingConvention = NativeCallingConvention)]
240+
internal static extern void CSharpResourceImpl_SetRemoveVoiceChannelDelegate(IntPtr resource,
241+
RemoveVoiceChannelDelegate @delegate);
242+
243+
[DllImport(DllName, CallingConvention = NativeCallingConvention)]
244+
internal static extern void CSharpResourceImpl_SetConsoleCommandDelegate(IntPtr resource,
245+
ConsoleCommandDelegate @delegate);
246+
247+
[DllImport(DllName, CallingConvention = NativeCallingConvention)]
248+
internal static extern void CSharpResourceImpl_SetMetaChangeDelegate(IntPtr resource,
249+
MetaChangeDelegate @delegate);
250+
251+
[DllImport(DllName, CallingConvention = NativeCallingConvention)]
252+
internal static extern void CSharpResourceImpl_SetSyncedMetaChangeDelegate(IntPtr resource,
253+
MetaChangeDelegate @delegate);
254+
255+
[DllImport(DllName, CallingConvention = NativeCallingConvention)]
256+
internal static extern void CSharpResourceImpl_SetCreateColShapeDelegate(IntPtr resource,
257+
CreateColShapeDelegate @delegate);
258+
259+
[DllImport(DllName, CallingConvention = NativeCallingConvention)]
260+
internal static extern void CSharpResourceImpl_SetRemoveColShapeDelegate(IntPtr resource,
261+
RemoveColShapeDelegate @delegate);
262+
263+
[DllImport(DllName, CallingConvention = NativeCallingConvention)]
264+
internal static extern void CSharpResourceImpl_SetColShapeDelegate(IntPtr resource,
265+
ColShapeDelegate @delegate);
175266
}
176267
}
177268
}

0 commit comments

Comments
 (0)