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

#include <TTRB.h>

Classes

struct  Header
 
struct  RELCEntry
 
struct  SecInfo
 
struct  SYMB
 
struct  TTRBSymbol
 

Public Types

enum  ERROR_ : ERROR {
  ERROR_OK = 0 , ERROR_NO_HEADER = 1 , ERROR_NOT_TRBF = 2 , ERROR_PARSE_ERROR = 3 ,
  ERROR_WRONG_MAGIC = 4 , ERROR_FORM_MAGIC = 5 , ERROR_NO_FILE = 6 , ERROR_NOT_TRB = 7 ,
  ERROR_NO_FILEINFO_ON_STACK = 8
}
 
enum  AllocType_ : AllocType { AllocType_Unk0 = 0 , AllocType_Unk1 = 1 , AllocType_Unk2 = 2 }
 
typedef TUINT8 ERROR
 
typedef TUINT8 AllocType
 
using t_MemoryFuncAlloc = void* (*)( AllocType alloctype, TUINT32 size, TINT16 unk1, TUINT32 unk2, void* userData )
 
using t_MemoryFuncDealloc = void ( * )( AllocType alloctype, void* ptr, TINT16 unk1, TUINT32 unk2, void* userData )
 

Public Member Functions

 TTRB ()
 
 ~TTRB ()
 
ERROR Load (const TCHAR *a_szFilePath, TUINT32 a_uiUnknown=0)
 
TINT GetSymbolIndex (const TCHAR *symbName)
 
void * GetSymbolAddress (const TCHAR *symbName)
 
void * GetSymbolAddress (TTRBSymbol &symb)
 
void Close ()
 
template<typename T>
T * CastSymbol (const TCHAR *symbName)
 
SecInfoGetSectionInfoList () const
 
SecInfoGetSectionInfo (TINT index) const
 
TTRBSymbolGetSymbol (TINT index) const
 
TTRBSymbolGetSymbol (const TCHAR *a_symbolName)
 
const TCHARGetSymbolName (TINT index) const
 
const TCHARGetSymbolName (TTRBSymbol *symbol) const
 
TINT32 GetNumSymbols () const
 
SYMBGetSymbolTable () const
 
void DeleteSymbolTable ()
 
void SetMemoryFunctions (t_MemoryFuncAlloc allocator, t_MemoryFuncDealloc deallocator, void *userdata)
 

Static Public Member Functions

static TUINT32 GetHeaderSize (TUINT32 count)
 
static TUINT32 GetSymbolTableSize (TUINT32 count)
 
static TINT16 HashString (const TCHAR *str)
 

Detailed Description

Definition at line 252 of file TTRB.h.

Member Typedef Documentation

◆ AllocType

Definition at line 269 of file TTRB.h.

◆ ERROR

Definition at line 255 of file TTRB.h.

◆ t_MemoryFuncAlloc

using TTRB::t_MemoryFuncAlloc = void* (*)( AllocType alloctype, TUINT32 size, TINT16 unk1, TUINT32 unk2, void* userData )

Definition at line 277 of file TTRB.h.

◆ t_MemoryFuncDealloc

using TTRB::t_MemoryFuncDealloc = void ( * )( AllocType alloctype, void* ptr, TINT16 unk1, TUINT32 unk2, void* userData )

Definition at line 278 of file TTRB.h.

Member Enumeration Documentation

◆ AllocType_

Enumerator
AllocType_Unk0 
AllocType_Unk1 
AllocType_Unk2 

Definition at line 270 of file TTRB.h.

271 {
272 AllocType_Unk0 = 0,
273 AllocType_Unk1 = 1,
274 AllocType_Unk2 = 2,
275 };
@ AllocType_Unk0
Definition TTRB.h:272
@ AllocType_Unk1
Definition TTRB.h:273
@ AllocType_Unk2
Definition TTRB.h:274

◆ ERROR_

Enumerator
ERROR_OK 
ERROR_NO_HEADER 
ERROR_NOT_TRBF 
ERROR_PARSE_ERROR 
ERROR_WRONG_MAGIC 
ERROR_FORM_MAGIC 
ERROR_NO_FILE 
ERROR_NOT_TRB 
ERROR_NO_FILEINFO_ON_STACK 

Definition at line 256 of file TTRB.h.

257 {
258 ERROR_OK = 0,
259 ERROR_NO_HEADER = 1,
260 ERROR_NOT_TRBF = 2,
264 ERROR_NO_FILE = 6,
265 ERROR_NOT_TRB = 7,
267 };
@ ERROR_NOT_TRB
Definition TTRB.h:265
@ ERROR_NOT_TRBF
Definition TTRB.h:260
@ ERROR_WRONG_MAGIC
Definition TTRB.h:262
@ ERROR_FORM_MAGIC
Definition TTRB.h:263
@ ERROR_OK
Definition TTRB.h:258
@ ERROR_NO_FILE
Definition TTRB.h:264
@ ERROR_NO_FILEINFO_ON_STACK
Definition TTRB.h:266
@ ERROR_NO_HEADER
Definition TTRB.h:259
@ ERROR_PARSE_ERROR
Definition TTRB.h:261

Constructor & Destructor Documentation

◆ TTRB()

TTRB::TTRB ( )

Definition at line 24 of file TTRB.cpp.

25{
26 m_pHeader = TNULL;
27 m_SYMB = TNULL;
28 SetMemoryFunctions( s_cbDefAllocator, s_cbDefDeallocator, s_pDefAllocatorUserData );
29}
#define TNULL
Definition Typedefs.h:23
void SetMemoryFunctions(t_MemoryFuncAlloc allocator, t_MemoryFuncDealloc deallocator, void *userdata)
Definition TTRB.cpp:311

◆ ~TTRB()

TTRB::~TTRB ( )

Definition at line 32 of file TTRB.cpp.

33{
34 Close();
35}
void Close()
Definition TTRB.cpp:289

Member Function Documentation

◆ CastSymbol()

template<typename T>
T * TTRB::CastSymbol ( const TCHAR * symbName)
inline

Definition at line 334 of file TTRB.h.

334{ return TSTATICCAST( T, GetSymbolAddress( symbName ) ); }
#define TSTATICCAST(POINTERTYPE, VALUE)
Definition Defines.h:69
void * GetSymbolAddress(const TCHAR *symbName)
Definition TTRB.cpp:251

◆ Close()

void TTRB::Close ( )

Definition at line 289 of file TTRB.cpp.

290{
291 if ( m_pHeader != TNULL )
292 {
293 for ( TINT i = 0; i < m_pHeader->m_i32SectionCount; i++ )
294 {
295 auto sec = GetSectionInfo( i );
296
297 if ( sec->m_Data != TNULL )
298 {
299 m_MemDeallocator( AllocType_Unk1, sec->m_Data, sec->m_Unk1, sec->m_Unk2, m_MemUserData );
300 }
301 }
302
303 m_MemDeallocator( AllocType_Unk0, m_pHeader, 0, 0, m_MemUserData );
304 m_pHeader = TNULL;
305 }
306
308}
int TINT
Definition Typedefs.h:7
void DeleteSymbolTable()
Definition TTRB.cpp:319
SecInfo * GetSectionInfo(TINT index) const
Definition TTRB.h:337

◆ DeleteSymbolTable()

void TTRB::DeleteSymbolTable ( )

Definition at line 319 of file TTRB.cpp.

320{
321 if ( m_SYMB != TNULL )
322 {
323 m_MemDeallocator( AllocType_Unk2, m_SYMB, 0, 0, m_MemUserData );
324 m_SYMB = TNULL;
325 }
326}

◆ GetHeaderSize()

static TUINT32 TTRB::GetHeaderSize ( TUINT32 count)
inlinestatic

Definition at line 352 of file TTRB.h.

352{ return sizeof( SecInfo ) * count + sizeof( Header ); }

◆ GetNumSymbols()

TINT32 TTRB::GetNumSymbols ( ) const
inline

Definition at line 343 of file TTRB.h.

343{ return m_SYMB->m_i32SymbCount; }

◆ GetSectionInfo()

SecInfo * TTRB::GetSectionInfo ( TINT index) const
inline

Definition at line 337 of file TTRB.h.

337{ return GetSectionInfoList() + index; }
SecInfo * GetSectionInfoList() const
Definition TTRB.h:336

◆ GetSectionInfoList()

SecInfo * TTRB::GetSectionInfoList ( ) const
inline

Definition at line 336 of file TTRB.h.

336{ return reinterpret_cast<SecInfo*>( m_pHeader + 1 ); }

◆ GetSymbol() [1/2]

TTRB::TTRBSymbol * TTRB::GetSymbol ( const TCHAR * a_symbolName)

Definition at line 383 of file TTRB.cpp.

384{
385 TINT index = GetSymbolIndex( a_symbolName );
386 if ( index == -1 )
387 {
388 return TNULL;
389 }
390
391 return GetSymbol( index );
392}
TTRBSymbol * GetSymbol(TINT index) const
Definition TTRB.cpp:368
TINT GetSymbolIndex(const TCHAR *symbName)
Definition TTRB.cpp:265

◆ GetSymbol() [2/2]

TTRB::TTRBSymbol * TTRB::GetSymbol ( TINT index) const

Definition at line 368 of file TTRB.cpp.

369{
370 if ( m_SYMB == TNULL )
371 {
372 return TNULL;
373 }
374 else if ( index < m_SYMB->m_i32SymbCount )
375 {
376 return reinterpret_cast<TTRBSymbol*>( m_SYMB + 1 ) + index;
377 }
378
379 return TNULL;
380}

◆ GetSymbolAddress() [1/2]

void * TTRB::GetSymbolAddress ( const TCHAR * symbName)

Definition at line 251 of file TTRB.cpp.

252{
253 auto index = GetSymbolIndex( symbName );
254
255 if ( m_SYMB != TNULL && index != -1 && index < m_SYMB->m_i32SymbCount )
256 {
257 auto entry = GetSymbol( index );
258 return static_cast<TCHAR*>( GetSection( entry->HDRX ) ) + entry->DataOffset;
259 }
260
261 return TNULL;
262}
char TCHAR
Definition Typedefs.h:20

◆ GetSymbolAddress() [2/2]

void * TTRB::GetSymbolAddress ( TTRBSymbol & symb)
inline

Definition at line 328 of file TTRB.h.

328{ return static_cast<TCHAR*>( GetSection( symb.HDRX ) ) + symb.DataOffset; }

◆ GetSymbolIndex()

TINT TTRB::GetSymbolIndex ( const TCHAR * symbName)

Definition at line 265 of file TTRB.cpp.

266{
267 if ( m_SYMB != TNULL )
268 {
269 short hash = HashString( symbName );
270
271 for ( TINT i = 0; i < m_SYMB->m_i32SymbCount; i++ )
272 {
273 auto symbol = GetSymbol( i );
274
275 if ( symbol->NameHash == hash )
276 {
277 if ( Toshi::TStringManager::String8Compare( symbName, GetSymbolName( symbol ), -1 ) == 0 )
278 {
279 return i;
280 }
281 }
282 }
283 }
284
285 return -1;
286}
static TINT16 HashString(const TCHAR *str)
Definition TTRB.cpp:328
const TCHAR * GetSymbolName(TINT index) const
Definition TTRB.cpp:357

◆ GetSymbolName() [1/2]

const TCHAR * TTRB::GetSymbolName ( TINT index) const

Definition at line 357 of file TTRB.cpp.

358{
359 if ( m_SYMB == TNULL )
360 {
361 return TNULL;
362 }
363
364 return GetSymbolName( reinterpret_cast<TTRBSymbol*>( m_SYMB + 1 ) + index );
365}

◆ GetSymbolName() [2/2]

const TCHAR * TTRB::GetSymbolName ( TTRBSymbol * symbol) const

Definition at line 343 of file TTRB.cpp.

344{
345 if ( m_SYMB == TNULL )
346 {
347 return TNULL;
348 }
349
350 return reinterpret_cast<const TCHAR*>(
351 reinterpret_cast<uintptr_t>( m_SYMB ) +
352 GetSymbolTableSize( m_SYMB->m_i32SymbCount ) +
353 symbol->NameOffset
354 );
355}
static TUINT32 GetSymbolTableSize(TUINT32 count)
Definition TTRB.h:354

◆ GetSymbolTable()

SYMB * TTRB::GetSymbolTable ( ) const
inline

Definition at line 345 of file TTRB.h.

345{ return m_SYMB; }

◆ GetSymbolTableSize()

static TUINT32 TTRB::GetSymbolTableSize ( TUINT32 count)
inlinestatic

Definition at line 354 of file TTRB.h.

354{ return sizeof( TTRBSymbol ) * count + sizeof( SYMB ); }

◆ HashString()

TINT16 TTRB::HashString ( const TCHAR * str)
static

Definition at line 328 of file TTRB.cpp.

329{
330 TINT16 hash = 0;
331 TCHAR character;
332
333 while ( *str != '\0' )
334 {
335 character = *( str++ );
336 hash = (TINT16)character + hash * 0x1f;
337 }
338
339 return hash;
340}
int16_t TINT16
Definition Typedefs.h:14

◆ Load()

TTRB::ERROR TTRB::Load ( const TCHAR * a_szFilePath,
TUINT32 a_uiUnknown = 0 )

Definition at line 38 of file TTRB.cpp.

39{
41 ERROR error = m_TTSFI.Open( a_szFilePath );
42
43 if ( error == ERROR_OK )
44 {
45 if ( m_TTSFI.m_Magic == TFourCC( "TRBF" ) )
46 {
47 m_UNK = a_uiUnknown;
48
49 if ( ProcessForm( m_TTSFI ) )
50 {
51 error = ERROR_OK;
52 }
53 else
54 {
55 error = ERROR_PARSE_ERROR;
56 }
57 }
58 else
59 {
60 error = ERROR_NOT_TRBF;
61 }
62 }
63 else
64 {
65 error = ERROR_NO_HEADER;
66 }
67
68 m_TTSFI.Close();
69 return error;
70}
TFORCEINLINE constexpr TUINT32 TFourCC(const TCHAR str[4])
Definition Helpers.h:15
#define TPROFILER_SCOPE()
Definition Profiler.h:17
TUINT8 ERROR
Definition TTRB.h:255

◆ SetMemoryFunctions()

void TTRB::SetMemoryFunctions ( t_MemoryFuncAlloc allocator,
t_MemoryFuncDealloc deallocator,
void * userdata )

Definition at line 311 of file TTRB.cpp.

312{
313 m_MemAllocator = allocator;
314 m_MemDeallocator = deallocator;
315 m_MemUserData = userdata;
316}

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