Skip to content
This repository was archived by the owner on Apr 7, 2024. It is now read-only.

Commit 4ffe59e

Browse files
committed
initial commit
0 parents  commit 4ffe59e

File tree

573 files changed

+116900
-0
lines changed

Some content is hidden

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

573 files changed

+116900
-0
lines changed

.clang-format

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# https://clang.llvm.org/docs/ClangFormatStyleOptions.html
2+
IndentWidth: 4
3+
ColumnLimit: 140
4+
UseTab: Never
5+
AllowShortIfStatementsOnASingleLine: false
6+
UseCRLF: false
7+
AlignArrayOfStructures: None
8+
# AlignArrayOfStructures: Left
9+
# AlignConsecutiveAssignments: Consecutive
10+
AlignTrailingComments: true
11+
AllowShortBlocksOnASingleLine: Never
12+
AllowShortCaseLabelsOnASingleLine: false
13+
AllowShortEnumsOnASingleLine: false
14+
AllowShortFunctionsOnASingleLine: Empty
15+
AlwaysBreakTemplateDeclarations: Yes
16+
PointerAlignment: Left
17+
QualifierAlignment: Left
18+
SpaceAroundPointerQualifiers: Before
19+
SpaceBeforeCaseColon: false
20+
SpaceBeforeCpp11BracedList: true
21+
SpaceBeforeCtorInitializerColon: true
22+
SpaceBeforeInheritanceColon: true
23+
SpaceBeforeRangeBasedForLoopColon: true
24+
SpaceBeforeSquareBrackets: false
25+
SpaceInEmptyBlock: false
26+
SpaceInEmptyParentheses: false
27+
SpacesInAngles: Never
28+
SpacesInCStyleCastParentheses: false
29+
SpacesInConditionalStatement: false
30+
SpacesInContainerLiterals: false
31+
SpaceAfterLogicalNot: false
32+
SpaceAfterTemplateKeyword: true
33+
NamespaceIndentation: All
34+
SortIncludes: Never

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/.vscode/
2+
/.vs/
3+
/build/
4+
/build_linux/
5+
/out/
6+
/NDKPath.txt
7+
/*.bat

.gitmodules

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[submodule "libs/fmt"]
2+
path = libs/fmt
3+
url = https://github.com/fmtlib/fmt.git
4+
[submodule "libs/utf8"]
5+
path = libs/utf8
6+
url = https://github.com/nemtrif/utfcpp.git
7+
[submodule "libs/jansson"]
8+
path = libs/jansson
9+
url = https://github.com/akheron/jansson.git

CMakeLists.txt

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
cmake_minimum_required(VERSION 3.0.0)
2+
3+
# write path to ur android ndk into NDKPath.txt. Recommended version is r16b
4+
# use / in the path (not \ or \\)
5+
file(STRINGS "NDKPath.txt" CMAKE_ANDROID_NDK)
6+
7+
set(CMAKE_CXX_STANDARD 11)
8+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
9+
set(CMAKE_CXX_EXTENSIONS OFF)
10+
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/out)
11+
set(CMAKE_SYSTEM_NAME Android)
12+
set(CMAKE_SYSTEM_VERSION 21)
13+
set(CMAKE_ANDROID_ARCH_ABI armeabi-v7a) # arm64-v8a / armeabi-v7a
14+
set(CMAKE_ANDROID_STL_TYPE gnustl_static)
15+
set(MODNAME GDL)
16+
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
17+
18+
project(${MODNAME} VERSION 1.0.0)
19+
20+
file(GLOB SOURCES
21+
src/*.cpp
22+
libs/KittyMemory/*.cpp
23+
)
24+
25+
add_subdirectory(libs/fmt)
26+
add_subdirectory(libs/cocos2dx)
27+
add_subdirectory(libs/utf8)
28+
set(JANSSON_BUILD_DOCS OFF CACHE INTERNAL "" FORCE)
29+
add_subdirectory(libs/jansson)
30+
31+
add_library(${MODNAME} SHARED ${SOURCES})
32+
33+
target_link_libraries(${MODNAME} log ${CMAKE_SOURCE_DIR}/libs/dobby/libdobby.a fmt cocos2d utf8cpp jansson ${CMAKE_SOURCE_DIR}/libs/libcocos2dcpp.so)
34+
target_include_directories(${MODNAME} PUBLIC
35+
libs/dobby
36+
libs/KittyMemory
37+
libs/jansson/src
38+
libs/jansson/android
39+
libs
40+
libs/gdh/
41+
libs/gdh/achievement_nodes
42+
libs/gdh/actions
43+
libs/gdh/audio_nodes
44+
libs/gdh/delegates
45+
libs/gdh/include
46+
libs/gdh/layers_scenes_transitions_nodes
47+
libs/gdh/level_nodes
48+
libs/gdh/manager_nodes
49+
libs/gdh/menu_nodes
50+
libs/gdh/other_nodes
51+
libs/gdh/scroll_nodes
52+
libs/gdh/sprite_nodes
53+
libs/gdh/text_input_nodes
54+
)
55+
56+
install(TARGETS ${MODNAME} LIBRARY)

libs/BrownAlertDelegate.hpp

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
#pragma once
2+
#include "../src/includes.hpp"
3+
4+
class FLAlertLayer_ : public cocos2d::CCLayerColor {
5+
public:
6+
cocos2d::CCMenu* m_buttonMenu;
7+
int m_controlConnected;
8+
void* m_alertProtocol;
9+
cocos2d::CCNode* m_scene;
10+
bool m_reverseKeyBack;
11+
cocos2d::ccColor3B m_color;
12+
cocos2d::CCLayer* m_mainLayer;
13+
int m_ZOrder;
14+
bool m_noElasticity;
15+
cocos2d::ccColor3B m_color2;
16+
ButtonSprite* m_button1;
17+
ButtonSprite* m_button2;
18+
cocos2d::CCLayerColor* m_scrollingLayer;
19+
int m_joystickConnected;
20+
bool m_containsBorder;
21+
bool m_noAction;
22+
};
23+
24+
class BrownAlertDelegate : public FLAlertLayer_ {
25+
protected:
26+
// layer size is stored here
27+
cocos2d::CCSize m_pLrSize;
28+
29+
// override this to add your own
30+
// layer code
31+
virtual void setup() = 0;
32+
33+
// dont override this one
34+
// the floats are width and height
35+
// the background sprite may be changed
36+
inline virtual bool init(float _w, float _h, const char* _spr = "GJ_square01.png") {
37+
auto winSize = cocos2d::CCDirector::sharedDirector()->getWinSize();
38+
this->m_pLrSize = cocos2d::CCSize { _w, _h };
39+
40+
if (!this->initWithColor({ 0, 0, 0, 125 })) return false;
41+
this->m_mainLayer = cocos2d::CCLayer::create();
42+
this->addChild(this->m_mainLayer);
43+
44+
auto bg = cocos2d::extension::CCScale9Sprite::create(_spr, { 0.0f, 0.0f, 80.0f, 80.0f });
45+
bg->setContentSize(this->m_pLrSize);
46+
bg->setPosition(winSize.width / 2, winSize.height / 2);
47+
this->m_mainLayer->addChild(bg);
48+
49+
this->m_buttonMenu = cocos2d::CCMenu::create();
50+
this->m_mainLayer->addChild(this->m_buttonMenu);
51+
52+
setup();
53+
54+
// auto closeSpr = cocos2d::CCSprite::createWithSpriteFrameName("GJ_closeBtn_001.png");
55+
// closeSpr->setScale(.8f);
56+
57+
// auto closeBtn = CCMenuItemSpriteExtra::create(
58+
// closeSpr,
59+
// this,
60+
// (cocos2d::SEL_MenuHandler)&BrownAlertDelegate::onClose
61+
// );
62+
// closeBtn->setUserData(reinterpret_cast<void*>(this));
63+
64+
// this->m_buttonMenu->addChild(closeBtn);
65+
66+
// closeBtn->setPosition( - _w / 2, _h / 2 );
67+
68+
this->setKeypadEnabled(true);
69+
this->setTouchEnabled(true);
70+
71+
this->m_mainLayer->setScale(0.1f);
72+
this->m_mainLayer->runAction(
73+
CCEaseElasticOut::create(
74+
CCScaleTo::create(0.5f, 1.0),
75+
0.6f
76+
)
77+
);
78+
79+
return true;
80+
}
81+
82+
inline void onClose(cocos2d::CCObject*) {
83+
this->setKeyboardEnabled(false);
84+
this->removeFromParentAndCleanup(true);
85+
}
86+
};

libs/KittyMemory/KittyArm64.cpp

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
#include "KittyArm64.h"
2+
3+
// refs to
4+
// https://github.com/CAS-Atlantic/AArch64-Encoding
5+
// https://github.com/bminor/binutils-gdb
6+
// https://github.com/capstone-engine/capstone
7+
// https://github.com/qemu/QEMU
8+
// https://reverseengineering.stackexchange.com/questions/15418/getting-function-address-by-reading-adrp-and-add-instruction-values
9+
// https://stackoverflow.com/questions/41906688/what-are-the-semantics-of-adrp-and-adrl-instructions-in-arm-assembly
10+
11+
namespace KittyArm64
12+
{
13+
14+
int32_t bit_from(uint32_t insn, int pos)
15+
{
16+
return ((1 << pos) & insn) >> pos;
17+
}
18+
19+
int32_t bits_from(uint32_t insn, int pos, int l)
20+
{
21+
return (insn >> pos) & ((1 << l) - 1);
22+
}
23+
24+
bool is_insn_adr(uint32_t insn)
25+
{
26+
return (insn & 0x9F000000) == 0x10000000;
27+
}
28+
29+
bool is_insn_adrp(uint32_t insn)
30+
{
31+
return (insn & 0x9F000000) == 0x90000000;
32+
}
33+
34+
// decode adr/adrp
35+
bool decode_adr_imm(uint32_t insn, int64_t *imm)
36+
{
37+
if (is_insn_adr(insn) || is_insn_adrp(insn))
38+
{
39+
// 21-bit imm encoded in adrp.
40+
int64_t imm_val = bits_from(insn, 5, 19) << 2; // immhi
41+
imm_val |= bits_from(insn, 29, 2); // immlo
42+
43+
if (is_insn_adrp(insn))
44+
{
45+
// Retrieve msb of 21-bit-signed imm for sign extension.
46+
uint64_t msbt = (imm_val >> 20) & 1;
47+
48+
// Real value is imm multiplied by 4k. Value now has 33-bit information.
49+
imm_val <<= 12;
50+
51+
// Sign extend to 64-bit by repeating msbt 31 (64-33) times and merge it
52+
// with value.
53+
*imm = ((((uint64_t)(1) << 32) - msbt) << 33) | imm_val;
54+
}
55+
else // adr
56+
{
57+
// Sign-extend the 21-bit immediate.
58+
if (imm_val & (1 << (21 - 1)))
59+
imm_val |= ~((1LL << 21) - 1);
60+
61+
*imm = imm_val;
62+
}
63+
64+
return true;
65+
}
66+
67+
return false;
68+
}
69+
70+
/*
71+
* 31 30 29 28 23 22 21 10 9 5 4 0
72+
* +--+--+--+-------------+--+-------------+-----+-----+
73+
* |sf|op| S| 1 0 0 0 1 0 |sh| imm12 | Rn | Rd |
74+
* +--+--+--+-------------+--+-------------+-----+-----+
75+
*
76+
* sf: 0 -> 32bit, 1 -> 64bit
77+
* op: 0 -> add , 1 -> sub
78+
* S: 1 -> set flags
79+
* sh: 1 -> LSL imm by 12
80+
*/
81+
82+
int32_t decode_addsub_imm(uint32_t insn)
83+
{
84+
int32_t imm12 = bits_from(insn, 10, 12);
85+
86+
bool shift = bit_from(insn, 22) == 1;
87+
88+
if (shift)
89+
{
90+
imm12 <<= 12;
91+
}
92+
93+
return imm12;
94+
}
95+
96+
bool is_insn_ld(uint32_t insn)
97+
{
98+
// L bit
99+
return bit_from(insn, 22) == 1;
100+
}
101+
102+
bool is_insn_ldst(uint32_t insn)
103+
{
104+
return (insn & 0x0a000000) == 0x08000000;
105+
}
106+
107+
bool is_insn_ldst_uimm(uint32_t insn)
108+
{
109+
return (insn & 0x3b000000) == 0x39000000;
110+
}
111+
112+
// decode Load/store unsigned immediate
113+
bool decode_ldrstr_uimm(uint32_t insn, int32_t *imm12)
114+
{
115+
if (is_insn_ldst_uimm(insn))
116+
{
117+
*imm12 = bits_from(insn, 10, 12);
118+
// shift with scale value
119+
*imm12 <<= bits_from(insn, 30, 2); // size bits
120+
121+
return true;
122+
}
123+
124+
return false;
125+
}
126+
127+
}

libs/KittyMemory/KittyArm64.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#pragma once
2+
3+
#include <cstdio>
4+
#include <cstdint>
5+
#include <string>
6+
7+
namespace KittyArm64
8+
{
9+
10+
int32_t bit_from(uint32_t insn, int pos);
11+
12+
int32_t bits_from(uint32_t insn, int pos, int l);
13+
14+
bool is_insn_adr(uint32_t insn);
15+
16+
bool is_insn_adrp(uint32_t insn);
17+
18+
bool decode_adr_imm(uint32_t insn, int64_t *imm);
19+
20+
int32_t decode_addsub_imm(uint32_t insn);
21+
22+
bool is_insn_ld(uint32_t insn);
23+
24+
bool is_insn_ldst(uint32_t insn);
25+
26+
bool is_insn_ldst_uimm(uint32_t insn);
27+
28+
bool decode_ldrstr_uimm(uint32_t insn, int32_t *offset);
29+
30+
}

0 commit comments

Comments
 (0)