From ae040aa688d6937ded96ea46e5ab804019d1ee85 Mon Sep 17 00:00:00 2001 From: jdflyer Date: Sat, 24 Dec 2022 12:47:48 -0700 Subject: [PATCH 1/6] Old JAudio changes --- Makefile | 5 +- include/JSystem/JAudio2/JAIAudible.h | 3 +- include/JSystem/JAudio2/JAIAudience.h | 4 +- include/JSystem/JAudio2/JAISound.h | 126 +++++++++++++--- include/JSystem/JAudio2/JAISoundParams.h | 6 +- include/JSystem/JAudio2/JASAudioReseter.h | 9 +- include/JSystem/JAudio2/JASAudioThread.h | 12 ++ include/JSystem/JAudio2/JASGadget.h | 13 +- include/JSystem/JAudio2/JASReport.h | 2 + include/JSystem/JAudio2/dspproc.h | 1 + include/Z2AudioLib/Z2Audience.h | 4 +- include/dolphin/dsp/dsp.h | 6 + include/m_Do/m_Do_audio.h | 12 +- libs/JSystem/JAudio2/JAISound.cpp | 167 ++++++++++++++-------- libs/JSystem/JAudio2/JASAudioReseter.cpp | 78 +++++----- libs/JSystem/JAudio2/JASAudioThread.cpp | 12 -- libs/JSystem/JAudio2/dspproc.cpp | 61 +++++--- libs/Z2AudioLib/Z2Audience.cpp | 4 +- libs/Z2AudioLib/Z2SceneMgr.cpp | 14 +- src/m_Do/m_Do_main.cpp | 3 + 20 files changed, 365 insertions(+), 177 deletions(-) diff --git a/Makefile b/Makefile index 29a48139249..1929850be58 100644 --- a/Makefile +++ b/Makefile @@ -45,11 +45,13 @@ include obj_files.mk MWCC_VERSION := 2.7 # Programs +ifeq ($(WINE),) #if WINE varible is unset (wine can be replaced with a less bloated translation layer such as wibo if needed) ifeq ($(WINDOWS),1) WINE := else WINE := wine endif +endif # Hack for OSX ifeq ($(UNAME_S),Darwin) @@ -168,7 +170,8 @@ $(DOL_SHIFT): $(ELF_SHIFT) | tools shift: dirs $(DOL_SHIFT) -game: | shift rels +game: shift + $(MAKE) rels @mkdir -p game @$(PYTHON) tools/package_game_assets.py game $(BUILD_DIR) diff --git a/include/JSystem/JAudio2/JAIAudible.h b/include/JSystem/JAudio2/JAIAudible.h index d42029bec94..047b9132953 100644 --- a/include/JSystem/JAudio2/JAIAudible.h +++ b/include/JSystem/JAudio2/JAIAudible.h @@ -2,10 +2,11 @@ #define JAIAUDIBLE_H #include "dolphin/types.h" +#include "JSystem/JAudio2/JASSoundParams.h" struct JAIAudible { virtual ~JAIAudible(); - virtual void getOuterParams(int) = 0; + virtual JASSoundParams* getOuterParams(int) = 0; virtual void calc() = 0; }; diff --git a/include/JSystem/JAudio2/JAIAudience.h b/include/JSystem/JAudio2/JAIAudience.h index 2f2586bf2d0..1621386ad8a 100644 --- a/include/JSystem/JAudio2/JAIAudience.h +++ b/include/JSystem/JAudio2/JAIAudience.h @@ -13,9 +13,9 @@ struct JAIAudience { virtual ~JAIAudience(); virtual JAIAudible* newAudible(JGeometry::TVec3 const&, JAISoundID, JGeometry::TVec3 const*, u32) = 0; - virtual void getMaxChannels() = 0; + virtual int getMaxChannels() = 0; virtual void deleteAudible(JAIAudible*) = 0; - virtual void calcPriority(JAIAudible*) = 0; + virtual u32 calcPriority(JAIAudible*) = 0; virtual void mixChannelOut(JASSoundParams const&, JAIAudible*, int) = 0; }; diff --git a/include/JSystem/JAudio2/JAISound.h b/include/JSystem/JAudio2/JAISound.h index 61bac44a425..1fd0f4f9c94 100644 --- a/include/JSystem/JAudio2/JAISound.h +++ b/include/JSystem/JAudio2/JAISound.h @@ -11,11 +11,11 @@ class JAISoundID { public: operator u32() const { return this->mId; } - void operator=(JAISoundID const&); + void operator=(JAISoundID const& other) {mId = other.mId;}; JAISoundID(u32 pId) { mId = pId; }; - JAISoundID(JAISoundID const& other); + JAISoundID(JAISoundID const& other) {mId = other.mId;}; JAISoundID() {} @@ -29,6 +29,13 @@ struct JASTrack { /* 80291C30 */ void openChild(u32); /* 80292918 */ void writePort(u32, u16); /* 8029297C */ void readPort(u32); + + inline int getChannelMgrCount() { + return channelMgrCount; + } + + /* 0x0 */u8 field_0x0[0x1d0]; + /* 0x1d0 */ int channelMgrCount; }; struct JAISoundStatus_ { @@ -36,26 +43,92 @@ struct JAISoundStatus_ { /* 802A2244 */ s32 unlockIfLocked(); void init() { - field_0x0 = 0; - field_0x1 = 0; - *((u16*)(this) + 2) = 0; + field_0x0.value = 0; + field_0x1.value = 0; + *((u16*)&state) = 0; user_data = 0; } - /* 0x0 */ u8 field_0x0; - /* 0x1 */ u8 field_0x1; - /* 0x2 */ u8 state[2]; // debug accesses like "state.flags.calcedOnce" + bool isAlive(); //used in assert + + inline bool isPlaying() { + return state.unk==5; + } + + inline bool isPaused() { + return field_0x0.flags.paused; + } + + /* 0x0 */ union { + u8 value; + struct{ + u8 flag1:1; + u8 paused:1; + u8 flag3:1; + u8 flag4:1; + u8 flag5:1; + u8 flag6:1; + u8 flag7:1; + u8 flag8:1; + }flags; + }field_0x0; + /* 0x1 */ union { + u8 value; + struct{ + u8 flag1:1; + u8 flag2:1; + u8 flag3:1; + u8 flag4:1; + u8 flag5:1; + u8 flag6:1; + u8 flag7:1; + u8 flag8:1; + }flags; + }field_0x1; + /* 0x2 */ struct { + u8 unk; + struct { + u8 flag1:1; + u8 flag2:1; + u8 flag3:1; + u8 flag4:1; + u8 flag5:1; + u8 flag6:1; + u8 flag7:1; + u8 flag8:1; + }flags; + } state; /* 0x4 */ u32 user_data; }; // Size: 0x6 struct JAISoundFader { void forceIn() { mIntensity = 1.0f; - field_0x4.zero(); + mTransition.zero(); + } + inline void forceOut() { + mIntensity = 0.0f; + mTransition.zero(); + } + inline void fadeOut(u32 fadeCount) { + if (fadeCount!=0) { + mTransition.set(0.0f,mIntensity,fadeCount); + }else{ + forceOut(); + } + } + inline bool isOut() { + if(mTransition.mCount!=0||mIntensity<0.01f) { + return true; + } + return false; + } + inline void calc() { + mIntensity = mTransition.apply(mIntensity); } /* 0x00 */ f32 mIntensity; - /* 0x04 */ JAISoundParamsTransition::TTransition field_0x4; + /* 0x04 */ JAISoundParamsTransition::TTransition mTransition; }; // Size: 0x10 template @@ -88,29 +161,50 @@ public: JAIAudience*); /* 802A2598 */ void stop(); /* 802A24DC */ void stop(u32 fadeout); - /* 802A25D8 */ bool asSe(); - /* 802A25E0 */ bool asSeq(); - /* 802A25E8 */ bool asStream(); /* 802A25F0 */ void die_JAISound_(); /* 802A266C */ void increasePrepareCount_JAISound_(); - /* 802A26B8 */ void calc_JAISound_(); + /* 802A26B8 */ bool calc_JAISound_(); /* 802A29DC */ void initTrack_JAISound_(JASTrack*); virtual void getNumChild() = 0; + virtual void getChild() = 0; + virtual void releaseChild() = 0; + /* 802A25D8 */ virtual bool asSe(); + /* 802A25E0 */ virtual bool asSeq(); + /* 802A25E8 */ virtual bool asStream(); + virtual void getTrack() = 0; + virtual void getChildTrack() = 0; + virtual void getTempoMgr() = 0; + virtual bool JAISound_tryDie_() = 0; JAISoundID getID() const; u32 getUserData() const { return status_.user_data; } bool isHandleAttached() const { return handle_ != NULL; } + inline void removeLifeTime_() { + status_.field_0x1.flags.flag1 = false; + } + inline void stop_JAISound_() { + status_.state.flags.flag5 = 0; + status_.state.flags.flag1 = 1; + } + inline bool isStopping() { + bool isStopping = false; + if(status_.state.flags.flag1) { + isStopping = status_.state.flags.flag5 ? fader.isOut() : true; + } + return isStopping; + } + /* 0x04 */ JAISoundHandle* handle_; /* 0x08 */ JAIAudible* audible_; /* 0x0C */ JAIAudience* audience_; - /* 0x10 */ s32 lifeTime; + /* 0x10 */ u32 lifeTime; /* 0x14 */ s32 prepareCount; /* 0x18 */ JAISoundID soundID; /* 0x1C */ JAISoundStatus_ status_; /* 0x24 */ JAISoundFader fader; - /* 0x34 */ s32 field_0x34; + /* 0x34 */ s32 mPriority; /* 0x38 */ s32 mCount; /* 0x3C */ JAISoundParams params; }; // Size: 0x98 diff --git a/include/JSystem/JAudio2/JAISoundParams.h b/include/JSystem/JAudio2/JAISoundParams.h index 6984c0a912d..f9befe83e08 100644 --- a/include/JSystem/JAudio2/JAISoundParams.h +++ b/include/JSystem/JAudio2/JAISoundParams.h @@ -24,9 +24,9 @@ struct JAISoundParamsTransition { field_0x4 = 0.0f; } - void set(f32 newValue, f32 param_1, u32 param_2) { - mCount = param_2; - field_0x0 = (newValue - param_1) / mCount; + void set(f32 newValue, f32 intensity, u32 fadeCount) { + mCount = fadeCount; + field_0x0 = (newValue - intensity) / mCount; field_0x4 = newValue; } diff --git a/include/JSystem/JAudio2/JASAudioReseter.h b/include/JSystem/JAudio2/JASAudioReseter.h index 25e6af4a336..66d466f3f51 100644 --- a/include/JSystem/JAudio2/JASAudioReseter.h +++ b/include/JSystem/JAudio2/JASAudioReseter.h @@ -3,6 +3,13 @@ #include "JSystem/JAudio2/JASDriverIF.h" #include "dolphin/types.h" +#include "dolphin/os/OS.h" + +struct JASCriticalSection { + inline JASCriticalSection() {mInterruptState = OSDisableInterrupts();}; + inline ~JASCriticalSection() {OSRestoreInterrupts(mInterruptState);}; + u32 mInterruptState; +}; struct JASAudioReseter { /* 8029D0B4 */ JASAudioReseter(); @@ -10,7 +17,7 @@ struct JASAudioReseter { /* 8029D138 */ bool start(u32, bool); /* 8029D1D4 */ void resume(); /* 8029D1F8 */ s32 checkDone() const; - /* 8029D200 */ static s32 calc(); + /* 8029D200 */ s32 calc(); /* 8029D2D4 */ static s32 callback(void*); /* 0x0 */ u32 field_0x0; diff --git a/include/JSystem/JAudio2/JASAudioThread.h b/include/JSystem/JAudio2/JASAudioThread.h index 2ed9d02f549..e8da1c883b6 100644 --- a/include/JSystem/JAudio2/JASAudioThread.h +++ b/include/JSystem/JAudio2/JASAudioThread.h @@ -3,4 +3,16 @@ #include "dolphin/types.h" +struct JASAudioThread { + /* 8029CCDC */ JASAudioThread(int, int, u32); + /* 8029CD4C */ void create(s32); + /* 8029CDC0 */ void stop(); + /* 8029CDEC */ void run(); + /* 8029CF68 */ void DMACallback(); + /* 8029CFBC */ void DSPCallback(void*); + /* 8029D028 */ ~JASAudioThread(); + + static u8 snIntCount[4 + 4 /* padding */]; +}; + #endif /* JASAUDIOTHREAD_H */ diff --git a/include/JSystem/JAudio2/JASGadget.h b/include/JSystem/JAudio2/JASGadget.h index 6edcf6961a5..811aeacb3bd 100644 --- a/include/JSystem/JAudio2/JASGadget.h +++ b/include/JSystem/JAudio2/JASGadget.h @@ -6,9 +6,18 @@ template class JASGlobalInstance { public: - // T* getInstance() { return sInstance; } + T* getInstance() { return sInstance; } - // static T* sInstance; + JASGlobalInstance(bool param) { + if (param) { + ASSERT(sInstance == 0); + if (this!=NULL) { + sInstance = this - sizeof(T); + } + } + } + + static T* sInstance; }; #endif /* JASGADGET_H */ diff --git a/include/JSystem/JAudio2/JASReport.h b/include/JSystem/JAudio2/JASReport.h index 6f0c1a0fae5..86b0944e835 100644 --- a/include/JSystem/JAudio2/JASReport.h +++ b/include/JSystem/JAudio2/JASReport.h @@ -3,4 +3,6 @@ #include "dolphin/types.h" +void JASReport(const char* message, ...); + #endif /* JASREPORT_H */ diff --git a/include/JSystem/JAudio2/dspproc.h b/include/JSystem/JAudio2/dspproc.h index e624638ec31..5f1c5304954 100644 --- a/include/JSystem/JAudio2/dspproc.h +++ b/include/JSystem/JAudio2/dspproc.h @@ -2,5 +2,6 @@ #define DSPPROC_H #include "dolphin/types.h" +#include "dolphin/dsp/dsp.h" #endif /* DSPPROC_H */ diff --git a/include/Z2AudioLib/Z2Audience.h b/include/Z2AudioLib/Z2Audience.h index d3ea344af88..a3af8c114d3 100644 --- a/include/Z2AudioLib/Z2Audience.h +++ b/include/Z2AudioLib/Z2Audience.h @@ -121,9 +121,9 @@ struct Z2Audience : public JAIAudience { /* 802BD1FC */ virtual ~Z2Audience(); /* 802BD338 */ virtual JAIAudible* newAudible(JGeometry::TVec3 const&, JAISoundID, JGeometry::TVec3 const*, u32); - /* 802BDED4 */ virtual void getMaxChannels(); + /* 802BDED4 */ virtual int getMaxChannels(); /* 802BD4D4 */ virtual void deleteAudible(JAIAudible*); - /* 802BD5B8 */ virtual void calcPriority(JAIAudible*); + /* 802BD5B8 */ virtual u32 calcPriority(JAIAudible*); /* 802BD71C */ virtual void mixChannelOut(JASSoundParams const&, JAIAudible*, int); /* 0x004 */ f32 field_0x4; diff --git a/include/dolphin/dsp/dsp.h b/include/dolphin/dsp/dsp.h index f7cb94b2912..65c00614896 100644 --- a/include/dolphin/dsp/dsp.h +++ b/include/dolphin/dsp/dsp.h @@ -3,4 +3,10 @@ #include "dolphin/types.h" +void DSPReleaseHalt2(u32 msg); +u16 DSP_CreateMap2(u32 msg); +void DSPSendCommands2(u32* msgs, u32 param_1, void (*param_2)(u16)); +void DsetupTable(u32 param_0, u32 param_1, u32 param_2, u32 param_3, u32 param_4); +void DsetMixerLevel(f32 level); + #endif /* DSP_H */ diff --git a/include/m_Do/m_Do_audio.h b/include/m_Do/m_Do_audio.h index 3cc4b621608..898f8344891 100644 --- a/include/m_Do/m_Do_audio.h +++ b/include/m_Do/m_Do_audio.h @@ -1,18 +1,10 @@ #ifndef M_DO_M_DO_AUDIO_H #define M_DO_M_DO_AUDIO_H +#include "dolphin/types.h" +#include "JSystem/JAudio2/JASGadget.h" #include "Z2AudioLib/Z2AudioMgr.h" #include "Z2AudioLib/Z2EnvSeMgr.h" -#include "dolphin/types.h" - -// move/fix later -template -class JASGlobalInstance { -public: - T* getInstance() { return sInstance; }; - - static T* sInstance; -}; class mDoAud_zelAudio_c { public: diff --git a/libs/JSystem/JAudio2/JAISound.cpp b/libs/JSystem/JAudio2/JAISound.cpp index 2f943947c1e..9f9e3162d1e 100644 --- a/libs/JSystem/JAudio2/JAISound.cpp +++ b/libs/JSystem/JAudio2/JAISound.cpp @@ -6,6 +6,7 @@ #include "JSystem/JAudio2/JAISound.h" #include "dol2asm.h" #include "dolphin/types.h" +#include "JSystem/JAudio2/JASReport.h" // // Forward References: @@ -79,8 +80,8 @@ void JAISound::attachHandle(JAISoundHandle* handle) { /* 802A2220-802A2244 29CB60 0024+00 0/0 2/2 0/0 .text lockWhenPrepared__15JAISoundStatus_Fv */ s32 JAISoundStatus_::lockWhenPrepared() { - if (state[0] == 0) { - state[0] = 1; + if (state.unk == 0) { + state.unk = 1; return 1; } return 0; @@ -89,12 +90,12 @@ s32 JAISoundStatus_::lockWhenPrepared() { /* 802A2244-802A2280 29CB84 003C+00 0/0 2/2 0/0 .text unlockIfLocked__15JAISoundStatus_Fv */ s32 JAISoundStatus_::unlockIfLocked() { - if (state[0] == 3) { - state[0] = 4; + if (state.unk == 3) { + state.unk = 4; return 1; } - if (state[0] == 1) { - state[0] = 0; + if (state.unk == 1) { + state.unk = 0; return 1; } return 0; @@ -171,11 +172,10 @@ void JAISound::start_JAISound_(JAISoundID param_0, JGeometry::TVec3 const* prepareCount = 0; mCount = 0; - if (param_1 == NULL || audience_ == NULL) { - audible_ = NULL; + if (param_1 != 0 && audience_ != NULL) { + audible_ = audience_->newAudible(*param_1, soundID, NULL, 0); } else { - JAISoundID sound = soundID; - audible_ = audience_->newAudible(*param_1, sound, NULL, 0); + audible_ = NULL; } field_0x34 = 0; } @@ -194,7 +194,7 @@ asm void JAISound::start_JAISound_(JAISoundID param_0, JGeometry::TVec3 con /* 802A244C-802A2474 29CD8C 0028+00 0/0 2/2 0/0 .text acceptsNewAudible__8JAISoundCFv */ bool JAISound::acceptsNewAudible() const { bool accepts = false; - if (audible_ == NULL && !(status_.state[1] >> 6 & 1)) { + if (audible_ == NULL && status_.state.flags.flag2==0) { accepts = true; } return accepts; @@ -202,7 +202,6 @@ bool JAISound::acceptsNewAudible() const { /* 802A2474-802A24DC 29CDB4 0068+00 0/0 2/2 0/0 .text /* * newAudible__8JAISoundFRCQ29JGeometry8TVec3PCQ29JGeometry8TVec3UlP11JAIAudience */ -#ifdef NONMATCHING void JAISound::newAudible(JGeometry::TVec3 const& param_0, JGeometry::TVec3 const* param_1, u32 param_2, JAIAudience* param_3) { if (param_3 != NULL) { @@ -211,24 +210,27 @@ void JAISound::newAudible(JGeometry::TVec3 const& param_0, JAISoundID sound = soundID; audible_ = audience_->newAudible(param_0, sound, param_1, param_2); } -#else -#pragma push -#pragma optimization_level 0 -#pragma optimizewithasm off -asm void JAISound::newAudible(JGeometry::TVec3 const& param_0, - JGeometry::TVec3 const* param_1, u32 param_2, - JAIAudience* param_3) { - nofralloc -#include "asm/JSystem/JAudio2/JAISound/func_802A2474.s" -} -#pragma pop -#endif /* ############################################################################################## */ /* 804557C8-804557D0 003DC8 0008+00 1/1 0/0 0/0 .sdata2 @766 */ SECTION_SDATA2 static f64 lit_766 = 4503599627370496.0 /* cast u32 to float */; /* 802A24DC-802A2598 29CE1C 00BC+00 0/0 24/24 0/0 .text stop__8JAISoundFUl */ +#ifdef NONMATCHING +void JAISound::stop(u32 fadeCount) { + ASSERT(status_.isAlive()); + if (fadeCount==0) { + stop(); + return; + }else{ + fader.fadeOut(fadeCount); + removeLifeTime_(); + status_.field_0x1.flags.flag2 = 0; + status_.state.flags.flag5 = 1; + status_.state.flags.flag1 = 1; + } +} +#else #pragma push #pragma optimization_level 0 #pragma optimizewithasm off @@ -237,16 +239,13 @@ asm void JAISound::stop(u32 param_0) { #include "asm/JSystem/JAudio2/JAISound/stop__8JAISoundFUl.s" } #pragma pop +#endif /* 802A2598-802A25D8 29CED8 0040+00 2/2 21/21 0/0 .text stop__8JAISoundFv */ -#pragma push -#pragma optimization_level 0 -#pragma optimizewithasm off -asm void JAISound::stop() { - nofralloc -#include "asm/JSystem/JAudio2/JAISound/stop__8JAISoundFv.s" +void JAISound::stop() { + stop_JAISound_(); + releaseHandle(); } -#pragma pop /* 802A25D8-802A25E0 29CF18 0008+00 1/0 2/0 0/0 .text asSe__8JAISoundFv */ bool JAISound::asSe() { @@ -264,6 +263,18 @@ bool JAISound::asStream() { } /* 802A25F0-802A266C 29CF30 007C+00 0/0 3/3 0/0 .text die_JAISound___8JAISoundFv */ +#ifdef NONMATCHING +void JAISound::die_JAISound_() { + if (audible_!=NULL){ + audience_->deleteAudible(audible_); + audible_ = NULL; + audience_ = NULL; + } + fader.forceOut(); + releaseHandle(); + status_.state.unk = 6; +} +#else #pragma push #pragma optimization_level 0 #pragma optimizewithasm off @@ -272,28 +283,15 @@ asm void JAISound::die_JAISound_() { #include "asm/JSystem/JAudio2/JAISound/die_JAISound___8JAISoundFv.s" } #pragma pop - -/* ############################################################################################## */ -/* 8039B910-8039B910 027F70 0000+00 0/0 0/0 0/0 .rodata @stringBase0 */ -#pragma push -#pragma force_active on -SECTION_DEAD static char const* const stringBase_8039B910 = - "It cost %d steps to prepare Sound(ID:%08x, Addre" - "ss%08x).\n"; -/* @stringBase0 padding */ -SECTION_DEAD static char const* const pad_8039B94A = "\0\0\0\0\0"; -#pragma pop +#endif /* 802A266C-802A26B8 29CFAC 004C+00 0/0 3/3 0/0 .text increasePrepareCount_JAISound___8JAISoundFv */ -#pragma push -#pragma optimization_level 0 -#pragma optimizewithasm off -asm void JAISound::increasePrepareCount_JAISound_() { - nofralloc -#include "asm/JSystem/JAudio2/JAISound/increasePrepareCount_JAISound___8JAISoundFv.s" +void JAISound::increasePrepareCount_JAISound_() { + if((++prepareCount&0xFF) == 0) { + JASReport("It cost %d steps to prepare Sound(ID:%08x, Address%08x).\n",prepareCount,(u32)soundID,this); + } } -#pragma pop /* ############################################################################################## */ /* 804557D0-804557D8 003DD0 0004+04 1/1 0/0 0/0 .sdata2 @887 */ @@ -304,23 +302,74 @@ SECTION_SDATA2 static f32 lit_887[1 + 1 /* padding */] = { }; /* 802A26B8-802A29DC 29CFF8 0324+00 0/0 3/3 0/0 .text calc_JAISound___8JAISoundFv */ +#ifdef NONMATCHING +bool JAISound::calc_JAISound_() { + status_.state.flags.flag2 = 1; + if(isStopping()&&JAISound_tryDie_()) { + return false; + } + ASSERT(status_.isAlive()); + bool isPlaying = status_.isPlaying(); + if(isPlaying) { + mCount++; + } + bool isPaused = status_.isPaused(); + if(isPaused==false) { + fader.calc(); + } + bool playing = isPlaying&&isPaused == false; + if (playing) { + params.mMove.calc(); + if (audible_!=NULL) { + audible_->calc(); + } + if(status_.field_0x1.flags.flag2!=0) { + if(lifeTime==0) { + stop_JAISound_(); + }else{ + lifeTime--; + } + } + } + if(audience_!=NULL&&audible_!=NULL) { + u32 priority = audience_->calcPriority(audible_); + mPriority = priority; + if (priority==0xFFFFFFFF&&status_.field_0x1.flags.flag1==0) { + stop_JAISound_(); + } + }else{ + mPriority = 0; + } + + return playing; +} +#else #pragma push #pragma optimization_level 0 #pragma optimizewithasm off -asm void JAISound::calc_JAISound_() { +asm bool JAISound::calc_JAISound_() { nofralloc #include "asm/JSystem/JAudio2/JAISound/calc_JAISound___8JAISoundFv.s" } #pragma pop +#endif /* 802A29DC-802A2AB0 29D31C 00D4+00 0/0 2/2 0/0 .text initTrack_JAISound___8JAISoundFP8JASTrack */ -#pragma push -#pragma optimization_level 0 -#pragma optimizewithasm off -asm void JAISound::initTrack_JAISound_(JASTrack* param_0) { - nofralloc -#include "asm/JSystem/JAudio2/JAISound/initTrack_JAISound___8JAISoundFP8JASTrack.s" +void JAISound::initTrack_JAISound_(JASTrack* track) { + JASSoundParams* soundParams[8]; + ASSERT(audience_); + ASSERT(audible_); + int numChannels = 0; + for (int i = 0; igetMaxChannels(); i++) { + JASSoundParams* currentParams = audible_->getOuterParams(i); + if (currentParams!=NULL) { + soundParams[numChannels] = currentParams; + numChannels++; + } + } + ASSERT(numChannels >= 1) + track->setChannelMgrCount(numChannels); + for (size_t i = 0; igetChannelMgrCount(); i++) { + track->assignExtBuffer(i,soundParams[i]); + } } -#pragma pop - -/* 8039B910-8039B910 027F70 0000+00 0/0 0/0 0/0 .rodata @stringBase0 */ diff --git a/libs/JSystem/JAudio2/JASAudioReseter.cpp b/libs/JSystem/JAudio2/JASAudioReseter.cpp index 3ed33e6dd33..b253f6c3f26 100644 --- a/libs/JSystem/JAudio2/JASAudioReseter.cpp +++ b/libs/JSystem/JAudio2/JASAudioReseter.cpp @@ -7,6 +7,9 @@ #include "dol2asm.h" #include "dolphin/os/OS.h" #include "dolphin/types.h" +#include "JSystem/JAudio2/JAISoundHandles.h" +#include "JSystem/JAudio2/JASGadget.h" +#include "JSystem/JAudio2/JASAudioThread.h" // // Types: @@ -14,11 +17,10 @@ struct JASDSPChannel { /* 8029D340 */ void drop(); - /* 8029D948 */ void getHandle(u32); -}; + /* 8029D948 */ static JASDSPChannel* getHandle(u32); -struct JASAudioThread { - /* 8029CDC0 */ void stop(); + inline u32 getStatus() {return mStatus;} + u32 mStatus; }; // @@ -44,7 +46,7 @@ extern "C" void setDSPLevel__9JASDriverFf(); extern "C" void getDSPLevel__9JASDriverFv(); extern "C" void registerDspSyncCallback__9JASDriverFPFPv_lPv(); extern "C" void __dl__FPv(); -extern "C" extern u8 data_80450B8C[4]; +extern "C" extern JASAudioThread* data_80450B8C; // // Declarations: @@ -62,38 +64,21 @@ JASAudioReseter::JASAudioReseter() { JASAudioReseter::~JASAudioReseter() {} /* 8029D138-8029D1D4 297A78 009C+00 0/0 1/1 0/0 .text start__15JASAudioReseterFUlb */ -#ifdef NONMATCHING bool JASAudioReseter::start(u32 param_0, bool param_1) { - u32 interrupt_status; - if (mIsDone == false) { return false; + } + field_0xc = param_1; + JASCriticalSection critical; + if (!JASDriver::registerDspSyncCallback(callback, this)) { + return false; } else { - field_0xc = param_1; - interrupt_status = OSDisableInterrupts(); - - if (!JASDriver::registerDspSyncCallback(callback, (void*)param_0)) { - OSRestoreInterrupts(interrupt_status); - return false; - } else { - mDSPLevel = JASDriver::getDSPLevel(); - field_0x0 = param_0; - mIsDone = false; - OSRestoreInterrupts(interrupt_status); - return true; - } + mDSPLevel = JASDriver::getDSPLevel(); + field_0x0 = param_0; + mIsDone = false; + return true; } } -#else -#pragma push -#pragma optimization_level 0 -#pragma optimizewithasm off -asm bool JASAudioReseter::start(u32 param_0, bool param_1) { - nofralloc -#include "asm/JSystem/JAudio2/JASAudioReseter/start__15JASAudioReseterFUlb.s" -} -#pragma pop -#endif /* 8029D1D4-8029D1F8 297B14 0024+00 0/0 1/1 0/0 .text resume__15JASAudioReseterFv */ void JASAudioReseter::resume() { @@ -105,21 +90,30 @@ s32 JASAudioReseter::checkDone() const { return mIsDone; } -/* ############################################################################################## */ -/* 80455740-80455748 003D40 0008+00 1/1 0/0 0/0 .sdata2 @156 */ -SECTION_SDATA2 static f64 lit_156 = 4503599627370496.0 /* cast u32 to float */; /* 8029D200-8029D2D4 297B40 00D4+00 1/1 0/0 0/0 .text calc__15JASAudioReseterFv */ -#pragma push -#pragma optimization_level 0 -#pragma optimizewithasm off -asm s32 JASAudioReseter::calc() { - nofralloc -#include "asm/JSystem/JAudio2/JASAudioReseter/calc__15JASAudioReseterFv.s" +s32 JASAudioReseter::calc() { + if(field_0x0==0) { + for(size_t i = 0; i<64; i++) { + JASDSPChannel* handle = JASDSPChannel::getHandle(i); + if ((handle->getStatus()&0xFF)==0) { + handle->drop(); + } + } + if(field_0xc!=false) { + data_80450B8C->stop();//JASGlobalInstance::sInstance->stop(); + } + mIsDone = 1; + return -1; + } + field_0x0--; + u32 unk = field_0x0; + float dspLevel = JASDriver::getDSPLevel(); + JASDriver::setDSPLevel(((float)unk*dspLevel)/(float)(unk+1)); + return 0; } -#pragma pop /* 8029D2D4-8029D2F4 297C14 0020+00 1/1 0/0 0/0 .text callback__15JASAudioReseterFPv */ s32 JASAudioReseter::callback(void* param_0) { - return calc(); + return ((JASAudioReseter*)param_0)->calc(); } diff --git a/libs/JSystem/JAudio2/JASAudioThread.cpp b/libs/JSystem/JAudio2/JASAudioThread.cpp index 0667bfb0cc1..415d62b23db 100644 --- a/libs/JSystem/JAudio2/JASAudioThread.cpp +++ b/libs/JSystem/JAudio2/JASAudioThread.cpp @@ -58,18 +58,6 @@ struct JASDSPChannel { /* 8029D3C8 */ void initAll(); }; -struct JASAudioThread { - /* 8029CCDC */ JASAudioThread(int, int, u32); - /* 8029CD4C */ void create(s32); - /* 8029CDC0 */ void stop(); - /* 8029CDEC */ void run(); - /* 8029CF68 */ void DMACallback(); - /* 8029CFBC */ void DSPCallback(void*); - /* 8029D028 */ ~JASAudioThread(); - - static u8 snIntCount[4 + 4 /* padding */]; -}; - // // Forward References: // diff --git a/libs/JSystem/JAudio2/dspproc.cpp b/libs/JSystem/JAudio2/dspproc.cpp index f91c6ff13e2..e034a347bd3 100644 --- a/libs/JSystem/JAudio2/dspproc.cpp +++ b/libs/JSystem/JAudio2/dspproc.cpp @@ -29,7 +29,19 @@ extern "C" void DSPSendCommands2__FPUlUlPFUs_v(); // Declarations: // +//Different compiler version for this TU? Something to note is that JAudio 1 is 32 byte aligned like this file + +#pragma function_align 32 + /* 8029E4E0-8029E528 298E20 0048+00 0/0 1/1 0/0 .text DSPReleaseHalt2__FUl */ +#ifdef NONMATCHING +void DSPReleaseHalt2(u32 msg) { + u32 msgs[2]; + msgs[0] = (msg<<16) | DSP_CreateMap2(msg); + + DSPSendCommands2(msgs,0,NULL); +} +#else #pragma push #pragma optimization_level 0 #pragma optimizewithasm off @@ -39,23 +51,32 @@ asm void DSPReleaseHalt2(u32 param_0) { #include "asm/JSystem/JAudio2/dspproc/DSPReleaseHalt2__FUl.s" } #pragma pop +#endif /* ############################################################################################## */ /* 804512F8-80451300 0007F8 0004+04 2/2 0/0 0/0 .sbss flag */ -static u8 flag[4 + 4 /* padding */]; +static u32 flag; /* 8029E540-8029E54C 298E80 000C+00 1/1 0/0 0/0 .text setup_callback__FUs */ -#pragma push -#pragma optimization_level 0 -#pragma optimizewithasm off -#pragma function_align 32 -static asm void setup_callback(u16 param_0) { - nofralloc -#include "asm/JSystem/JAudio2/dspproc/setup_callback__FUs.s" +static void setup_callback(u16 param_0) { + flag = 0; } -#pragma pop /* 8029E560-8029E5C4 298EA0 0064+00 0/0 1/1 0/0 .text DsetupTable__FUlUlUlUlUl */ +#ifdef NONMATCHING +void DsetupTable(u32 param_0, u32 param_1, u32 param_2, u32 param_3, u32 param_4) { + u32 r8 = 1; + void(*callback_func)(u16) = setup_callback; + u32 table[5] = {param_0&0xFFFF,param_1,param_2,param_3,param_4}; + flag = r8; + DSPSendCommands2(table,5,callback_func); + while (true) { + if (flag==0) { + return; + } + } +} +#else #pragma push #pragma optimization_level 0 #pragma optimizewithasm off @@ -65,16 +86,22 @@ asm void DsetupTable(u32 param_0, u32 param_1, u32 param_2, u32 param_3, u32 par #include "asm/JSystem/JAudio2/dspproc/DsetupTable__FUlUlUlUlUl.s" } #pragma pop +#endif /* ############################################################################################## */ /* 804507C8-804507D0 000248 0002+06 3/3 0/0 0/0 .sdata DSP_MIXERLEVEL */ -SECTION_SDATA static u16 DSP_MIXERLEVEL[1 + 3 /* padding */] = { - 0x4000, - /* padding */ - 0x0000, - 0x0000, - 0x0000, -}; +static u16 DSP_MIXERLEVEL = 0x4000; + +/* 8029E5E0-8029E604 298F20 0024+00 0/0 1/1 0/0 .text DsetMixerLevel__Ff */ +#ifdef NONMATCHING +void DsetMixerLevel(f32 level) { + DSP_MIXERLEVEL = 4096.0f*level; +} +#else +#pragma push +#pragma optimization_level 0 +#pragma optimizewithasm off +#pragma function_align 32 /* 80455770-80455778 003D70 0004+04 1/1 0/0 0/0 .sdata2 @333 */ SECTION_SDATA2 static f32 lit_333[1 + 1 /* padding */] = { @@ -83,7 +110,6 @@ SECTION_SDATA2 static f32 lit_333[1 + 1 /* padding */] = { 0.0f, }; -/* 8029E5E0-8029E604 298F20 0024+00 0/0 1/1 0/0 .text DsetMixerLevel__Ff */ #pragma push #pragma optimization_level 0 #pragma optimizewithasm off @@ -93,6 +119,7 @@ asm void DsetMixerLevel(f32 param_0) { #include "asm/JSystem/JAudio2/dspproc/DsetMixerLevel__Ff.s" } #pragma pop +#endif /* 8029E620-8029E674 298F60 0054+00 0/0 1/1 0/0 .text DsyncFrame2ch__FUlUlUl */ #pragma push diff --git a/libs/Z2AudioLib/Z2Audience.cpp b/libs/Z2AudioLib/Z2Audience.cpp index 4bf359b0d55..a38aeb57533 100644 --- a/libs/Z2AudioLib/Z2Audience.cpp +++ b/libs/Z2AudioLib/Z2Audience.cpp @@ -739,7 +739,7 @@ asm Z2Audible::~Z2Audible() { #pragma push #pragma optimization_level 0 #pragma optimizewithasm off -asm void Z2Audience::calcPriority(JAIAudible* param_0) { +asm u32 Z2Audience::calcPriority(JAIAudible* param_0) { nofralloc #include "asm/Z2AudioLib/Z2Audience/calcPriority__10Z2AudienceFP10JAIAudible.s" } @@ -882,7 +882,7 @@ asm void Z2Audience::calcPitch_(Z2AudibleChannel* param_0, Z2Audible const* para #pragma push #pragma optimization_level 0 #pragma optimizewithasm off -asm void Z2Audience::getMaxChannels() { +asm int Z2Audience::getMaxChannels() { nofralloc #include "asm/Z2AudioLib/Z2Audience/getMaxChannels__10Z2AudienceFv.s" } diff --git a/libs/Z2AudioLib/Z2SceneMgr.cpp b/libs/Z2AudioLib/Z2SceneMgr.cpp index c139fc41202..4f0a62b583a 100644 --- a/libs/Z2AudioLib/Z2SceneMgr.cpp +++ b/libs/Z2AudioLib/Z2SceneMgr.cpp @@ -79,7 +79,7 @@ extern "C" void setSceneExist__10Z2SceneMgrFb(); extern "C" void setFadeOutStart__10Z2SceneMgrFUc(); extern "C" void setFadeInStart__10Z2SceneMgrFUc(); extern "C" void setSceneName__10Z2SceneMgrFPcll(); -extern "C" void __ct__10JAISoundIDFRC10JAISoundID(); +extern "C" void __ct__10JAISoundIDFRC10JAISoundID(JAISoundID* this_, JAISoundID const& soundIdToSet); extern "C" void setFieldBgmPlay__8Z2SeqMgrFb(); extern "C" void isActive__12JAIStreamMgrCFv(); extern "C" void getID__8JAISoundCFv(); @@ -87,12 +87,11 @@ extern "C" void func_802B9994(void* _this); extern "C" static void dComIfGs_getStartPoint__Fv(); extern "C" void unMuteSceneBgm__8Z2SeqMgrFUl(); extern "C" void muteSceneBgm__8Z2SeqMgrFUlf(); -extern "C" void __as__10JAISoundIDFRC10JAISoundID(); extern "C" static void dComIfGs_isSaveSwitch__Fi(); extern "C" void resetCrowdSize__7Z2SeMgrFv(); extern "C" void setTwilightGateVol__8Z2SeqMgrFf(); extern "C" void setWindStoneVol__8Z2SeqMgrFfUl(); -extern "C" void __ct__10JAISoundIDFUl(void* param_0, u32 param_1); +extern "C" void __as__10JAISoundIDFRC10JAISoundID(JAISoundID* this_, JAISoundID const& param_0); extern "C" void sceneChange__10Z2SceneMgrF10JAISoundIDUcUcUcUcUcb(); extern "C" void framework__10Z2SceneMgrFv(); extern "C" void load1stDynamicWave__10Z2SceneMgrFv(); @@ -108,6 +107,7 @@ extern "C" void eraseBgmWave__10Z2SceneMgrFUl(); extern "C" void getWaveLoadStatus__10Z2SceneMgrFUlUl(); extern "C" void loadSeWave__10Z2SceneMgrFUl(); extern "C" void loadBgmWave__10Z2SceneMgrFUl(); +extern "C" void __ct__10JAISoundIDFUl(void* param_0, u32 param_1); extern "C" extern char const* const Z2SceneMgr__stringBase0; // @@ -707,9 +707,9 @@ asm void Z2SceneMgr::setSceneName(char* param_0, s32 param_1, s32 param_2) { } #pragma pop -//! @meme this looks to be non-inlined here because @ref setSceneName is too large -JAISoundID::JAISoundID(JAISoundID const& soundIdToSet) { - mId = soundIdToSet.mId; +//! @meme this looks to be non-inlined here because @ref setSceneName is too large* +extern "C" void __ct__10JAISoundIDFRC10JAISoundID(JAISoundID* this_, JAISoundID const& soundIdToSet) { + *this_ = soundIdToSet; } /* 802B9968-802B9978 2B42A8 0010+00 1/1 0/0 0/0 .text setFieldBgmPlay__8Z2SeqMgrFb */ @@ -795,7 +795,7 @@ asm void Z2SeqMgr::muteSceneBgm(u32 param_0, f32 param_1) { #pragma push #pragma optimization_level 0 #pragma optimizewithasm off -asm void JAISoundID::operator=(JAISoundID const& param_0) { +extern "C" asm void __as__10JAISoundIDFRC10JAISoundID(JAISoundID* this_, JAISoundID const& param_0) { nofralloc #include "asm/Z2AudioLib/Z2SceneMgr/__as__10JAISoundIDFRC10JAISoundID.s" } diff --git a/src/m_Do/m_Do_main.cpp b/src/m_Do/m_Do_main.cpp index 5cd9a893aac..fe03c669103 100644 --- a/src/m_Do/m_Do_main.cpp +++ b/src/m_Do/m_Do_main.cpp @@ -20,6 +20,8 @@ #include "m_Do/m_Do_dvd_thread.h" #include "m_Do/m_Do_graphic.h" #include "m_Do/m_Do_machine.h" +#include "JSystem/JAudio2/JASGadget.h" +#include "JSystem/JAudio2/JASAudioThread.h" // // Forward References: @@ -735,6 +737,7 @@ u8 data_80450B88[4]; * sInstance__35JASGlobalInstance<14JASAudioThread> */ extern u8 data_80450B8C[4]; u8 data_80450B8C[4]; +//JASAudioThread* JASGlobalInstance::sInstance; /* 80450B90-80450B98 000090 0004+04 0/0 4/4 0/0 .sbss * sInstance__40JASGlobalInstance<19JASDefaultBankTable> */ From 56764ac3bdefe04047693f8f004d0320256b8792 Mon Sep 17 00:00:00 2001 From: jdflyer Date: Thu, 29 Dec 2022 15:22:26 -0700 Subject: [PATCH 2/6] Some Z2WolfHowlMgr progress --- include/JSystem/JAudio2/JAISoundHandles.h | 2 +- include/JSystem/JAudio2/JASGadget.h | 29 +++++++++++--- include/Z2AudioLib/Z2WolfHowlMgr.h | 45 +++++++-------------- libs/Z2AudioLib/Z2WolfHowlMgr.cpp | 49 ++++++++++++++++++++++- 4 files changed, 86 insertions(+), 39 deletions(-) diff --git a/include/JSystem/JAudio2/JAISoundHandles.h b/include/JSystem/JAudio2/JAISoundHandles.h index 850358facd2..d79baaa2dc6 100644 --- a/include/JSystem/JAudio2/JAISoundHandles.h +++ b/include/JSystem/JAudio2/JAISoundHandles.h @@ -10,7 +10,7 @@ class JAISoundID; class JAISoundHandle { public: - JAISoundHandle(); + JAISoundHandle() {sound_ = NULL;}; ~JAISoundHandle() {} bool isSoundAttached() const { return sound_ != NULL; } diff --git a/include/JSystem/JAudio2/JASGadget.h b/include/JSystem/JAudio2/JASGadget.h index 811aeacb3bd..578ad9a5be9 100644 --- a/include/JSystem/JAudio2/JASGadget.h +++ b/include/JSystem/JAudio2/JASGadget.h @@ -6,18 +6,35 @@ template class JASGlobalInstance { public: - T* getInstance() { return sInstance; } + inline T* getInstance() { return sInstance; } - JASGlobalInstance(bool param) { + inline JASGlobalInstance(bool param) { if (param) { ASSERT(sInstance == 0); - if (this!=NULL) { - sInstance = this - sizeof(T); - } + //if (this!=NULL) { + sInstance = (T*)this; + //We need a better way to compute the location of sInstance + //sInstance = (T*)((char*)this-(char*)&(((T*)NULL)->JASGlobalInstance)); + //} } } - static T* sInstance; }; +class Parent { + public: + int x; +}; + +class Parent2 { + public: + int y; +}; + +class Child : public Parent, public Parent2 { + public: + void func() { + Parent2::y = 5; // Access the member x of the Parent class + } +}; #endif /* JASGADGET_H */ diff --git a/include/Z2AudioLib/Z2WolfHowlMgr.h b/include/Z2AudioLib/Z2WolfHowlMgr.h index ba41b0539e4..224aa60485b 100644 --- a/include/Z2AudioLib/Z2WolfHowlMgr.h +++ b/include/Z2AudioLib/Z2WolfHowlMgr.h @@ -1,8 +1,9 @@ #ifndef Z2WOLFHOWLMGR_H #define Z2WOLFHOWLMGR_H -#include "Z2AudioLib/Z2SoundObject.h" #include "dolphin/types.h" +#include "Z2AudioLib/Z2SoundObject.h" +#include "JSystem/JAudio2/JASGadget.h" /* * Z2WolfHowlData @@ -17,7 +18,7 @@ struct Z2WolfHowlData { u16* mSongData; }; -class Z2WolfHowlMgr { +class Z2WolfHowlMgr : public JASGlobalInstance { public: Z2WolfHowlMgr(); @@ -36,10 +37,11 @@ public: void startGuideMelody(bool); void skipCorrectDemo(); + private: - /* 0x00 */ JAISoundHandle* field_0x00; - /* 0x04 */ JAISoundHandle* field_0x04; - /* 0x08 */ JAISoundHandle* field_0x08; + /* 0x00 */ JAISoundHandle field_0x00; + /* 0x04 */ JAISoundHandle field_0x04; + /* 0x08 */ JAISoundHandle field_0x08; /* 0x0C */ Z2WolfHowlData* mpCurSong; /* 0x10 */ Z2WolfHowlData** mpSongList; /* 0x14 */ f32 mNowInputValue; @@ -51,37 +53,18 @@ private: /* 0x2C */ u8 field_0x2c[4]; /* 0x30 */ f32 field_0x30; /* 0x34 */ f32 field_0x34; - /* 0x38 */ f32 field_0x38; - /* 0x3C */ f32 field_0x3c; - /* 0x40 */ f32 field_0x40; - /* 0x44 */ f32 field_0x44; - /* 0x48 */ f32 field_0x48; - /* 0x4C */ f32 field_0x4c; - /* 0x50 */ f32 field_0x50; - /* 0x54 */ f32 field_0x54; - /* 0x58 */ f32 field_0x58; - /* 0x5C */ f32 field_0x5c; - /* 0x60 */ f32 field_0x60; - /* 0x64 */ f32 field_0x64; - /* 0x68 */ f32 field_0x68; - /* 0x6C */ f32 field_0x6c; - /* 0x70 */ f32 field_0x70; - /* 0x74 */ f32 field_0x74; - /* 0x78 */ f32 field_0x78; - /* 0x7C */ f32 field_0x7c; - /* 0x80 */ f32 field_0x80; - /* 0x84 */ f32 field_0x84; + /* 0x38 */ f32 field_0x38[10]; + /* 0x60 */ f32 field_0x60[10]; /* 0x88 */ void* mTimer; /* 0x8C */ u8 mReleaseTimer; /* 0x8D */ u8 field_0x8d; - /* 0x8E */ u8 mCorrectCurveID; + /* 0x8E */ s8 mCorrectCurveID; /* 0x8F */ u8 field_0x8f; /* 0x90 */ s16 field_0x90; - /* 0x92 */ u8 field_0x92[20]; - /* 0xA6 */ u8 field_0xa6[0x14]; - /* 0xBA */ u8 field_0xba; - /* 0xBB */ u8 field_0xbb; - /* 0xBC */ u8 field_0xbc; + /* 0x92 */ u16 field_0x92[20]; + /* 0xBA */ s8 field_0xba; + /* 0xBB */ s8 field_0xbb; + /* 0xBC */ s8 field_0xbc; }; #endif /* Z2WOLFHOWLMGR_H */ diff --git a/libs/Z2AudioLib/Z2WolfHowlMgr.cpp b/libs/Z2AudioLib/Z2WolfHowlMgr.cpp index e99da12893a..dcb579b215d 100644 --- a/libs/Z2AudioLib/Z2WolfHowlMgr.cpp +++ b/libs/Z2AudioLib/Z2WolfHowlMgr.cpp @@ -71,7 +71,7 @@ extern "C" void _savegpr_29(); extern "C" void _restgpr_28(); extern "C" void _restgpr_29(); extern "C" extern u32 __float_nan; -extern "C" extern u8 data_80450B38[4]; +extern "C" extern Z2WolfHowlMgr* data_80450B38; extern "C" extern u8 data_80450B44[4]; extern "C" extern u8 data_80450B60[4]; extern "C" extern u8 data_80450B74[4]; @@ -194,6 +194,35 @@ SECTION_SDATA2 static u8 lit_3485[4] = { SECTION_SDATA2 static f32 lit_3486 = 1.0f; /* 802CAAC0-802CAB8C 2C5400 00CC+00 0/0 1/1 0/0 .text __ct__13Z2WolfHowlMgrFv */ +#ifdef NONMATCHING +Z2WolfHowlMgr* JASGlobalInstance::sInstance = reinterpret_cast(data_80450B38); +Z2WolfHowlMgr::Z2WolfHowlMgr() : JASGlobalInstance(true) { + mpCurSong = NULL; + mNowInputValue = 0.0f; + field_0x18 = 1.0f; + field_0x1c = 1.0f; + field_0x20 = cPitchCenter; + field_0x24 = cPitchCenter; + field_0x28 = 1.0f; + mTimer = NULL; + mReleaseTimer = 0; + mCorrectCurveID = -1; + field_0x90 = -1; + field_0xba = 0; + field_0xbb = 0; + field_0xbc = 0; + for (u8 i = 0; i<20; i++) { + field_0x92[i] = 0; + } + for (u8 i = 0; i<10; i++) { + field_0x38[i] = 0.0f; + field_0x60[i] = 0.0f; + } + field_0x34 = 0.0f; + field_0x30 = 0.0f; + mpSongList = (Z2WolfHowlData**)&sGuideData; +} +#else #pragma push #pragma optimization_level 0 #pragma optimizewithasm off @@ -202,8 +231,25 @@ asm Z2WolfHowlMgr::Z2WolfHowlMgr() { #include "asm/Z2AudioLib/Z2WolfHowlMgr/__ct__13Z2WolfHowlMgrFv.s" } #pragma pop +#endif /* 802CAB8C-802CABEC 2C54CC 0060+00 1/1 0/0 0/0 .text resetState__13Z2WolfHowlMgrFv */ +#ifdef NONMATCHING +void Z2WolfHowlMgr::resetState() { + field_0x18 = 1.0f; + field_0x24 = cPitchCenter; + field_0x28 = 1.0f; + mTimer = NULL; + mReleaseTimer = 0; + field_0xba = 0; + for (u8 i = 0; i<10; i++) { + field_0x38[i] = 0.0f; + field_0x60[i] = 0.0f; + } + field_0x34 = 0.0f; + field_0x30 = 0.0f; +} +#else #pragma push #pragma optimization_level 0 #pragma optimizewithasm off @@ -212,6 +258,7 @@ asm void Z2WolfHowlMgr::resetState() { #include "asm/Z2AudioLib/Z2WolfHowlMgr/resetState__13Z2WolfHowlMgrFv.s" } #pragma pop +#endif /* ############################################################################################## */ /* 80455E68-80455E6C 004468 0004+00 2/2 0/0 0/0 .sdata2 @3527 */ From 74daacb2777f0607266d11268171f7819b8d175f Mon Sep 17 00:00:00 2001 From: jdflyer Date: Thu, 29 Dec 2022 15:45:50 -0700 Subject: [PATCH 3/6] remove unused asm --- asm/JSystem/JAudio2/JAISound/func_802A2474.s | 28 --------- ...reasePrepareCount_JAISound___8JAISoundFv.s | 21 ------- ...nitTrack_JAISound___8JAISoundFP8JASTrack.s | 59 ------------------- .../JAudio2/JAISound/stop__8JAISoundFv.s | 17 ------ .../calc__15JASAudioReseterFv.s | 59 ------------------- .../start__15JASAudioReseterFUlb.s | 43 -------------- .../JAudio2/dspproc/setup_callback__FUs.s | 4 -- 7 files changed, 231 deletions(-) delete mode 100644 asm/JSystem/JAudio2/JAISound/func_802A2474.s delete mode 100644 asm/JSystem/JAudio2/JAISound/increasePrepareCount_JAISound___8JAISoundFv.s delete mode 100644 asm/JSystem/JAudio2/JAISound/initTrack_JAISound___8JAISoundFP8JASTrack.s delete mode 100644 asm/JSystem/JAudio2/JAISound/stop__8JAISoundFv.s delete mode 100644 asm/JSystem/JAudio2/JASAudioReseter/calc__15JASAudioReseterFv.s delete mode 100644 asm/JSystem/JAudio2/JASAudioReseter/start__15JASAudioReseterFUlb.s delete mode 100644 asm/JSystem/JAudio2/dspproc/setup_callback__FUs.s diff --git a/asm/JSystem/JAudio2/JAISound/func_802A2474.s b/asm/JSystem/JAudio2/JAISound/func_802A2474.s deleted file mode 100644 index b677eb5c103..00000000000 --- a/asm/JSystem/JAudio2/JAISound/func_802A2474.s +++ /dev/null @@ -1,28 +0,0 @@ -lbl_802A2474: -/* 802A2474 94 21 FF E0 */ stwu r1, -0x20(r1) -/* 802A2478 7C 08 02 A6 */ mflr r0 -/* 802A247C 90 01 00 24 */ stw r0, 0x24(r1) -/* 802A2480 93 E1 00 1C */ stw r31, 0x1c(r1) -/* 802A2484 7C 7F 1B 78 */ mr r31, r3 -/* 802A2488 7C A9 2B 78 */ mr r9, r5 -/* 802A248C 7C C8 33 78 */ mr r8, r6 -/* 802A2490 28 07 00 00 */ cmplwi r7, 0 -/* 802A2494 41 82 00 08 */ beq lbl_802A249C -/* 802A2498 90 FF 00 0C */ stw r7, 0xc(r31) -lbl_802A249C: -/* 802A249C 80 1F 00 18 */ lwz r0, 0x18(r31) -/* 802A24A0 90 01 00 08 */ stw r0, 8(r1) -/* 802A24A4 80 7F 00 0C */ lwz r3, 0xc(r31) -/* 802A24A8 38 A1 00 08 */ addi r5, r1, 8 -/* 802A24AC 7D 26 4B 78 */ mr r6, r9 -/* 802A24B0 7D 07 43 78 */ mr r7, r8 -/* 802A24B4 81 83 00 00 */ lwz r12, 0(r3) -/* 802A24B8 81 8C 00 0C */ lwz r12, 0xc(r12) -/* 802A24BC 7D 89 03 A6 */ mtctr r12 -/* 802A24C0 4E 80 04 21 */ bctrl -/* 802A24C4 90 7F 00 08 */ stw r3, 8(r31) -/* 802A24C8 83 E1 00 1C */ lwz r31, 0x1c(r1) -/* 802A24CC 80 01 00 24 */ lwz r0, 0x24(r1) -/* 802A24D0 7C 08 03 A6 */ mtlr r0 -/* 802A24D4 38 21 00 20 */ addi r1, r1, 0x20 -/* 802A24D8 4E 80 00 20 */ blr diff --git a/asm/JSystem/JAudio2/JAISound/increasePrepareCount_JAISound___8JAISoundFv.s b/asm/JSystem/JAudio2/JAISound/increasePrepareCount_JAISound___8JAISoundFv.s deleted file mode 100644 index 3ae33c8ba93..00000000000 --- a/asm/JSystem/JAudio2/JAISound/increasePrepareCount_JAISound___8JAISoundFv.s +++ /dev/null @@ -1,21 +0,0 @@ -lbl_802A266C: -/* 802A266C 94 21 FF F0 */ stwu r1, -0x10(r1) -/* 802A2670 7C 08 02 A6 */ mflr r0 -/* 802A2674 90 01 00 14 */ stw r0, 0x14(r1) -/* 802A2678 7C 66 1B 78 */ mr r6, r3 -/* 802A267C 80 63 00 14 */ lwz r3, 0x14(r3) -/* 802A2680 38 03 00 01 */ addi r0, r3, 1 -/* 802A2684 90 06 00 14 */ stw r0, 0x14(r6) -/* 802A2688 54 00 06 3F */ clrlwi. r0, r0, 0x18 -/* 802A268C 40 82 00 1C */ bne lbl_802A26A8 -/* 802A2690 3C 60 80 3A */ lis r3, JAISound__stringBase0@ha /* 0x8039B910@ha */ -/* 802A2694 38 63 B9 10 */ addi r3, r3, JAISound__stringBase0@l /* 0x8039B910@l */ -/* 802A2698 80 86 00 14 */ lwz r4, 0x14(r6) -/* 802A269C 80 A6 00 18 */ lwz r5, 0x18(r6) -/* 802A26A0 4C C6 31 82 */ crclr 6 -/* 802A26A4 4B FE E8 C1 */ bl JASReport__FPCce -lbl_802A26A8: -/* 802A26A8 80 01 00 14 */ lwz r0, 0x14(r1) -/* 802A26AC 7C 08 03 A6 */ mtlr r0 -/* 802A26B0 38 21 00 10 */ addi r1, r1, 0x10 -/* 802A26B4 4E 80 00 20 */ blr diff --git a/asm/JSystem/JAudio2/JAISound/initTrack_JAISound___8JAISoundFP8JASTrack.s b/asm/JSystem/JAudio2/JAISound/initTrack_JAISound___8JAISoundFP8JASTrack.s deleted file mode 100644 index fdf4bf80740..00000000000 --- a/asm/JSystem/JAudio2/JAISound/initTrack_JAISound___8JAISoundFP8JASTrack.s +++ /dev/null @@ -1,59 +0,0 @@ -lbl_802A29DC: -/* 802A29DC 94 21 FF C0 */ stwu r1, -0x40(r1) -/* 802A29E0 7C 08 02 A6 */ mflr r0 -/* 802A29E4 90 01 00 44 */ stw r0, 0x44(r1) -/* 802A29E8 39 61 00 40 */ addi r11, r1, 0x40 -/* 802A29EC 48 0B F7 E5 */ bl _savegpr_26 -/* 802A29F0 7C 7A 1B 78 */ mr r26, r3 -/* 802A29F4 7C 9B 23 78 */ mr r27, r4 -/* 802A29F8 3B A0 00 00 */ li r29, 0 -/* 802A29FC 3B E0 00 00 */ li r31, 0 -/* 802A2A00 3B 80 00 00 */ li r28, 0 -/* 802A2A04 3B C1 00 08 */ addi r30, r1, 8 -/* 802A2A08 48 00 00 34 */ b lbl_802A2A3C -lbl_802A2A0C: -/* 802A2A0C 80 7A 00 08 */ lwz r3, 8(r26) -/* 802A2A10 7F 84 E3 78 */ mr r4, r28 -/* 802A2A14 81 83 00 00 */ lwz r12, 0(r3) -/* 802A2A18 81 8C 00 0C */ lwz r12, 0xc(r12) -/* 802A2A1C 7D 89 03 A6 */ mtctr r12 -/* 802A2A20 4E 80 04 21 */ bctrl -/* 802A2A24 28 03 00 00 */ cmplwi r3, 0 -/* 802A2A28 41 82 00 10 */ beq lbl_802A2A38 -/* 802A2A2C 7C 7E F9 2E */ stwx r3, r30, r31 -/* 802A2A30 3B BD 00 01 */ addi r29, r29, 1 -/* 802A2A34 3B FF 00 04 */ addi r31, r31, 4 -lbl_802A2A38: -/* 802A2A38 3B 9C 00 01 */ addi r28, r28, 1 -lbl_802A2A3C: -/* 802A2A3C 80 7A 00 0C */ lwz r3, 0xc(r26) -/* 802A2A40 81 83 00 00 */ lwz r12, 0(r3) -/* 802A2A44 81 8C 00 10 */ lwz r12, 0x10(r12) -/* 802A2A48 7D 89 03 A6 */ mtctr r12 -/* 802A2A4C 4E 80 04 21 */ bctrl -/* 802A2A50 7C 1C 18 00 */ cmpw r28, r3 -/* 802A2A54 41 80 FF B8 */ blt lbl_802A2A0C -/* 802A2A58 7F 63 DB 78 */ mr r3, r27 -/* 802A2A5C 7F A4 EB 78 */ mr r4, r29 -/* 802A2A60 4B FE E9 E5 */ bl setChannelMgrCount__8JASTrackFUl -/* 802A2A64 3B 80 00 00 */ li r28, 0 -/* 802A2A68 3B E0 00 00 */ li r31, 0 -/* 802A2A6C 3B C1 00 08 */ addi r30, r1, 8 -/* 802A2A70 48 00 00 1C */ b lbl_802A2A8C -lbl_802A2A74: -/* 802A2A74 7F 63 DB 78 */ mr r3, r27 -/* 802A2A78 7F 84 E3 78 */ mr r4, r28 -/* 802A2A7C 7C BE F8 2E */ lwzx r5, r30, r31 -/* 802A2A80 4B FE EF 75 */ bl assignExtBuffer__8JASTrackFUlP14JASSoundParams -/* 802A2A84 3B 9C 00 01 */ addi r28, r28, 1 -/* 802A2A88 3B FF 00 04 */ addi r31, r31, 4 -lbl_802A2A8C: -/* 802A2A8C 80 1B 01 D0 */ lwz r0, 0x1d0(r27) -/* 802A2A90 7C 1C 00 40 */ cmplw r28, r0 -/* 802A2A94 41 80 FF E0 */ blt lbl_802A2A74 -/* 802A2A98 39 61 00 40 */ addi r11, r1, 0x40 -/* 802A2A9C 48 0B F7 81 */ bl _restgpr_26 -/* 802A2AA0 80 01 00 44 */ lwz r0, 0x44(r1) -/* 802A2AA4 7C 08 03 A6 */ mtlr r0 -/* 802A2AA8 38 21 00 40 */ addi r1, r1, 0x40 -/* 802A2AAC 4E 80 00 20 */ blr diff --git a/asm/JSystem/JAudio2/JAISound/stop__8JAISoundFv.s b/asm/JSystem/JAudio2/JAISound/stop__8JAISoundFv.s deleted file mode 100644 index be2ecbbd20e..00000000000 --- a/asm/JSystem/JAudio2/JAISound/stop__8JAISoundFv.s +++ /dev/null @@ -1,17 +0,0 @@ -lbl_802A2598: -/* 802A2598 94 21 FF F0 */ stwu r1, -0x10(r1) -/* 802A259C 7C 08 02 A6 */ mflr r0 -/* 802A25A0 90 01 00 14 */ stw r0, 0x14(r1) -/* 802A25A4 38 80 00 00 */ li r4, 0 -/* 802A25A8 88 03 00 1F */ lbz r0, 0x1f(r3) -/* 802A25AC 50 80 1F 38 */ rlwimi r0, r4, 3, 0x1c, 0x1c -/* 802A25B0 98 03 00 1F */ stb r0, 0x1f(r3) -/* 802A25B4 38 80 00 01 */ li r4, 1 -/* 802A25B8 88 03 00 1F */ lbz r0, 0x1f(r3) -/* 802A25BC 50 80 3E 30 */ rlwimi r0, r4, 7, 0x18, 0x18 -/* 802A25C0 98 03 00 1F */ stb r0, 0x1f(r3) -/* 802A25C4 4B FF FB DD */ bl releaseHandle__8JAISoundFv -/* 802A25C8 80 01 00 14 */ lwz r0, 0x14(r1) -/* 802A25CC 7C 08 03 A6 */ mtlr r0 -/* 802A25D0 38 21 00 10 */ addi r1, r1, 0x10 -/* 802A25D4 4E 80 00 20 */ blr diff --git a/asm/JSystem/JAudio2/JASAudioReseter/calc__15JASAudioReseterFv.s b/asm/JSystem/JAudio2/JASAudioReseter/calc__15JASAudioReseterFv.s deleted file mode 100644 index beab1fea431..00000000000 --- a/asm/JSystem/JAudio2/JASAudioReseter/calc__15JASAudioReseterFv.s +++ /dev/null @@ -1,59 +0,0 @@ -lbl_8029D200: -/* 8029D200 94 21 FF E0 */ stwu r1, -0x20(r1) -/* 8029D204 7C 08 02 A6 */ mflr r0 -/* 8029D208 90 01 00 24 */ stw r0, 0x24(r1) -/* 8029D20C 93 E1 00 1C */ stw r31, 0x1c(r1) -/* 8029D210 93 C1 00 18 */ stw r30, 0x18(r1) -/* 8029D214 7C 7E 1B 78 */ mr r30, r3 -/* 8029D218 80 63 00 00 */ lwz r3, 0(r3) -/* 8029D21C 28 03 00 00 */ cmplwi r3, 0 -/* 8029D220 40 82 00 50 */ bne lbl_8029D270 -/* 8029D224 3B E0 00 00 */ li r31, 0 -lbl_8029D228: -/* 8029D228 7F E3 FB 78 */ mr r3, r31 -/* 8029D22C 48 00 07 1D */ bl getHandle__13JASDSPChannelFUl -/* 8029D230 80 03 00 00 */ lwz r0, 0(r3) -/* 8029D234 54 00 06 3F */ clrlwi. r0, r0, 0x18 -/* 8029D238 40 82 00 08 */ bne lbl_8029D240 -/* 8029D23C 48 00 01 05 */ bl drop__13JASDSPChannelFv -lbl_8029D240: -/* 8029D240 3B FF 00 01 */ addi r31, r31, 1 -/* 8029D244 28 1F 00 40 */ cmplwi r31, 0x40 -/* 8029D248 41 80 FF E0 */ blt lbl_8029D228 -/* 8029D24C 88 1E 00 0C */ lbz r0, 0xc(r30) -/* 8029D250 28 00 00 00 */ cmplwi r0, 0 -/* 8029D254 41 82 00 0C */ beq lbl_8029D260 -/* 8029D258 80 6D 86 0C */ lwz r3, data_80450B8C(r13) -/* 8029D25C 4B FF FB 65 */ bl stop__14JASAudioThreadFv -lbl_8029D260: -/* 8029D260 38 00 00 01 */ li r0, 1 -/* 8029D264 90 1E 00 08 */ stw r0, 8(r30) -/* 8029D268 38 60 FF FF */ li r3, -1 -/* 8029D26C 48 00 00 50 */ b lbl_8029D2BC -lbl_8029D270: -/* 8029D270 38 03 FF FF */ addi r0, r3, -1 -/* 8029D274 90 1E 00 00 */ stw r0, 0(r30) -/* 8029D278 83 FE 00 00 */ lwz r31, 0(r30) -/* 8029D27C 48 00 0E DD */ bl getDSPLevel__9JASDriverFv -/* 8029D280 C8 42 BD 40 */ lfd f2, lit_156(r2) -/* 8029D284 93 E1 00 0C */ stw r31, 0xc(r1) -/* 8029D288 3C 60 43 30 */ lis r3, 0x4330 -/* 8029D28C 90 61 00 08 */ stw r3, 8(r1) -/* 8029D290 C8 01 00 08 */ lfd f0, 8(r1) -/* 8029D294 EC 00 10 28 */ fsubs f0, f0, f2 -/* 8029D298 EC 20 00 72 */ fmuls f1, f0, f1 -/* 8029D29C 38 1F 00 01 */ addi r0, r31, 1 -/* 8029D2A0 90 01 00 14 */ stw r0, 0x14(r1) -/* 8029D2A4 90 61 00 10 */ stw r3, 0x10(r1) -/* 8029D2A8 C8 01 00 10 */ lfd f0, 0x10(r1) -/* 8029D2AC EC 00 10 28 */ fsubs f0, f0, f2 -/* 8029D2B0 EC 21 00 24 */ fdivs f1, f1, f0 -/* 8029D2B4 48 00 0E 7D */ bl setDSPLevel__9JASDriverFf -/* 8029D2B8 38 60 00 00 */ li r3, 0 -lbl_8029D2BC: -/* 8029D2BC 83 E1 00 1C */ lwz r31, 0x1c(r1) -/* 8029D2C0 83 C1 00 18 */ lwz r30, 0x18(r1) -/* 8029D2C4 80 01 00 24 */ lwz r0, 0x24(r1) -/* 8029D2C8 7C 08 03 A6 */ mtlr r0 -/* 8029D2CC 38 21 00 20 */ addi r1, r1, 0x20 -/* 8029D2D0 4E 80 00 20 */ blr diff --git a/asm/JSystem/JAudio2/JASAudioReseter/start__15JASAudioReseterFUlb.s b/asm/JSystem/JAudio2/JASAudioReseter/start__15JASAudioReseterFUlb.s deleted file mode 100644 index 40bd2006aa1..00000000000 --- a/asm/JSystem/JAudio2/JASAudioReseter/start__15JASAudioReseterFUlb.s +++ /dev/null @@ -1,43 +0,0 @@ -lbl_8029D138: -/* 8029D138 94 21 FF E0 */ stwu r1, -0x20(r1) -/* 8029D13C 7C 08 02 A6 */ mflr r0 -/* 8029D140 90 01 00 24 */ stw r0, 0x24(r1) -/* 8029D144 93 E1 00 1C */ stw r31, 0x1c(r1) -/* 8029D148 93 C1 00 18 */ stw r30, 0x18(r1) -/* 8029D14C 7C 7E 1B 78 */ mr r30, r3 -/* 8029D150 7C 9F 23 78 */ mr r31, r4 -/* 8029D154 80 03 00 08 */ lwz r0, 8(r3) -/* 8029D158 2C 00 00 00 */ cmpwi r0, 0 -/* 8029D15C 40 82 00 0C */ bne lbl_8029D168 -/* 8029D160 38 60 00 00 */ li r3, 0 -/* 8029D164 48 00 00 58 */ b lbl_8029D1BC -lbl_8029D168: -/* 8029D168 98 BE 00 0C */ stb r5, 0xc(r30) -/* 8029D16C 48 0A 05 89 */ bl OSDisableInterrupts -/* 8029D170 90 61 00 08 */ stw r3, 8(r1) -/* 8029D174 3C 60 80 2A */ lis r3, callback__15JASAudioReseterFPv@ha /* 0x8029D2D4@ha */ -/* 8029D178 38 63 D2 D4 */ addi r3, r3, callback__15JASAudioReseterFPv@l /* 0x8029D2D4@l */ -/* 8029D17C 7F C4 F3 78 */ mr r4, r30 -/* 8029D180 48 00 10 C1 */ bl registerDspSyncCallback__9JASDriverFPFPv_lPv -/* 8029D184 54 60 06 3F */ clrlwi. r0, r3, 0x18 -/* 8029D188 40 82 00 14 */ bne lbl_8029D19C -/* 8029D18C 80 61 00 08 */ lwz r3, 8(r1) -/* 8029D190 48 0A 05 8D */ bl OSRestoreInterrupts -/* 8029D194 38 60 00 00 */ li r3, 0 -/* 8029D198 48 00 00 24 */ b lbl_8029D1BC -lbl_8029D19C: -/* 8029D19C 48 00 0F BD */ bl getDSPLevel__9JASDriverFv -/* 8029D1A0 D0 3E 00 04 */ stfs f1, 4(r30) -/* 8029D1A4 93 FE 00 00 */ stw r31, 0(r30) -/* 8029D1A8 38 00 00 00 */ li r0, 0 -/* 8029D1AC 90 1E 00 08 */ stw r0, 8(r30) -/* 8029D1B0 80 61 00 08 */ lwz r3, 8(r1) -/* 8029D1B4 48 0A 05 69 */ bl OSRestoreInterrupts -/* 8029D1B8 38 60 00 01 */ li r3, 1 -lbl_8029D1BC: -/* 8029D1BC 83 E1 00 1C */ lwz r31, 0x1c(r1) -/* 8029D1C0 83 C1 00 18 */ lwz r30, 0x18(r1) -/* 8029D1C4 80 01 00 24 */ lwz r0, 0x24(r1) -/* 8029D1C8 7C 08 03 A6 */ mtlr r0 -/* 8029D1CC 38 21 00 20 */ addi r1, r1, 0x20 -/* 8029D1D0 4E 80 00 20 */ blr diff --git a/asm/JSystem/JAudio2/dspproc/setup_callback__FUs.s b/asm/JSystem/JAudio2/dspproc/setup_callback__FUs.s deleted file mode 100644 index ddb13445571..00000000000 --- a/asm/JSystem/JAudio2/dspproc/setup_callback__FUs.s +++ /dev/null @@ -1,4 +0,0 @@ -lbl_8029E540: -/* 8029E540 38 00 00 00 */ li r0, 0 -/* 8029E544 90 0D 8D 78 */ stw r0, flag(r13) -/* 8029E548 4E 80 00 20 */ blr From 4c87c49937907071ca0df78720200291f847dc42 Mon Sep 17 00:00:00 2001 From: jdflyer Date: Thu, 29 Dec 2022 16:22:54 -0700 Subject: [PATCH 4/6] formatting fixes --- include/JSystem/JAudio2/JAISound.h | 14 +++++++------- include/JSystem/JAudio2/JASGadget.h | 16 ---------------- 2 files changed, 7 insertions(+), 23 deletions(-) diff --git a/include/JSystem/JAudio2/JAISound.h b/include/JSystem/JAudio2/JAISound.h index 1fd0f4f9c94..f027ab22cdd 100644 --- a/include/JSystem/JAudio2/JAISound.h +++ b/include/JSystem/JAudio2/JAISound.h @@ -106,19 +106,19 @@ struct JAISoundFader { mIntensity = 1.0f; mTransition.zero(); } - inline void forceOut() { + void forceOut() { mIntensity = 0.0f; mTransition.zero(); } - inline void fadeOut(u32 fadeCount) { + void fadeOut(u32 fadeCount) { if (fadeCount!=0) { mTransition.set(0.0f,mIntensity,fadeCount); }else{ forceOut(); } } - inline bool isOut() { - if(mTransition.mCount!=0||mIntensity<0.01f) { + bool isOut() { + if(mTransition.mCount != 0 || mIntensity < 0.01f) { return true; } return false; @@ -181,14 +181,14 @@ public: u32 getUserData() const { return status_.user_data; } bool isHandleAttached() const { return handle_ != NULL; } - inline void removeLifeTime_() { + void removeLifeTime_() { status_.field_0x1.flags.flag1 = false; } - inline void stop_JAISound_() { + void stop_JAISound_() { status_.state.flags.flag5 = 0; status_.state.flags.flag1 = 1; } - inline bool isStopping() { + bool isStopping() { bool isStopping = false; if(status_.state.flags.flag1) { isStopping = status_.state.flags.flag5 ? fader.isOut() : true; diff --git a/include/JSystem/JAudio2/JASGadget.h b/include/JSystem/JAudio2/JASGadget.h index 578ad9a5be9..9af40931c49 100644 --- a/include/JSystem/JAudio2/JASGadget.h +++ b/include/JSystem/JAudio2/JASGadget.h @@ -21,20 +21,4 @@ public: static T* sInstance; }; -class Parent { - public: - int x; -}; - -class Parent2 { - public: - int y; -}; - -class Child : public Parent, public Parent2 { - public: - void func() { - Parent2::y = 5; // Access the member x of the Parent class - } -}; #endif /* JASGADGET_H */ From f453841a5ce81e1790ccb130d7568f7908b703e2 Mon Sep 17 00:00:00 2001 From: jdflyer Date: Fri, 30 Dec 2022 17:45:12 -0700 Subject: [PATCH 5/6] ISO packaging script --- Makefile | 9 ++- tools/packageISO.py | 111 +++++++++++++++++++++++++++++++++++ tools/package_game_assets.py | 6 +- 3 files changed, 121 insertions(+), 5 deletions(-) create mode 100644 tools/packageISO.py diff --git a/Makefile b/Makefile index 1929850be58..7ddf95c491d 100644 --- a/Makefile +++ b/Makefile @@ -21,6 +21,7 @@ TARGET := dolzel2 BUILD_PATH := build BUILD_DIR := $(BUILD_PATH)/$(TARGET) +TARGET_ISO := $(BUILD_DIR)/dolzel2.iso SRC_DIRS := $(shell find src/ libs/ -type f -name '*.cpp') ASM_DIRS := $(shell find asm/ -type f -name '*.s') @@ -129,6 +130,7 @@ clean: clean_game: rm -r -f -d $(TARGET)/game + rm -r -f -d $(TARGET_ISO) clean_assets: rm -r -f -d game @@ -173,7 +175,10 @@ shift: dirs $(DOL_SHIFT) game: shift $(MAKE) rels @mkdir -p game - @$(PYTHON) tools/package_game_assets.py game $(BUILD_DIR) + @$(PYTHON) tools/package_game_assets.py ./game $(BUILD_DIR) + +iso: game + @$(PYTHON) tools/packageISO.py $(BUILD_DIR)/game/ $(TARGET_ISO) rungame: game @echo If you are playing on a shifted game make sure Hyrule Field Speed hack is disabled in dolphin! @@ -206,4 +211,4 @@ include tools/elf2dol/Makefile ### Debug Print ### print-% : ; $(info $* is a $(flavor $*) variable set to [$($*)]) @true -.PHONY: default all dirs clean tools docs shift game rungame print-% +.PHONY: default all dirs clean tools docs shift game rungame iso print-% diff --git a/tools/packageISO.py b/tools/packageISO.py new file mode 100644 index 00000000000..ad2f222172a --- /dev/null +++ b/tools/packageISO.py @@ -0,0 +1,111 @@ +import sys +import os +from pathlib import Path +import struct + +def addPaddingToFile(file,padding): + file.write(bytearray(padding - (file.tell() % padding))) + +def sortFileList(x): + l = [] + for c in x: + c = ord(c.lower()) + if c==ord('_'): + l.append(255) + else: + l.append(c) + return l + +def parseDir(dir,stringTable,currentEntryNum,parent): + os.chdir(dir) + entries = sorted(os.listdir('./'), key=sortFileList) + table = [] + for entry in entries: + currentEntryNum = currentEntryNum + 1 + tableEntry = {"name": entry, "children": None, "size": None,"stringTableOffset": len(stringTable),"entryNum": currentEntryNum,"parent": parent, "path": None} + stringTable = stringTable+entry+"\0" + if os.path.isdir(entry): + tableEntry["children"],stringTable,currentEntryNum = parseDir(entry,stringTable,currentEntryNum,tableEntry) + else: + tableEntry["size"] = os.path.getsize(entry) + tableEntry["path"] = os.path.abspath(entry) + + table.append(tableEntry) + os.chdir("..") + return table,stringTable,currentEntryNum + +def recurseWriteFst(files,fstBin,isoFile): + for currentFile in files: + if currentFile["children"]: #is a directory + nextDirEntryNum = 0 + testLastEntryFile = currentFile["children"][-1] + parentEntryNum = 0 + while True: + if testLastEntryFile["children"]: + testLastEntryFile = testLastEntryFile["children"][-1] + else: + nextDirEntryNum = testLastEntryFile["entryNum"]+1 + break + if currentFile["parent"]: + parentEntryNum = currentFile["parent"]["entryNum"] + fstBin.append(struct.pack(">BBHII",1,(currentFile["stringTableOffset"]>>16)&0xFF,currentFile["stringTableOffset"]&0xFFFF,parentEntryNum,nextDirEntryNum)) + recurseWriteFst(currentFile["children"],fstBin,isoFile) + else: #is a file + fstBin.append(struct.pack(">BBHII",0,(currentFile["stringTableOffset"]>>16)&0xFF,currentFile["stringTableOffset"]&0xFFFF,isoFile.tell(),currentFile["size"])) + isoFile.write(open(currentFile["path"],"rb").read()) + addPaddingToFile(isoFile,0x100) + + +def packageISO(sourcePath,destPath): + print("Converting filesystem into ISO") + + ISOfile = open(destPath,"wb") + #write sys files + ISOfile.write(open(sourcePath/"sys/boot.bin","rb").read()) + ISOfile.write(open(sourcePath/"sys/bi2.bin","rb").read()) + ISOfile.write(open(sourcePath/"sys/apploader.img","rb").read()) + addPaddingToFile(ISOfile,0x100) + + dolStartPos = ISOfile.tell() + ISOfile.seek(0x420) + ISOfile.write(struct.pack(">I",dolStartPos)) + ISOfile.seek(dolStartPos) + + ISOfile.write(open(sourcePath/"sys/main.dol","rb").read()) + addPaddingToFile(ISOfile,0x100) + + fstStartPos = ISOfile.tell() + + files,stringTable,entryLength = parseDir(sourcePath/"files","",0,None) + entryLength = entryLength + 1 + + ISOfile.seek(0x424) + ISOfile.write(struct.pack(">II",fstStartPos,(entryLength*12)+len(stringTable))) + + + #print(stringTable) + #print(files) + #print(hex(entryLength)) + #print(files[0]["entryNum"]) + + fstBin = [] + fstBin.append(struct.pack(">BBHII",1,0,0,0,entryLength)) + + ISOfile.seek(fstStartPos+(entryLength*12)+len(stringTable)) + addPaddingToFile(ISOfile,0x100) + recurseWriteFst(files,fstBin,ISOfile) + + ISOfile.write(bytearray(1459978240 - (ISOfile.tell()))) + + ISOfile.seek(fstStartPos) + for fileEntry in fstBin: + ISOfile.write(fileEntry) + ISOfile.seek((entryLength*12) + fstStartPos) + ISOfile.write(bytearray(stringTable,"utf8")) + + + + + +if __name__ == "__main__": + packageISO(Path(sys.argv[1]),Path(sys.argv[2])) \ No newline at end of file diff --git a/tools/package_game_assets.py b/tools/package_game_assets.py index 20bcf18f224..960ca1cc99b 100644 --- a/tools/package_game_assets.py +++ b/tools/package_game_assets.py @@ -6,7 +6,7 @@ from pathlib import Path import hashlib import struct import ctypes -import syaz0 +import oead def copy(path,destPath): @@ -224,7 +224,7 @@ def addFile(index,sizeIndex,dirs,name,stringTable,paths,data): path = relPath file.unk1 = 0 fileData = open(path,"rb") - compressedData = syaz0.compress(fileData.read()) + compressedData = oead.yaz0.compress(fileData.read()) padding = (0x20-(len(compressedData)%0x20)) file.fileLength = len(compressedData) file.fileOffset = sizeIndex @@ -255,7 +255,7 @@ def copyRelFiles(buildPath,aMemList,mMemList): relSource = open(fullPath,"rb") data = relSource.read() relSource.close() - data = syaz0.compress(data) + data = oead.yaz0.compress(data) relNew = open(buildPath/"game/files/rel/Final/Release"/file,"wb") relNew.write(data) relNew.truncate() From 248e523987cf5d2aca8de10e98d621ee66a47108 Mon Sep 17 00:00:00 2001 From: jdflyer Date: Fri, 30 Dec 2022 19:00:42 -0700 Subject: [PATCH 6/6] Python script formatting --- tools/extract_game_assets.py | 52 +++---- tools/packageISO.py | 124 +++++++++------ tools/package_game_assets.py | 285 ++++++++++++++++++++++------------- 3 files changed, 280 insertions(+), 181 deletions(-) diff --git a/tools/extract_game_assets.py b/tools/extract_game_assets.py index 44124d3d3cb..fc110081355 100644 --- a/tools/extract_game_assets.py +++ b/tools/extract_game_assets.py @@ -101,7 +101,7 @@ Write the current folder to disk and return it's name/last entry number def writeFolder(parsedFstBin, i): - folderPath = i["folderName"] + "/" + folderPath = i["folderName"] + "/" lastEntryNumber = i["lastEntryNumber"] if i["parentFolderEntryNumber"] == 0: @@ -133,8 +133,8 @@ def writeAssets(parsedFstBin, handler): j = 0 folderStack = [] if not os.path.exists("./files/"): - os.makedirs("./files/") - os.chdir('./files/') + os.makedirs("./files/") + os.chdir("./files/") folderStack.append({"folderName": "./", "lastEntryNumber": numFileEntries}) for i in parsedFstBin: j += 1 @@ -153,37 +153,38 @@ def writeAssets(parsedFstBin, handler): while folderStack[-1]["lastEntryNumber"] == j + 1: folderStack.pop() -def writeSys(boot,bi2,apploader,dol,fst): + +def writeSys(boot, bi2, apploader, dol, fst): if not os.path.exists("./sys/"): os.makedirs("./sys/") - open("./sys/boot.bin","wb").write(boot) - open("./sys/bi2.bin","wb").write(bi2) - open("./sys/apploader.img","wb").write(apploader) - open("./sys/main.dol","wb").write(dol) - open("./sys/fst.bin","wb").write(fst) + open("./sys/boot.bin", "wb").write(boot) + open("./sys/bi2.bin", "wb").write(bi2) + open("./sys/apploader.img", "wb").write(apploader) + open("./sys/main.dol", "wb").write(dol) + open("./sys/fst.bin", "wb").write(fst) + def getDolInfo(disc): disc.seek(dolInfoPosition) dolOffset = int.from_bytes(bytearray(disc.read(4)), byteorder="big") dolSize = 0 for i in range(7): - disc.seek(dolOffset+(i*4)) + disc.seek(dolOffset + (i * 4)) segmentOffset = int.from_bytes(bytearray(disc.read(4)), byteorder="big") - disc.seek(dolOffset+0x90+(i*4)) + disc.seek(dolOffset + 0x90 + (i * 4)) segmentSize = int.from_bytes(bytearray(disc.read(4)), byteorder="big") - if (segmentOffset+segmentSize)>dolSize: + if (segmentOffset + segmentSize) > dolSize: dolSize = segmentOffset + segmentSize - - for i in range(11): - disc.seek(dolOffset+0x1c+(i*4)) - dataOffset = int.from_bytes(bytearray(disc.read(4)), byteorder="big") - disc.seek(dolOffset+0xac+(i*4)) - dataSize = int.from_bytes(bytearray(disc.read(4)), byteorder="big") - if (dataOffset+dataSize)>dolSize: - dolSize = dataOffset + dataSize - - return dolOffset, dolSize + for i in range(11): + disc.seek(dolOffset + 0x1C + (i * 4)) + dataOffset = int.from_bytes(bytearray(disc.read(4)), byteorder="big") + disc.seek(dolOffset + 0xAC + (i * 4)) + dataSize = int.from_bytes(bytearray(disc.read(4)), byteorder="big") + if (dataOffset + dataSize) > dolSize: + dolSize = dataOffset + dataSize + + return dolOffset, dolSize def extract(path): @@ -198,9 +199,9 @@ def extract(path): f.seek(bi2Position) bi2Bytes = bytearray(f.read(bi2Size)) - f.seek(apploaderPosition+0x14) + f.seek(apploaderPosition + 0x14) apploaderSize = int.from_bytes(bytearray(f.read(4)), byteorder="big") - f.seek(apploaderPosition+0x18) + f.seek(apploaderPosition + 0x18) trailerSize = int.from_bytes(bytearray(f.read(4)), byteorder="big") apploaderMainSize = 0x20 + apploaderSize + trailerSize f.seek(apploaderPosition) @@ -208,13 +209,12 @@ def extract(path): dolOffset, dolSize = getDolInfo(f) f.seek(dolOffset) dolBytes = bytearray(f.read(dolSize)) - # Seek to fst.bin and retrieve it f.seek(fstOffset) fstBinBytes = bytearray(f.read(fstSize)) - writeSys(bootBytes,bi2Bytes,apploaderBytes,dolBytes,fstBinBytes) + writeSys(bootBytes, bi2Bytes, apploaderBytes, dolBytes, fstBinBytes) # Parse fst.bin parsedFstBin = parseFstBin(fstBinBytes) diff --git a/tools/packageISO.py b/tools/packageISO.py index ad2f222172a..a074318e330 100644 --- a/tools/packageISO.py +++ b/tools/packageISO.py @@ -3,40 +3,54 @@ import os from pathlib import Path import struct -def addPaddingToFile(file,padding): + +def addPaddingToFile(file, padding): file.write(bytearray(padding - (file.tell() % padding))) + def sortFileList(x): l = [] for c in x: c = ord(c.lower()) - if c==ord('_'): + if c == ord("_"): l.append(255) else: l.append(c) return l -def parseDir(dir,stringTable,currentEntryNum,parent): + +def parseDir(dir, stringTable, currentEntryNum, parent): os.chdir(dir) - entries = sorted(os.listdir('./'), key=sortFileList) + entries = sorted(os.listdir("./"), key=sortFileList) table = [] for entry in entries: currentEntryNum = currentEntryNum + 1 - tableEntry = {"name": entry, "children": None, "size": None,"stringTableOffset": len(stringTable),"entryNum": currentEntryNum,"parent": parent, "path": None} - stringTable = stringTable+entry+"\0" + tableEntry = { + "name": entry, + "children": None, + "size": None, + "stringTableOffset": len(stringTable), + "entryNum": currentEntryNum, + "parent": parent, + "path": None, + } + stringTable = stringTable + entry + "\0" if os.path.isdir(entry): - tableEntry["children"],stringTable,currentEntryNum = parseDir(entry,stringTable,currentEntryNum,tableEntry) + tableEntry["children"], stringTable, currentEntryNum = parseDir( + entry, stringTable, currentEntryNum, tableEntry + ) else: tableEntry["size"] = os.path.getsize(entry) tableEntry["path"] = os.path.abspath(entry) - + table.append(tableEntry) os.chdir("..") - return table,stringTable,currentEntryNum + return table, stringTable, currentEntryNum -def recurseWriteFst(files,fstBin,isoFile): + +def recurseWriteFst(files, fstBin, isoFile): for currentFile in files: - if currentFile["children"]: #is a directory + if currentFile["children"]: # is a directory nextDirEntryNum = 0 testLastEntryFile = currentFile["children"][-1] parentEntryNum = 0 @@ -44,68 +58,84 @@ def recurseWriteFst(files,fstBin,isoFile): if testLastEntryFile["children"]: testLastEntryFile = testLastEntryFile["children"][-1] else: - nextDirEntryNum = testLastEntryFile["entryNum"]+1 + nextDirEntryNum = testLastEntryFile["entryNum"] + 1 break if currentFile["parent"]: parentEntryNum = currentFile["parent"]["entryNum"] - fstBin.append(struct.pack(">BBHII",1,(currentFile["stringTableOffset"]>>16)&0xFF,currentFile["stringTableOffset"]&0xFFFF,parentEntryNum,nextDirEntryNum)) - recurseWriteFst(currentFile["children"],fstBin,isoFile) - else: #is a file - fstBin.append(struct.pack(">BBHII",0,(currentFile["stringTableOffset"]>>16)&0xFF,currentFile["stringTableOffset"]&0xFFFF,isoFile.tell(),currentFile["size"])) - isoFile.write(open(currentFile["path"],"rb").read()) - addPaddingToFile(isoFile,0x100) + fstBin.append( + struct.pack( + ">BBHII", + 1, + (currentFile["stringTableOffset"] >> 16) & 0xFF, + currentFile["stringTableOffset"] & 0xFFFF, + parentEntryNum, + nextDirEntryNum, + ) + ) + recurseWriteFst(currentFile["children"], fstBin, isoFile) + else: # is a file + fstBin.append( + struct.pack( + ">BBHII", + 0, + (currentFile["stringTableOffset"] >> 16) & 0xFF, + currentFile["stringTableOffset"] & 0xFFFF, + isoFile.tell(), + currentFile["size"], + ) + ) + isoFile.write(open(currentFile["path"], "rb").read()) + addPaddingToFile(isoFile, 0x100) -def packageISO(sourcePath,destPath): +def packageISO(sourcePath, destPath): print("Converting filesystem into ISO") - ISOfile = open(destPath,"wb") - #write sys files - ISOfile.write(open(sourcePath/"sys/boot.bin","rb").read()) - ISOfile.write(open(sourcePath/"sys/bi2.bin","rb").read()) - ISOfile.write(open(sourcePath/"sys/apploader.img","rb").read()) - addPaddingToFile(ISOfile,0x100) + ISOfile = open(destPath, "wb") + # write sys files + ISOfile.write(open(sourcePath / "sys/boot.bin", "rb").read()) + ISOfile.write(open(sourcePath / "sys/bi2.bin", "rb").read()) + ISOfile.write(open(sourcePath / "sys/apploader.img", "rb").read()) + addPaddingToFile(ISOfile, 0x100) dolStartPos = ISOfile.tell() ISOfile.seek(0x420) - ISOfile.write(struct.pack(">I",dolStartPos)) + ISOfile.write(struct.pack(">I", dolStartPos)) ISOfile.seek(dolStartPos) - ISOfile.write(open(sourcePath/"sys/main.dol","rb").read()) - addPaddingToFile(ISOfile,0x100) + ISOfile.write(open(sourcePath / "sys/main.dol", "rb").read()) + addPaddingToFile(ISOfile, 0x100) fstStartPos = ISOfile.tell() - files,stringTable,entryLength = parseDir(sourcePath/"files","",0,None) + files, stringTable, entryLength = parseDir(sourcePath / "files", "", 0, None) entryLength = entryLength + 1 ISOfile.seek(0x424) - ISOfile.write(struct.pack(">II",fstStartPos,(entryLength*12)+len(stringTable))) - + ISOfile.write( + struct.pack(">II", fstStartPos, (entryLength * 12) + len(stringTable)) + ) + + # print(stringTable) + # print(files) + # print(hex(entryLength)) + # print(files[0]["entryNum"]) - #print(stringTable) - #print(files) - #print(hex(entryLength)) - #print(files[0]["entryNum"]) - fstBin = [] - fstBin.append(struct.pack(">BBHII",1,0,0,0,entryLength)) + fstBin.append(struct.pack(">BBHII", 1, 0, 0, 0, entryLength)) - ISOfile.seek(fstStartPos+(entryLength*12)+len(stringTable)) - addPaddingToFile(ISOfile,0x100) - recurseWriteFst(files,fstBin,ISOfile) + ISOfile.seek(fstStartPos + (entryLength * 12) + len(stringTable)) + addPaddingToFile(ISOfile, 0x100) + recurseWriteFst(files, fstBin, ISOfile) ISOfile.write(bytearray(1459978240 - (ISOfile.tell()))) - + ISOfile.seek(fstStartPos) for fileEntry in fstBin: ISOfile.write(fileEntry) - ISOfile.seek((entryLength*12) + fstStartPos) - ISOfile.write(bytearray(stringTable,"utf8")) - - - + ISOfile.seek((entryLength * 12) + fstStartPos) + ISOfile.write(bytearray(stringTable, "utf8")) if __name__ == "__main__": - packageISO(Path(sys.argv[1]),Path(sys.argv[2])) \ No newline at end of file + packageISO(Path(sys.argv[1]), Path(sys.argv[2])) diff --git a/tools/package_game_assets.py b/tools/package_game_assets.py index 960ca1cc99b..ae1053e833c 100644 --- a/tools/package_game_assets.py +++ b/tools/package_game_assets.py @@ -9,22 +9,22 @@ import ctypes import oead -def copy(path,destPath): - for root,dirs,files in os.walk(str(path)): +def copy(path, destPath): + for root, dirs, files in os.walk(str(path)): for file in files: - outputDir = destPath/Path(str(root)) - #print(str(outputDir.absolute())+file) + outputDir = destPath / Path(str(root)) + # print(str(outputDir.absolute())+file) if not outputDir.absolute().exists(): os.makedirs(outputDir.absolute()) - outputFile = Path(str(outputDir.absolute())+"/"+str(file)) - inFile = Path(str(Path(root).absolute())+"/"+str(file)) + outputFile = Path(str(outputDir.absolute()) + "/" + str(file)) + inFile = Path(str(Path(root).absolute()) + "/" + str(file)) if not outputFile.exists(): - print(str(inFile)+" -> "+str(outputFile)) - shutil.copyfile(inFile,outputFile) + print(str(inFile) + " -> " + str(outputFile)) + shutil.copyfile(inFile, outputFile) else: - if os.path.getmtime(inFile)>os.path.getmtime(outputFile): - print(str(inFile)+" -> "+str(outputFile)) - shutil.copyfile(inFile,outputFile) + if os.path.getmtime(inFile) > os.path.getmtime(outputFile): + print(str(inFile) + " -> " + str(outputFile)) + shutil.copyfile(inFile, outputFile) aMemRels = """d_a_alldie.rel @@ -163,56 +163,62 @@ d_a_vrbox.rel d_a_vrbox2.rel f_pc_profile_lst.rel""" -#Because libarc is only geared toward reading from arcs I'm writing my own arc writer in this file +# Because libarc is only geared toward reading from arcs I'm writing my own arc writer in this file + class HEADER: - RARC : int - length : int - headerLength : int - fileDataOffset : int - fileDataLen : int - fileDataLen2 : int - unk1 : int - unk2 : int + RARC: int + length: int + headerLength: int + fileDataOffset: int + fileDataLen: int + fileDataLen2: int + unk1: int + unk2: int + class INFO: - numNodes : int - firstNodeOffset : int - totalDirNum : int - firstDirOffset : int - stringTableLen : int - stringTableOffset : int - numDirsThatAreFiles : int - unk1 : int - unk2 : int + numNodes: int + firstNodeOffset: int + totalDirNum: int + firstDirOffset: int + stringTableLen: int + stringTableOffset: int + numDirsThatAreFiles: int + unk1: int + unk2: int + class NODE: - NAME : int + NAME: int stringTableOffset: int - hash : int - numDirs : int - firstDirIndex : int + hash: int + numDirs: int + firstDirIndex: int + class DIRECTORY: - dirIndex : int - stringHash : int - type : int - stringOffset : int - fileOffset : int - fileLength : int - unk1 : int + dirIndex: int + stringHash: int + type: int + stringOffset: int + fileOffset: int + fileLength: int + unk1: int + def computeHash(string): hash = 0 for char in string: - hash = hash*3 + hash = hash * 3 hash = hash + ord(char) hash = ctypes.c_ushort(hash) hash = hash.value return hash -def addFile(index,sizeIndex,dirs,name,stringTable,paths,data): + +def addFile(index, sizeIndex, dirs, name, stringTable, paths, data): file = DIRECTORY() file.dirIndex = index file.stringHash = computeHash(name) @@ -220,12 +226,12 @@ def addFile(index,sizeIndex,dirs,name,stringTable,paths,data): file.stringOffset = stringTable.find(name) path = None for relPath in paths: - if str(relPath).find(name)!=-1: + if str(relPath).find(name) != -1: path = relPath file.unk1 = 0 - fileData = open(path,"rb") + fileData = open(path, "rb") compressedData = oead.yaz0.compress(fileData.read()) - padding = (0x20-(len(compressedData)%0x20)) + padding = 0x20 - (len(compressedData) % 0x20) file.fileLength = len(compressedData) file.fileOffset = sizeIndex sizeIndex = sizeIndex + file.fileLength + padding @@ -234,37 +240,41 @@ def addFile(index,sizeIndex,dirs,name,stringTable,paths,data): fileData.close() dirs.append(file) - return dirs,data,sizeIndex + return dirs, data, sizeIndex -def copyRelFiles(buildPath,aMemList,mMemList): +def copyRelFiles(buildPath, aMemList, mMemList): relArcPaths = [] - for root,dirs,files in os.walk(str(buildPath/"rel")): + for root, dirs, files in os.walk(str(buildPath / "rel")): for file in files: - if file.find(".rel")!=-1: + if file.find(".rel") != -1: relArcFound = False for rel in aMemList: - if rel==file: + if rel == file: relArcFound = True for rel in mMemList: - if rel==file: + if rel == file: relArcFound = True - fullPath = Path(root+"/"+file) - if relArcFound==False: - print(str(fullPath)+" -> "+str(buildPath/"game/files/rel/Final/Release"/file)) - relSource = open(fullPath,"rb") + fullPath = Path(root + "/" + file) + if relArcFound == False: + print( + str(fullPath) + + " -> " + + str(buildPath / "game/files/rel/Final/Release" / file) + ) + relSource = open(fullPath, "rb") data = relSource.read() relSource.close() data = oead.yaz0.compress(data) - relNew = open(buildPath/"game/files/rel/Final/Release"/file,"wb") + relNew = open( + buildPath / "game/files/rel/Final/Release" / file, "wb" + ) relNew.write(data) relNew.truncate() relNew.close() else: relArcPaths.append(fullPath) - - arcHeader = HEADER() arcHeader.RARC = 0x52415243 arcHeader.headerLength = 0x20 @@ -279,24 +289,24 @@ def copyRelFiles(buildPath,aMemList,mMemList): rootNode.firstDirIndex = 0 rootNode.hash = computeHash("rels") aMemNode = NODE() - aMemNode.NAME = 0x414d454d + aMemNode.NAME = 0x414D454D aMemNode.hash = computeHash("amem") aMemNode.numDirs = 79 aMemNode.firstDirIndex = 4 mMemNode = NODE() mMemNode.hash = computeHash("mmem") - mMemNode.NAME = 0x4d4d454d + mMemNode.NAME = 0x4D4D454D mMemNode.numDirs = 59 mMemNode.firstDirIndex = 83 stringTable = ".\0..\0rels\0amem\0" for rel in aMemList: - stringTable = stringTable+rel+'\0' - stringTable = stringTable+"mmem\0" + stringTable = stringTable + rel + "\0" + stringTable = stringTable + "mmem\0" for rel in mMemList: - stringTable = stringTable+rel+'\0' - stringTable = stringTable+"\0\0\0\0\0\0" - + stringTable = stringTable + rel + "\0" + stringTable = stringTable + "\0\0\0\0\0\0" + rootNode.stringTableOffset = stringTable.find("rels") aMemNode.stringTableOffset = stringTable.find("amem") mMemNode.stringTableOffset = stringTable.find("mmem") @@ -337,26 +347,30 @@ def copyRelFiles(buildPath,aMemList,mMemList): unkDir2.fileLength = 0x10 unkDir2.unk1 = 0 - dirs = [aMemDir,mMemDir,unkDir,unkDir2] + dirs = [aMemDir, mMemDir, unkDir, unkDir2] data = bytearray() dirIndex = 4 sizeIndex = 0 for rel in aMemList: - retdirs,retdata,retSize = addFile(dirIndex,sizeIndex,dirs,rel,stringTable,relArcPaths,data) - dirIndex = dirIndex+1 + retdirs, retdata, retSize = addFile( + dirIndex, sizeIndex, dirs, rel, stringTable, relArcPaths, data + ) + dirIndex = dirIndex + 1 sizeIndex = retSize dirs = retdirs data = retdata dirs.append(unkDir) dirs.append(unkDir2) - dirIndex = dirIndex+2 + dirIndex = dirIndex + 2 for rel in mMemList: - retdirs,retdata,retSize = addFile(dirIndex,sizeIndex,dirs,rel,stringTable,relArcPaths,data) - dirIndex = dirIndex+1 + retdirs, retdata, retSize = addFile( + dirIndex, sizeIndex, dirs, rel, stringTable, relArcPaths, data + ) + dirIndex = dirIndex + 1 sizeIndex = retSize - #print(hex(dirIndex)) + # print(hex(dirIndex)) dirs = retdirs data = retdata unkDir3 = DIRECTORY() @@ -378,12 +392,14 @@ def copyRelFiles(buildPath,aMemList,mMemList): unkDir4.unk1 = 0 dirs.append(unkDir3) dirs.append(unkDir4) - dirIndex = dirIndex+2 + dirIndex = dirIndex + 2 - arcHeader.length = len(stringTable)+0x20+0x20+0x30+(len(dirs)*0x14)+len(data) - arcHeader.fileDataOffset=0x14E0 - arcHeader.fileDataLen=len(data) - arcHeader.fileDataLen2=arcHeader.fileDataLen + arcHeader.length = ( + len(stringTable) + 0x20 + 0x20 + 0x30 + (len(dirs) * 0x14) + len(data) + ) + arcHeader.fileDataOffset = 0x14E0 + arcHeader.fileDataLen = len(data) + arcHeader.fileDataLen2 = arcHeader.fileDataLen infoBlock.firstNodeOffset = 0x20 infoBlock.firstDirOffset = 0x60 @@ -393,49 +409,100 @@ def copyRelFiles(buildPath,aMemList,mMemList): infoBlock.unk2 = 0 infoBlock.totalDirNum = 0x8E - - outputArcFile = open(buildPath/"game/files/RELS.arc","wb") + outputArcFile = open(buildPath / "game/files/RELS.arc", "wb") outputArcFile.seek(0) - outputArcFile.write(struct.pack(">IIIIIIII",arcHeader.RARC,arcHeader.length,arcHeader.headerLength,arcHeader.fileDataOffset,arcHeader.fileDataLen,arcHeader.unk1,arcHeader.fileDataLen2,arcHeader.unk2)) - outputArcFile.write(struct.pack(">IIIIIIHHI",infoBlock.numNodes,infoBlock.firstNodeOffset,infoBlock.totalDirNum,infoBlock.firstDirOffset,infoBlock.stringTableLen,infoBlock.stringTableOffset,infoBlock.numDirsThatAreFiles,infoBlock.unk1,infoBlock.unk2)) - outputArcFile.write(struct.pack(">IIHHI",rootNode.NAME,rootNode.stringTableOffset,rootNode.hash,rootNode.numDirs,rootNode.firstDirIndex)) - outputArcFile.write(struct.pack(">IIHHI",aMemNode.NAME,aMemNode.stringTableOffset,aMemNode.hash,aMemNode.numDirs,aMemNode.firstDirIndex)) - outputArcFile.write(struct.pack(">IIHHI",mMemNode.NAME,mMemNode.stringTableOffset,mMemNode.hash,mMemNode.numDirs,mMemNode.firstDirIndex)) + outputArcFile.write( + struct.pack( + ">IIIIIIII", + arcHeader.RARC, + arcHeader.length, + arcHeader.headerLength, + arcHeader.fileDataOffset, + arcHeader.fileDataLen, + arcHeader.unk1, + arcHeader.fileDataLen2, + arcHeader.unk2, + ) + ) + outputArcFile.write( + struct.pack( + ">IIIIIIHHI", + infoBlock.numNodes, + infoBlock.firstNodeOffset, + infoBlock.totalDirNum, + infoBlock.firstDirOffset, + infoBlock.stringTableLen, + infoBlock.stringTableOffset, + infoBlock.numDirsThatAreFiles, + infoBlock.unk1, + infoBlock.unk2, + ) + ) + outputArcFile.write( + struct.pack( + ">IIHHI", + rootNode.NAME, + rootNode.stringTableOffset, + rootNode.hash, + rootNode.numDirs, + rootNode.firstDirIndex, + ) + ) + outputArcFile.write( + struct.pack( + ">IIHHI", + aMemNode.NAME, + aMemNode.stringTableOffset, + aMemNode.hash, + aMemNode.numDirs, + aMemNode.firstDirIndex, + ) + ) + outputArcFile.write( + struct.pack( + ">IIHHI", + mMemNode.NAME, + mMemNode.stringTableOffset, + mMemNode.hash, + mMemNode.numDirs, + mMemNode.firstDirIndex, + ) + ) outputArcFile.write(bytearray(16)) for dir in dirs: - outputArcFile.write(struct.pack(">HHHHIII",dir.dirIndex,dir.stringHash,dir.type,dir.stringOffset,dir.fileOffset,dir.fileLength,dir.unk1)) + outputArcFile.write( + struct.pack( + ">HHHHIII", + dir.dirIndex, + dir.stringHash, + dir.type, + dir.stringOffset, + dir.fileOffset, + dir.fileLength, + dir.unk1, + ) + ) outputArcFile.write(bytearray(8)) strBytearray = bytearray() - strBytearray.extend(map(ord,stringTable)) + strBytearray.extend(map(ord, stringTable)) outputArcFile.write(strBytearray) outputArcFile.write(data) outputArcFile.truncate() outputArcFile.close() - - - - - - - - - - - -def main(gamePath,buildPath): +def main(gamePath, buildPath): if not gamePath.exists(): gamePath.mkdir(parents=True, exist_ok=True) - + iso = Path("gz2e01.iso") if not iso.exists() or not iso.is_file(): print("gz2e01.iso doesn't exist in project directory!") sys.exit(1) - - if not (gamePath/"files").exists() or not (gamePath/"sys").exists(): + + if not (gamePath / "files").exists() or not (gamePath / "sys").exists(): print("ISO is not extracted; extracting...") previousDir = os.getcwd() os.chdir(str(gamePath.absolute())) @@ -443,15 +510,17 @@ def main(gamePath,buildPath): os.chdir(previousDir) print("Copying game files...") - copy(gamePath,buildPath.absolute()) + copy(gamePath, buildPath.absolute()) - print(str(buildPath/"main_shift.dol")+" -> "+str(buildPath/"game/sys/main.dol")) - shutil.copyfile(buildPath/"main_shift.dol",buildPath/"game/sys/main.dol") - - copyRelFiles(buildPath,aMemRels.splitlines(),mMemRels.splitlines()) + print( + str(buildPath / "main_shift.dol") + + " -> " + + str(buildPath / "game/sys/main.dol") + ) + shutil.copyfile(buildPath / "main_shift.dol", buildPath / "game/sys/main.dol") + copyRelFiles(buildPath, aMemRels.splitlines(), mMemRels.splitlines()) - if __name__ == "__main__": - main(Path(sys.argv[1]),Path(sys.argv[2])) \ No newline at end of file + main(Path(sys.argv[1]), Path(sys.argv[2]))