#pragma once #include "../src/modules/world_modules.h" #include "../src/modules/fps_counter.h" #include "../src/modules/keystrokes.h" #include "../src/modules/watermark.h" #include "../src/modules/cps_counter.h" #include "../src/modules/clock.h" #include "../src/modules/zoom.h" #include "../src/modules/anti_afk.h" inline float world_test_time(void*,int ticks,float alpha){return float(ticks)+alpha;} inline world::color* world_test_fog(void*,world::color* output,const world::color* base,float brightness){*output=*base;output->r*=brightness;return output;} inline const std::string* world_test_name(uintptr_t){static const std::string real="Original";return ℜ} inline void test_world_math_and_hooks() { using namespace world; float matrix[16]={1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1};ImVec2 screen; assert(project(matrix,{0,0,0},{0,0,-5},1,1,{800,600},screen));assert(screen.x==400 && screen.y==300); assert(!project(matrix,{0,0,0},{0,0,5},1,1,{800,600},screen)); assert(!project(matrix,{0,0,0},{0,0,0},1,1,{800,600},screen)); ImVec2 end;assert(project_edge(matrix,{0,0,0},{0,0,1},{0,0,-5},1,1,{800,600},screen,end)); assert(!project_edge(matrix,{0,0,0},{0,0,1},{0,0,2},1,1,{800,600},screen,end)); const auto q=turn({},90,20);assert(std::abs(q.x*q.x+q.y*q.y+q.z*q.z+q.w*q.w-1)<1e-5f); const auto original=quaternion{};const auto restored=turn(turn(original,90,0),-90,0);assert(std::abs(restored.w-1)<1e-5f); // Orbit position follows camera orientation around a fixed player pivot. const vec3 pivot{12,65,-8};const auto back=orbit_position(pivot,{},4); assert(distance(back,pivot)==4 && back.z==-4 && back.x==12); const auto side=orbit_position(pivot,turn({},90,0),4); assert(std::abs(distance(side,pivot)-4)<1e-5f && std::abs(side.x-8)<1e-5f); const auto front=orbit_position(pivot,turn({},180,0),4); assert(std::abs(front.z+12)<1e-5f && std::abs(front.x-12)<1e-5f); const auto full=orbit_position(pivot,turn({},360,0),4);assert(distance(full,back)<1e-5f); const auto overhead=orbit_position(pivot,turn({},90,85),6);assert(std::abs(distance(overhead,pivot)-6)<1e-5f); assert(pivot.x==12 && pivot.y==65 && pivot.z==-8); // Player angle locking is independent of movement and camera orbit rotation. player_look_lock angle_lock;std::array player_rotation{15,70,14,69}; std::array head_angle{70,69},body_angle{65,64},render_angle{15,70};vec3 moving_player{2,3,4}; auto apply_lock=[&](bool active,uintptr_t owner=1){return angle_lock.apply(owner,7,uintptr_t(&player_rotation),uintptr_t(&head_angle),uintptr_t(&body_angle),uintptr_t(&render_angle),active);}; assert(apply_lock(true)); player_rotation={80,-120,79,-119};head_angle={-120,-119};body_angle={-100,-99};render_angle={80,-120};moving_player.x+=5; assert(apply_lock(true) && player_rotation[0]==15 && player_rotation[1]==70 && head_angle[0]==70 && body_angle[0]==65 && render_angle[1]==70); assert(angle_lock.delta[0]==65 && angle_lock.delta[1]==170); assert(apply_lock(true) && angle_lock.delta[0]==0 && angle_lock.delta[1]==0); player_rotation={80,-120,79,-119};assert(apply_lock(true)); assert(angle_lock.delta[0]==0 && angle_lock.delta[1]==0); // cached target, mouse stopped player_rotation={85,-110,84,-111};assert(apply_lock(true)); assert(angle_lock.delta[0]==5 && angle_lock.delta[1]==10); // new mouse movement only assert(moving_player.x==7 && moving_player.y==3 && moving_player.z==4); const auto camera_side=orbit_position(moving_player,turn({},120,0),4);assert(std::abs(distance(camera_side,moving_player)-4)<1e-5f); assert(!apply_lock(false));player_rotation={20,90,20,90};assert(!apply_lock(false) && player_rotation[1]==90); assert(apply_lock(true) && angle_lock.rotation[1]==90); player_rotation={25,100,25,100};assert(apply_lock(true,2) && angle_lock.rotation[1]==100); assert(weapon("diamond_sword") && weapon("crossbow") && weapon("netherite_axe") && !weapon("diamond_pickaxe") && !weapon("bread")); assert(clean_name("\xc2\xa7" "aPlayer\n")=="Player"); assert(item_label("minecraft:diamond_helmet")=="diamond helmet"); auto old_time=original_time;original_time=&world_test_time;render_thread=GetCurrentThreadId();time_override=6000; assert(time_detour(nullptr,18000,.5f)==6000.5f);time_override=-1;assert(time_detour(nullptr,18000,.5f)==18000.5f); time_override=6000;render_thread=0;assert(time_detour(nullptr,18000,.5f)==18000.5f);time_override=-1;original_time=old_time; auto old_fog=original_fog;original_fog=&world_test_fog;render_thread=GetCurrentThreadId();fog_enabled=true;fog_color=IM_COL32(255,0,0,255); color input{.25f,.5f,.75f,1},result{};fog_detour(nullptr,&result,&input,1);assert(result.r==1 && result.g==0 && result.b==0 && result.a==1); fog_enabled=false;fog_detour(nullptr,&result,&input,1);assert(result.r==input.r && result.g==input.g);original_fog=old_fog; auto old_name=original_name;original_name=&world_test_name;local_actor=123;alias_enabled=true;set_alias("My local name");rendering=true; assert(*name_detour(123)=="My local name");rendering=false;assert(*name_detour(123)=="Original");assert(*world_test_name(123)=="Original"); alias_enabled=false;original_name=old_name;local_actor=0; // Real native get_at ABI using a controlled executable leaf with the // verified payload-load prefix, sparse versions and packed membership. const unsigned char bytes[]={0x48,0x8b,0x49,0x50,0x49,0x89,0xd0,0x49,0xc1,0xe8,0x07,0x83,0xe2,0x7f,0x8d,0x04,0xd5,0,0,0,0,0x4a,0x03,0x04,0xc1,0xc3}; auto* code=VirtualAlloc(nullptr,4096,MEM_COMMIT|MEM_RESERVE,PAGE_READWRITE);assert(code);memcpy(code,bytes,sizeof(bytes));DWORD old; assert(VirtualProtect(code,4096,PAGE_EXECUTE_READ,&old));FlushInstructionCache(GetCurrentProcess(),code,sizeof(bytes)); uintptr_t vt[]={reinterpret_cast(code)};uint32_t sparse[2048];std::fill(sparse,sparse+2048,0xffffffffu); uint32_t packed[]={0x40003};sparse[3]=0x40000;uintptr_t pages[]={reinterpret_cast(sparse)}; uintptr_t payload[128]{};payload[0]=0x12345678;uintptr_t payload_pages[]={reinterpret_cast(payload)}; uintptr_t storage[16]{};storage[0]=reinterpret_cast(vt);storage[1]=reinterpret_cast(pages);storage[2]=storage[1]+8; storage[4]=reinterpret_cast(packed);storage[5]=storage[4]+4;storage[10]=reinterpret_cast(payload_pages); assert(component_at(reinterpret_cast(storage),0x40003)==reinterpret_cast(payload)); assert(!component_at(reinterpret_cast(storage),3));assert(!component_at(reinterpret_cast(storage),0x40004)); assert(!component_at(0,0x40003));assert(!component_at(1,0x40003)); // ActorRotation's real 16-byte getter has an index-copy prefix. const unsigned char rotation_bytes[]={0x48,0x89,0xd0,0x48,0x8b,0x49,0x50,0x48,0xc1,0xea,0x07,0x83,0xe0,0x7f,0xc1,0xe0,0x04,0x48,0x03,0x04,0xd1,0xc3}; assert(VirtualProtect(code,4096,PAGE_READWRITE,&old));memcpy(code,rotation_bytes,sizeof(rotation_bytes)); assert(VirtualProtect(code,4096,PAGE_EXECUTE_READ,&old));FlushInstructionCache(GetCurrentProcess(),code,sizeof(rotation_bytes)); assert(component_at(reinterpret_cast(storage),0x40003)==reinterpret_cast(payload)); assert(!component_at(reinterpret_cast(storage),0x80003)); assert(VirtualFree(code,0,MEM_RELEASE)); std::cout<<"PASS: projection, freelook quaternion, weapon filtering, visual time/fog/name isolation and native ECS read-only access\n"; } inline void test_world_filter() { using namespace world_filter; ComPtr device;ComPtr context;D3D_FEATURE_LEVEL level; assert(SUCCEEDED(D3D11CreateDevice(nullptr,D3D_DRIVER_TYPE_WARP,nullptr,0,nullptr,0,D3D11_SDK_VERSION,&device,&level,&context))); D3D11_TEXTURE2D_DESC desc{};desc.Width=32;desc.Height=32;desc.MipLevels=1;desc.ArraySize=1;desc.Format=DXGI_FORMAT_R8G8B8A8_UNORM; desc.SampleDesc.Count=1;desc.Usage=D3D11_USAGE_DEFAULT;desc.BindFlags=D3D11_BIND_RENDER_TARGET; ComPtr output;ComPtr target; assert(SUCCEEDED(device->CreateTexture2D(&desc,nullptr,&output)));assert(SUCCEEDED(device->CreateRenderTargetView(output.Get(),nullptr,&target))); ID3D11RenderTargetView* rt=target.Get();context->OMSetRenderTargets(1,&rt,nullptr); const float white[4]={1,1,1,1};context->ClearRenderTargetView(rt,white); context->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_LINELIST); D3D11_VIEWPORT viewport{2,3,20,18,0,1};context->RSSetViewports(1,&viewport); enabled=true;tint=IM_COL32(255,128,64,255);brightness=.5f; assert(apply(device.Get(),context.Get(),rt)); D3D11_PRIMITIVE_TOPOLOGY topology;context->IAGetPrimitiveTopology(&topology);assert(topology==D3D11_PRIMITIVE_TOPOLOGY_LINELIST); UINT count=1;D3D11_VIEWPORT restored{};context->RSGetViewports(&count,&restored);assert(restored.TopLeftX==2 && restored.Height==18); desc.Usage=D3D11_USAGE_STAGING;desc.BindFlags=0;desc.CPUAccessFlags=D3D11_CPU_ACCESS_READ;ComPtr staging; assert(SUCCEEDED(device->CreateTexture2D(&desc,nullptr,&staging)));context->CopyResource(staging.Get(),output.Get()); D3D11_MAPPED_SUBRESOURCE mapped{};assert(SUCCEEDED(context->Map(staging.Get(),0,D3D11_MAP_READ,0,&mapped))); auto* pixel=static_cast(mapped.pData)+16*mapped.RowPitch+16*4; assert(std::abs(int(pixel[0])-128)<=1 && std::abs(int(pixel[1])-64)<=1 && std::abs(int(pixel[2])-32)<=1 && pixel[3]==255); context->Unmap(staging.Get(),0);enabled=false;assert(!apply(device.Get(),context.Get(),rt));shutdown(); std::cout<<"PASS: actual D3D11 color/darkness shader and render-state restoration (WARP)\n"; } inline void test_world_huds() { ImGui::CreateContext();auto& io=ImGui::GetIO();io.DisplaySize={1280,720};io.DeltaTime=.016f; io.Fonts->AddFontDefault();unsigned char* pixels;int width,height;io.Fonts->GetTexDataAsRGBA32(&pixels,&width,&height); ImGui::NewFrame(); world::frame frame;frame.valid=true;frame.stamp=GetTickCount64();frame.world_id=1;frame.has_block=true;frame.block={-1,-1,-5}; frame.matrix[0]=frame.matrix[5]=frame.matrix[10]=frame.matrix[15]=1; frame.local.position={0,1.62f,0};frame.local.held.name="diamond_sword"; for(int i=0;i<4;++i)frame.local.armor[i].name="diamond_helmet"; frame.has_target=true;frame.target.name="Actual player";frame.target.position={0,0,-5};frame.target.head={0,1,-5}; frame.target.health=12;frame.target.max_health=20;frame.target.health_known=true;frame.players.push_back(frame.target); world::publish(frame); fps_counter fps;watermark logo;keystrokes keys;cps_counter cps;clock_hud clock; armor_hud armor;target_hud target;coordinates_hud coordinates;block_outlines outline;better_nametags tags; module* hud_modules[]={&fps,&logo,&keys,&cps,&clock,&armor,&target,&coordinates,&outline,&tags}; for(auto* m:hud_modules)m->on_render(); anti_afk afk;afk.on_render();assert(afk.hud_size().x>0);afk.on_disable(); block_outlines::draw_selection(frame,frame.block,IM_COL32_WHITE,2,true); assert(armor.hud_size().y>0 && target.hud_size().y>0); const float compact_height=target.hud_size().y; for(auto& setting:target.settings()) if(setting.name=="equipment")setting.bool_value=true; target.on_render();assert(target.hud_size().y>compact_height); // Unknown/zero maximum health must never produce invalid geometry. frame.target.max_health=0;world::publish(frame);target.on_render(); frame.target.health_known=false;world::publish(frame);target.on_render(); zoom magnifier;zoom_effect::magnification=4; g_menu_open=true;magnifier.on_render();assert(zoom_effect::magnification==1); g_menu_open=false;zoom_effect::magnification=4; magnifier.on_disable();assert(zoom_effect::magnification==1); ImGui::Render();auto* data=ImGui::GetDrawData();assert(data->TotalVtxCount>100); for(int i=0;iCmdListsCount;++i)for(const auto& v:data->CmdLists[i]->VtxBuffer)assert(std::isfinite(v.pos.x) && std::isfinite(v.pos.y)); world::publish({});ImGui::DestroyContext(); std::cout<<"PASS: actual HUD/card, armor, target, coordinates, nametag and outlined-block geometry\n"; }