2021-03-09 18:53:27 +01:00
|
|
|
#include "game/cinema.h"
|
|
|
|
#include "game/demo.h"
|
|
|
|
#include "game/game.h"
|
2021-03-10 23:47:59 +01:00
|
|
|
#include "game/gameflow.h"
|
2021-03-09 18:53:27 +01:00
|
|
|
#include "game/inv.h"
|
|
|
|
#include "game/savegame.h"
|
|
|
|
#include "game/setup.h"
|
2021-03-08 00:41:27 +01:00
|
|
|
#include "game/text.h"
|
|
|
|
#include "game/vars.h"
|
|
|
|
#include "specific/display.h"
|
|
|
|
#include "specific/file.h"
|
|
|
|
#include "specific/frontend.h"
|
2021-03-09 18:53:27 +01:00
|
|
|
#include "specific/init.h"
|
|
|
|
#include "specific/output.h"
|
|
|
|
#include "specific/shed.h"
|
|
|
|
#include "specific/shell.h"
|
|
|
|
#include "specific/sndpc.h"
|
2021-03-11 14:48:26 +01:00
|
|
|
#include "config.h"
|
2021-03-08 00:41:27 +01:00
|
|
|
#include "util.h"
|
|
|
|
#include <stdio.h>
|
2021-03-11 14:47:35 +01:00
|
|
|
#include <stdlib.h>
|
2021-03-08 00:41:27 +01:00
|
|
|
|
2021-03-11 15:47:48 +01:00
|
|
|
// NOTE: this function is inlined in original code
|
2021-03-10 21:39:29 +01:00
|
|
|
void S_ReadUserSettings()
|
2021-03-08 00:41:27 +01:00
|
|
|
{
|
|
|
|
FILE *fp = fopen("atiset.dat", "rb");
|
|
|
|
if (fp) {
|
|
|
|
fread(&OptionMusicVolume, sizeof(int16_t), 1, fp);
|
|
|
|
fread(&OptionSoundFXVolume, sizeof(int16_t), 1, fp);
|
|
|
|
fread(Layout[1], sizeof(int16_t), 13, fp);
|
|
|
|
fread(&AppSettings, sizeof(int32_t), 1, fp);
|
|
|
|
fread(&GameHiRes, sizeof(int32_t), 1, fp);
|
|
|
|
fread(&GameSizer, sizeof(double), 1, fp);
|
|
|
|
if (OptionMusicVolume) {
|
|
|
|
S_CDVolume(25 * OptionMusicVolume + 5);
|
|
|
|
} else {
|
|
|
|
S_CDVolume(0);
|
|
|
|
}
|
2021-03-09 18:53:27 +01:00
|
|
|
// NOTE: missing in original code
|
|
|
|
if (OptionSoundFXVolume) {
|
|
|
|
adjust_master_volume(6 * OptionSoundFXVolume + 3);
|
|
|
|
} else {
|
|
|
|
adjust_master_volume(0);
|
|
|
|
}
|
2021-03-08 00:41:27 +01:00
|
|
|
fclose(fp);
|
|
|
|
}
|
2021-03-10 21:39:29 +01:00
|
|
|
}
|
|
|
|
|
2021-03-11 15:47:48 +01:00
|
|
|
// NOTE: this function is inlined in original code
|
2021-03-10 21:39:29 +01:00
|
|
|
void S_WriteUserSettings()
|
|
|
|
{
|
|
|
|
FILE *fp = fopen("atiset.dat", "wb");
|
|
|
|
if (fp) {
|
|
|
|
fwrite(&OptionMusicVolume, sizeof(int16_t), 1, fp);
|
|
|
|
fwrite(&OptionSoundFXVolume, sizeof(int16_t), 1, fp);
|
|
|
|
fwrite(Layout[1], sizeof(int16_t), 13, fp);
|
|
|
|
fwrite(&AppSettings, sizeof(int32_t), 1, fp);
|
|
|
|
fwrite(&GameHiRes, sizeof(int32_t), 1, fp);
|
|
|
|
fwrite(&GameSizer, sizeof(double), 1, fp);
|
|
|
|
fclose(fp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GameMain()
|
|
|
|
{
|
|
|
|
DemoLevel = 1;
|
|
|
|
SoundIsActive = 1;
|
|
|
|
HiRes = 0;
|
|
|
|
GameHiRes = 0;
|
|
|
|
ScreenSizer = 1.0;
|
|
|
|
GameSizer = 1.0;
|
|
|
|
|
|
|
|
S_InitialiseSystem();
|
|
|
|
InitialiseStartInfo();
|
|
|
|
|
2021-03-10 23:47:59 +01:00
|
|
|
// NOTE: not present in original game
|
2021-03-10 21:39:29 +01:00
|
|
|
if (!GF_LoadScriptFile("Tomb1Main_gameflow.json5")) {
|
2021-03-10 23:47:59 +01:00
|
|
|
ShowFatalError("MAIN: unable to load script file");
|
|
|
|
return;
|
2021-03-10 21:39:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
S_FrontEndCheck();
|
|
|
|
S_ReadUserSettings();
|
2021-03-08 00:41:27 +01:00
|
|
|
|
|
|
|
if (IsHardwareRenderer) {
|
|
|
|
GameSizer = 1.0;
|
|
|
|
dword_45E960 = AppSettings;
|
|
|
|
}
|
|
|
|
HiRes = 0;
|
|
|
|
TempVideoAdjust(2, 1.0);
|
|
|
|
S_DisplayPicture("data\\eidospc");
|
|
|
|
sub_408E41();
|
2021-03-11 15:47:48 +01:00
|
|
|
S_Wait(60);
|
2021-03-08 00:41:27 +01:00
|
|
|
|
2021-03-11 14:48:26 +01:00
|
|
|
// NOTE: this check is missing in original game
|
|
|
|
if (!T1MConfig.disable_fmv) {
|
|
|
|
if (IsHardwareRenderer) {
|
|
|
|
HardwarePrepareFMV();
|
|
|
|
}
|
|
|
|
WinPlayFMV(FMV_CORE, 1);
|
|
|
|
WinPlayFMV(FMV_ESCAPE, 1);
|
|
|
|
WinPlayFMV(FMV_INTRO, 1);
|
2021-03-08 00:41:27 +01:00
|
|
|
if (!IsHardwareRenderer) {
|
|
|
|
HiRes = -1;
|
2021-03-11 14:48:26 +01:00
|
|
|
} else {
|
|
|
|
HardwareFMVDone();
|
|
|
|
if (!IsHardwareRenderer) {
|
|
|
|
HiRes = -1;
|
|
|
|
}
|
2021-03-08 00:41:27 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-11 14:47:35 +01:00
|
|
|
GameMemoryPointer = malloc(MALLOC_SIZE);
|
2021-03-08 00:41:27 +01:00
|
|
|
if (!GameMemoryPointer) {
|
|
|
|
S_ExitSystem("ERROR: Could not allocate enough memory");
|
2021-03-10 18:54:01 +01:00
|
|
|
return;
|
2021-03-08 00:41:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int32_t gf_option = GF_EXIT_TO_TITLE;
|
|
|
|
|
|
|
|
int8_t loop_continue = 1;
|
|
|
|
while (loop_continue) {
|
|
|
|
TempVideoRemove();
|
|
|
|
int32_t gf_direction = gf_option & ~((1 << 6) - 1);
|
|
|
|
int32_t gf_param = gf_option & ((1 << 6) - 1);
|
|
|
|
|
|
|
|
TRACE("%d %d", gf_direction >> 6, gf_param);
|
|
|
|
|
|
|
|
switch (gf_direction) {
|
|
|
|
case GF_STARTGAME:
|
|
|
|
if (!LevelIsValid(gf_param)) {
|
|
|
|
do {
|
|
|
|
++gf_param;
|
|
|
|
} while (gf_param <= LV_LEVEL10C && !LevelIsValid(gf_param));
|
|
|
|
}
|
|
|
|
if (gf_param == LV_TITLE) {
|
|
|
|
S_ExitSystem("MAIN: play title");
|
2021-03-10 18:54:01 +01:00
|
|
|
return;
|
2021-03-08 00:41:27 +01:00
|
|
|
}
|
|
|
|
gf_option = StartGame(gf_param);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GF_STARTCINE:
|
|
|
|
gf_option = StartCinematic(gf_param);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GF_STARTDEMO:
|
|
|
|
gf_option = StartDemo();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GF_LEVELCOMPLETE:
|
|
|
|
gf_option = LevelCompleteSequence(gf_param);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GF_EXIT_TO_TITLE:
|
|
|
|
T_InitPrint();
|
|
|
|
TempVideoAdjust(2, 1.0);
|
|
|
|
S_DisplayPicture("data\\titleh");
|
|
|
|
NoInputCount = 0;
|
|
|
|
if (TitleLoaded) {
|
|
|
|
S_CDPlay(2);
|
|
|
|
} else {
|
|
|
|
if (!InitialiseLevel(LV_TITLE)) {
|
|
|
|
gf_option = GF_EXITGAME;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
TitleLoaded = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
dword_45B940 = 0;
|
|
|
|
Display_Inventory(1);
|
|
|
|
dword_45B940 = 1;
|
|
|
|
|
|
|
|
S_FadeToBlack();
|
|
|
|
S_CDStop();
|
|
|
|
|
|
|
|
if (ResetFlag) {
|
|
|
|
ResetFlag = 0;
|
|
|
|
gf_option = GF_STARTDEMO;
|
|
|
|
} else if (InventoryChosen == O_PHOTO_OPTION) {
|
|
|
|
gf_option = GF_STARTGAME | LV_GYM;
|
|
|
|
} else {
|
|
|
|
if (InventoryChosen != O_PASSPORT_OPTION) {
|
|
|
|
gf_option = GF_EXITGAME;
|
|
|
|
}
|
|
|
|
if (InventoryExtraData[0]) {
|
|
|
|
if (InventoryExtraData[0] == 1) {
|
|
|
|
InitialiseStartInfo();
|
2021-03-08 02:15:14 +01:00
|
|
|
#ifdef T1M_FEAT_GAMEPLAY
|
|
|
|
SaveGame[0].bonus_flag = InventoryExtraData[1];
|
|
|
|
ModifyStartInfo(LV_FIRSTLEVEL);
|
|
|
|
#endif
|
2021-03-08 00:41:27 +01:00
|
|
|
gf_option = GF_STARTGAME | LV_FIRSTLEVEL;
|
|
|
|
} else {
|
|
|
|
gf_option = GF_EXITGAME;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
S_LoadGame(
|
|
|
|
SaveGame, sizeof(SAVEGAME_INFO), InventoryExtraData[1]);
|
|
|
|
gf_option = GF_STARTGAME | LV_CURRENT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GF_EXITGAME:
|
|
|
|
loop_continue = 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
sprintf(
|
|
|
|
StringToShow, "MAIN: Unknown request %x %d", gf_direction,
|
|
|
|
gf_param);
|
|
|
|
S_ExitSystem(StringToShow);
|
2021-03-10 18:54:01 +01:00
|
|
|
return;
|
2021-03-08 00:41:27 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-10 21:39:29 +01:00
|
|
|
S_WriteUserSettings();
|
2021-03-08 00:41:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void T1MInjectSpecificShell()
|
|
|
|
{
|
|
|
|
INJECT(0x00438410, GameMain);
|
|
|
|
}
|