Skip to content

Commit 15c77b0

Browse files
committed
Initial commit
0 parents  commit 15c77b0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+21132
-0
lines changed

.clang-format

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
BasedOnStyle: LLVM
3+
---
4+
Language: Cpp
5+
# AlignAfterOpenBracket: AlwaysBreak
6+
ColumnLimit: 150
7+
AlignConsecutiveAssignments: true
8+
AlignOperands: true
9+
AlignTrailingComments: true
10+
AllowAllParametersOfDeclarationOnNextLine: false
11+
AllowShortBlocksOnASingleLine: true
12+
AllowShortCaseLabelsOnASingleLine: true
13+
AllowShortFunctionsOnASingleLine: All
14+
AllowShortIfStatementsOnASingleLine: true
15+
AllowShortLoopsOnASingleLine: true
16+
AlwaysBreakBeforeMultilineStrings: true
17+
BinPackArguments: true
18+
BinPackParameters: true
19+
BreakBeforeTernaryOperators: false
20+
BreakConstructorInitializers: BeforeComma
21+
Cpp11BracedListStyle: false
22+
FixNamespaceComments: true
23+
IndentCaseLabels: false
24+
IndentWrappedFunctionNames: false

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
test
2+
lib
3+
out
4+
deps
5+
objs

.vscode/c_cpp_properties.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"configurations": [
3+
{
4+
"name": "Linux",
5+
"includePath": [
6+
"${workspaceFolder}/include",
7+
"${workspaceFolder}/third"
8+
],
9+
"defines": [],
10+
"compilerPath": "/opt/cuda/bin/gcc",
11+
"cStandard": "c11",
12+
"cppStandard": "c++17",
13+
"intelliSenseMode": "clang-x64"
14+
}
15+
],
16+
"version": 4
17+
}

.vscode/settings.json

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
{
2+
"files.associations": {
3+
"iosfwd": "cpp",
4+
"typeindex": "cpp",
5+
"typeinfo": "cpp",
6+
"cctype": "cpp",
7+
"clocale": "cpp",
8+
"cmath": "cpp",
9+
"cstdarg": "cpp",
10+
"cstddef": "cpp",
11+
"cstdio": "cpp",
12+
"cstdlib": "cpp",
13+
"cstring": "cpp",
14+
"ctime": "cpp",
15+
"cwchar": "cpp",
16+
"cwctype": "cpp",
17+
"array": "cpp",
18+
"atomic": "cpp",
19+
"*.tcc": "cpp",
20+
"bitset": "cpp",
21+
"chrono": "cpp",
22+
"cinttypes": "cpp",
23+
"codecvt": "cpp",
24+
"condition_variable": "cpp",
25+
"cstdint": "cpp",
26+
"deque": "cpp",
27+
"list": "cpp",
28+
"unordered_map": "cpp",
29+
"unordered_set": "cpp",
30+
"vector": "cpp",
31+
"exception": "cpp",
32+
"fstream": "cpp",
33+
"functional": "cpp",
34+
"future": "cpp",
35+
"initializer_list": "cpp",
36+
"iostream": "cpp",
37+
"istream": "cpp",
38+
"limits": "cpp",
39+
"memory": "cpp",
40+
"mutex": "cpp",
41+
"numeric": "cpp",
42+
"optional": "cpp",
43+
"ostream": "cpp",
44+
"ratio": "cpp",
45+
"sstream": "cpp",
46+
"stdexcept": "cpp",
47+
"streambuf": "cpp",
48+
"string_view": "cpp",
49+
"system_error": "cpp",
50+
"thread": "cpp",
51+
"type_traits": "cpp",
52+
"tuple": "cpp",
53+
"utility": "cpp",
54+
"variant": "cpp",
55+
"__config": "cpp",
56+
"__nullptr": "cpp",
57+
"algorithm": "cpp",
58+
"iomanip": "cpp",
59+
"forward_list": "cpp",
60+
"valarray": "cpp"
61+
}
62+
}

.vscode/tasks.json

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
{
2+
// See https://go.microsoft.com/fwlink/?LinkId=733558
3+
// for the documentation about the tasks.json format
4+
"version": "2.0.0",
5+
"tasks": [
6+
{
7+
"label": "build",
8+
"type": "shell",
9+
"command": "make -j8",
10+
"options": {
11+
"env": {
12+
"CPP": "/data/ndk/bin/i686-linux-android-g++"
13+
}
14+
},
15+
"group": {
16+
"kind": "build",
17+
"isDefault": true
18+
},
19+
"problemMatcher": [
20+
"$gcc"
21+
]
22+
},
23+
{
24+
"label": "test",
25+
"type": "shell",
26+
"command": "make",
27+
"options": {
28+
"cwd": "./test"
29+
},
30+
"group": {
31+
"kind": "test",
32+
"isDefault": true
33+
},
34+
"presentation": {
35+
"echo": false,
36+
"reveal": "always",
37+
"focus": true,
38+
"panel": "shared",
39+
"showReuseMessage": false
40+
},
41+
"problemMatcher": []
42+
}
43+
]
44+
}

Makefile

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
CXXFLAGS = -ffast-math -std=c++14 -Iinclude -DCHAISCRIPT_NO_THREADS -Wno-invalid-offsetof -O3
2+
LDFLAGS = -L./lib -lminecraftpe
3+
4+
LPLAYER = -Lout -lplayer_support
5+
6+
MODS = chat command form player test
7+
8+
$(shell mkdir -p objs deps out >/dev/null)
9+
10+
.PHONY: all
11+
all: out/libplayer_support.so out/ChaiSupport.so $(addsuffix .mod,$(addprefix out/,$(MODS)))
12+
13+
.PHONY: clean
14+
clean:
15+
@rm -rf objs out deps
16+
17+
out/libplayer_support.so: objs/fix.o objs/player_support.o lib/libminecraftpe.so
18+
@echo LD $@
19+
@$(CPP) $(LDFLAGS) -shared -fPIC -o $@ $(filter %.o,$^)
20+
out/%.mod: objs/%.o objs/hack.o out/libplayer_support.so lib/libminecraftpe.so
21+
@echo LD $@
22+
@$(CPP) $(LDFLAGS) $(LPLAYER) -shared -fPIC -o $@ $(filter %.o,$^)
23+
out/ChaiSupport.so: objs/fix.o objs/main.o out/libplayer_support.so lib/libminecraftpe.so
24+
@echo LD $@
25+
@$(CPP) $(LDFLAGS) $(LPLAYER) -shared -fPIC -o $@ $(filter %.o,$^)
26+
27+
.PRECIOUS: deps/%.d
28+
deps/%.d: src/%.cpp
29+
@echo DP $<
30+
@$(CPP) $(CXXFLAGS) -MT $(patsubst deps/%.d,objs/%.o,$@) -M -o $@ $<
31+
32+
.PRECIOUS: objs/%.o
33+
objs/%.o: src/%.cpp
34+
objs/%.o: src/%.cpp deps/%.d
35+
@echo CC $@
36+
@$(CPP) $(CXXFLAGS) -c -o $@ $<
37+
38+
-include deps/*

include/StaticHook.h

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#pragma once
2+
3+
#include <hook.h>
4+
#include <minecraft/extra/MinecraftHandle.h>
5+
#include <dlfcn.h>
6+
7+
struct RegisterStaticHook {
8+
9+
RegisterStaticHook(const char* sym, void* hook, void** org) {
10+
mcpelauncher_hook(dlsym(MinecraftHandle(), sym), hook, org);
11+
}
12+
13+
// workaround for a warning
14+
template <typename T>
15+
RegisterStaticHook(const char* sym, T hook, void** org) {
16+
union {
17+
T a;
18+
void* b;
19+
} hookUnion;
20+
hookUnion.a = hook;
21+
RegisterStaticHook(sym, hookUnion.b, org);
22+
}
23+
24+
};
25+
26+
27+
#define _TInstanceHook(class_inh, pclass, iname, sym, ret, args...) \
28+
struct _TInstanceHook_##iname class_inh { \
29+
static ret (_TInstanceHook_##iname::*_original)(args); \
30+
template <typename ...Params> \
31+
static ret original(pclass* _this, Params&&... params) { return (((_TInstanceHook_##iname*) _this)->*_original)(std::forward<Params>(params)...); } \
32+
ret _hook(args); \
33+
}; \
34+
static RegisterStaticHook _TRInstanceHook_##iname (#sym, &_TInstanceHook_##iname::_hook, (void**) &_TInstanceHook_##iname::_original); \
35+
ret (_TInstanceHook_##iname::*_TInstanceHook_##iname::_original)(args); \
36+
ret _TInstanceHook_##iname::_hook(args)
37+
#define _TInstanceDefHook(iname, sym, ret, type, args...) _TInstanceHook(: public type, type, iname, sym, ret, args)
38+
#define _TInstanceNoDefHook(iname, sym, ret, args...) _TInstanceHook(, void, iname, sym, ret, args)
39+
40+
#define _TStaticHook(pclass, iname, sym, ret, args...) \
41+
struct _TStaticHook_##iname pclass { \
42+
static ret (*_original)(args); \
43+
template <typename ...Params> \
44+
static ret original(Params&&... params) { return (*_original)(std::forward<Params>(params)...); } \
45+
static ret _hook(args); \
46+
}; \
47+
static RegisterStaticHook _TRStaticHook_##iname (#sym, &_TStaticHook_##iname::_hook, (void**) &_TStaticHook_##iname::_original); \
48+
ret (*_TStaticHook_##iname::_original)(args); \
49+
ret _TStaticHook_##iname::_hook(args)
50+
#define _TStaticDefHook(iname, sym, ret, type, args...) _TStaticHook(: public type, iname, sym, ret, args)
51+
#define _TStaticNoDefHook(iname, sym, ret, args...) _TStaticHook(, iname, sym, ret, args)
52+
53+
#define THook2(iname, ret, sym, args...) _TStaticNoDefHook(iname, sym, ret, args)
54+
#define THook(ret, sym, args...) THook2(sym, ret, sym, args)
55+
#define TClasslessInstanceHook2(iname, ret, sym, args...) _TInstanceNoDefHook(iname, sym, ret, args)
56+
#define TClasslessInstanceHook(ret, sym, args...) TClasslessInstanceHook2(sym, ret, sym, args)
57+
#define TInstanceHook2(iname, ret, sym, type, args...) _TInstanceDefHook(iname, sym, ret, type, args)
58+
#define TInstanceHook(ret, sym, type, args...) TInstanceHook2(sym, ret, sym, type, args)
59+
#define TStaticHook2(iname, ret, sym, type, args...) _TStaticDefHook(iname, sym, ret, type, args)
60+
#define TStaticHook(ret, sym, type, args...) TStaticHook2(sym, ret, sym, type, args)

0 commit comments

Comments
 (0)