TRX/src/main.c

183 lines
5.6 KiB
C
Raw Normal View History

2021-01-01 19:50:16 +01:00
#include <stdio.h>
2021-02-10 16:03:02 +01:00
#include <windows.h>
2021-01-01 19:50:16 +01:00
2021-02-08 11:30:21 +01:00
#include "json_utils.h"
2021-02-10 16:03:02 +01:00
#include "mod.h"
2021-02-08 01:18:57 +01:00
#include "util.h"
2021-01-01 19:50:16 +01:00
2021-02-21 23:27:13 +01:00
#include "game/bat.h"
2021-02-22 00:00:17 +01:00
#include "game/bear.h"
2021-02-22 00:31:16 +01:00
#include "game/box.h"
2021-02-13 14:58:42 +01:00
#include "game/control.h"
2021-02-20 22:41:08 +01:00
#include "game/demo.h"
2021-02-13 17:23:14 +01:00
#include "game/draw.h"
2021-02-14 16:07:16 +01:00
#include "game/effects.h"
2021-02-20 22:44:56 +01:00
#include "game/game.h"
2021-02-13 14:58:42 +01:00
#include "game/health.h"
#include "game/items.h"
#include "game/lara.h"
#include "game/lot.h"
2021-02-22 10:30:35 +01:00
#include "game/option.h"
2021-02-13 18:46:57 +01:00
#include "game/setup.h"
2021-02-14 16:07:16 +01:00
#include "game/text.h"
2021-02-17 23:59:55 +01:00
#include "specific/file.h"
#include "specific/init.h"
#include "specific/input.h"
#include "specific/output.h"
2021-02-13 14:58:42 +01:00
2021-01-01 19:50:16 +01:00
HINSTANCE hInstance = NULL;
2021-02-18 16:40:32 +01:00
static void Tomb1MInject()
2021-02-10 16:03:02 +01:00
{
2021-02-21 23:27:13 +01:00
Tomb1MInjectGameBat();
2021-02-22 00:00:17 +01:00
Tomb1MInjectGameBear();
2021-02-22 00:31:16 +01:00
Tomb1MInjectGameBox();
2021-02-18 16:40:32 +01:00
Tomb1MInjectGameControl();
2021-02-20 22:41:08 +01:00
Tomb1MInjectGameDemo();
2021-02-18 16:40:32 +01:00
Tomb1MInjectGameDraw();
Tomb1MInjectGameEffects();
Tomb1MInjectGameHealth();
Tomb1MInjectGameItems();
Tomb1MInjectGameLOT();
Tomb1MInjectGameLara();
2021-02-20 13:47:10 +01:00
Tomb1MInjectGameLaraFire();
2021-02-20 01:09:31 +01:00
Tomb1MInjectGameLaraGun1();
2021-02-20 11:33:32 +01:00
Tomb1MInjectGameLaraGun2();
2021-02-18 16:40:32 +01:00
Tomb1MInjectGameLaraMisc();
Tomb1MInjectGameLaraSurf();
Tomb1MInjectGameLaraSwim();
2021-02-22 10:30:35 +01:00
Tomb1MInjectGameOption();
2021-02-18 16:40:32 +01:00
Tomb1MInjectGameSetup();
Tomb1MInjectGameText();
Tomb1MInjectSpecificFile();
Tomb1MInjectSpecificGame();
Tomb1MInjectSpecificInit();
Tomb1MInjectSpecificInput();
Tomb1MInjectSpecificOutput();
2021-01-01 19:50:16 +01:00
}
2021-02-22 20:24:47 +01:00
static int8_t Tomb1MReadHealthbarLocationConfig(
json_value* root, const char* name, int8_t default_value)
{
const char* value_str = tr1m_json_get_string_value(root, name);
if (!value_str) {
return default_value;
}
if (!strcmp(value_str, "top-left")) {
2021-02-22 21:15:23 +01:00
return T1M_BL_VTOP | T1M_BL_HLEFT;
2021-02-22 20:24:47 +01:00
} else if (!strcmp(value_str, "top-center")) {
2021-02-22 21:15:23 +01:00
return T1M_BL_VTOP | T1M_BL_HCENTER;
2021-02-22 20:24:47 +01:00
} else if (!strcmp(value_str, "top-right")) {
2021-02-22 21:15:23 +01:00
return T1M_BL_VTOP | T1M_BL_HRIGHT;
2021-02-22 20:24:47 +01:00
} else if (!strcmp(value_str, "bottom-left")) {
2021-02-22 21:15:23 +01:00
return T1M_BL_VBOTTOM | T1M_BL_HLEFT;
2021-02-22 20:24:47 +01:00
} else if (!strcmp(value_str, "bottom-center")) {
2021-02-22 21:15:23 +01:00
return T1M_BL_VBOTTOM | T1M_BL_HCENTER;
2021-02-22 20:24:47 +01:00
} else if (!strcmp(value_str, "bottom-right")) {
2021-02-22 21:15:23 +01:00
return T1M_BL_VBOTTOM | T1M_BL_HRIGHT;
2021-02-22 20:24:47 +01:00
}
return default_value;
}
2021-02-18 16:40:32 +01:00
static int Tomb1MReadConfig()
2021-02-10 16:03:02 +01:00
{
2021-02-18 16:40:32 +01:00
FILE* fp = fopen("Tomb1Main.json", "rb");
2021-02-08 11:30:21 +01:00
if (!fp) {
return 0;
}
fseek(fp, 0, SEEK_END);
int cfg_size = ftell(fp);
fseek(fp, 0, SEEK_SET);
2021-02-10 16:03:02 +01:00
char* cfg_data = malloc(cfg_size);
2021-02-08 11:50:39 +01:00
if (!cfg_data) {
fclose(fp);
return 0;
}
2021-02-08 11:30:21 +01:00
fread(cfg_data, 1, cfg_size, fp);
2021-02-08 11:50:39 +01:00
fclose(fp);
2021-02-08 11:30:21 +01:00
2021-02-10 16:03:02 +01:00
json_value* json = json_parse((const json_char*)cfg_data, cfg_size);
2021-02-08 11:30:21 +01:00
2021-02-22 21:06:28 +01:00
T1MConfig.disable_healing_between_levels =
2021-02-10 16:03:02 +01:00
tr1m_json_get_boolean_value(json, "disable_healing_between_levels");
2021-02-22 21:06:28 +01:00
T1MConfig.disable_medpacks =
2021-02-10 16:03:02 +01:00
tr1m_json_get_boolean_value(json, "disable_medpacks");
2021-02-22 21:06:28 +01:00
T1MConfig.disable_magnums =
2021-02-13 19:00:58 +01:00
tr1m_json_get_boolean_value(json, "disable_magnums");
2021-02-22 21:06:28 +01:00
T1MConfig.disable_uzis = tr1m_json_get_boolean_value(json, "disable_uzis");
T1MConfig.disable_shotgun =
2021-02-13 19:00:58 +01:00
tr1m_json_get_boolean_value(json, "disable_shotgun");
2021-02-22 21:06:28 +01:00
T1MConfig.enable_red_healthbar =
2021-02-10 23:59:11 +01:00
tr1m_json_get_boolean_value(json, "enable_red_healthbar");
2021-02-22 21:06:28 +01:00
T1MConfig.enable_enemy_healthbar =
2021-02-10 22:31:06 +01:00
tr1m_json_get_boolean_value(json, "enable_enemy_healthbar");
2021-02-22 21:06:28 +01:00
T1MConfig.enable_enhanced_look =
tr1m_json_get_boolean_value(json, "enable_enhanced_look");
2021-02-22 21:06:28 +01:00
T1MConfig.enable_enhanced_ui =
2021-02-14 20:20:53 +01:00
tr1m_json_get_boolean_value(json, "enable_enhanced_ui");
2021-02-22 21:06:28 +01:00
T1MConfig.enable_shotgun_flash =
2021-02-20 01:22:23 +01:00
tr1m_json_get_boolean_value(json, "enable_shotgun_flash");
2021-02-22 21:06:28 +01:00
T1MConfig.enable_cheats =
2021-02-21 17:53:09 +01:00
tr1m_json_get_boolean_value(json, "enable_cheats");
const char* healthbar_showing_mode =
tr1m_json_get_string_value(json, "healthbar_showing_mode");
2021-02-22 21:15:23 +01:00
T1MConfig.healthbar_showing_mode = T1M_BSM_DEFAULT;
if (healthbar_showing_mode) {
if (!strcmp(healthbar_showing_mode, "flashing")) {
2021-02-22 21:15:23 +01:00
T1MConfig.healthbar_showing_mode = T1M_BSM_FLASHING;
} else if (!strcmp(healthbar_showing_mode, "always")) {
2021-02-22 21:15:23 +01:00
T1MConfig.healthbar_showing_mode = T1M_BSM_ALWAYS;
}
}
2021-02-22 21:06:28 +01:00
T1MConfig.healthbar_location = Tomb1MReadHealthbarLocationConfig(
2021-02-22 21:15:23 +01:00
json, "healthbar_location", T1M_BL_VTOP | T1M_BL_HLEFT);
2021-02-22 21:06:28 +01:00
T1MConfig.airbar_location = Tomb1MReadHealthbarLocationConfig(
2021-02-22 21:15:23 +01:00
json, "airbar_location", T1M_BL_VTOP | T1M_BL_HRIGHT);
2021-02-22 21:06:28 +01:00
T1MConfig.enemy_healthbar_location = Tomb1MReadHealthbarLocationConfig(
2021-02-22 21:15:23 +01:00
json, "enemy_healthbar_location", T1M_BL_VBOTTOM | T1M_BL_HLEFT);
2021-02-22 20:24:47 +01:00
2021-02-22 21:06:28 +01:00
T1MConfig.enable_numeric_keys =
2021-02-13 21:32:42 +01:00
tr1m_json_get_boolean_value(json, "enable_numeric_keys");
2021-02-22 21:06:28 +01:00
T1MConfig.fix_end_of_level_freeze =
2021-02-10 16:03:02 +01:00
tr1m_json_get_boolean_value(json, "fix_end_of_level_freeze");
2021-02-22 21:06:28 +01:00
T1MConfig.fix_tihocan_secret_sound =
tr1m_json_get_boolean_value(json, "fix_tihocan_secret_sound");
2021-02-22 21:06:28 +01:00
T1MConfig.fix_pyramid_secret_trigger =
2021-02-20 18:48:05 +01:00
tr1m_json_get_boolean_value(json, "fix_pyramid_secret_trigger");
2021-02-22 21:06:28 +01:00
T1MConfig.fix_hardcoded_secret_counts =
2021-02-20 17:17:46 +01:00
tr1m_json_get_boolean_value(json, "fix_hardcoded_secret_counts");
2021-02-08 11:30:21 +01:00
json_value_free(json);
free(cfg_data);
return 1;
}
2021-02-10 16:03:02 +01:00
BOOL APIENTRY DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
2021-01-01 19:50:16 +01:00
switch (fdwReason) {
2021-02-10 16:03:02 +01:00
case DLL_PROCESS_ATTACH:
2021-02-18 16:40:32 +01:00
freopen("./Tomb1Main.log", "w", stdout);
Tomb1MReadConfig();
2021-02-10 16:03:02 +01:00
TRACE("Attached");
hInstance = hinstDLL;
2021-02-18 16:40:32 +01:00
Tomb1MInject();
2021-02-10 16:03:02 +01:00
break;
2021-01-01 19:50:16 +01:00
2021-02-10 16:03:02 +01:00
case DLL_PROCESS_DETACH:
TRACE("Detached");
break;
2021-01-01 19:50:16 +01:00
2021-02-10 16:03:02 +01:00
case DLL_THREAD_ATTACH:
break;
2021-01-01 19:50:16 +01:00
2021-02-10 16:03:02 +01:00
case DLL_THREAD_DETACH:
break;
2021-01-01 19:50:16 +01:00
}
return TRUE;
}