Skip to content

Commit 31c0ff8

Browse files
RZSenfodedmen
RZSenfo
authored andcommitted
Fix unitloadout crash on null objects (intercept#162)
* getUnitLoadout returns empty array for objnull -> std constructurs needed * static cast * various data structure fixes * suggested changes * fix server_command sqf-command * Fixes/improvements - style changes (dedmen)
1 parent 1e643f6 commit 31c0ff8

File tree

8 files changed

+145
-101
lines changed

8 files changed

+145
-101
lines changed

.clang-format

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ PenaltyBreakFirstLessLess: 120
7171
PenaltyBreakString: 1000
7272
PenaltyExcessCharacter: 1000000
7373
PenaltyReturnTypeOnItsOwnLine: 200
74-
PointerAlignment: Left
74+
PointerAlignment: Right
7575
ReflowComments: false
7676
SortIncludes: false
7777
SpaceAfterCStyleCast: false

src/client/headers/client/sqf/inventory.hpp

+71-40
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,29 @@ namespace intercept {
2424
struct rv_magazine_ammo {
2525
std::string name;
2626
int count;
27+
28+
rv_magazine_ammo(const game_value &from_gv_) : name(from_gv_[0]),
29+
count(from_gv_[1]) {}
30+
31+
operator game_value() const {
32+
return game_value({name, static_cast<float>(count)});
33+
}
34+
};
35+
36+
struct rv_magazine_ammo_full : rv_magazine_ammo {
2737
bool loaded;
2838
int type;
2939
std::string location;
3040

41+
rv_magazine_ammo_full(const game_value &from_gv_) : rv_magazine_ammo(from_gv_),
42+
loaded(from_gv_[2]),
43+
type(from_gv_[3]),
44+
location(from_gv_[4]) {}
45+
46+
rv_magazine_ammo_full(const rv_magazine_ammo &from_mag_) : rv_magazine_ammo(from_mag_),
47+
loaded(false),
48+
type(-1) {}
49+
3150
operator game_value() const {
3251
return game_value({name,
3352
static_cast<float>(count),
@@ -47,6 +66,12 @@ namespace intercept {
4766
struct rv_container {
4867
std::string type;
4968
object container;
69+
70+
rv_container(const game_value &from_gv_) : type(from_gv_[0]),
71+
container(from_gv_[1]) {}
72+
operator game_value() const {
73+
return game_value({type, container});
74+
}
5075
};
5176
struct rv_weapon_accessories {
5277
std::string silencer;
@@ -62,11 +87,11 @@ namespace intercept {
6287
std::string magazine;
6388
float ammo_count;
6489

65-
rv_weapon_state(game_value ret_game_value_) : weapon(ret_game_value_[0]),
66-
muzzle(ret_game_value_[1]),
67-
mode(ret_game_value_[2]),
68-
magazine(ret_game_value_[3]),
69-
ammo_count(ret_game_value_[4]) {}
90+
rv_weapon_state(const game_value &ret_game_value_) : weapon(ret_game_value_[0]),
91+
muzzle(ret_game_value_[1]),
92+
mode(ret_game_value_[2]),
93+
magazine(ret_game_value_[3]),
94+
ammo_count(ret_game_value_[4]) {}
7095
};
7196

7297
/* potential namespace: items, inventory, campaign */
@@ -93,7 +118,7 @@ namespace intercept {
93118
std::vector<rv_turret_magazine> magazines_all_turrets(const object &obj_);
94119
std::vector<rv_magazine_ammo> magazines_ammo(const object &obj_);
95120
std::vector<rv_magazine_ammo> magazines_ammo_cargo(const object &obj_);
96-
std::vector<rv_magazine_ammo> magazines_ammo_full(const object &obj_);
121+
std::vector<rv_magazine_ammo_full> magazines_ammo_full(const object &obj_);
97122
sqf_return_string_list magazines_detail(const object &obj_);
98123
sqf_return_string_list magazines_detail_backpack(const object &obj_);
99124
sqf_return_string_list magazines_detail_uniform(const object &obj_);
@@ -206,14 +231,14 @@ namespace intercept {
206231
std::vector<float> amounts;
207232

208233
explicit operator game_value() const {
209-
return game_value({ types, amounts });
234+
return game_value({types, amounts});
210235
}
211236
};
212237

213-
std::vector<rv_cargo> get_backpack_cargo(const object &container_);
214-
std::vector<rv_cargo> get_item_cargo(const object &container_);
215-
std::vector<rv_cargo> get_magazine_cargo(const object &container_);
216-
std::vector<rv_cargo> get_weapon_cargo(const object &container_);
238+
rv_cargo get_backpack_cargo(const object &container_);
239+
rv_cargo get_item_cargo(const object &container_);
240+
rv_cargo get_magazine_cargo(const object &container_);
241+
rv_cargo get_weapon_cargo(const object &container_);
217242
sqf_return_string_list item_cargo(const object &container_);
218243
sqf_return_string_list weapon_cargo(const object &container_);
219244
sqf_return_string_list weapons(const object &unit_);
@@ -231,7 +256,7 @@ namespace intercept {
231256
ammo(ret_game_value_[1]) {}
232257

233258
explicit operator game_value() const {
234-
return game_value({ name, ammo });
259+
return game_value({name, ammo});
235260
}
236261
};
237262

@@ -253,7 +278,7 @@ namespace intercept {
253278
bipod(ret_game_value_.size() > 6 ? ret_game_value_[6] : ret_game_value_[5]) {}
254279

255280
explicit operator game_value() const {
256-
return game_value({ weapon, muzzle, laser, optics, game_value(magazine), grenade_launcher_magazine ? game_value(*grenade_launcher_magazine) : game_value({}), bipod });
281+
return game_value({weapon, muzzle, laser, optics, game_value(magazine), grenade_launcher_magazine ? game_value(*grenade_launcher_magazine) : game_value({}), bipod});
257282
}
258283
};
259284

@@ -343,28 +368,30 @@ namespace intercept {
343368

344369
operator game_value() const {
345370
if (ammo != -1) {
346-
return game_value({ magazine,
371+
return game_value({magazine,
347372
static_cast<float>(ammo),
348-
static_cast<float>(count) });
373+
static_cast<float>(count)});
349374
} else if (count != -1) {
350-
return game_value({ magazine,
351-
static_cast<float>(count) });
375+
return game_value({magazine,
376+
static_cast<float>(count)});
352377
} else {
353378
return game_value({});
354379
}
355380
}
356381
};
357382

358-
struct rv_weapon_info { //#TODO It would be better to store these as r_strings
383+
struct rv_weapon_info { //#TODO It would be better to store these as r_strings
359384
std::string weapon;
360-
std::string silencer = "";
361-
std::string laser;
385+
std::string silencer;
386+
std::string laser;
362387
std::string optics;
363388
rv_magazine_info primary_muzzle_magazine;
364389
rv_magazine_info secondary_muzzle_magazine;
365390
std::string bipod;
366391

367-
rv_weapon_info(const game_value &ret_game_value_) {
392+
rv_weapon_info() {}
393+
394+
rv_weapon_info(const game_value &ret_game_value_) {
368395
if (ret_game_value_.size() > 0) {
369396
weapon = static_cast<std::string>(ret_game_value_[0]);
370397
silencer = static_cast<std::string>(ret_game_value_[1]);
@@ -380,13 +407,13 @@ namespace intercept {
380407

381408
explicit operator game_value() const {
382409
if (weapon != "") {
383-
return game_value({ weapon,
384-
silencer,
385-
laser,
386-
optics,
387-
primary_muzzle_magazine,
388-
secondary_muzzle_magazine,
389-
bipod });
410+
return game_value({weapon,
411+
silencer,
412+
laser,
413+
optics,
414+
primary_muzzle_magazine,
415+
secondary_muzzle_magazine,
416+
bipod});
390417
} else {
391418
return game_value({});
392419
}
@@ -397,6 +424,8 @@ namespace intercept {
397424
std::string container;
398425
std::vector<rv_magazine_info> items;
399426

427+
rv_container_info() {}
428+
400429
rv_container_info(const game_value &ret_game_value_) {
401430
if (ret_game_value_.size() > 0) {
402431
container = static_cast<std::string>(ret_game_value_[0]);
@@ -411,8 +440,8 @@ namespace intercept {
411440

412441
explicit operator game_value() const {
413442
if (container != "") {
414-
return game_value({ container,
415-
auto_array<game_value>(items.begin(), items.end()) });
443+
return game_value({container,
444+
auto_array<game_value>(items.begin(), items.end())});
416445
} else {
417446
return game_value({});
418447
}
@@ -431,16 +460,18 @@ namespace intercept {
431460
rv_weapon_info binocular;
432461
std::vector<std::string> assigned_items;
433462

434-
rv_unit_loadout(const game_value &ret_game_value_) : primary(ret_game_value_[0]),
435-
secondary(ret_game_value_[1]),
436-
handgun(ret_game_value_[2]),
437-
uniform(ret_game_value_[3]),
438-
vest(ret_game_value_[4]),
439-
backpack(ret_game_value_[5]),
440-
headgear(ret_game_value_[6]),
441-
facewear(ret_game_value_[7]),
442-
binocular(ret_game_value_[8]) {
443-
auto_array<game_value> _tmp = ret_game_value_[9].to_array();
463+
rv_unit_loadout(const game_value &ret_game_value_) {
464+
if (ret_game_value_.size() == 0) return;
465+
primary = ret_game_value_[0];
466+
secondary = ret_game_value_[1];
467+
handgun = ret_game_value_[2];
468+
uniform = ret_game_value_[3];
469+
vest = ret_game_value_[4];
470+
backpack = ret_game_value_[5];
471+
headgear = static_cast<std::string>(ret_game_value_[6]);
472+
facewear = static_cast<std::string>(ret_game_value_[7]);
473+
binocular = ret_game_value_[8];
474+
auto &_tmp = ret_game_value_[9].to_array();
444475
assigned_items = std::vector<std::string>(_tmp.begin(), _tmp.end());
445476
}
446477

src/client/headers/client/sqf/multiplayer.hpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ namespace intercept {
5757
void public_variable_client(float value0_, sqf_string_const_ref value1_);
5858

5959
bool server_command(sqf_string_const_ref value_);
60+
bool server_command(sqf_string_const_ref command_, sqf_string_const_ref password_);
61+
6062
bool server_command_available(sqf_string_const_ref value_);
6163
bool server_command_executable(sqf_string_const_ref value_);
6264

@@ -70,7 +72,6 @@ namespace intercept {
7072
game_value remote_exec(const game_value &params_, sqf_string_const_ref function_, std::variant<int, object, sqf_string_const_ref_wrapper, side, group, std::reference_wrapper<const std::vector<game_value>>> targets_, std::optional<std::variant<sqf_string_const_ref_wrapper, bool, object, group>> jip_);
7173
game_value remote_exec_call(const game_value &params_, sqf_string_const_ref function_, std::variant<int, object, sqf_string_const_ref_wrapper, side, group, std::reference_wrapper<const std::vector<game_value>>> targets_, std::optional<std::variant<sqf_string_const_ref_wrapper, bool, object, group>> jip_);
7274

73-
void serverCommand(sqf_string_const_ref command_, sqf_string_const_ref password_);
7475
bool turret_local(const object &vehicle_, const std::vector<int> &turret_path_);
7576
int turret_owner(const object &vehicle_, const std::vector<int> &turret_path_);
7677
//mp

src/client/headers/shared/client_types.hpp

+11
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,17 @@ namespace intercept {
334334
struct rv_best_place {
335335
vector2 pos;
336336
float result;
337+
338+
rv_best_place(const game_value& gv) {
339+
if (gv.size() == 2) {
340+
pos = gv[0];
341+
result = gv[1];
342+
}
343+
}
344+
345+
operator game_value() const {
346+
return game_value({ pos, result });
347+
}
337348
};
338349
struct rv_uav_control {
339350
object unit;

0 commit comments

Comments
 (0)