summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAECX <maurice.henke@protonmail.com>2021-02-18 10:34:48 +0100
committerGitHub <noreply@github.com>2021-02-18 10:34:48 +0100
commitaad6ffee2e9d17839145a7bea9d0dbc63accd196 (patch)
tree2e386e05a6309daaba823f43e4da444209b78098
parentd62408f9d8b798c77ca47bfe747124666c64b603 (diff)
parent83965c2855e898614b54ca86664b7b5e7033a260 (diff)
Merge pull request #2 from jdflyer/stable
BGM Randomization
-rw-r--r--include/musicRando.h7
-rw-r--r--include/tp.eu.lst5
-rw-r--r--include/tp.jp.lst5
-rw-r--r--include/tp.us.lst3
-rw-r--r--include/tp/Z2SceneMgr.h13
-rw-r--r--source/mod.cpp7
-rw-r--r--source/musicRando.cpp165
7 files changed, 203 insertions, 2 deletions
diff --git a/include/musicRando.h b/include/musicRando.h
new file mode 100644
index 0000000..7870a05
--- /dev/null
+++ b/include/musicRando.h
@@ -0,0 +1,7 @@
+#pragma once
+#include "defines.h"
+
+namespace mod::musicrando {
+ extern u8 musicRandoEnabled;
+ void initMusicRando();
+} \ No newline at end of file
diff --git a/include/tp.eu.lst b/include/tp.eu.lst
index 04bc152..b250747 100644
--- a/include/tp.eu.lst
+++ b/include/tp.eu.lst
@@ -178,4 +178,7 @@
80408956:can_warp
//d_meter2_info.o
-80432164:wZButtonPtr \ No newline at end of file
+80432164:wZButtonPtr
+
+//Z2SceneMgr
+802BA968:sceneChange
diff --git a/include/tp.jp.lst b/include/tp.jp.lst
index b4e2fe7..0ee2a64 100644
--- a/include/tp.jp.lst
+++ b/include/tp.jp.lst
@@ -179,4 +179,7 @@
80400AF6:can_warp
//d_meter2_info.o
-8042A2E4:wZButtonPtr \ No newline at end of file
+8042A2E4:wZButtonPtr
+
+//Z2SceneMgr
+802BBFA8:sceneChange
diff --git a/include/tp.us.lst b/include/tp.us.lst
index 8ba6c1c..3a58939 100644
--- a/include/tp.us.lst
+++ b/include/tp.us.lst
@@ -194,3 +194,6 @@
//d_meter2_info.o
804301A4:wZButtonPtr
+
+//Z2SceneMgr
+802B9B68:sceneChange
diff --git a/include/tp/Z2SceneMgr.h b/include/tp/Z2SceneMgr.h
new file mode 100644
index 0000000..f3aa195
--- /dev/null
+++ b/include/tp/Z2SceneMgr.h
@@ -0,0 +1,13 @@
+#pragma once
+#include "defines.h"
+
+struct Z2SceneMgr;
+
+struct JAISoundID {
+ u32 id;
+};
+namespace tp::Z2AudioLib::SceneMgr {
+ extern "C" {
+ void sceneChange(Z2SceneMgr* sceneMgr, JAISoundID id,u8 SeWave1,u8 SeWave2,u8 BgmWave1,u8 BgmWave2,u8 DemoWave,bool param_7);
+ };
+}
diff --git a/source/mod.cpp b/source/mod.cpp
index f4945d7..e030760 100644
--- a/source/mod.cpp
+++ b/source/mod.cpp
@@ -38,6 +38,7 @@
#include "stage.h"
#include "systemConsole.h"
#include "tools.h"
+#include "musicRando.h"
namespace mod
{
@@ -277,6 +278,10 @@ hudConsole->addWatch(page, "throw:", &throwResult, 'x', WatchInterpretation::_u1
hudConsole->addOption(page, "LTN Ot Green:", &outerGreen, 0xFF);
hudConsole->addOption(page, "LTN Ot Blue:", &outerBlue, 0xFF);
+ //Bgm Options
+ page = hudConsole->addPage("BGM");
+ hudConsole->addOption(page, "BGM Rando: ",&musicrando::musicRandoEnabled,0x1);
+
// local area
/*page = hudConsole->addPage("Local Area 1");
hudConsole->addWatch(page, "AreaNodes0:", &gameInfo.localAreaNodes.unk_0[0], 'x', WatchInterpretation::_u8);
@@ -891,6 +896,7 @@ hudConsole->addWatch(page, "throw:", &throwResult, 'x', WatchInterpretation::_u1
customSeed = true;
tools::randomSeed = *global::seedInSaveFile;
chestRandomizer->generate();
+ musicrando::initMusicRando();
}
}
@@ -949,6 +955,7 @@ hudConsole->addWatch(page, "throw:", &throwResult, 'x', WatchInterpretation::_u1
// manually in the save data
*global::seedInSaveFile = tools::randomSeed;
chestRandomizer->generate();
+ musicrando::initMusicRando();
}
// Parse inputs of this frame
diff --git a/source/musicRando.cpp b/source/musicRando.cpp
new file mode 100644
index 0000000..ac8ed16
--- /dev/null
+++ b/source/musicRando.cpp
@@ -0,0 +1,165 @@
+#include "musicRando.h"
+#include "tools.h"
+#include "patch.h"
+#include "tp/Z2SceneMgr.h"
+
+struct BGM { //Struct to store info about the source of BGM and the waves required to play correctly. Not using full Ids here to save memory
+ u8 id = 0x0;
+ u8 bgmwave_1 = 0x0;
+ u8 bgmwave_2 = 0x0;
+};
+
+static const BGM bgmSource[] = {
+{0x0,0x19},
+{0x1,0x19},
+{0x4,0xd},
+{0x5,0x3,0x4},
+{0x6,0x1,0x2},
+{0x9,0xa,0x40},
+{0xd,0xc},
+{0xe,0xc},
+{0xf},
+{0x10,0x1,0x2},
+{0x11,0x1,0x2},
+{0x16,0xe},
+{0x17,0x5},
+{0x18,0x13,0x3c},
+{0x1a,0x11},
+{0x1b,0xe},
+{0x1d,0x13,0x14},
+{0x1e,0x7},
+{0x1f,0x7},
+{0x20,0x15,0x40},
+{0x23,0xf},
+{0x24,0x8,0x9},
+{0x25,0x16},
+{0x26,0x10,0x18},
+{0x27,0x15,0x17},
+{0x29,0x10,0x18},
+{0x2c,0x8},
+{0x2d,0x1a,0x41},
+//{0x2e,0x40}, //Lost woods statue game (Currently doesn't work)
+{0x2f,0xe,0x1c},
+{0x30,0x1e},
+{0x31,0x1e},
+{0x34,0x1f},
+{0x35,0x20},
+{0x36,0xe,0x1c},
+{0x37,0x1d,0x40},
+{0x39,0x28,0x48},
+{0x3a,0x24},
+{0x3b,0x25},
+{0x3c,0x26,0x40},
+{0x3d,0x27},
+{0x3e,0x28},
+{0x3f,0x29},
+{0x40,0x11,0x12},
+{0x41,0x2a,0x1b},
+{0x42,0x2b},
+{0x47,0xe,0x2c},
+{0x48,0x2c},
+{0x49},
+{0x4a,0x2d,0x3a},
+{0x4b,0x2d,0x3a},
+{0x4c,0x2e},
+{0x4d,0x2e},
+{0x50,0x2f},
+{0x51,0x30},
+{0x57,0x31},
+{0x58,0x32},
+{0x59,0x33},
+{0x5a,0x34}, //Lake hylia, but plays plums song; MUST FIGURE OUT
+{0x5e,0x35},
+{0x5f,0x36},
+{0x60,0x37},
+{0x61,0x26,0x3f},
+{0x62,0x39},
+{0x6b,0x3e},
+{0x6c,0x26,0x3f},
+{0x6d,0x40},
+{0x6e,0x24,0x57},
+{0x6f,0x26,0x3f},
+{0x70,0x44},
+{0x77,0x45},
+{0x78,0x46},
+{0x7a,0x46},
+{0x85,0x28,0x48},
+{0x86,0x49},
+{0x87,0x4a},
+{0x88,0x4b},
+{0x8b,0x4c,0x1a},
+{0x8c,0x4c,0x1a},
+{0x8f,0x1e,0x27},
+{0x90,0x1e,0x27},
+{0x91,0x8,0x47},
+{0x94,0x4e,0x26},
+{0x95,0x4e,0x26},
+{0x96,0x1c,0xe}, //might not be right
+{0x97,0x3d,0x1c},
+{0x9a,0x8},
+{0x9b,0x56},
+{0x9e,0x19},
+{0x9f,0x55},
+{0xa5,0x57},
+{0xa8,0x58,0x29}, //Might not be right
+{0xa9,0x59}
+};
+
+const u8 bgmSource_length = sizeof(bgmSource)/sizeof(BGM);
+
+static u8 randomizedBGMs[bgmSource_length];
+
+void (*sceneChange_trampoline)(Z2SceneMgr* sceneMgr, JAISoundID id,u8 SeWave1,u8 SeWave2,u8 BgmWave1,u8 BgmWave2,u8 DemoWave,bool param_7) = nullptr;
+
+void sceneChangeHook(Z2SceneMgr* sceneMgr, JAISoundID BGMId,u8 SeWave1,u8 SeWave2,u8 BgmWave1,u8 BgmWave2,u8 DemoWave,bool param_7) {
+ u32 id = BGMId.id;
+ if (mod::musicrando::musicRandoEnabled && id>=0x1000000 && id<0x2000000)
+ {
+ //Only Sequences are applied here
+ id = id-0x1000000;
+ u8 index_of_id = 0;
+ bool found = false;
+ for (u8 i = 0; i < bgmSource_length; i++) {
+ if (randomizedBGMs[i] == id) {
+ index_of_id = i;
+ found = true;
+ break;
+ }
+ }
+ if (found) {
+ JAISoundID new_id;
+ new_id.id = bgmSource[index_of_id].id + 0x1000000;
+ sceneChange_trampoline(sceneMgr,new_id,SeWave1,SeWave2,bgmSource[index_of_id].bgmwave_1,bgmSource[index_of_id].bgmwave_2,DemoWave,param_7);
+ }else{
+ sceneChange_trampoline(sceneMgr,BGMId,SeWave1,SeWave2,BgmWave1,BgmWave2,DemoWave,param_7);
+ }
+ }else{
+ sceneChange_trampoline(sceneMgr,BGMId,SeWave1,SeWave2,BgmWave1,BgmWave2,DemoWave,param_7);
+ }
+}
+
+namespace mod::musicrando {
+ u8 musicRandoEnabled = 0;
+ void initMusicRando() {
+ for(u8 i = 0; i<bgmSource_length; i++){ //Fills in the randomizedBGMs array with random ids
+ bool gotUnique = false;
+ while (!gotUnique) { //Depends on randomness to shuffle the original array; needs a better method
+ u8 random = tools::getRandom(bgmSource_length);
+ u8 idGot = bgmSource[random].id;
+ bool valueExists = false;
+ for (u8 j = 0; j<i; j++) {
+ if (randomizedBGMs[j] == idGot){
+ valueExists = true;
+ }
+ }
+ if (valueExists == false){
+ randomizedBGMs[i] = bgmSource[random].id;
+ gotUnique = true;
+ }
+ }
+ }
+ if (sceneChange_trampoline == nullptr) {
+ sceneChange_trampoline = mod::patch::hookFunction(tp::Z2AudioLib::SceneMgr::sceneChange,sceneChangeHook);
+ }
+ }
+} //namespace mod::musicrando