Skip to content

Commit

Permalink
tr1/data: fix mesh positions in Obelisk of Khamoon
Browse files Browse the repository at this point in the history
This fixes the angle of the drawbridge when open so that Lara's shadow
isn't occluded and the artefacts aren't embedded. It also lifts the
senet table and lowers the toppled chair in room 57.

Resolves LostArtefacts#2006.
  • Loading branch information
lahm86 committed Dec 12, 2024
1 parent 544faeb commit 54b9ddc
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 6 deletions.
1 change: 1 addition & 0 deletions data/tr1/ship/cfg/TR1X_gameflow.json5
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@
"injections": [
"data/injections/obelisk_fd.bin",
"data/injections/obelisk_itemrots.bin",
"data/injections/obelisk_meshfixes.bin",
"data/injections/obelisk_skybox.bin",
"data/injections/obelisk_textures.bin",
],
Expand Down
Binary file not shown.
2 changes: 2 additions & 0 deletions docs/tr1/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
- fixed incorrect transparent pixels on some Egypt textures (#1975)
- fixed arrows overlapping with passport text if strings longer than the defaults are used (#1971)
- fixed objects close to the camera being clipped (#819, regression from TombATI)
- fixed the drawbridge in Obelisk of Khamoon not being angled correctly when open, which was resulting in embedded artefacts (#2006)
- fixed incorrect positions on static meshes in Obelisk of Khamoon (#2006)

## [4.6.1](https://github.com/LostArtefacts/TRX/compare/tr1-4.6...tr1-4.6.1) - 2024-11-25
- added ability to disable saves completely by setting the save slot to 0 (#1954)
Expand Down
57 changes: 51 additions & 6 deletions src/tr1/game/inject.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include <stddef.h>

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

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

typedef enum {
Expand Down Expand Up @@ -170,6 +171,7 @@ static uint16_t *M_GetRoomFaceVertices(
static void M_RoomDoorEdits(INJECTION *injection);

static void M_ItemPositions(INJECTION *injection);
static void M_FrameEdits(const INJECTION *injection);

static void M_LoadFromFile(INJECTION *injection, const char *filename)
{
Expand Down Expand Up @@ -313,6 +315,12 @@ static void M_LoadFromFile(INJECTION *injection, const char *filename)
info->item_position_count = 0;
}

if (injection->version > INJ_VERSION_9) {
info->frame_edit_count = VFile_ReadS32(fp);
} else {
info->frame_edit_count = 0;
}

// Get detailed frame counts
{
const size_t prev_pos = VFile_GetPos(fp);
Expand Down Expand Up @@ -892,14 +900,23 @@ static void M_MeshEdits(INJECTION *injection, uint16_t *palette_map)
static void M_ApplyMeshEdit(
const MESH_EDIT *const mesh_edit, const uint16_t *const palette_map)
{
const OBJECT *const object = Object_GetObject(mesh_edit->object_id);
if (!object->loaded) {
OBJECT_MESH *mesh;
if (mesh_edit->object_id < O_NUMBER_OF) {
const OBJECT *const object = Object_GetObject(mesh_edit->object_id);
if (!object->loaded) {
return;
}

mesh = Object_GetMesh(object->mesh_idx + mesh_edit->mesh_idx);
} else if (mesh_edit->object_id - O_NUMBER_OF < STATIC_NUMBER_OF) {
const STATIC_INFO *const info =
&g_StaticObjects[mesh_edit->object_id - O_NUMBER_OF];
mesh = Object_GetMesh(info->mesh_num);
} else {
LOG_WARNING("Invalid object ID %d", mesh_edit->object_id);
return;
}

OBJECT_MESH *const mesh =
Object_GetMesh(object->mesh_idx + mesh_edit->mesh_idx);

mesh->center.x += mesh_edit->centre_shift.x;
mesh->center.y += mesh_edit->centre_shift.y;
mesh->center.z += mesh_edit->centre_shift.z;
Expand Down Expand Up @@ -1642,6 +1659,33 @@ static void M_ItemPositions(INJECTION *injection)
Benchmark_End(benchmark, NULL);
}

static void M_FrameEdits(const INJECTION *const injection)
{
if (injection->version < INJ_VERSION_10) {
return;
}

BENCHMARK *const benchmark = Benchmark_Start();

VFILE *const fp = injection->fp;
for (int32_t i = 0; i < injection->info->frame_edit_count; i++) {
const GAME_OBJECT_ID object_id = VFile_ReadS32(fp);
const int32_t anim_idx = VFile_ReadS32(fp);
const int32_t packed_rot = VFile_ReadS32(fp);

const OBJECT *const obj = Object_GetObject(object_id);
if (!obj->loaded) {
continue;
}

const ANIM *const anim = &g_Anims[obj->anim_idx + anim_idx];
FRAME_INFO *const frame = anim->frame_ptr;
frame->mesh_rots[0] = packed_rot;
}

Benchmark_End(benchmark, NULL);
}

void Inject_Init(
int32_t num_injections, char *filenames[], INJECTION_INFO *aggregate)
{
Expand Down Expand Up @@ -1700,6 +1744,7 @@ void Inject_AllInjections(LEVEL_INFO *level_info)
M_AnimRangeEdits(injection);

M_ItemPositions(injection);
M_FrameEdits(injection);

// Realign base indices for the next injection.
INJECTION_INFO *inj_info = injection->info;
Expand Down
1 change: 1 addition & 0 deletions src/tr1/game/inject.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ typedef struct {
int32_t room_door_edit_count;
int32_t anim_range_edit_count;
int32_t item_position_count;
int32_t frame_edit_count;
} INJECTION_INFO;

void Inject_Init(
Expand Down

0 comments on commit 54b9ddc

Please sign in to comment.