Skip to content

Commit

Permalink
Merge pull request #14 from marioCST/feat/1.21.40
Browse files Browse the repository at this point in the history
1.21.4X support
  • Loading branch information
Plextora authored Nov 22, 2024
2 parents 2a6ead1 + add9113 commit 03359ff
Show file tree
Hide file tree
Showing 43 changed files with 221 additions and 147 deletions.
6 changes: 4 additions & 2 deletions LatiteRewrite.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,6 @@
<ClInclude Include="src\client\feature\setting\script\JsSetting.h" />
<ClInclude Include="src\client\hook\Hook.h" />
<ClInclude Include="src\client\hook\Hooks.h" />
<ClInclude Include="src\client\hook\impl\AppPlatformHooks.h" />
<ClInclude Include="src\client\hook\impl\DXHooks.h" />
<ClInclude Include="src\client\hook\impl\PlayerHooks.h" />
<ClInclude Include="src\client\hook\impl\GeneralHooks.h" />
Expand Down Expand Up @@ -562,8 +561,12 @@
<ClInclude Include="src\sdk\common\client\renderer\Tessellator.h" />
<ClInclude Include="src\sdk\common\client\renderer\TexturePtr.h" />
<ClInclude Include="src\sdk\common\client\util\JpegCommentWriter.h" />
<ClInclude Include="src\sdk\common\entity\component\ActorDataFlagComponent.h" />
<ClInclude Include="src\sdk\common\entity\component\ActorEquipmentComponent.h" />
<ClInclude Include="src\sdk\common\entity\component\ActorTypeComponent.h" />
<ClInclude Include="src\sdk\common\entity\component\AttributesComponent.h" />
<ClInclude Include="src\sdk\common\entity\component\MoveInputComponent.h" />
<ClInclude Include="src\sdk\common\entity\component\RuntimeIDComponent.h" />
<ClInclude Include="src\sdk\common\nbt\CompoundTag.h" />
<ClInclude Include="src\sdk\common\nbt\Tag.h" />
<ClInclude Include="src\sdk\common\network\MinecraftPackets.h" />
Expand Down Expand Up @@ -722,7 +725,6 @@
<ClCompile Include="src\client\feature\module\TextModule.cpp" />
<ClCompile Include="src\client\hook\Hook.cpp" />
<ClCompile Include="src\client\hook\Hooks.cpp" />
<ClCompile Include="src\client\hook\impl\AppPlatformHooks.cpp" />
<ClCompile Include="src\client\hook\impl\DXHooks.cpp" />
<ClCompile Include="src\client\hook\impl\GeneralHooks.cpp" />
<ClCompile Include="src\client\hook\impl\LevelRendererHooks.cpp" />
Expand Down
20 changes: 12 additions & 8 deletions src/client/Latite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,15 @@ DWORD __stdcall startThread(HINSTANCE dll) {
int deadCount = 0;

std::unordered_map<std::string, SDK::Version> versNumMap = {
{ "1.21.30", SDK::VLATEST },
{ "1.21.31", SDK::VLATEST }
// { "1.21.20", SDK::VLATEST },
// { "1.21.21", SDK::VLATEST },
// { "1.21.22", SDK::VLATEST },
{ "1.21.44", SDK::VLATEST},
{ "1.21.43", SDK::VLATEST},
{ "1.21.41", SDK::VLATEST},
{ "1.21.40", SDK::VLATEST},
// { "1.21.30", SDK::V1_21_30 },
// { "1.21.31", SDK::V1_21_30 }
// { "1.21.20", SDK::V1_21_20 },
// { "1.21.21", SDK::V1_21_20 },
// { "1.21.22", SDK::V1_21_20 },
//{ "1.21.0", SDK::V1_21 },
//{ "1.21.1", SDK::V1_21 },
//{ "1.21.2", SDK::V1_21 },
Expand Down Expand Up @@ -193,7 +197,7 @@ DWORD __stdcall startThread(HINSTANCE dll) {
MVSIG(ChatScreenController_sendChatMessage),
MVSIG(GameRenderer__renderCurrentFrame),
MVSIG(onClick),
MVSIG(AppPlatform__fireAppFocusLost),
MVSIG(MinecraftGame_onDeviceLost),
MVSIG(MinecraftGame_onAppSuspended),
MVSIG(RenderController_getOverlayColor),
MVSIG(ScreenView_setupAndRender),
Expand Down Expand Up @@ -221,15 +225,15 @@ DWORD __stdcall startThread(HINSTANCE dll) {
MVSIG(BaseActorRenderContext_BaseActorRenderContext),
MVSIG(ItemRenderer_renderGuiItemNew),
MVSIG(BaseAttributeMap_getInstance),
MVSIG(UIControl_setPosition),
MVSIG(UIControl_getPosition),
MVSIG(MinecraftGame_getPrimaryClientInstance),
MVSIG(Components::actorTypeComponent),
MVSIG(ActorRenderDispatcher_render),
MVSIG(LevelRendererPlayer_renderOutlineSelection),
MVSIG(Components::attributesComponent),
MVSIG(Dimension_getSkyColor),
MVSIG(Dimension_getTimeOfDay),
MVSIG(Weather_tick),
MVSIG(Dimension_tick),
MVSIG(Misc::thirdPersonNametag),
MVSIG(ItemStackBase_getDamageValue),
MVSIG(MinecraftPackets_createPacket),
Expand Down
1 change: 0 additions & 1 deletion src/client/hook/Hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include "impl/LevelRendererHooks.h"
#include "impl/OptionHooks.h"
#include "impl/DXHooks.h"
#include "impl/AppPlatformHooks.h"
#include "impl/MinecraftGameHooks.h"
#include "impl/RenderControllerHooks.h"
#include "impl/ScreenViewHooks.h"
Expand Down
2 changes: 0 additions & 2 deletions src/client/hook/Hooks.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include "impl/LevelRendererHooks.h"
#include "impl/OptionHooks.h"
#include "impl/DXHooks.h"
#include "impl/AppPlatformHooks.h"
#include "impl/MinecraftGameHooks.h"
#include "impl/RenderControllerHooks.h"
#include "impl/ScreenViewHooks.h"
Expand All @@ -19,7 +18,6 @@ class LatiteHooks final : public StaticManager<HookGroup,
OptionHooks,
DXHooks,
PlayerHooks,
AppPlatformHooks,
MinecraftGameHooks,
RenderControllerHooks,
ScreenViewHooks,
Expand Down
19 changes: 0 additions & 19 deletions src/client/hook/impl/AppPlatformHooks.cpp

This file was deleted.

9 changes: 0 additions & 9 deletions src/client/hook/impl/AppPlatformHooks.h

This file was deleted.

10 changes: 5 additions & 5 deletions src/client/hook/impl/GeneralHooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace {
std::shared_ptr<Hook> OutlineSelectionHook;
std::shared_ptr<Hook> RenderGuiItemNewHook;
std::shared_ptr<Hook> GetTimeOfDayHook;
std::shared_ptr<Hook> WeatherHook;
std::shared_ptr<Hook> DimensionHook;
std::shared_ptr<Hook> FogColorHook;
std::shared_ptr<Hook> AddMessageHook;
std::shared_ptr<Hook> UpdatePlayerHook;
Expand Down Expand Up @@ -328,15 +328,15 @@ float GenericHooks::hkGetTimeOfDay(SDK::Dimension* obj) {
return ev.getTime();
}

void GenericHooks::hkWeatherTick(SDK::Weather* obj) {
void GenericHooks::hkDimensionTick(SDK::Dimension* obj) {
WeatherEvent ev{};
Eventing::get().dispatch(ev);

if (!ev.shouldShowWeather()) {
obj->data = SDK::Weather::WeatherData{};
obj->weather->data = SDK::Weather::WeatherData{};
}

WeatherHook->oFunc<decltype(&hkWeatherTick)>()(obj);
DimensionHook->oFunc<decltype(&hkDimensionTick)>()(obj);
}

Color* GenericHooks::hkGetFogColor(SDK::Dimension* obj, Color* out, SDK::Actor* ent, float f) {
Expand Down Expand Up @@ -449,7 +449,7 @@ GenericHooks::GenericHooks() : HookGroup("General") {

FogColorHook = addHook(Signatures::Dimension_getSkyColor.result, hkGetFogColor, "Dimension::getFogColor");
GetTimeOfDayHook = addHook(Signatures::Dimension_getTimeOfDay.result, hkGetTimeOfDay, "Dimension::getTimeOfDay");
WeatherHook = addHook(Signatures::Weather_tick.result, hkWeatherTick, "Weather::tick");
DimensionHook = addHook(Signatures::Dimension_tick.result, hkDimensionTick, "Dimension::tick");
AddMessageHook = addHook(Signatures::GuiData__addMessage.result, hkAddMessage, "GuiData::_addMessage");
UpdatePlayerHook = addHook(Signatures::_updatePlayer.result, hkUpdatePlayer, "`anonymous namespace'::_updatePlayer");
OnUriHook = addHook(Signatures::GameArguments__onUri.result, hkOnUri, "GameArguments::_onUri");
Expand Down
2 changes: 1 addition & 1 deletion src/client/hook/impl/GeneralHooks.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class GenericHooks : public HookGroup {
static void LevelRendererPlayer_renderOutlineSelection(SDK::LevelRendererPlayer* obj, SDK::ScreenContext* scn, void* block, void* region, BlockPos pos);
static void* hkRenderGuiItemNew(void* obj, SDK::BaseActorRenderContext* baseActorRenderContext, SDK::ItemStack* itemStack, int mode, float x, float y, float opacity, float scale, float a9, bool ench);
static float hkGetTimeOfDay(SDK::Dimension* obj);
static void hkWeatherTick(SDK::Weather* obj);
static void hkDimensionTick(SDK::Dimension* obj);
static Color* hkGetFogColor(SDK::Dimension* obj, Color* out, SDK::Actor* ent, float f);
static void hkAddMessage(SDK::GuiData* obj, void* msg, uint32_t profanityContext);
static void hkUpdatePlayer(SDK::CameraComponent* obj, void* a, void* b);
Expand Down
12 changes: 12 additions & 0 deletions src/client/hook/impl/MinecraftGameHooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

namespace {
std::shared_ptr<Hook> onAppSuspendedHook;
std::shared_ptr<Hook> onDeviceLostHook;
std::shared_ptr<Hook> _updateHook;
}

Expand All @@ -22,6 +23,15 @@ void* MinecraftGameHooks::onAppSuspended(SDK::MinecraftGame* game,void*a,void*b,
return onAppSuspendedHook->oFunc<decltype(&onAppSuspended)>()(game,a,b,c);
}

void MinecraftGameHooks::onDeviceLost(SDK::MinecraftGame* game) {
FocusLostEvent ev{};

if (Eventing::get().dispatch(ev))
return;

onDeviceLostHook->oFunc<decltype(&onDeviceLost)>()(game);
}

void __fastcall MinecraftGameHooks::_update(SDK::MinecraftGame* game) {
_updateHook->oFunc<decltype(&_update)>()(game);
UpdateEvent ev{};
Expand All @@ -37,6 +47,8 @@ void __fastcall MinecraftGameHooks::_update(SDK::MinecraftGame* game) {
MinecraftGameHooks::MinecraftGameHooks() {
onAppSuspendedHook = addHook(Signatures::MinecraftGame_onAppSuspended.result, onAppSuspended,
"MinecraftGame::onAppSuspended");
onDeviceLostHook = addHook(Signatures::MinecraftGame_onDeviceLost.result, onDeviceLost,
"MinecraftGame::onDeviceLost");
_updateHook = addHook(Signatures::MinecraftGame__update.result, _update,
"MinecraftGame::_update");
}
1 change: 1 addition & 0 deletions src/client/hook/impl/MinecraftGameHooks.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

class MinecraftGameHooks : public HookGroup {
static void* __fastcall onAppSuspended(SDK::MinecraftGame* game,void*,void*,void*);
static void __fastcall onDeviceLost(SDK::MinecraftGame* game);
static void __fastcall _update(SDK::MinecraftGame* game);
public:
MinecraftGameHooks();
Expand Down
24 changes: 24 additions & 0 deletions src/sdk/Util.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,30 @@ namespace util {
}

namespace SDK {
template <int offs_1_21_40, int offs_1_21_30, int offs_1_21_20, int offs_1_20_50, int offs_1_20_40, int offs_1_20_30, int offs_1_18_12, int offs_1_19_51>
extern inline const int mvGetOffset() {
switch (SDK::internalVers) {
case SDK::V1_21_40:
default:
return offs_1_21_40;
case SDK::V1_21_30:
return offs_1_21_30;
case SDK::V1_21_20:
return offs_1_21_20;
case SDK::V1_20_50:
return offs_1_20_50;
case SDK::V1_20_40:
return offs_1_20_40;
case SDK::V1_20_30:
return offs_1_20_30;
case SDK::V1_19_51:
return offs_1_19_51;
break;
case SDK::V1_18_12:
return offs_1_18_12;
}
}

template <int offs_1_21_30, int offs_1_21_20, int offs_1_20_50, int offs_1_20_40, int offs_1_20_30, int offs_1_18_12, int offs_1_19_51>
extern inline const int mvGetOffset() {
switch (SDK::internalVers) {
Expand Down
3 changes: 2 additions & 1 deletion src/sdk/Version.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ namespace SDK {
V1_21 = 12100,
V1_21_20 = 12120,
V1_21_30 = 12130,
VLATEST = V1_21_30,
V1_21_40 = 12140,
VLATEST = V1_21_40,
};

extern int internalVers;
Expand Down
15 changes: 12 additions & 3 deletions src/sdk/common/client/game/ClientInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ SDK::BlockSource* SDK::ClientInstance::getRegion() {
if (SDK::internalVers < SDK::V1_20_50) {
return memory::callVirtual<BlockSource*>(this, 0x1A);
}
return memory::callVirtual<BlockSource*>(this, 0x1C);
if (SDK::internalVers < SDK::V1_21_40) {
return memory::callVirtual<BlockSource*>(this, 0x1C);
}
return memory::callVirtual<BlockSource*>(this, 0x1D);
}


Expand All @@ -50,7 +53,10 @@ SDK::LocalPlayer* SDK::ClientInstance::getLocalPlayer() {
if (SDK::internalVers < SDK::V1_20_50) {
return memory::callVirtual<LocalPlayer*>(this, 0x1B);
}
return memory::callVirtual<LocalPlayer*>(this, 0x1D);
if (SDK::internalVers < SDK::V1_21_40) {
return memory::callVirtual<LocalPlayer*>(this, 0x1D);
}
return memory::callVirtual<LocalPlayer*>(this, 0x1E);
}

SDK::GuiData* SDK::ClientInstance::getGuiData() {
Expand All @@ -64,13 +70,16 @@ SDK::GuiData* SDK::ClientInstance::getGuiData() {
{
return util::directAccess<GuiData*>(this, 0x558);
}
if (internalVers >= V1_21_40) {
return util::directAccess<GuiData*>(this, 0x590);
}
return util::directAccess<GuiData*>(this, 0x588);
}
return nullptr;
}

SDK::Options* SDK::ClientInstance::getOptions() {
return memory::callVirtual<Options*>(this, 0xBD);
return memory::callVirtual<Options*>(this, 0xBE);
}

void SDK::ClientInstance::grabCursor() {
Expand Down
10 changes: 5 additions & 5 deletions src/sdk/common/client/game/ClientInstance.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
namespace SDK {
class ClientInstance {
public:
MVCLASS_FIELD(class MinecraftGame*, minecraftGame, 0xC8, 0xA8, 0xA8);
MVCLASS_FIELD(class Minecraft*, minecraft, 0xD0, 0xC0, 0xC0);
MVCLASS_FIELD(class LevelRenderer*, levelRenderer, 0xE0, 0xD0, 0xD0);
MVCLASS_FIELD(class ClientInputHandler*, inputHandler, 0x0110, 0x100, 0x100);
MVCLASS_FIELD(struct Vec2, cursorPos, 0x4C8, 0x498, 0x458, 0x458);
MVCLASS_FIELD(class MinecraftGame*, minecraftGame, 0xD0, 0xC8, 0xC8, 0xC8, 0xC8, 0xC8, 0xA8, 0xA8);
MVCLASS_FIELD(class Minecraft*, minecraft, 0xD8, 0xD0, 0xD0, 0xD0, 0xD0, 0xD0, 0xC0, 0xC0);
MVCLASS_FIELD(class LevelRenderer*, levelRenderer, 0xE8, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xD0, 0xD0);
MVCLASS_FIELD(class ClientInputHandler*, inputHandler, 0x118, 0x110, 0x110, 0x110, 0x110, 0x110, 0x100, 0x100);
MVCLASS_FIELD(struct Vec2, cursorPos, 0x4D0, 0x4C8, 0x4C8, 0x4C8, 0x4C8, 0x498, 0x458, 0x458);

static ClientInstance* get();
class BlockSource* getRegion();
Expand Down
2 changes: 1 addition & 1 deletion src/sdk/common/client/game/FontRepository.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
namespace SDK {
class FontRepository {
public:
MVCLASS_FIELD(std::vector<std::shared_ptr<class Font>>, fontList, 0x20, 0x28, 0x20);
MVCLASS_FIELD(std::vector<std::shared_ptr<class Font>>, fontList, 0x30, 0x20, 0x20, 0x20, 0x20, 0x20, 0x28, 0x20);

class Font* getSmoothFont() {
return fontList[7].get();
Expand Down
4 changes: 4 additions & 0 deletions src/sdk/common/client/game/MinecraftGame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ bool SDK::MinecraftGame::isCursorGrabbed() {
}

SDK::ClientInstance* SDK::MinecraftGame::getPrimaryClientInstance() {
if (SDK::internalVers >= V1_21_40) {
const auto map = reinterpret_cast<std::map<unsigned char, std::shared_ptr<SDK::ClientInstance>>*>(reinterpret_cast<uintptr_t>(this) + 0x828);
return map->at(0).get();
}
//19AAAB62768
// actually a NonOwnerPointer
std::shared_ptr<ClientInstance*> inst = nullptr;
Expand Down
7 changes: 5 additions & 2 deletions src/sdk/common/client/game/MinecraftGame.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@ namespace SDK {

MVCLASS_FIELD(std::string, xuid, 0x310, 0x320, 0x318, 0x318, 0x2F8, 0x618, 0x228);
private:
MVCLASS_FIELD(class FontRepository**, fontRepo, 0xE08, 0xE00, 0xF60, 0xF30, 0xF20, 0x110, 0xF88);
MVCLASS_FIELD(class FontRepository**, fontRepo, 0xDE0, 0xE08, 0xE00, 0xF60, 0xF30, 0xF20, 0x110, 0xF88);
public:
MVCLASS_FIELD(class Font*, minecraftFont, 0xE18, 0xE10, 0xF70, 0xF40, 0xF30, 0x120, 0xF78);
MVCLASS_FIELD(class Font*, minecraftFont, 0xDE8, 0xE18, 0xE10, 0xF70, 0xF40, 0xF30, 0x120, 0xF78);

class FontRepository* getFontRepository() {
if (internalVers >= V1_21_40) {
return reinterpret_cast<FontRepository*>(fontRepo);
}
if (internalVers > V1_19_41) {
return *fontRepo;
}
Expand Down
3 changes: 2 additions & 1 deletion src/sdk/common/client/gui/controls/UIControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
#include "sdk/signature/storage.h"

void SDK::UIControl::updatePos() {
reinterpret_cast<void(*)(UIControl*)>(Signatures::UIControl_setPosition.result)(this);
flags |= 1;
reinterpret_cast<void(*)(UIControl*)>(Signatures::UIControl_getPosition.result)(this);
}
4 changes: 1 addition & 3 deletions src/sdk/common/client/gui/controls/UIControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@ namespace SDK {
char pad_0000[16]; //0x0000
public:
Vec2 position; //0x0010
private:
char pad_0018[8]; //0x0018
public:
uint64_t flags; //0x0018
std::string name; //0x0020
private:
char pad_0040[8]; //0x0040
Expand Down
2 changes: 1 addition & 1 deletion src/sdk/common/client/input/ClientInputHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ namespace SDK {

class ClientInputHandler {
public:
MVCLASS_FIELD(ClientInputMappingFactory*, mappingFactory, 0x20, 0x18, 0x18); // ClientInputHandler::getMappingFactory
MVCLASS_FIELD(ClientInputMappingFactory*, mappingFactory, 0x28, 0x20, 0x20, 0x20, 0x20, 0x20, 0x18, 0x18); // ClientInputHandler::getMappingFactory
};
}
2 changes: 1 addition & 1 deletion src/sdk/common/client/renderer/game/LevelRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace SDK {
class LevelRenderer {
MVCLASS_FIELD(LevelRendererPlayer*, levelRendererPlayer, 0x308, 0x288, 0x2A8);
MVCLASS_FIELD(LevelRendererPlayer*, levelRendererPlayer, 0x318, 0x308, 0x308, 0x308, 0x308, 0x308, 0x288, 0x2A8);
public:
LevelRendererPlayer* getLevelRendererPlayer() {
if (SDK::internalVers <= V1_19_51 /*1.20+*/) {
Expand Down
Loading

0 comments on commit 03359ff

Please sign in to comment.