1. Your DwEnginePointer offset is wrong, i've told you that before. The correct offset is 0x5B92A4. Also, the correct name is ClientState.
2. Your "getDll" function is not calling Module32First before calling Module32Next, which firstly makes it error prone aswell as the do while loop useless since a while loop would be enough in this case. Call Module32First first before you get to the do while loop.
3. In your "getTeam" function you're returning an integer. Why do you return void in "getVelocity"? You could be returning the Vector. "getVelocity" infact does nothing. You have a parameter called buffer, but you're using C++ here, not Java ( as far as i know, variables are passed by reference by default [ edit: apparently not ] ). "buffer" is a local variable, it gets created when the function gets called and gets deleted when the function returns. When you're calling the function, you are creating a copy and assign the buffer to the value you passed as an argument, then modify the local variable. When the function returns, you modified the local buffer instead of the variable you passed as an argument. Your function should be taking a pointer to a vector and you should call the function by passing the address of your buffer using the address of operator ( & ). This way you modify the buffer you pass as an argument. Your ReadMem function returns the value you want to use, yet you never assign it to any variable, hence making it completely useless. The same issue applies to the following functions: getVelocity ( within the Entity struct and the Player struct ), getBonePosition, getAngles, getPunch, getPosition ( within the Player struct ), calcAngle, smoothAngleFunc, velocityCompensation
4. Your "getBonePosition" function could use the ReadMem function by reading 3 floats. This way you would avoid raw ReadProcessMemory calls and keep it consistent by calling your wrapper function.
5. You're passing a Vector in setAngles where you could pass a reference to optimize performance. It won't be a huge difference in such a small project, but generally you want to pass any type that is bigger than 4 bytes and not a default type ( such as int ) by reference. ( & )
6. As said above in point 3, you return the values directly in functions such as getTeam, but you return void and use a buffer in functions such as getVelocity. This is inconsistent and not really useful. Using a buffer as parameter is useful in cases where you want to return values to know whether the funciton succeeded or not, returning void is kind of useless in such a case. You will avoid copies, but that shouldn't be a huge deal.
7. getCrosshairId is reading a wrong memory address. You want to subtract one from the result of the ReadMem call ( from the CrosshairID to line it up with the entitylist offset you're using ), but you're subtracting 1 from the memory address to use to read. Use
Code:
return ReadMem<int>(hProc, (playerBase + DwCrosshairId)) - 1;
instead.
8. getViewOrigin ( vecView ) creates a buffer of 3 floats, then reads 3 floats, but only returns the z value. You could consider only reading the z value instead of 12 bytes for 3 floats. ( playerBase + DwVecViewOrigin + 8 ).
9. Your normalize function is clamping aswell. If you perform multiple operations, it could be that whenever you're normalizing ( +1 for normalizing after every operation ) you're accidently clamping a value which shouldn't be clamped, thus resulting in wrong calculations. Consider using 2 seperate functions instead. You also should implement a NaN check. Take a look at
this thread for that. Make sure to only clamp right before you set your angle.
10. Please don't combine punch compensation and CalcAngle. Consider compensating for punch in a seperate function. Also if you want to use a random number, why don't you use rand( )? It's much easier.
11. Inside your main function, you're using a while loop. This is useless and can be replaced with a simple if statement. GetAsyncKeyState( KEY ) < 0 will not work correctly, if you want to check if you are holding the key, consider using GetAsyncKeyState( KEY ) & ( 1 << 15 ) instead.
12. You should add a check for the player base of an entity, otherwise you could be aiming at the world entity.
13. You get your crosshair id twice, aswell as check all the health, team etc twice in a row, which is completely redundant. Check it once.
14. You're calculating an angle between your feet position and the enemies head position. The starting point should be the position of your viewangles, which is m_vecOrigin + m_vecViewOffset.
15. You should implement a function which returns the closest enemy to your crosshair instead of using crosshair id. Now you'll only aim if crosshair id is set to the entity, and you'll only aim at that specific entity.
Reminder: Don't forget to change the parameters of the mentioned functions above to pointers to the buffer.