Skip to content

Commit 9776360

Browse files
authored
Merge pull request #32 from selauraclient/feat/rewrite
plugin loading
2 parents 8543e5c + 9508ad5 commit 9776360

49 files changed

Lines changed: 778 additions & 811 deletions

Some content is hidden

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

CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ add_compile_definitions(
4848
)
4949
5050
add_subdirectory(include)
51-
add_subdirectory(src/mc)
52-
add_subdirectory(src/client)
51+
add_subdirectory(src)
52+
add_subdirectory(test)
5353
5454
if (MSVC)
5555
add_compile_options(/W4 /permissive- /wd4201 /wd4324)

README.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,8 @@ Selaura Client
1212
This repository contains the full source code for Selaura Client. Selaura Client is a mod that aims to improve user experience of Minecraft: Bedrock Edition.
1313

1414
## 🖥️ Compatibility
15-
Selaura Client currently supports:
15+
Selaura Client aims to support:
1616
- Windows 10/11 (64-bit Only)
17-
- Xbox (requires Dev Mode and installation of DLL within Minecraft's files)
1817
- Android 9+ (ARM64 Only)
1918
- Any device supporting [mcpelauncher-linux](https://github.com/minecraft-linux/mcpelauncher-manifest)
2019

@@ -24,8 +23,6 @@ Selaura Client currently supports:
2423
- [foonathan/type_safe](https://github.com/foonathan/type_safe)
2524
- [BasedInc/libhat](https://github.com/BasedInc/libhat)
2625
- [Neargye/magic_enum](https://github.com/Neargye/magic_enum)
27-
- [kunitoki/LuaBridge3](https://github.com/kunitoki/LuaBridge3)
28-
- [Sinan-Karakaya/cpp-i18n](https://github.com/Sinan-Karakaya/cpp-i18n)
2926
- [g-truc/glm](https://github.com/g-truc/glm)
3027
- [ocornut/imgui](https://github.com/ocornut/imgui)
3128

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,9 @@ cmake_minimum_required(VERSION 3.28)
22
project(selaura_client LANGUAGES CXX)
33

44
add_library(selaura_client SHARED
5-
dllmain.cpp
6-
components/client.cpp
7-
memory/scanner.cpp
8-
memory/scan_target.cpp
9-
memory/handle.cpp
10-
patches/patch_manager.cpp
5+
loader/main_win.cpp
6+
loader/runtime.cpp
7+
hooks/hooks.cpp
118
)
129

1310
target_include_directories(selaura_client PRIVATE
@@ -20,6 +17,8 @@ target_include_directories(selaura_client PRIVATE
2017
safetyhook
2118
glaze
2219
magic_enum
20+
21+
${CMAKE_SOURCE_DIR}/src
2322
)
2423

2524
target_link_libraries(selaura_client PRIVATE
@@ -31,4 +30,5 @@ target_link_libraries(selaura_client PRIVATE
3130
safetyhook::safetyhook
3231
glaze::glaze
3332
magic_enum::magic_enum
33+
runtimeobject.lib
3434
)

src/api/helpers/mcuirc.hpp

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#pragma once
2+
#include <api/mc/client/renderer/MinecraftUIRenderContext.hpp>
3+
#include <glm/glm.hpp>
4+
#include <concepts>
5+
6+
namespace selaura {
7+
struct mcuirc {
8+
MinecraftUIRenderContext* ctx;
9+
explicit mcuirc(MinecraftUIRenderContext* _ctx) noexcept : ctx(_ctx) {}
10+
11+
void draw_rect(float x, float y, float width, float height,
12+
const glm::vec4& color,
13+
bool stroke = false, int stroke_width = 1) const noexcept {
14+
const RectangleArea area{x, x + width, y, y + height};
15+
const mce::Color c{color.x, color.y, color.z, color.w};
16+
17+
if (stroke) {
18+
ctx->drawRectangle(area, c, color.z, stroke_width);
19+
}
20+
else {
21+
ctx->fillRectangle(area, c, color.w);
22+
}
23+
}
24+
25+
void draw_rect(const glm::vec2& pos, const glm::vec2& size,
26+
const glm::vec4& color,
27+
bool stroke = false, int stroke_width = 1) const noexcept {
28+
draw_rect(pos.x, pos.y, size.x, size.y, color, stroke, stroke_width);
29+
}
30+
31+
void fill_rect(const glm::vec2& pos, const glm::vec2& size, const glm::vec4& color) const noexcept {
32+
draw_rect(pos, size, color, false);
33+
}
34+
35+
void stroke_rect(const glm::vec2& pos, const glm::vec2& size, const glm::vec4& color, int width = 1) const noexcept {
36+
draw_rect(pos, size, color, true, width);
37+
}
38+
39+
void draw_rect(const glm::vec4& rect, const glm::vec4& color,
40+
bool stroke = false, int stroke_width = 1) const noexcept {
41+
draw_rect(rect.x, rect.y, rect.z, rect.w, color, stroke, stroke_width);
42+
}
43+
};
44+
45+
}

src/api/imports.hpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#pragma once
2+
3+
#ifdef _WIN32
4+
#define MCAPI extern "C" __declspec(dllimport)
5+
#define SELAURA_API extern "C" __declspec(dllexport)
6+
#else
7+
#define SELAURA_API extern "C" __attribute__((visibility("default")))
8+
#endif
9+
10+
#include <entt/entt.hpp>
11+
#include <glm/glm.hpp>
12+
13+
#include <string>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#pragma once
2+
#include <api/mc/client/gui/GuiData.hpp>
3+
4+
class ClientInstance {
5+
public:
6+
uintptr_t** vtable;
7+
std::byte pad_4[1080];
8+
std::unique_ptr<GuiData> mGuiData;
9+
public:
10+
void* $ctor(
11+
void* a1,
12+
void* a2,
13+
void* a3,
14+
void* a4,
15+
void* a5,
16+
void* a6,
17+
void* a7,
18+
void* a8,
19+
void* a9
20+
);
21+
};

src/api/mc/client/gui/GuiData.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#pragma once
2+
#include <string>
3+
4+
class GuiData {
5+
public:
6+
void displayLocalMessage(const std::string& message);
7+
};
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#pragma once
2+
3+
#include <api/mc/client/renderer/MinecraftUIRenderContext.hpp>
4+
5+
class ScreenView {
6+
public:
7+
void setupAndRender(MinecraftUIRenderContext&);
8+
public:
9+
void setupAndRender_hk(MinecraftUIRenderContext* ctx);
10+
};
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
#pragma once
2+
#include <cstdint>
3+
#include <glm/glm.hpp>
4+
#include <gsl/gsl>
5+
6+
#include <api/mc/client/ClientInstance.hpp>
7+
8+
#pragma pack(push, 4)
9+
struct RectangleArea {
10+
float _x0;
11+
float _x1;
12+
float _y0;
13+
float _y1;
14+
};
15+
#pragma pack(pop)
16+
17+
namespace mce {
18+
class Color {
19+
public:
20+
float r;
21+
float g;
22+
float b;
23+
float a;
24+
25+
Color(float r, float g, float b, float a)
26+
{
27+
this->r = r;
28+
this->g = g;
29+
this->b = b;
30+
this->a = a;
31+
}
32+
33+
Color(unsigned int color)
34+
{
35+
this->r = (float)((color & 0xFF000000) >> 24) / 255.0f;
36+
this->g = (float)((color & 0x00FF0000) >> 16) / 255.0f;
37+
this->b = (float)((color & 0x0000FF00) >> 8) / 255.0f;
38+
this->a = (float)((color & 0x000000FF)) / 255.0f;
39+
}
40+
41+
Color()
42+
{
43+
this->r = 0.0f;
44+
this->g = 0.0f;
45+
this->b = 0.0f;
46+
this->a = 0.0f;
47+
}
48+
49+
uint32_t As32() const
50+
{
51+
struct PackedColors {
52+
union {
53+
struct {
54+
char r;
55+
char g;
56+
char b;
57+
char a;
58+
};
59+
unsigned int intValue;
60+
};
61+
};
62+
63+
PackedColors result{};
64+
result.r = static_cast<char>(this->r * 255.0f);
65+
result.g = static_cast<char>(this->g * 255.0f);
66+
result.b = static_cast<char>(this->b * 255.0f);
67+
result.a = static_cast<char>(this->a * 255.0f);
68+
69+
return result.intValue;
70+
}
71+
};
72+
73+
class TexturePtr;
74+
};
75+
76+
class Font;
77+
class NinesliceInfo;
78+
class HashedString;
79+
class ComponentRenderBatch;
80+
class CustomRenderComponent;
81+
class ResourceLocation;
82+
83+
namespace Core {
84+
class Path;
85+
};
86+
87+
class TextMeasureData;
88+
class CaretMeasureData;
89+
90+
namespace ui {
91+
class TextAlignment;
92+
};
93+
94+
class MinecraftUIRenderContext {
95+
public:
96+
MinecraftUIRenderContext(ClientInstance& client, void* screenContext, void* currentScene);
97+
virtual ~MinecraftUIRenderContext();
98+
virtual float getLineLength(Font& font, const std::string& text, float fontSize, bool showColorSymbol);
99+
virtual float getTextAlpha();
100+
virtual void setTextAlpha(float alpha);
101+
virtual void drawDebugText(const RectangleArea& rect, const std::string& text, const mce::Color& color, float alpha, ui::TextAlignment alignment, const TextMeasureData& textData, const CaretMeasureData& caretData);
102+
virtual void drawText(Font& font, const RectangleArea& rect, const std::string& text, const mce::Color& color, float alpha, ui::TextAlignment alignment, const TextMeasureData& textData, const CaretMeasureData& caretData);
103+
virtual void flushText(float deltaTime);
104+
virtual void drawImage(const mce::TexturePtr& texture, const glm::tvec2<float>& position, const glm::tvec2<float>& size, glm::tvec2<float>& uv, glm::tvec2<float>& uvSize, int degree);
105+
virtual void drawNineslice(const mce::TexturePtr& texture, const NinesliceInfo& nineslice);
106+
virtual void flushImages(const mce::Color& color, float alpha, const HashedString& materialNameHash);
107+
virtual void beginSharedMeshBatch(ComponentRenderBatch& renderBatch);
108+
virtual void endSharedMeshBatch(ComponentRenderBatch& renderBatch);
109+
virtual void drawRectangle(const RectangleArea& rect, const mce::Color& color, float alpha, int thickness);
110+
virtual void fillRectangle(const RectangleArea& rect, const mce::Color& color, float alpha);
111+
virtual void increaseStencilRef();
112+
virtual void decreaseStencilRef();
113+
virtual void resetStencilRef();
114+
virtual void fillRectangleStencil(const RectangleArea& rect);
115+
virtual void enableScissorTest(const RectangleArea& rect);
116+
virtual void disableScissorTest();
117+
virtual void setClippingRectangle(const RectangleArea& rect);
118+
virtual void setFullClippingRectangle();
119+
virtual void saveCurrentClippingRectangle();
120+
virtual void restoreSavedClippingRectangle();
121+
virtual RectangleArea getFullClippingRectangle();
122+
virtual bool updateCustom(gsl::not_null<CustomRenderComponent*> customRenderer);
123+
virtual void renderCustom(gsl::not_null<CustomRenderComponent*> customRenderer, int pass, RectangleArea& renderAABB);
124+
virtual void cleanup();
125+
virtual void removePersistentMeshes();
126+
virtual mce::TexturePtr getTexture(const ResourceLocation& resourceLocation, bool forceReload);
127+
virtual mce::TexturePtr getZippedTexture(const Core::Path& zippedFolderPath, const ResourceLocation& resourceLocation, bool forceReload);
128+
virtual void unloadTexture(ResourceLocation const &);
129+
};

src/api/mc/world/Minecraft.hpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#pragma once
2+
#include <api/mc/world/Timer.hpp>
3+
4+
class Minecraft {
5+
public:
6+
std::byte _pad0[216];
7+
Timer& mSimTimer;
8+
Timer& mRealTimer;
9+
public:
10+
Minecraft* $ctor(
11+
void* app,
12+
void* gameCallbacks,
13+
void* allowList,
14+
void* permissionsFile,
15+
void* filePathManager,
16+
void* maxPlayerIdleTime,
17+
void* eventing,
18+
void* network,
19+
void* packetSender,
20+
void* clientSubId,
21+
void* simTimer,
22+
void* realTimer,
23+
void* contentTierManager,
24+
void* serverMetrics
25+
);
26+
};

0 commit comments

Comments
 (0)