shithub: cstory

Download patch

ref: 767c2972ae09642c63528c2efbe4adf77f9a6e11
parent: 378be5ae8610e54ae20a62d35a6e5c6cf6a4ba92
author: cuckydev <cuckydev@users.noreply.github.com>
date: Sat Feb 9 17:02:18 EST 2019

tallscreen fix, replicated MSVC rand

--- a/src/Back.cpp
+++ b/src/Back.cpp
@@ -52,6 +52,7 @@
 void PutBack(int fx, int fy)
 {
 	RECT rect = {0, 0, gBack.partsW, gBack.partsH};
+	RECT rcSkyFiller = {106, 0, 255, 88};
 	
 	switch (gBack.type)
 	{
@@ -90,30 +91,30 @@
 		case 6:
 		case 7:
 			//Sky
+			for (int y = 0; y < WINDOW_HEIGHT - 240 + 88; y += 88)
+			{
+				for (int x = -((y * 54) % 149); x < WINDOW_WIDTH; x += 149)
+				{
+					PutBitmap4(&grcGame, x, y, &rcSkyFiller, SURFACE_ID_LEVEL_BACKGROUND);
+				}
+			}
+			
 			rect.top = 0;
 			rect.bottom = 88;
 			rect.left = 0;
 			rect.right = 320;
-			PutBitmap4(&grcGame, (WINDOW_WIDTH - 320) / 2, 0, &rect, SURFACE_ID_LEVEL_BACKGROUND);
-			
-			rect.left = 106;
-			rect.right = 255;
-			for (int i = 0; i < ((WINDOW_WIDTH + 329) / 320); i++)
-			{
-				PutBitmap4(&grcGame, (WINDOW_WIDTH - 320) / 2 - (149 * (i + 1)), 0, &rect, SURFACE_ID_LEVEL_BACKGROUND);
-				PutBitmap4(&grcGame, (WINDOW_WIDTH - 320) / 2 + 320 + (149 * i), 0, &rect, SURFACE_ID_LEVEL_BACKGROUND);
-			}
-			
+			PutBitmap4(&grcGame, (WINDOW_WIDTH - 320) / 2, WINDOW_HEIGHT - 240, &rect, SURFACE_ID_LEVEL_BACKGROUND);
+
 			//Cloud layer 1
 			rect.top = 88;
 			rect.bottom = 123;
 			rect.left = gBack.fx / 2;
 			rect.right = 320;
-			PutBitmap4(&grcGame, 0, 88, &rect, SURFACE_ID_LEVEL_BACKGROUND);
+			PutBitmap4(&grcGame, 0, 88 + (WINDOW_HEIGHT - 240), &rect, SURFACE_ID_LEVEL_BACKGROUND);
 			
 			rect.left = 0;
 			for (int i = 0; i < ((WINDOW_WIDTH + 329) / 320) + 1; i++)
-				PutBitmap4(&grcGame, (320 * (i + 1)) - gBack.fx / 2 % 320, 88, &rect, SURFACE_ID_LEVEL_BACKGROUND);
+				PutBitmap4(&grcGame, (320 * (i + 1)) - gBack.fx / 2 % 320, 88 + (WINDOW_HEIGHT - 240), &rect, SURFACE_ID_LEVEL_BACKGROUND);
 			
 			//Cloud layer 2
 			rect.top = 123;
@@ -120,11 +121,11 @@
 			rect.bottom = 146;
 			rect.left = gBack.fx % 320;
 			rect.right = 320;
-			PutBitmap4(&grcGame, 0, 123, &rect, SURFACE_ID_LEVEL_BACKGROUND);
+			PutBitmap4(&grcGame, 0, 123 + (WINDOW_HEIGHT - 240), &rect, SURFACE_ID_LEVEL_BACKGROUND);
 			
 			rect.left = 0;
 			for (int i = 0; i < ((WINDOW_WIDTH + 329) / 320) + 1; i++)
-				PutBitmap4(&grcGame, (320 * (i + 1)) - gBack.fx % 320, 123, &rect, SURFACE_ID_LEVEL_BACKGROUND);
+				PutBitmap4(&grcGame, (320 * (i + 1)) - gBack.fx % 320, 123 + (WINDOW_HEIGHT - 240), &rect, SURFACE_ID_LEVEL_BACKGROUND);
 			
 			//Cloud layer 3
 			rect.top = 146;
@@ -131,11 +132,11 @@
 			rect.bottom = 176;
 			rect.left = 2 * gBack.fx % 320;
 			rect.right = 320;
-			PutBitmap4(&grcGame, 0, 146, &rect, SURFACE_ID_LEVEL_BACKGROUND);
+			PutBitmap4(&grcGame, 0, 146 + (WINDOW_HEIGHT - 240), &rect, SURFACE_ID_LEVEL_BACKGROUND);
 			
 			rect.left = 0;
 			for (int i = 0; i < ((WINDOW_WIDTH + 329) / 320) + 1; i++)
-				PutBitmap4(&grcGame, (320 * (i + 1)) - 2 * gBack.fx % 320, 146, &rect, SURFACE_ID_LEVEL_BACKGROUND);
+				PutBitmap4(&grcGame, (320 * (i + 1)) - 2 * gBack.fx % 320, 146 + (WINDOW_HEIGHT - 240), &rect, SURFACE_ID_LEVEL_BACKGROUND);
 			
 			//Cloud layer 4
 			rect.top = 176;
@@ -142,11 +143,11 @@
 			rect.bottom = 240;
 			rect.left = 4 * gBack.fx % 320;
 			rect.right = 320;
-			PutBitmap4(&grcGame, 0, 176, &rect, SURFACE_ID_LEVEL_BACKGROUND);
+			PutBitmap4(&grcGame, 0, 176 + (WINDOW_HEIGHT - 240), &rect, SURFACE_ID_LEVEL_BACKGROUND);
 			
 			rect.left = 0;
 			for (int i = 0; i < ((WINDOW_WIDTH + 329) / 320) + 1; i++)
-				PutBitmap4(&grcGame, (320 * (i + 1)) - 4 * gBack.fx % 320, 176, &rect, SURFACE_ID_LEVEL_BACKGROUND);
+				PutBitmap4(&grcGame, (320 * (i + 1)) - 4 * gBack.fx % 320, 176 + (WINDOW_HEIGHT - 240), &rect, SURFACE_ID_LEVEL_BACKGROUND);
 			break;
 			
 		default:
--- a/src/Ending.cpp
+++ b/src/Ending.cpp
@@ -100,6 +100,10 @@
 {
 	switch (Illust.act_no)
 	{
+		case 0: //Off-screen to the left
+			Illust.x = -0x14000;
+			break;
+			
 		case 1: //Move in from the left
 			Illust.x += 0x5000;
 			if (Illust.x > 0)
@@ -111,10 +115,6 @@
 			if (Illust.x < -0x14000)
 				Illust.x = -0x14000;
 			break;
-			
-		case 0: //Off-screen to the left
-			Illust.x = -0x14000;
-			break;
 	}
 }
 
@@ -137,6 +137,7 @@
 //Initialize and release credits
 void InitCreditScript()
 {
+	//Clear script state and casts
 	memset(&Credit, 0, sizeof(CREDIT));
 	memset(Strip, 0, sizeof(Strip));
 }
@@ -145,6 +146,7 @@
 {
 	if (Credit.pData)
 	{
+		//Free script data
 		free(Credit.pData);
 		Credit.pData = NULL;
 	}
@@ -179,7 +181,8 @@
 		return false;
 	
 	//Read data
-	fp->read(fp, Credit.pData, 1, Credit.size);
+	SDL_RWread(fp, Credit.pData, 1, Credit.size);
+	SDL_RWclose(fp);
 	EncryptionBinaryData2((uint8_t*)Credit.pData, Credit.size);
 	
 	//Reset credits
@@ -203,7 +206,6 @@
 	
 	//Clear casts
 	memset(Strip, 0, sizeof(Strip));
-	SDL_RWclose(fp);
 	return true;
 }
 
@@ -210,7 +212,10 @@
 //Get number from text (4 digit)
 int GetScriptNumber(const char *text)
 {
-	return 1000 * *text - 48000 + 100 * text[1] - 4800 + 10 * text[2] - 480 + text[3] - 48;
+	return	1000 * text[0] - 48000 +
+			100 * text[1] - 4800 +
+			10 * text[2] - 480 +
+			text[3] - 48;
 }
 
 //Parse credits
@@ -218,6 +223,7 @@
 {
 	while (Credit.offset < Credit.size)
 	{
+		//Get character
 		uint8_t character = Credit.pData[Credit.offset];
 		
 		int a, b, len;
@@ -352,6 +358,7 @@
 {
 	if (Credit.offset < Credit.size)
 	{
+		//Update script, or if waiting, decrement the wait value
 		if (Credit.mode == 1)
 		{
 			ActionCredit_Read();
@@ -379,23 +386,24 @@
 //Scene of the island falling
 int Scene_DownIsland(int mode)
 {
-	RECT rc_sprite;
-	RECT rc_ground;
-	RECT rc_sky;
-	RECT rc_frame;
+	//Setup background
+	RECT rc_frame = {(WINDOW_WIDTH - 160) / 2, (WINDOW_HEIGHT - 80) / 2, (WINDOW_WIDTH + 160) / 2, (WINDOW_HEIGHT + 80) / 2};
+	RECT rc_sky = {0, 0, 160, 80};
+	RECT rc_ground = {160, 48, 320, 80};
+	
+	//Setup island
+	RECT rc_sprite = {160, 0, 200, 24};
+	
 	ISLAND_SPRITE sprite;
-
-	rc_frame = {(WINDOW_WIDTH - 160) / 2, (WINDOW_HEIGHT - 80) / 2, (WINDOW_WIDTH + 160) / 2, (WINDOW_HEIGHT + 80) / 2};
-	rc_sky = {0, 0, 160, 80};
-	rc_ground = {160, 48, 320, 80};
-	rc_sprite = {160, 0, 200, 24};
 	sprite.x = 0x15000;
 	sprite.y = 0x8000;
 	
 	for (int wait = 0; wait < 900; wait++)
 	{
+		//Get pressed keys
 		GetTrg();
 		
+		//Escape menu
 		if (gKey & 0x8000)
 		{
 			int escRet = Call_Escape();
@@ -408,6 +416,7 @@
 		switch (mode)
 		{
 			case 0:
+				//Move down
 				sprite.y += 0x33;
 				break;
 				
@@ -418,27 +427,31 @@
 					{
 						if (wait >= 600)
 						{
+							//End scene
 							if (wait == 750)
 								wait = 900;
 						}
 						else
 						{
+							//Move down slow
 							sprite.y += 0xC;
 						}
 					}
 					else
 					{
+						//Move down slower
 						sprite.y += 0x19;
 					}
 				}
 				else
 				{
+					//Move down at normal speed
 					sprite.y += 0x33;
 				}
 				break;
 		}
 		
-		
+		//Draw scene
 		CortBox(&grcFull, 0);
 		PutBitmap3(&rc_frame, 80 + (WINDOW_WIDTH - 320) / 2, 80 + (WINDOW_HEIGHT - 240) / 2, &rc_sky, 21);
 		PutBitmap3(&rc_frame, sprite.x / 0x200 - 20 + (WINDOW_WIDTH - 320) / 2, sprite.y / 512 - 12 + (WINDOW_HEIGHT - 240) / 2, &rc_sprite, 21);
@@ -445,6 +458,7 @@
 		PutBitmap3(&rc_frame, 80 + (WINDOW_WIDTH - 320) / 2, 128 + (WINDOW_HEIGHT - 240) / 2, &rc_ground, 21);
 		PutTimeCounter(16, 8);
 		
+		//Draw window
 		PutFramePerSecound();
 		if (!Flip_SystemTask())
 			return 0;
--- a/src/Main.cpp
+++ b/src/Main.cpp
@@ -44,6 +44,21 @@
 const char *lpWindowName = "Cave Story Engine 2 ~ Doukutsu Monogatari Enjin 2";
 #endif
 
+//A replication of MSVC's rand algorithm
+static unsigned long int next = 1;
+
+int _rand()
+{
+	next = ((next) * 214013 + 2531011);
+    return ((next) >> 16) & 0x7FFF;
+}
+
+void _srand(unsigned int seed)
+{
+    next = seed;
+}
+
+//Framerate stuff
 void PutFramePerSecound()
 {
 	if (bFps)
--- a/src/PixTone.cpp
+++ b/src/PixTone.cpp
@@ -5,6 +5,8 @@
 #include <cstring>
 #include <math.h>
 
+#include "WindowsWrapper.h"
+
 #include "CommonDefines.h"
 #include "Tags.h"
 #include "PixTone.h"
--- a/src/WindowsWrapper.h
+++ b/src/WindowsWrapper.h
@@ -1,5 +1,10 @@
 #pragma once
 
+#define rand _rand
+#define srand _srand
+int _rand();
+void _srand(unsigned int seed);
+
 typedef int BOOL;
 
 #ifndef FALSE