From bed0b55e70f13adf772584fc0d31ebfe59597115 Mon Sep 17 00:00:00 2001 From: gameboyprinter Date: Thu, 5 Jul 2018 12:21:32 -0500 Subject: [PATCH 1/5] Make discord toggleable, OOC name option, default bg fix --- aoapplication.cpp | 3 ++- aoapplication.h | 6 ++++++ aoblipplayer.cpp | 6 +++--- aoblipplayer.h | 4 +++- courtroom.cpp | 7 +++++-- courtroom.h | 2 +- lobby.cpp | 1 + packet_distribution.cpp | 3 ++- path_functions.cpp | 19 ++----------------- text_file_functions.cpp | 15 ++++++++++----- 10 files changed, 35 insertions(+), 31 deletions(-) diff --git a/aoapplication.cpp b/aoapplication.cpp index 12e540c..54ec180 100644 --- a/aoapplication.cpp +++ b/aoapplication.cpp @@ -40,7 +40,8 @@ void AOApplication::construct_lobby() int y = (screenGeometry.height()-w_lobby->height()) / 2; w_lobby->move(x, y); - discord->state_lobby(); + if(is_discord_enabled()) + discord->state_lobby(); w_lobby->show(); } diff --git a/aoapplication.h b/aoapplication.h index 2a5c436..f7cdb00 100644 --- a/aoapplication.h +++ b/aoapplication.h @@ -114,6 +114,9 @@ public: //Reads the theme from config.ini and loads it into the current_theme variable QString read_theme(); + //Returns the value of ooc_name in config.ini + QString get_ooc_name(); + //Returns the blip rate from config.ini int read_blip_rate(); @@ -129,6 +132,9 @@ public: //Returns the value of default_blip in config.ini int get_default_blip(); + //Returns true if discord is enabled in config.ini and false otherwise + bool is_discord_enabled(); + //Returns the list of words in callwords.ini QStringList get_call_words(); diff --git a/aoblipplayer.cpp b/aoblipplayer.cpp index f212453..63f0494 100644 --- a/aoblipplayer.cpp +++ b/aoblipplayer.cpp @@ -14,7 +14,7 @@ void AOBlipPlayer::set_blips(QString p_sfx) { QString f_path = ao_app->get_sounds_path() + p_sfx.toLower(); - for (int n_stream = 0 ; n_stream < 5 ; ++n_stream) + for (int n_stream = 0 ; n_stream < BLIP_COUNT ; ++n_stream) { BASS_StreamFree(m_stream_list[n_stream]); @@ -28,7 +28,7 @@ void AOBlipPlayer::blip_tick() { int f_cycle = m_cycle++; - if (m_cycle == 5) + if (m_cycle == BLIP_COUNT) m_cycle = 0; HSTREAM f_stream = m_stream_list[f_cycle]; @@ -42,7 +42,7 @@ void AOBlipPlayer::set_volume(int p_value) float volume = p_value / 100.0f; - for (int n_stream = 0 ; n_stream < 5 ; ++n_stream) + for (int n_stream = 0 ; n_stream < BLIP_COUNT ; ++n_stream) { BASS_ChannelSetAttribute(m_stream_list[n_stream], BASS_ATTRIB_VOL, volume); } diff --git a/aoblipplayer.h b/aoblipplayer.h index 430f702..6e3ce1c 100644 --- a/aoblipplayer.h +++ b/aoblipplayer.h @@ -6,6 +6,8 @@ #include +const int BLIP_COUNT = 5; + class AOBlipPlayer { public: @@ -22,7 +24,7 @@ private: AOApplication *ao_app; int m_volume; - HSTREAM m_stream_list[5]; + HSTREAM m_stream_list[BLIP_COUNT]; }; #endif // AOBLIPPLAYER_H diff --git a/courtroom.cpp b/courtroom.cpp index ca94f43..8ddb6ed 100644 --- a/courtroom.cpp +++ b/courtroom.cpp @@ -109,6 +109,7 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow() ui_ooc_chat_name = new QLineEdit(this); ui_ooc_chat_name->setFrame(false); ui_ooc_chat_name->setPlaceholderText("Name"); + ui_ooc_chat_name->setText(ao_app->get_ooc_name()); //ui_area_password = new QLineEdit(this); //ui_area_password->setFrame(false); @@ -663,13 +664,15 @@ void Courtroom::enter_courtroom(int p_cid) if (m_cid == -1) { - ao_app->discord->state_spectate(); + if(ao_app->is_discord_enabled()) + ao_app->discord->state_spectate(); f_char = ""; } else { f_char = ao_app->get_char_name(char_list.at(m_cid).name); - ao_app->discord->state_character(f_char.toStdString()); + if(ao_app->is_discord_enabled()) + ao_app->discord->state_character(f_char.toStdString()); } current_char = f_char; diff --git a/courtroom.h b/courtroom.h index 85554a0..e4a4f16 100644 --- a/courtroom.h +++ b/courtroom.h @@ -250,7 +250,7 @@ private: //whether the ooc chat is server or master chat, true is server bool server_ooc = true; - QString current_background = "gs4"; + QString current_background = "default"; AOMusicPlayer *music_player; AOSfxPlayer *sfx_player; diff --git a/lobby.cpp b/lobby.cpp index 13ef550..c0dbf0c 100644 --- a/lobby.cpp +++ b/lobby.cpp @@ -29,6 +29,7 @@ Lobby::Lobby(AOApplication *p_ao_app) : QMainWindow() ui_chatbox->setOpenExternalLinks(true); ui_chatname = new QLineEdit(this); ui_chatname->setPlaceholderText("Name"); + ui_chatname->setText(ao_app->get_ooc_name()); ui_chatmessage = new QLineEdit(this); ui_loading_background = new AOImage(this, ao_app); ui_loading_text = new QTextEdit(ui_loading_background); diff --git a/packet_distribution.cpp b/packet_distribution.cpp index 3908ffa..4299518 100644 --- a/packet_distribution.cpp +++ b/packet_distribution.cpp @@ -264,7 +264,8 @@ void AOApplication::server_packet_received(AOPacket *p_packet) QCryptographicHash hash(QCryptographicHash::Algorithm::Sha256); hash.addData(server_address.toUtf8()); - discord->state_server(server_name.toStdString(), hash.result().toBase64().toStdString()); + if(is_discord_enabled()) + discord->state_server(server_name.toStdString(), hash.result().toBase64().toStdString()); } else if (header == "CI") { diff --git a/path_functions.cpp b/path_functions.cpp index 6e772db..820c05a 100644 --- a/path_functions.cpp +++ b/path_functions.cpp @@ -29,21 +29,6 @@ QString AOApplication::get_base_path() #endif } return base_path; - /* -#ifdef OMNI_DEBUG - return "/media/omnitroid/Data/winshare/AO/client/base/"; -#elif OMNI_DEBUG2 - return "/home/omnitroid/winshare/AO/client/base/"; -#elif defined(OMNI_WIN_DEBUG) - return "E:/AO/client/base/"; -#elif defined(OMNI_WIN_DEBUG2) - return "F:/winshare/AO/client/base/"; -#elif defined(ANDROID) - return "/storage/extSdCard/AO2/"; -#else - return QDir::currentPath() + "/base/"; -#endif -*/ } QString AOApplication::get_data_path() @@ -96,7 +81,7 @@ QString AOApplication::get_background_path() QString AOApplication::get_default_background_path() { - return get_base_path() + "background/gs4/"; + return get_base_path() + "background/default/"; } QString AOApplication::get_evidence_path() @@ -118,5 +103,5 @@ QString Courtroom::get_background_path() QString Courtroom::get_default_background_path() { - return ao_app->get_base_path() + "background/gs4/"; + return ao_app->get_base_path() + "background/default/"; } diff --git a/text_file_functions.cpp b/text_file_functions.cpp index 90b10f5..2263fa1 100644 --- a/text_file_functions.cpp +++ b/text_file_functions.cpp @@ -52,6 +52,11 @@ QString AOApplication::read_theme() return result; } +QString AOApplication::get_ooc_name() +{ + return read_config("ooc_name"); +} + int AOApplication::read_blip_rate() { QString result = read_config("blip_rate"); @@ -571,8 +576,8 @@ bool AOApplication::get_blank_blip() return f_result.startsWith("true"); } - - - - - +bool AOApplication::is_discord_enabled() +{ + QString f_result = read_config("discord"); + return f_result.startsWith("true"); +} \ No newline at end of file From 4e96a41b4ee6bbc920b7c5a5ec555d6d14e65b18 Mon Sep 17 00:00:00 2001 From: gameboyprinter Date: Thu, 5 Jul 2018 12:26:15 -0500 Subject: [PATCH 2/5] better int to hex --- hex_functions.cpp | 34 +++++++++------------------------- hex_functions.h | 2 ++ 2 files changed, 11 insertions(+), 25 deletions(-) diff --git a/hex_functions.cpp b/hex_functions.cpp index 9db2b0a..c503af6 100644 --- a/hex_functions.cpp +++ b/hex_functions.cpp @@ -4,6 +4,9 @@ namespace omni { + // This might be unused but I don't care to search the entire source code + // So it will remain here (lol) + // The actual int to hex conversion is now done properly char halfword_to_hex_char(unsigned int input) { if (input > 127) @@ -53,31 +56,12 @@ namespace omni if (input > 255) return "FF"; - std::bitset<8> whole_byte(input); - //240 represents 11110000, our needed bitmask - uint8_t left_mask_int = 240; - std::bitset<8> left_mask(left_mask_int); - std::bitset<8> left_halfword((whole_byte & left_mask) >> 4); - //likewise, 15 represents 00001111 - uint8_t right_mask_int = 15; - std::bitset<8> right_mask(right_mask_int); - std::bitset<8> right_halfword((whole_byte & right_mask)); + std::stringstream stream; + stream << std::setfill ('0') << std::setw(sizeof(char)*2) + << std::hex << your_int; + std::string result(stream.str()); + std::transform(str.begin(), str.end(), str.begin(), ::toupper); - unsigned int left = left_halfword.to_ulong(); - unsigned int right = right_halfword.to_ulong(); - - //std::cout << "now have have " << left << " and " << right << '\n'; - - char a = halfword_to_hex_char(left); - char b = halfword_to_hex_char(right); - - std::string left_string(1, a); - std::string right_string(1, b); - - std::string final_byte = left_string + right_string; - - //std::string final_byte = halfword_to_hex_char(left) + "" + halfword_to_hex_char(right); - - return final_byte; + return result; } } //namespace omni diff --git a/hex_functions.h b/hex_functions.h index 47d9466..9f7a1e7 100644 --- a/hex_functions.h +++ b/hex_functions.h @@ -4,6 +4,8 @@ #include #include #include +#include +#include namespace omni { From bb0b767ba40d189b97ffe371ab063c5380609b0c Mon Sep 17 00:00:00 2001 From: Denton Date: Thu, 5 Jul 2018 12:47:36 -0500 Subject: [PATCH 3/5] pretend you didnt see this --- hex_functions.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hex_functions.cpp b/hex_functions.cpp index c503af6..e07a7b0 100644 --- a/hex_functions.cpp +++ b/hex_functions.cpp @@ -58,7 +58,7 @@ namespace omni std::stringstream stream; stream << std::setfill ('0') << std::setw(sizeof(char)*2) - << std::hex << your_int; + << std::hex << input; std::string result(stream.str()); std::transform(str.begin(), str.end(), str.begin(), ::toupper); From e36dae20b7d1baba912c55ec55b82a380c4973da Mon Sep 17 00:00:00 2001 From: oldmud0 Date: Thu, 5 Jul 2018 21:26:05 -0500 Subject: [PATCH 4/5] Fix hex_functions compile errors --- hex_functions.cpp | 4 ++-- hex_functions.h | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/hex_functions.cpp b/hex_functions.cpp index e07a7b0..683097e 100644 --- a/hex_functions.cpp +++ b/hex_functions.cpp @@ -57,10 +57,10 @@ namespace omni return "FF"; std::stringstream stream; - stream << std::setfill ('0') << std::setw(sizeof(char)*2) + stream << std::setfill('0') << std::setw(sizeof(char)*2) << std::hex << input; std::string result(stream.str()); - std::transform(str.begin(), str.end(), str.begin(), ::toupper); + std::transform(result.begin(), result.end(), result.begin(), ::toupper); return result; } diff --git a/hex_functions.h b/hex_functions.h index 9f7a1e7..1f22339 100644 --- a/hex_functions.h +++ b/hex_functions.h @@ -6,6 +6,8 @@ #include #include #include +#include +#include namespace omni { From 42e26d67756afc2cb8cdeb97ed654507c7cf4f3e Mon Sep 17 00:00:00 2001 From: oldmud0 Date: Thu, 5 Jul 2018 21:32:49 -0500 Subject: [PATCH 5/5] Enable Discord by default if not in config.ini --- text_file_functions.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/text_file_functions.cpp b/text_file_functions.cpp index 2263fa1..b77e178 100644 --- a/text_file_functions.cpp +++ b/text_file_functions.cpp @@ -579,5 +579,5 @@ bool AOApplication::get_blank_blip() bool AOApplication::is_discord_enabled() { QString f_result = read_config("discord"); - return f_result.startsWith("true"); -} \ No newline at end of file + return !f_result.startsWith("false"); +}