-
Notifications
You must be signed in to change notification settings - Fork 17
/
sign.cpp
57 lines (50 loc) · 1.63 KB
/
sign.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <vector>
#include <SDL/SDL.h>
#include <libreborn/libreborn.h>
#include <symbols/minecraft.h>
#include <mods/init/init.h>
#include <mods/feature/feature.h>
#include <mods/input/input.h>
#include <mods/sign/sign.h>
// Handle Backspace
static int32_t sdl_key_to_minecraft_key_injection(Common_sdl_key_to_minecraft_key_t original, int32_t sdl_key) {
if (sdl_key == SDLK_BACKSPACE) {
return 0x8;
} else if (sdl_key == SDLK_DELETE) {
return 0x2e;
} else if (sdl_key == SDLK_LEFT) {
return 0x25;
} else if (sdl_key == SDLK_RIGHT) {
return 0x27;
} else if (sdl_key == SDLK_F1) {
return 0x70;
} else if (sdl_key == SDLK_F5) {
return 0x74;
} else {
// Call Original Method
return original(sdl_key);
}
}
// Open Sign Screen
static void LocalPlayer_openTextEdit_injection(LocalPlayer *local_player, TileEntity *sign) {
if (sign->type == 4) {
Minecraft *minecraft = local_player->minecraft;
TextEditScreen *screen = alloc_TextEditScreen();
ALLOC_CHECK(screen);
screen = TextEditScreen_constructor(screen, (SignTileEntity *) sign);
Minecraft_setScreen(minecraft, (Screen *) screen);
}
}
// Store Text Input
void sign_key_press(char key) {
Keyboard__inputText.push_back(key);
}
// Init
void init_sign() {
if (feature_has("Fix Sign Placement", server_disabled)) {
// Fix Signs
patch_address(LocalPlayer_openTextEdit_vtable_addr, (void *) LocalPlayer_openTextEdit_injection);
}
// Handle Backspace
overwrite_calls(Common_sdl_key_to_minecraft_key, sdl_key_to_minecraft_key_injection);
}