Skip to content

Commit

Permalink
Merge pull request #63 from FrederoxDev/1.20.71.1-initial-support
Browse files Browse the repository at this point in the history
1.20.71.1 initial support
  • Loading branch information
FrederoxDev authored Mar 13, 2024
2 parents 75feebf + e145c40 commit 4f88043
Show file tree
Hide file tree
Showing 64 changed files with 924 additions and 602 deletions.
3 changes: 1 addition & 2 deletions AmethystAPI/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
/cmake-build-relwithdebinfo-visual-studio
/.idea
/cmake-build-relwithdebinfo-visual-studio
8 changes: 8 additions & 0 deletions AmethystAPI/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions AmethystAPI/.idea/AmethystAPI.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions AmethystAPI/.idea/cmake.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions AmethystAPI/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions AmethystAPI/.idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions AmethystAPI/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions AmethystAPI/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,14 @@ set_property(GLOBAL PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreadedDLL")

file(GLOB_RECURSE SOURCES "src/*.cpp" "src/*.c" "src/*.asm")
file(GLOB_RECURSE HEADERS "src/*.h" "src/*.hpp")

# Create AmethystAPI as a .lib
add_library(${PROJECT_NAME} STATIC
${SOURCES}
${HEADERS}
src/minecraft/src/common/world/item/Item.asm
src/minecraft/src/common/world/level/block/BlockLegacy.asm
src/minecraft/src-deps/minecraftrenderer/renderer/MaterialPtr.asm
src/minecraft/src/common/world/level/BlockSourceListener.h
)


Expand Down Expand Up @@ -78,4 +77,4 @@ foreach(_source IN ITEMS ${SOURCES} ${HEADERS})
file(RELATIVE_PATH _source_path_rel "${CMAKE_CURRENT_SOURCE_DIR}/src" "${_source_path}")
string(REPLACE "/" "\\" _group_path "${_source_path_rel}")
source_group("${_group_path}" FILES "${_source}")
endforeach()
endforeach()
35 changes: 0 additions & 35 deletions AmethystAPI/src/amethyst/HookManager.cpp

This file was deleted.

65 changes: 0 additions & 65 deletions AmethystAPI/src/amethyst/HookManager.h

This file was deleted.

27 changes: 0 additions & 27 deletions AmethystAPI/src/amethyst/InputManager.h

This file was deleted.

46 changes: 28 additions & 18 deletions AmethystAPI/src/amethyst/Log.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,34 @@
#include <iostream>

namespace Log {
void InitializeConsole();
void DestroyConsole();
void InitializeConsole();
void DestroyConsole();

template <typename... T>
void Info(fmt::format_string<T...> fmt, T&&... args) {
std::string formatted_string = fmt::format(fmt, std::forward<T>(args)...);
fmt::print("{}\n", formatted_string);
}
template <typename... T>
void Info(fmt::format_string<T...> fmt, T&&... args) {
std::string formatted_string = fmt::format(fmt, std::forward<T>(args)...);
fmt::print("{}\n", formatted_string);
}

template <typename... T>
void Warning(fmt::format_string<T...> fmt, T&&... args) {
std::string formatted_string = fmt::format(fmt, std::forward<T>(args)...);
fmt::print(fg(fmt::rgb(0xf5f556)) | fmt::emphasis::bold, "{}\n", formatted_string);
}
template <typename... T>
void Warning(fmt::format_string<T...> fmt, T&&... args) {
std::string formatted_string = fmt::format(fmt, std::forward<T>(args)...);
fmt::print(fg(fmt::rgb(0xf5f556)) | fmt::emphasis::bold, "{}\n", formatted_string);
}

template <typename... T>
void Error(fmt::format_string<T...> fmt, T&&... args) {
std::string formatted_string = fmt::format(fmt, std::forward<T>(args)...);
fmt::print(fg(fmt::rgb(0xf55762)) | fmt::emphasis::bold, "{}\n", formatted_string);
}
}; // namespace Log
template <typename... T>
void Error(fmt::format_string<T...> fmt, T&&... args) {
std::string formatted_string = fmt::format(fmt, std::forward<T>(args)...);
fmt::print(fg(fmt::rgb(0xf55762)) | fmt::emphasis::bold, "{}\n", formatted_string);
}

template <typename... T>
inline void _Assert(const char* function, int line, fmt::format_string<T...> fmt, T&&... args)
{
std::string formatted_string = fmt::format(fmt, std::forward<T>(args)...);
formatted_string += fmt::format("\n\tin: {}, line: {}", function, line);
throw std::exception(formatted_string.c_str());
}

#define Assert(...) _Assert(__FUNCTION__, __LINE__, __VA_ARGS__)
}; // namespace Log
18 changes: 13 additions & 5 deletions AmethystAPI/src/amethyst/Memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <libhat/Scanner.hpp>
#include <mutex>
#include <thread>
#include <optional>

uintptr_t GetMinecraftBaseAddress()
{
Expand All @@ -25,7 +26,7 @@ uintptr_t SlideAddress(uintptr_t offset)
return GetMinecraftBaseAddress() + offset;
}

uintptr_t SigScan(std::string_view signature)
std::optional<uintptr_t> SigScanSafe(std::string_view signature)
{
const auto parsed = hat::parse_signature(signature);
if (!parsed.has_value()) {
Expand All @@ -37,12 +38,19 @@ uintptr_t SigScan(std::string_view signature)
const auto end = begin + GetMinecraftSize();
const auto result = hat::find_pattern(begin, end, parsed.value());

if (!result.has_result()) {
Log::Error("Sigscan failed! {:s}", signature);
throw std::exception();
if (!result.has_result()) return std::nullopt;
return reinterpret_cast<uintptr_t>(result.get());
}

uintptr_t SigScan(std::string_view signature) {
auto result = SigScanSafe(signature);

if (!result.has_value()) {
std::string errorMessage = fmt::format("Failed to find signature \"{:s}\"", signature);
throw std::exception(errorMessage.c_str());
}

return reinterpret_cast<uintptr_t>(result.get());
return result.value();
}

size_t FindOffsetOfPointer(void* _base, void* _pointer, size_t maxSearchSize)
Expand Down
32 changes: 6 additions & 26 deletions AmethystAPI/src/amethyst/Memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ Offsets an address from the game binary, with the position the game has been loa
*/
uintptr_t SlideAddress(uintptr_t offset);

/*
Finds an address of a function with its signature within the loaded game memory
*/
std::optional<uintptr_t> SigScanSafe(std::string_view signature);

/*
Finds an address of a function with its signature within the loaded game memory
*/
Expand All @@ -33,29 +38,4 @@ uintptr_t SigScan(std::string_view signature);
* Finds the offset of a pointer in a struct/class
* returns SIZE_MAX if it fails
*/
size_t FindOffsetOfPointer(void* _base, void* _pointer, size_t maxSearchSize);

template <typename Ret, typename Type>
typename std::conditional<std::is_const<Type>::value, std::add_const<Ret>, std::remove_const<Ret>>::type&
DirectAccess(Type* type, size_t offset) {
union {
size_t raw;
Type* source;
Ret* target;
} u;
u.source = type;
u.raw += offset;
return *u.target;
}

#define AS_FIELD(type, name, fn) __declspec(property(get = fn, put = set##name)) type name
#define DEF_FIELD_RW(type, name) __declspec(property(get = get##name, put = set##name)) type name

#define FAKE_FIELD(type, name) \
AS_FIELD(type, name, get##name); \
type& get##name()

#define BUILD_ACCESS(ptr, type, name, offset) \
AS_FIELD(type, name, get##name); \
type& get##name() const { return DirectAccess<type>(ptr, offset); } \
void set##name(type v) const { DirectAccess<type>(ptr, offset) = std::move(v); }
size_t FindOffsetOfPointer(void* _base, void* _pointer, size_t maxSearchSize);
2 changes: 0 additions & 2 deletions AmethystAPI/src/amethyst/MinecraftVtables.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,4 @@ void InitializeVtablePtrs() {
BlockItem_ctor = reinterpret_cast<void*>(SigScan("48 89 5C 24 ? 48 89 74 24 ? 48 89 4C 24 ? 57 48 83 EC ? 48 8B F2 48 8B F9 E8 ? ? ? ? 90 48 8D 05"));

MaterialPtr_ctor = reinterpret_cast<void*>(SigScan("48 89 4C 24 ? 53 48 83 EC ? 4C 8B CA 48 8B D9 33 C0"));

// mce::RenderMaterialGroup::switchable = reinterpret_cast<mce::RenderMaterialGroupBase*>(SlideAddress(0x572BBB0));
}
2 changes: 1 addition & 1 deletion AmethystAPI/src/amethyst/Utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ std::string GetAmethystFolder()
errno_t err = _dupenv_s(&path, &path_length, "LocalAppData");

if (err) throw std::exception("Failed to get environment variable %LocalAppData%");
if (path == NULL) throw std::exception("%LocalAppData% was null");
if (path == nullptr) throw std::exception("%LocalAppData% was null");

std::string localAppDataFolder(path);
free(path);
Expand Down
22 changes: 22 additions & 0 deletions AmethystAPI/src/amethyst/runtime/AmethystContext.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#pragma once
#include "minecraft/src-client/common/client/game/ClientInstance.h"
#include "minecraft/src-client/common/client/input/MinecraftInputHandler.h"
#include "amethyst/runtime/HookManager.h"
#include "amethyst/runtime/events/EventManager.h"
#include "amethyst/runtime/input/InputManager.h"

class AmethystContext {
public:
/**
* Amethyst Specific stuff
*/
HookManager mHookManager;
Amethyst::EventManager mEventManager;
Amethyst::InputManager mInputManager;

/**
* Minecraft Specific stuff
*/
ClientInstance* mClientInstance = nullptr;
MinecraftInputHandler* mMcInputHandler = nullptr;
};
Loading

0 comments on commit 4f88043

Please sign in to comment.