144 lines
12 KiB
C++
144 lines
12 KiB
C++
#pragma once
|
|
#include "../src/modules/qol_modules.h"
|
|
#include "../src/config/profiles.h"
|
|
|
|
inline void test_qol_readers() {
|
|
auto put=[](void* p,size_t offset,auto value){memcpy(static_cast<unsigned char*>(p)+offset,&value,sizeof(value));};
|
|
unsigned char type2[]{0xb0,2,0xc3},type3[]{0xb0,3,0xc3},type9[]{0xb0,9,0xc3},type10[]{0xb0,10,0xc3};
|
|
uintptr_t vt2[6]{},vt3[6]{},vt9[6]{},vt10[6]{};
|
|
vt2[5]=uintptr_t(type2);vt3[5]=uintptr_t(type3);vt9[5]=uintptr_t(type9);vt10[5]=uintptr_t(type10);
|
|
struct node {uintptr_t left=0,parent=0,right=0;uint64_t flags=0;std::string key;unsigned char value[96]{};};
|
|
static_assert(offsetof(node,key)==32 && offsetof(node,value)==64);
|
|
struct compound {uintptr_t vt=0,head=0;size_t count=0;};
|
|
node head,damage,ench,ench_head,id,lvl;
|
|
compound tags{uintptr_t(vt10),uintptr_t(&head),2},enchantment{uintptr_t(vt10),uintptr_t(&ench_head),2};
|
|
head.parent=uintptr_t(&damage);damage.key="Damage";damage.left=uintptr_t(&head);damage.right=uintptr_t(&ench);
|
|
ench.key="ench";ench.left=ench.right=uintptr_t(&head);
|
|
put(damage.value,0,uintptr_t(vt3));put(damage.value,8,275);
|
|
ench_head.parent=uintptr_t(&id);id.key="id";id.left=uintptr_t(&ench_head);id.right=uintptr_t(&lvl);
|
|
lvl.key="lvl";lvl.left=lvl.right=uintptr_t(&ench_head);
|
|
put(id.value,0,uintptr_t(vt2));put(id.value,8,int16_t(17));put(lvl.value,0,uintptr_t(vt2));put(lvl.value,8,int16_t(3));
|
|
uintptr_t entry=uintptr_t(&enchantment);put(ench.value,0,uintptr_t(vt9));put(ench.value,8,uintptr_t(&entry));put(ench.value,16,uintptr_t(&entry+1));
|
|
unsigned char item[0x240]{},stack[152]{},max_getter[]{0x0f,0xb7,0x81,0x50,1,0,0,0xc3},attack_getter[]{0x8b,0x81,0x28,2,0,0,0xc3};
|
|
uintptr_t item_vt[38]{},counter=uintptr_t(item);item_vt[36]=uintptr_t(max_getter);item_vt[37]=uintptr_t(attack_getter);
|
|
put(item,0,uintptr_t(item_vt));put(item,0x150,uint16_t(1561));put(item,0x228,5);
|
|
const char* name="diamond_pickaxe";memcpy(item+0xd8,name,strlen(name));put(item,0xe8,uint64_t(strlen(name)));put(item,0xf0,uint64_t(15));
|
|
put(stack,8,uintptr_t(&counter));put(stack,16,uintptr_t(&tags));put(stack,0x22,uint8_t(1));
|
|
auto value=world::read_item(uintptr_t(stack),true);
|
|
assert(value.name==name && value.durability_known && value.damage==275 && value.max_damage==1561);
|
|
assert(value.attack_known && value.attack_bonus==5 && value.enchantments.size()==1 && value.enchantments[0].id==17 && value.enchantments[0].level==3);
|
|
put(damage.value,8,1600);assert(!world::read_item(uintptr_t(stack),true).durability_known);put(damage.value,8,275);
|
|
tags.count=129;assert(!world::read_item(uintptr_t(stack),true).durability_known);tags.count=2;
|
|
put(ench.value,16,uintptr_t(&entry)+513);assert(world::read_item(uintptr_t(stack),true).enchantments.empty());
|
|
assert(!world::read_item(uintptr_t(stack),false).durability_known);
|
|
unsigned char effect_data[144*3]{};uintptr_t effects[]{uintptr_t(effect_data),uintptr_t(effect_data+sizeof(effect_data)),uintptr_t(effect_data+sizeof(effect_data))};
|
|
put(effect_data,144,1);put(effect_data,144+4,1200);put(effect_data,144+0x10,14);put(effect_data,144+0x20,0);
|
|
put(effect_data,288,19);put(effect_data,288+4,60);put(effect_data,288+0x20,1);
|
|
std::vector<world::effect> active;assert(world::read_effects(uintptr_t(effects),active) && active.size()==2 && active[0].amplifier==0 && active[1].ticks==60);
|
|
put(effect_data,144+4,-1);assert(world::read_effects(uintptr_t(effects),active) && active[0].ticks==-1);
|
|
put(effect_data,144+0x20,256);assert(!world::read_effects(uintptr_t(effects),active));
|
|
effects[1]++;assert(!world::read_effects(uintptr_t(effects),active));
|
|
std::cout<<"PASS: native item Damage/enchantment tags, verified durability/attack getters and indexed effect timers\n";
|
|
}
|
|
|
|
inline void test_qol_state() {
|
|
qol::waypoint p{"home \"base\"","realm",{123,64,-256},0,false},restored;
|
|
assert(qol::decode(qol::encode(p),restored) && restored.name==p.name && restored.position.z==-256);
|
|
assert(!qol::decode("broken",restored));p.position.x=std::numeric_limits<float>::infinity();assert(!qol::decode(qol::encode(p),restored));
|
|
assert(qol::bearing({},{0,0,10})==0 && std::abs(qol::bearing({},{10,0,0})+90)<.01f);
|
|
world::frame f;f.valid=true;f.stamp=GetTickCount64();f.world_id=1;f.local.health_known=true;f.local.health=20;
|
|
f.xp_known=true;f.xp_level=1;f.xp_progress=0;
|
|
qol::session stats;assert(!stats.update(f,1));f.local.feet={3,0,4};f.xp_progress=.5f;
|
|
stats.update(f,1.5);assert(std::abs(stats.distance-5)<.01 && stats.seconds==.5 && stats.xp==4.5);
|
|
f.local.feet={1000,0,0};stats.update(f,1.6);assert(std::abs(stats.distance-5)<.01);
|
|
f.local.health=0;assert(stats.update(f,1.7) && stats.deaths==1);assert(!stats.update(f,1.8) && stats.deaths==1);
|
|
f.local.health=20;stats.update(f,1.9);f.local.health=0;assert(stats.update(f,2) && stats.deaths==2);
|
|
f.world_id=2;stats.update(f,2.1);assert(stats.deaths==2);
|
|
const double previous_xp=stats.xp;f.local.id=2;f.xp_level=100;stats.update(f,2.2);assert(stats.xp==previous_xp);
|
|
assert(qol::total_xp(16,0)==352 && qol::total_xp(17,0)==394 && qol::total_xp(31,0)==1507 && qol::total_xp(32,0)==1628);
|
|
assert(qol::clock_text(65)=="1:05" && qol::clock_text(3661)=="1:01:01");
|
|
module_manager manager;auto* points=manager.add<waypoints_module>();const auto defaults=config::capture(manager);
|
|
const auto saved=qol::encode({"realm home","my world",{10,64,20},0,false});
|
|
for(auto& setting:points->settings())if(setting.name=="saved waypoint 1")setting.text_value=saved;
|
|
config::snapshot loaded;assert(config::decode(config::encode(config::capture(manager)),loaded));
|
|
for(auto& setting:points->settings())if(setting.name=="saved waypoint 1")setting.text_value.clear();
|
|
config::apply(manager,defaults,loaded);
|
|
for(auto& setting:points->settings())if(setting.name=="saved waypoint 1")assert(setting.hidden && setting.text_value==saved);
|
|
qol_events::particle_categories=1;qol_events::density=0;assert(qol_events::suppress_particle("minecraft:portal_directional"));
|
|
assert(!qol_events::suppress_particle("minecraft:critical_hit_emitter"));
|
|
qol_events::particle_categories=0x3f;qol_events::density=50;qol_events::sequence=0;int dropped=0;
|
|
for(int i=0;i<100;++i)dropped+=qol_events::suppress_particle("minecraft:rain_splash");assert(dropped==50);
|
|
qol_events::density=100;assert(!qol_events::suppress_particle("minecraft:portal_directional"));
|
|
std::cout<<"PASS: waypoint round-trip, bearings, death latching, teleport rejection, session XP and particle sampling\n";
|
|
}
|
|
|
|
inline setting& qol_setting(module& m,const char* name) {
|
|
for(auto& s:m.settings())if(s.name==name)return s;
|
|
assert(false);return m.settings().front();
|
|
}
|
|
inline void test_qol_event_forwarding() {
|
|
auto put=[](void* p,size_t offset,auto value){memcpy(static_cast<unsigned char*>(p)+offset,&value,sizeof(value));};
|
|
const auto old_sound=qol_events::original_sound,old_short=qol_events::original_short_sound;const auto old_particle=qol_events::original_particle;
|
|
world::frame f;f.valid=true;f.stamp=GetTickCount64();f.world_id=17;world::publish(f);
|
|
unsigned char object[0x128]{};const char* name="zombie.hurt";
|
|
memcpy(object+0x20,name,strlen(name));put(object,0x30,uint64_t(strlen(name)));put(object,0x38,uint64_t(15));
|
|
put(object,0x100,world::vec3{12,64,20});put(object,0x11c,uint8_t(1));
|
|
qol_events::original_sound=+[](uintptr_t self,float dt) {
|
|
assert(dt==.125f);world::write(self+0x88,uintptr_t(12345));world::write(self+0xa8,3);
|
|
};
|
|
qol_events::sounds_enabled=true;qol_events::pending.clear();
|
|
qol_events::sound_detour(uintptr_t(object),.125f);
|
|
assert(qol_events::pending.size()==1 && qol_events::pending[0].name==name && qol_events::pending[0].position.x==12);
|
|
qol_events::sound_detour(uintptr_t(object),.125f);assert(qol_events::pending.size()==1);
|
|
put(object,0x88,uintptr_t(0));put(object,0x11c,uint8_t(0));qol_events::sound_detour(uintptr_t(object),.125f);assert(qol_events::pending.size()==1);
|
|
qol_events::pending.clear();put(object,0x88,uintptr_t(0));put(object,0xbc,uint8_t(1));put(object,0xa8,world::vec3{5,64,8});
|
|
qol_events::original_short_sound=+[](uintptr_t self,float dt) {
|
|
assert(dt==.125f);world::write(self+0x88,uintptr_t(23456));world::write(self+0xcc,1);
|
|
};
|
|
qol_events::short_sound_detour(uintptr_t(object),.125f);assert(qol_events::pending.size()==1 && qol_events::pending[0].position.x==5);
|
|
qol_events::short_sound_detour(uintptr_t(object),.125f);assert(qol_events::pending.size()==1);
|
|
qol_events::sounds_enabled=false;qol_events::pending.clear();
|
|
struct hashed {uint64_t hash=0;std::string text;};hashed particle;particle.text="minecraft:portal_directional";
|
|
uintptr_t output[]{111,222};
|
|
qol_events::original_particle=+[](uintptr_t cache,uintptr_t out,uintptr_t id) {
|
|
assert(cache==123 && id);world::write(out,std::array<uintptr_t,2>{11,22});return out;
|
|
};
|
|
qol_events::particles_enabled=true;qol_events::particle_categories=1;qol_events::density=0;
|
|
assert(qol_events::particle_detour(123,uintptr_t(output),uintptr_t(&particle))==uintptr_t(output) && output[0]==0 && output[1]==0);
|
|
qol_events::particles_enabled=false;qol_events::particle_detour(123,uintptr_t(output),uintptr_t(&particle));assert(output[0]==11 && output[1]==22);
|
|
performance::particles=true;performance::keep=0;
|
|
qol_events::particle_detour(123,uintptr_t(output),uintptr_t(&particle));assert(output[0]==0 && output[1]==0);
|
|
particle.text="minecraft:critical_hit_emitter";performance::protect_combat=true;
|
|
qol_events::particle_detour(123,uintptr_t(output),uintptr_t(&particle));assert(output[0]==11 && output[1]==22);
|
|
// Independent Particle Controls still applies its own selected categories.
|
|
qol_events::particles_enabled=true;qol_events::particle_categories=1u<<2;qol_events::density=0;
|
|
qol_events::particle_detour(123,uintptr_t(output),uintptr_t(&particle));assert(output[0]==0 && output[1]==0);
|
|
qol_events::particles_enabled=false;performance::reset();
|
|
qol_events::original_sound=old_sound;qol_events::original_short_sound=old_short;qol_events::original_particle=old_particle;world::publish({});
|
|
std::cout<<"PASS: native sound forwarding/start deduplication and particle empty-handle/pass-through paths\n";
|
|
}
|
|
inline void test_qol_modules() {
|
|
ImGui::CreateContext();auto& io=ImGui::GetIO();io.DisplaySize={1280,900};io.DeltaTime=.016f;
|
|
io.Fonts->AddFontDefault();unsigned char* pixels;int w,h;io.Fonts->GetTexDataAsRGBA32(&pixels,&w,&h);
|
|
world::frame f;f.valid=true;f.stamp=GetTickCount64();f.world_id=1;f.dimension=0;f.local.feet={10,64,20};f.local.health_known=true;f.local.health=20;
|
|
f.matrix[0]=f.matrix[5]=f.matrix[15]=1;f.matrix[10]=-1;f.xp_known=true;f.xp_level=28;f.xp_progress=.3f;
|
|
f.effects_known=true;f.effects={{1,1200,0},{19,80,1}};
|
|
f.local.held.name="diamond_axe";f.local.held.damage=1500;f.local.held.max_damage=1561;f.local.held.durability_known=true;f.local.held.enchantments={{17,3},{26,1}};
|
|
world::publish(f);const bool was_ready=world::ready;world::ready=true;
|
|
waypoints_module points;compass_hud compass(points);session_stats stats;durability_alerts alerts;tool_info tool;status_effects_hud effects;sound_indicators sounds;
|
|
points.set_enabled(true);tool.set_enabled(true);alerts.set_enabled(true);effects.set_enabled(true);stats.set_enabled(true);
|
|
assert(world::collect_item_details==2 && world::collect_effects==1 && world::extra_xp_readers==1);
|
|
qol_setting(points,"save current location").action();assert(points.points(f).size()==1);
|
|
f.dimension=1;assert(points.points(f).empty());f.dimension=0;
|
|
g_menu_open=true;ImGui::NewFrame();
|
|
module* hud_modules[]{&points,&compass,&stats,&alerts,&tool,&effects,&sounds};
|
|
for(module* m:hud_modules)m->on_render();
|
|
const auto notification_count=notifications::items.size();alerts.on_render();assert(notifications::items.size()==notification_count);
|
|
ImGui::Render();auto* data=ImGui::GetDrawData();assert(data->TotalVtxCount>100);
|
|
for(int i=0;i<data->CmdListsCount;++i)for(const auto& v:data->CmdLists[i]->VtxBuffer)assert(std::isfinite(v.pos.x) && std::isfinite(v.pos.y));
|
|
points.set_enabled(false);tool.set_enabled(false);alerts.set_enabled(false);effects.set_enabled(false);stats.set_enabled(false);
|
|
assert(world::collect_item_details==0 && world::collect_effects==0 && world::extra_xp_readers==0);
|
|
world::ready=was_ready;g_menu_open=false;world::publish({});notifications::items.clear();ImGui::DestroyContext();
|
|
std::cout<<"PASS: new HUD geometry, waypoint actions/dimension filtering, alerts and shared-reader lifetime\n";
|
|
}
|