Skip to content

Commit 3db5001

Browse files
Timschuumarkatk
authored andcommitted
Add synced methods to player weapons
1 parent 4094886 commit 3db5001

File tree

2 files changed

+162
-57
lines changed

2 files changed

+162
-57
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using System;
21
using System.Collections.Generic;
32
using System.Linq;
43
using System.Runtime.InteropServices;
@@ -11,111 +10,171 @@ namespace AlternateLife.RageMP.Net.Elements.Entities
1110
{
1211
internal partial class Player
1312
{
14-
public async Task SetCurrentWeaponAsync(uint value)
13+
public void SetCurrentWeapon(uint value)
1514
{
1615
CheckExistence();
1716

18-
await _plugin
19-
.Schedule(() => Rage.Player.Player_SetCurrentWeapon(NativePointer, value))
20-
.ConfigureAwait(false);
17+
Rage.Player.Player_SetCurrentWeapon(NativePointer, value);
2118
}
2219

23-
public async Task<uint> GetCurrentWeaponAsync()
20+
public Task SetCurrentWeaponAsync(uint value)
21+
{
22+
return _plugin.Schedule(() => SetCurrentWeapon(value));
23+
}
24+
25+
public uint GetCurrentWeapon()
2426
{
2527
CheckExistence();
2628

27-
return await _plugin
28-
.Schedule(() => Rage.Player.Player_GetCurrentWeapon(NativePointer))
29-
.ConfigureAwait(false);
29+
return Rage.Player.Player_GetCurrentWeapon(NativePointer);
30+
}
31+
32+
public Task<uint> GetCurrentWeaponAsync()
33+
{
34+
return _plugin.Schedule(GetCurrentWeapon);
3035
}
3136

32-
public async Task SetCurrentWeaponAmmoAsync(uint value)
37+
public void SetCurrentWeaponAmmo(uint value)
3338
{
3439
CheckExistence();
3540

36-
await _plugin
37-
.Schedule(() => Rage.Player.Player_SetCurrentWeaponAmmo(NativePointer, value))
38-
.ConfigureAwait(false);
41+
Rage.Player.Player_SetCurrentWeaponAmmo(NativePointer, value);
3942
}
4043

41-
public async Task<uint> GetCurrentWeaponAmmoAsync()
44+
public Task SetCurrentWeaponAmmoAsync(uint value)
45+
{
46+
return _plugin.Schedule(() => SetCurrentWeaponAmmo(value));
47+
}
48+
49+
public uint GetCurrentWeaponAmmo()
4250
{
4351
CheckExistence();
4452

45-
return await _plugin
46-
.Schedule(() => Rage.Player.Player_GetCurrentWeaponAmmo(NativePointer))
47-
.ConfigureAwait(false);
53+
return Rage.Player.Player_GetCurrentWeaponAmmo(NativePointer);
54+
}
55+
56+
public Task<uint> GetCurrentWeaponAmmoAsync()
57+
{
58+
return _plugin.Schedule(GetCurrentWeaponAmmo);
4859
}
4960

50-
public async Task<uint> GetWeaponAmmoAsync(WeaponHash weaponHash)
61+
public uint GetWeaponAmmo(WeaponHash weaponHash)
5162
{
5263
CheckExistence();
5364

54-
return await _plugin
55-
.Schedule(() => Rage.Player.Player_GetWeaponAmmo(NativePointer, (uint) weaponHash))
56-
.ConfigureAwait(false);
65+
return Rage.Player.Player_GetWeaponAmmo(NativePointer, (uint) weaponHash);
66+
}
67+
68+
public Task<uint> GetWeaponAmmoAsync(WeaponHash weaponHash)
69+
{
70+
return _plugin.Schedule(() => GetWeaponAmmo(weaponHash));
71+
}
72+
73+
public uint GetWeaponAmmo(uint weapon)
74+
{
75+
return GetWeaponAmmo((WeaponHash) weapon);
5776
}
5877

5978
public Task<uint> GetWeaponAmmoAsync(uint weapon)
6079
{
6180
return GetWeaponAmmoAsync((WeaponHash) weapon);
6281
}
6382

64-
public async Task<int> GetWeaponAmmoAsync(int weapon)
83+
public int GetWeaponAmmo(int weapon)
6584
{
66-
return (int) await GetWeaponAmmoAsync((WeaponHash) weapon)
67-
.ConfigureAwait(false);
85+
return (int) GetWeaponAmmo((WeaponHash) weapon);
6886
}
6987

70-
public async Task SetWeaponAmmoAsync(WeaponHash weaponHash, uint ammo)
88+
public Task<int> GetWeaponAmmoAsync(int weapon)
89+
{
90+
return _plugin.Schedule(() => GetWeaponAmmo(weapon));
91+
}
92+
93+
public void SetWeaponAmmo(WeaponHash weaponHash, uint ammo)
7194
{
7295
CheckExistence();
7396

74-
await _plugin
75-
.Schedule(() => Rage.Player.Player_SetWeaponAmmo(NativePointer, (uint) weaponHash, ammo))
76-
.ConfigureAwait(false);
97+
Rage.Player.Player_SetWeaponAmmo(NativePointer, (uint) weaponHash, ammo);
98+
}
99+
100+
public Task SetWeaponAmmoAsync(WeaponHash weaponHash, uint ammo)
101+
{
102+
return _plugin.Schedule(() => SetWeaponAmmo(weaponHash, ammo));
103+
}
104+
105+
public void SetWeaponAmmo(WeaponHash weapon, int ammo)
106+
{
107+
SetWeaponAmmo(weapon, (uint) ammo);
77108
}
78109

79110
public Task SetWeaponAmmoAsync(WeaponHash weapon, int ammo)
80111
{
81112
return SetWeaponAmmoAsync(weapon, (uint) ammo);
82113
}
83114

115+
public void SetWeaponAmmo(uint weapon, uint ammo)
116+
{
117+
SetWeaponAmmo((WeaponHash) weapon, ammo);
118+
}
119+
84120
public Task SetWeaponAmmoAsync(uint weapon, uint ammo)
85121
{
86122
return SetWeaponAmmoAsync((WeaponHash) weapon, ammo);
87123
}
88124

125+
public void SetWeaponAmmo(int weapon, int ammo)
126+
{
127+
SetWeaponAmmo((WeaponHash) weapon, (uint) ammo);
128+
}
129+
89130
public Task SetWeaponAmmoAsync(int weapon, int ammo)
90131
{
91132
return SetWeaponAmmoAsync((WeaponHash) weapon, (uint) ammo);
92133
}
93134

94-
public async Task GiveWeaponAsync(WeaponHash weaponHash, uint ammo)
135+
public void GiveWeapon(WeaponHash weaponHash, uint ammo)
95136
{
96137
CheckExistence();
97138

98-
await _plugin
99-
.Schedule(() => Rage.Player.Player_GiveWeapon(NativePointer, (uint) weaponHash, ammo))
100-
.ConfigureAwait(false);
139+
Rage.Player.Player_GiveWeapon(NativePointer, (uint) weaponHash, ammo);
140+
}
141+
142+
public Task GiveWeaponAsync(WeaponHash weaponHash, uint ammo)
143+
{
144+
return _plugin.Schedule(() => GiveWeapon(weaponHash, ammo));
145+
}
146+
147+
public void GiveWeapon(WeaponHash weapon, int ammo)
148+
{
149+
GiveWeapon(weapon, (uint) ammo);
101150
}
102151

103152
public Task GiveWeaponAsync(WeaponHash weapon, int ammo)
104153
{
105154
return GiveWeaponAsync(weapon, (uint) ammo);
106155
}
107156

157+
public void GiveWeapon(uint weapon, uint ammo)
158+
{
159+
GiveWeapon((WeaponHash) weapon, ammo);
160+
}
161+
108162
public Task GiveWeaponAsync(uint weapon, uint ammo)
109163
{
110164
return GiveWeaponAsync((WeaponHash) weapon, ammo);
111165
}
112166

167+
public void GiveWeapon(int weapon, int ammo)
168+
{
169+
GiveWeapon((WeaponHash) weapon, (uint) ammo);
170+
}
171+
113172
public Task GiveWeaponAsync(int weapon, int ammo)
114173
{
115174
return GiveWeaponAsync((WeaponHash) weapon, (uint) ammo);
116175
}
117176

118-
public async Task GiveWeaponsAsync(IDictionary<WeaponHash, uint> weapons)
177+
public void GiveWeapons(IDictionary<WeaponHash, uint> weapons)
119178
{
120179
Contract.NotNull(weapons, nameof(weapons));
121180
CheckExistence();
@@ -125,87 +184,128 @@ public async Task GiveWeaponsAsync(IDictionary<WeaponHash, uint> weapons)
125184
var hashes = weapons.Keys.Select(x => (uint) x).ToArray();
126185
var ammo = weapons.Values.ToArray();
127186

128-
await _plugin
129-
.Schedule(() => Rage.Player.Player_GiveWeapons(NativePointer, hashes, ammo, (ulong) count))
130-
.ConfigureAwait(false);
187+
Rage.Player.Player_GiveWeapons(NativePointer, hashes, ammo, (ulong) count);
188+
}
189+
190+
public Task GiveWeaponsAsync(IDictionary<WeaponHash, uint> weapons)
191+
{
192+
return _plugin.Schedule(() => GiveWeapons(weapons));
193+
}
194+
195+
public void GiveWeapons(IDictionary<WeaponHash, int> weapons)
196+
{
197+
GiveWeapons(weapons.ToDictionary(x => x.Key, x => (uint) x.Value));
131198
}
132199

133200
public Task GiveWeaponsAsync(IDictionary<WeaponHash, int> weapons)
134201
{
135202
return GiveWeaponsAsync(weapons.ToDictionary(x => x.Key, x => (uint) x.Value));
136203
}
137204

205+
public void GiveWeapons(IDictionary<uint, uint> weapons)
206+
{
207+
GiveWeapons(weapons.ToDictionary(x => (WeaponHash) x.Key, x => x.Value));
208+
}
209+
138210
public Task GiveWeaponsAsync(IDictionary<uint, uint> weapons)
139211
{
140212
return GiveWeaponsAsync(weapons.ToDictionary(x => (WeaponHash) x.Key, x => x.Value));
141213
}
142214

215+
public void GiveWeapons(IDictionary<int, int> weapons)
216+
{
217+
GiveWeapons(weapons.ToDictionary(x => (WeaponHash) x.Key, x => (uint) x.Value));
218+
}
219+
143220
public Task GiveWeaponsAsync(IDictionary<int, int> weapons)
144221
{
145222
return GiveWeaponsAsync(weapons.ToDictionary(x => (WeaponHash) x.Key, x => (uint) x.Value));
146223
}
147224

148-
public async Task RemoveWeaponAsync(WeaponHash weaponHash)
225+
public void RemoveWeapon(WeaponHash weaponHash)
149226
{
150227
CheckExistence();
151228

152-
await _plugin
153-
.Schedule(() => Rage.Player.Player_RemoveWeapon(NativePointer, (uint) weaponHash))
154-
.ConfigureAwait(false);
229+
Rage.Player.Player_RemoveWeapon(NativePointer, (uint) weaponHash);
230+
}
231+
232+
public Task RemoveWeaponAsync(WeaponHash weaponHash)
233+
{
234+
return _plugin.Schedule(() => RemoveWeapon(weaponHash));
235+
}
236+
237+
public void RemoveWeapon(uint weapon)
238+
{
239+
RemoveWeapon((WeaponHash) weapon);
155240
}
156241

157242
public Task RemoveWeaponAsync(uint weapon)
158243
{
159244
return RemoveWeaponAsync((WeaponHash) weapon);
160245
}
161246

247+
public void RemoveWeapon(int weapon)
248+
{
249+
RemoveWeapon((WeaponHash) weapon);
250+
}
251+
162252
public Task RemoveWeaponAsync(int weapon)
163253
{
164254
return RemoveWeaponAsync((WeaponHash) weapon);
165255
}
166256

167-
public async Task RemoveWeaponsAsync(IEnumerable<uint> weaponHashes)
257+
public void RemoveWeapons(IEnumerable<uint> weaponHashes)
168258
{
169259
Contract.NotNull(weaponHashes, nameof(weaponHashes));
170260
CheckExistence();
171261

172262
var weapons = weaponHashes.ToArray();
173263

174-
await _plugin
175-
.Schedule(() => Rage.Player.Player_RemoveWeapons(NativePointer, weapons, (ulong) weapons.LongLength))
176-
.ConfigureAwait(false);
264+
Rage.Player.Player_RemoveWeapons(NativePointer, weapons, (ulong) weapons.LongLength);
265+
}
266+
267+
public Task RemoveWeaponsAsync(IEnumerable<uint> weaponHashes)
268+
{
269+
return _plugin.Schedule(() => RemoveWeapons(weaponHashes));
177270
}
178271

272+
public void RemoveWeapons(IEnumerable<WeaponHash> weaponHashes)
273+
{
274+
RemoveWeapons(weaponHashes.Select(x => (uint) x));
275+
}
276+
179277
public Task RemoveWeaponsAsync(IEnumerable<WeaponHash> weaponHashes)
180278
{
181279
return RemoveWeaponsAsync(weaponHashes.Select(x => (uint) x));
182280
}
183281

282+
public void RemoveWeapons(IEnumerable<int> weaponHashes)
283+
{
284+
RemoveWeapons(weaponHashes.Select(x => (uint) x));
285+
}
286+
184287
public Task RemoveWeaponsAsync(IEnumerable<int> weaponHashes)
185288
{
186289
return RemoveWeaponsAsync(weaponHashes.Select(x => (uint) x));
187290
}
188291

189-
public async Task RemoveAllWeaponsAsync()
292+
public void RemoveAllWeapons()
190293
{
191294
CheckExistence();
192295

193-
await _plugin
194-
.Schedule(() => Rage.Player.Player_RemoveAllWeapons(NativePointer))
195-
.ConfigureAwait(false);
296+
Rage.Player.Player_RemoveAllWeapons(NativePointer);
297+
}
298+
299+
public Task RemoveAllWeaponsAsync()
300+
{
301+
return _plugin.Schedule(RemoveAllWeapons);
196302
}
197303

198-
public async Task<IReadOnlyDictionary<WeaponHash, uint>> GetWeaponsAsync()
304+
public IReadOnlyDictionary<WeaponHash, uint> GetWeapons()
199305
{
200306
CheckExistence();
201307

202-
IntPtr weapons = IntPtr.Zero;
203-
IntPtr ammo = IntPtr.Zero;
204-
ulong count = 0;
205-
206-
await _plugin
207-
.Schedule(() => Rage.Player.Player_GetWeapons(NativePointer, out weapons, out ammo, out count))
208-
.ConfigureAwait(false);
308+
Rage.Player.Player_GetWeapons(NativePointer, out var weapons, out var ammo, out var count);
209309

210310
var allWeapons = new Dictionary<WeaponHash, uint>();
211311

@@ -219,5 +319,10 @@ await _plugin
219319

220320
return allWeapons;
221321
}
322+
323+
public Task<IReadOnlyDictionary<WeaponHash, uint>> GetWeaponsAsync()
324+
{
325+
return _plugin.Schedule(GetWeapons);
326+
}
222327
}
223328
}

src/AlternateLife.RageMP.Net/Interfaces/IPlayer.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1622,7 +1622,7 @@ Task SetCustomizationAsync(bool isMale, HeadBlendData headBlend, int eyeColor, i
16221622
/// </summary>
16231623
/// <param name="weapon">Weapon to remove</param>
16241624
/// <exception cref="EntityDeletedException">This entity was deleted before</exception>
1625-
Task RemoveWeapon(WeaponHash weapon);
1625+
void RemoveWeapon(WeaponHash weapon);
16261626

16271627
/// <summary>
16281628
/// Remove a weapon from the player.

0 commit comments

Comments
 (0)