2021-02-28 21:25:35 +01:00
|
|
|
#include "config.h"
|
|
|
|
#include "game/const.h"
|
|
|
|
#include "json_utils.h"
|
|
|
|
#include "util.h"
|
2021-02-22 21:20:50 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2021-02-22 21:36:00 +01:00
|
|
|
#define Q(x) #x
|
|
|
|
#define QUOTE(x) Q(x)
|
|
|
|
#define READ_BOOL(OPT) \
|
|
|
|
do { \
|
|
|
|
T1MConfig.OPT = JSONGetBooleanValue(json, QUOTE(OPT)); \
|
|
|
|
} while (0)
|
|
|
|
|
2021-02-22 22:29:13 +01:00
|
|
|
static int8_t ReadBarShowingMode(struct json_value_s* root, const char* name)
|
2021-02-22 21:20:50 +01:00
|
|
|
{
|
2021-02-22 21:26:01 +01:00
|
|
|
const char* value_str = JSONGetStringValue(root, name);
|
2021-02-22 21:20:50 +01:00
|
|
|
if (!value_str) {
|
|
|
|
return T1M_BSM_DEFAULT;
|
2021-02-28 09:28:25 +01:00
|
|
|
} else if (!strcmp(value_str, "flashing-or-default")) {
|
|
|
|
return T1M_BSM_FLASHING_OR_DEFAULT;
|
|
|
|
} else if (!strcmp(value_str, "flashing-only")) {
|
|
|
|
return T1M_BSM_FLASHING_ONLY;
|
2021-02-22 21:20:50 +01:00
|
|
|
} else if (!strcmp(value_str, "always")) {
|
|
|
|
return T1M_BSM_ALWAYS;
|
2021-02-27 15:40:52 +01:00
|
|
|
} else if (!strcmp(value_str, "never")) {
|
|
|
|
return T1M_BSM_NEVER;
|
2021-02-22 21:20:50 +01:00
|
|
|
}
|
|
|
|
return T1M_BSM_DEFAULT;
|
|
|
|
}
|
|
|
|
|
2021-02-22 23:21:35 +01:00
|
|
|
static int8_t ReadBarColorConfig(
|
|
|
|
struct json_value_s* root, const char* name, int8_t default_value)
|
|
|
|
{
|
|
|
|
const char* value_str = JSONGetStringValue(root, name);
|
|
|
|
if (!value_str) {
|
|
|
|
return default_value;
|
|
|
|
} else if (!strcmp(value_str, "gold")) {
|
|
|
|
return T1M_BC_GOLD;
|
|
|
|
} else if (!strcmp(value_str, "blue")) {
|
|
|
|
return T1M_BC_BLUE;
|
|
|
|
} else if (!strcmp(value_str, "grey")) {
|
|
|
|
return T1M_BC_GREY;
|
|
|
|
} else if (!strcmp(value_str, "red")) {
|
|
|
|
return T1M_BC_RED;
|
|
|
|
} else if (!strcmp(value_str, "silver")) {
|
|
|
|
return T1M_BC_SILVER;
|
|
|
|
} else if (!strcmp(value_str, "green")) {
|
|
|
|
return T1M_BC_GREEN;
|
|
|
|
} else if (!strcmp(value_str, "gold2")) {
|
|
|
|
return T1M_BC_GOLD2;
|
|
|
|
} else if (!strcmp(value_str, "blue2")) {
|
|
|
|
return T1M_BC_BLUE2;
|
|
|
|
} else if (!strcmp(value_str, "pink")) {
|
|
|
|
return T1M_BC_PINK;
|
|
|
|
}
|
|
|
|
return default_value;
|
|
|
|
}
|
|
|
|
|
2021-02-22 22:29:13 +01:00
|
|
|
static int8_t ReadBarLocationConfig(
|
|
|
|
struct json_value_s* root, const char* name, int8_t default_value)
|
2021-02-22 21:20:50 +01:00
|
|
|
{
|
2021-02-22 21:26:01 +01:00
|
|
|
const char* value_str = JSONGetStringValue(root, name);
|
2021-02-22 21:20:50 +01:00
|
|
|
if (!value_str) {
|
|
|
|
return default_value;
|
|
|
|
} else if (!strcmp(value_str, "top-left")) {
|
2021-02-22 22:50:59 +01:00
|
|
|
return T1M_BL_TOP_LEFT;
|
2021-02-22 21:20:50 +01:00
|
|
|
} else if (!strcmp(value_str, "top-center")) {
|
2021-02-22 22:50:59 +01:00
|
|
|
return T1M_BL_TOP_CENTER;
|
2021-02-22 21:20:50 +01:00
|
|
|
} else if (!strcmp(value_str, "top-right")) {
|
2021-02-22 22:50:59 +01:00
|
|
|
return T1M_BL_TOP_RIGHT;
|
2021-02-22 21:20:50 +01:00
|
|
|
} else if (!strcmp(value_str, "bottom-left")) {
|
2021-02-22 22:50:59 +01:00
|
|
|
return T1M_BL_BOTTOM_LEFT;
|
2021-02-22 21:20:50 +01:00
|
|
|
} else if (!strcmp(value_str, "bottom-center")) {
|
2021-02-22 22:50:59 +01:00
|
|
|
return T1M_BL_BOTTOM_CENTER;
|
2021-02-22 21:20:50 +01:00
|
|
|
} else if (!strcmp(value_str, "bottom-right")) {
|
2021-02-22 22:50:59 +01:00
|
|
|
return T1M_BL_BOTTOM_RIGHT;
|
2021-02-22 21:20:50 +01:00
|
|
|
}
|
|
|
|
return default_value;
|
|
|
|
}
|
|
|
|
|
|
|
|
int T1MReadConfig()
|
|
|
|
{
|
|
|
|
FILE* fp = fopen("Tomb1Main.json", "rb");
|
|
|
|
if (!fp) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
fseek(fp, 0, SEEK_END);
|
|
|
|
int cfg_size = ftell(fp);
|
|
|
|
fseek(fp, 0, SEEK_SET);
|
|
|
|
|
|
|
|
char* cfg_data = malloc(cfg_size);
|
|
|
|
if (!cfg_data) {
|
|
|
|
fclose(fp);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
fread(cfg_data, 1, cfg_size, fp);
|
|
|
|
fclose(fp);
|
|
|
|
|
2021-02-22 22:29:13 +01:00
|
|
|
struct json_value_s* json = json_parse_ex(
|
|
|
|
cfg_data, cfg_size, json_parse_flags_allow_json5, NULL, NULL, NULL);
|
2021-02-22 21:20:50 +01:00
|
|
|
|
2021-02-22 21:36:00 +01:00
|
|
|
READ_BOOL(disable_healing_between_levels);
|
|
|
|
READ_BOOL(disable_medpacks);
|
|
|
|
READ_BOOL(disable_magnums);
|
|
|
|
READ_BOOL(disable_uzis);
|
|
|
|
READ_BOOL(disable_shotgun);
|
|
|
|
READ_BOOL(enable_enemy_healthbar);
|
|
|
|
READ_BOOL(enable_enhanced_look);
|
|
|
|
READ_BOOL(enable_enhanced_ui);
|
|
|
|
READ_BOOL(enable_shotgun_flash);
|
|
|
|
READ_BOOL(enable_cheats);
|
|
|
|
READ_BOOL(enable_numeric_keys);
|
2021-02-27 15:02:35 +01:00
|
|
|
READ_BOOL(enable_tr3_sidesteps);
|
2021-02-27 16:31:04 +01:00
|
|
|
READ_BOOL(enable_braid);
|
2021-02-27 14:46:03 +01:00
|
|
|
READ_BOOL(fix_key_triggers);
|
2021-02-22 21:36:00 +01:00
|
|
|
READ_BOOL(fix_end_of_level_freeze);
|
|
|
|
READ_BOOL(fix_tihocan_secret_sound);
|
|
|
|
READ_BOOL(fix_pyramid_secret_trigger);
|
|
|
|
READ_BOOL(fix_hardcoded_secret_counts);
|
2021-02-27 21:10:43 +01:00
|
|
|
READ_BOOL(fix_illegal_gun_equip);
|
2021-02-28 21:25:35 +01:00
|
|
|
READ_BOOL(fov_vertical);
|
2021-02-22 21:20:50 +01:00
|
|
|
|
|
|
|
T1MConfig.healthbar_showing_mode =
|
|
|
|
ReadBarShowingMode(json, "healthbar_showing_mode");
|
2021-02-27 15:41:17 +01:00
|
|
|
T1MConfig.airbar_showing_mode =
|
|
|
|
ReadBarShowingMode(json, "airbar_showing_mode");
|
2021-02-22 21:20:50 +01:00
|
|
|
|
2021-02-22 22:50:59 +01:00
|
|
|
T1MConfig.healthbar_location =
|
|
|
|
ReadBarLocationConfig(json, "healthbar_location", T1M_BL_TOP_LEFT);
|
|
|
|
T1MConfig.airbar_location =
|
|
|
|
ReadBarLocationConfig(json, "airbar_location", T1M_BL_TOP_RIGHT);
|
2021-02-22 21:20:50 +01:00
|
|
|
T1MConfig.enemy_healthbar_location = ReadBarLocationConfig(
|
2021-02-22 22:50:59 +01:00
|
|
|
json, "enemy_healthbar_location", T1M_BL_BOTTOM_LEFT);
|
2021-02-22 21:20:50 +01:00
|
|
|
|
2021-02-22 23:21:35 +01:00
|
|
|
T1MConfig.healthbar_color =
|
|
|
|
ReadBarColorConfig(json, "healthbar_color", T1M_BC_RED);
|
|
|
|
T1MConfig.airbar_color =
|
|
|
|
ReadBarColorConfig(json, "airbar_color", T1M_BC_BLUE);
|
|
|
|
T1MConfig.enemy_healthbar_color =
|
|
|
|
ReadBarColorConfig(json, "enemy_healthbar_color", T1M_BC_GREY);
|
|
|
|
|
2021-02-28 21:25:35 +01:00
|
|
|
T1MConfig.fov_value = JSONGetIntegerValue(json, "fov_value");
|
|
|
|
if (!T1MConfig.fov_value) {
|
|
|
|
T1MConfig.fov_value = GAME_FOV;
|
|
|
|
}
|
|
|
|
CLAMP(T1MConfig.fov_value, 30, 255);
|
|
|
|
|
2021-02-22 22:29:13 +01:00
|
|
|
free(json);
|
2021-02-22 21:20:50 +01:00
|
|
|
free(cfg_data);
|
|
|
|
return 1;
|
|
|
|
}
|