remove some memcpy/memset calls in favor of default constructors
This commit is contained in:
+1
-2
@@ -165,7 +165,7 @@ static void command_cheat(shared_ptr<ServerState>, shared_ptr<Lobby> l,
|
|||||||
c->infinite_tp = false;
|
c->infinite_tp = false;
|
||||||
c->switch_assist = false;
|
c->switch_assist = false;
|
||||||
}
|
}
|
||||||
memset(&l->next_drop_item, 0, sizeof(l->next_drop_item));
|
l->next_drop_item = PlayerInventoryItem();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -661,7 +661,6 @@ static void command_item(shared_ptr<ServerState>, shared_ptr<Lobby> l,
|
|||||||
}
|
}
|
||||||
|
|
||||||
ItemData item_data;
|
ItemData item_data;
|
||||||
memset(&item_data, 0, sizeof(item_data));
|
|
||||||
if (data.size() <= 12) {
|
if (data.size() <= 12) {
|
||||||
memcpy(&l->next_drop_item.data.data1, data.data(), data.size());
|
memcpy(&l->next_drop_item.data.data1, data.data(), data.size());
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -316,7 +316,6 @@ ItemData CommonItemCreator::create_drop_item(bool is_box, uint8_t episode,
|
|||||||
}
|
}
|
||||||
|
|
||||||
ItemData item;
|
ItemData item;
|
||||||
memset(&item, 0, sizeof(item));
|
|
||||||
|
|
||||||
// picks a random non-rare item type, then gives it appropriate random stats
|
// picks a random non-rare item type, then gives it appropriate random stats
|
||||||
// modify some of the constants in this section to change the system's
|
// modify some of the constants in this section to change the system's
|
||||||
@@ -476,7 +475,6 @@ ItemData CommonItemCreator::create_shop_item(uint8_t difficulty,
|
|||||||
static const uint8_t max_anti_level[4] = { 2, 4, 6, 7};
|
static const uint8_t max_anti_level[4] = { 2, 4, 6, 7};
|
||||||
|
|
||||||
ItemData item;
|
ItemData item;
|
||||||
memset(&item, 0, sizeof(item));
|
|
||||||
|
|
||||||
item.data1[0] = item_type;
|
item.data1[0] = item_type;
|
||||||
while (item.data1[0] == 2) {
|
while (item.data1[0] == 2) {
|
||||||
|
|||||||
+1
-1
@@ -20,7 +20,7 @@ Lobby::Lobby() : lobby_id(0), min_level(0), max_level(0xFFFFFFFF),
|
|||||||
for (size_t x = 0; x < 12; x++) {
|
for (size_t x = 0; x < 12; x++) {
|
||||||
this->next_item_id[x] = 0;
|
this->next_item_id[x] = 0;
|
||||||
}
|
}
|
||||||
memset(&this->next_drop_item, 0, sizeof(this->next_drop_item));
|
this->next_drop_item = PlayerInventoryItem();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Lobby::reassign_leader_on_client_departure(size_t leaving_client_index) {
|
void Lobby::reassign_leader_on_client_departure(size_t leaving_client_index) {
|
||||||
|
|||||||
+18
-7
@@ -541,6 +541,16 @@ PlayerBankItem::PlayerBankItem(const PlayerInventoryItem& src)
|
|||||||
amount(combine_item_to_max.count(this->data.primary_identifier()) ? this->data.data1[5] : 1),
|
amount(combine_item_to_max.count(this->data.primary_identifier()) ? this->data.data1[5] : 1),
|
||||||
show_flags(1) { }
|
show_flags(1) { }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
PlayerInventory::PlayerInventory()
|
||||||
|
: num_items(0),
|
||||||
|
hp_materials_used(0),
|
||||||
|
tp_materials_used(0),
|
||||||
|
language(0) { }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// TODO: Eliminate duplication between this function and the parallel function
|
// TODO: Eliminate duplication between this function and the parallel function
|
||||||
// in PlayerBank
|
// in PlayerBank
|
||||||
void SavedPlayerDataBB::add_item(const PlayerInventoryItem& item) {
|
void SavedPlayerDataBB::add_item(const PlayerInventoryItem& item) {
|
||||||
@@ -638,8 +648,6 @@ PlayerInventoryItem SavedPlayerDataBB::remove_item(
|
|||||||
if (amount > this->disp.meseta) {
|
if (amount > this->disp.meseta) {
|
||||||
throw out_of_range("player does not have enough meseta");
|
throw out_of_range("player does not have enough meseta");
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(&ret, 0, sizeof(ret));
|
|
||||||
ret.data.data1[0] = 0x04;
|
ret.data.data1[0] = 0x04;
|
||||||
ret.data.data2d = amount;
|
ret.data.data2d = amount;
|
||||||
this->disp.meseta -= amount;
|
this->disp.meseta -= amount;
|
||||||
@@ -667,8 +675,10 @@ PlayerInventoryItem SavedPlayerDataBB::remove_item(
|
|||||||
// and return the deleted item.
|
// and return the deleted item.
|
||||||
ret = inventory_item;
|
ret = inventory_item;
|
||||||
this->inventory.num_items--;
|
this->inventory.num_items--;
|
||||||
memcpy(&this->inventory.items[index], &this->inventory.items[index + 1],
|
for (size_t x = index; x < this->inventory.num_items - 1; x++) {
|
||||||
sizeof(PlayerInventoryItem) * (this->inventory.num_items - index));
|
this->inventory.items[x] = this->inventory.items[x + 1];
|
||||||
|
}
|
||||||
|
this->inventory.items[this->inventory.num_items - 1] = PlayerInventoryItem();
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -679,7 +689,6 @@ PlayerBankItem PlayerBank::remove_item(uint32_t item_id, uint32_t amount) {
|
|||||||
if (amount > this->meseta) {
|
if (amount > this->meseta) {
|
||||||
throw out_of_range("player does not have enough meseta");
|
throw out_of_range("player does not have enough meseta");
|
||||||
}
|
}
|
||||||
memset(&ret, 0, sizeof(ret));
|
|
||||||
ret.data.data1[0] = 0x04;
|
ret.data.data1[0] = 0x04;
|
||||||
ret.data.data2d = amount;
|
ret.data.data2d = amount;
|
||||||
this->meseta -= amount;
|
this->meseta -= amount;
|
||||||
@@ -701,8 +710,10 @@ PlayerBankItem PlayerBank::remove_item(uint32_t item_id, uint32_t amount) {
|
|||||||
|
|
||||||
ret = bank_item;
|
ret = bank_item;
|
||||||
this->num_items--;
|
this->num_items--;
|
||||||
memcpy(&this->items[index], &this->items[index + 1],
|
for (size_t x = index; x < this->num_items - 1; x++) {
|
||||||
sizeof(PlayerBankItem) * (this->num_items - index));
|
this->items[x] = this->items[x + 1];
|
||||||
|
}
|
||||||
|
this->items[this->num_items - 1] = PlayerBankItem();
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -59,6 +59,8 @@ struct PlayerInventory {
|
|||||||
uint8_t language;
|
uint8_t language;
|
||||||
PlayerInventoryItem items[30];
|
PlayerInventoryItem items[30];
|
||||||
|
|
||||||
|
PlayerInventory();
|
||||||
|
|
||||||
size_t find_item(uint32_t item_id);
|
size_t find_item(uint32_t item_id);
|
||||||
} __attribute__((packed));
|
} __attribute__((packed));
|
||||||
|
|
||||||
|
|||||||
@@ -586,7 +586,6 @@ static void process_subcommand_sort_inventory_bb(shared_ptr<ServerState>,
|
|||||||
const auto* cmd = check_size_sc<G_SortInventory_6xC4>(data);
|
const auto* cmd = check_size_sc<G_SortInventory_6xC4>(data);
|
||||||
|
|
||||||
PlayerInventory sorted;
|
PlayerInventory sorted;
|
||||||
memset(&sorted, 0, sizeof(PlayerInventory));
|
|
||||||
|
|
||||||
for (size_t x = 0; x < 30; x++) {
|
for (size_t x = 0; x < 30; x++) {
|
||||||
if (cmd->item_ids[x] == 0xFFFFFFFF) {
|
if (cmd->item_ids[x] == 0xFFFFFFFF) {
|
||||||
@@ -619,7 +618,6 @@ static void process_subcommand_enemy_drop_item_request(shared_ptr<ServerState> s
|
|||||||
}
|
}
|
||||||
|
|
||||||
PlayerInventoryItem item;
|
PlayerInventoryItem item;
|
||||||
memset(&item, 0, sizeof(PlayerInventoryItem));
|
|
||||||
|
|
||||||
// TODO: Deduplicate this code with the box drop item request handler
|
// TODO: Deduplicate this code with the box drop item request handler
|
||||||
bool is_rare = false;
|
bool is_rare = false;
|
||||||
@@ -634,7 +632,10 @@ static void process_subcommand_enemy_drop_item_request(shared_ptr<ServerState> s
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (is_rare) {
|
if (is_rare) {
|
||||||
memcpy(&item.data.data1d, l->rare_item_set->rares[cmd->enemy_id].item_code, 3);
|
const auto& code = l->rare_item_set->rares[cmd->enemy_id].item_code;
|
||||||
|
item.data.data1[0] = code[0];
|
||||||
|
item.data.data1[1] = code[1];
|
||||||
|
item.data.data1[2] = code[2];
|
||||||
//RandPercentages();
|
//RandPercentages();
|
||||||
if (item.data.data1d[0] == 0) {
|
if (item.data.data1d[0] == 0) {
|
||||||
item.data.data1[4] |= 0x80; // make it unidentified if it's a weapon
|
item.data.data1[4] |= 0x80; // make it unidentified if it's a weapon
|
||||||
@@ -671,7 +672,6 @@ static void process_subcommand_box_drop_item_request(shared_ptr<ServerState> s,
|
|||||||
}
|
}
|
||||||
|
|
||||||
PlayerInventoryItem item;
|
PlayerInventoryItem item;
|
||||||
memset(&item, 0, sizeof(PlayerInventoryItem));
|
|
||||||
|
|
||||||
bool is_rare = false;
|
bool is_rare = false;
|
||||||
if (l->next_drop_item.data.data1d[0]) {
|
if (l->next_drop_item.data.data1d[0]) {
|
||||||
@@ -692,7 +692,10 @@ static void process_subcommand_box_drop_item_request(shared_ptr<ServerState> s,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (is_rare) {
|
if (is_rare) {
|
||||||
memcpy(item.data.data1, l->rare_item_set->box_rares[index].item_code, 3);
|
const auto& code = l->rare_item_set->box_rares[index].item_code;
|
||||||
|
item.data.data1[0] = code[0];
|
||||||
|
item.data.data1[1] = code[1];
|
||||||
|
item.data.data1[2] = code[2];
|
||||||
//RandPercentages();
|
//RandPercentages();
|
||||||
if (item.data.data1d[0] == 0) {
|
if (item.data.data1d[0] == 0) {
|
||||||
item.data.data1[4] |= 0x80; // make it unidentified if it's a weapon
|
item.data.data1[4] |= 0x80; // make it unidentified if it's a weapon
|
||||||
|
|||||||
@@ -890,9 +890,6 @@ void send_join_game_t(shared_ptr<Client> c, shared_ptr<Lobby> l) {
|
|||||||
l->clients[x]->game_data.player()->disp);
|
l->clients[x]->game_data.player()->disp);
|
||||||
}
|
}
|
||||||
player_count++;
|
player_count++;
|
||||||
} else {
|
|
||||||
// inventory doesn't have a default contructor, so clear it manually
|
|
||||||
memset(&cmd.players_ep3[x].inventory, 0, sizeof(cmd.players_ep3[x].inventory));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user