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

#include <PTRB.h>

Public Member Functions

 PTRB (Endianess a_eEndianess=Endianess_Little)
 
 PTRB (Toshi::T2StringView filepath)
 
void Reset ()
 
TBOOL ReadFromFile (Toshi::T2StringView filepath)
 
TBOOL WriteToFile (Toshi::T2StringView filepath, TBOOL compress=false)
 
template<typename T>
ConvertEndianess (T a_numValue)
 
PTRBSymbolsGetSymbols ()
 
PTRBSectionsGetSections ()
 
Endianess GetEndianess () const
 

Static Public Attributes

static constexpr Toshi::TVersion VERSION = { TVERSION( 1, 1 ) }
 

Detailed Description

Definition at line 594 of file PTRB.h.

Constructor & Destructor Documentation

◆ PTRB() [1/2]

PTRB::PTRB ( Endianess a_eEndianess = Endianess_Little)
inline

Definition at line 600 of file PTRB.h.

601 : m_HDRX( VERSION )
602 , m_eEndianess( a_eEndianess )
603 {
604 m_SECT.SetEndianess( m_eEndianess );
605 }
static constexpr Toshi::TVersion VERSION
Definition PTRB.h:597

◆ PTRB() [2/2]

PTRB::PTRB ( Toshi::T2StringView filepath)
inline

Definition at line 607 of file PTRB.h.

608 : m_HDRX( VERSION ) { ReadFromFile( filepath ); }
TBOOL ReadFromFile(Toshi::T2StringView filepath)
Definition PTRB.h:617

Member Function Documentation

◆ ConvertEndianess()

template<typename T>
T PTRB::ConvertEndianess ( T a_numValue)
inline

Definition at line 714 of file PTRB.h.

715 {
716 return CONVERTENDIANESS( m_eEndianess, a_numValue );
717 }

◆ GetEndianess()

Endianess PTRB::GetEndianess ( ) const
inline

Definition at line 721 of file PTRB.h.

721{ return m_eEndianess; }

◆ GetSections()

PTRBSections * PTRB::GetSections ( )
inline

Definition at line 720 of file PTRB.h.

720{ return &m_SECT; }

◆ GetSymbols()

PTRBSymbols * PTRB::GetSymbols ( )
inline

Definition at line 719 of file PTRB.h.

719{ return &m_SYMB; }

◆ ReadFromFile()

TBOOL PTRB::ReadFromFile ( Toshi::T2StringView filepath)
inline

Definition at line 617 of file PTRB.h.

618 {
619 Reset();
620
621 Toshi::TTSFI ttsfi;
622 auto pFile = Toshi::TFile::Create( filepath.Get() );
623
624 m_eEndianess = -1;
625 if ( pFile && ttsfi.Open( pFile ) == Toshi::TTRB::ERROR_OK )
626 {
627 m_eEndianess = ttsfi.GetEndianess();
628 int32_t leftSize = ttsfi.GetCurrentHunk().Size - 4;
629
630 m_SECT.SetEndianess( m_eEndianess );
631
632 while ( leftSize > sizeof( Toshi::TTSF::Hunk ) )
633 {
634 if ( ttsfi.ReadHunk() != Toshi::TTRB::ERROR_OK ) break;
635 leftSize -= ttsfi.GetCurrentHunk().Size + sizeof( Toshi::TTSF::Hunk );
636
637 switch ( ttsfi.GetCurrentHunk().Name )
638 {
639 case TFourCC( "HDRX" ):
640 m_HDRX.Read( ttsfi, m_SECT, m_eEndianess );
641 break;
642 case TFourCC( "SECT" ):
643 m_SECT.Read( ttsfi, TFALSE, m_eEndianess );
644 break;
645 case TFourCC( "SECC" ):
646 m_SECT.Read( ttsfi, TTRUE, m_eEndianess );
647 break;
648 case TFourCC( "RELC" ):
649 m_RELC.Read( ttsfi, m_SECT, m_eEndianess );
650 break;
651 case TFourCC( "SYMB" ):
652 m_SYMB.Read( ttsfi, m_SECT, m_eEndianess );
653 break;
654 }
655
656 ttsfi.SkipHunk();
657 }
658
659 ttsfi.Close( TFALSE );
660 pFile->Destroy();
661 return TTRUE;
662 }
663
664 if ( pFile != TNULL )
665 {
666 ttsfi.Close( TFALSE );
667 pFile->Destroy();
668 }
669
670 return TFALSE;
671 }
TFORCEINLINE constexpr TUINT32 TFourCC(const TCHAR str[4])
Definition Helpers.h:15
#define TNULL
Definition Typedefs.h:23
#define TFALSE
Definition Typedefs.h:24
#define TTRUE
Definition Typedefs.h:25
void Reset()
Definition PTRB.h:610

◆ Reset()

void PTRB::Reset ( )
inline

Definition at line 610 of file PTRB.h.

611 {
612 m_SECT.Reset();
613 m_SYMB.Reset();
614 m_SECT.SetEndianess( m_eEndianess );
615 }

◆ WriteToFile()

TBOOL PTRB::WriteToFile ( Toshi::T2StringView filepath,
TBOOL compress = false )
inline

Definition at line 673 of file PTRB.h.

674 {
675 if ( m_eEndianess != -1 )
676 {
677 Toshi::TTSFO ttsfo;
678 Toshi::TTSFO::HunkMark mark;
679 ttsfo.Create( filepath, ( m_eEndianess == Endianess_Big ) ? "FBRT" : "TRBF", m_eEndianess );
680
681 // HDRX
682 ttsfo.OpenHunk( &mark, "HDRX" );
683 m_HDRX.SetSectionCount( m_SECT.GetStackCount() );
684 m_HDRX.Write( ttsfo, m_SECT, m_eEndianess );
685 ttsfo.CloseHunk( &mark );
686
687 // SECT
688 if ( compress )
689 Toshi::TCompress::ms_bIsBigEndian = ( m_eEndianess == Endianess_Big );
690
691 ttsfo.OpenHunk( &mark, compress ? "SECC" : "SECT" );
692 m_SECT.Write( ttsfo, compress );
693 ttsfo.CloseHunk( &mark );
694
695 // RELC
696 ttsfo.OpenHunk( &mark, "RELC" );
697 m_RELC.Write( ttsfo, m_SECT, m_eEndianess );
698 ttsfo.CloseHunk( &mark );
699
700 // SYMB
701 ttsfo.OpenHunk( &mark, "SYMB" );
702 m_SYMB.Write( ttsfo, m_eEndianess );
703 ttsfo.CloseHunk( &mark );
704
705 ttsfo.Close();
706
707 return TTRUE;
708 }
709
710 return TFALSE;
711 }
@ Endianess_Big
Definition Endianness.h:9

Member Data Documentation

◆ VERSION

Toshi::TVersion PTRB::VERSION = { TVERSION( 1, 1 ) }
staticconstexpr

Definition at line 597 of file PTRB.h.

597{ TVERSION( 1, 1 ) };
#define TVERSION(VER_MAJOR, VER_MINOR)
Definition Defines.h:14

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