Skip to content
This repository has been archived by the owner on Oct 4, 2024. It is now read-only.

Move /hp and /pos console commands to libtrx #242

Merged
merged 3 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
- fixed secret rewards not displaying shotgun ammo (#159)
- fixed controls dialog remapping being too sensitive (#5)
- fixed `/tp` console command during special animations in HSH and Offshore Rig (#178, regression from 0.2)
- fixed `/hp` console command taking arbitrary integers
- fixed console commands being able to interfere with demos, cutscenes and the title screen (#182, #179, regression from 0.2)
- fixed console registering key inputs too eagerly (regression from 0.2)
- fixed console not being drawn in cutscenes (#180, regression from 0.2)
Expand Down
64 changes: 32 additions & 32 deletions data/ship/cfg/TR2X_gameflow.json5
Original file line number Diff line number Diff line change
Expand Up @@ -351,48 +351,48 @@
},

"game_strings": {
"OSD_FLY_MODE_ON": "Fly mode enabled",
"OSD_COMMAND_BAD_INVOCATION": "Invalid invocation: %s",
"OSD_COMMAND_UNAVAILABLE": "This command is not currently available",
"OSD_COMPLETE_LEVEL": "Level complete!",
"OSD_CURRENT_HEALTH_GET": "Current Lara's health: %d",
"OSD_CURRENT_HEALTH_SET": "Lara's health set to %d",
"OSD_DOOR_CLOSE": "Close Sesame!",
"OSD_DOOR_OPEN": "Open Sesame!",
"OSD_DOOR_OPEN_FAIL": "No doors in Lara's proximity",
"OSD_FLIPMAP_FAIL_ALREADY_OFF": "Flipmap is already OFF",
"OSD_FLIPMAP_FAIL_ALREADY_ON": "Flipmap is already ON",
"OSD_FLIPMAP_OFF": "Flipmap set to OFF",
"OSD_FLIPMAP_ON": "Flipmap set to ON",
"OSD_FLY_MODE_OFF": "Fly mode disabled",
"OSD_POS_GET": "Room: %d\nPosition: %.3f, %.3f, %.3f\nRotation: %.3f,%.3f,%.3f",
"OSD_POS_SET_POS": "Teleported to position: %.3f %.3f %.3f",
"OSD_POS_SET_POS_FAIL": "Failed to teleport to position: %.3f %.3f %.3f",
"OSD_POS_SET_ROOM": "Teleported to room: %d",
"OSD_POS_SET_ROOM_FAIL": "Failed to teleport to room: %d",
"OSD_POS_SET_ITEM": "Teleported to object: %s",
"OSD_POS_SET_ITEM_FAIL": "Failed to teleport to object: %s",
"OSD_FLY_MODE_ON": "Fly mode enabled",
"OSD_GIVE_ITEM": "Added %s to Lara's inventory",
"OSD_GIVE_ITEM_ALL_KEYS": "Surprise! Every key item Lara needs is now in her backpack.",
"OSD_GIVE_ITEM_ALL_GUNS": "Lock'n'load - Lara's armed to the teeth!",
"OSD_GIVE_ITEM_ALL_KEYS": "Surprise! Every key item Lara needs is now in her backpack.",
"OSD_GIVE_ITEM_CHEAT": "Lara's backpack just got way heavier!",
"OSD_FLIPMAP_ON": "Flipmap set to ON",
"OSD_FLIPMAP_OFF": "Flipmap set to OFF",
"OSD_FLIPMAP_FAIL_ALREADY_ON": "Flipmap is already ON",
"OSD_FLIPMAP_FAIL_ALREADY_OFF": "Flipmap is already OFF",
"OSD_KILL_ALL": "Poof! %d enemies gone!",
"OSD_KILL_ALL_FAIL": "Uh-oh, there are no enemies left to kill...",
"OSD_KILL": "Bye-bye!",
"OSD_KILL_FAIL": "No enemy nearby...",
"OSD_COMPLETE_LEVEL": "Level complete!",
"OSD_PLAY_LEVEL": "Loading %s",
"OSD_HEAL_ALREADY_FULL_HP": "Lara's already at full health",
"OSD_HEAL_SUCCESS": "Healed Lara back to full health",
"OSD_INVALID_ITEM": "Invalid item: %s",
"OSD_INVALID_ROOM": "Invalid room: %d. Valid rooms are 0-%d",
"OSD_INVALID_OBJECT": "Invalid object",
"OSD_OBJECT_NOT_FOUND": "Object not found",
"OSD_INVALID_LEVEL": "Invalid level",
"OSD_INVALID_OBJECT": "Invalid object",
"OSD_INVALID_ROOM": "Invalid room: %d. Valid rooms are 0-%d",
"OSD_INVALID_SAVE_SLOT": "Invalid save slot %d",
"OSD_UNKNOWN_COMMAND": "Unknown command: %s",
"OSD_COMMAND_BAD_INVOCATION": "Invalid invocation: %s",
"OSD_COMMAND_UNAVAILABLE": "This command is not currently available",
"OSD_DOOR_OPEN": "Open Sesame!",
"OSD_DOOR_CLOSE": "Close Sesame!",
"OSD_DOOR_OPEN_FAIL": "No doors in Lara's proximity",
"OSD_KILL": "Bye-bye!",
"OSD_KILL_ALL": "Poof! %d enemies gone!",
"OSD_KILL_ALL_FAIL": "Uh-oh, there are no enemies left to kill...",
"OSD_KILL_FAIL": "No enemy nearby...",
"OSD_LOAD_GAME": "Loaded game from save slot %d",
"OSD_LOAD_GAME_FAIL_UNAVAILABLE_SLOT": "Save slot %d is not available",
"OSD_OBJECT_NOT_FOUND": "Object not found",
"OSD_PLAY_LEVEL": "Loading %s",
"OSD_POS_GET": "Room: %d\nPosition: %.3f, %.3f, %.3f\nRotation: %.3f,%.3f,%.3f",
"OSD_POS_SET_ITEM": "Teleported to object: %s",
"OSD_POS_SET_ITEM_FAIL": "Failed to teleport to object: %s",
"OSD_POS_SET_POS": "Teleported to position: %.3f %.3f %.3f",
"OSD_POS_SET_POS_FAIL": "Failed to teleport to position: %.3f %.3f %.3f",
"OSD_POS_SET_ROOM": "Teleported to room: %d",
"OSD_POS_SET_ROOM_FAIL": "Failed to teleport to room: %d",
"OSD_SAVE_GAME": "Saved game to save slot %d",
"OSD_SAVE_GAME_FAIL": "Cannot save the game in the current state",
"OSD_CURRENT_HEALTH_GET": "Current Lara's health: %d",
"OSD_CURRENT_HEALTH_SET": "Lara's health set to %d",
"OSD_HEAL_ALREADY_FULL_HP": "Lara's already at full health",
"OSD_HEAL_SUCCESS": "Healed Lara back to full health",
"OSD_UNKNOWN_COMMAND": "Unknown command: %s",
},
}
6 changes: 3 additions & 3 deletions docs/progress.txt
Original file line number Diff line number Diff line change
Expand Up @@ -473,13 +473,13 @@ typedef enum {
DRAW_COLOR_KEY = 1,
} DRAW_TYPE;

typedef struct __unaligned {
typedef struct __unaligned { // decompiled
int32_t floor;
int32_t ceiling;
int32_t type;
} COLL_SIDE;

typedef struct __unaligned {
typedef struct __unaligned { // decompiled
COLL_SIDE side_mid;
COLL_SIDE side_front;
COLL_SIDE side_left;
Expand Down Expand Up @@ -1107,7 +1107,7 @@ typedef struct __unaligned {
uint16_t reserved4[2];
} GAME_FLOW;

typedef struct __unaligned {
typedef struct __unaligned { // decompiled
int16_t mesh_count;
int16_t mesh_idx;
int32_t bone_idx;
Expand Down
1 change: 1 addition & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ dll_sources = [
'src/game/inventory/ring.c',
'src/game/inventory/vars.c',
'src/game/items.c',
'src/game/lara/common.c',
'src/game/lara/lara_cheat.c',
'src/game/lara/lara_col.c',
'src/game/lara/lara_control.c',
Expand Down
10 changes: 7 additions & 3 deletions src/game/console.c
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#include "game/console.h"

#include "game/clock.h"
#include "game/console_cmd.h"
#include "game/game_string.h"
#include "game/input.h"
#include "game/output.h"
#include "game/text.h"
#include "global/const.h"
#include "global/types.h"

#include <libtrx/game/console/common.h>
#include <libtrx/log.h>
#include <libtrx/memory.h>
#include <libtrx/utils.h>
Expand Down Expand Up @@ -51,6 +51,7 @@ static void Console_UpdatePromptTextstring(void);
static void Console_UpdateCaretTextstring(void);
static COMMAND_RESULT Console_Eval(const char *cmdline);

extern CONSOLE_COMMAND *g_ConsoleCommands[];
static void Console_ShutdownPrompt(void)
{
if (m_Prompt.prompt_ts != NULL) {
Expand Down Expand Up @@ -91,8 +92,11 @@ static COMMAND_RESULT Console_Eval(const char *const cmdline)
const char *args = NULL;
const CONSOLE_COMMAND *matching_cmd = NULL;

for (CONSOLE_COMMAND *cur_cmd = &g_ConsoleCommands[0];
cur_cmd->proc != NULL; cur_cmd++) {
for (int32_t i = 0;; i++) {
CONSOLE_COMMAND *cur_cmd = g_ConsoleCommands[i];
if (cur_cmd == NULL) {
break;
}
if (strstr(cmdline, cur_cmd->prefix) != cmdline) {
continue;
}
Expand Down
95 changes: 26 additions & 69 deletions src/game/console_cmd.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#include "game/console_cmd.h"

#include "decomp/effects.h"
#include "game/console.h"
#include "game/creature.h"
Expand All @@ -20,6 +18,9 @@
#include "global/vars.h"
#include "lara/lara_misc.h"

#include <libtrx/game/console/commands/pos.h>
#include <libtrx/game/console/commands/set_health.h>
#include <libtrx/game/console/common.h>
#include <libtrx/memory.h>
#include <libtrx/strings.h>

Expand All @@ -30,9 +31,7 @@ static bool Console_Cmd_CanTargetObject(GAME_OBJECT_ID object_id);
static bool Console_Cmd_CanTargetObjectCreature(GAME_OBJECT_ID object_id);
static bool Console_Cmd_CanTargetObjectPickup(GAME_OBJECT_ID object_id);
static bool Console_Cmd_IsFloatRound(float num);
static COMMAND_RESULT Console_Cmd_Pos(const char *args);
static COMMAND_RESULT Console_Cmd_Teleport(const char *args);
static COMMAND_RESULT Console_Cmd_SetHealth(const char *args);
static COMMAND_RESULT Console_Cmd_Heal(const char *args);
static COMMAND_RESULT Console_Cmd_Fly(const char *const args);
static COMMAND_RESULT Console_Cmd_FlipMap(const char *args);
Expand Down Expand Up @@ -70,22 +69,6 @@ static inline bool Console_Cmd_IsFloatRound(const float num)
return (fabsf(num) - roundf(num)) < 0.0001f;
}

static COMMAND_RESULT Console_Cmd_Pos(const char *const args)
{
if (!g_Objects[O_LARA].loaded) {
return CR_UNAVAILABLE;
}

Console_Log(
GS(OSD_POS_GET), g_LaraItem->room_num,
g_LaraItem->pos.x / (float)WALL_L, g_LaraItem->pos.y / (float)WALL_L,
g_LaraItem->pos.z / (float)WALL_L,
g_LaraItem->rot.x * 360.0f / (float)PHD_ONE,
g_LaraItem->rot.y * 360.0f / (float)PHD_ONE,
g_LaraItem->rot.z * 360.0f / (float)PHD_ONE);
return CR_SUCCESS;
}

static COMMAND_RESULT Console_Cmd_Teleport(const char *const args)
{
if (g_GameInfo.current_level.type == GFL_TITLE
Expand Down Expand Up @@ -216,33 +199,6 @@ static COMMAND_RESULT Console_Cmd_Teleport(const char *const args)
return CR_BAD_INVOCATION;
}

static COMMAND_RESULT Console_Cmd_SetHealth(const char *const args)
{
if (g_GameInfo.current_level.type == GFL_TITLE
|| g_GameInfo.current_level.type == GFL_DEMO
|| g_GameInfo.current_level.type == GFL_CUTSCENE) {
return CR_UNAVAILABLE;
}

if (!g_Objects[O_LARA].loaded) {
return CR_UNAVAILABLE;
}

if (strcmp(args, "") == 0) {
Console_Log(GS(OSD_CURRENT_HEALTH_GET), g_LaraItem->hit_points);
return CR_SUCCESS;
}

int32_t hp;
if (sscanf(args, "%d", &hp) != 1) {
return CR_BAD_INVOCATION;
}

g_LaraItem->hit_points = hp;
Console_Log(GS(OSD_CURRENT_HEALTH_SET), hp);
return CR_SUCCESS;
}

static COMMAND_RESULT Console_Cmd_Heal(const char *const args)
{
if (g_GameInfo.current_level.type == GFL_TITLE
Expand Down Expand Up @@ -603,26 +559,27 @@ static COMMAND_RESULT Console_Cmd_Abortion(const char *const args)
return CR_SUCCESS;
}

CONSOLE_COMMAND g_ConsoleCommands[] = {
{ .prefix = "pos", .proc = Console_Cmd_Pos },
{ .prefix = "tp", .proc = Console_Cmd_Teleport },
{ .prefix = "hp", .proc = Console_Cmd_SetHealth },
{ .prefix = "heal", .proc = Console_Cmd_Heal },
{ .prefix = "fly", .proc = Console_Cmd_Fly },
{ .prefix = "give", .proc = Console_Cmd_GiveItem },
{ .prefix = "gimme", .proc = Console_Cmd_GiveItem },
{ .prefix = "flip", .proc = Console_Cmd_FlipMap },
{ .prefix = "flipmap", .proc = Console_Cmd_FlipMap },
{ .prefix = "kill", .proc = Console_Cmd_Kill },
{ .prefix = "endlevel", .proc = Console_Cmd_EndLevel },
{ .prefix = "play", .proc = Console_Cmd_StartLevel },
{ .prefix = "level", .proc = Console_Cmd_StartLevel },
{ .prefix = "load", .proc = Console_Cmd_LoadGame },
{ .prefix = "save", .proc = Console_Cmd_SaveGame },
{ .prefix = "demo", .proc = Console_Cmd_StartDemo },
{ .prefix = "title", .proc = Console_Cmd_ExitToTitle },
{ .prefix = "exit", .proc = Console_Cmd_ExitGame },
{ .prefix = "abortion", .proc = Console_Cmd_Abortion },
{ .prefix = "natlastinks", .proc = Console_Cmd_Abortion },
{ .prefix = NULL, .proc = NULL },
CONSOLE_COMMAND *g_ConsoleCommands[] = {
&(CONSOLE_COMMAND) { .prefix = "tp", .proc = Console_Cmd_Teleport },
&(CONSOLE_COMMAND) { .prefix = "heal", .proc = Console_Cmd_Heal },
&(CONSOLE_COMMAND) { .prefix = "fly", .proc = Console_Cmd_Fly },
&(CONSOLE_COMMAND) { .prefix = "give", .proc = Console_Cmd_GiveItem },
&(CONSOLE_COMMAND) { .prefix = "gimme", .proc = Console_Cmd_GiveItem },
&(CONSOLE_COMMAND) { .prefix = "flip", .proc = Console_Cmd_FlipMap },
&(CONSOLE_COMMAND) { .prefix = "flipmap", .proc = Console_Cmd_FlipMap },
&(CONSOLE_COMMAND) { .prefix = "kill", .proc = Console_Cmd_Kill },
&(CONSOLE_COMMAND) { .prefix = "endlevel", .proc = Console_Cmd_EndLevel },
&(CONSOLE_COMMAND) { .prefix = "play", .proc = Console_Cmd_StartLevel },
&(CONSOLE_COMMAND) { .prefix = "level", .proc = Console_Cmd_StartLevel },
&(CONSOLE_COMMAND) { .prefix = "load", .proc = Console_Cmd_LoadGame },
&(CONSOLE_COMMAND) { .prefix = "save", .proc = Console_Cmd_SaveGame },
&(CONSOLE_COMMAND) { .prefix = "demo", .proc = Console_Cmd_StartDemo },
&(CONSOLE_COMMAND) { .prefix = "title", .proc = Console_Cmd_ExitToTitle },
&(CONSOLE_COMMAND) { .prefix = "exit", .proc = Console_Cmd_ExitGame },
&(CONSOLE_COMMAND) { .prefix = "abortion", .proc = Console_Cmd_Abortion },
&(CONSOLE_COMMAND) { .prefix = "natlastinks",
.proc = Console_Cmd_Abortion },
&g_Console_Cmd_Pos,
&g_Console_Cmd_SetHealth,
NULL,
};
15 changes: 0 additions & 15 deletions src/game/console_cmd.h

This file was deleted.

16 changes: 16 additions & 0 deletions src/game/game.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "decomp/decomp.h"
#include "game/camera.h"
#include "game/demo.h"
#include "game/gameflow/gameflow_new.h"
#include "game/input.h"
#include "game/inventory/common.h"
#include "game/lara/lara_control.h"
Expand Down Expand Up @@ -296,3 +297,18 @@ int32_t __cdecl Game_Loop(const bool demo_mode)

return dir;
}

bool Game_IsPlayable(void)
{
if (g_GameInfo.current_level.type == GFL_TITLE
|| g_GameInfo.current_level.type == GFL_DEMO
|| g_GameInfo.current_level.type == GFL_CUTSCENE) {
return false;
}

if (!g_Objects[O_LARA].loaded) {
return false;
}

return true;
}
1 change: 1 addition & 0 deletions src/game/game.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ int32_t __cdecl Game_Draw(void);
int32_t __cdecl Game_DrawCinematic(void);
int16_t __cdecl Game_Start(int32_t level_num, GF_LEVEL_TYPE level_type);
int32_t __cdecl Game_Loop(bool demo_mode);
bool Game_IsPlayable(void);
2 changes: 2 additions & 0 deletions src/game/game_string.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
void GameString_Init(void)
{
#include "game_string.def"

#include <libtrx/game/game_string.def>
}

void GameString_Shutdown(void)
Expand Down
1 change: 0 additions & 1 deletion src/game/game_string.def
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
GS_DEFINE(OSD_FLY_MODE_ON, "Fly mode enabled")
GS_DEFINE(OSD_FLY_MODE_OFF, "Fly mode disabled")
GS_DEFINE(OSD_POS_GET, "Room: %d\nPosition: %.3f, %.3f, %.3f\nRotation: %.3f,%.3f,%.3f")
GS_DEFINE(OSD_POS_SET_POS, "Teleported to position: %.3f %.3f %.3f")
GS_DEFINE(OSD_POS_SET_POS_FAIL, "Failed to teleport to position: %.3f %.3f %.3f")
GS_DEFINE(OSD_POS_SET_ROOM, "Teleported to room: %d")
Expand Down
8 changes: 8 additions & 0 deletions src/game/lara/common.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include "game/lara/common.h"

#include "global/vars.h"

ITEM_INFO *Lara_GetItem(void)
{
return g_LaraItem;
}
5 changes: 5 additions & 0 deletions src/game/lara/common.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#pragma once

#include "game/items.h"

ITEM_INFO *Lara_GetItem(void);
5 changes: 5 additions & 0 deletions src/game/objects/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
#include "global/funcs.h"
#include "global/vars.h"

OBJECT_INFO *Object_GetObject(GAME_OBJECT_ID object_id)
{
return &g_Objects[object_id];
}

GAME_OBJECT_ID Object_GetCognate(
GAME_OBJECT_ID key_id, const GAME_OBJECT_PAIR *test_map)
{
Expand Down
1 change: 1 addition & 0 deletions src/game/objects/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ typedef struct GAME_OBJECT_PAIR {
const GAME_OBJECT_ID value_id;
} GAME_OBJECT_PAIR;

OBJECT_INFO *Object_Get(GAME_OBJECT_ID object_id);
GAME_OBJECT_ID Object_GetCognate(
GAME_OBJECT_ID key_id, const GAME_OBJECT_PAIR *test_map);
GAME_OBJECT_ID Object_GetCognateInverse(
Expand Down
Loading
Loading