From dce2ca08f3d36c5a160989a3b2c2176cb195b7c4 Mon Sep 17 00:00:00 2001 From: Knaapchen Date: Mon, 10 Oct 2022 00:45:29 +0200 Subject: [PATCH] First kills made by bot only :D --- flyff-api/src/Mover.h | 14 +++ flyff-api/src/ObjectType.h | 19 ++- flyff-api/src/core.h | 3 +- fugg-client/src/client.cpp | 243 ++++++++++++++++++++++++++++--------- 4 files changed, 221 insertions(+), 58 deletions(-) diff --git a/flyff-api/src/Mover.h b/flyff-api/src/Mover.h index 492be39..5275e83 100644 --- a/flyff-api/src/Mover.h +++ b/flyff-api/src/Mover.h @@ -6,6 +6,7 @@ #include "core.h" #include "math.h" +#include "ObjectType.h" namespace flyff { struct __attribute__((packed)) Mover { @@ -21,10 +22,23 @@ struct __attribute__((packed)) Mover { DEFINE_MEMBER(1768, flyff::MoverID, current_attack_target); DEFINE_MEMBER(1776, flyff::MoverID, platform_standing_on); + DEFINE_MEMBER(1820, uint32_t, server_tick); + DEFINE_MEMBER(1792, int, current_animation); + DEFINE_MEMBER(204, ObjectType, type); + + DEFINE_MEMBER(216, uint32_t, existence_check); + DEFINE_MEMBER(916, uint32_t, if_not_null_needsattackitem); + + DEFINE_MEMBER(1807, uint8_t, is_dead_flags); + const MinimumSize<4096> __size; }; + + bool is_dead() const { + return (is_dead_flags & 8) != 0; + } }; }; \ No newline at end of file diff --git a/flyff-api/src/ObjectType.h b/flyff-api/src/ObjectType.h index bc51340..b9c7726 100644 --- a/flyff-api/src/ObjectType.h +++ b/flyff-api/src/ObjectType.h @@ -10,4 +10,21 @@ enum class ObjectType : int { Region = 6 /* Region (event, attribute) */, Ship = 7, Path = 8 -}; \ No newline at end of file +}; + +static std::ostream& operator<<(std::ostream& os, const ObjectType& type) { + switch(type) { + case ObjectType::Object: os << "Object"; break; + case ObjectType::Animation: os << "Animation"; break; + case ObjectType::Ctrl: os << "Ctrl"; break; + case ObjectType::Sfx: os << "Sfx"; break; + case ObjectType::Item: os << "Item"; break; + case ObjectType::Mover: os << "Mover"; break; + case ObjectType::Region: os << "Region"; break; + case ObjectType::Ship: os << "Ship"; break; + case ObjectType::Path: os << "Path"; break; + default: os << "Unknown"; break; + } + + return os; +} diff --git a/flyff-api/src/core.h b/flyff-api/src/core.h index dedfa12..cbf4cae 100644 --- a/flyff-api/src/core.h +++ b/flyff-api/src/core.h @@ -86,8 +86,7 @@ public: copy.text = kMemory.to_outside(text); // TODO: Probably offset capacity too. } - - std::cout << "RIGHT BEFORE COPY!" << std::endl; + return *reinterpret_cast(©); } diff --git a/fugg-client/src/client.cpp b/fugg-client/src/client.cpp index e96ce26..eaf80ff 100644 --- a/fugg-client/src/client.cpp +++ b/fugg-client/src/client.cpp @@ -3,11 +3,36 @@ #include #include +#include namespace fugg { } +constexpr const uint32_t hash_to_id(const uint32_t hashed) { + constexpr uint32_t header_hash = 0x644ab400; + + return hashed ^ header_hash; +} + +template +void packet_push(std::vector& packet, const T& value, std::vector::iterator offset) { + union ToBytes { + T value; + uint8_t bytes[sizeof(T)]; + }; + + ToBytes ref = { value }; + + packet.insert(offset, std::begin(ref.bytes), std::end(ref.bytes)); +} + +template +void packet_push(std::vector& packet, const T& value) { + return packet_push(packet, value, std::end(packet)); +} + + const flyff::String get_text(const std::string& id) { auto result = std::make_unique(); auto id_ = std::make_unique(id); @@ -41,7 +66,12 @@ void show_message(const std::string& message, const flyff::Color& color) { ); } -void send_packet(std::vector payload) { +void send_packet(const uint32_t& id, std::vector payload) { + const uint32_t header_hash = 0x644ab400; + const uint32_t header = id ^ header_hash; + // Add header + packet_push(payload, header, std::begin(payload)); + struct Vector { uintptr_t begin; uintptr_t end; @@ -66,6 +96,10 @@ void send_packet(std::vector payload) { ); } +void send_logout() { + send_packet(0x403, {}); +} + #include #include #include @@ -77,72 +111,89 @@ void send_packet(std::vector payload) { #include -template -void packet_push(std::vector& packet, const T& value) { - union ToBytes { - T value; - uint8_t bytes[sizeof(T)]; - }; - - ToBytes ref = { value }; - - packet.insert(packet.end(), std::begin(ref.bytes), std::end(ref.bytes)); -} - void move_item_in_inventory(const uint32_t& from_slot, const uint32_t& to_slot) { std::vector packet; - // Not sure yet about these - packet.insert(packet.end(), { 0x01, 0x94 }); - packet.insert(packet.end(), { 0x4a, 0x64 }); packet_push(packet, from_slot); packet_push(packet, to_slot); - send_packet(packet); + send_packet(0x2001, packet); } void use_item_in_inventory(const uint32_t& slot) { std::vector packet; - // Not sure yet - packet.insert(packet.end(), { 0x10, 0xb0 }); - // Same as move_item_in_inventory - packet.insert(packet.end(), { 0x4a, 0x64 }); packet_push(packet, slot); // Unknown yet packet_push(packet, 0); - send_packet(packet); + send_packet(0x410, packet); +} +using MotionParam = unsigned long long; + +void send_motion_packet( + const uint32_t& action, + MotionParam param0 = 0, + MotionParam param1 = 0, + MotionParam param2 = 0, + MotionParam param3 = 0 +) { + const int32_t motion_packet_id = 0x404; + + auto& player_pointer = fugg::module_ref(0x0003546c); + if(player_pointer == 0) + return; + + auto& player = fugg::module_ref(player_pointer); + + std::vector packet; + + uint8_t param_flags = 0; + if(param0 != 0) param_flags |= 1; + if(param1 != 0) param_flags |= 2; + if(param2 != 0) param_flags |= 4; + if(param3 != 0) param_flags |= 8; + + packet_push(packet, player.position); + packet_push(packet, action); + packet_push(packet, param_flags); + packet_push(packet, player.server_tick); + + if(param0 != 0) packet_push(packet, param0); + if(param1 != 0) packet_push(packet, param1); + if(param2 != 0) packet_push(packet, param2); + if(param3 != 0) packet_push(packet, param3); + + send_packet(0x404, packet); +} + +void set_target(const unsigned long long& id) { + send_motion_packet(0x04, id); +} + +void clear_target() { + send_motion_packet(0x04); +} + +void interact_target(const unsigned long long& id) { + send_motion_packet(0x11, id); } void move_to(const float& x, const float& y, const float& z) { // Mouse click - // 04 B0 4A 64 FC D9 D4 45 AC 20 D4 42 C3 B9 52 45 00 07 65 30 00 00 68 F5 D4 45 00 00 00 00 8B A8 D1 42 00 00 00 00 FE 98 52 45 00 00 00 00 - - std::vector packet; - packet.push_back(0x04); - packet.push_back(0xb0); - - // Same as move_item_in_inventory - packet.insert(packet.end(), { 0x4a, 0x64 }); - - packet_push(packet, x); - packet_push(packet, y); - packet_push(packet, z); - // ... - // send_packet(packet); + send_motion_packet( + 0, + *reinterpret_cast(&x), + *reinterpret_cast(&y), + *reinterpret_cast(&z) + ); } void write_chat_message(const std::string& message) { // 00 94 4A 64 [0B 00 00 00] [48 65 6C 6C 6F 20 77 6F 72 6C 64] 00 00 00 00 00 00 00 00 std::vector packet; - packet.push_back(0x00); - packet.push_back(0x94); - // Same as move_item_in_inventory - packet.insert(packet.end(), { 0x4a, 0x64 }); - // Message length packet_push(packet, message.length()); // Write message @@ -154,26 +205,108 @@ void write_chat_message(const std::string& message) { // Unknown 2 packet_push(packet, 0); - send_packet(packet); + send_packet(0x2000, packet); } void on_keyup_hook(int event_type, const EmscriptenKeyboardEvent* event, void* user_data) { // [ - if(event->keyCode == 219) { - show_message("HAHAH DIKKE VETTE ANUSSEN", { 0xFF, 0, 0 }); - - // send_packet({ - // 0x01, 0x94, 0x4a, 0x64, - // // From slot - // 0x05, 0x00, 0x00, 0x00, - // // To slot - // 0x00, 0x00, 0x00, 0x00 - // }); + if(event->keyCode == 219) { + // send_logout(); + // show_message(get_text("ids_textclient_fly_noskill"), { 0xFF, 0xFF, 0xFF }); - // move_item_in_inventory(0, 50); - use_item_in_inventory(0); + // set_target(778); + // interact_target(1); + + // Some aibatt NW of Flaris + // set_target(0x069f7df5); + // interact_target(1); + + + const auto& player_pointer = fugg::module_ref(0x0003546c); + if(player_pointer == 0) + return; + + const auto& player = fugg::module_ref(player_pointer); + const auto& player_object_id = fugg::module_ref(0x00034598); + + // std::stringstream str; + // str << "Position: " + // << player.position.x << ", " + // << player.position.y << ", " + // << player.position.z; + + // show_message(str.str(), { 0xFF, 0, 0xFF }); + // std::stringstream str; + // str << "Sent_in_motion_packet: " << player.sent_in_motion_packet; + + // show_message(str.str(), { 0xFF, 0, 0xFF }); + + // show_message(get_text("ids_ui_pk_confirm_title"), { 0x00, 0xFF, 0x00 }); + + // write_chat_message("Hahaha dikke vette moeders"); + + // move_to(6968.38, 100.011, 3328.86); + // send_motion_packet(0x404, 0x04, 535); + // send_motion_packet(0x404, 0x11, 1); + + + struct __attribute__((packed)) MoverHolder { + uintptr_t next; + unsigned int list_index; + unsigned long long hash; + uintptr_t mover; + }; + + struct __attribute__((packed)) MoverHolderMap { + uintptr_t buckets; + size_t capacity; + uintptr_t first; + }; + + const auto& map = fugg::module_ref(0x00032968); + + std::cout << "Got mover map with " << map.capacity << " movers." << std::endl; + + float lowest_distance = 999999.f; + uintptr_t closest = 0; + flyff::MoverID closest_hash = 0; + + auto current = map.first; + do { + const auto& current_ = fugg::module_ref(current); + const auto& mover = fugg::module_ref(current_.mover); + + auto dx = mover.position.x - player.position.x; + auto dz = mover.position.z - player.position.z; + + auto squared = (dx * dx) + (dz * dz); + auto d = std::sqrt(squared); + + + if(mover.type == ObjectType::Mover && + current_.hash != player_object_id && + !mover.is_dead() && + d < lowest_distance) { + + closest = current_.mover; + closest_hash = current_.hash; + lowest_distance = d; + } + + current = current_.next; + } while(current != 0); + + if(closest != 0) { + const auto& closest_ = fugg::module_ref(closest); + + std::cout << closest_.name << " (of type " << closest_.type << ") is closest to the player." << std::endl; + + set_target(closest_hash); + interact_target(1); + } else { + std::cout << "There is no one close" << std::endl; + } - write_chat_message("Hahaha dikke vette moeders"); } }