Help Calculation problem when window mode active

Parazitas

God
Joined
Jan 2, 2017
Messages
3,103
Solutions
5
Reaction score
882
Location
Lithuania
Position Is matching perfectly until i activate window mode.
So does anyone know how to accurately calculate everything?

Example in cleo code
PHP:
{$CLEO .cs}

0000:

REPEAT
IF 8256:   player $PLAYER_CHAR defined
THEN 0A93: end_custom_thread
END
WAIT 1500
UNTIL 0256:   player $PLAYER_CHAR defined

WHILE TRUE
WAIT 0   
 
IF 0256:   player $PLAYER_CHAR defined
THEN
    03F0: enable_text_draw 1
    038E: draw_box_position 400.0 300.0 size 120.0 5.0 RGBA 255 255 0 255
    IF 0AB1: @is_cursor_inside_square 4 XY 400.0 300.0 size 120.0 5.0
    THEN
        0AD1: "Is Here!" 100
    END
    0A8D: 31@ = read_memory 0xC9C060 size 4 virtual_protect 1
    0A8D: 30@ = read_memory 0xC9C070 size 4 virtual_protect 0
    IF AND
    31@ == 1
    30@ == 0
    THEN
        //  Window Mode Active, Do something...
    END
END    
                       

END

:is_cursor_inside_square
// 0AB1: @is_cursor_inside_square 4 XY 400.0 300.0 size 120.0 25.0
0087: 29@ = 0@ // (float) Copy PositionX = targetPosX
0087: 28@ = 0@ // (float) Copy PositionX = targetPosX
0087: 27@ = 1@ // (float) Copy PositionY = targetPosY
0087: 26@ = 1@ // (float) Copy PositionY = targetPosY
0087: 25@ = 2@ // (float) Copy SizeX = targetSizeX
0087: 24@ = 3@ // (float) Copy SizeY = targetSizeY
25@ /= 2.0 // halfSizeX
24@ /= 2.0 // halfSizeY
0063: 29@ -= 25@  // (float) leftBoundary = targetPosX - halfSizeX
005B: 28@ += 25@  // (float) rightBoundary = targetPosX + halfSizeX
0063: 27@ -= 24@  // (float) topBoundary = targetPosY - halfSizeY
005B: 26@ += 24@  // (float) bottomBoundary = targetPosY + halfSizeY
0AB1: @GetCursorPosOfFullScreenXY 0 _Returned: XY 31@ 30@
IF AND
0035: 31@ >= 29@ // mouseX >= leftBoundary
8035: 31@ <= 28@ // mouseX <= rightBoundary
0035: 30@ >= 27@ // mouseY >= topBoundary
8035: 30@ <= 26@ // mouseY <= bottomBoundary
THEN 0485:  return_true
ELSE 059A:  return_false
END
0AB2: ret 0

:GetCursorPosOfFullScreenXY
// 0AB1: @GetCursorPosOfFullScreenXY 0 _Returned: 31@ 30@
0A8D: 31@ = read_memory 0xC97C1C size 4 virtual_protect 0 // HWND - A handle to the window
0A8D: 30@ = read_memory 0x8582F0 size 4 virtual_protect 0 // GetWindowRect
IF AND
31@ > 0
30@ > 0
THEN
    IF 0AA2: 22@ = load_library "user32.dll"
    THEN
        IF 0AA4: 21@ = get_proc_address "GetCursorPos" library 22@
        THEN
            0AC7: 28@ = var 29@ offset
            0AA7: call_function 30@ num_params 2 pop 0 RectStructure 28@ WindowHandle 31@ _Returned: state 23@
            0A8D: 12@ = read_memory 28@ size 1 virtual_protect 0
            28@ += 2    
            0A8D: 11@ = read_memory 28@ size 1 virtual_protect 0   
            28@ += 2    
            0A8D: 10@ = read_memory 28@ size 1 virtual_protect 0
            28@ += 4    
            0A8D: 25@ = read_memory 28@ size 4 virtual_protect 0 // full screen X
            28@ += 4
            0A8D: 24@ = read_memory 28@ size 4 virtual_protect 0 // full screen Y
          
            0AC7: 19@ = var 20@ offset
            0AA5: call 21@ num_params 1 pop 0 PointStructure 19@
            0A8D: 18@ = read_memory 19@ size 4 virtual_protect 0 // Cursor X
            19@ += 4
            0A8D: 17@ = read_memory 19@ size 4 virtual_protect 0 // Cursor Y
            0093: 25@ = integer 25@ to_float // Full Screen X convert to float
            0093: 24@ = integer 24@ to_float // Full Screen Y convert to float
            0093: 18@ = integer 18@ to_float // Cursor X convert to float
            0093: 17@ = integer 17@ to_float // Cursor Y convert to float
          
            16@ = 640.0 // Screen X
            0073: 16@ /= 25@
            006B: 18@ *= 16@
          
            15@ = 448.0 // Screen Y
            0073: 15@ /= 24@
            006B: 17@ *= 15@ 
        END
    END   
END
0AB2: ret 2 18@ 17@

Same Code Example in C++
C++:
#include <iostream>
#include <tuple>
bool isMouseOnSquare(std::pair<int, int> mousePosXY, std::pair<int, int> targetPosXY, std::pair<int, int> targetSizeXY) {
}
int mouseX = mousePosXY.first;
int mousey = mousePosXY.second;
int targetX = targetPosXY.first;
int targetY = targetPosXY.second;
int targetSizeX = targetSizeXY.first;
int targetSizeY = targetSizeXY.second;
return (mousex >= targetX && mousex <= targetX + targetSizeX && mousey >= targetY && mousey <= targetY + targetSizeY);
int main() {
// Example usage:
std::pair<int, int> mousePosXY = std::make_pair(50, 50);
std::pair<int, int> targetPosXY = std::make_pair(30, 30);
std::pair<int, int> targetSizeXY = std::make_pair(40, 40);
if (isMouseOnSquare (mousePosXY, targetPosXY, targetSizeXY)) {
std::cout << "Mouse is on the square." << std::endl;
} else {
}
std::cout << "Mouse is not on the square." << std::endl;
return 0;
}
 

SIGKILL

Active member
Joined
Apr 29, 2020
Messages
37
Reaction score
22
Location
Earth
Sounds to me that you want to get the relative mouse position because the window itself has a position too. To get the relative position you need to subtract the window position from the mouse position, so something like this:
C++:
Vector2 mousePosition = GetMousePosition();
Vector2 windowPosition = GetwindowPosition();
Vector2 relativePosition = mousePosition - windowPosition;
//Or like this:
float relativePositionX = mousePosition.x - windowPosition.x;
float relativePositionY = mousePosition.y - windowPosition.y;
 

SobFoX

Expert
Joined
Jul 14, 2015
Messages
1,386
Solutions
4
Reaction score
893
Location
Israel
I think I got to deal with this problem with SAMPADDON
Try this and see if it helps you instead:
C:
0A8D: 31@ = read_memory 0xC97C1C size 4 virtual_protect 0 // HWND - A handle to the window


Bash:
POINT cursor_pos;
if (GetCursorPos(&cursor_pos) && ScreenToClient(**(HWND**)0xC17054, &cursor_pos))
{   
    //use
    //cursor_pos.x
    //cursor_pos.y

}
 
Top