From c7ee48dfa6b1aae259af518a1fe3ef409039eca4 Mon Sep 17 00:00:00 2001 From: Wizzard <25581244+Wizzard@users.noreply.toomuchslop.com> Date: Tue, 19 Sep 2023 13:16:13 -0400 Subject: [PATCH] Added game by game detection to help fix certain issues with specific games --- Makefile | 2 +- src/game_detection.c | 68 ++++++++++++++++++++++++++++++++++++ src/include/game_detection.h | 17 +++++++++ src/main.c | 28 +++++++++++++++ 4 files changed, 114 insertions(+), 1 deletion(-) create mode 100644 src/game_detection.c create mode 100644 src/include/game_detection.h diff --git a/Makefile b/Makefile index 04fc3f6..cfb7a84 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ INCLUDES=-Isrc/include/sdk/common -Isrc/include/sdk/public -Isrc/include/sdk/pm_ CFLAGS=-Wall -Wextra -Wno-write-strings -m32 -fPIC $(INCLUDES) LDFLAGS=-lm -OBJS=obj/main.c.o obj/globals.c.o obj/cvars.c.o obj/hooks.c.o obj/detour.c.o obj/util.c.o obj/features/movement.c.o obj/features/esp.c.o obj/features/chams.c.o obj/features/aim.c.o obj/features/misc.c.o +OBJS=obj/main.c.o obj/globals.c.o obj/cvars.c.o obj/hooks.c.o obj/detour.c.o obj/util.c.o obj/features/movement.c.o obj/features/esp.c.o obj/features/chams.c.o obj/features/aim.c.o obj/features/misc.c.o obj/game_detection.c.o BIN=libhlcheat.so .PHONY: clean all inject diff --git a/src/game_detection.c b/src/game_detection.c new file mode 100644 index 0000000..31c2eb4 --- /dev/null +++ b/src/game_detection.c @@ -0,0 +1,68 @@ +#include "include/game_detection.h" +#include +#include + +static GameType current_game = GAME_UNKNOWN; + +GameType get_current_game(void) { + if (current_game != GAME_UNKNOWN) { + return current_game; + } + + FILE *fp = fopen("/proc/self/cmdline", "r"); + if (fp) { + char buf[1024]; + size_t size = fread(buf, sizeof(char), sizeof(buf) - 1, fp); + fclose(fp); + + if (size > 0) { + buf[size] = '\0'; + + char *gameTypeToken = NULL; + char *steamToken = NULL; + + int tokensFound = 0; + + for (char *token = buf; token < buf + size; token += strlen(token) + 1) { + tokensFound++; + + if (strcmp(token, "-game") == 0) { + gameTypeToken = token + strlen(token) + 1; + } else if (strcmp(token, "-steam") == 0) { + steamToken = token; + } + } + + if (gameTypeToken) { + if (strcmp(gameTypeToken, "cstrike") == 0) { + current_game = GAME_CS16; + } else if (strcmp(gameTypeToken, "dod") == 0) { + current_game = GAME_DAY_OF_DEFEAT; + } else if (strcmp(gameTypeToken, "tfc") == 0) { + current_game = GAME_TFC; + } + } else if (steamToken && tokensFound == 2) { + // If only `-steam` is found and no `-game`, with only two tokens, assume it's Half-Life 1 + current_game = GAME_HALFLIFE; + } + } + } + + return current_game; +} + +int IsCS16(void) { + return get_current_game() == GAME_CS16; +} + +int IsHalfLife(void) { + return get_current_game() == GAME_HALFLIFE; +} + +int IsDayOfDefeat(void) { + return get_current_game() == GAME_DAY_OF_DEFEAT; +} + +int IsTFC(void) { + return get_current_game() == GAME_TFC; +} diff --git a/src/include/game_detection.h b/src/include/game_detection.h new file mode 100644 index 0000000..3de898f --- /dev/null +++ b/src/include/game_detection.h @@ -0,0 +1,17 @@ +#ifndef _GAME_DETECT_H_ +#define _GAME_DETECT_H_ + +typedef enum { + GAME_UNKNOWN = 0, + GAME_HALFLIFE, + GAME_CS16, + GAME_TFC, + GAME_DAY_OF_DEFEAT +} GameType; + +GameType get_current_game(void); +int IsCS16(void); +int IsHalfLife(void); +int IsDayOfDefeat(void); + +#endif diff --git a/src/main.c b/src/main.c index 2646507..4bf157c 100644 --- a/src/main.c +++ b/src/main.c @@ -8,6 +8,7 @@ #include "include/cvars.h" #include "include/hooks.h" #include "include/util.h" +#include "include/game_detection.h" static bool loaded = false; @@ -40,6 +41,33 @@ void load(void) { this_game_id = get_cur_game(); i_engine->pfnClientCmd("echo \"goldsource-cheat loaded successfully!\""); + i_engine->pfnClientCmd("echo \"Deadzone rulez!\""); + i_engine->pfnClientCmd("echo \"https://git.deadzone.lol/Wizzard/goldsource-cheat\""); + + + GameType game = get_current_game(); + switch(game) { + case GAME_HALFLIFE: + i_engine->pfnClientCmd("echo \"Detected Game: Half-Life 1\""); + break; + case GAME_CS16: + i_engine->pfnClientCmd("echo \"Detected Game: Counter-Strike 1.6\""); + break; + case GAME_DAY_OF_DEFEAT: + i_engine->pfnClientCmd("echo \"Detected Game: Day of Defeat\""); + break; + case GAME_TFC: + i_engine->pfnClientCmd("echo \"Detected Game: Team Fortress Classic\""); + break; + default: + i_engine->pfnClientCmd("echo \"Detected Game: Unknown Game\""); + break; + } + + + return; + + loaded = true; }