First kills made by bot only :D

This commit is contained in:
Knaapchen 2022-10-10 00:45:29 +02:00
parent afdd6589a7
commit dce2ca08f3
4 changed files with 221 additions and 58 deletions

View File

@ -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;
}
};
};

View File

@ -10,4 +10,21 @@ enum class ObjectType : int {
Region = 6 /* Region (event, attribute) */,
Ship = 7,
Path = 8
};
};
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;
}

View File

@ -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<std::string*>(&copy);
}

View File

@ -3,11 +3,36 @@
#include <flyff.h>
#include <iostream>
#include <sstream>
namespace fugg
{
}
constexpr const uint32_t hash_to_id(const uint32_t hashed) {
constexpr uint32_t header_hash = 0x644ab400;
return hashed ^ header_hash;
}
template<typename T>
void packet_push(std::vector<uint8_t>& packet, const T& value, std::vector<uint8_t>::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<typename T>
void packet_push(std::vector<uint8_t>& 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<fugg::detail::RawBasicString>();
auto id_ = std::make_unique<fugg::String>(id);
@ -41,7 +66,12 @@ void show_message(const std::string& message, const flyff::Color& color) {
);
}
void send_packet(std::vector<uint8_t> payload) {
void send_packet(const uint32_t& id, std::vector<uint8_t> 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<uint8_t> payload) {
);
}
void send_logout() {
send_packet(0x403, {});
}
#include <unordered_set>
#include <unordered_map>
#include <vector>
@ -77,72 +111,89 @@ void send_packet(std::vector<uint8_t> payload) {
#include <cstddef>
template<typename T>
void packet_push(std::vector<uint8_t>& 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<uint8_t> packet;
// Not sure yet about these
packet.insert(packet.end(), { 0x01, 0x94 });
packet.insert(packet.end(), { 0x4a, 0x64 });
packet_push<uint32_t>(packet, from_slot);
packet_push<uint32_t>(packet, to_slot);
send_packet(packet);
send_packet(0x2001, packet);
}
void use_item_in_inventory(const uint32_t& slot) {
std::vector<uint8_t> packet;
// Not sure yet
packet.insert(packet.end(), { 0x10, 0xb0 });
// Same as move_item_in_inventory
packet.insert(packet.end(), { 0x4a, 0x64 });
packet_push<uint32_t>(packet, slot);
// Unknown yet
packet_push<uint32_t>(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<uintptr_t>(0x0003546c);
if(player_pointer == 0)
return;
auto& player = fugg::module_ref<flyff::Mover>(player_pointer);
std::vector<uint8_t> 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<flyff::Vector3>(packet, player.position);
packet_push<uint8_t>(packet, action);
packet_push<uint8_t>(packet, param_flags);
packet_push(packet, player.server_tick);
if(param0 != 0) packet_push<unsigned long long>(packet, param0);
if(param1 != 0) packet_push<unsigned long long>(packet, param1);
if(param2 != 0) packet_push<unsigned long long>(packet, param2);
if(param3 != 0) packet_push<unsigned long long>(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<uint8_t> packet;
packet.push_back(0x04);
packet.push_back(0xb0);
// Same as move_item_in_inventory
packet.insert(packet.end(), { 0x4a, 0x64 });
packet_push<float>(packet, x);
packet_push<float>(packet, y);
packet_push<float>(packet, z);
// ...
// send_packet(packet);
send_motion_packet(
0,
*reinterpret_cast<const MotionParam*>(&x),
*reinterpret_cast<const MotionParam*>(&y),
*reinterpret_cast<const MotionParam*>(&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<uint8_t> 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<uint32_t>(packet, message.length());
// Write message
@ -154,26 +205,108 @@ void write_chat_message(const std::string& message) {
// Unknown 2
packet_push<uint32_t>(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<uintptr_t>(0x0003546c);
if(player_pointer == 0)
return;
const auto& player = fugg::module_ref<flyff::Mover>(player_pointer);
const auto& player_object_id = fugg::module_ref<flyff::MoverID>(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<MoverHolderMap>(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<MoverHolder>(current);
const auto& mover = fugg::module_ref<flyff::Mover>(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<flyff::Mover>(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");
}
}