Unit x,y to minimap x,y (Different screen sizes)

This is a discussion on Unit x,y to minimap x,y (Different screen sizes) within the Starcraft 2 Coding board part of the Starcraft 2 forum category; Hi guys, I am trying to update my SC2 code that I wrote a while ago, mainly with help from ...

Results 1 to 4 of 4
  1. #1
    MarineMarauderMedivac is offline Wannabe Member
    Array
    Join Date
    Mar 2013
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Rep Power
    7
    Reputation
    1

    Unit x,y to minimap x,y (Different screen sizes)

    Hi guys,



    I am trying to update my SC2 code that I wrote a while ago, mainly with help from RHCP's autoit source. I have this minimap code which works but it does not align the units properly on the minimap, does anyone have any tips on how to make this code work correctly for my resolution (1920 x 1200) ? possibly would be cool to have it handle any resolution too.

    Thanks!

    Code:
    unsigned int GetMapLeft(HANDLE Process) //Might return float?
    {
        unsigned int A = 0;
        DWORD N;
        ReadProcessMemory(Process, (LPCVOID)O_mLeft, &A, sizeof(unsigned int), &N);
        return A / 4096;
    }
    
    
    unsigned int GetMapBottom(HANDLE Process)
    {
        unsigned int A = 0;
        DWORD N;
        ReadProcessMemory(Process, (LPCVOID)O_mBottom, &A, sizeof(unsigned int), &N);
        return A / 4096;
    }
    
    
    unsigned int GetMapRight(HANDLE Process)
    {
        unsigned int A = 0;
        DWORD N;
        ReadProcessMemory(Process, (LPCVOID)O_mRight, &A, sizeof(unsigned int), &N);
        return A / 4096;
    }
    
    
    unsigned int GetMapTop(HANDLE Process)
    {
        unsigned int A = 0;
        DWORD N;
        ReadProcessMemory(Process, (LPCVOID)O_mTop, &A, sizeof(unsigned int), &N);
        return A / 4096;
    }
    
    
    void Minimap::Init(HANDLE Process, unsigned int iScreenWidth, unsigned int iScreenHeight)
    {
        MapLeft   = GetMapLeft(Process);
        MapRight  = GetMapRight(Process);    
        MapTop    = GetMapTop(Process);
        MapBottom = GetMapBottom(Process);
    
    
        float TenEighty = 1200.0f;
        
        ScreenLeft          = (29.0f/1920.0f)   * iScreenWidth;
        ScreenBottom     = (1066.0f/TenEighty) * TenEighty;
        ScreenRight        = (289.0f/1920.0f)  * iScreenWidth;
        ScreenTop           = (807.0f/TenEighty)  * TenEighty;
        
        ScreenWidth       = ScreenRight  - ScreenLeft; //Minimap LED screen
        ScreenHeight      = ScreenBottom - ScreenTop;  //Minimap LED screen
        MapPlayableWidth  = MapRight     - MapLeft;    //In game coords of the map extents?
        MapPlayableHeight = MapTop       - MapBottom;  //In game coords of the map extents?
    
    
        First = false;
    
    
        if(MapPlayableWidth >= MapPlayableHeight)
        {
            Scale = ScreenWidth / MapPlayableWidth;
            X_Offset = 0;
            ScreenLeft = ScreenLeft + X_Offset;
            Y_offset = (ScreenHeight - Scale * MapPlayableHeight) / 2;
            ScreenTop = ScreenTop + Y_offset;
            ScreenBottom = ScreenBottom - Y_offset;
            Height = ScreenBottom - ScreenTop;
            Width = ScreenWidth;
    
    
            First = true;
        }
        else
        {
            Scale = ScreenHeight / MapPlayableHeight;
            X_Offset = (ScreenWidth - Scale * MapPlayableWidth) / 2;
            ScreenLeft = ScreenLeft + X_Offset;
            ScreenRight = ScreenRight - X_Offset;    
            Y_offset = 0;
            ScreenTop = ScreenTop + Y_offset;
            ScreenBottom = ScreenBottom - Y_offset;
            Height = ScreenHeight;
            Width = ScreenRight - ScreenLeft;
    
    
            First = false;
        }    
     }
    
    
    int GlobalAdderX = -15;
    int GlobalAdderY =  90;
    
    
    void Minimap::GetUnitMinimapXY(unsigned int UnitX, unsigned UnitY, unsigned int& Xvar, unsigned int& Yvar)
    {
        float uX = UnitX;
        float uY = UnitY;
    
    
        uX -= MapLeft;
        uY -= MapBottom; //correct units position as mapleft/start of map can be >0
        Xvar = ScreenLeft + (uX / MapPlayableWidth * Width);
        Yvar = ScreenBottom - (uY / MapPlayableHeight * Height); //think about rounding mouse clicks igornore decimals
    
    
        Xvar += GlobalAdderX;
        Yvar += GlobalAdderY; //To adjust to 1920x1200 from 1920x1080
    }
    
    
    struct MINIMAP_COORD
    {
        unsigned int X, Y;
    };
    
    
    const float UnitRadius = 5;
    const float BaseRadius = 10;
    
    
    RECT GetRECT(unsigned int MX, unsigned int MY, bool Unit)
    {
        RECT R;
    
    
        if(Unit)
        {
            R.left   = MX - UnitRadius;
            R.right  = MX + UnitRadius;
            R.top    = MY - UnitRadius;
            R.bottom = MY + UnitRadius;
        }
        else
        {
            R.left   = MX - BaseRadius;
            R.right  = MX + BaseRadius;
            R.top    = MY - BaseRadius;
            R.bottom = MY + BaseRadius;
        }
    
    
        return R;
    }

  2. The Following User Says Thank You to MarineMarauderMedivac For This Useful Post:


  3. #2
    madBovine123 is offline Hacker


    Array
    Join Date
    Jun 2012
    Posts
    162
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Rep Power
    10
    Reputation
    513
    Having it handle any standard resolution is relatively easy, just use a known minimap side x,y co-ordinate for the users aspect ratio and then scale it to the users resolution. MyTeeOne pointed out that the minimap location can be found in the memory too.

    As for scaling, I too would be interested in this. A year ago I fucked around for hours trying to get it perfect, but couldn't work it out. It seems to be an issue with map width/height scaling, as some maps are almost perfect.

    Here's an example of supporting multiple aspect rations.

    All the external hacks on D3 seem to have some scaling issues.

    Code:
    ;--------------------;    
    Mini Map Setup
    ;--------------------
    SetMiniMap(byref minimap)
    {    
        ; minimap is a super global (though here it is a local)
        minimap := []
    
    
        minimap.MapLeft := getmapleft()
        minimap.MapRight := getmapright()    
        minimap.MapTop := getMaptop()
        minimap.MapBottom := getMapBottom()
    
    
        AspectRatio := getScreenAspectRatio()    
        If (AspectRatio = "16:10")
        {
            ScreenLeft := (27/1680) * A_ScreenWidth        
            ScreenBottom := (1036/1050) * A_ScreenHeight    
            ScreenRight := (281/1680) * A_ScreenWidth    
            ScreenTop := (786/1050) * A_ScreenHeight
    
    
        }    
        Else If (AspectRatio = "5:4")
        {    
            ScreenLeft := (25/1280) * A_ScreenWidth
            ScreenBottom := (1011/1024) * A_ScreenHeight
            ScreenRight := (257/1280) * A_ScreenWidth 
            Screentop := (783/1024) * A_ScreenHeight
        }    
        Else If (AspectRatio = "4:3")
        {    
            ScreenLeft := (25/1280) * A_ScreenWidth
            ScreenBottom := (947/960) * A_ScreenHeight
            ScreenRight := (257/1280) * A_ScreenWidth 
            ScreenTop := (718/960) * A_ScreenHeight
    
    
        }
        Else ;16:9 Else if (AspectRatio = "16:9") ; (16:10 falls into this else as well - its close enough that it scales well)
        {
            ScreenLeft         := (29/1920) * A_ScreenWidth
            ScreenBottom     := (1066/1080) * A_ScreenHeight
            ScreenRight     := (289/1920) * A_ScreenWidth 
            ScreenTop         := (807/1080) * A_ScreenHeight
        }    
        minimap.ScreenWidth := ScreenRight - ScreenLeft
        minimap.ScreenHeight := ScreenBottom - ScreenTop
        minimap.MapPlayableWidth     := minimap.MapRight - minimap.MapLeft
        minimap.MapPlayableHeight     := minimap.MapTop - minimap.MapBottom
    
    
        if (minimap.MapPlayableWidth >= minimap.MapPlayableHeight)
        {
            minimap.scale := minimap.Screenwidth / minimap.MapPlayableWidth
            X_Offset := 0
            minimap.ScreenLeft := ScreenLeft + X_Offset
            minimap.ScreenRight := ScreenRight - X_Offset    
            Y_offset := (minimap.ScreenHeight - minimap.scale * minimap.MapPlayableHeight) / 2
            minimap.ScreenTop := ScreenTop + Y_offset
            minimap.ScreenBottom := ScreenBottom - Y_offset
            minimap.Height := minimap.ScreenBottom - minimap.ScreenTop
            minimap.Width := minimap.ScreenWidth 
    
    
        }
        else
        {
            minimap.scale := minimap.ScreenHeight / minimap.MapPlayableHeight
            X_Offset:= (minimap.ScreenWidth - minimap.scale * minimap.MapPlayableWidth)/2
            minimap.ScreenLeft := ScreenLeft + X_Offset
            minimap.ScreenRight := ScreenRight - X_Offset    
            Y_offset := 0
            minimap.ScreenTop := ScreenTop + Y_offset
            minimap.ScreenBottom := ScreenBottom - Y_offset
            minimap.Height := minimap.ScreenHeight 
            minimap.Width := minimap.ScreenRight - minimap.ScreenLeft    
        }
        minimap.UnitMinimumRadius := 1 / minimap.scale
        minimap.UnitMaximumRadius  := 10
        minimap.AddToRadius := 1 / minimap.scale            
    Return
    }
    Oh and it's AutoHotkey - autoIt is for noobs


    Edit:

    Also you can read the unit's radius directly from the unitmodel. This would make it look a lot nicer too. To draw it on the minimap, just double the radius and subtract the radius from the units position to get the start location of the border.

    Code:
     /*      
    B_uStructure := base + 0x3665140            
    S_uStructure := 0x1C0
        O_uModelPointer := 0x8
    
    O_mMiniMapSize := 0x3AC
    */
    
    
    
    
     pUnitModel := ReadMemory(B_uStructure + (Unit * S_uStructure) + O_uModelPointer, GameIdentifier) 
     ; this just reads a certain number of bytes (O_mMiniMapSize+4) starting at: pUnitModel<< 5) & 0xFFFFFFFF 
     ReadRawMemory((pUnitModel<< 5) & 0xFFFFFFFF, GameIdentifier, uModelData, O_mMiniMapSize+4) 
     ; this just retries the radius value
     this.MiniMapRadius := numget(uModelData, O_mMiniMapSize, "int")/4096
    Last edited by madBovine123; 12-12-2013 at 04:37 PM.

  4. The Following User Says Thank You to madBovine123 For This Useful Post:


  5. #3
    MyTeeWun's Avatar
    MyTeeWun is offline Mentor
    Array
    Join Date
    Mar 2012
    Posts
    124
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Rep Power
    9
    Reputation
    279
    Quote Originally Posted by MarineMarauderMedivac View Post
    Code:
    unsigned int GetMapLeft(HANDLE Process) //Might return float?
    {
        unsigned int A = 0;
        DWORD N;
        ReadProcessMemory(Process, (LPCVOID)O_mLeft, &A, sizeof(unsigned int), &N);
        return A / 4096;
    }
    This code may give incorrect measurements since it truncates the decimal value rather than rounding it. A value of 150.9999999 would get converted to int as 150.

  6. The Following User Says Thank You to MyTeeWun For This Useful Post:


  7. #4
    mfedorov is offline Member
    Array
    Join Date
    Jun 2014
    Location
    Russia
    Posts
    48
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Rep Power
    6
    Reputation
    7
    Anyone can post finale code for this issue? It's really nightmare to make code work on all maps, over 60% work fine +- 1-4 pixels offsets, but others have to much offseting at 20 - 100 pixels. Thanks.

Similar Threads

  1. unit pos into pos on screen?
    By kentakuk in forum Starcraft 2 Coding
    Replies: 2
    Last Post: 08-03-2013, 04:28 AM
  2. [Help] Convert from structure Unit to Unit handle
    By accounttest in forum Warcraft 3 Hacks, bots and tools
    Replies: 1
    Last Post: 07-18-2013, 02:24 PM
  3. Unit XYZ world pos to screen coordinates
    By MarineMarauderMedivac in forum Starcraft 2 Coding
    Replies: 10
    Last Post: 05-13-2013, 06:08 AM
  4. Avatar Sizes?!
    By iR0Nik in forum Graphics
    Replies: 3
    Last Post: 03-07-2007, 07:37 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •