2021-03-14 13:50:30 +01:00
|
|
|
#include "specific/shell.h"
|
|
|
|
|
|
|
|
#include "game/const.h"
|
2021-03-09 18:53:27 +01:00
|
|
|
#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"
|
2021-03-17 13:22:04 +01:00
|
|
|
#include "game/option.h"
|
2021-03-09 18:53:27 +01:00
|
|
|
#include "game/savegame.h"
|
|
|
|
#include "game/setup.h"
|
2021-03-08 00:41:27 +01:00
|
|
|
#include "game/text.h"
|
2021-03-14 13:50:30 +01:00
|
|
|
#include "game/types.h"
|
2021-03-08 00:41:27 +01:00
|
|
|
#include "game/vars.h"
|
|
|
|
#include "specific/display.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/sndpc.h"
|
2021-03-14 13:50:30 +01:00
|
|
|
|
2021-03-18 16:14:28 +01:00
|
|
|
#include "filesystem.h"
|
2021-03-08 00:41:27 +01:00
|
|
|
#include "util.h"
|
2021-03-14 13:50:30 +01:00
|
|
|
|
|
|
|
#include <stdint.h>
|
2021-03-08 00:41:27 +01:00
|
|
|
#include <stdio.h>
|
2021-03-11 14:47:35 +01:00
|
|
|
#include <stdlib.h>
|
2021-03-08 00:41:27 +01:00
|
|
|
|
2021-03-10 21:39:29 +01:00
|
|
|
void S_ReadUserSettings()
|
2021-03-08 00:41:27 +01:00
|
|
|
{
|
2021-03-18 16:14:28 +01:00
|
|
|
MYFILE *fp = FileOpen(UserSettingsPath, FILE_OPEN_READ);
|
2021-03-14 15:33:00 +01:00
|
|
|
if (!fp) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-03-18 16:14:28 +01:00
|
|
|
FileRead(&OptionMusicVolume, sizeof(int16_t), 1, fp);
|
|
|
|
FileRead(&OptionSoundFXVolume, sizeof(int16_t), 1, fp);
|
|
|
|
FileRead(Layout[1], sizeof(int16_t), 13, fp);
|
|
|
|
FileRead(&AppSettings, sizeof(int32_t), 1, fp);
|
|
|
|
FileRead(&GameHiRes, sizeof(int32_t), 1, fp);
|
|
|
|
FileRead(&GameSizer, sizeof(double), 1, fp);
|
|
|
|
FileRead(&IConfig, sizeof(int32_t), 1, fp);
|
2021-03-14 15:33:00 +01:00
|
|
|
|
2021-03-17 13:22:04 +01:00
|
|
|
DefaultConflict();
|
|
|
|
|
2021-03-14 15:33:00 +01:00
|
|
|
if (OptionMusicVolume) {
|
|
|
|
S_CDVolume(25 * OptionMusicVolume + 5);
|
|
|
|
} else {
|
|
|
|
S_CDVolume(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (OptionSoundFXVolume) {
|
|
|
|
adjust_master_volume(6 * OptionSoundFXVolume + 3);
|
|
|
|
} else {
|
|
|
|
adjust_master_volume(0);
|
2021-03-08 00:41:27 +01:00
|
|
|
}
|
2021-03-14 15:33:00 +01:00
|
|
|
|
2021-03-18 16:14:28 +01:00
|
|
|
FileClose(fp);
|
2021-03-10 21:39:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void S_WriteUserSettings()
|
|
|
|
{
|
2021-03-18 16:14:28 +01:00
|
|
|
MYFILE *fp = FileOpen(UserSettingsPath, FILE_OPEN_WRITE);
|
2021-03-14 15:33:00 +01:00
|
|
|
if (!fp) {
|
|
|
|
return;
|
2021-03-10 21:39:29 +01:00
|
|
|
}
|
2021-03-18 16:14:28 +01:00
|
|
|
FileWrite(&OptionMusicVolume, sizeof(int16_t), 1, fp);
|
|
|
|
FileWrite(&OptionSoundFXVolume, sizeof(int16_t), 1, fp);
|
|
|
|
FileWrite(Layout[1], sizeof(int16_t), 13, fp);
|
|
|
|
FileWrite(&AppSettings, sizeof(int32_t), 1, fp);
|
|
|
|
FileWrite(&GameHiRes, sizeof(int32_t), 1, fp);
|
|
|
|
FileWrite(&GameSizer, sizeof(double), 1, fp);
|
|
|
|
FileWrite(&IConfig, sizeof(int32_t), 1, fp);
|
|
|
|
FileClose(fp);
|
2021-03-10 21:39:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void GameMain()
|
|
|
|
{
|
|
|
|
SoundIsActive = 1;
|
|
|
|
HiRes = 0;
|
|
|
|
GameHiRes = 0;
|
|
|
|
ScreenSizer = 1.0;
|
|
|
|
GameSizer = 1.0;
|
|
|
|
|
|
|
|
S_InitialiseSystem();
|
|
|
|
|
2021-03-18 15:08:25 +01:00
|
|
|
if (!GF_LoadScriptFile("cfg/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
|
|
|
}
|
|
|
|
|
2021-03-12 17:02:41 +01:00
|
|
|
InitialiseStartInfo();
|
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-17 00:24:00 +01:00
|
|
|
if (IsHardwareRenderer) {
|
|
|
|
HardwarePrepareFMV();
|
|
|
|
}
|
|
|
|
WinPlayFMV(FMV_CORE, 1);
|
|
|
|
WinPlayFMV(FMV_ESCAPE, 1);
|
|
|
|
WinPlayFMV(FMV_INTRO, 1);
|
|
|
|
if (!IsHardwareRenderer) {
|
|
|
|
HiRes = -1;
|
|
|
|
} else {
|
|
|
|
HardwareFMVDone();
|
2021-03-08 00:41:27 +01:00
|
|
|
if (!IsHardwareRenderer) {
|
|
|
|
HiRes = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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);
|
2021-03-12 17:02:41 +01:00
|
|
|
TRACE("%d %d", gf_direction, gf_param);
|
2021-03-08 00:41:27 +01:00
|
|
|
|
|
|
|
switch (gf_direction) {
|
2021-03-11 23:21:18 +01:00
|
|
|
case GF_START_GAME:
|
2021-03-12 17:02:41 +01:00
|
|
|
gf_option = GF_InterpretSequence(gf_param, GFL_NORMAL);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GF_START_SAVED_GAME:
|
2021-03-13 17:51:46 +01:00
|
|
|
S_LoadGame(&SaveGame, gf_param);
|
|
|
|
gf_option = GF_InterpretSequence(SaveGame.current_level, GFL_SAVED);
|
2021-03-08 00:41:27 +01:00
|
|
|
break;
|
|
|
|
|
2021-03-11 23:21:18 +01:00
|
|
|
case GF_START_CINE:
|
2021-03-14 15:38:11 +01:00
|
|
|
gf_option = GF_InterpretSequence(gf_param, GFL_CUTSCENE);
|
2021-03-08 00:41:27 +01:00
|
|
|
break;
|
|
|
|
|
2021-03-11 23:21:18 +01:00
|
|
|
case GF_START_DEMO:
|
2021-03-08 00:41:27 +01:00
|
|
|
gf_option = StartDemo();
|
|
|
|
break;
|
|
|
|
|
2021-03-11 23:21:18 +01:00
|
|
|
case GF_LEVEL_COMPLETE:
|
2021-03-08 00:41:27 +01:00
|
|
|
gf_option = LevelCompleteSequence(gf_param);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GF_EXIT_TO_TITLE:
|
|
|
|
T_InitPrint();
|
|
|
|
TempVideoAdjust(2, 1.0);
|
|
|
|
S_DisplayPicture("data\\titleh");
|
|
|
|
NoInputCount = 0;
|
2021-03-12 17:02:41 +01:00
|
|
|
if (!InitialiseLevel(GF.title_level_num, GFL_TITLE)) {
|
|
|
|
gf_option = GF_EXIT_GAME;
|
|
|
|
break;
|
2021-03-08 00:41:27 +01:00
|
|
|
}
|
2021-03-12 17:02:41 +01:00
|
|
|
TitleLoaded = 1;
|
2021-03-08 00:41:27 +01:00
|
|
|
|
|
|
|
dword_45B940 = 0;
|
|
|
|
Display_Inventory(1);
|
|
|
|
dword_45B940 = 1;
|
|
|
|
|
|
|
|
S_FadeToBlack();
|
|
|
|
S_CDStop();
|
|
|
|
|
|
|
|
if (ResetFlag) {
|
|
|
|
ResetFlag = 0;
|
2021-03-11 23:21:18 +01:00
|
|
|
gf_option = GF_START_DEMO;
|
2021-03-08 00:41:27 +01:00
|
|
|
} else if (InventoryChosen == O_PHOTO_OPTION) {
|
2021-03-12 17:02:41 +01:00
|
|
|
gf_option = GF_START_GAME | GF.gym_level_num;
|
2021-03-11 23:21:18 +01:00
|
|
|
} else if (InventoryChosen == O_PASSPORT_OPTION) {
|
|
|
|
if (InventoryExtraData[0] == 0) {
|
2021-03-12 17:02:41 +01:00
|
|
|
gf_option = GF_START_SAVED_GAME | InventoryExtraData[1];
|
2021-03-11 23:21:18 +01:00
|
|
|
} else if (InventoryExtraData[0] == 1) {
|
2021-03-16 21:35:50 +01:00
|
|
|
switch (InventoryExtraData[1]) {
|
|
|
|
case 0:
|
|
|
|
SaveGame.bonus_flag = 0;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
SaveGame.bonus_flag = GBF_NGPLUS;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
SaveGame.bonus_flag = GBF_JAPANESE;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
SaveGame.bonus_flag = GBF_JAPANESE | GBF_NGPLUS;
|
|
|
|
break;
|
|
|
|
}
|
2021-03-12 16:51:37 +01:00
|
|
|
InitialiseStartInfo();
|
2021-03-12 17:02:41 +01:00
|
|
|
gf_option = GF_START_GAME | GF.first_level_num;
|
2021-03-08 00:41:27 +01:00
|
|
|
} else {
|
2021-03-11 23:21:18 +01:00
|
|
|
gf_option = GF_EXIT_GAME;
|
2021-03-08 00:41:27 +01:00
|
|
|
}
|
2021-03-11 23:21:18 +01:00
|
|
|
} else {
|
|
|
|
gf_option = GF_EXIT_GAME;
|
2021-03-08 00:41:27 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2021-03-11 23:21:18 +01:00
|
|
|
case GF_EXIT_GAME:
|
2021-03-08 00:41:27 +01:00
|
|
|
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);
|
|
|
|
}
|