From 1f3f1ab2a20c6d90189cf1fd03cfbb08077bc02e Mon Sep 17 00:00:00 2001 From: navewindre Date: Thu, 30 Aug 2018 22:58:37 +0200 Subject: dsad --- internal_rewrite/autowall.cpp | 16 +- internal_rewrite/c_base_player.cpp | 38 ++- internal_rewrite/c_base_player.hpp | 2 + internal_rewrite/detours.cpp | 292 +++++++++++++++++ internal_rewrite/detours.h | 164 ++++++++++ internal_rewrite/factory.hpp | 2 +- internal_rewrite/hde32.cpp | 377 ++++++++++++++++++++++ internal_rewrite/hde32.h | 109 +++++++ internal_rewrite/hooks.cpp | 5 + internal_rewrite/internal_rewrite.vcxproj | 5 + internal_rewrite/internal_rewrite.vcxproj.filters | 15 + internal_rewrite/prediction.cpp | 1 + internal_rewrite/ragebot.cpp | 2 +- internal_rewrite/settings.hpp | 1 - internal_rewrite/table32.h | 73 +++++ internal_rewrite/ui.h | 1 - internal_rewrite/visual_local.cpp | 9 + 17 files changed, 1096 insertions(+), 16 deletions(-) create mode 100644 internal_rewrite/detours.cpp create mode 100644 internal_rewrite/detours.h create mode 100644 internal_rewrite/hde32.cpp create mode 100644 internal_rewrite/hde32.h create mode 100644 internal_rewrite/table32.h diff --git a/internal_rewrite/autowall.cpp b/internal_rewrite/autowall.cpp index d402ee1..72236cd 100644 --- a/internal_rewrite/autowall.cpp +++ b/internal_rewrite/autowall.cpp @@ -92,16 +92,16 @@ namespace features CTraceFilter filter; Ray_t ray, ray_2; + float step = 4.f; + if( g_settings.rage.preserve_fps( ) && util::is_low_fps( ) ) + step = 8.f; + while( dist <= 90.f ) { // This may seem retarded to you, but it will help frame-rate a lot // and the accuracy loss is almost negligible. You can remove this if // you want to. - if ( !util::is_low_fps( ) && g_settings.rage.autowall_fps( ) ) { - dist += 4.f; - } - else { - dist += 8.0f; - } + + dist += step; out_end = start + dir * dist; @@ -110,7 +110,7 @@ namespace features if( contents & MASK_SHOT_HULL && !( contents & CONTENTS_HITBOX ) ) continue; - ray.Init( out_end, out_end - dir * 4.f ); + ray.Init( out_end, out_end - dir * step ); g_csgo.m_trace( )->TraceRay( ray, MASK_SHOT_HULL | CONTENTS_HITBOX, 0, exit_trace ); if( exit_trace->startsolid && exit_trace->surface.flags & SURF_HITBOX ) { @@ -135,7 +135,7 @@ namespace features else if( ( ( exit_trace->surface.flags >> 7 ) & 1 ) && !( ( tr.surface.flags >> 7 ) & 1 ) ) continue; else if( exit_trace->plane.normal.dot( dir ) <= 1.0f ) { - auto fraction = exit_trace->fraction * 4.0f; + auto fraction = exit_trace->fraction * step; out_end = out_end - dir * fraction; return true; diff --git a/internal_rewrite/c_base_player.cpp b/internal_rewrite/c_base_player.cpp index 0cc95aa..5274f63 100644 --- a/internal_rewrite/c_base_player.cpp +++ b/internal_rewrite/c_base_player.cpp @@ -675,6 +675,31 @@ void c_base_player::calc_abs_velocity( ) { } } +void c_base_player::fix_jump_fall( bool reset ) { + if( reset ) + return; + + int prev_flags = get_animdata( ).m_prev_flags; + int flags = m_fFlags( ); + + if( ( prev_flags & FL_ONGROUND ) && ( flags & FL_ONGROUND ) ) { + flags |= FL_ONGROUND; + } + else { + auto layer_weight = m_AnimOverlay( ).GetElements( )[ 4 ].m_flWeight; + auto last_weight = get_animdata( ).m_last_layers.at( 4 ).m_flWeight; + + if( layer_weight != 1.f && last_weight == 1.f && + m_AnimOverlay( ).GetElements( )[ 5 ].m_flWeight != 0.f ) + flags |= FL_ONGROUND; + + if( ( flags & FL_ONGROUND ) && !( prev_flags & FL_ONGROUND ) ) + flags &= ~FL_ONGROUND; + } + + m_fFlags( ) = flags; +} + void c_base_player::fix_animations( bool reset, bool resolver_change ) { //todo: legs dont match up when fakelagging <- not anymore int idx = ce( )->GetIndex( ); @@ -732,6 +757,7 @@ void c_base_player::fix_animations( bool reset, bool resolver_change ) { set_abs_origin( m_vecOrigin( ) ); //networked duck amount comes from the last simulation tick instead of the current one calculate_duckamount( reset ); + fix_jump_fall( reset ); validate_animation_layers( ); float old_cycle = m_AnimOverlay( ).GetElements( )[ 6 ].m_flCycle; @@ -751,8 +777,16 @@ void c_base_player::fix_animations( bool reset, bool resolver_change ) { } sm_animdata[ idx ].m_last_duck = m_flDuckAmount( ); + get_animstate( )->update( eye_angles.y, eye_angles.x ); + get_animdata( ).m_prev_flags = flags; + memcpy( + get_animdata( ).m_last_layers.data( ), + m_AnimOverlay( ).GetElements( ), + sizeof( C_AnimationLayer ) * 13 + ); + sm_animdata[ idx ].m_fraction = get_animstate( )->m_flUnknownFraction; m_vecVelocity( ) = velocity; @@ -762,8 +796,6 @@ void c_base_player::fix_animations( bool reset, bool resolver_change ) { m_AnimOverlay( ).GetElements( )[ 6 ].m_flPrevCycle = old_cycle; - //estimate_layers( reset ); - //check for any possible mistakes validate_animation_layers( ); @@ -804,8 +836,6 @@ void c_base_player::fix_animations( bool reset, bool resolver_change ) { invalidate_bone_cache( ); ce( )->SetupBones( nullptr, -1, BONE_USED_BY_ANYTHING, anim_time ); cache_anim_data( ); - ///let the game calculate its velocity again... - //calc_abs_velocity( ); g_csgo.m_globals->m_curtime = backup_curtime; g_csgo.m_globals->m_frametime = backup_frametime; diff --git a/internal_rewrite/c_base_player.hpp b/internal_rewrite/c_base_player.hpp index 8aef969..0ed9aa1 100644 --- a/internal_rewrite/c_base_player.hpp +++ b/internal_rewrite/c_base_player.hpp @@ -238,6 +238,7 @@ struct ent_animdata_t { vec3_t m_anim_velocity; bool m_valid{ }; float m_last_duck; + int m_prev_flags; }; class c_base_player { @@ -456,6 +457,7 @@ public: void restore_anim_data( bool layers = false ); void handle_taser_animation( ); void calc_anim_velocity( bool reset ); + void fix_jump_fall( bool reset ); bool is_breaking_lc( ); }; \ No newline at end of file diff --git a/internal_rewrite/detours.cpp b/internal_rewrite/detours.cpp new file mode 100644 index 0000000..a12520c --- /dev/null +++ b/internal_rewrite/detours.cpp @@ -0,0 +1,292 @@ +#include "detours.h" +#include "hde32.h" + +// very MUCH comment i APPRECIATE cool + +memory::c_detours memory::detours; + +__forceinline static bool is_code_padding( uintptr_t address, size_t size ) +{ + uint8_t* code_ptr = (uint8_t*)address; + + if ( code_ptr[0] != 0x00 && code_ptr[0] != 0x90 && code_ptr[0] != 0xCC ) + return false; + + for ( int i = 1; i < size; ++i ) + { + if ( code_ptr[i] != code_ptr[0] ) + return false; + } + + return true; +} + +bool memory::c_detours::create_trampoline( detour_hook_t* hook ) +{ + if ( !hook->allocate_trampoline( ) ) + return false; + + instructions::long_jump_t call = { + 0xE8, + 0x00000000 + }; + + instructions::long_jump_t jmp = { + 0xE9, + 0x00000000 + }; + + instructions::JCC_REL jcc = { + 0x0F, 0x80, + 0x00000000 + }; + + uint8_t old_position = 0; + uint8_t new_position = 0; + uintptr_t jmp_dest = 0; + bool finished = false; + + hook->short_patch = false; + + const int max_instruction_boundaries = 8; + int instruction_boundaries = 0; + + do + { + hde32s hs; + uint8_t copy_size; + uintptr_t copy_src; + uintptr_t old_instruction = hook->m_original + old_position; + uintptr_t new_instruction = hook->m_trampoline + new_position; + + copy_size = hde32_disasm( (void*)old_instruction, &hs ); + if ( hs.flags & F_ERROR ) + return false; + + copy_src = old_instruction; + if ( old_position >= sizeof( instructions::long_jump_t ) ) + { + // the trampoline function is long enough. + // complete the function with the jump to the target function. + + jmp.opcode = 0xE9; + jmp.operand = (uint32_t)( old_instruction - ( new_instruction + sizeof( instructions::long_jump_t ) ) ); + copy_src = uintptr_t( &jmp ); + copy_size = sizeof( jmp ); + + finished = true; + } + else if ( hs.opcode == 0xE8 ) + { + // direct relative CALL + uintptr_t dest = old_instruction + hs.len + (int32_t)hs.imm.imm32; + + call.opcode = 0xE8; + call.operand = (uint32_t)( dest - ( new_instruction + sizeof( instructions::long_jump_t ) ) ); + + copy_src = uintptr_t( &call ); + copy_size = sizeof( call ); + } + else if ( ( hs.opcode & 0xFD ) == 0xE9 ) + { + // direct relative JMP (EB or E9) + uintptr_t dest = old_instruction + hs.len; + + if ( hs.opcode == 0xEB ) // short jmp + dest += (int8_t)hs.imm.imm8; + else + dest += (int32_t)hs.imm.imm32; + + // simply copy an internal jump. + if ( hook->m_original <= dest && dest < hook->m_original + sizeof( instructions::long_jump_t ) ) + { + if ( jmp_dest < dest ) + jmp_dest = dest; + } + else + { + jmp.operand = (uint32_t)( dest - ( new_instruction + sizeof( instructions::long_jump_t ) ) ); + + copy_src = uintptr_t( &jmp ); + copy_size = sizeof( instructions::long_jump_t ); + + // exit the function if it is not in the branch + finished = ( old_instruction >= jmp_dest ); + } + } + else if ( ( hs.opcode & 0xF0 ) == 0x70 || ( hs.opcode & 0xFC ) == 0xE0 || ( hs.opcode2 & 0xF0 ) == 0x80 ) + { + // direct relative JCC + uintptr_t dest = old_instruction + hs.len; + + if ( ( hs.opcode & 0xF0 ) == 0x70 // JCC + || ( hs.opcode & 0xFC ) == 0xE0 ) // LOOPNZ/LOOPZ/LOOP/JECXZ + dest += (int8_t)hs.imm.imm8; + else + dest += (int32_t)hs.imm.imm32; + + // simply copy an internal jump. + if ( (uintptr_t)hook->m_original <= dest && dest < ( (uintptr_t)hook->m_original + sizeof( instructions::long_jump_t ) ) ) + { + if ( jmp_dest < dest ) + jmp_dest = dest; + } + else if ( ( hs.opcode & 0xFC ) == 0xE0 ) + { + // LOOPNZ/LOOPZ/LOOP/JCXZ/JECXZ to the outside are not supported. + return false; + } + else + { + uint8_t cond = ( ( hs.opcode != 0x0F ? hs.opcode : hs.opcode2 ) & 0x0F ); + + jcc.opcode1 = 0x80 | cond; + jcc.operand = (uint32_t)( dest - ( new_instruction + sizeof( jcc ) ) ); + + copy_src = uintptr_t( &jcc ); + copy_size = sizeof( jcc ); + } + } + else if ( ( hs.opcode & 0xFE ) == 0xC2 ) + { + // RET (C2 or C3) + + // complete the function if not in a branch. + finished = ( old_instruction >= jmp_dest ); + } + + // can't alter the instruction length in a branch. + if ( old_instruction < jmp_dest && copy_size != hs.len ) + return false; + + // trampoline function is too large. + if ( new_position + copy_size > MEMORY_SLOT_SIZE ) + return false; + + // trampoline function has too many instructions. + if ( instruction_boundaries >= max_instruction_boundaries ) + return false; + + instruction_boundaries++; + + memcpy( (void*)( hook->m_trampoline + new_position ), (void*)copy_src, copy_size ); + + new_position += copy_size; + old_position += hs.len; + } + while ( !finished ); + + // can we do a regular 5 byte jmp patch? + if ( old_position < sizeof( instructions::long_jump_t ) && !is_code_padding( (uintptr_t)hook->m_original + old_position, sizeof( instructions::long_jump_t ) - old_position ) ) + { + // can we put 2 byte jmp patch? + if ( old_position < sizeof( instructions::short_jump_t ) && !is_code_padding( (uintptr_t)hook->m_original + old_position, sizeof( instructions::short_jump_t ) - old_position ) ) + return false; + + // can we put a 5 byte jmp patch above it? + if ( !is_code_padding( (uintptr_t)hook->m_original - sizeof( instructions::long_jump_t ), sizeof( instructions::long_jump_t ) ) ) + return false; + + hook->short_patch = true; + } + + return true; +} + +bool memory::c_detours::set_hook( detour_hook_t* hook, bool enable ) +{ + // hook is already in place silly + if ( hook->enabled == enable ) + return true; + + if ( enable ) + { + if ( hook->short_patch ) + { + uint8_t* target = (uint8_t*)( hook->m_original - sizeof( instructions::long_jump_t ) ); + + // prepare patch + instructions::short_patch_t jmp_patch; + jmp_patch.jmp.opcode = 0xE9; + jmp_patch.jmp.operand = (uint32_t)( hook->m_custom - hook->m_original - sizeof( instructions::long_jump_t ) ); + + jmp_patch.jmp_short.opcode = 0xEB; + jmp_patch.jmp_short.operand = (uint8_t)( 0 - sizeof( instructions::short_patch_t ) ); + + // overwrite protection + DWORD original_protection; + VirtualProtect( target, sizeof( instructions::short_patch_t ), PAGE_EXECUTE_READWRITE, &original_protection ); + + // place hook + memcpy( target, &jmp_patch, sizeof( instructions::short_patch_t ) ); + + // restore protection + VirtualProtect( target, sizeof( instructions::short_patch_t ), original_protection, &original_protection ); + + // let cpu know we altered code + FlushInstructionCache( GetCurrentProcess( ), target, sizeof( instructions::short_patch_t ) ); + } + else + { + // prepare patch + instructions::long_jump_t jmp_patch; + jmp_patch.opcode = 0xE9; + jmp_patch.operand = (uint32_t)( hook->m_custom - hook->m_original - sizeof( instructions::long_jump_t ) ); + + // overwrite protection + DWORD original_protection; + VirtualProtect( (void*)hook->m_original, sizeof( instructions::long_jump_t ), PAGE_EXECUTE_READWRITE, &original_protection ); + + // place hook + memcpy( (void*)hook->m_original, &jmp_patch, sizeof( instructions::long_jump_t ) ); + + // restore protection + VirtualProtect( (void*)hook->m_original, sizeof( instructions::long_jump_t ), original_protection, &original_protection ); + + // let cpu know we altered code + FlushInstructionCache( GetCurrentProcess( ), (void*)hook->m_original, sizeof( instructions::long_jump_t ) ); + } + + + } + else + { + if ( hook->short_patch ) + { + uint8_t* target = (uint8_t*)( hook->m_original - sizeof( instructions::long_jump_t ) ); + + // overwrite protection + DWORD original_protection; + VirtualProtect( target, sizeof( instructions::short_patch_t ), PAGE_EXECUTE_READWRITE, &original_protection ); + + // restore backup + memcpy( target, hook->m_original_bytes, sizeof( instructions::short_patch_t ) ); + + // restore protection + VirtualProtect( target, sizeof( instructions::short_patch_t ), original_protection, &original_protection ); + + // let cpu know we altered code + FlushInstructionCache( GetCurrentProcess( ), target, sizeof( instructions::short_patch_t ) ); + } + else + { + uint8_t* target = (uint8_t*)hook->m_original; + + // overwrite protection + DWORD original_protection; + VirtualProtect( target, sizeof( instructions::long_jump_t ), PAGE_EXECUTE_READWRITE, &original_protection ); + + // restore backup + memcpy( target, hook->m_original_bytes, sizeof( instructions::long_jump_t ) ); + + // restore protection + VirtualProtect( target, sizeof( instructions::long_jump_t ), original_protection, &original_protection ); + + // let cpu know we altered code + FlushInstructionCache( GetCurrentProcess( ), target, sizeof( instructions::long_jump_t ) ); + } + } + + hook->enabled = enable; + return true; +} \ No newline at end of file diff --git a/internal_rewrite/detours.h b/internal_rewrite/detours.h new file mode 100644 index 0000000..d4998b5 --- /dev/null +++ b/internal_rewrite/detours.h @@ -0,0 +1,164 @@ +#pragma once +#include +#include +#include + +#define MEMORY_SLOT_SIZE 64 + +namespace memory +{ + namespace instructions + { +// we're dealing with opcodes, align by 1 byte +#pragma pack(push, 1) + struct short_jump_t + { + uint8_t opcode{ }; + uint8_t operand{ }; + }; + + struct long_jump_t + { + uint8_t opcode{ }; + uint32_t operand{ }; + }; + + struct short_patch_t + { + long_jump_t jmp{ }; + short_jump_t jmp_short{ }; + }; + + struct JCC_REL + { + uint8_t opcode0{ }; + uint8_t opcode1{ }; + uint32_t operand{ }; + }; +#pragma pack(pop) + } + + struct detour_hook_t + { + bool enabled{ }; + bool short_patch{ }; + + uintptr_t m_original{ }; + uintptr_t m_custom{ }; + uintptr_t m_trampoline{ }; + + uint8_t m_original_bytes[8]{ }; + + bool allocate_trampoline( ) + { + if ( m_trampoline ) + return false; + + m_trampoline = (uintptr_t)VirtualAlloc( nullptr, MEMORY_SLOT_SIZE, MEM_RESERVE | MEM_COMMIT, PAGE_EXECUTE_READWRITE ); + memset( (void*)m_trampoline, 0, MEMORY_SLOT_SIZE ); + + return m_trampoline; + } + + void restore( ) + { + if ( m_trampoline ) + { + VirtualFree( (void*)m_trampoline, MEMORY_SLOT_SIZE, MEM_RELEASE ); + m_trampoline = 0; + } + } + }; + + class c_detours + { + std::vector m_hooks; + + static bool create_trampoline( detour_hook_t* hook ); + + detour_hook_t* find_hook( uintptr_t custom_func ) + { + detour_hook_t* hook = nullptr; + + for ( auto& m_hook : m_hooks ) + { + if ( m_hook.m_custom == custom_func ) + { + return &m_hook; + } + } + + return nullptr; + } + + bool set_hook( detour_hook_t* hook, bool enable ); + + bool set_hook( uintptr_t custom_func, bool enable ) + { + detour_hook_t* hook = find_hook( custom_func ); + + if ( hook ) + return set_hook( hook, enable ); + + return false; + } + + public: + + template < typename fn = uintptr_t > + fn create_hook( fn custom_func, void* original_func ) + { + detour_hook_t hook; + hook.m_original = uintptr_t( original_func ); + hook.m_custom = intptr_t( custom_func ); + + if ( create_trampoline( &hook ) ) + { + if ( hook.short_patch ) + memcpy( hook.m_original_bytes, (void*)( hook.m_original - sizeof( instructions::long_jump_t ) ), sizeof( instructions::short_patch_t ) ); + else + memcpy( hook.m_original_bytes, (void*)( hook.m_original ), sizeof( instructions::long_jump_t ) ); + +#ifdef _DEBUG + printf( " $> prepared hook [ original: 0x%08x ] [ custom: 0x%08x ] [ short jmp: %d ] \n", uintptr_t( original_func ), uintptr_t( custom_func ), hook.short_patch ); +#endif + + m_hooks.push_back( hook ); + return (fn)hook.m_trampoline; + } +#ifdef _DEBUG + printf( " $> FAILED TO HOOK [ original: 0x%08x ] [ custom: hook 0x%08x ] \n", uintptr_t( original_func ), uintptr_t( custom_func ) ); +#endif + return (fn)0; + } + + void enable( ) + { + for ( auto& hook : m_hooks ) + set_hook( &hook, true ); + } + + void restore( ) + { + for ( auto& hook : m_hooks ) + { + set_hook( &hook, false ); + hook.restore( ); + } + + m_hooks.clear( ); + } + + template < typename fn = uintptr_t > + fn original( void* custom_func ) + { + auto hook = find_hook( (uintptr_t)custom_func ); + + if ( hook ) + return (fn)hook->m_trampoline; + + return (fn)0; + } + }; extern c_detours detours; +} + diff --git a/internal_rewrite/factory.hpp b/internal_rewrite/factory.hpp index 50cbf60..9946f1b 100644 --- a/internal_rewrite/factory.hpp +++ b/internal_rewrite/factory.hpp @@ -10,7 +10,7 @@ //IFACE_DLLMAIN - interfaces are passed through dllmain and below code doesnt need to be ran #ifndef _DEBUG -//#define IFACE_DLLMAIN +#define IFACE_DLLMAIN #endif #ifdef IFACE_DLLMAIN diff --git a/internal_rewrite/hde32.cpp b/internal_rewrite/hde32.cpp new file mode 100644 index 0000000..8569287 --- /dev/null +++ b/internal_rewrite/hde32.cpp @@ -0,0 +1,377 @@ +/* +* Hacker Disassembler Engine 32 C +* Copyright (c) 2008-2009, Vyacheslav Patkov. +* All rights reserved. +* +*/ + +#include +#include "hde32.h" +#include "table32.h" + +unsigned int hde32_disasm( const void *code, hde32s *hs ) +{ + uint8_t x, c, *p = (uint8_t *)code, cflags, opcode, pref = 0; + uint8_t *ht = hde32_table, m_mod, m_reg, m_rm, disp_size = 0; + + memset( (uint8_t*)hs, 0, sizeof( hde32s ) ); + + for ( x = 16; x; x-- ) + switch ( c = *p++ ) + { + case 0xf3: + hs->p_rep = c; + pref |= PRE_F3; + break; + case 0xf2: + hs->p_rep = c; + pref |= PRE_F2; + break; + case 0xf0: + hs->p_lock = c; + pref |= PRE_LOCK; + break; + case 0x26: case 0x2e: case 0x36: + case 0x3e: case 0x64: case 0x65: + hs->p_seg = c; + pref |= PRE_SEG; + break; + case 0x66: + hs->p_66 = c; + pref |= PRE_66; + break; + case 0x67: + hs->p_67 = c; + pref |= PRE_67; + break; + default: + goto pref_done; + } +pref_done: + + hs->flags = (uint32_t)pref << 23; + + if ( !pref ) + pref |= PRE_NONE; + + if ( ( hs->opcode = c ) == 0x0f ) + { + hs->opcode2 = c = *p++; + ht += DELTA_OPCODES; + } + else if ( c >= 0xa0 && c <= 0xa3 ) + { + if ( pref & PRE_67 ) + pref |= PRE_66; + else + pref &= ~PRE_66; + } + + opcode = c; + cflags = ht[ht[opcode / 4] + ( opcode % 4 )]; + + if ( cflags == C_ERROR ) + { + hs->flags |= F_ERROR | F_ERROR_OPCODE; + cflags = 0; + if ( ( opcode & -3 ) == 0x24 ) + cflags++; + } + + x = 0; + if ( cflags & C_GROUP ) + { + uint16_t t; + t = *(uint16_t *)( ht + ( cflags & 0x7f ) ); + cflags = (uint8_t)t; + x = (uint8_t)( t >> 8 ); + } + + if ( hs->opcode2 ) + { + ht = hde32_table + DELTA_PREFIXES; + if ( ht[ht[opcode / 4] + ( opcode % 4 )] & pref ) + hs->flags |= F_ERROR | F_ERROR_OPCODE; + } + + if ( cflags & C_MODRM ) + { + hs->flags |= F_MODRM; + hs->modrm = c = *p++; + hs->modrm_mod = m_mod = c >> 6; + hs->modrm_rm = m_rm = c & 7; + hs->modrm_reg = m_reg = ( c & 0x3f ) >> 3; + + if ( x && ( ( x << m_reg ) & 0x80 ) ) + hs->flags |= F_ERROR | F_ERROR_OPCODE; + + if ( !hs->opcode2 && opcode >= 0xd9 && opcode <= 0xdf ) + { + uint8_t t = opcode - 0xd9; + if ( m_mod == 3 ) + { + ht = hde32_table + DELTA_FPU_MODRM + t * 8; + t = ht[m_reg] << m_rm; + } + else + { + ht = hde32_table + DELTA_FPU_REG; + t = ht[t] << m_reg; + } + if ( t & 0x80 ) + hs->flags |= F_ERROR | F_ERROR_OPCODE; + } + + if ( pref & PRE_LOCK ) + { + if ( m_mod == 3 ) + { + hs->flags |= F_ERROR | F_ERROR_LOCK; + } + else + { + uint8_t *table_end, op = opcode; + if ( hs->opcode2 ) + { + ht = hde32_table + DELTA_OP2_LOCK_OK; + table_end = ht + DELTA_OP_ONLY_MEM - DELTA_OP2_LOCK_OK; + } + else + { + ht = hde32_table + DELTA_OP_LOCK_OK; + table_end = ht + DELTA_OP2_LOCK_OK - DELTA_OP_LOCK_OK; + op &= -2; + } + for ( ; ht != table_end; ht++ ) + if ( *ht++ == op ) + { + if ( !( ( *ht << m_reg ) & 0x80 ) ) + goto no_lock_error; + else + break; + } + hs->flags |= F_ERROR | F_ERROR_LOCK; + no_lock_error: + ; + } + } + + if ( hs->opcode2 ) + { + switch ( opcode ) + { + case 0x20: case 0x22: + m_mod = 3; + if ( m_reg > 4 || m_reg == 1 ) + goto error_operand; + else + goto no_error_operand; + case 0x21: case 0x23: + m_mod = 3; + if ( m_reg == 4 || m_reg == 5 ) + goto error_operand; + else + goto no_error_operand; + } + } + else + { + switch ( opcode ) + { + case 0x8c: + if ( m_reg > 5 ) + goto error_operand; + else + goto no_error_operand; + case 0x8e: + if ( m_reg == 1 || m_reg > 5 ) + goto error_operand; + else + goto no_error_operand; + } + } + + if ( m_mod == 3 ) + { + uint8_t *table_end; + if ( hs->opcode2 ) + { + ht = hde32_table + DELTA_OP2_ONLY_MEM; + table_end = ht + sizeof( hde32_table ) - DELTA_OP2_ONLY_MEM; + } + else + { + ht = hde32_table + DELTA_OP_ONLY_MEM; + table_end = ht + DELTA_OP2_ONLY_MEM - DELTA_OP_ONLY_MEM; + } + for ( ; ht != table_end; ht += 2 ) + if ( *ht++ == opcode ) + { + if ( *ht++ & pref && !( ( *ht << m_reg ) & 0x80 ) ) + goto error_operand; + else + break; + } + goto no_error_operand; + } + else if ( hs->opcode2 ) + { + switch ( opcode ) + { + case 0x50: case 0xd7: case 0xf7: + if ( pref & ( PRE_NONE | PRE_66 ) ) + goto error_operand; + break; + case 0xd6: + if ( pref & ( PRE_F2 | PRE_F3 ) ) + goto error_operand; + break; + case 0xc5: + goto error_operand; + } + goto no_error_operand; + } + else + goto no_error_operand; + + error_operand: + hs->flags |= F_ERROR | F_ERROR_OPERAND; + no_error_operand: + + c = *p++; + if ( m_reg <= 1 ) + { + if ( opcode == 0xf6 ) + cflags |= C_IMM8; + else if ( opcode == 0xf7 ) + cflags |= C_IMM_P66; + } + + switch ( m_mod ) + { + case 0: + if ( pref & PRE_67 ) + { + if ( m_rm == 6 ) + disp_size = 2; + } + else + if ( m_rm == 5 ) + disp_size = 4; + break; + case 1: + disp_size = 1; + break; + case 2: + disp_size = 2; + if ( !( pref & PRE_67 ) ) + disp_size <<= 1; + } + + if ( m_mod != 3 && m_rm == 4 && !( pref & PRE_67 ) ) + { + hs->flags |= F_SIB; + p++; + hs->sib = c; + hs->sib_scale = c >> 6; + hs->sib_index = ( c & 0x3f ) >> 3; + if ( ( hs->sib_base = c & 7 ) == 5 && !( m_mod & 1 ) ) + disp_size = 4; + } + + p--; + switch ( disp_size ) + { + case 1: + hs->flags |= F_DISP8; + hs->disp.disp8 = *p; + break; + case 2: + hs->flags |= F_DISP16; + hs->disp.disp16 = *(uint16_t *)p; + break; + case 4: + hs->flags |= F_DISP32; + hs->disp.disp32 = *(uint32_t *)p; + } + p += disp_size; + } + else if ( pref & PRE_LOCK ) + hs->flags |= F_ERROR | F_ERROR_LOCK; + + if ( cflags & C_IMM_P66 ) + { + if ( cflags & C_REL32 ) + { + if ( pref & PRE_66 ) + { + hs->flags |= F_IMM16 | F_RELATIVE; + hs->imm.imm16 = *(uint16_t *)p; + p += 2; + goto disasm_done; + } + goto rel32_ok; + } + if ( pref & PRE_66 ) + { + hs->flags |= F_IMM16; + hs->imm.imm16 = *(uint16_t *)p; + p += 2; + } + else + { + hs->flags |= F_IMM32; + hs->imm.imm32 = *(uint32_t *)p; + p += 4; + } + } + + if ( cflags & C_IMM16 ) + { + if ( hs->flags & F_IMM32 ) + { + hs->flags |= F_IMM16; + hs->disp.disp16 = *(uint16_t *)p; + } + else if ( hs->flags & F_IMM16 ) + { + hs->flags |= F_2IMM16; + hs->disp.disp16 = *(uint16_t *)p; + } + else + { + hs->flags |= F_IMM16; + hs->imm.imm16 = *(uint16_t *)p; + } + p += 2; + } + if ( cflags & C_IMM8 ) + { + hs->flags |= F_IMM8; + hs->imm.imm8 = *p++; + } + + if ( cflags & C_REL32 ) + { + rel32_ok: + hs->flags |= F_IMM32 | F_RELATIVE; + hs->imm.imm32 = *(uint32_t *)p; + p += 4; + } + else if ( cflags & C_REL8 ) + { + hs->flags |= F_IMM8 | F_RELATIVE; + hs->imm.imm8 = *p++; + } + +disasm_done: + + if ( ( hs->len = (uint8_t)( p - (uint8_t *)code ) ) > 15 ) + { + hs->flags |= F_ERROR | F_ERROR_LENGTH; + hs->len = 15; + } + + return (unsigned int)hs->len; +} + diff --git a/internal_rewrite/hde32.h b/internal_rewrite/hde32.h new file mode 100644 index 0000000..dd2ef6d --- /dev/null +++ b/internal_rewrite/hde32.h @@ -0,0 +1,109 @@ +/* +* Hacker Disassembler Engine 32 +* Copyright (c) 2006-2009, Vyacheslav Patkov. +* All rights reserved. +* +* hde32.h: C/C++ header file +* +*/ + +#ifndef _HDE32_H_ +#define _HDE32_H_ + +/* stdint.h - C99 standard header +* http://en.wikipedia.org/wiki/stdint.h +* +* if your compiler doesn't contain "stdint.h" header (for +* example, Microsoft Visual C++), you can download file: +* http://www.azillionmonkeys.com/qed/pstdint.h +* and change next line to: +* #include "pstdint.h" +*/ + +#include + +#define F_MODRM 0x00000001 +#define F_SIB 0x00000002 +#define F_IMM8 0x00000004 +#define F_IMM16 0x00000008 +#define F_IMM32 0x00000010 +#define F_DISP8 0x00000020 +#define F_DISP16 0x00000040 +#define F_DISP32 0x00000080 +#define F_RELATIVE 0x00000100 +#define F_2IMM16 0x00000800 +#define F_ERROR 0x00001000 +#define F_ERROR_OPCODE 0x00002000 +#define F_ERROR_LENGTH 0x00004000 +#define F_ERROR_LOCK 0x00008000 +#define F_ERROR_OPERAND 0x00010000 +#define F_PREFIX_REPNZ 0x01000000 +#define F_PREFIX_REPX 0x02000000 +#define F_PREFIX_REP 0x03000000 +#define F_PREFIX_66 0x04000000 +#define F_PREFIX_67 0x08000000 +#define F_PREFIX_LOCK 0x10000000 +#define F_PREFIX_SEG 0x20000000 +#define F_PREFIX_ANY 0x3f000000 + +#define PREFIX_SEGMENT_CS 0x2e +#define PREFIX_SEGMENT_SS 0x36 +#define PREFIX_SEGMENT_DS 0x3e +#define PREFIX_SEGMENT_ES 0x26 +#define PREFIX_SEGMENT_FS 0x64 +#define PREFIX_SEGMENT_GS 0x65 +#define PREFIX_LOCK 0xf0 +#define PREFIX_REPNZ 0xf2 +#define PREFIX_REPX 0xf3 +#define PREFIX_OPERAND_SIZE 0x66 +#define PREFIX_ADDRESS_SIZE 0x67 + +#pragma pack(push,1) + +typedef struct +{ + uint8_t len; + uint8_t p_rep; + uint8_t p_lock; + uint8_t p_seg; + uint8_t p_66; + uint8_t p_67; + uint8_t opcode; + uint8_t opcode2; + uint8_t modrm; + uint8_t modrm_mod; + uint8_t modrm_reg; + uint8_t modrm_rm; + uint8_t sib; + uint8_t sib_scale; + uint8_t sib_index; + uint8_t sib_base; + union + { + uint8_t imm8; + uint16_t imm16; + uint32_t imm32; + } imm; + union + { + uint8_t disp8; + uint16_t disp16; + uint32_t disp32; + } disp; + uint32_t flags; +} hde32s; + +#pragma pack(pop) + +#ifdef __cplusplus +extern "C" { +#endif + + /* __cdecl */ + unsigned int hde32_disasm( const void *code, hde32s *hs ); + +#ifdef __cplusplus +} +#endif + +#endif /* _HDE32_H_ */ \ No newline at end of file diff --git a/internal_rewrite/hooks.cpp b/internal_rewrite/hooks.cpp index 9a2aea1..3d21d2a 100644 --- a/internal_rewrite/hooks.cpp +++ b/internal_rewrite/hooks.cpp @@ -1,5 +1,7 @@ #include "hooks.hpp" #include "interface.hpp" +#include "detours.h" + hooks::c_netvar_proxy hooks::lby_proxy; hooks::c_netvar_proxy hooks::last_shot_proxy; @@ -16,6 +18,9 @@ bool hooks::commit( factory::c_csgo* instance ) { lby_proxy.init( g_netvars.get_prop( fnv( "DT_CSPlayer" ), fnv( "m_flLowerBodyYawTarget" ) ), &lby_proxy_fn ); last_shot_proxy.init( g_netvars.get_prop( fnv( "DT_WeaponCSBaseGun" ), fnv( "m_fLastShotTime" ) ), &last_shot_proxy_fn ); + // god i'm thriving the d + auto* d = &memory::detours; + instance->m_d3d->hook( 42, &hooks::d3d::end_scene ); instance->m_d3d->hook( 16, &hooks::d3d::reset ); instance->m_d3d->hook( 17, &hooks::d3d::present ); diff --git a/internal_rewrite/internal_rewrite.vcxproj b/internal_rewrite/internal_rewrite.vcxproj index 8a582d1..5a7f59e 100644 --- a/internal_rewrite/internal_rewrite.vcxproj +++ b/internal_rewrite/internal_rewrite.vcxproj @@ -310,6 +310,7 @@ + @@ -323,6 +324,7 @@ + @@ -397,10 +399,12 @@ + + @@ -449,6 +453,7 @@ + diff --git a/internal_rewrite/internal_rewrite.vcxproj.filters b/internal_rewrite/internal_rewrite.vcxproj.filters index 4a2a246..8e5da24 100644 --- a/internal_rewrite/internal_rewrite.vcxproj.filters +++ b/internal_rewrite/internal_rewrite.vcxproj.filters @@ -271,6 +271,12 @@ hooks + + hooks\hookers + + + hooks\hookers + @@ -555,5 +561,14 @@ sdk + + hooks\hookers + + + hooks\hookers + + + hooks\hookers + \ No newline at end of file diff --git a/internal_rewrite/prediction.cpp b/internal_rewrite/prediction.cpp index 32a30ae..233fb62 100644 --- a/internal_rewrite/prediction.cpp +++ b/internal_rewrite/prediction.cpp @@ -819,6 +819,7 @@ void c_prediction::run_command( user_cmd_t *ucmd ) { ucmd->m_forwardmove = backup_forwardmove; ucmd->m_sidemove = backup_sidemove; + ucmd->m_buttons = backup_buttons; if( auto wep = g_ctx.m_local->get_weapon( ) ) { wep->update_accuracy_penalty( ); diff --git a/internal_rewrite/ragebot.cpp b/internal_rewrite/ragebot.cpp index a4ecc9a..435559e 100644 --- a/internal_rewrite/ragebot.cpp +++ b/internal_rewrite/ragebot.cpp @@ -217,8 +217,8 @@ namespace features return g_settings.rage.hitscan.head; case HITBOX_PELVIS: case HITBOX_BODY: - case HITBOX_CHEST: return g_settings.rage.hitscan.stomach; + case HITBOX_CHEST: case HITBOX_UPPER_CHEST: case HITBOX_THORAX: return g_settings.rage.hitscan.chest; diff --git a/internal_rewrite/settings.hpp b/internal_rewrite/settings.hpp index 45c012e..1a2874e 100644 --- a/internal_rewrite/settings.hpp +++ b/internal_rewrite/settings.hpp @@ -208,7 +208,6 @@ namespace data con_var< bool > preserve_fps{ &holder_, fnv( "rage_preserve_fps" ), false }; con_var< int > multipoint{ &holder_, fnv( "rage_multipoint" ), false }; con_var< bool > compensate_spread{ &holder_, fnv( "rage_compensate_spread" ) }; - con_var< bool > autowall_fps { &holder_, fnv( "rage_autowall_fps" ), false }; con_var< int > selection_type{ &holder_, fnv( "rage_selection_type" ) }; con_var< bool > prefer_moving{ &holder_, fnv( "rage_prefer_moving" ) }; diff --git a/internal_rewrite/table32.h b/internal_rewrite/table32.h new file mode 100644 index 0000000..2bd19d8 --- /dev/null +++ b/internal_rewrite/table32.h @@ -0,0 +1,73 @@ +/* +* Hacker Disassembler Engine 32 C +* Copyright (c) 2008-2009, Vyacheslav Patkov. +* All rights reserved. +* +*/ + +#define C_NONE 0x00 +#define C_MODRM 0x01 +#define C_IMM8 0x02 +#define C_IMM16 0x04 +#define C_IMM_P66 0x10 +#define C_REL8 0x20 +#define C_REL32 0x40 +#define C_GROUP 0x80 +#define C_ERROR 0xff + +#define PRE_ANY 0x00 +#define PRE_NONE 0x01 +#define PRE_F2 0x02 +#define PRE_F3 0x04 +#define PRE_66 0x08 +#define PRE_67 0x10 +#define PRE_LOCK 0x20 +#define PRE_SEG 0x40 +#define PRE_ALL 0xff + +#define DELTA_OPCODES 0x4a +#define DELTA_FPU_REG 0xf1 +#define DELTA_FPU_MODRM 0xf8 +#define DELTA_PREFIXES 0x130 +#define DELTA_OP_LOCK_OK 0x1a1 +#define DELTA_OP2_LOCK_OK 0x1b9 +#define DELTA_OP_ONLY_MEM 0x1cb +#define DELTA_OP2_ONLY_MEM 0x1da + +static unsigned char hde32_table[] = { + 0xa3,0xa8,0xa3,0xa8,0xa3,0xa8,0xa3,0xa8,0xa3,0xa8,0xa3,0xa8,0xa3,0xa8,0xa3, + 0xa8,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xac,0xaa,0xb2,0xaa,0x9f,0x9f, + 0x9f,0x9f,0xb5,0xa3,0xa3,0xa4,0xaa,0xaa,0xba,0xaa,0x96,0xaa,0xa8,0xaa,0xc3, + 0xc3,0x96,0x96,0xb7,0xae,0xd6,0xbd,0xa3,0xc5,0xa3,0xa3,0x9f,0xc3,0x9c,0xaa, + 0xaa,0xac,0xaa,0xbf,0x03,0x7f,0x11,0x7f,0x01,0x7f,0x01,0x3f,0x01,0x01,0x90, + 0x82,0x7d,0x97,0x59,0x59,0x59,0x59,0x59,0x7f,0x59,0x59,0x60,0x7d,0x7f,0x7f, + 0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x9a,0x88,0x7d, + 0x59,0x50,0x50,0x50,0x50,0x59,0x59,0x59,0x59,0x61,0x94,0x61,0x9e,0x59,0x59, + 0x85,0x59,0x92,0xa3,0x60,0x60,0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x59, + 0x59,0x59,0x9f,0x01,0x03,0x01,0x04,0x03,0xd5,0x03,0xcc,0x01,0xbc,0x03,0xf0, + 0x10,0x10,0x10,0x10,0x50,0x50,0x50,0x50,0x14,0x20,0x20,0x20,0x20,0x01,0x01, + 0x01,0x01,0xc4,0x02,0x10,0x00,0x00,0x00,0x00,0x01,0x01,0xc0,0xc2,0x10,0x11, + 0x02,0x03,0x11,0x03,0x03,0x04,0x00,0x00,0x14,0x00,0x02,0x00,0x00,0xc6,0xc8, + 0x02,0x02,0x02,0x02,0x00,0x00,0xff,0xff,0xff,0xff,0x00,0x00,0x00,0xff,0xca, + 0x01,0x01,0x01,0x00,0x06,0x00,0x04,0x00,0xc0,0xc2,0x01,0x01,0x03,0x01,0xff, + 0xff,0x01,0x00,0x03,0xc4,0xc4,0xc6,0x03,0x01,0x01,0x01,0xff,0x03,0x03,0x03, + 0xc8,0x40,0x00,0x0a,0x00,0x04,0x00,0x00,0x00,0x00,0x7f,0x00,0x33,0x01,0x00, + 0x00,0x00,0x00,0x00,0x00,0xff,0xbf,0xff,0xff,0x00,0x00,0x00,0x00,0x07,0x00, + 0x00,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0xff,0xff,0x00,0x00,0x00,0xbf,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x7f,0x00,0x00,0xff,0x4a,0x4a,0x4a,0x4a,0x4b,0x52,0x4a,0x4a,0x4a,0x4a,0x4f, + 0x4c,0x4a,0x4a,0x4a,0x4a,0x4a,0x4a,0x4a,0x4a,0x55,0x45,0x40,0x4a,0x4a,0x4a, + 0x45,0x59,0x4d,0x46,0x4a,0x5d,0x4a,0x4a,0x4a,0x4a,0x4a,0x4a,0x4a,0x4a,0x4a, + 0x4a,0x4a,0x4a,0x4a,0x4a,0x61,0x63,0x67,0x4e,0x4a,0x4a,0x6b,0x6d,0x4a,0x4a, + 0x45,0x6d,0x4a,0x4a,0x44,0x45,0x4a,0x4a,0x00,0x00,0x00,0x02,0x0d,0x06,0x06, + 0x06,0x06,0x0e,0x00,0x00,0x00,0x00,0x06,0x06,0x06,0x00,0x06,0x06,0x02,0x06, + 0x00,0x0a,0x0a,0x07,0x07,0x06,0x02,0x05,0x05,0x02,0x02,0x00,0x00,0x04,0x04, + 0x04,0x04,0x00,0x00,0x00,0x0e,0x05,0x06,0x06,0x06,0x01,0x06,0x00,0x00,0x08, + 0x00,0x10,0x00,0x18,0x00,0x20,0x00,0x28,0x00,0x30,0x00,0x80,0x01,0x82,0x01, + 0x86,0x00,0xf6,0xcf,0xfe,0x3f,0xab,0x00,0xb0,0x00,0xb1,0x00,0xb3,0x00,0xba, + 0xf8,0xbb,0x00,0xc0,0x00,0xc1,0x00,0xc7,0xbf,0x62,0xff,0x00,0x8d,0xff,0x00, + 0xc4,0xff,0x00,0xc5,0xff,0x00,0xff,0xff,0xeb,0x01,0xff,0x0e,0x12,0x08,0x00, + 0x13,0x09,0x00,0x16,0x08,0x00,0x17,0x09,0x00,0x2b,0x09,0x00,0xae,0xff,0x07, + 0xb2,0xff,0x00,0xb4,0xff,0x00,0xb5,0xff,0x00,0xc3,0x01,0x00,0xc7,0xff,0xbf, + 0xe7,0x08,0x00,0xf0,0x02,0x00 +}; \ No newline at end of file diff --git a/internal_rewrite/ui.h b/internal_rewrite/ui.h index 7cb5fdd..5585973 100644 --- a/internal_rewrite/ui.h +++ b/internal_rewrite/ui.h @@ -195,7 +195,6 @@ namespace ui main_form->add_item( std::make_shared< ui::c_dropdown< > >( 0, 0, 120, xors( "multipoint" ), &g_settings.rage.multipoint, &dropdowns::multipoint_types ) ); main_form->add_item( std::make_shared< ui::c_checkbox >( 0, 0, xors( "preserve fps" ), &g_settings.rage.preserve_fps ) ); - main_form->add_item( std::make_shared< ui::c_checkbox >( 0, 0, xors( "preserve autowall fps" ), &g_settings.rage.autowall_fps ) ); } auto accuracy_form = std::make_shared< ui::c_form >( 0, 0, 215, 157, xors( "accuracy" ), 157 ); { diff --git a/internal_rewrite/visual_local.cpp b/internal_rewrite/visual_local.cpp index 8a20aea..413a35f 100644 --- a/internal_rewrite/visual_local.cpp +++ b/internal_rewrite/visual_local.cpp @@ -441,6 +441,15 @@ namespace features draw_line( screen_w / 2, screen_h / 2 - 1, screen_w / 2, screen_h / 2 + 2, can_penetrate ? clr_t( 0, 220, 0 ) : clr_t( 220, 0, 0 ) ); + +#ifdef _DEBUG + static con_var< bool > dbg_awall{ &data::holder_, fnv( "dbg_awall" ) }; + + if( dbg_awall( ) ) { + draw_string( screen_w / 2 + 5, screen_h / 2 + 5, ALIGN_LEFT, true, + can_penetrate ? clr_t( 0, 220, 0 ) : clr_t( 220, 0, 0 ), "%d", ( int )data.current_damage ); + } +#endif } void c_visuals::draw_spread( ) { -- cgit v1.2.3