Skip to content

Commit

Permalink
Make a new list for hardcoded map series in Discord RPC module and fi…
Browse files Browse the repository at this point in the history
…xed declaration of struct in com_model.h (#185)

* Added discord_rpc_closest_map_match to pickup map from list that closest match to current

* Convert the name of the current map and maps in the list to lowercase always

* Revert changes from previous commit, added comment about adding maps for list only in lower case!

* Removed discord_rpc_closest_map_match in favor of creating hardcoded map series list

* Moved helper function for lowercase to cl_util.h

* Replaced match method to eliminate wrong occurrences

* Fixed quotes in comment

* Separation of hldm and bhop maps into different lists for optimization

For those who play only in deathmatch mode, this will be an optimization, because compared to bhop maps there are less of them in the lists

* Revert empty lines that have been removed in one of previous commits

* Combined both of hldm and bhop lists back to the single one, but added some comments for 'separating' them

* map_series: replaced unordered_set to vector for O(n)
  • Loading branch information
SmileyAG committed Dec 30, 2023
1 parent 4ad5b2f commit 0ad666a
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 46 deletions.
9 changes: 9 additions & 0 deletions cl_dll/cl_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,15 @@ static size_t get_player_count()
return player_count;
}

inline void convert_to_lower_case(const char *str)
{
unsigned char *str_lw = (unsigned char *)str;
while (*str_lw) {
*str_lw = tolower(*str_lw);
str_lw++;
}
}

inline client_textmessage_t *TextMessageGet( const char *pName ) { return gEngfuncs.pfnTextMessageGet( pName ); }
inline int TextMessageDrawChar( int x, int y, int number, int r, int g, int b )
{
Expand Down
109 changes: 64 additions & 45 deletions cl_dll/discord_integration.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <algorithm>
#include <chrono>
#include <cstdint>
#include <cstring>
Expand All @@ -24,8 +25,53 @@ namespace discord_integration
// This seems to be consistent across PCs.
constexpr const char STEAM_APP_ID[] = "17215498729465839686";

// Maps for which we have thumbnails.
// Maps in next lists must be lowercase!
// Discord RPC allow to upload 300 assets per app, but we also use one thumbnail as default icon, so the lists cannot contain more than 299 maps in total!

// This list was specially created for a map series, let's say that "hl1_bhop_am" series have a several versions of maps (example: hl1_bhop_am_beta1), but in fact those maps are almost identical
// If the beginning of map name matches with what presented in the list, then we set the same name for the thumbnail as in the list (e.g. map name: hl1_bhop_uc1_beta1, thumbnail name: hl1_bhop_uc1)
const std::vector<std::string> map_series {
"hl1_bhop_am"s,
"hl1_bhop_bp1"s,
"hl1_bhop_bp2"s,
"hl1_bhop_faf"s,
"hl1_bhop_lc"s,
"hl1_bhop_oar"s,
"hl1_bhop_ocwgh"s,
"hl1_bhop_pu"s,
"hl1_bhop_qe"s,
"hl1_bhop_rp"s,
"hl1_bhop_st"s,
"hl1_bhop_uc1"s,
"hl1_bhop_uc2"s,
};

const std::unordered_set<std::string> maps_with_thumbnails {
// DM maps
"boot_camp"s,
"bootbox"s,
"bounce"s,
"crossfire"s,
"datacore"s,
"dm_dust2"s,
"eden"s,
"elixir"s,
"endcamp"s,
"frenzy"s,
"gasworks"s,
"havoc"s,
"killbox"s,
"lost_village2"s,
"outcry"s,
"rapidcore"s,
"scary_1"s,
"snark_pit"s,
"stalkx"s,
"stalkyard"s,
"subtransit"s,
"urethane"s,
"vengeance"s,
// Bhop maps
"2bfree"s,
"8b1_hellinashop"s,
"ag_bhop_dungeon"s,
Expand Down Expand Up @@ -68,9 +114,6 @@ namespace discord_integration
"bkz_aztecbhop"s,
"bkz_goldbhop"s,
"bkz_junglebhop"s,
"boot_camp"s,
"bootbox"s,
"bounce"s,
"bunnyrace_beta2"s,
"cg_cbblebhop"s,
"cg_coldbhop_v2"s,
Expand All @@ -80,43 +123,21 @@ namespace discord_integration
"cnd_speed_bhop"s,
"cobkz_construction"s,
"cosy_merrychristmas4"s,
"crossfire"s,
"d2_mario_bhop"s,
"datacore"s,
"daza_junglebhop"s,
"de_racetownz"s,
"destructo_hops"s,
"dev_control"s,
"dg_winterclimb"s,
"dm_dust2"s,
"dr0_deepbluesea"s,
"dyd_axn_plant"s,
"dyd_axn_sky"s,
"dyd_cosy_cupbhop_ez"s,
"e1m1"s,
"eden"s,
"elixir"s,
"endcamp"s,
"fof_axn_scroll_killa"s,
"fof_chillbhop"s,
"frenzy"s,
"fu_darkhop"s,
"gasworks"s,
"gayl0rd_bhop"s,
"havoc"s,
"hl1_bhop_am"s,
"hl1_bhop_bp1"s,
"hl1_bhop_bp2"s,
"hl1_bhop_faf"s,
"hl1_bhop_lc"s,
"hl1_bhop_oar"s,
"hl1_bhop_ocwgh"s,
"hl1_bhop_pu"s,
"hl1_bhop_qe"s,
"hl1_bhop_rp"s,
"hl1_bhop_st"s,
"hl1_bhop_uc1"s,
"hl1_bhop_uc2"s,
"hl_trick"s,
"hm_castlebhop"s,
"hm_speedwinterz"s,
Expand All @@ -128,7 +149,6 @@ namespace discord_integration
"j2s_4floors"s,
"jagkz_inferno"s,
"ka_kart-race"s,
"killbox"s,
"klbk_go"s,
"ksz_skeleton"s,
"kz-endo_bikinihop"s,
Expand Down Expand Up @@ -168,24 +188,14 @@ namespace discord_integration
"kzru_mam6ahop"s,
"kzsca_snakebhop"s,
"kzsca_watertemple"s,
"lost_village2"s,
"mf_doom_e1m1_e"s,
"outcry"s,
"pd_shafthop"s,
"prochallenge2_longjump"s,
"rapidcore"s,
"rnr_speedcrag"s,
"scary_1"s,
"smk_floppytown"s,
"snark_pit"s,
"speed_ytt_egypt"s,
"stalkx"s,
"stalkyard"s,
"subtransit"s,
"uq_axn_imoor"s,
"uq_skrol_bhop"s,
"urethane"s,
"vengeance"s,
"xjbg_bhoptemple_hard"s,
"zjumps"s,
"ztricks"s
Expand Down Expand Up @@ -343,17 +353,26 @@ namespace discord_integration
get_map_name(map_name, ARRAYSIZE(map_name));
if (map_name[0])
{
// adjust to lowercase
unsigned char *tptr = (unsigned char *)map_name;
while (*tptr) {
*tptr = tolower(*tptr);
tptr++;
}
// We specifically don't want to convert the map name that will be shown when hovering over the map icon (presence.largeImageText), so that why it got moved above.
presence.largeImageText = map_name;

convert_to_lower_case(map_name);

if (maps_with_thumbnails.find(map_name) != maps_with_thumbnails.cend())
{
presence.largeImageKey = map_name;

presence.largeImageText = map_name;
}
else
{
auto closest_match = std::find_if(map_series.begin(), map_series.end(), [&](const std::string& str) {
return static_cast<std::string>(map_name).compare(0, str.length(), str) == 0; // hl1_bhop_am_beta6 -> hl1_bhop_am
});

if (closest_match != map_series.end())
{
presence.largeImageKey = closest_match->c_str();
}
}
}

// Get the server address.
Expand Down
2 changes: 1 addition & 1 deletion common/com_model.h
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ typedef struct glpoly_s
float verts[4][VERTEXSIZE];
} glpoly_t;

typedef struct mdisplaylist_t // Half-Life 25th Anniversary Update
typedef struct mdisplaylist_s // Half-Life 25th Anniversary Update
{
unsigned gl_displaylist;
int rendermode;
Expand Down

0 comments on commit 0ad666a

Please sign in to comment.