commit ff25887f41698cf711a1be80bfdf1aa41cc6c8cd Author: Jonas Kulla Date: Sun Sep 1 16:27:21 2013 +0200 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1f4f889 --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ +*.o +*.pro.* +*.bak +*.frag.xxd +*.ttf.xxd + +mkxp diff --git a/README.md b/README.md new file mode 100644 index 0000000..d93b192 --- /dev/null +++ b/README.md @@ -0,0 +1,85 @@ +# mkxp + +mkxp is a project that seeks to provide a fully open source implementation of the RGSS (Ruby Game Scripting System) interface used in the popular game creation software "RPG Maker XP" (trademark by Enterbrain, Inc.), with focus on Linux. The goal is to be able to run games created with the above software natively without changing a single file. + +## Bindings +Bindings provide the interpreted language environment to run game scripts in. As of right now, they are compiled directly into the executable. Currently there are three bindings: + +### MRI +Website: https://www.ruby-lang.org/en/ + +Matz's Ruby Interpreter, also called CRuby, is the most widely deployed version of ruby. If you're interested in running games created with RPG Maker XP, this is the one you should go for. MRI 1.8 is what was used in RPG Maker XP, however, this binding is written against 2.0 (the latest version). For games utilizing only the default scripts provided by Enterbrain, this binding works quite well so far. Note that there are language and syntax differences between 1.8 and 2.0, so some user created scripts may not work correctly. + +For a list of differences, see: +http://stackoverflow.com/questions/21574/what-is-the-difference-between-ruby-1-8-and-ruby-1-9 + +To select this backend, run `qmake BINDING=BINDING_MRI` + +### mruby (Lightweight Ruby) +Website: https://github.com/mruby/mruby + +mruby is a new endeavor by Matz and others to create a more lightweight, spec-adhering, embeddable Ruby implementation. You can think of it as a Ruby version of Lua. + +Due to heavy differences between mruby and MRI as well as lacking modules, running RPG Maker games with this backend will most likely not work correctly. It is provided as experimental code. You can eg. write your own ruby scripts and run them with this backend. + +Some extensions to the standard classes/modules are provided taking the RPG Maker XP helpfile as a quasi "standard". These include Marshal, File, FileTest and Time. + +To select this backend, run `qmake BINDING=BINDING_MRUBY` + +### null +This backend only exists for testing purposes and does nothing (the engine quits immediately). + +To select this backend, run `qmake BINDING=BINDING_NULL` + +## Dependencies + +* QtCore 4.8 +* libsigc++ +* PhysFS +* glew +* SDL2 +* SDL2_image +* SDL2_ttf +* sfml-system 2.0 +* sfml-audio 2.0 + +(If no version specified, assume latest) + +### MRI binding: +Place a recent version of ruby in the project folder and build it. + +### mruby binding: +Place a recent version of mruby in the project folder and build it. + +To run mkxp, you should have a graphics card capable of at least **OpenGL 3.0** + +## Building + +mkxp employs Qt's qmake build system, so you'll need to install that beforehand. After cloning mkxp, run one of the above qmake calls, or simply `qmake` to select the default backend (currently MRI), then `make`. + +## Configuration + +mkxp reads configuration data from the file "mkxp.conf" contained in the current directory. The format is ini-style. + +* "gameFolder": Specifies where mkxp will look for the game scripts. Default is the current directory. +* "customScript": Specifies a raw ruby script file to be run instead of an RPG Maker game, residing in "gameFolder". +* "RTPs": Specifies a list of space separated paths to RTPs to be used. (See next section) + +Most other entries are self explanatory. + +## RTPs + +As of right now, mkxp doesn't support midi files, so to use the default RTPs provided by Enterbrain you will have to convert all midi tracks (those in BGM and ME) to ogg or wav. Make sure that the file names match up, ie. "foobar.mid" should be converted to "foobar.ogg". + +## Fonts + +In the RMXP version of RGSS, fonts are loaded directly from system specific search paths (meaning they must be installed to be available to games). Because this whole thing is a giant platform-dependent headache, I decided to implement the behavior Enterbrain thankfully added in VX Ace: loading fonts will automatically search a folder called "Fonts", which obeys the default searchpath behavior (ie. it can be located directly in the game folder, or an RTP). + +If a requested font is not found, no error is generated. Instead, a built-in font is used (currently "Liberation Sans"). + +## What doesn't work + +* Audio formats other than ogg/wav (this might change in the future) +* Audio "pitch" parameter +* The Win32API ruby class (for obvious reasons) +* Loading Bitmaps with sizes greater than the OpenGL texture size limit (around 8192 on modern cards) \ No newline at end of file diff --git a/assets/liberation.ttf b/assets/liberation.ttf new file mode 100644 index 0000000..626dd93 Binary files /dev/null and b/assets/liberation.ttf differ diff --git a/binding-mri/audio-binding.cpp b/binding-mri/audio-binding.cpp new file mode 100644 index 0000000..4fa35bb --- /dev/null +++ b/binding-mri/audio-binding.cpp @@ -0,0 +1,88 @@ +/* +** audio-binding.cpp +** +** This file is part of mkxp. +** +** Copyright (C) 2013 Jonas Kulla +** +** mkxp is free software: you can redistribute it and/or modify +** it under the terms of the GNU General Public License as published by +** the Free Software Foundation, either version 2 of the License, or +** (at your option) any later version. +** +** mkxp is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with mkxp. If not, see . +*/ + +#include "audio.h" +#include "globalstate.h" +#include "binding-util.h" +#include "exception.h" + +#define DEF_PLAY_STOP(entity) \ + RB_METHOD(audio_##entity##Play) \ + { \ + RB_UNUSED_PARAM; \ + const char *filename; \ + int volume = 100; \ + int pitch = 100; \ + rb_get_args(argc, argv, "z|ii", &filename, &volume, &pitch); \ + GUARD_EXC( gState->audio().entity##Play(filename, volume, pitch); ) \ + return Qnil; \ + } \ + RB_METHOD(audio_##entity##Stop) \ + { \ + RB_UNUSED_PARAM; \ + gState->audio().entity##Stop(); \ + return Qnil; \ + } + +#define DEF_FADE(entity) \ +RB_METHOD(audio_##entity##Fade) \ +{ \ + RB_UNUSED_PARAM; \ + int time; \ + rb_get_args(argc, argv, "i", &time); \ + gState->audio().bgmFade(time); \ + return Qnil; \ +} + +#define DEF_PLAY_STOP_FADE(entity) \ + DEF_PLAY_STOP(entity) \ + DEF_FADE(entity) + +DEF_PLAY_STOP_FADE( bgm ) +DEF_PLAY_STOP_FADE( bgs ) +DEF_PLAY_STOP_FADE( me ) + +DEF_PLAY_STOP( se ) + + +#define BIND_PLAY_STOP(entity) \ + _rb_define_module_function(module, #entity "_play", audio_##entity##Play); \ + _rb_define_module_function(module, #entity "_stop", audio_##entity##Stop); + +#define BIND_FADE(entity) \ + _rb_define_module_function(module, #entity "_fade", audio_##entity##Fade); + +#define BIND_PLAY_STOP_FADE(entity) \ + BIND_PLAY_STOP(entity) \ + BIND_FADE(entity) + + +void +audioBindingInit() +{ + VALUE module = rb_define_module("Audio"); + + BIND_PLAY_STOP_FADE( bgm ) + BIND_PLAY_STOP_FADE( bgs ) + BIND_PLAY_STOP_FADE( me ) + + BIND_PLAY_STOP( se ) +} diff --git a/binding-mri/binding-mri.cpp b/binding-mri/binding-mri.cpp new file mode 100644 index 0000000..0b6118e --- /dev/null +++ b/binding-mri/binding-mri.cpp @@ -0,0 +1,313 @@ +/* +** binding-mri.cpp +** +** This file is part of mkxp. +** +** Copyright (C) 2013 Jonas Kulla +** +** mkxp is free software: you can redistribute it and/or modify +** it under the terms of the GNU General Public License as published by +** the Free Software Foundation, either version 2 of the License, or +** (at your option) any later version. +** +** mkxp is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with mkxp. If not, see . +*/ + +#include "binding.h" +#include "binding-util.h" +#include "globalstate.h" +#include "eventthread.h" +#include "filesystem.h" + +#include "./ruby/include/ruby.h" + +#include "zlib.h" + +#include +#include + +#include + +extern const char module_rpg[]; + +static void mriBindingExecute(); +static void mriBindingTerminate(); + +ScriptBinding scriptBindingImpl = +{ + mriBindingExecute, + mriBindingTerminate +}; + +ScriptBinding *scriptBinding = &scriptBindingImpl; + +void tableBindingInit(); +void etcBindingInit(); +void fontBindingInit(); +void bitmapBindingInit(); +void spriteBindingInit(); +void viewportBindingInit(); +void planeBindingInit(); +void windowBindingInit(); +void tilemapBindingInit(); + +void inputBindingInit(); +void audioBindingInit(); +void graphicsBindingInit(); + +void fileIntBindingInit(); + +static VALUE mriPrint(int, VALUE*, VALUE); +static VALUE mriP(int, VALUE*, VALUE); + +static void mriBindingInit() +{ + tableBindingInit(); + etcBindingInit(); + fontBindingInit(); + bitmapBindingInit(); + spriteBindingInit(); + viewportBindingInit(); + planeBindingInit(); + windowBindingInit(); + tilemapBindingInit(); + + inputBindingInit(); + audioBindingInit(); + graphicsBindingInit(); + + fileIntBindingInit(); + + _rb_define_module_function(rb_mKernel, "print", mriPrint); + _rb_define_module_function(rb_mKernel, "p", mriP); + + rb_eval_string(module_rpg); + + rb_define_global_const("MKXP", Qtrue); +} + +static void +showMsg(const QByteArray &msg) +{ + gState->eThread().showMessageBox(msg.constData()); +} + +static void printP(int argc, VALUE *argv, + const char *convMethod, const char *sep) +{ + VALUE dispString = rb_str_buf_new(128); + ID conv = rb_intern(convMethod); + + for (int i = 0; i < argc; ++i) + { + VALUE str = rb_funcall(argv[i], conv, 0); + rb_str_buf_append(dispString, str); + + if (i < argc) + rb_str_buf_cat2(dispString, sep); + } + + showMsg(RSTRING_PTR(dispString)); + + rb_str_free(dispString); +} + +RB_METHOD(mriPrint) +{ + RB_UNUSED_PARAM; + + printP(argc, argv, "to_s", ""); + + return Qnil; +} + +RB_METHOD(mriP) +{ + RB_UNUSED_PARAM; + + printP(argc, argv, "inspect", "\n"); + + return Qnil; +} + +static void runCustomScript(const char *filename) +{ + QFile scriptFile(filename); + if (!scriptFile.open(QFile::ReadOnly)) + { + showMsg(QByteArray("Unable to open '") + filename + "'"); + return; + } + + QByteArray scriptData = scriptFile.readAll(); + scriptFile.close(); + + rb_eval_string_protect(scriptData.constData(), 0); +} + +VALUE kernelLoadDataInt(const char *filename); + +struct Script +{ + QByteArray name; + QByteArray encData; + uint32_t unknown; + + QByteArray decData; +}; + +static void runRMXPScripts() +{ + const QByteArray &scriptPack = gState->rtData().config.game.scripts; + + if (!gState->fileSystem().exists(scriptPack.constData())) + { + showMsg("Unable to open '" + scriptPack + "'"); + return; + } + + VALUE scriptArray = kernelLoadDataInt(scriptPack.constData()); + + if (rb_type(scriptArray) != RUBY_T_ARRAY) + { + showMsg("Failed to read script data"); + return; + } + + int scriptCount = RARRAY_LEN(scriptArray); + + QByteArray decodeBuffer; + decodeBuffer.resize(0x1000); + + QVector