shithub: cstory

Download patch

ref: e43160825e95651a8b34cb70441504d1c5023845
parent: 541ec3695e75ace3713deeda4e42480595e3af13
author: Clownacy <Clownacy@users.noreply.github.com>
date: Thu Sep 3 16:35:51 EDT 2020

Add bugfix for the broken Waterway TSC script

--- a/src/TextScr.cpp
+++ b/src/TextScr.cpp
@@ -898,6 +898,32 @@
 						x = GetTextScriptNo(gTS.p_read + 4);
 						z = GetTextScriptNo(gTS.p_read + 9);
 
+					#ifdef FIX_BUGS
+						// Some versions of the Waterway TSC script contain a bug:
+						//  <FLJ850:0111
+						// This command *should* be...
+						//  <FLJ0850:0111
+						// This bug causes the values to be misread as 8510 and 1075,
+						// leading to an out-of-bounds gFlagNPC access.
+						// As well as this, the out-of-bound read has a random chance
+						// of being true or false. If it's true, then the game will
+						// try to execute script 1075, causing a crash.
+						// To fix this, we manually catch this error and use the
+						// correct values.
+						// This bug is present in...
+						//  Japanese 1.0.0.5 (and presumably earlier versions)
+						//  Aeon Genesis 1.0.0.5
+						//  Aeon Genesis 1.0.0.6
+						//  Cave Story (WiiWare)
+						//  Cave Story+ (Steam)
+						// Gee, I wonder how it snuck into the Nicalis ports. ¬_¬
+						if (!memcmp(&gTS.data[gTS.p_read + 4], "850:0111", 8))
+						{
+							x = 850;
+							z = 111;
+						}
+					#endif
+
 						if (GetNPCFlag(x))
 							JumpTextScript(z);
 						else