-
Notifications
You must be signed in to change notification settings - Fork 187
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Destiny Patch support #3131
Draft
drxgb
wants to merge
6
commits into
EasyRPG:master
Choose a base branch
from
drxgb:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Destiny Patch support #3131
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
d94557b
Destiny Patch support
drxgb 401582d
Make DestinyScript command
drxgb 9695f59
Call Destiny Interpreter by comment event command
drxgb 7e23f12
Destiny: OOP approach
drxgb b59b5a7
Include Game_Destiny instance to main_data
drxgb c6c1f56
Add game_destiny.h/cpp to CMake
drxgb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
/* | ||
* This file is part of EasyRPG Player. | ||
* | ||
* EasyRPG Player 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 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* EasyRPG Player 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 EasyRPG Player. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
// Headers | ||
#include "destiny.h" | ||
|
||
#include <vector> | ||
|
||
#ifndef EMSCRIPTEN | ||
#include "exe_reader.h" | ||
#endif // !EMSCRIPTEN | ||
#include "output.h" | ||
|
||
|
||
using lcf::ToString; | ||
using lcf::rpg::EventCommand; | ||
|
||
|
||
// Definitions | ||
using destiny_dword_list = std::vector<int>; | ||
using destiny_float_list = std::vector<double>; | ||
using destiny_string_list = std::vector<std::string>; | ||
|
||
|
||
namespace Destiny { | ||
// Destiny containers | ||
static destiny_dword_list dwords; | ||
static destiny_float_list floats; | ||
static destiny_string_list strings; | ||
|
||
// Destiny data | ||
static Version dllVersion; | ||
static Version gameVersion; | ||
static Language language; | ||
static uint32_t extra; | ||
|
||
// Settings | ||
static bool decimalComma; | ||
} | ||
|
||
|
||
// Implementations | ||
void Destiny::Load() | ||
{ | ||
// Do not load Destiny whether player cannot find "Destiny.dll" | ||
if (!FileFinder::Game().Exists(DESTINY_DLL)) | ||
return; | ||
|
||
uint32_t dllVersion = 0; | ||
uint32_t language = 0; | ||
uint32_t gameVersion = 0; | ||
uint32_t extra = 0; | ||
uint32_t dwordSize = 0; | ||
uint32_t floatSize = 0; | ||
uint32_t stringSize = 0; | ||
|
||
#ifndef EMSCRIPTEN | ||
Filesystem_Stream::InputStream exe = FileFinder::Game().OpenFile(EXE_NAME); | ||
|
||
if (exe) { | ||
exe.seekg(0x00030689, std::ios_base::beg); | ||
exe.read(reinterpret_cast<char*>(&stringSize), sizeof(uint32_t)); | ||
exe.seekg(1, std::ios_base::cur); | ||
exe.read(reinterpret_cast<char*>(&floatSize), sizeof(uint32_t)); | ||
exe.seekg(1, std::ios_base::cur); | ||
exe.read(reinterpret_cast<char*>(&dwordSize), sizeof(uint32_t)); | ||
exe.seekg(1, std::ios_base::cur); | ||
exe.read(reinterpret_cast<char*>(&extra), sizeof(uint32_t)); | ||
exe.seekg(1, std::ios_base::cur); | ||
exe.read(reinterpret_cast<char*>(&gameVersion), sizeof(uint32_t)); | ||
exe.seekg(1, std::ios_base::cur); | ||
exe.read(reinterpret_cast<char*>(&language), sizeof(uint32_t)); | ||
exe.seekg(1, std::ios_base::cur); | ||
exe.read(reinterpret_cast<char*>(&dllVersion), sizeof(uint32_t)); | ||
exe.seekg(1, std::ios_base::cur); | ||
} | ||
#else | ||
// TODO [Dr.XGB]: Find to manage Destiny initialization parameters on Emscripten | ||
dllVersion = 0x20000; | ||
language = ENGLISH; | ||
gameVersion = 0x20000107; | ||
extra = 0x01; | ||
dwordSize = floatSize = stringSize = 0x64; | ||
#endif // !EMSCRIPTEN | ||
|
||
Initialize(dllVersion, language, gameVersion, extra, dwordSize, floatSize, stringSize); | ||
} | ||
|
||
void Destiny::Initialize(uint32_t _dllVersion, uint32_t _language, uint32_t _gameVersion, uint32_t _extra, uint32_t _dwordSize, uint32_t _floatSize, uint32_t _stringSize) | ||
{ | ||
dllVersion = Version(_dllVersion); | ||
gameVersion = Version(_gameVersion); | ||
language = static_cast<Language>(_language); | ||
extra = _extra; | ||
decimalComma = language == ENGLISH; | ||
|
||
// Init containers | ||
dwords.resize(_dwordSize); | ||
floats.resize(_floatSize); | ||
strings.resize(_stringSize); | ||
|
||
// TODO: Init File container | ||
// TODO: Init ClientSocket container | ||
|
||
// Debug | ||
Output::Debug("Destiny Initialized"); | ||
Output::Debug("Language: {}", decimalComma ? "English" : "Deutsch"); | ||
Output::Debug("DLL Version: {}", dllVersion.toString()); | ||
Output::Debug("Dwords: {}", _dwordSize); | ||
Output::Debug("Floats: {}", _floatSize); | ||
Output::Debug("Strings: {}", _stringSize); | ||
} | ||
|
||
void Destiny::Terminate() | ||
{ | ||
dwords.clear(); | ||
floats.clear(); | ||
strings.clear(); | ||
|
||
// TODO: Clear File container | ||
// TODO: Clear ClientSocket container | ||
} | ||
|
||
std::string Destiny::MakeString(lcf::rpg::SaveEventExecFrame& scriptData) | ||
{ | ||
std::string code; | ||
|
||
int32_t& current = scriptData.current_command; | ||
const std::vector<EventCommand>& cmdList = scriptData.commands; | ||
std::vector<EventCommand>::const_iterator it = cmdList.begin() + current++; | ||
|
||
code = ToString((*it++).string); | ||
while (it != cmdList.cend() && it->code == static_cast<int32_t>(EventCommand::Code::Comment_2)) { | ||
code += '\n'; | ||
code += ToString((*it++).string); | ||
++current; | ||
} | ||
|
||
return code; | ||
} | ||
|
||
bool Destiny::Interpret(const std::string& code) | ||
{ | ||
// TODO [Dr.XGB]: DestinyScript Interpret | ||
return true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
/* | ||
* This file is part of EasyRPG Player. | ||
* | ||
* EasyRPG Player 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 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* EasyRPG Player 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 EasyRPG Player. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#ifndef EP_DESTINY_H | ||
#define EP_DESTINY_H | ||
|
||
#include <cstdint> | ||
#include <sstream> | ||
|
||
#include "lcf/rpg/saveeventexecframe.h" | ||
|
||
|
||
namespace Destiny { | ||
// Constants | ||
constexpr const char* DESTINY_DLL = "Destiny.dll"; | ||
|
||
|
||
// Enums | ||
enum Language { | ||
DEUTSCH = 0, | ||
ENGLISH, | ||
}; | ||
|
||
|
||
// Structs | ||
struct Version { | ||
uint16_t major; | ||
uint16_t minor; | ||
|
||
Version() | ||
: major(0), minor(0) {} | ||
Version(uint32_t version) { | ||
major = version >> 0x10; | ||
minor = version & 0xFFFF; | ||
} | ||
|
||
std::string toString() { | ||
std::stringstream ss; | ||
|
||
ss << major << '.' << minor; | ||
return ss.str(); | ||
} | ||
}; | ||
|
||
|
||
// Functions | ||
/** | ||
* Load the Destiny module | ||
*/ | ||
void Load(); | ||
|
||
/** | ||
* Initialize and apply the patch to the game interpreter | ||
*/ | ||
void Initialize( | ||
uint32_t _dllVersion, | ||
uint32_t _language, | ||
uint32_t _gameVersion, | ||
uint32_t _extra, | ||
uint32_t _dwordSize, | ||
uint32_t _floatSize, | ||
uint32_t _stringSize | ||
); | ||
|
||
/** | ||
* Clear Destiny patch before close | ||
*/ | ||
void Terminate(); | ||
|
||
|
||
// Interpret functions | ||
|
||
/* | ||
* Make the DestinyScript code exctracting from the event script's comment command | ||
*/ | ||
std::string MakeString(lcf::rpg::SaveEventExecFrame& scriptData); | ||
|
||
|
||
/* | ||
* Evaluate DestinyScript code | ||
*/ | ||
bool Interpret(const std::string& code); | ||
|
||
} | ||
#endif // !EP_DESTINY_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Imo this is a good start. Just a little nit-pick:
Can you rename it to
Game_Destiny
similiar to how Ineluki patch is implemented (which isGame_Ineluki
).Then make it a class and put the instance variable in
main_data.h/cpp
and instantiate it inResetGameObjects
.Also please update
Makefile.am
andCMakeLists.txt
by adding the new files to it (put them at the correct location in alphabetical order).Yes I know that DynRPG does it in a different way but I plan to rewrite this as less global state makes the cleanup easier when switching the game.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, no problem. I thought that I must create a singleton, but if already exists a container so it's much better.
I'll make this fixes. =D
Thanks for the tips.