Skip to content

Commit

Permalink
data: rotate some OG 3D pickups (#914)
Browse files Browse the repository at this point in the history
Resolves #253.
  • Loading branch information
walkawayy authored Aug 12, 2023
1 parent e25172e commit 8ed735d
Show file tree
Hide file tree
Showing 28 changed files with 106 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- fixed an error message from showing on exiting the game when the gym level is not present in the gameflow (#899)
- fixed the bear pat attack so it does not miss Lara (#450)
- fixed Lara not grabbing certain edges when the swing-cancel option is enabled (#911)
- fixed some incorrectly rotated pickups when using the 3D pickups option (#253)
- improve spanish localization and added translation for rotated pickups

## [2.15.2](https://github.com/rr-/Tomb1Main/compare/2.15.1...2.15.2) - 2023-07-17
Expand Down
14 changes: 14 additions & 0 deletions bin/cfg/Tomb1Main_gameflow.json5
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@
"type": "normal",
"music": 57,
"injections": [
"data/caves_itemrots.bin",
"data/caves_textures.bin",
],
"sequence": [
Expand All @@ -127,6 +128,7 @@
"type": "normal",
"music": 57,
"injections": [
"data/vilcabamba_itemrots.bin",
"data/vilcabamba_textures.bin",
],
"sequence": [
Expand All @@ -150,6 +152,7 @@
"type": "normal",
"music": 57,
"injections": [
"data/valley_itemrots.bin",
"data/valley_textures.bin",
],
"sequence": [
Expand All @@ -173,6 +176,7 @@
"music": 57,
"injections": [
"data/larson_textures.bin",
"data/qualopec_itemrots.bin",
"data/qualopec_textures.bin",
],
"sequence": [
Expand All @@ -191,6 +195,7 @@
"type": "normal",
"music": 59,
"injections": [
"data/folly_itemrots.bin",
"data/folly_textures.bin",
],
"sequence": [
Expand All @@ -217,6 +222,7 @@
"music": 59,
"injections": [
"data/colosseum_fd.bin",
"data/colosseum_itemrots.bin",
"data/colosseum_textures.bin",
],
"sequence": [
Expand All @@ -238,6 +244,7 @@
"type": "normal",
"music": 59,
"injections": [
"data/midas_itemrots.bin",
"data/midas_textures.bin",
],
"sequence": [
Expand All @@ -260,6 +267,7 @@
"type": "normal",
"music": 58,
"injections": [
"data/cistern_itemrots.bin",
"data/cistern_textures.bin",
],
"sequence": [
Expand All @@ -283,6 +291,7 @@
"type": "normal",
"music": 58,
"injections": [
"data/tihocan_itemrots.bin",
"data/tihocan_textures.bin",
],
"sequence": [
Expand Down Expand Up @@ -326,6 +335,9 @@
"file": "data/level8b.phd",
"type": "normal",
"music": 59,
"injections": [
"data/obelisk_itemrots.bin",
],
"sequence": [
{"type": "start_game"},
{"type": "loop_game"},
Expand All @@ -349,6 +361,7 @@
"type": "normal",
"music": 59,
"injections": [
"data/sanctuary_itemrots.bin",
"data/sanctuary_textures.bin",
],
"sequence": [
Expand All @@ -374,6 +387,7 @@
"injections": [
"data/cowboy_textures.bin",
"data/kold_textures.bin",
"data/mines_itemrots.bin",
"data/mines_textures.bin",
"data/skateboardkid_textures.bin"
],
Expand Down
3 changes: 3 additions & 0 deletions bin/cfg/Tomb1Main_gameflow_ub.json5
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"type": "normal",
"music": 59,
"injections": [
"data/cat_itemrots.bin",
"data/cat_textures.bin",
],
"sequence": [
Expand All @@ -66,6 +67,7 @@
"type": "normal",
"music": 60,
"injections": [
"data/stronghold_itemrots.bin",
"data/stronghold_textures.bin",
],
"sequence": [
Expand All @@ -86,6 +88,7 @@
"type": "normal",
"music": 60,
"injections": [
"data/hive_itemrots.bin",
"data/hive_textures.bin",
],
"sequence": [
Expand Down
Binary file added bin/data/cat_itemrots.bin
Binary file not shown.
Binary file added bin/data/caves_itemrots.bin
Binary file not shown.
Binary file added bin/data/cistern_itemrots.bin
Binary file not shown.
Binary file added bin/data/colosseum_itemrots.bin
Binary file not shown.
Binary file added bin/data/folly_itemrots.bin
Binary file not shown.
Binary file added bin/data/hive_itemrots.bin
Binary file not shown.
Binary file added bin/data/midas_itemrots.bin
Binary file not shown.
Binary file added bin/data/mines_itemrots.bin
Binary file not shown.
Binary file added bin/data/obelisk_itemrots.bin
Binary file not shown.
Binary file added bin/data/qualopec_itemrots.bin
Binary file not shown.
Binary file added bin/data/sanctuary_itemrots.bin
Binary file not shown.
Binary file added bin/data/stronghold_itemrots.bin
Binary file not shown.
Binary file added bin/data/tihocan_itemrots.bin
Binary file not shown.
Binary file added bin/data/valley_itemrots.bin
Binary file not shown.
Binary file added bin/data/vilcabamba_itemrots.bin
Binary file not shown.
2 changes: 2 additions & 0 deletions src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ bool Config_ReadFromJSON(const char *cfg_data)
READ_BOOL(enable_tr2_jumping, false);
READ_BOOL(load_current_music, true);
READ_BOOL(load_music_triggers, true);
READ_BOOL(fix_item_rots, true);

CLAMP(g_Config.start_lara_hitpoints, 1, LARA_HITPOINTS);
CLAMP(g_Config.fov_value, 30, 255);
Expand Down Expand Up @@ -419,6 +420,7 @@ bool Config_Write(void)
WRITE_BOOL(enable_tr2_jumping);
WRITE_BOOL(load_current_music);
WRITE_BOOL(load_music_triggers);
WRITE_BOOL(fix_item_rots);

// User settings
WRITE_BOOL(rendering.enable_bilinear_filter);
Expand Down
1 change: 1 addition & 0 deletions src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ typedef struct {
bool enable_tr2_jumping;
bool load_current_music;
bool load_music_triggers;
bool fix_item_rots;

struct {
int32_t layout;
Expand Down
42 changes: 41 additions & 1 deletion src/game/inject.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,21 @@
#include "game/packer.h"
#include "global/const.h"
#include "global/vars.h"
#include "items.h"
#include "log.h"
#include "memory.h"
#include "util.h"

#include <stddef.h>

#define INJECTION_MAGIC MKTAG('T', '1', 'M', 'J')
#define INJECTION_CURRENT_VERSION 3
#define INJECTION_CURRENT_VERSION 4

typedef enum INJECTION_VERSION {
INJ_VERSION_1 = 1,
INJ_VERSION_2 = 2,
INJ_VERSION_3 = 3,
INJ_VERSION_4 = 4,
} INJECTION_VERSION;

typedef enum INJECTION_TYPE {
Expand All @@ -30,6 +32,7 @@ typedef enum INJECTION_TYPE {
INJ_FLOOR_DATA = 4,
INJ_LARA_ANIMS = 5,
INJ_LARA_JUMPS = 6,
INJ_ITEM_ROTATION = 7,
} INJECTION_TYPE;

typedef struct INJECTION {
Expand Down Expand Up @@ -135,6 +138,8 @@ static int16_t *Inject_GetRoomFace(

static void Inject_RoomDoorEdits(INJECTION *injection);

static void Inject_ItemRotations(INJECTION *injection);

bool Inject_Init(
int num_injections, char *filenames[], INJECTION_INFO *aggregate)
{
Expand Down Expand Up @@ -199,6 +204,9 @@ static bool Inject_LoadFromFile(INJECTION *injection, const char *filename)
case INJ_LARA_JUMPS:
injection->relevant = g_Config.enable_tr2_jumping;
break;
case INJ_ITEM_ROTATION:
injection->relevant = g_Config.fix_item_rots;
break;
default:
injection->relevant = false;
LOG_WARNING("%s is of unknown type %d", filename, injection->type);
Expand Down Expand Up @@ -255,6 +263,12 @@ static bool Inject_LoadFromFile(INJECTION *injection, const char *filename)
info->anim_range_edit_count = 0;
}

if (injection->version > INJ_VERSION_3) {
File_Read(&info->item_rotation_count, sizeof(int32_t), 1, fp);
} else {
info->item_rotation_count = 0;
}

m_Aggregate->texture_page_count += info->texture_page_count;
m_Aggregate->texture_count += info->texture_count;
m_Aggregate->sprite_info_count += info->sprite_info_count;
Expand Down Expand Up @@ -314,6 +328,8 @@ bool Inject_AllInjections(LEVEL_INFO *level_info)
Inject_RoomDoorEdits(injection);
Inject_AnimRangeEdits(injection);

Inject_ItemRotations(injection);

// Realign base indices for the next injection.
INJECTION_INFO *inj_info = injection->info;
level_info->anim_command_count += inj_info->anim_cmd_count;
Expand Down Expand Up @@ -1484,6 +1500,30 @@ static void Inject_RoomDoorEdits(INJECTION *injection)
}
}

static void Inject_ItemRotations(INJECTION *injection)
{
if (injection->version < INJ_VERSION_4) {
return;
}

INJECTION_INFO *inj_info = injection->info;
MYFILE *fp = injection->fp;

int16_t item_num;
int16_t y_rot;
for (int i = 0; i < inj_info->item_rotation_count; i++) {
File_Read(&item_num, sizeof(int16_t), 1, fp);
File_Read(&y_rot, sizeof(int16_t), 1, fp);

if (item_num < 0 || item_num >= g_LevelItemCount) {
LOG_WARNING("Item number %d is out of level item range", item_num);
continue;
}

(&g_Items[item_num])->pos.y_rot = y_rot;
}
}

static void Inject_Cleanup(void)
{
for (int i = 0; i < m_NumInjections; i++) {
Expand Down
1 change: 1 addition & 0 deletions src/game/inject.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ typedef struct INJECTION_INFO {
int32_t room_mesh_edit_count;
int32_t room_door_edit_count;
int32_t anim_range_edit_count;
int32_t item_rotation_count;
} INJECTION_INFO;

bool Inject_Init(
Expand Down
1 change: 1 addition & 0 deletions src/game/objects/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ void Object_DrawPickupItem(ITEM_INFO *item)

Matrix_Push();
Matrix_TranslateAbs(item->pos.x, offset, item->pos.z);
Matrix_RotYXZ(item->pos.y_rot, item->pos.x_rot, item->pos.z_rot);

Output_CalculateLight(
item->pos.x, item->pos.y, item->pos.z, item->room_number);
Expand Down
24 changes: 16 additions & 8 deletions src/game/objects/general/pickup.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,21 +86,24 @@ void Pickup_Collision(int16_t item_num, ITEM_INFO *lara_item, COLL_INFO *coll)
}

ITEM_INFO *item = &g_Items[item_num];
int16_t rotx = item->pos.x_rot;
int16_t roty = item->pos.y_rot;
int16_t rotz = item->pos.z_rot;
item->pos.y_rot = lara_item->pos.y_rot;
item->pos.z_rot = 0;

if (g_Lara.water_status == LWS_ABOVE_WATER) {
item->pos.x_rot = 0;
if (!Lara_TestPosition(item, m_PickUpBounds)) {
return;
goto cleanup;
}

if (lara_item->current_anim_state == LS_PICKUP) {
if (lara_item->frame_number != LF_PICKUP_ERASE) {
return;
goto cleanup;
}
PickUp_GetAllAtLaraPos(item, lara_item);
return;
goto cleanup;
}

if (g_Input.action && g_Lara.gun_status == LGS_ARMLESS
Expand All @@ -110,30 +113,35 @@ void Pickup_Collision(int16_t item_num, ITEM_INFO *lara_item, COLL_INFO *coll)
Lara_AnimateUntil(lara_item, LS_PICKUP);
lara_item->goal_anim_state = LS_STOP;
g_Lara.gun_status = LGS_HANDS_BUSY;
return;
goto cleanup;
}
} else if (g_Lara.water_status == LWS_UNDERWATER) {
item->pos.x_rot = -25 * PHD_DEGREE;
if (!Lara_TestPosition(item, m_PickUpBoundsUW)) {
return;
goto cleanup;
}

if (lara_item->current_anim_state == LS_PICKUP) {
if (lara_item->frame_number != LF_PICKUP_UW) {
return;
goto cleanup;
}
PickUp_GetAllAtLaraPos(item, lara_item);
return;
goto cleanup;
}

if (g_Input.action && lara_item->current_anim_state == LS_TREAD) {
if (!Lara_MovePosition(item, &m_PickUpPositionUW)) {
return;
goto cleanup;
}
Lara_AnimateUntil(lara_item, LS_PICKUP);
lara_item->goal_anim_state = LS_TREAD;
}
}

cleanup:
item->pos.x_rot = rotx;
item->pos.y_rot = roty;
item->pos.z_rot = rotz;
}

void Pickup_CollisionControlled(
Expand Down
15 changes: 13 additions & 2 deletions src/game/objects/general/scion.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,15 @@ void Scion_Control3(int16_t item_num)
void Scion_Collision(int16_t item_num, ITEM_INFO *lara_item, COLL_INFO *coll)
{
ITEM_INFO *item = &g_Items[item_num];
int16_t rotx = item->pos.x_rot;
int16_t roty = item->pos.y_rot;
int16_t rotz = item->pos.z_rot;
item->pos.y_rot = lara_item->pos.y_rot;
item->pos.x_rot = 0;
item->pos.z_rot = 0;

if (!Lara_TestPosition(item, m_Scion_Bounds)) {
return;
goto cleanup;
}

if (lara_item->current_anim_state == LS_PICKUP) {
Expand All @@ -169,6 +172,10 @@ void Scion_Collision(int16_t item_num, ITEM_INFO *lara_item, COLL_INFO *coll)
g_CineFrame = 0;
g_CinePosition = lara_item->pos;
}
cleanup:
item->pos.x_rot = rotx;
item->pos.y_rot = roty;
item->pos.z_rot = rotz;
}

void Scion_Collision4(int16_t item_num, ITEM_INFO *lara_item, COLL_INFO *coll)
Expand All @@ -179,7 +186,7 @@ void Scion_Collision4(int16_t item_num, ITEM_INFO *lara_item, COLL_INFO *coll)
item->pos.z_rot = 0;

if (!Lara_TestPosition(item, m_Scion_Bounds4)) {
return;
goto cleanup;
}

if (g_Input.action && g_Lara.gun_status == LGS_ARMLESS
Expand All @@ -196,4 +203,8 @@ void Scion_Collision4(int16_t item_num, ITEM_INFO *lara_item, COLL_INFO *coll)
g_CinePosition = lara_item->pos;
g_CinePosition.y_rot -= PHD_90;
}
cleanup:
item->pos.x_rot = rotx;
item->pos.y_rot = roty;
item->pos.z_rot = rotz;
}
4 changes: 4 additions & 0 deletions tools/config/Tomb1Main_ConfigTool/Resources/Lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@
"Title": "Fix texture issues",
"Description": "Fixes original issues with missing or incorrect textures."
},
"fix_item_rots": {
"Title": "Fix item rotation issues",
"Description": "Fixes original issues with some incorrectly rotated pickups when using the 3D pickups option."
},
"fix_qwop_glitch": {
"Title": "Fix QWOP glitch",
"Description": "Fixes Lara jumping on small steps sometimes resulting in a weird running animation, known as a QWOP state."
Expand Down
Loading

0 comments on commit 8ed735d

Please sign in to comment.