From 4aae3fb78d0085e9dcb57c01f5259ab315e54bc1 Mon Sep 17 00:00:00 2001 From: bnnm Date: Mon, 23 Jan 2023 00:50:19 +0100 Subject: [PATCH] Add PS3 .gtd [Knight's Contract (PS3)] --- src/formats.c | 2 +- src/meta/gtd.c | 50 ++++++++++++++++++++++++++++++++++++++++++------- src/meta/meta.h | 3 ++- src/vgmstream.c | 3 ++- src/vgmstream.h | 2 +- 5 files changed, 49 insertions(+), 11 deletions(-) diff --git a/src/formats.c b/src/formats.c index 527c4b66..9e1f6350 100644 --- a/src/formats.c +++ b/src/formats.c @@ -1248,7 +1248,7 @@ static const meta_info meta_info_list[] = { {meta_SXD, "Sony SXD header"}, {meta_OGL, "Shin'en OGL header"}, {meta_MC3, "Paradigm MC3 header"}, - {meta_GTD, "Hexadrive GHS/S_P_STH header"}, + {meta_GHS, "Hexadrive GHS/S_P_STH header"}, {meta_AAC_TRIACE, "tri-Ace AAC header"}, {meta_MTA2, "Konami MTA2 header"}, {meta_NGC_ULW, "Criterion ULW raw header"}, diff --git a/src/meta/gtd.c b/src/meta/gtd.c index bcee0370..254ac5ef 100644 --- a/src/meta/gtd.c +++ b/src/meta/gtd.c @@ -2,9 +2,9 @@ #include "../coding/coding.h" typedef enum { XMA2, ATRAC9 } gtd_codec; - -/* GTD - from Hexadrive's HexaEngine [Knights Contract (X360/PS3), Valhalla Knights 3 (Vita)] */ -VGMSTREAM* init_vgmstream_gtd(STREAMFILE* sf) { +//TODO rename gtd to ghs +/* GHS - Hexadrive's HexaEngine games [Knights Contract (X360), Valhalla Knights 3 (Vita)] */ +VGMSTREAM* init_vgmstream_ghs(STREAMFILE* sf) { VGMSTREAM* vgmstream = NULL; off_t start_offset, chunk_offset, stpr_offset, name_offset = 0, loop_start_offset, loop_end_offset; size_t data_size, chunk_size; @@ -36,7 +36,8 @@ VGMSTREAM* init_vgmstream_gtd(STREAMFILE* sf) { /* 0x34(18): null, 0x54(4): seek table offset, 0x58(4): seek table size, 0x5c(8): null, 0x64: seek table */ stpr_offset = read_32bitBE(chunk_offset+0x54,sf) + read_32bitBE(chunk_offset+0x58,sf); - if (read_32bitBE(stpr_offset,sf) == 0x53545052) { /* "STPR" */ + if (is_id32be(stpr_offset,sf, "STPR")) { + /* SRPR encases the original "S_P_STH" header (no data) */ name_offset = stpr_offset + 0xB8; /* there are offsets fields but seems to work */ } @@ -55,14 +56,14 @@ VGMSTREAM* init_vgmstream_gtd(STREAMFILE* sf) { /* 0x18-0x28: fixed/unknown values */ stpr_offset = 0x2c; - if (read_32bitBE(stpr_offset,sf) == 0x53545052) { /* "STPR" */ + if (is_id32be(stpr_offset,sf, "STPR")) { + /* STPR encases the original "S_P_STH" header (no data) */ name_offset = stpr_offset + 0xE8; /* there are offsets fields but seems to work */ } codec = ATRAC9; } else { - /* there is a PS3 variation with MSF inside */ goto fail; } @@ -75,7 +76,7 @@ VGMSTREAM* init_vgmstream_gtd(STREAMFILE* sf) { vgmstream->sample_rate = sample_rate; vgmstream->loop_start_sample = loop_start_sample; vgmstream->loop_end_sample = loop_end_sample; - vgmstream->meta_type = meta_GTD; + vgmstream->meta_type = meta_GHS; if (name_offset) //encoding is Shift-Jis in some PSV files read_string(vgmstream->stream_name,STREAM_NAME_SIZE, name_offset,sf); @@ -125,3 +126,38 @@ fail: close_vgmstream(vgmstream); return NULL; } + +/* S_P_STH - Hexadrive's HexaEngine games [Knights Contract (PS3)] */ +VGMSTREAM* init_vgmstream_s_p_sth(STREAMFILE* sf) { + VGMSTREAM* vgmstream = NULL; + STREAMFILE* temp_sf = NULL; + uint32_t subfile_offset, subfile_size, name_offset; + + + /* checks */ + if (!is_id64be(0x00,sf,"S_P_STH\x01")) + goto fail; + if (!check_extensions(sf,"gtd")) + goto fail; + + subfile_offset = read_u32be(0x08, sf); + subfile_size = get_streamfile_size(sf) - subfile_offset; + + temp_sf = setup_subfile_streamfile(sf, subfile_offset, subfile_size, "msf"); + if (!temp_sf) goto fail; + + vgmstream = init_vgmstream_msf(temp_sf); + if (!vgmstream) goto fail; + + vgmstream->meta_type = meta_GHS; + name_offset = 0xB0; /* there are offsets fields but seems to work */ + read_string(vgmstream->stream_name, STREAM_NAME_SIZE, name_offset, sf); + + close_streamfile(temp_sf); + return vgmstream; + +fail: + close_streamfile(temp_sf); + close_vgmstream(vgmstream); + return NULL; +} diff --git a/src/meta/meta.h b/src/meta/meta.h index 534a7793..5638866d 100644 --- a/src/meta/meta.h +++ b/src/meta/meta.h @@ -596,7 +596,8 @@ VGMSTREAM * init_vgmstream_ogl(STREAMFILE *streamFile); VGMSTREAM * init_vgmstream_mc3(STREAMFILE *streamFile); -VGMSTREAM * init_vgmstream_gtd(STREAMFILE *streamFile); +VGMSTREAM* init_vgmstream_ghs(STREAMFILE* sf); +VGMSTREAM* init_vgmstream_s_p_sth(STREAMFILE* sf); VGMSTREAM* init_vgmstream_aac_triace(STREAMFILE* sf); diff --git a/src/vgmstream.c b/src/vgmstream.c index e589f63e..27584085 100644 --- a/src/vgmstream.c +++ b/src/vgmstream.c @@ -294,7 +294,7 @@ VGMSTREAM* (*init_vgmstream_functions[])(STREAMFILE* sf) = { init_vgmstream_sxd, init_vgmstream_ogl, init_vgmstream_mc3, - init_vgmstream_gtd, + init_vgmstream_ghs, init_vgmstream_aac_triace, init_vgmstream_va3, init_vgmstream_mta2, @@ -524,6 +524,7 @@ VGMSTREAM* (*init_vgmstream_functions[])(STREAMFILE* sf) = { init_vgmstream_vab, init_vgmstream_bigrp, init_vgmstream_sscf_encrypted, + init_vgmstream_s_p_sth, /* lower priority metas (no clean header identity, somewhat ambiguous, or need extension/companion file to identify) */ init_vgmstream_scd_pcm, diff --git a/src/vgmstream.h b/src/vgmstream.h index 1cb088fb..1f6d989d 100644 --- a/src/vgmstream.h +++ b/src/vgmstream.h @@ -593,7 +593,7 @@ typedef enum { meta_SXD, /* Sony SXD (Gravity Rush, Freedom Wars PSV) */ meta_OGL, /* Shin'en Wii/WiiU (Jett Rocket (Wii), FAST Racing NEO (WiiU)) */ meta_MC3, /* Paradigm games (T3 PS2, MX Rider PS2, MI: Operation Surma PS2) */ - meta_GTD, + meta_GHS, meta_AAC_TRIACE, meta_MTA2, meta_NGC_ULW, /* Burnout 1 (GC only) */