main: Add EnsureWorldPakReady

This commit is contained in:
Luke Street 2022-04-11 18:42:08 -04:00
parent 7a95698329
commit 292dfa1eea
15 changed files with 119 additions and 54 deletions

View File

@ -99,7 +99,7 @@ PYTHON := python3
FRANK := tools/franklite.py FRANK := tools/franklite.py
# Options # Options
INCLUDES := -i include/ INCLUDES := -i include/ -i include/Kyoto_CWD/ -i include/rstl/
ASM_INCLUDES := -I include/ ASM_INCLUDES := -I include/
ASFLAGS := -mgekko $(ASM_INCLUDES) --defsym version=$(VERSION) ASFLAGS := -mgekko $(ASM_INCLUDES) --defsym version=$(VERSION)

View File

@ -50,7 +50,6 @@ private:
// TODO move to related headers // TODO move to related headers
extern unkptr gGuiSystem; extern unkptr gGuiSystem;
extern unkptr gpStringTable;
extern unkptr gpController; extern unkptr gpController;
extern unkptr gpDefaultFont; extern unkptr gpDefaultFont;

View File

@ -25,6 +25,8 @@ public:
CGameState& operator=(const CGameState&); CGameState& operator=(const CGameState&);
rstl::rc_ptr< CPlayerState >& PlayerState(); rstl::rc_ptr< CPlayerState >& PlayerState();
CAssetId CurrentWorldAssetId();
CSystemOptions& SystemOptions() { return xa8_systemOptions; } CSystemOptions& SystemOptions() { return xa8_systemOptions; }
CGameOptions& GameOptions() { return x17c_gameOptions; } CGameOptions& GameOptions() { return x17c_gameOptions; }
CHintOptions& HintOptions() { return x1f8_hintOptions; } CHintOptions& HintOptions() { return x1f8_hintOptions; }
@ -32,11 +34,6 @@ public:
u64& CardSerial() { return x210_cardSerial; } u64& CardSerial() { return x210_cardSerial; }
rstl::vector< u8 >& BackupBuf() { return x218_backupBuf; } rstl::vector< u8 >& BackupBuf() { return x218_backupBuf; }
void SetGameOptions(CGameOptions options) {
x17c_gameOptions = options;
x17c_gameOptions.EnsureOptions();
}
private: private:
rstl::reserved_vector< bool, 128 > x0_; rstl::reserved_vector< bool, 128 > x0_;
CAssetId x84_mlvlId; CAssetId x84_mlvlId;

View File

@ -13,6 +13,7 @@
#include "CStopwatch.hpp" #include "CStopwatch.hpp"
#include "CTweaks.hpp" #include "CTweaks.hpp"
#include "TReservedAverage.hpp" #include "TReservedAverage.hpp"
#include "TGameTypes.hpp"
class CMain { class CMain {
public: public:
@ -22,7 +23,6 @@ public:
void StreamNewGameState(CInputStream& in, int saveIdx); void StreamNewGameState(CInputStream& in, int saveIdx);
void RefreshGameState(); void RefreshGameState();
void AddWorldPaks(); void AddWorldPaks();
void EnsureWorldPaksReady();
void AsyncIdle(u32 time); void AsyncIdle(u32 time);
int RsMain(int argc, char** argv); int RsMain(int argc, char** argv);
void InitializeSubsystems(); void InitializeSubsystems();
@ -34,6 +34,9 @@ public:
bool CheckTerminate(); bool CheckTerminate();
bool CheckReset(); bool CheckReset();
static void EnsureWorldPaksReady();
static void EnsureWorldPakReady(CAssetId id);
private: private:
COsContext x0_osContext; COsContext x0_osContext;
u8 x6c_unk; u8 x6c_unk;

View File

@ -3,19 +3,36 @@
#include "types.h" #include "types.h"
#include "rstl/auto_ptr.hpp"
#include "rstl/string.hpp"
#include "CDvdFile.hpp" #include "CDvdFile.hpp"
#include "CResLoader.hpp"
#include "TGameTypes.hpp"
class CPakFile : CDvdFile { class CPakFile : CDvdFile {
public: public:
bool IsWorldPak() const { return x28_26_worldPak; } bool IsWorldPak() const { return x28_26_worldPak; }
void EnsureWorldPakReady(); void EnsureWorldPakReady();
void sub_8036742c();
rstl::vector< rstl::pair< rstl::string, SObjectTag > >& NameList() { return x54_nameList; }
private: private:
bool x28_24_buildDepList : 1; bool x28_24_buildDepList : 1;
bool x28_25_aramFile : 1; bool x28_25_aramFile : 1;
bool x28_26_worldPak : 1; bool x28_26_worldPak : 1;
bool x28_27_stashedInARAM : 1; bool x28_27_stashedInARAM : 1;
// TODO int x2c_asyncLoadPhase; // EAsyncPhase
rstl::auto_ptr< void > x30_dvdReq; // IDvdRequest
rstl::vector< u8 > x38_headerData;
u32 x48_resTableOffset;
u32 x4c_resTableCount;
s32 x50_aramBase;
rstl::vector< rstl::pair< rstl::string, SObjectTag > > x54_nameList;
rstl::vector< CAssetId > x64_depList;
rstl::vector< SResInfo > x74_resList;
mutable s32 x84_currentSeek;
}; };
#endif #endif

View File

@ -6,9 +6,10 @@
#include "rstl/list.hpp" #include "rstl/list.hpp"
#include "rstl/string.hpp" #include "rstl/string.hpp"
#include "CPakFile.hpp"
#include "TGameTypes.hpp" #include "TGameTypes.hpp"
class CPakFile;
struct SResInfo { struct SResInfo {
CAssetId x0_id; CAssetId x0_id;
bool x4_compressed : 1; bool x4_compressed : 1;
@ -19,9 +20,9 @@ struct SResInfo {
class CResLoader { class CResLoader {
public: public:
s32 GetPakCount(); s32 GetPakCount() const;
CPakFile& GetPakFile(s32 idx); CPakFile& GetPakFile(int idx) const;
void AddPakFileAsync(rstl::string&, bool, bool); void AddPakFileAsync(const rstl::string&, bool, bool);
void AsyncIdlePakLoading(); void AsyncIdlePakLoading();
bool AreAllPaksLoaded() const; bool AreAllPaksLoaded() const;

View File

@ -15,6 +15,7 @@ public:
s64 GetTimerFreq() const { return x0_timerFreq; } s64 GetTimerFreq() const { return x0_timerFreq; }
s64 GetTimerFreqO1M() const { return x8_timerFreqO1M; } s64 GetTimerFreqO1M() const { return x8_timerFreqO1M; }
f32 GetTimerPeriod() const { return x10_timerPeriod; } f32 GetTimerPeriod() const { return x10_timerPeriod; }
s64 GetCPUCycles() const { return OSGetTime(); }
private: private:
s64 x0_timerFreq; s64 x0_timerFreq;
@ -22,17 +23,17 @@ public:
f32 x10_timerPeriod; f32 x10_timerPeriod;
}; };
CStopwatch() : x0_startTime(OSGetTime()) {} CStopwatch() : x0_startTime(mData.GetCPUCycles()) {}
// static inline void InitGlobalTimer() {} // static inline void InitGlobalTimer() {}
// static inline CStopwatch& GetGlobalTimerObj() { return mGlobalTimer; } // static inline CStopwatch& GetGlobalTimerObj() { return mGlobalTimer; }
inline void Reset() { inline void Reset() {
if (mData.GetTimerFreq() == 0) { if (mData.GetTimerFreq() == 0) {
mData.Initialize(); mData.Initialize();
} }
x0_startTime = OSGetTime(); x0_startTime = mData.GetCPUCycles();
} }
inline float GetElapsedTime() const { return (OSGetTime() - x0_startTime) * mData.GetTimerPeriod(); } inline float GetElapsedTime() const { return (mData.GetCPUCycles() - x0_startTime) * mData.GetTimerPeriod(); }
inline s64 GetElapsedMicros() const { return (OSGetTime() - x0_startTime) / mData.GetTimerFreqO1M(); } inline s64 GetElapsedMicros() const { return (mData.GetCPUCycles() - x0_startTime) / mData.GetTimerFreqO1M(); }
private: private:
static CSWData mData; static CSWData mData;

View File

@ -15,4 +15,6 @@ public:
CStringTable(CInputStream& in); CStringTable(CInputStream& in);
}; };
extern CStringTable* gpStringTable;
#endif #endif

View File

@ -11,16 +11,21 @@ extern TAreaId kInvalidAreaId;
extern TEditorId kInvalidEditorId; extern TEditorId kInvalidEditorId;
extern TUniqueId kInvalidUniqueId; extern TUniqueId kInvalidUniqueId;
class CAssetId { typedef u32 CAssetId;
public: // class CAssetId {
u32 id; // public:
}; // u32 id;
struct SObjectTag { // bool operator==(const CAssetId& other) { return id == other.id; }
char type[4]; // };
u32 id;
};
#define FourCC unsigned long #define FourCC unsigned long
struct SObjectTag {
FourCC type;
CAssetId id;
SObjectTag(const SObjectTag& other) : type(other.type), id(other.id) {}
};
#endif #endif

19
include/rstl/auto_ptr.hpp Normal file
View File

@ -0,0 +1,19 @@
#ifndef _RSTL_AUTO_PTR_HPP
#define _RSTL_AUTO_PTR_HPP
#include "types.h"
namespace rstl {
template < typename T >
class auto_ptr {
bool x0_has;
T* x4_item;
public:
auto_ptr() : x0_has(false), x4_item(nullptr) {}
T* get() { return x4_item; }
T* operator->() { return get(); }
};
} // namespace rstl
#endif

View File

@ -6,7 +6,7 @@
namespace rstl { namespace rstl {
template < typename T > template < typename T >
inline void construct(void* dest, const T& src) { inline void construct(void* dest, const T& src) {
*static_cast< T* >(dest) = src; new(dest) T(src);
} }
template < typename T > template < typename T >
@ -32,14 +32,12 @@ inline void uninitialized_copy(Iter begin, Iter end, T* in) {
} }
} }
template < typename T > template < typename S, typename D >
inline void uninitialized_copy_n(T* dest, size_t count, T* src) { inline void uninitialized_copy_n(D* dest, S* src, size_t count) {
for (size_t i = 0; i < count; ++i) { for (size_t i = 0; i < count; ++dest, ++i, ++src) {
construct(dest, *src); construct(dest, *src);
destroy(src);
++dest;
++src;
} }
// destroy(src, src + count); ??
} }
} // namespace rstl } // namespace rstl

View File

@ -7,11 +7,13 @@ namespace rstl {
template < typename L, typename R > template < typename L, typename R >
class pair { class pair {
public: public:
L first;
R second;
inline pair() {} inline pair() {}
inline pair(const L& first, const R& second) : first(first), second(second) {} inline pair(const L& first, const R& second) : first(first), second(second) {}
inline pair(const pair& other) : first(other.first), second(other.second) {}
inline void operator=(const pair& other) { first = other.first; second = other.second; }
L first;
R second;
}; };
} // namespace rstl } // namespace rstl

View File

@ -8,8 +8,8 @@
namespace rstl { namespace rstl {
struct rmemory_allocator { struct rmemory_allocator {
template < typename T > template < typename T >
static void allocate(T*& out, size_t count) { static void allocate(T*& out, size_t sz) {
out = new T[count]; out = reinterpret_cast< T* >(new u8[sz]);
} }
template < typename T > template < typename T >
static void deallocate(T* ptr) { static void deallocate(T* ptr) {

View File

@ -30,26 +30,18 @@ public:
if (x4_count == 0 && x8_capacity == 0) { if (x4_count == 0 && x8_capacity == 0) {
xc_items = NULL; xc_items = NULL;
} else { } else {
if (x8_capacity == 0) { size_t sz = x8_capacity * sizeof(T);
if (sz == 0) {
xc_items = NULL; xc_items = NULL;
} else { } else {
Alloc::allocate(xc_items, x8_capacity); x0_allocator.allocate(xc_items, sz);
}
// what's going on here?
iterator iter;
const_iterator otherIter;
otherIter = other.begin();
iter = begin();
for (size_t i = 0; i < x4_count; ++i) {
iter = *otherIter;
++iter;
++otherIter;
} }
rstl::uninitialized_copy_n(data(), other.data(), x4_count);
} }
} }
~vector() { ~vector() {
rstl::destroy(begin(), end()); rstl::destroy(begin(), end());
Alloc::deallocate(xc_items); x0_allocator.deallocate(xc_items);
} }
void reserve(size_t size); /* { void reserve(size_t size); /* {

View File

@ -16,11 +16,13 @@
#include "Kyoto_CWD/CInGameTweakManager.hpp" #include "Kyoto_CWD/CInGameTweakManager.hpp"
#include "Kyoto_CWD/CMemoryCardSys.hpp" #include "Kyoto_CWD/CMemoryCardSys.hpp"
#include "Kyoto_CWD/CMemoryInStream.hpp" #include "Kyoto_CWD/CMemoryInStream.hpp"
#include "Kyoto_CWD/CPakFile.hpp"
#include "Kyoto_CWD/CPlayerState.hpp" #include "Kyoto_CWD/CPlayerState.hpp"
#include "Kyoto_CWD/CResFactory.hpp" #include "Kyoto_CWD/CResFactory.hpp"
#include "Kyoto_CWD/CSfxManager.hpp" #include "Kyoto_CWD/CSfxManager.hpp"
#include "Kyoto_CWD/CSimplePool.hpp" #include "Kyoto_CWD/CSimplePool.hpp"
#include "Kyoto_CWD/CStreamAudioManager.hpp" #include "Kyoto_CWD/CStreamAudioManager.hpp"
#include "Kyoto_CWD/CStringTable.hpp"
#include "Kyoto_CWD/CSystemOptions.hpp" #include "Kyoto_CWD/CSystemOptions.hpp"
#include "Kyoto_CWD/CTweakGame.hpp" #include "Kyoto_CWD/CTweakGame.hpp"
@ -38,7 +40,7 @@ CSimplePool* gpSimplePool;
CCubeRenderer* gpRender; CCubeRenderer* gpRender;
CCharacterFactoryBuilder* gpCharacterFactoryBuilder; CCharacterFactoryBuilder* gpCharacterFactoryBuilder;
unkptr gGuiSystem; unkptr gGuiSystem;
unkptr gpStringTable; CStringTable* gpStringTable;
CMain* gpMain; CMain* gpMain;
unkptr gpController; unkptr gpController;
CGameState* gpGameState; CGameState* gpGameState;
@ -78,7 +80,8 @@ void CMain::ResetGameState() {
x128_gameGlobalObjects->SetGameState(nullptr); x128_gameGlobalObjects->SetGameState(nullptr);
x128_gameGlobalObjects->SetGameState(new CGameState()); x128_gameGlobalObjects->SetGameState(new CGameState());
gpGameState->SystemOptions() = persistentOptions; gpGameState->SystemOptions() = persistentOptions;
gpGameState->SetGameOptions(gameOptions); gpGameState->GameOptions() = gameOptions;
gpGameState->GameOptions().EnsureOptions();
gpGameState->PlayerState()->SetIsFusionEnabled( gpGameState->PlayerState()->SetIsFusionEnabled(
gpGameState->SystemOptions().GetHasFusion()); gpGameState->SystemOptions().GetHasFusion());
} }
@ -109,7 +112,8 @@ void CMain::RefreshGameState() {
} }
// gpGameState = x128_gameGlobalObjects->x134_gameState.get(); // gpGameState = x128_gameGlobalObjects->x134_gameState.get();
gpGameState->SystemOptions() = systemOptions; gpGameState->SystemOptions() = systemOptions;
gpGameState->SetGameOptions(gameOptions); gpGameState->GameOptions() = gameOptions;
gpGameState->GameOptions().EnsureOptions();
gpGameState->CardSerial() = cardSerial; gpGameState->CardSerial() = cardSerial;
gpGameState->PlayerState()->SetIsFusionEnabled( gpGameState->PlayerState()->SetIsFusionEnabled(
gpGameState->SystemOptions().GetHasFusion()); gpGameState->SystemOptions().GetHasFusion());
@ -209,7 +213,8 @@ int CMain::RsMain(int argc, char** argv) {
if (lbl_805A8C54 != nullptr) { if (lbl_805A8C54 != nullptr) {
CMemoryInStream stream(lbl_805A8C54, 0x80); CMemoryInStream stream(lbl_805A8C54, 0x80);
stream.ReadBits(1); stream.ReadBits(1);
gpGameState->SetGameOptions(CGameOptions(stream)); gpGameState->GameOptions() = CGameOptions(stream);
gpGameState->GameOptions().EnsureOptions();
lbl_805A6BC0 = stream.ReadBits(1); lbl_805A6BC0 = stream.ReadBits(1);
} }
@ -300,3 +305,27 @@ int CMain::RsMain(int argc, char** argv) {
CARAMManager::Shutdown(); CARAMManager::Shutdown();
return 0; return 0;
} }
// 8036723C
void CMain::EnsureWorldPakReady(CAssetId id) {
CResLoader& resLoader = gpResourceFactory->GetResLoader();
for (int i = 0; i < resLoader.GetPakCount(); ++i) {
bool notInNameList = true;
CPakFile& pakFile = resLoader.GetPakFile(i);
if (pakFile.IsWorldPak()) {
rstl::vector< rstl::pair< rstl::string, SObjectTag > > nameList = pakFile.NameList();
rstl::vector< rstl::pair< rstl::string, SObjectTag > >::iterator cur = nameList.begin();
while (cur != nameList.end()) {
if (cur->second.id == id) {
notInNameList = false;
}
++cur;
}
if (notInNameList) {
pakFile.sub_8036742c();
} else {
pakFile.EnsureWorldPakReady();
}
}
}
}