diff --git a/ChatCommands.cc b/ChatCommands.cc index b50cbd79..b418bdad 100644 --- a/ChatCommands.cc +++ b/ChatCommands.cc @@ -1,5 +1,7 @@ #include "ChatCommands.hh" +#include + #include #include #include diff --git a/Compression.cc b/Compression.cc index 92f56f8f..31b593c4 100644 --- a/Compression.cc +++ b/Compression.cc @@ -102,7 +102,7 @@ string prs_compress(const string& data) { prs_compress_ctx pc; ssize_t read_offset = 0; - while (read_offset < data.size()) { + while (read_offset < static_cast(data.size())) { // look for a chunk of data in history matching what's at the current offset ssize_t best_offset = 0; @@ -263,7 +263,7 @@ size_t prs_decompress_size(const string& data, size_t max_size) { size_t output_size = 0; StringReader r(data.data(), data.size()); - int32_t r3, r5; + int32_t r3; int bitpos = 9; int16_t currentbyte; // int16_t because it can be -1 when EOF occurs int flag; @@ -321,7 +321,6 @@ size_t prs_decompress_size(const string& data, size_t max_size) { return output_size; } r3 = r3 & 0x00000007; - r5 = (offset >> 3) | 0xFFFFE000; if (r3 == 0) { flag = 0; r3 = get_u8_or_eof(r); @@ -353,7 +352,6 @@ size_t prs_decompress_size(const string& data, size_t max_size) { return output_size; } r3 += 2; - r5 = offset | 0xFFFFFF00; } if (r3 == 0) { continue; diff --git a/DNSServer.cc b/DNSServer.cc index a1a83a95..a7e5e5f9 100644 --- a/DNSServer.cc +++ b/DNSServer.cc @@ -1,6 +1,7 @@ #include "DNSServer.hh" #include +#include #include #include #include diff --git a/Items.cc b/Items.cc index 7e92df6e..4224e1a6 100644 --- a/Items.cc +++ b/Items.cc @@ -1,5 +1,7 @@ #include "Items.hh" +#include + #include using namespace std; @@ -143,22 +145,23 @@ void player_use_item_locked(shared_ptr l, shared_ptr c, size_t item_index) { ssize_t equipped_weapon = -1; - ssize_t equipped_armor = -1; - ssize_t equipped_shield = -1; - ssize_t equipped_mag = -1; + // ssize_t equipped_armor = -1; + // ssize_t equipped_shield = -1; + // ssize_t equipped_mag = -1; for (size_t y = 0; y < c->player.inventory.num_items; y++) { if (c->player.inventory.items[y].equip_flags & 0x0008) { if (c->player.inventory.items[y].data.item_data1[0] == 0) { equipped_weapon = y; - } else if ((c->player.inventory.items[y].data.item_data1[0] == 1) && - (c->player.inventory.items[y].data.item_data1[1] == 1)) { - equipped_armor = y; - } else if ((c->player.inventory.items[y].data.item_data1[0] == 1) && - (c->player.inventory.items[y].data.item_data1[1] == 2)) { - equipped_shield = y; - } else if (c->player.inventory.items[y].data.item_data1[0] == 2) { - equipped_mag = y; } + // else if ((c->player.inventory.items[y].data.item_data1[0] == 1) && + // (c->player.inventory.items[y].data.item_data1[1] == 1)) { + // equipped_armor = y; + // } else if ((c->player.inventory.items[y].data.item_data1[0] == 1) && + // (c->player.inventory.items[y].data.item_data1[1] == 2)) { + // equipped_shield = y; + // } else if (c->player.inventory.items[y].data.item_data1[0] == 2) { + // equipped_mag = y; + // } } } diff --git a/LevelTable.cc b/LevelTable.cc index 65acbea7..dc0f83c5 100644 --- a/LevelTable.cc +++ b/LevelTable.cc @@ -1,5 +1,7 @@ #include "LevelTable.hh" +#include + #include #include "Compression.hh" diff --git a/License.cc b/License.cc index b08d0283..967ca12b 100644 --- a/License.cc +++ b/License.cc @@ -43,8 +43,9 @@ LicenseManager::LicenseManager(const std::string& filename) : filename(filename) auto licenses = load_vector_file(this->filename); for (const auto& read_license : licenses) { shared_ptr license(new License(read_license)); + uint32_t serial_number = license->serial_number; this->bb_username_to_license.emplace(license->username, license); - this->serial_number_to_license.emplace(license->serial_number, license); + this->serial_number_to_license.emplace(serial_number, license); } } catch (const cannot_open_file&) { @@ -124,7 +125,8 @@ void LicenseManager::ban_until(uint32_t serial_number, uint64_t end_time) { void LicenseManager::add(shared_ptr l) { { rw_guard g(this->lock, true); - this->serial_number_to_license.emplace(l->serial_number, l); + uint32_t serial_number = l->serial_number; + this->serial_number_to_license.emplace(serial_number, l); if (l->username[0]) { this->bb_username_to_license.emplace(l->username, l); } diff --git a/Lobby.cc b/Lobby.cc index 42fc1d43..10852c5b 100644 --- a/Lobby.cc +++ b/Lobby.cc @@ -1,5 +1,7 @@ #include "Lobby.hh" +#include + #include "SendCommands.hh" #include "Text.hh" diff --git a/PSOEncryption.cc b/PSOEncryption.cc index 2a5673ac..a666ab10 100644 --- a/PSOEncryption.cc +++ b/PSOEncryption.cc @@ -299,11 +299,9 @@ void PSOBBEncryption::decrypt(void* vdata, size_t size) { size >>= 3; uint32_t* data = reinterpret_cast(vdata); - uint32_t eax, ecx, edx, ebx, ebp, esi, edi; + uint32_t edx, ebx, ebp, esi, edi; edx = 0; - ecx = 0; - eax = 0; while (edx < size) { ebx = data[edx]; ebx = ebx ^ this->stream[5]; @@ -337,11 +335,9 @@ void PSOBBEncryption::encrypt(void* vdata, size_t size) { size >>= 3; uint8_t* data = reinterpret_cast(vdata); - uint32_t eax, ecx, edx, ebx, ebp, esi, edi; + uint32_t edx, ebx, ebp, esi, edi; edx = 0; - ecx = 0; - eax = 0; while (edx < size) { ebx = data[edx]; ebx = ebx ^ this->stream[0]; diff --git a/PSOProtocol.cc b/PSOProtocol.cc index 22b8a65d..a74aa906 100644 --- a/PSOProtocol.cc +++ b/PSOProtocol.cc @@ -1,5 +1,9 @@ #include "PSOProtocol.hh" +#include + +using namespace std; + uint16_t PSOCommandHeader::command(GameVersion version) const { @@ -13,6 +17,7 @@ uint16_t PSOCommandHeader::command(GameVersion version) const { case GameVersion::BB: return reinterpret_cast(this)->command; } + throw logic_error("unknown game version"); } uint16_t PSOCommandHeader::size(GameVersion version) const { @@ -26,6 +31,7 @@ uint16_t PSOCommandHeader::size(GameVersion version) const { case GameVersion::BB: return reinterpret_cast(this)->size; } + throw logic_error("unknown game version"); } uint32_t PSOCommandHeader::flag(GameVersion version) const { @@ -39,5 +45,6 @@ uint32_t PSOCommandHeader::flag(GameVersion version) const { case GameVersion::BB: return reinterpret_cast(this)->flag; } + throw logic_error("unknown game version"); } diff --git a/Quest.cc b/Quest.cc index 3d8fd67b..5ccd9d33 100644 --- a/Quest.cc +++ b/Quest.cc @@ -1,5 +1,6 @@ #include "Quest.hh" +#include #include #include #include @@ -330,7 +331,8 @@ QuestIndex::QuestIndex(const char* directory) : directory(directory) { string full_path = this->directory + "/" + filename; if (ends_with(filename, ".gba")) { - this->gba_file_contents.emplace(filename, new string(load_file(full_path))); + shared_ptr contents(new string(load_file(full_path))); + this->gba_file_contents.emplace(make_pair(filename, contents)); continue; } diff --git a/Quest.hh b/Quest.hh index 909a453d..ef28b37a 100644 --- a/Quest.hh +++ b/Quest.hh @@ -3,7 +3,9 @@ #include #include +#include #include +#include #include "Version.hh" diff --git a/README.md b/README.md index 7880123b..08766088 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,10 @@ This project is primarily for my own nostalgia. Feel free to peruse if you'd lik ## Usage +Currently this code should build on macOS and Ubuntu. It might build on other Linux flavors, but don't expect it to work on Windows at all. + So, you've read all of the above and you want to try it out? Here's what you do: +- Make sure you have libreadline installed (use Homebrew in macOS, or install libreadline-dev in Linux). - Build and install phosg (https://github.com/fuzziqersoftware/phosg). - Run `make`. - Edit system/config.json to your liking. diff --git a/ReceiveCommands.cc b/ReceiveCommands.cc index 62639c8c..9f118474 100644 --- a/ReceiveCommands.cc +++ b/ReceiveCommands.cc @@ -1,6 +1,7 @@ #include "SendCommands.hh" #include +#include #include #include diff --git a/ReceiveSubcommands.cc b/ReceiveSubcommands.cc index b7bbca3f..88cec0d7 100644 --- a/ReceiveSubcommands.cc +++ b/ReceiveSubcommands.cc @@ -1,5 +1,7 @@ #include "ReceiveSubcommands.hh" +#include + #include #include diff --git a/SendCommands.cc b/SendCommands.cc index 56c1e42a..11d65107 100644 --- a/SendCommands.cc +++ b/SendCommands.cc @@ -1,5 +1,7 @@ #include "SendCommands.hh" +#include + #include #include #include diff --git a/Server.cc b/Server.cc index 5808fa5c..2b05e4aa 100644 --- a/Server.cc +++ b/Server.cc @@ -128,7 +128,8 @@ void Server::on_listen_accept(Server::WorkerThread& wt, struct bufferevent *bev = bufferevent_socket_new(wt.base.get(), fd, BEV_OPT_CLOSE_ON_FREE | BEV_OPT_THREADSAFE | BEV_OPT_DEFER_CALLBACKS | BEV_OPT_UNLOCK_CALLBACKS); - auto emplace_ret = wt.bev_to_client.emplace(bev, new Client(bev, version, initial_state)); + shared_ptr c(new Client(bev, version, initial_state)); + auto emplace_ret = wt.bev_to_client.emplace(make_pair(bev, c)); this->client_count++; bufferevent_setcb(bev, &WorkerThread::dispatch_on_client_input, NULL, @@ -231,7 +232,7 @@ void Server::receive_and_process_commands(shared_ptr c, struct buffereve new_bytes &= ~(header_size - 1); // only read in multiples of header_size c->recv_buffer.resize(existing_bytes + new_bytes); void* recv_ptr = const_cast(c->recv_buffer.data() + existing_bytes); - if (evbuffer_remove(buf, recv_ptr, new_bytes) != new_bytes) { + if (evbuffer_remove(buf, recv_ptr, new_bytes) != static_cast(new_bytes)) { throw runtime_error("some bytes could not be read from the receive buffer"); }