From 00c0d32c57bea82f703b818513680ebcdc7775ce Mon Sep 17 00:00:00 2001
From: Colin Noga <Tempus@chronometry.ca>
Date: Wed, 29 May 2013 16:15:00 -0500
Subject: Added secret hardmode, press A/B/+ on star coin screen

---
 NewerProjectKP.yaml        |  1 +
 hardMode.yaml              | 28 ++++++++++++++++++
 src/hardMode.s             | 71 ++++++++++++++++++++++++++++++++++++++++++++++
 src/koopatlas/starcoin.cpp | 35 +++++++++++++++++++++++
 4 files changed, 135 insertions(+)
 create mode 100644 hardMode.yaml
 create mode 100644 src/hardMode.s

diff --git a/NewerProjectKP.yaml b/NewerProjectKP.yaml
index 57cc063..9ee51cf 100644
--- a/NewerProjectKP.yaml
+++ b/NewerProjectKP.yaml
@@ -4,6 +4,7 @@ modules:
   - processed/prolog.yaml
   - processed/corseClear.yaml
   - processed/apDebug.yaml
+  - processed/hardMode.yaml
 #  - processed/layoutDebug.yaml
   - processed/creditsMgr.yaml
   - processed/endingMgr.yaml
diff --git a/hardMode.yaml b/hardMode.yaml
new file mode 100644
index 0000000..7eac5cf
--- /dev/null
+++ b/hardMode.yaml
@@ -0,0 +1,28 @@
+---
+source_files: [../src/hardMode.s]
+hooks:
+
+
+  - name: OneHitKill
+    type: branch_insn
+    branch_type: bl
+    src_addr_pal: 0x801465DC
+    target_func: 'OneHitKill'
+
+  - name: TimerAdjustments
+    type: branch_insn
+    branch_type: bl
+    src_addr_pal: 0x800E3AB8
+    target_func: 'TimerAdjustments'
+
+
+  # - name: OneHitKill
+  #   type: patch
+  #   addr_pal: 0x801465E0
+  #   data: '4800000C'
+  #   # data: '60000000'
+
+  # - name: TimerAdjustments
+  #   type: patch
+  #   addr_pal: 0x800E3AB8
+  #   data: '3403FF38'
diff --git a/src/hardMode.s b/src/hardMode.s
new file mode 100644
index 0000000..95b6f80
--- /dev/null
+++ b/src/hardMode.s
@@ -0,0 +1,71 @@
+#ifndef __MWERKS__
+.set r0,0;   .set r1,1;   .set r2,2; .set r3,3;   .set r4,4
+.set r5,5;   .set r6,6;   .set r7,7;   .set r8,8;   .set r9,9
+.set r10,10; .set r11,11; .set r12,12; .set r13,13; .set r14,14
+.set r15,15; .set r16,16; .set r17,17; .set r18,18; .set r19,19
+.set r20,20; .set r21,21; .set r22,22; .set r23,23; .set r24,24
+.set r25,25; .set r26,26; .set r27,27; .set r28,28; .set r29,29
+.set r30,30; .set r31,31; .set f0,0; .set f1,1; .set f2,2
+.set f3,3; .set f4,4; .set f5,5; .set f6,6; .set f8,8
+.set f31,31; .set f30,30
+#endif
+
+
+.text
+
+.align 4
+
+.global TimerAdjustments
+TimerAdjustments:
+
+	lis 	r10, enableHardMode@h
+	ori 	r10, r10, enableHardMode@l
+	lbz 	r10, 0(r10)
+	cmpwi 	r10, 0
+	beq 	NoTimerAdjust
+
+	li		r10, 300
+	slwi	r10, r10, 0xC
+	cmp		r3, r10
+	blt		NoTimerAdjust
+
+	mr		r3, r10
+
+	b 		NoTimerAdjust
+
+NoTimerAdjust:
+
+	subic.	r0, r3, 92	
+	blr
+
+
+
+.global OneHitKill
+OneHitKill:
+
+	lis 	r10, enableHardMode@h
+	ori 	r10, r10, enableHardMode@l
+	lbz 	r10, 0(r10)
+	cmpwi 	r10, 0
+	beq 	NoOneHitKill
+
+	li		r0, 0
+	cmpwi	r0, 0
+	blr
+
+NoOneHitKill:
+
+	cmpwi	r0, 0
+	blr
+
+
+
+.align 4
+
+.data
+
+.global enableHardMode
+enableHardMode:
+	.byte 0
+
+.align 4
diff --git a/src/koopatlas/starcoin.cpp b/src/koopatlas/starcoin.cpp
index 34c1982..5725ceb 100644
--- a/src/koopatlas/starcoin.cpp
+++ b/src/koopatlas/starcoin.cpp
@@ -373,6 +373,7 @@ static const int secretCode[] = {
 static const int secretCodeButtons = WPAD_UP|WPAD_DOWN|WPAD_LEFT|WPAD_RIGHT|WPAD_ONE|WPAD_TWO;
 static int secretCodeIndex = 0;
 static int minusCount = 0;
+extern bool enableHardMode;
 extern bool enableDebugMode;
 extern u8 isReplayEnabled;
 
@@ -442,6 +443,38 @@ void dWMStarCoin_c::beginState_Wait() { }
 void dWMStarCoin_c::executeState_Wait() {
 	int nowPressed = Remocon_GetPressed(GetActiveRemocon());
 
+	if ((GetActiveRemocon()->heldButtons == 0xc10) && (nowPressed & 0xc10)) { // A, B, and Plus
+
+		const int lineCountOn = 9, lineCountOff = 2;
+		static const wchar_t *linesOn[lineCountOn] = {
+			L"You've activated Hard Mode",
+			L" ",
+			L"In Hard Mode, Mario will die",
+			L"any time he takes damage, and",
+			L"the timer will be more strict.",
+			L" ",
+			L"So treasure your Yoshi, and",
+			L"and hold on to your hats, you're",
+			L"in for a wild ride!",
+		};
+		static const wchar_t *linesOff[lineCountOff] = {
+			L"Hard Mode has been",
+			L"turned off.",
+		};
+
+		if (!enableHardMode) {
+			enableHardMode = true;
+			OSReport("Hard Mode enabled!\n");
+			MapSoundPlayer(SoundRelatedClass, SE_VOC_MA_CS_COURSE_IN_HARD, 1);
+			showSecretMessage(L"Hard Mode", linesOn, lineCountOn);
+		} else {
+			enableHardMode = false;
+			OSReport("Hard Mode disabled!\n");
+			showSecretMessage(L"Classic Mario", linesOff, lineCountOff);
+		}
+		return;
+	}
+
 	if (nowPressed & secretCodeButtons) {
 		int nextKey = secretCode[secretCodeIndex];
 		if (nowPressed & nextKey) {
@@ -492,6 +525,8 @@ void dWMStarCoin_c::executeState_Wait() {
 			enableDebugMode = !enableDebugMode;
 
 			if (enableDebugMode) {
+				MapSoundPlayer(SoundRelatedClass, SE_VOC_MA_GET_PRIZE, 1);
+
 				const int msgCount = 9;
 				static const wchar_t *msg[msgCount] = {
 					L"You've found the Totally",
-- 
cgit v1.2.3