From 28a89231c3e3a2c1f7f3e558adf16601594cc347 Mon Sep 17 00:00:00 2001 From: walkawayy <81546780+walkawayy@users.noreply.github.com> Date: Thu, 10 Aug 2023 21:31:25 -0400 Subject: [PATCH] use injection for rotations and add .bins --- bin/cfg/Tomb1Main_gameflow.json5 | 25 +++++---- bin/cfg/Tomb1Main_gameflow_ub.json5 | 3 ++ bin/data/cat_itemrots.bin | Bin 0 -> 892 bytes bin/data/caves_itemrots.bin | Bin 0 -> 884 bytes bin/data/cistern_itemrots.bin | Bin 0 -> 892 bytes bin/data/colosseum_itemrots.bin | Bin 0 -> 884 bytes bin/data/folly_itemrots.bin | Bin 0 -> 896 bytes bin/data/hive_itemrots.bin | Bin 0 -> 888 bytes bin/data/midas_itemrots.bin | Bin 0 -> 884 bytes bin/data/mines_itemrots.bin | Bin 0 -> 884 bytes bin/data/obelisk_itemrots.bin | Bin 0 -> 888 bytes bin/data/qualopec_itemrots.bin | Bin 0 -> 884 bytes bin/data/sanctuary_itemrots.bin | Bin 0 -> 896 bytes bin/data/stronghold_itemrots.bin | Bin 0 -> 892 bytes bin/data/tihocan_itemrots.bin | Bin 0 -> 892 bytes bin/data/valley_itemrots.bin | Bin 0 -> 892 bytes bin/data/vilcabamba_itemrots.bin | Bin 0 -> 884 bytes src/game/gameflow.c | 77 ---------------------------- src/game/gameflow.h | 11 ---- src/game/inject.c | 42 ++++++++++++++- src/game/inject.h | 1 + src/game/items.c | 8 --- src/game/items.h | 2 - src/game/level.c | 9 ---- src/game/objects/common.c | 1 + 25 files changed, 60 insertions(+), 119 deletions(-) create mode 100644 bin/data/cat_itemrots.bin create mode 100644 bin/data/caves_itemrots.bin create mode 100644 bin/data/cistern_itemrots.bin create mode 100644 bin/data/colosseum_itemrots.bin create mode 100644 bin/data/folly_itemrots.bin create mode 100644 bin/data/hive_itemrots.bin create mode 100644 bin/data/midas_itemrots.bin create mode 100644 bin/data/mines_itemrots.bin create mode 100644 bin/data/obelisk_itemrots.bin create mode 100644 bin/data/qualopec_itemrots.bin create mode 100644 bin/data/sanctuary_itemrots.bin create mode 100644 bin/data/stronghold_itemrots.bin create mode 100644 bin/data/tihocan_itemrots.bin create mode 100644 bin/data/valley_itemrots.bin create mode 100644 bin/data/vilcabamba_itemrots.bin diff --git a/bin/cfg/Tomb1Main_gameflow.json5 b/bin/cfg/Tomb1Main_gameflow.json5 index 6a37053fd..9669d3e49 100644 --- a/bin/cfg/Tomb1Main_gameflow.json5 +++ b/bin/cfg/Tomb1Main_gameflow.json5 @@ -107,6 +107,7 @@ "type": "normal", "music": 57, "injections": [ + "data/caves_itemrots.bin", "data/caves_textures.bin", ], "sequence": [ @@ -118,9 +119,6 @@ {"type": "exit_to_level", "level_id": 2}, ], "strings": {}, - "item_rotations": [ - {"item_num": 54, "x_rot": 180, "y_rot": 0, "z_rot": 0}, - ], }, // level 2 @@ -130,6 +128,7 @@ "type": "normal", "music": 57, "injections": [ + "data/vilcabamba_itemrots.bin", "data/vilcabamba_textures.bin", ], "sequence": [ @@ -143,9 +142,6 @@ "key1": "Silver Key", "puzzle1": "Gold Idol" }, - "item_rotations": [ - {"item_num": 4, "x_rot": -90, "y_rot": 0, "z_rot": 0}, - ], "demo": true, }, @@ -156,6 +152,7 @@ "type": "normal", "music": 57, "injections": [ + "data/valley_itemrots.bin", "data/valley_textures.bin", ], "sequence": [ @@ -168,11 +165,6 @@ "strings": { "puzzle1": "Machine Cog" }, - "item_rotations": [ - {"item_num": 40, "x_rot": 0, "y_rot": -90, "z_rot": 0}, - {"item_num": 59, "x_rot": 0, "y_rot": 180, "z_rot": 0}, - {"item_num": 14, "x_rot": 0, "y_rot": -90, "z_rot": 0}, - ], "demo": true, }, @@ -184,6 +176,7 @@ "music": 57, "injections": [ "data/larson_textures.bin", + "data/qualopec_itemrots.bin", "data/qualopec_textures.bin", ], "sequence": [ @@ -202,6 +195,7 @@ "type": "normal", "music": 59, "injections": [ + "data/folly_itemrots.bin", "data/folly_textures.bin", ], "sequence": [ @@ -228,6 +222,7 @@ "music": 59, "injections": [ "data/colosseum_fd.bin", + "data/colosseum_itemrots.bin", "data/colosseum_textures.bin", ], "sequence": [ @@ -249,6 +244,7 @@ "type": "normal", "music": 59, "injections": [ + "data/midas_itemrots.bin", "data/midas_textures.bin", ], "sequence": [ @@ -271,6 +267,7 @@ "type": "normal", "music": 58, "injections": [ + "data/cistern_itemrots.bin", "data/cistern_textures.bin", ], "sequence": [ @@ -294,6 +291,7 @@ "type": "normal", "music": 58, "injections": [ + "data/tihocan_itemrots.bin", "data/tihocan_textures.bin", ], "sequence": [ @@ -337,6 +335,9 @@ "file": "data/level8b.phd", "type": "normal", "music": 59, + "injections": [ + "data/obelisk_itemrots.bin", + ], "sequence": [ {"type": "start_game"}, {"type": "loop_game"}, @@ -360,6 +361,7 @@ "type": "normal", "music": 59, "injections": [ + "data/sanctuary_itemrots.bin", "data/sanctuary_textures.bin", ], "sequence": [ @@ -385,6 +387,7 @@ "injections": [ "data/cowboy_textures.bin", "data/kold_textures.bin", + "data/mines_itemrots.bin", "data/mines_textures.bin", "data/skateboardkid_textures.bin" ], diff --git a/bin/cfg/Tomb1Main_gameflow_ub.json5 b/bin/cfg/Tomb1Main_gameflow_ub.json5 index 9cd8e4162..fb408bac3 100644 --- a/bin/cfg/Tomb1Main_gameflow_ub.json5 +++ b/bin/cfg/Tomb1Main_gameflow_ub.json5 @@ -46,6 +46,7 @@ "type": "normal", "music": 59, "injections": [ + "data/cat_itemrots.bin", "data/cat_textures.bin", ], "sequence": [ @@ -66,6 +67,7 @@ "type": "normal", "music": 60, "injections": [ + "data/stronghold_itemrots.bin", "data/stronghold_textures.bin", ], "sequence": [ @@ -86,6 +88,7 @@ "type": "normal", "music": 60, "injections": [ + "data/hive_itemrots.bin", "data/hive_textures.bin", ], "sequence": [ diff --git a/bin/data/cat_itemrots.bin b/bin/data/cat_itemrots.bin new file mode 100644 index 0000000000000000000000000000000000000000..1be24fe5d2ad405d73bce77c0b5189846669688c GIT binary patch literal 892 rcmWGB^z~w4U|?VeVp;=cT3aw`{%8mc@(|ErU~rhpz;IwS149D<9^V8T literal 0 HcmV?d00001 diff --git a/bin/data/caves_itemrots.bin b/bin/data/caves_itemrots.bin new file mode 100644 index 0000000000000000000000000000000000000000..fa195a4ec08f6f953848ab1c7d1465ae096b7c66 GIT binary patch literal 884 jcmWGB^z~w4U|?VeVp;=6T3aw`{%8mc@(?g%U}yjU0Lua2 literal 0 HcmV?d00001 diff --git a/bin/data/cistern_itemrots.bin b/bin/data/cistern_itemrots.bin new file mode 100644 index 0000000000000000000000000000000000000000..0e633cde00d3669ce80e5fbc6a16c02115d824aa GIT binary patch literal 892 ocmWGB^z~w4U|?VeVp;=cT3aw`{%8mc@(@U2U^pNF#Ckvs03bsI6#xJL literal 0 HcmV?d00001 diff --git a/bin/data/colosseum_itemrots.bin b/bin/data/colosseum_itemrots.bin new file mode 100644 index 0000000000000000000000000000000000000000..66b6ceceab8dcfac3aa9b895bd282e8b4e5ec1a8 GIT binary patch literal 884 jcmWGB^z~w4U|?VeVp;=6T3aw`{%8mc@(?g$U^oB(0Q&+P literal 0 HcmV?d00001 diff --git a/bin/data/folly_itemrots.bin b/bin/data/folly_itemrots.bin new file mode 100644 index 0000000000000000000000000000000000000000..dab50716db89619ab7ec58abd55d98e0ebf0948d GIT binary patch literal 896 qcmWGB^z~w4U|?VeVp;=`J)>YW1V(ZQBrz}?$YNkE^KnwslR|QxA literal 0 HcmV?d00001 diff --git a/bin/data/hive_itemrots.bin b/bin/data/hive_itemrots.bin new file mode 100644 index 0000000000000000000000000000000000000000..8953b574747185c6f55b1480856b5ca6bc07324e GIT binary patch literal 888 lcmWGB^z~w4U|?VeVp;U~mv*U^oB(3Eu)r literal 0 HcmV?d00001 diff --git a/bin/data/qualopec_itemrots.bin b/bin/data/qualopec_itemrots.bin new file mode 100644 index 0000000000000000000000000000000000000000..1b2019933387f23d764972e0b78511383d2fc6dc GIT binary patch literal 884 jcmWGB^z~w4U|?VeVp;=6T3aw`{%8mc@(_?=U~m8c03!i~ literal 0 HcmV?d00001 diff --git a/bin/data/sanctuary_itemrots.bin b/bin/data/sanctuary_itemrots.bin new file mode 100644 index 0000000000000000000000000000000000000000..3d34b64e478276d21c63f2a037023eb2719ad113 GIT binary patch literal 896 ocmWGB^z~w4U|?VeVp;=`J)>YW1V(ZQm@zOMa0X&EAoc`e05o$26aWAK literal 0 HcmV?d00001 diff --git a/bin/data/stronghold_itemrots.bin b/bin/data/stronghold_itemrots.bin new file mode 100644 index 0000000000000000000000000000000000000000..e3168374293e538c9f7c1386e6a5fa1c9813f90f GIT binary patch literal 892 ocmWGB^z~w4U|?VeVp;=cT3aw`{%8mc@(|!+U}%^R#C|{w038DZq5uE@ literal 0 HcmV?d00001 diff --git a/bin/data/tihocan_itemrots.bin b/bin/data/tihocan_itemrots.bin new file mode 100644 index 0000000000000000000000000000000000000000..5ee92b1a40adcb0cd4ba516868b3d1298b07ac47 GIT binary patch literal 892 pcmWGB^z~w4U|?VeVp;=cT3aw`{%8mc@(|!+U}&&sU~q5*VgMLV0<{1D literal 0 HcmV?d00001 diff --git a/bin/data/valley_itemrots.bin b/bin/data/valley_itemrots.bin new file mode 100644 index 0000000000000000000000000000000000000000..1f5aeee5ab7cdd718358d84e32554f3611605c1f GIT binary patch literal 892 pcmWGB^z~w4U|?VeVp;=cT3aw`{%8mc@(|EqU^rmSz|g=4qyZeu1DpT= literal 0 HcmV?d00001 diff --git a/bin/data/vilcabamba_itemrots.bin b/bin/data/vilcabamba_itemrots.bin new file mode 100644 index 0000000000000000000000000000000000000000..a9e1e3646cad74b8e7e36b487ff79c81920a2529 GIT binary patch literal 884 icmWGB^z~w4U|?VeVp;=6T3aw`{%8mc@(=*#wF3YELjmmo literal 0 HcmV?d00001 diff --git a/src/game/gameflow.c b/src/game/gameflow.c index e97b23cff..fccc1253f 100644 --- a/src/game/gameflow.c +++ b/src/game/gameflow.c @@ -649,75 +649,6 @@ static bool GameFlow_LoadLevelSequence( return true; } -static bool GameFlow_LoadItemRots( - GAMEFLOW_LEVEL *cur, struct json_object_s *obj, int32_t level_num) -{ - struct json_array_s *jrot_arr = - json_object_get_array(obj, "item_rotations"); - if (!jrot_arr) { - cur->item_rots.length = 0; - return true; - } - - cur->item_rots.length = jrot_arr->length; - LOG_DEBUG("ROT item_rots.length %d", cur->item_rots.length); - cur->item_rots.rots = - Memory_Alloc(sizeof(GAMEFLOW_ITEM_ROT_DATA) * cur->item_rots.length); - - GAMEFLOW_ITEM_ROT_DATA *rots = cur->item_rots.rots; - struct json_array_element_s *jrot_elem = jrot_arr->start; - while (jrot_elem) { - struct json_object_s *jrot_obj = json_value_as_object(jrot_elem->value); - if (!jrot_obj) { - LOG_ERROR( - "level %d: 'item_rotations' elements must be dictionaries"); - return false; - } - - int item_num = - json_object_get_int(jrot_obj, "item_num", JSON_INVALID_NUMBER); - LOG_DEBUG("ROT read for item_num %d", item_num); - if (item_num == JSON_INVALID_NUMBER) { - LOG_ERROR("level %d: 'item_num' must be a number", level_num); - return false; - } - LOG_DEBUG("Read item_num %d", item_num); - rots->item_num = item_num; - - int32_t x_rot = - json_object_get_int(jrot_obj, "x_rot", JSON_INVALID_NUMBER); - if (x_rot == JSON_INVALID_NUMBER) { - LOG_ERROR("level %d: 'x_rot' must be a number", level_num); - return false; - } - LOG_DEBUG("Read x_rot %d", x_rot); - rots->x_rot = x_rot * PHD_DEGREE; - - int32_t y_rot = - json_object_get_int(jrot_obj, "y_rot", JSON_INVALID_NUMBER); - if (y_rot == JSON_INVALID_NUMBER) { - LOG_ERROR("level %d: 'y_rot' must be a number", level_num); - return false; - } - LOG_DEBUG("Read y_rot %d", y_rot); - rots->y_rot = y_rot * PHD_DEGREE; - - int32_t z_rot = - json_object_get_int(jrot_obj, "z_rot", JSON_INVALID_NUMBER); - if (z_rot == JSON_INVALID_NUMBER) { - LOG_ERROR("level %d: 'z_rot' must be a number", level_num); - return false; - } - LOG_DEBUG("Read z_rot %d", z_rot); - rots->z_rot = z_rot * PHD_DEGREE; - - jrot_elem = jrot_elem->next; - rots++; - } - - return true; -} - static bool GameFlow_LoadScriptLevels(struct json_object_s *obj) { struct json_array_s *jlvl_arr = json_object_get_array(obj, "levels"); @@ -983,10 +914,6 @@ static bool GameFlow_LoadScriptLevels(struct json_object_s *obj) cur->injections.length = 0; } - if (!GameFlow_LoadItemRots(cur, jlvl_obj, level_num)) { - return false; - } - tmp_i = json_object_get_int(jlvl_obj, "lara_type", (int32_t)O_LARA); if (tmp_i < 0 || tmp_i >= O_NUMBER_OF) { LOG_ERROR( @@ -1092,10 +1019,6 @@ void GameFlow_Shutdown(void) &g_GameFlow.levels[i].injections.data_paths[j]); } - for (int j = 0; j < g_GameFlow.levels[i].item_rots.length; j++) { - Memory_FreePointer(&g_GameFlow.levels[i].item_rots.rots[j]); - } - GAMEFLOW_SEQUENCE *seq = g_GameFlow.levels[i].sequence; if (seq) { while (seq->type != GFS_END) { diff --git a/src/game/gameflow.h b/src/game/gameflow.h index 839d9d997..7f5c1ca9c 100644 --- a/src/game/gameflow.h +++ b/src/game/gameflow.h @@ -15,13 +15,6 @@ typedef struct GAMEFLOW_SEQUENCE { void *data; } GAMEFLOW_SEQUENCE; -typedef struct GAMEFLOW_ITEM_ROT_DATA { - int16_t item_num; - int32_t x_rot; - int32_t y_rot; - int32_t z_rot; -} GAMEFLOW_ITEM_ROT_DATA; - typedef struct GAMEFLOW_LEVEL { GAMEFLOW_LEVEL_TYPE level_type; int16_t music; @@ -59,10 +52,6 @@ typedef struct GAMEFLOW_LEVEL { int length; char **data_paths; } injections; - struct { - int length; - GAMEFLOW_ITEM_ROT_DATA *rots; - } item_rots; GAME_OBJECT_ID lara_type; } GAMEFLOW_LEVEL; diff --git a/src/game/inject.c b/src/game/inject.c index 1cd1e0144..c5e2653dc 100644 --- a/src/game/inject.c +++ b/src/game/inject.c @@ -7,6 +7,7 @@ #include "game/packer.h" #include "global/const.h" #include "global/vars.h" +#include "items.h" #include "log.h" #include "memory.h" #include "util.h" @@ -14,12 +15,13 @@ #include #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 { @@ -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 { @@ -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) { @@ -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 = true; + break; default: injection->relevant = false; LOG_WARNING("%s is of unknown type %d", filename, injection->type); @@ -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; @@ -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; @@ -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 outwith 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++) { diff --git a/src/game/inject.h b/src/game/inject.h index 037ecbcf9..0f8cdf679 100644 --- a/src/game/inject.h +++ b/src/game/inject.h @@ -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( diff --git a/src/game/items.c b/src/game/items.c index 76afea375..881788efa 100644 --- a/src/game/items.c +++ b/src/game/items.c @@ -732,11 +732,3 @@ void Item_TakeDamage(ITEM_INFO *item, int16_t damage, bool hit_status) item->hit_status = 1; } } - -void Item_AdjustRot( - ITEM_INFO *item, int32_t x_rot, int32_t y_rot, int32_t z_rot) -{ - item->pos.x_rot = x_rot; - item->pos.y_rot = y_rot; - item->pos.z_rot = z_rot; -} diff --git a/src/game/items.h b/src/game/items.h index c255f2cb9..41c1f12c9 100644 --- a/src/game/items.h +++ b/src/game/items.h @@ -45,5 +45,3 @@ int16_t *Item_GetBoundsAccurate(ITEM_INFO *item); int32_t Item_GetFrames(ITEM_INFO *item, int16_t *frmptr[], int32_t *rate); void Item_TakeDamage(ITEM_INFO *item, int16_t damage, bool hit_status); -void Item_AdjustRot( - ITEM_INFO *item, int32_t x_rot, int32_t y_rot, int32_t z_rot); diff --git a/src/game/level.c b/src/game/level.c index 373e92017..edf5537d1 100644 --- a/src/game/level.c +++ b/src/game/level.c @@ -112,15 +112,6 @@ static bool Level_LoadFromFile(const char *filename, int32_t level_num) if (!Level_LoadItems(fp)) { return false; } - for (int i = 0; i < g_GameFlow.levels[level_num].item_rots.length; i++) { - GAMEFLOW_ITEM_ROT_DATA *rots = - &g_GameFlow.levels[level_num].item_rots.rots[i]; - LOG_DEBUG( - "Adjust rot of item num %d by %d %d %d", rots->item_num, - rots->x_rot, rots->y_rot, rots->z_rot); - Item_AdjustRot( - &g_Items[rots->item_num], rots->x_rot, rots->y_rot, rots->z_rot); - } Stats_ObserveItemsLoad(); if (!Level_LoadDepthQ(fp)) { diff --git a/src/game/objects/common.c b/src/game/objects/common.c index 1a1041c63..6ec475a22 100644 --- a/src/game/objects/common.c +++ b/src/game/objects/common.c @@ -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);