Skip to content

Commit

Permalink
Support pre-1.2.10 text input
Browse files Browse the repository at this point in the history
  • Loading branch information
MCMrARM committed Nov 12, 2018
1 parent 46d89b5 commit 559d45e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/client_app_platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@
#include <minecraft/ImagePickingCallback.h>
#include <minecraft/FilePickerSettings.h>
#include <minecraft/MinecraftGame.h>
#include <minecraft/legacy/MinecraftGame.h>
#include <minecraft/legacy/AppPlatform.h>
#include <file_picker_factory.h>
#include <hybris/dlfcn.h>
#include <minecraft/Keyboard.h>
#include <mcpelauncher/minecraft_version.h>
#include "utf8_util.h"

const char* ClientAppPlatform::TAG = "ClientAppPlatform";
Expand All @@ -31,6 +34,7 @@ void ClientAppPlatform::initVtable(void* lib) {
vtr.replace(PatchUtils::memberFuncCast(&LauncherAppPlatform::pickFile), &ClientAppPlatform::pickFile);
vtr.replace(PatchUtils::memberFuncCast(&LauncherAppPlatform::setFullscreenMode), &ClientAppPlatform::setFullscreenMode);
vtr.replace("_ZN11AppPlatform12showKeyboardERKSsibbbiRK4Vec2", &ClientAppPlatform::showKeyboard);
vtr.replace("_ZN11AppPlatform12showKeyboardERKSsibbbRK4Vec2", &ClientAppPlatform::showKeyboardLegacy);
vtr.replace("_ZN11AppPlatform17updateTextBoxTextERKSs", &ClientAppPlatform::updateTextBoxText);
vtr.replace("_ZN11AppPlatform12hideKeyboardEv", &ClientAppPlatform::hideKeyboard);
vtr.replace("_ZNK11AppPlatform17supportsClipboardEv", &ClientAppPlatform::supportsClipboard);
Expand Down Expand Up @@ -112,6 +116,13 @@ void ClientAppPlatform::showKeyboard(mcpe::string const &text, int i, bool b, bo
updateTextBoxText(text);
}

void ClientAppPlatform::showKeyboardLegacy(mcpe::string const &text, int i, bool b, bool b2, bool multiline,
Vec2 const &v) {
((Legacy::Pre_1_2_10::AppPlatform*) (AppPlatform*) this)->showKeyboard(text, i, b, b2, multiline, v);
currentTextMutliline = multiline;
updateTextBoxText(text);
}

void ClientAppPlatform::updateTextBoxText(mcpe::string const &text) {
currentText = text.std();
currentTextPosition = currentText.size();
Expand Down Expand Up @@ -148,7 +159,10 @@ void ClientAppPlatform::onKeyboardText(MinecraftGame &game, std::string const &t
currentTextPosition += text.size();
currentTextPositionUTF += UTF8Util::getLength(text.c_str(), text.size());
}
game.setTextboxText(currentText, 0);
if (MinecraftVersion::isAtLeast(1, 2, 10))
game.setTextboxText(currentText, 0);
else
((Legacy::Pre_1_2_10::MinecraftGame*) &game)->setTextboxText(currentText);
Keyboard::_inputCaretLocation->push_back(currentTextPositionUTF);
}

Expand Down
1 change: 1 addition & 0 deletions src/client_app_platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class ClientAppPlatform : public LauncherAppPlatform {
void setFullscreenMode(int mode);

void showKeyboard(mcpe::string const& text, int, bool, bool, bool, int, Vec2 const&);
void showKeyboardLegacy(mcpe::string const& text, int, bool, bool, bool, Vec2 const&);
void updateTextBoxText(mcpe::string const& text);
void hideKeyboard();
bool isKeyboardMultiline() const { return currentTextMutliline; }
Expand Down

0 comments on commit 559d45e

Please sign in to comment.