Skip to content

Commit

Permalink
use injection for rotations and add .bins
Browse files Browse the repository at this point in the history
  • Loading branch information
walkawayy committed Aug 11, 2023
1 parent 8816345 commit 28a8923
Show file tree
Hide file tree
Showing 25 changed files with 60 additions and 119 deletions.
25 changes: 14 additions & 11 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 @@ -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
Expand All @@ -130,6 +128,7 @@
"type": "normal",
"music": 57,
"injections": [
"data/vilcabamba_itemrots.bin",
"data/vilcabamba_textures.bin",
],
"sequence": [
Expand All @@ -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,
},

Expand All @@ -156,6 +152,7 @@
"type": "normal",
"music": 57,
"injections": [
"data/valley_itemrots.bin",
"data/valley_textures.bin",
],
"sequence": [
Expand All @@ -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,
},

Expand All @@ -184,6 +176,7 @@
"music": 57,
"injections": [
"data/larson_textures.bin",
"data/qualopec_itemrots.bin",
"data/qualopec_textures.bin",
],
"sequence": [
Expand All @@ -202,6 +195,7 @@
"type": "normal",
"music": 59,
"injections": [
"data/folly_itemrots.bin",
"data/folly_textures.bin",
],
"sequence": [
Expand All @@ -228,6 +222,7 @@
"music": 59,
"injections": [
"data/colosseum_fd.bin",
"data/colosseum_itemrots.bin",
"data/colosseum_textures.bin",
],
"sequence": [
Expand All @@ -249,6 +244,7 @@
"type": "normal",
"music": 59,
"injections": [
"data/midas_itemrots.bin",
"data/midas_textures.bin",
],
"sequence": [
Expand All @@ -271,6 +267,7 @@
"type": "normal",
"music": 58,
"injections": [
"data/cistern_itemrots.bin",
"data/cistern_textures.bin",
],
"sequence": [
Expand All @@ -294,6 +291,7 @@
"type": "normal",
"music": 58,
"injections": [
"data/tihocan_itemrots.bin",
"data/tihocan_textures.bin",
],
"sequence": [
Expand Down Expand Up @@ -337,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 @@ -360,6 +361,7 @@
"type": "normal",
"music": 59,
"injections": [
"data/sanctuary_itemrots.bin",
"data/sanctuary_textures.bin",
],
"sequence": [
Expand All @@ -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"
],
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.
77 changes: 0 additions & 77 deletions src/game/gameflow.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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) {
Expand Down
11 changes: 0 additions & 11 deletions src/game/gameflow.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

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 = true;
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 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++) {
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
8 changes: 0 additions & 8 deletions src/game/items.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Loading

0 comments on commit 28a8923

Please sign in to comment.