Skip to content

Commit

Permalink
override detail levels in config
Browse files Browse the repository at this point in the history
  • Loading branch information
fgsfdsfgs committed Feb 15, 2021
1 parent 9e68f3f commit 72bd793
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
12 changes: 12 additions & 0 deletions config.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,21 @@
CONFIG_VAR_INT(disable_mipmaps); \
CONFIG_VAR_INT(language); \
CONFIG_VAR_INT(crouch_toggle); \
CONFIG_VAR_INT(character_shadows); \
CONFIG_VAR_INT(drop_highest_lod); \
CONFIG_VAR_FLOAT(decal_limit); \
CONFIG_VAR_FLOAT(debris_limit); \
CONFIG_VAR_STR(mod_file);

Config config;

static inline void parse_var(const char *name, const char *value) {
#define CONFIG_VAR_INT(var) if (!strcmp(name, #var)) { config.var = atoi(value); return; }
#define CONFIG_VAR_FLOAT(var) if (!strcmp(name, #var)) { config.var = atof(value); return; }
#define CONFIG_VAR_STR(var) if (!strcmp(name, #var)) { strlcpy(config.var, value, sizeof(config.var)); return; }
CONFIG_VARS
#undef CONFIG_VAR_INT
#undef CONFIG_VAR_FLOAT
#undef CONFIG_VAR_STR
}

Expand All @@ -48,6 +54,10 @@ int read_config(const char *file) {
config.disable_mipmaps = 0;
config.language = 0; // english
config.crouch_toggle = 1;
config.character_shadows = 1; // 1 - one blob; 2 - foot shadows
config.drop_highest_lod = 1; // does this even do anything?
config.decal_limit = 0.33f;
config.debris_limit = 0.33f;

FILE *f = fopen(file, "r");
if (f == NULL)
Expand Down Expand Up @@ -87,9 +97,11 @@ int write_config(const char *file) {
return -1;

#define CONFIG_VAR_INT(var) fprintf(f, "%s %d\n", #var, config.var)
#define CONFIG_VAR_FLOAT(var) fprintf(f, "%s %g\n", #var, config.var)
#define CONFIG_VAR_STR(var) if (config.var[0]) fprintf(f, "%s %s\n", #var, config.var)
CONFIG_VARS
#undef CONFIG_VAR_INT
#undef CONFIG_VAR_FLOAT
#undef CONFIG_VAR_STR

fclose(f);
Expand Down
4 changes: 4 additions & 0 deletions config.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ typedef struct {
int disable_mipmaps;
int language;
int crouch_toggle;
int character_shadows;
int drop_highest_lod;
float decal_limit;
float debris_limit;
char mod_file[0x100];
} Config;

Expand Down
23 changes: 21 additions & 2 deletions hooks/game.c
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,22 @@ int R_File_setFileSystemRoot(void *this, const char *root) {
return res;
}

int X_DetailLevel_getCharacterShadows(void) {
return config.character_shadows;
}

int X_DetailLevel_getDropHighestLOD(void) {
return config.drop_highest_lod;
}

float X_DetailLevel_getDecalLimitMultiplier(void) {
return config.decal_limit;
}

float X_DetailLevel_getDebrisProjectileLimitMultiplier(void) {
return config.debris_limit;
}

void patch_game(void) {
// make it crash in an obvious location when it calls JNI methods
hook_thumb(so_find_addr("_Z24NVThreadGetCurrentJNIEnvv"), (uintptr_t)0x1337);
Expand Down Expand Up @@ -392,8 +408,11 @@ void patch_game(void) {

hook_thumb(so_find_addr("_Z15ExitAndroidGamev"), (uintptr_t)ExitAndroidGame);

// enable shadows
hook_thumb(so_find_addr("_ZN13X_DetailLevel19getCharacterShadowsEv"), (uintptr_t)ret1);
// hook detail level getters to our own settings
hook_thumb(so_find_addr("_ZN13X_DetailLevel19getCharacterShadowsEv"), (uintptr_t)X_DetailLevel_getCharacterShadows);
hook_thumb(so_find_addr("_ZN13X_DetailLevel34getDebrisProjectileLimitMultiplierEv"), (uintptr_t)X_DetailLevel_getDebrisProjectileLimitMultiplier);
hook_thumb(so_find_addr("_ZN13X_DetailLevel23getDecalLimitMultiplierEv"), (uintptr_t)X_DetailLevel_getDecalLimitMultiplier);
hook_thumb(so_find_addr("_ZN13X_DetailLevel13dropHighesLODEv"), (uintptr_t)X_DetailLevel_getDropHighestLOD);

// crouch toggle
if (config.crouch_toggle) {
Expand Down

0 comments on commit 72bd793

Please sign in to comment.