From b117a7a1bcbb16819defa729c8598b84fabdfdf2 Mon Sep 17 00:00:00 2001 From: cuckydev <44537737+cuckydev@users.noreply.github.com> Date: Thu, 10 Jan 2019 21:16:55 -0500 Subject: [PATCH] Initial Commit --- Makefile | 39 ++++++++++++++++++++ src/CommonDefines.h | 2 + src/Config.cpp | 70 +++++++++++++++++++++++++++++++++++ src/Config.h | 17 +++++++++ src/KeyControl.cpp | 24 ++++++++++++ src/KeyControl.h | 45 +++++++++++++++++++++++ src/Main.cpp | 87 ++++++++++++++++++++++++++++++++++++++++++++ src/Types.h | 5 +++ src/WindowsWrapper.h | 5 +++ 9 files changed, 294 insertions(+) create mode 100644 Makefile create mode 100644 src/CommonDefines.h create mode 100644 src/Config.cpp create mode 100644 src/Config.h create mode 100644 src/KeyControl.cpp create mode 100644 src/KeyControl.h create mode 100644 src/Main.cpp create mode 100644 src/Types.h create mode 100644 src/WindowsWrapper.h diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..d3b6e84c --- /dev/null +++ b/Makefile @@ -0,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 diff --git a/src/CommonDefines.h b/src/CommonDefines.h new file mode 100644 index 00000000..772e5b1c --- /dev/null +++ b/src/CommonDefines.h @@ -0,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. diff --git a/src/Config.cpp b/src/Config.cpp new file mode 100644 index 00000000..7fe654c9 --- /dev/null +++ b/src/Config.cpp @@ -0,0 +1,70 @@ +#include +#include "Types.h" +#include +#include +#include + +#include + +#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; +} diff --git a/src/Config.h b/src/Config.h new file mode 100644 index 00000000..5e600d3d --- /dev/null +++ b/src/Config.h @@ -0,0 +1,17 @@ +#pragma once +#include + +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); diff --git a/src/KeyControl.cpp b/src/KeyControl.cpp new file mode 100644 index 00000000..aa67f578 --- /dev/null +++ b/src/KeyControl.cpp @@ -0,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; +} diff --git a/src/KeyControl.h b/src/KeyControl.h new file mode 100644 index 00000000..e6e7a818 --- /dev/null +++ b/src/KeyControl.h @@ -0,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; diff --git a/src/Main.cpp b/src/Main.cpp new file mode 100644 index 00000000..749e14e8 --- /dev/null +++ b/src/Main.cpp @@ -0,0 +1,87 @@ +#include +#include "Types.h" +#include "CommonDefines.h" +#include +#include + +#include +#include +#include +#include +#include + +#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; +} diff --git a/src/Types.h b/src/Types.h new file mode 100644 index 00000000..2ba246ce --- /dev/null +++ b/src/Types.h @@ -0,0 +1,5 @@ +#pragma once +struct RECT +{ + int left, right, top, bottom; +}; diff --git a/src/WindowsWrapper.h b/src/WindowsWrapper.h new file mode 100644 index 00000000..8870bdba --- /dev/null +++ b/src/WindowsWrapper.h @@ -0,0 +1,5 @@ +#pragma once +#include "CommonDefines.h" + +extern char gModulePath[PATH_LENGTH]; +extern char gDataPath[PATH_LENGTH];