OpenBarnyard
 
Loading...
Searching...
No Matches
TTSFI Class Reference

#include <TTRB.h>

Inheritance diagram for TTSFI:
TTSF

Public Member Functions

 TTSFI ()
 
 ~TTSFI ()
 
TUINT32 ReadAlignmentPad ()
 
TUINT32 Open (TFile *a_pFile)
 
TUINT32 Open (const TCHAR *a_szFilePath)
 
TUINT32 PushForm ()
 
TUINT32 PopForm ()
 
void ReadRaw (void *dst, TUINT32 size)
 
template<class T>
void Read (T *a_pDst)
 
template<class T>
void Read (T *a_pDst, TUINT a_uiCount)
 
TUINT8 ReadHunk ()
 
TUINT8 SkipHunk ()
 
TUINT8 ReadFORM (TFORM *section)
 
TUINT8 ReadHunkData (void *dest)
 
void Close (TBOOL free=true)
 
void ReadCompressed (void *buffer, TUINT32 size)
 
void CompressSection (TFile *file, TBYTE *data, TUINT32 unk2, TUINT32 unk3)
 
const HunkGetCurrentHunk () const
 
- Public Member Functions inherited from TTSF
 TTSF ()
 
 ~TTSF ()=default
 
Endianess GetEndianess () const
 

Friends

class TTRB
 

Additional Inherited Members

- Static Public Attributes inherited from TTSF
static constexpr TUINT32 IDMAGICB = TFourCC( "TSFB" )
 
static constexpr TUINT32 IDMAGICL = TFourCC( "TSFL" )
 
- Protected Attributes inherited from TTSF
Endianess m_Endianess
 
TFilem_pFile
 

Detailed Description

Definition at line 73 of file TTRB.h.

Constructor & Destructor Documentation

◆ TTSFI()

TTSFI::TTSFI ( )

Definition at line 186 of file TTSF.cpp.

187{
188 m_pFile = TNULL;
189 m_FileInfoCount = 0;
190 m_UNKFLAG = TFALSE;
191 m_ReadPos = 0;
192 TUtil::MemClear( m_FileInfo, sizeof( m_FileInfo ) );
193 m_Magic = 0;
194 m_CurrentHunk.Name = 0;
195 m_CurrentHunk.Size = 0;
196}
#define TNULL
Definition Typedefs.h:23
#define TFALSE
Definition Typedefs.h:24
TFile * m_pFile
Definition TTRB.h:70
static void MemClear(void *ptr, TSIZE size)
Definition TUtil.h:91

◆ ~TTSFI()

TTSFI::~TTSFI ( )
inline

Definition at line 80 of file TTRB.h.

80{ Close(); }
void Close(TBOOL free=true)
Definition TTSF.cpp:156

Member Function Documentation

◆ Close()

void TTSFI::Close ( TBOOL free = true)

Definition at line 156 of file TTSF.cpp.

157{
158 PopForm();
159
160 if ( m_pFile != TNULL && free )
161 {
162 m_pFile->Destroy();
163 }
164
165 m_pFile = TNULL;
166 m_FileInfoCount = 0;
167}
TUINT32 PopForm()
Definition TTSF.cpp:84

◆ CompressSection()

void TTSFI::CompressSection ( TFile * file,
TBYTE * data,
TUINT32 unk2,
TUINT32 unk3 )
inline

Definition at line 103 of file TTRB.h.

103{ TCompress::Compress( file, data, unk2, unk3, m_Endianess ); }
static size_t Compress(TFile *file, TBYTE *data, TUINT32 size, TUINT32 unused, TBOOL isBigEndian)
Endianess m_Endianess
Definition TTRB.h:69

◆ GetCurrentHunk()

const Hunk & TTSFI::GetCurrentHunk ( ) const
inline

Definition at line 105 of file TTRB.h.

105{ return m_CurrentHunk; }

◆ Open() [1/2]

TUINT32 TTSFI::Open ( const TCHAR * a_szFilePath)

Definition at line 58 of file TTSF.cpp.

59{
60 TFile* pFile = TFile::Create( a_szFilePath );
61 auto uiResult = Open( pFile );
62 m_UNKFLAG = TFALSE;
63 return uiResult;
64}
static TFile * Create(const TString8 &a_rcFilename, TFILEMODE a_eMode=TFILEMODE_READ)
Definition TFile.cpp:29
TUINT32 Open(TFile *a_pFile)
Definition TTSF.cpp:13

◆ Open() [2/2]

TUINT32 TTSFI::Open ( TFile * a_pFile)

Definition at line 13 of file TTSF.cpp.

14{
15 m_pFile = a_pFile;
16 m_FileInfoCount = 0;
17 m_UNKFLAG = TFALSE;
18
19 if ( m_pFile == TNULL )
20 {
22 }
23
24 m_UNKFLAG = TTRUE;
25
26 m_pFile->Read( &m_Header, sizeof( TTSFI::Header ) );
27
28 if ( m_Header.Magic == IDMAGICL )
29 {
31 }
32 else
33 {
34 if ( m_Header.Magic != IDMAGICB )
35 {
37 }
38
40 }
41
42 m_ReadPos += m_pFile->Read( &m_Magic, 4 );
43
45 {
46 m_Header.FileSize = PARSEDWORD_BIG( m_Header.FileSize );
47 m_Magic = PARSEDWORD_BIG( m_Magic );
48 }
49
50 m_CurrentHunk.Name = m_Header.Magic;
51 m_CurrentHunk.Size = m_Header.FileSize;
52 PushForm();
53
54 return TTRB::ERROR_OK;
55}
@ Endianess_Big
Definition Endianness.h:9
@ Endianess_Little
Definition Endianness.h:8
#define TTRUE
Definition Typedefs.h:25
static constexpr TUINT32 IDMAGICL
Definition TTRB.h:40
static constexpr TUINT32 IDMAGICB
Definition TTRB.h:39
TUINT32 PushForm()
Definition TTSF.cpp:67
@ ERROR_NOT_TRB
Definition TTRB.h:265
@ ERROR_OK
Definition TTRB.h:258
@ ERROR_NO_FILE
Definition TTRB.h:264

◆ PopForm()

TUINT32 TTSFI::PopForm ( )

Definition at line 84 of file TTSF.cpp.

85{
86 if ( m_FileInfoCount < 1 ) return TTRB::ERROR_NO_FILEINFO_ON_STACK;
87
88 m_FileInfoCount--;
89 auto& fileInfo = m_FileInfo[ m_FileInfoCount ];
90
91 m_CurrentHunk.Size = fileInfo.FileSize;
92 m_ReadPos = m_pFile->Tell() - fileInfo.FileStartOffset;
93
94 TUINT32 alignedPos = TAlignNumUp( m_CurrentHunk.Size );
95 m_pFile->Seek( alignedPos - m_ReadPos, TSEEK_CUR );
96 m_ReadPos = alignedPos;
97
98 return TTRB::ERROR_OK;
99}
@ TSEEK_CUR
Definition TFile.h:31
TFORCEINLINE constexpr T TAlignNumUp(T a_iValue, TSIZE a_uiAlignment=4)
Definition Helpers.h:66
uint32_t TUINT32
Definition Typedefs.h:13
@ ERROR_NO_FILEINFO_ON_STACK
Definition TTRB.h:266

◆ PushForm()

TUINT32 TTSFI::PushForm ( )

Definition at line 67 of file TTSF.cpp.

68{
69 if ( m_CurrentHunk.Name != TFourCC( "FORM" ) &&
70 m_CurrentHunk.Name != TFourCC( "TSFL" ) &&
71 m_CurrentHunk.Name != TFourCC( "TSFB" ) )
72 {
74 }
75
76 m_FileInfo[ m_FileInfoCount ].FileStartOffset = m_pFile->Tell() - 4;
77 m_FileInfo[ m_FileInfoCount ].FileSize = m_CurrentHunk.Size;
78 m_FileInfoCount++;
79
80 return TTRB::ERROR_OK;
81}
TFORCEINLINE constexpr TUINT32 TFourCC(const TCHAR str[4])
Definition Helpers.h:15
@ ERROR_WRONG_MAGIC
Definition TTRB.h:262

◆ Read() [1/2]

template<class T>
void TTSFI::Read ( T * a_pDst)
inline

Definition at line 92 of file TTRB.h.

92{ m_ReadPos += m_pFile->Read( a_pDst, sizeof( T ) ); }

◆ Read() [2/2]

template<class T>
void TTSFI::Read ( T * a_pDst,
TUINT a_uiCount )
inline

Definition at line 93 of file TTRB.h.

93{ m_ReadPos += m_pFile->Read( a_pDst, a_uiCount * sizeof( T ) ); }

◆ ReadAlignmentPad()

TUINT32 TTSFI::ReadAlignmentPad ( )

Definition at line 332 of file TTSF.cpp.

333{
334 TASSERT( m_pFile != TNULL, "File is TNULL" );
335
336 static TCHAR s_AlignBuffer[ 4 ];
337 TUINT8 alignValue = 4 - ( m_pFile->Tell() & 3 );
338
339 if ( alignValue != 4 )
340 {
341 return m_pFile->Read( s_AlignBuffer, alignValue );
342 }
343
344 return 0;
345}
#define TASSERT(X,...)
Definition Defines.h:138
char TCHAR
Definition Typedefs.h:20
uint8_t TUINT8
Definition Typedefs.h:17

◆ ReadCompressed()

void TTSFI::ReadCompressed ( void * buffer,
TUINT32 size )

Definition at line 170 of file TTSF.cpp.

171{
172 TCompress::Header header;
173
174 TUINT32 headerStart = m_pFile->Tell();
175 int8_t error = TCompress::GetHeader( m_pFile, header );
176
177 if ( error == TCOMPRESS_ERROR_OK )
178 {
179 TUINT32 headerSize = m_pFile->Tell() - headerStart;
180 TCompress::Decompress( m_pFile, &header, (TBYTE*)buffer, size );
181 m_ReadPos += header.CompressedSize + headerSize;
182 }
183}
@ TCOMPRESS_ERROR_OK
Definition TCompress.h:9
uint8_t TBYTE
Definition Typedefs.h:19
static uintptr_t Decompress(TFile *file, TCompress::Header *header, TBYTE *buffer, TUINT32 bufferSize)
static int8_t GetHeader(TFile *file, TCompress::Header &btecHeader)
TUINT32 CompressedSize
Definition TCompress.h:40

◆ ReadFORM()

TUINT8 TTSFI::ReadFORM ( TFORM * section)

Definition at line 128 of file TTSF.cpp.

129{
130 if ( m_CurrentHunk.Name != TFourCC( "FORM" ) )
131 {
133 }
134
135 m_ReadPos += m_pFile->Read( section, sizeof( TFORM ) );
136
137 return TTRB::ERROR_OK;
138}

◆ ReadHunk()

TUINT8 TTSFI::ReadHunk ( )

Definition at line 102 of file TTSF.cpp.

103{
104 m_pFile->Read( &m_CurrentHunk, sizeof( Hunk ) );
105
107 {
108 m_CurrentHunk.Name = PARSEDWORD_BIG( m_CurrentHunk.Name );
109 m_CurrentHunk.Size = PARSEDWORD_BIG( m_CurrentHunk.Size );
110 }
111
112 m_ReadPos = 0;
113
114 return TTRB::ERROR_OK;
115}

◆ ReadHunkData()

TUINT8 TTSFI::ReadHunkData ( void * dest)

Definition at line 141 of file TTSF.cpp.

142{
143 if ( m_CurrentHunk.Name == TFourCC( "FORM" ) )
144 {
146 }
147
148 TASSERT( m_ReadPos == 0, "m_ReadPos should be zero" );
149 m_ReadPos += m_pFile->Read( dst, m_CurrentHunk.Size );
150 m_ReadPos += TTSFI::ReadAlignmentPad();
151
152 return TTRB::ERROR_OK;
153}
TUINT32 ReadAlignmentPad()
Definition TTSF.cpp:332
@ ERROR_FORM_MAGIC
Definition TTRB.h:263

◆ ReadRaw()

void TTSFI::ReadRaw ( void * dst,
TUINT32 size )

Definition at line 347 of file TTSF.cpp.

348{
349 m_ReadPos += m_pFile->Read( dst, size );
350}

◆ SkipHunk()

TUINT8 TTSFI::SkipHunk ( )

Definition at line 118 of file TTSF.cpp.

119{
120 TUINT32 alignedSize = TAlignNumUp( m_CurrentHunk.Size );
121 m_pFile->Seek( alignedSize - m_ReadPos, TSEEK_CUR );
122 m_ReadPos = alignedSize;
123
124 return TTRB::ERROR_OK;
125}

Friends And Related Symbol Documentation

◆ TTRB

friend class TTRB
friend

Definition at line 76 of file TTRB.h.


The documentation for this class was generated from the following files: