-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathnetwork.cpp
More file actions
364 lines (329 loc) · 12.5 KB
/
Copy pathnetwork.cpp
File metadata and controls
364 lines (329 loc) · 12.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
#include "network.hpp"
#include "../../script.hpp"
#include "core/data/language_codes.hpp"
#include "core/data/infractions.hpp"
#include "core/scr_globals.hpp"
#include "pointers.hpp"
#include "util/scripts.hpp"
#include "util/teleport.hpp"
#include <script/globals/GPBD_FM.hpp>
#include <script/globals/GPBD_FM_3.hpp>
namespace lua::network
{
// Lua API: Table
// Name: network
// Table containing helper functions for network related features.
// Lua API: Function
// Table: network
// Name: trigger_script_event
// Param: bitset: integer
// Param: _args: table
// Call trigger_script_event (TSE)
static void trigger_script_event(int bitset, sol::table _args)
{
auto args = convert_sequence<int32_t>(_args);
if (args.size() >= 1)
args[1] = self::id;
std::vector<std::int64_t> actual_args;
for (auto arg : args)
actual_args.push_back((uint32_t)arg);
SCRIPT::_SEND_TU_SCRIPT_EVENT_NEW(1, (Any*)actual_args.data(), actual_args.size(), bitset, args[0]);
}
// Lua API: Function
// Table: network
// Name: is_session_started
// Returns true if the local player is in a multiplayer session.
static bool is_session_started()
{
return *big::g_pointers->m_is_session_started;
}
// Lua API: Function
// Table: network
// Name: give_pickup_rewards
// Param: player: integer: Index of the player.
// Param: reward: integer: Index of the reward pickup.
// Give the given pickup reward to the given player.
static void give_pickup_rewards(int player, int reward)
{
big::g_pointers->m_give_pickup_rewards(1 << player, reward);
}
// Lua API: Function
// Table: network
// Name: set_player_coords
// Param: player_idx: integer: Index of the player.
// Param: x: float: New x position.
// Param: y: float: New y position.
// Param: z: float: New z position.
// Teleport the given player to the given position.
static void set_player_coords(int player_idx, float x, float y, float z)
{
if (auto player = big::g_player_service->get_by_id(player_idx))
big::teleport::teleport_player_to_coords(player, {x, y, z});
}
// Lua API: Function
// Table: network
// Name: set_all_player_coords
// Param: x: float: New x position.
// Param: y: float: New y position.
// Param: z: float: New z position.
// Teleport all players to the given position.
static void set_all_player_coords(float x, float y, float z)
{
for (auto& player : big::g_player_service->players())
big::g_fiber_pool->queue_job([player, x, y, z]() {
big::teleport::teleport_player_to_coords(player.second, {x, y, z});
});
}
// Lua API: Function
// Table: network
// Name: get_selected_player
// Returns: integer: Returns the index of the currently selected player in the GUI.
static int get_selected_player()
{
if (big::g_player_service->get_selected()->is_valid())
return big::g_player_service->get_selected()->id();
return -1;
}
// Lua API: Function
// Table: network
// Name: get_selected_database_player_rockstar_id
// Returns: integer: Returns the rockstar id of the currently selected player in the GUI.
static int get_selected_database_player_rockstar_id()
{
return -1;
}
static void flag_player_as_modder(int player_idx, big::Infraction reason)
{
}
// Lua API: Function
// Table: network
// Name: flag_player_as_modder
// Param: player_idx: integer: Index of the player.
// Param: reason: Infraction: Reason why the player is flagged as a modder, if the infraction is CUSTOM_REASON, then the custom_reason string is added in the local database. For a full list of the possible infraction reasons to use, please check the infraction page.
// Param: custom_reason: string: Optional, required only when the infraction is CUSTOM_REASON. The custom reason why the player is flagged as a modder.
// Flags the given player as a modder in our local database.
static void flag_player_as_modder_custom_reason(int player_idx, big::Infraction reason, const std::string& custom_reason)
{
}
// Lua API: Function
// Table: network
// Name: is_player_flagged_as_modder
// Param: player_idx: integer: Index of the player.
// Returns: boolean: Returns true if the given player is flagged as a modder.
static bool is_player_flagged_as_modder(int player_idx)
{
return false;
}
// Lua API: Function
// Table: network
// Name: is_player_friend
// Param: player_idx: integer: Index of the player.
// Returns: boolean: Returns true if the given player is a friend.
static bool is_player_friend(int player_idx)
{
if (auto player = big::g_player_service->get_by_id(player_idx))
return player->is_friend();
return false;
}
// Lua API: Function
// Table: network
// Name: get_flagged_modder_reason
// Param: player_idx: integer: Index of the player.
// Returns: string: Returns a string which contains the reason(s) why the player is flagged as a modder.
static std::string get_flagged_modder_reason(int player_idx)
{
return "";
}
// Lua API: Function
// Table: network
// Name: force_script_host
// Param: script_name: string: Name of the script.
// Try to force ourself to be host for the given GTA Script. Needs to be called in the fiber pool or a loop.
static void force_script_host(const std::string& script_name)
{
big::scripts::force_host(rage::joaat(script_name));
}
// Lua API: function
// Table: network
// Name: force_script_on_player
// Param: player_idx: integer: Index of the player.
// Param: script_name: string: Name of the script.
// Param: instance_id: integer: Instance ID of the script.
// Forces the given GTA script to be started on a player. Needs to be called in the fiber pool or a loop.
static void force_script_on_player(int player_idx, const std::string& script_name, int instance_id)
{
LOG(WARNING) << "force_script_on_player is not implemented";
}
// Lua API: Function
// Table: network
// Name: send_chat_message
// Param: msg: string: Message to be sent.
// Param: team_only: boolean: Should be true if the msg should only be sent to our team.
// Sends a message to the in game chat.
static void send_chat_message(const std::string& msg, bool team_only)
{
LOG(WARNING) << "Sending chat messages is not implemented";
}
// Lua API: Function
// Table: network
// Name: send_chat_message_to_player
// Param: player_idx: integer: Index of the player.
// Param: msg: string: Message to be sent.
// Sends a chat message to the specified player. Other players would not be able to see the message
static void send_chat_message_to_player(int player_idx, const std::string& msg)
{
LOG(WARNING) << "Sending chat messages to players is not implemented";
}
// Lua API: Function
// Table: network
// Name: get_player_rank
// Param: pid: integer: Index of the player.
// Returns: integer: An integer which contains the players rank.
// Call get_player_rank(playerID)
static int get_player_rank(int pid)
{
if (big::g_player_service->get_by_id(pid))
{
auto& stats = big::scr_globals::gpbd_fm_1.as<GPBD_FM*>()->Entries[pid].PlayerStats;
return stats.Rank;
}
return -1;
}
// Lua API: Function
// Table: network
// Name: get_player_rp
// Param: pid: integer: Index of the player.
// Returns: integer: An integer which contains the players rp.
// Call get_player_rp(playerID)
static int get_player_rp(int pid)
{
if (big::g_player_service->get_by_id(pid))
{
auto& stats = big::scr_globals::gpbd_fm_1.as<GPBD_FM*>()->Entries[pid].PlayerStats;
return stats.RP;
}
return -1;
}
// Lua API: Function
// Table: network
// Name: get_player_money
// Param: pid: integer: Index of the player.
// Returns: integer: An integer which contains the players money.
// Call get_player_money(playerID)
static int get_player_money(int pid)
{
if (big::g_player_service->get_by_id(pid))
{
auto& stats = big::scr_globals::gpbd_fm_1.as<GPBD_FM*>()->Entries[pid].PlayerStats;
return stats.Money;
}
return -1;
}
// Lua API: Function
// Table: network
// Name: get_player_wallet
// Param: pid: integer: Index of the player.
// Returns: integer: An integer which contains the players wallet.
// Call get_player_wallet(playerID)
static int get_player_wallet(int pid)
{
if (big::g_player_service->get_by_id(pid))
{
auto& stats = big::scr_globals::gpbd_fm_1.as<GPBD_FM*>()->Entries[pid].PlayerStats;
return stats.WalletBalance;
}
return -1;
}
// Lua API: Function
// Table: network
// Name: get_player_bank
// Param: pid: integer: Index of the player.
// Returns: integer: An integer which contains the players bank.
// Call get_player_bank(playerID)
static int get_player_bank(int pid)
{
if (big::g_player_service->get_by_id(pid))
{
auto& stats = big::scr_globals::gpbd_fm_1.as<GPBD_FM*>()->Entries[pid].PlayerStats;
return stats.Money - stats.WalletBalance;
}
return -1;
}
// Lua API: Function
// Table: network
// Name: get_player_language_id
// Param: pid: integer: Index of the player.
// Returns: integer: An integer which contains the players language id.
// Call get_player_language_id(playerID)
static int get_player_language_id(int pid)
{
if (big::g_player_service->get_by_id(pid))
{
auto& boss_goon = big::scr_globals::gpbd_fm_3.as<GPBD_FM_3*>()->Entries[pid].BossGoon;
return boss_goon.Language;
}
return -1;
}
// Lua API: Function
// Table: network
// Name: get_player_language_name
// Param: pid: integer: Index of the player.
// Returns: string: A string which contains the players language name.
// Call get_player_language_name(playerID)
static std::string get_player_language_name(int pid)
{
if (big::g_player_service->get_by_id(pid))
{
auto& boss_goon = big::scr_globals::gpbd_fm_3.as<GPBD_FM_3*>()->Entries[pid].BossGoon;
return big::languages.at((eGameLanguage)boss_goon.Language).data();
}
return "Unknown";
}
void bind(sol::state& state)
{
state.new_enum<big::Infraction>("infraction",
{
{"ATTACKING_WHEN_HIDDEN_FROM_PLAYER_LIST", big::Infraction::ATTACKING_WHEN_HIDDEN_FROM_PLAYER_LIST},
{"ATTACKING_WITH_GODMODE", big::Infraction::ATTACKING_WITH_GODMODE},
{"ATTACKING_WITH_INVISIBILITY", big::Infraction::ATTACKING_WITH_INVISIBILITY},
{"BLAME_EXPLOSION_DETECTED", big::Infraction::BLAME_EXPLOSION_DETECTED},
{"BREAKUP_KICK_DETECTED", big::Infraction::BREAKUP_KICK_DETECTED},
{"CUSTOM_REASON", big::Infraction::CUSTOM_REASON},
{"DESYNC_PROTECTION", big::Infraction::DESYNC_PROTECTION},
{"INVALID_PLAYER_MODEL", big::Infraction::INVALID_PLAYER_MODEL},
{"LOST_CONNECTION_KICK_DETECTED", big::Infraction::LOST_CONNECTION_KICK_DETECTED},
{"SPOOFED_DATA", big::Infraction::SPOOFED_DATA},
{"SPOOFED_HOST_TOKEN", big::Infraction::SPOOFED_HOST_TOKEN},
{"SPOOFED_ROCKSTAR_ID", big::Infraction::SPOOFED_ROCKSTAR_ID},
{"SUPER_JUMP", big::Infraction::SUPER_JUMP},
{"TRIED_CRASH_PLAYER", big::Infraction::TRIED_CRASH_PLAYER},
{"TRIED_KICK_PLAYER", big::Infraction::TRIED_KICK_PLAYER},
{"TRIGGERED_ANTICHEAT", big::Infraction::TRIGGERED_ANTICHEAT},
{"UNDEAD_OTR", big::Infraction::UNDEAD_OTR},
{"CHAT_SPAM", big::Infraction::CHAT_SPAM},
});
auto ns = state["network"].get_or_create<sol::table>();
ns["trigger_script_event"] = trigger_script_event;
ns["is_session_started"] = is_session_started;
ns["give_pickup_rewards"] = give_pickup_rewards;
ns["set_player_coords"] = set_player_coords;
ns["set_all_player_coords"] = set_all_player_coords;
ns["get_selected_player"] = get_selected_player;
ns["get_selected_database_player_rockstar_id"] = get_selected_database_player_rockstar_id;
ns["flag_player_as_modder"] = sol::overload(flag_player_as_modder, flag_player_as_modder_custom_reason);
ns["is_player_flagged_as_modder"] = is_player_flagged_as_modder;
ns["is_player_friend"] = is_player_friend;
ns["get_flagged_modder_reason"] = get_flagged_modder_reason;
ns["force_script_host"] = force_script_host;
ns["force_script_on_player"] = force_script_on_player;
ns["send_chat_message"] = send_chat_message;
ns["send_chat_message_to_player"] = send_chat_message_to_player;
ns["get_player_rank"] = get_player_rank;
ns["get_player_rp"] = get_player_rp;
ns["get_player_money"] = get_player_money;
ns["get_player_wallet"] = get_player_wallet;
ns["get_player_bank"] = get_player_bank;
ns["get_player_language_id"] = get_player_language_id;
ns["get_player_language_name"] = get_player_language_name;
}
}