shithub: cstory

Download patch

ref: b117a7a1bcbb16819defa729c8598b84fabdfdf2
parent: 7226a94fb11cfae1dd942c08c3748e8483021aa7
author: cuckydev <44537737+cuckydev@users.noreply.github.com>
date: Thu Jan 10 16:16:55 EST 2019

Initial Commit

diff: cannot open b/src//null: file does not exist: 'b/src//null'
--- /dev/null
+++ b/Makefile
@@ -1,0 +1,39 @@
+RELEASE = 0
+
+ifeq ($(RELEASE), 0)
+CXXFLAGS := -O0 -g -static
+FILENAME = debug
+else
+CXXFLAGS := -O3 -s -static
+FILENAME = release
+endif
+
+ifeq ($(JAPANESE), 1)
+CFLAGS += -DJAPANESE
+endif
+
+CXXFLAGS += `sdl2-config --cflags`
+LIBS += `sdl2-config --static-libs`
+
+# For an accurate result to the original's code, compile in alphabetical order
+SOURCES = \
+	Config \
+	KeyControl \
+	Main \
+
+OBJECTS = $(addprefix obj/$(FILENAME)/, $(addsuffix .o, $(SOURCES)))
+
+all: build/$(FILENAME).exe
+
+build/$(FILENAME).exe: $(OBJECTS)
+	@mkdir -p $(@D)
+	@g++ $(CXXFLAGS) $^ -o $@ $(LIBS)
+	@echo Finished compiling: $@
+
+obj/$(FILENAME)/%.o: src/%.cpp
+	@mkdir -p $(@D)
+	@echo Compiling $^
+	@g++ $(CXXFLAGS) $^ -o $@ -c
+
+clean:
+	@rm -rf build obj
--- /dev/null
+++ b/src/CommonDefines.h
@@ -1,0 +1,2 @@
+#pragma once
+#define PATH_LENGTH 260 //Pixel had the path size locked to 260 (dangerously low), if you tried to open the executable in a path with more than around 220 characters, it'd crash.
--- /dev/null
+++ b/src/Config.cpp
@@ -1,0 +1,70 @@
+#include <stddef.h>
+#include "Types.h"
+#include <stdio.h>
+#include <stdint.h>
+#include <string.h>
+
+#include <SDL_rwops.h>
+
+#include "Config.h"
+#include "WindowsWrapper.h"
+
+bool LoadConfigData(CONFIG *conf)
+{
+	//Clear old config data
+	memset(conf, 0, sizeof(CONFIG));
+	
+	//Get path
+	char path[PATH_LENGTH];
+	sprintf(path, "%s/%s", gModulePath, "Config.dat");
+	
+	//Open file
+	SDL_RWops *fp = SDL_RWFromFile(path, "rb");
+	if (!fp)
+		return false;
+	
+	//Read data (we're using SDL_RWops so we can load it with the specific endianness expected)
+	//Read the version id and font name
+	fp->read(fp, conf->proof, sizeof(conf->proof), 1);
+	fp->read(fp, conf->font_name, sizeof(conf->font_name), 1);
+	
+	//Read control settings
+	conf->move_button_mode = SDL_ReadLE32(fp);
+	conf->attack_button_mode = SDL_ReadLE32(fp);
+	conf->ok_button_mode = SDL_ReadLE32(fp);
+	
+	//Read display mode (320x240, 640x480, 24-bit fullscreen, 32-bit fullscreen) TODO: add more things?
+	conf->display_mode = SDL_ReadLE32(fp);
+	
+	//Read joystick configuration (if enabled, and mappings)
+	conf->bJoystick = SDL_ReadLE32(fp);
+	for (int button = 0; button < 8; button++)
+		conf->joystick_button[button] = SDL_ReadLE32(fp);
+	
+	//Close file
+	fp->close(fp);
+	
+	//Check if version is correct, return that it succeeded
+	if (!strcmp(conf->proof, "DOUKUTSU20041206"))
+		return true;
+	
+	//If not, return that it failed
+	return false;
+}
+
+void DefaultConfigData(CONFIG *conf)
+{
+	//Claer old config data
+	memset(conf, 0, sizeof(CONFIG));
+	
+	//Reset joystick settings (as these can't simply be set to 0)
+	conf->bJoystick = 1;
+	conf->joystick_button[0] = 2;
+	conf->joystick_button[1] = 1;
+	conf->joystick_button[2] = 5;
+	conf->joystick_button[3] = 6;
+	conf->joystick_button[4] = 3;
+	conf->joystick_button[5] = 4;
+	conf->joystick_button[6] = 6;
+	conf->joystick_button[7] = 3;
+}
--- /dev/null
+++ b/src/Config.h
@@ -1,0 +1,17 @@
+#pragma once
+#include <stdint.h>
+
+struct CONFIG
+{
+	char proof[0x20];
+	char font_name[0x40];
+	int32_t move_button_mode;
+	int32_t attack_button_mode;
+	int32_t ok_button_mode;
+	int32_t display_mode;
+	int32_t bJoystick;
+	int32_t joystick_button[8];
+};
+
+bool LoadConfigData(CONFIG *conf);
+void DefaultConfigData(CONFIG *conf);
--- /dev/null
+++ b/src/KeyControl.cpp
@@ -1,0 +1,24 @@
+#include "KeyControl.h"
+
+int gKey;
+int gKeyTrg;
+
+int gKeyJump = KEY_Z;
+int gKeyShot = KEY_X;
+int gKeyArms = KEY_ARMS;
+int gKeyArmsRev = KEY_ARMSREV;
+int gKeyItem = KEY_ITEM;
+int gKeyMap = KEY_MAP;
+int gKeyOk = KEY_Z;
+int gKeyCancel = KEY_X;
+int gKeyLeft = KEY_LEFT;
+int gKeyUp = KEY_UP;
+int gKeyRight = KEY_RIGHT;
+int gKeyDown = KEY_DOWN;
+
+void GetTrg()
+{
+	static int key_old;
+	gKeyTrg = gKey & (gKey ^ key_old);
+	key_old = gKey;
+}
--- /dev/null
+++ b/src/KeyControl.h
@@ -1,0 +1,45 @@
+#pragma once
+enum KEYBIND
+{
+	//The movement keys go in the order of left, right, up and down
+	KEY_LEFT =		0x00000001,
+	KEY_RIGHT =		0x00000002,
+	KEY_UP =		0x00000004,
+	KEY_DOWN =		0x00000008,
+	//Map key
+	KEY_MAP =		0x00000010,
+	//Okay and cancel keys
+	KEY_X =			0x00000020,
+	KEY_Z =			0x00000040,
+	//Left and right weapon switch keys
+	KEY_ARMS =		0x00000080,
+	KEY_ARMSREV =	0x00000100,
+	//Function keys
+	KEY_F1 =		0x00000400,
+	KEY_F2 =		0x00000800,
+	//Inventory
+	KEY_ITEM =		0x00001000,
+	//Escape key
+	KEY_ESCAPE =	0x00008000,
+	//The alt movement keys go in the order of left, up, right and down
+	KEY_ALT_LEFT =	0x00010000,
+	KEY_ALT_UP =	0x00020000,
+	KEY_ALT_RIGHT =	0x00040000,
+	KEY_ALT_DOWN =	0x00080000,
+};
+
+extern int gKey;
+extern int gKeyTrg;
+
+extern int gKeyJump;
+extern int gKeyShot;
+extern int gKeyArms;
+extern int gKeyArmsRev;
+extern int gKeyItem;
+extern int gKeyMap;
+extern int gKeyOk;
+extern int gKeyCancel;
+extern int gKeyLeft;
+extern int gKeyUp;
+extern int gKeyRight;
+extern int gKeyDown;
--- /dev/null
+++ b/src/Main.cpp
@@ -1,0 +1,87 @@
+#include <stddef.h>
+#include "Types.h"
+#include "CommonDefines.h"
+#include <stdint.h>
+#include <string>
+
+#include <SDL_main.h>
+#include <SDL_render.h>
+#include <SDL_keyboard.h>
+#include <SDL_filesystem.h>
+#include <SDL_events.h>
+
+#include "Config.h"
+#include "KeyControl.h"
+
+char gModulePath[PATH_LENGTH];
+char gDataPath[PATH_LENGTH];
+
+int main(int argc, char *argv[])
+{
+	//Get executable's path
+	strcpy(gModulePath, SDL_GetBasePath());
+	if (gModulePath[strlen(gModulePath) - 1] == '/' || gModulePath[strlen(gModulePath) - 1] == '\\')
+		gModulePath[strlen(gModulePath) - 1] = 0; //String cannot end in slash or stuff will probably break (original does this through a windows.h provided function)
+	
+	//Get path of the data folder
+	strcpy(gDataPath, gModulePath);
+	memcpy(&gDataPath[strlen(gDataPath)], "/data", 6); //Pixel didn't use a strcat
+	
+	//Load configuration
+	CONFIG config;
+	
+	if (!LoadConfigData(&config))
+		DefaultConfigData(&config);
+	
+	//Apply keybinds
+	//Swap X and Z buttons
+	if (config.attack_button_mode)
+	{
+		if (config.attack_button_mode == 1)
+		{
+			gKeyJump = KEY_X;
+			gKeyShot = KEY_Z;
+		}
+	}
+	else
+	{
+		gKeyJump = KEY_Z;
+		gKeyShot = KEY_X;
+	}
+	
+	//Swap Okay and Cancel buttons
+	if (config.ok_button_mode)
+	{
+		if (config.ok_button_mode == 1)
+		{
+			gKeyOk = gKeyShot;
+			gKeyCancel = gKeyJump;
+		}
+	}
+	else
+	{
+		gKeyOk = gKeyJump;
+		gKeyCancel = gKeyShot;
+	}
+	
+	//Alternate movement keys
+	if (config.move_button_mode)
+	{
+		if (config.move_button_mode == 1)
+		{
+			gKeyLeft = KEY_ALT_LEFT;
+			gKeyUp = KEY_ALT_UP;
+			gKeyRight = KEY_ALT_RIGHT;
+			gKeyDown = KEY_ALT_DOWN;
+		}
+	}
+	else
+	{
+		gKeyLeft = KEY_LEFT;
+		gKeyUp = KEY_UP;
+		gKeyRight = KEY_RIGHT;
+		gKeyDown = KEY_DOWN;
+	}
+	
+	return 0;
+}
--- /dev/null
+++ b/src/Types.h
@@ -1,0 +1,5 @@
+#pragma once
+struct RECT
+{
+	int left, right, top, bottom;
+};
--- /dev/null
+++ b/src/WindowsWrapper.h
@@ -1,0 +1,5 @@
+#pragma once
+#include "CommonDefines.h"
+
+extern char gModulePath[PATH_LENGTH];
+extern char gDataPath[PATH_LENGTH];