Skip to content

Commit

Permalink
inject: add PS1 crystal data
Browse files Browse the repository at this point in the history
This allows injections to replace an unused palette slot with a specific
color, and so allows an alternative to matching to the existing level
palette. Data provided for each case of the savegame crystal, and the
relevant config options updated.

Resolves LostArtefacts#1506.
  • Loading branch information
lahm86 committed Sep 14, 2024
1 parent 8d9b823 commit 9786568
Show file tree
Hide file tree
Showing 20 changed files with 80 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## [Unreleased](https://github.com/LostArtefacts/TR1X/compare/stable...develop) - ××××-××-××
- added `/exit` command (#1462)
- added reflections to Midas Hand death animation and savegame crystals (#154)
- added an option to use PS1 tinted savegame crystals (#1506)
- fixed `/play`, `/load`, `/demo` and similar commands not working in stats, credits, cinematics and fmvs (#1477)
- fixed console commands being able to interfere with demos, cutscenes and the title screen (#1489, regression from 3.0)
- fixed reopening the compass not resetting its needle (#1472, regression from 4.0)
Expand Down
15 changes: 15 additions & 0 deletions data/ship/cfg/TR1X_gameflow.json5
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
"data/injections/caves_fd.bin",
"data/injections/caves_itemrots.bin",
"data/injections/caves_textures.bin",
"data/injections/purple_crystal49.bin",
],
"sequence": [
{"type": "play_fmv", "fmv_path": "fmv/snow.avi"},
Expand All @@ -80,6 +81,7 @@
"type": "normal",
"music": 57,
"injections": [
"data/injections/purple_crystal68.bin",
"data/injections/vilcabamba_itemrots.bin",
"data/injections/vilcabamba_textures.bin",
],
Expand All @@ -105,6 +107,7 @@
"type": "normal",
"music": 57,
"injections": [
"data/injections/purple_crystal62.bin",
"data/injections/valley_itemrots.bin",
"data/injections/valley_skybox.bin",
"data/injections/valley_textures.bin",
Expand All @@ -131,6 +134,7 @@
"music": 57,
"injections": [
"data/injections/larson_textures.bin",
"data/injections/purple_crystal115.bin",
"data/injections/qualopec_fd.bin",
"data/injections/qualopec_itemrots.bin",
"data/injections/qualopec_textures.bin",
Expand All @@ -155,6 +159,7 @@
"data/injections/folly_fd.bin",
"data/injections/folly_itemrots.bin",
"data/injections/folly_textures.bin",
"data/injections/purple_crystal49.bin",
],
"sequence": [
{"type": "play_fmv", "fmv_path": "fmv/lift.avi"},
Expand Down Expand Up @@ -185,6 +190,7 @@
"data/injections/colosseum_itemrots.bin",
"data/injections/colosseum_skybox.bin",
"data/injections/colosseum_textures.bin",
"data/injections/purple_crystal49.bin",
],
"sequence": [
{"type": "loading_screen", "picture_path": "data/images/greece.webp", "display_time": 5},
Expand All @@ -208,6 +214,7 @@
"injections": [
"data/injections/midas_itemrots.bin",
"data/injections/midas_textures.bin",
"data/injections/purple_crystal49.bin",
],
"sequence": [
{"type": "loading_screen", "picture_path": "data/images/greece.webp", "display_time": 5},
Expand All @@ -234,6 +241,7 @@
"data/injections/cistern_itemrots.bin",
"data/injections/cistern_plants.bin",
"data/injections/cistern_textures.bin",
"data/injections/purple_crystal49.bin",
],
"sequence": [
{"type": "loading_screen", "picture_path": "data/images/greece.webp", "display_time": 5},
Expand All @@ -258,6 +266,7 @@
"music": 58,
"injections": [
"data/injections/cistern_plants.bin",
"data/injections/purple_crystal49.bin",
"data/injections/tihocan_fd.bin",
"data/injections/tihocan_itemrots.bin",
"data/injections/tihocan_textures.bin",
Expand Down Expand Up @@ -289,6 +298,7 @@
"data/injections/khamoon_fd.bin",
"data/injections/khamoon_mummy.bin",
"data/injections/khamoon_textures.bin",
"data/injections/purple_crystal49.bin",
],
"sequence": [
{"type": "play_fmv", "fmv_path": "fmv/vision.avi"},
Expand All @@ -315,6 +325,7 @@
"data/injections/obelisk_itemrots.bin",
"data/injections/obelisk_skybox.bin",
"data/injections/obelisk_textures.bin",
"data/injections/purple_crystal49.bin",
],
"sequence": [
{"type": "loading_screen", "picture_path": "data/images/egypt.webp", "display_time": 5},
Expand All @@ -340,6 +351,7 @@
"type": "normal",
"music": 59,
"injections": [
"data/injections/purple_crystal50.bin",
"data/injections/sanctuary_fd.bin",
"data/injections/sanctuary_itemrots.bin",
"data/injections/sanctuary_textures.bin",
Expand Down Expand Up @@ -371,6 +383,7 @@
"data/injections/mines_fd.bin",
"data/injections/mines_itemrots.bin",
"data/injections/mines_textures.bin",
"data/injections/purple_crystal49.bin",
"data/injections/skateboardkid_textures.bin"
],
"item_drops": [
Expand Down Expand Up @@ -404,6 +417,7 @@
"injections": [
"data/injections/atlantis_fd.bin",
"data/injections/atlantis_textures.bin",
"data/injections/purple_crystal50.bin",
],
"sequence": [
{"type": "play_fmv", "fmv_path": "fmv/pyramid.avi"},
Expand All @@ -427,6 +441,7 @@
"type": "normal",
"music": 60,
"injections": [
"data/injections/purple_crystal50.bin",
"data/injections/pyramid_fd.bin",
"data/injections/pyramid_textures.bin",
"data/injections/scion_collision.bin",
Expand Down
Binary file added data/ship/data/injections/purple_crystal115.bin
Binary file not shown.
Binary file added data/ship/data/injections/purple_crystal49.bin
Binary file not shown.
Binary file added data/ship/data/injections/purple_crystal50.bin
Binary file not shown.
Binary file added data/ship/data/injections/purple_crystal62.bin
Binary file not shown.
Binary file added data/ship/data/injections/purple_crystal68.bin
Binary file not shown.
1 change: 1 addition & 0 deletions src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ typedef struct {
bool enable_loading_screens;
bool fix_animated_sprites;
bool enable_skybox;
bool enable_ps1_crystals;

struct {
int32_t layout;
Expand Down
1 change: 1 addition & 0 deletions src/config_map.def
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,4 @@ CFG_DOUBLE(g_Config, ui.bar_scale, DEFAULT_UI_SCALE)
CFG_BOOL(g_Config, profile.new_game_plus_unlock, false)
CFG_BOOL(g_Config, fix_animated_sprites, true)
CFG_BOOL(g_Config, enable_skybox, true)
CFG_BOOL(g_Config, enable_ps1_crystals, true)
3 changes: 2 additions & 1 deletion src/game/console_cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,8 @@ static COMMAND_RESULT Console_Cmd_Teleport(const char *const args)
item_num++) {
const ITEM_INFO *const item = &g_Items[item_num];
const bool is_pickup =
Object_IsObjectType(item->object_id, g_PickupObjects);
Object_IsObjectType(item->object_id, g_PickupObjects)
|| item->object_id == O_SAVEGAME_ITEM;
if (is_pickup
&& (item->status == IS_INVISIBLE
|| item->status == IS_DEACTIVATED)) {
Expand Down
28 changes: 27 additions & 1 deletion src/game/inject.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include <stddef.h>

#define INJECTION_MAGIC MKTAG('T', '1', 'M', 'J')
#define INJECTION_CURRENT_VERSION 8
#define INJECTION_CURRENT_VERSION 9
#define NULL_FD_INDEX ((uint16_t)(-1))

typedef enum INJECTION_VERSION {
Expand All @@ -32,6 +32,7 @@ typedef enum INJECTION_VERSION {
INJ_VERSION_6 = 6,
INJ_VERSION_7 = 7,
INJ_VERSION_8 = 8,
INJ_VERSION_9 = 9,
} INJECTION_VERSION;

typedef enum INJECTION_TYPE {
Expand All @@ -46,6 +47,7 @@ typedef enum INJECTION_TYPE {
INJ_PS1_ENEMY = 8,
INJ_DISABLE_ANIM_SPRITE = 9,
INJ_SKYBOX = 10,
INJ_PS1_CRYSTAL = 11,
} INJECTION_TYPE;

typedef struct INJECTION {
Expand Down Expand Up @@ -243,6 +245,10 @@ static void Inject_LoadFromFile(INJECTION *injection, const char *filename)
case INJ_SKYBOX:
injection->relevant = g_Config.enable_skybox;
break;
case INJ_PS1_CRYSTAL:
injection->relevant =
g_Config.enable_save_crystals && g_Config.enable_ps1_crystals;
break;
default:
LOG_WARNING("%s is of unknown type %d", filename, injection->type);
break;
Expand Down Expand Up @@ -315,6 +321,11 @@ static void Inject_LoadFromFile(INJECTION *injection, const char *filename)
{
const size_t prev_pos = VFile_GetPos(fp);

if (injection->version >= INJ_VERSION_9) {
const uint8_t overwrite_count = VFile_ReadU8(fp);
VFile_Skip(fp, overwrite_count * 4);
}

// texture pages
VFile_Skip(fp, 256 * 3);
VFile_Skip(fp, info->texture_page_count * PAGE_SIZE);
Expand Down Expand Up @@ -457,6 +468,21 @@ static void Inject_LoadTexturePages(
INJECTION_INFO *inj_info = injection->info;
VFILE *const fp = injection->fp;

if (injection->version >= INJ_VERSION_9) {
// Pre-calculated unused palette slots can be repurposed where we need
// to inject a specific color, rather than matching the OG palette.
const uint8_t overwrite_count = VFile_ReadU8(fp);
for (int32_t i = 0; i < overwrite_count; i++) {
const uint8_t idx = VFile_ReadU8(fp);
const RGB_888 color = {
.r = VFile_ReadU8(fp),
.g = VFile_ReadU8(fp),
.b = VFile_ReadU8(fp),
};
Output_SetPaletteColor(idx, color);
}
}

palette_map[0] = 0;
RGB_888 source_palette[256];
for (int32_t i = 0; i < 256; i++) {
Expand Down
5 changes: 5 additions & 0 deletions src/game/output.c
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,11 @@ RGB_888 Output_GetPaletteColor(uint8_t idx)
return S_Output_GetPaletteColor(idx);
}

void Output_SetPaletteColor(const uint8_t idx, const RGB_888 color)
{
S_Output_SetPaletteColor(idx, color);
}

void Output_DrawBlack(void)
{
Output_DrawBlackOverlay(255);
Expand Down
1 change: 1 addition & 0 deletions src/game/output.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ void Output_DownloadTextures(int page_count);
RGBA_8888 Output_RGB2RGBA(const RGB_888 color);
void Output_SetPalette(RGB_888 palette[256]);
RGB_888 Output_GetPaletteColor(uint8_t idx);
void Output_SetPaletteColor(uint8_t idx, const RGB_888 color);

int32_t Output_GetNearZ(void);
int32_t Output_GetFarZ(void);
Expand Down
5 changes: 5 additions & 0 deletions src/specific/s_output.c
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,11 @@ RGB_888 S_Output_GetPaletteColor(uint8_t idx)
return m_ColorPalette[idx];
}

void S_Output_SetPaletteColor(const uint8_t idx, const RGB_888 color)
{
m_ColorPalette[idx] = color;
}

void S_Output_FlipScreen(void)
{
S_Output_FlipPrimaryBuffer();
Expand Down
1 change: 1 addition & 0 deletions src/specific/s_output.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ void S_Output_ApplyRenderSettings(void);

void S_Output_SetPalette(RGB_888 palette[256]);
RGB_888 S_Output_GetPaletteColor(uint8_t idx);
void S_Output_SetPaletteColor(uint8_t idx, const RGB_888 color);

void S_Output_DownloadTextures(int32_t pages);
void S_Output_SelectTexture(int32_t texture_num);
Expand Down
4 changes: 4 additions & 0 deletions tools/config/TR1X_ConfigTool/Resources/Lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,10 @@
"Title": "3D pickups",
"Description": "Enables 3D models to be rendered in place of the sprites for pickup items."
},
"enable_ps1_crystals": {
"Title": "Enable PS1 save crystals",
"Description": "Save crystals will be drawn with a purple tint, more similar to the PS1 type."
},
"enable_round_shadow": {
"Title": "Rounded shadows",
"Description": "Enables round shadows instead of the default octagonal ones."
Expand Down
4 changes: 4 additions & 0 deletions tools/config/TR1X_ConfigTool/Resources/Lang/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@
"Title": "Recogidas en 3D",
"Description": "Permite que los modelos en 3D se representen en lugar de los sprites para los objetos a recoger."
},
"enable_ps1_crystals": {
"Title": "Habilitar cristales guardados de PS1",
"Description": "Los cristales guardados se dibujarán con un tinte púrpura, más similar al tipo PS1."
},
"enable_skybox": {
"Title": "Cielo",
"Description": "Habilita el cielo en niveles soportados."
Expand Down
4 changes: 4 additions & 0 deletions tools/config/TR1X_ConfigTool/Resources/Lang/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,10 @@
"Title": "Collectibles 3D",
"Description": "Active les collectibles en 3D au lieu des objets en 2D."
},
"enable_ps1_crystals": {
"Title": "Activer les cristaux de sauvegarde PS1",
"Description": "Les cristaux de sauvegarde seront dessinés avec une teinte violette, plus similaire au type PS1."
},
"enable_round_shadow": {
"Title": "Ombres rondes",
"Description": "Active les ombres rondes au lieu d'ombres octagonales."
Expand Down
4 changes: 4 additions & 0 deletions tools/config/TR1X_ConfigTool/Resources/Lang/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,10 @@
"Title": "Oggetti 3D",
"Description": "Sostituisce gli oggetti 2D con i rispettivi modelli 3D."
},
"enable_ps1_crystals": {
"Title": "Abilita i cristalli di salvataggio PS1",
"Description": "I cristalli di salvataggio verranno disegnati con una tinta viola, più simile al tipo PS1."
},
"enable_round_shadow": {
"Title": "Ombre rotonde",
"Description": "Abilita le ombre rotonde invece di quelle ottagonali predefinite."
Expand Down
5 changes: 5 additions & 0 deletions tools/config/TR1X_ConfigTool/Resources/specification.json
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,11 @@
"DataType": "Bool",
"DefaultValue": true
},
{
"Field": "enable_ps1_crystals",
"DataType": "Bool",
"DefaultValue": true
},
{
"Field": "enable_round_shadow",
"DataType": "Bool",
Expand Down

0 comments on commit 9786568

Please sign in to comment.