Added game by game detection to help fix certain issues with specific games
This commit is contained in:
parent
a7b30ca7f8
commit
c7ee48dfa6
2
Makefile
2
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)
|
CFLAGS=-Wall -Wextra -Wno-write-strings -m32 -fPIC $(INCLUDES)
|
||||||
LDFLAGS=-lm
|
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
|
BIN=libhlcheat.so
|
||||||
|
|
||||||
.PHONY: clean all inject
|
.PHONY: clean all inject
|
||||||
|
|
|
@ -0,0 +1,68 @@
|
||||||
|
#include "include/game_detection.h"
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
|
@ -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
|
28
src/main.c
28
src/main.c
|
@ -8,6 +8,7 @@
|
||||||
#include "include/cvars.h"
|
#include "include/cvars.h"
|
||||||
#include "include/hooks.h"
|
#include "include/hooks.h"
|
||||||
#include "include/util.h"
|
#include "include/util.h"
|
||||||
|
#include "include/game_detection.h"
|
||||||
|
|
||||||
static bool loaded = false;
|
static bool loaded = false;
|
||||||
|
|
||||||
|
@ -40,6 +41,33 @@ void load(void) {
|
||||||
this_game_id = get_cur_game();
|
this_game_id = get_cur_game();
|
||||||
|
|
||||||
i_engine->pfnClientCmd("echo \"goldsource-cheat loaded successfully!\"");
|
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;
|
loaded = true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue