Skip to content

Commit

Permalink
Old functions for getting and checking the map name and game director…
Browse files Browse the repository at this point in the history
…y have been replaced with new ones
  • Loading branch information
SmileyAG committed Apr 3, 2024
1 parent 85d7c6d commit 5c47c8a
Show file tree
Hide file tree
Showing 8 changed files with 481 additions and 614 deletions.
359 changes: 146 additions & 213 deletions BunnymodXT/discord_integration.cpp

Large diffs are not rendered by default.

426 changes: 218 additions & 208 deletions BunnymodXT/discord_integration.hpp

Large diffs are not rendered by default.

57 changes: 56 additions & 1 deletion BunnymodXT/helper_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,8 @@ namespace helper_functions

double ret_bxt_time()
{
return (CustomHud::GetTime().hours * 60 * 60) + (CustomHud::GetTime().minutes * 60) + CustomHud::GetTime().seconds + (CustomHud::GetTime().milliseconds / 1000);
const auto& gt = CustomHud::GetTime();
return (gt.hours * 60 * 60) + (gt.minutes * 60) + gt.seconds + (gt.milliseconds / 1000);
}

void com_fixslashes(std::string &str)
Expand Down Expand Up @@ -371,6 +372,49 @@ namespace helper_functions
return false;
}

int build_number(const char *date)
{
const char *mon[12] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
const char mond[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };

#ifdef _WIN32
#define Q_strncasecmp _strnicmp
#else
#define Q_strncasecmp strncasecmp
#endif

int m = 0, d = 0, y = 0, build = 0;
for (m = 0; m < 11; m++)
{
if (Q_strncasecmp(&date[0], mon[m], 3) == 0)
break;
d += mond[m];
}

#undef Q_strncasecmp

d += atoi(&date[4]) - 1;
y = atoi(&date[7]) - 1900;
build = d + (int)((y - 1) * 365.25);

if (((y % 4) == 0) && m > 1)
build += 1;

#define START_DATE_GOLDSRC 34995 // Used in GoldSrc and Quake builds (Oct 24 1996)
#define START_DATE_SOURCE 35739 // Used in builds on the Source Engine (Nov 7 1998)
#define START_DATE_HL2_BETA 37527 // Used in builds on the Source Engine before the official release of HL2 (Sep 30 2003)

build -= START_DATE_GOLDSRC;

return build;
}

int build_number()
{
static int build = build_number(__DATE__);
return build;
}

int IsInWorld(Vector origin, Vector velocity, int map_size, int map_max_velocity)
{
/*
Expand Down Expand Up @@ -495,6 +539,17 @@ namespace helper_functions

// Below this comment are only functions for determining type or flags!

std::string get_difficulty(int skill)
{
switch (skill)
{
case 1: return "Easy";
case 2: return "Normal";
case 3: return "Hard";
default: return "Unknown";
}
}

std::string get_renderfx(int renderfx)
{
switch (renderfx)
Expand Down
29 changes: 19 additions & 10 deletions BunnymodXT/helper_functions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,22 @@

const steamid_t STEAMID64_CONST = 76561197960265728; // 0x110000100000000

// Usage:
// if (!strncmp(var, HF_StrAndLen("test")))
#define HF_StrAndLen(str) \
str, sizeof(str) - 1

// This is done in order to find out the length of string at the compile-time
// We subtract 1 from sizeof due of the null terminator
#define HF_DoesGameDirStartsWith(game) \
helper_functions::does_gamedir_starts_with(game, sizeof(game) - 1)
#define HF_DoesMapNameStartsWith(map) \
helper_functions::does_mapname_starts_with(map, sizeof(map) - 1)
#define HF_DoesGameDirMatch(game) \
helper_functions::does_gamedir_match(game)
#define HF_DoesMapNameMatch(map) \
helper_functions::does_mapname_match(map)

namespace helper_functions
{
// https://github.com/ValveSoftware/halflife/blob/master/common/parsemsg.cpp
Expand Down Expand Up @@ -54,16 +70,6 @@ namespace helper_functions
bool does_gamedir_match(const char *game);
bool does_mapname_starts_with(const char *map, size_t len);
bool does_mapname_match(const char *map);
// This is done in order to find out the length of string at the compile-time
// We subtract 1 from sizeof due of the null terminator
#define HF_DoesGameDirStartsWith(game) \
helper_functions::does_gamedir_starts_with(game, sizeof(game) - 1);
#define HF_DoesMapNameStartsWith(map) \
helper_functions::does_mapname_starts_with(game, sizeof(map) - 1);
#define HF_DoesGameDirMatch(game) \
helper_functions::does_gamedir_match(game);
#define HF_DoesMapNameMatch(map) \
helper_functions::does_mapname_match(map);

double ret_bxt_time();
void com_fixslashes(std::string &str); // https://github.com/ValveSoftware/halflife/blob/c7240b965743a53a29491dd49320c88eecf6257b/game_shared/bot/nav_file.cpp#L680
Expand All @@ -81,9 +87,12 @@ namespace helper_functions
std::string get_solid(int solid);
std::string get_monster_triggercondition(int m_iTriggerCondition);
std::string get_monster_task(int iTask);
std::string get_difficulty(int skill);
void split_console_print_to_chunks(std::string str, const unsigned int max_string_length);
void split_console_print_to_chunks(std::string str);
void convert_to_lowercase(const char *str);
int build_number(const char *date);
int build_number();

// https://developer.valvesoftware.com/wiki/SteamID
std::string get_steam_id(const unsigned long steamID32);
Expand Down
132 changes: 2 additions & 130 deletions BunnymodXT/modules/ClientDLL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1156,134 +1156,6 @@ void ClientDLL::StudioAdjustViewmodelAttachments(Vector &vOrigin)
vOrigin = last_vieworg + vOut;
}

void ClientDLL::FileBase(const char *in, char *out)
{
int len, start, end;

len = strlen(in);

// scan backward for '.'
end = len - 1;
while (0 != end && in[end] != '.' && in[end] != '/' && in[end] != '\\')
end--;

if (in[end] != '.') // no '.', copy to end
end = len - 1;
else
end--; // Found ',', copy to left of '.'

// Scan backward for '/'
start = len - 1;
while (start >= 0 && in[start] != '/' && in[start] != '\\')
start--;

if (in[start] != '/' && in[start] != '\\')
start = 0;
else
start++;

// Length of new sting
len = end - start + 1;

// Copy partial string
strncpy(out, &in[start], len);
// Terminate it
out[len] = 0;
}

void ClientDLL::ConvertToLowerCase(const char *str)
{
unsigned char *str_lw = (unsigned char *)str;
while (*str_lw) {
*str_lw = tolower(*str_lw);
str_lw++;
}
}

bool ClientDLL::DoesGameDirMatch(const char *game)
{
if (!pEngfuncs)
return false;

const char *gameDir = pEngfuncs->pfnGetGameDirectory();
char gd[1024];

if (gameDir && gameDir[0])
{
FileBase(gameDir, gd);
ConvertToLowerCase(gd);
}

return !std::strcmp(gd, game);
}

bool ClientDLL::DoesGameDirContain(const char *game)
{
if (!pEngfuncs)
return false;

const char *gameDir = pEngfuncs->pfnGetGameDirectory();
char gd[1024];

if (gameDir && gameDir[0])
{
FileBase(gameDir, gd);
ConvertToLowerCase(gd);
}

return std::strstr(gd, game);
}

size_t ClientDLL::GetMapName(char* dest, size_t count)
{
auto map_path = pEngfuncs->pfnGetLevelName();

const char* slash = strrchr(map_path, '/');
if (!slash)
slash = map_path - 1;

const char* dot = strrchr(map_path, '.');
if (!dot)
dot = map_path + strlen(map_path);

size_t bytes_to_copy = std::min(count - 1, static_cast<size_t>(dot - slash - 1));

strncpy(dest, slash + 1, bytes_to_copy);
dest[bytes_to_copy] = '\0';

return bytes_to_copy;
}

bool ClientDLL::DoesMapNameMatch(const char *map)
{
if (!pEngfuncs)
return false;

char map_name[64];

GetMapName(map_name, ARRAYSIZE_HL(map_name));

if (map_name[0])
ConvertToLowerCase(map_name);

return !std::strcmp(map_name, map);
}

bool ClientDLL::DoesMapNameContain(const char *map)
{
if (!pEngfuncs)
return false;

char map_name[64];

GetMapName(map_name, ARRAYSIZE_HL(map_name));

if (map_name[0])
ConvertToLowerCase(map_name);

return std::strstr(map_name, map);
}

std::string ClientDLL::GetLevelName()
{
std::string mapname = "";
Expand Down Expand Up @@ -1915,7 +1787,7 @@ HOOK_DEF_1(ClientDLL, void, __cdecl, CStudioModelRenderer__StudioSetupBones_Linu
{
ptrdiff_t offpCurrentEntity_Linux;
ptrdiff_t offpStudioHeader_Linux;
if (DoesGameDirMatch("dod")) {
if (HF_DoesGameDirMatch("dod")) {
offpCurrentEntity_Linux = 52;
offpStudioHeader_Linux = 72;
} else {
Expand Down Expand Up @@ -2042,7 +1914,7 @@ HOOK_DEF_1(ClientDLL, void, __fastcall, CStudioModelRenderer__StudioRenderModel,
HOOK_DEF_1(ClientDLL, void, __cdecl, CStudioModelRenderer__StudioRenderModel_Linux, void*, thisptr)
{
ptrdiff_t offpCurrentEntity_Linux;
if (DoesGameDirMatch("dod"))
if (HF_DoesGameDirMatch("dod"))
offpCurrentEntity_Linux = 52;
else
offpCurrentEntity_Linux = 44;
Expand Down
10 changes: 0 additions & 10 deletions BunnymodXT/modules/ClientDLL.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,6 @@ class ClientDLL : public IHookableNameFilter

void StudioAdjustViewmodelAttachments(Vector &vOrigin);

bool DoesGameDirMatch(const char *game);
bool DoesGameDirContain(const char *game);

size_t GetMapName(char* dest, size_t count);
bool DoesMapNameMatch(const char *map);
bool DoesMapNameContain(const char *map);

bool orig_forcehltv_found = false;
bool orig_righthand_not_found = false;

Expand Down Expand Up @@ -110,9 +103,6 @@ class ClientDLL : public IHookableNameFilter

void SetSpeedScaling(bool scaled);

void FileBase(const char *in, char *out);
void ConvertToLowerCase(const char *str);

void SetupTraceVectors(float start[3], float end[3]);

/*
Expand Down
12 changes: 6 additions & 6 deletions BunnymodXT/modules/HwDLL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6784,9 +6784,9 @@ HLStrafe::MovementVars HwDLL::GetMovementVars()
vars.Bounce = CVars::sv_bounce.GetFloat();
vars.Bhopcap = CVars::bxt_bhopcap.GetBool();

static bool is_paranoia_dir = cl.DoesGameDirMatch("paranoia");
is_tfc_dir = cl.DoesGameDirMatch("tfc");
is_cstrike_dir = cl.DoesGameDirMatch("cstrike") || cl.DoesGameDirMatch("czero");
static bool is_paranoia_dir = HF_DoesGameDirMatch("paranoia");
is_tfc_dir = HF_DoesGameDirMatch("tfc");
is_cstrike_dir = HF_DoesGameDirMatch("cstrike") || HF_DoesGameDirMatch("czero");

if (is_paranoia_dir)
vars.Maxspeed = cl.pEngfuncs->GetClientMaxspeed() * CVars::sv_maxspeed.GetFloat() / 100.0f; // GetMaxSpeed is factor here
Expand Down Expand Up @@ -7885,7 +7885,7 @@ HOOK_DEF_1(HwDLL, void, __cdecl, VGuiWrap_Paint, int, paintAll)

HOOK_DEF_3(HwDLL, int, __cdecl, DispatchDirectUserMsg, char*, pszName, int, iSize, void*, pBuf)
{
if (ClientDLL::GetInstance().DoesGameDirContain("czeror") && !std::strcmp(pszName, "InitHUD"))
if (HF_DoesGameDirStartsWith("czeror") && !std::strcmp(pszName, "InitHUD"))
return ORIG_DispatchDirectUserMsg(0, iSize, pBuf);
else
return ORIG_DispatchDirectUserMsg(pszName, iSize, pBuf);
Expand Down Expand Up @@ -8066,7 +8066,7 @@ HOOK_DEF_0(HwDLL, void, __cdecl, R_DrawParticles)

HOOK_DEF_0(HwDLL, int, __cdecl, BUsesSDLInput)
{
if (ClientDLL::GetInstance().DoesGameDirMatch("bshift_cutsceneless") || CVars::bxt_fix_mouse_horizontal_limit.GetBool())
if (HF_DoesGameDirMatch("bshift_cutsceneless") || CVars::bxt_fix_mouse_horizontal_limit.GetBool())
return true;
else
return ORIG_BUsesSDLInput();
Expand Down Expand Up @@ -8271,7 +8271,7 @@ HOOK_DEF_1(HwDLL, void, __cdecl, LoadThisDll, const char*, szDllFilename)

bool is_failed = false;

static bool is_cstrike = ClientDLL::GetInstance().DoesGameDirMatch("cstrike");
static bool is_cstrike = HF_DoesGameDirMatch("cstrike");
if (is_cstrike)
{
#ifdef _WIN32
Expand Down
Loading

0 comments on commit 5c47c8a

Please sign in to comment.