E1Bos / VALocker

VALocker: Valorant Agent Instalocker. Automate VALORANT agent selection with ease.
MIT License
11 stars 1 forks source link

4k Resolution Support #2

Closed Brownwarrior47 closed 4 months ago

Brownwarrior47 commented 5 months ago

Is your feature request related to a problem? Please describe. I play on 4k, or 2k res because my monitor isnt 1080p the program always picks something else.

Describe the solution you'd like 4k support, or a way to pick the coordinates of the agent manually

E1Bos commented 4 months ago

Hello, thanks for your request, I love seeing others' interest in my hobby project.

There is a hacky way to solve your problem, I plan on releasing VALocker 2.x soon-ish, which is planned to have a "calibrate" feature to support almost, if not all resolutions. However, using VALocker 1.6.x, there is a solution, but it's dependent on what the issue is.

If VALocker isn't selecting the right agent, it can be for some reasons, and there are only 2 real solutions. I'm assuming that it does detect when you're in the agent select screen, if it doesn't, (i.e. it doesn't move the mouse AT ALL when in the agent select screen, it always says "Locking") it may be really hard to change the values as they're hardcoded into instalocker.py, and would require you to use the Python installation and then go through my mess of a program, but it can be done.

If it does detect the agent selection screen, first of all, make sure you have all the correct agents selected in the "Agent Toggle" tab on the left-hand side. Every agent you have in-game needs to be selected, since agents are presented alphabetically in the agent select screen. If all the agents you have unlocked are selected (and none of the agents you don't have unlocked), there's one last thing you can do to get VALocker to work.

Once you've tried all that, the only solution is to modify data/config.json in your VALocker folder. You're interested in everything inside the key BOX_INFO. There are several keys, all of which you might need to change. However, it's key to note that since VALocker randomizes where it clicks, all pixels need to be within the selectable part of each element. I recommend using something like ShareX and using the Ctrl+PrintScreen keybind to get perfect X and Y coordinates.

Here are the keys you might need to change:

These are the most likely culprits:

The best way to configure this is to play a custom game alone with the options "Allow Cheats" and "Hide Match History" turned on. Then, you can hover over the top-left-most agent and use your screen capture keybind. With ShareX, Ctrl+PrintScreen will pop up X and Y coordinates and a helpful magnifier.

Here's an example of what you're aiming for, note that the top-left-most-pixel is the pixel that is highlighted, not the corner of the box. I've noted a 2px gap between the border of the box and the start of the tile, but your mileage may vary. VALocker TOPLEFT example

Aside from that, there is no current user-friendly way to solve your issue, but if you're willing to get your hands dirty-ish, I'd love to know if you managed to solve your problem.

Please feel free to ask me any additional questions, although response time may very, since I'm taking exams for my uni course.

Brownwarrior47 commented 4 months ago

Hello, and thank you for the detailed response!

I've followed your suggestions and used ShareX to capture the precise coordinates necessary for config.json. However, even after accurately setting SIZE, LOCK_SIZE, XDIST, YDIST, LOCK_COORDS , and TOPLEFT for my 4K resolution, the mouse does not move at all during the lock screen, suggesting that there may be hardcoded values in the instalocker.py that still need to be addressed.

Here are the new values I calculated for my 4K setup:

{
    "BOX_INFO": {
        "SIZE": 147,
        "LOCK_SIZE": [
            469,
            117
        ],
        "COLUMNS": 9,
        "XDIST": 25,
        "YDIST": 25,
        "LOCK_COORDS": [
            1685,
            1403
        ],
        "TOPLEFT": [
            1176,
            1610
        ]
    }
}

Given this situation, I suspect changes might also be necessary within the main Python script. I've been using the Python script (VALocker.pyw) directly rather than the executable, and I could try editing the script with some guidance from you. Could you possibly guide me towards what sections or lines might need modifications to accommodate the changes for a 4K resolution? Any pointers would be greatly appreciated, especially since the mouse never moves when in 4K resolution.

Aside from that, I'm eager to help improve and test VALocker for higher resolutions, which could be beneficial for the upcoming 2.x release you mentioned. I'm looking forward to your suggestions and thank you again for your assistance!

Please let me know if there's anything else I should consider or any additional details you need.

Feel free to ask any further questions, and good luck with your exams!

E1Bos commented 4 months ago

If the mouse is not moving at all, that means it's not detecting the agent selection screen.

However, since you're already using the python file, the fix should be fairly easy. VALocker works by taking screenshots and comparing them to known pixel patterns, using a different resolution requires excessive calibrating or testing, which is why I put off implementing it as a feature for so long.

In data/instalocker.py, there's a variable self.coords (~line 83). This variable points to a dict: [str, tuple[int, int, int, int]] the tuple points to the screen coords (x-start, y-start, x-end, y-end). Changing the coordinates for the locking key should fix detection, however you may need to change the other keys to make detecting when you are out of a game and in the main menu work.

You can also skip changing the other keys and manually change states using the "Current Task" button, which is easier in the short term.

Below is where the locking key coords point, again, a custom game with ShareX should be sufficient to calculate the position.

locking position

The lower yellow bar is one of the few constant GUI elements in the agent select screen. The y-start should be the same value ScreenX lists as the Y value, and the y-end should be that value +1, i.e. using the image as reference, y-start is 782, and y-end is 783. The x-start should be any pixel across the line, same as what ShareX shows, and can be any width as long as all the pixels are the same color. By default it is 5 pixels wide, which helps with false-positives, but there are other measures, so feel free to make it whatever size you like. However, you may see a performance increase with a smaller size, although I am not sure how much and doubt you'd be able to tell the difference.

While doing this, you could also take note of the color of the bar, I'm not sure how you'd do it. I've found taking a screenshot and using a color picker like the one in Adobe PS tends to change the colors, so I use the PowerToys color picker, but any color picker should be sufficient. If the value is different, you'll need to change the locking key in self.pixel_patterns (line ~97), with the values in (R, G, B). I'd skip this for the time being since the GUI colors are most likely the same, unless you are using a image sharpening modifier in your GPU settings. Since it's a very thin line with pixel-perfect accuracy, It can be somewhat hard to achieve consistent results on other machines.

Hopefully this solves your issue. While doing this, you may also want to directly run the instalocker.py file in your IDE or Terminal, so you can see any errors, it'll run just the same as the .pyw extension, but will open a terminal window as well.

Those changes should accommodate your 4K resolution, although I can't be certain as I don't have access to a 4K monitor and have never been able to test it.

Finally, if you keep getting the "You are not playing in 1920x1080" popup, you could also change the function get_game_resolution, on lines 3347 -> 3463 (the if block) to:

if self.screen_resolution != (1920, 1080):
                self.is_1920x1080 = False

Although the code is a bit of a mess, I've tried to make it as modular as possible, I hope you're able to accommodate your changes. Please let me know if this works for you, as I'm yet to hear much feedback from other users.

Brownwarrior47 commented 4 months ago

Hello, thank you so much for your detailed guidance!

I've implemented the suggested changes, and the script is now working perfectly. Here’s what I did:

  1. Updated the Locking Coordinates:

    • I modified the self.coords dictionary in the instalocker.py script to update the locking coordinates to the following values for my 4K resolution:
      self.coords = {
       "locking": (1892, 1565, 1893, 1566),  # Updated for 4K resolution
       ...
      }
  2. Checked the Color:

    • I verified that the color of the yellow bar in the agent selection screen remains the same.
  3. Modified the Resolution Checking:

    • I updated the get_game_resolution function to handle 4K resolution by adding it to the list of acceptable resolutions and updating the message:
      if self.screen_resolution not in [(1920, 1080), (3840, 2160)]:  # Added 4K resolution
       self.is_1920x1080 = False
       ErrorPopup(
           window_geometry=self.winfo_geometry(),
           title="Warning",
           message=f"Your game resolution is {self.screen_resolution}.\nPlease change it to 1920x1080 or 3840x2160\nin fullscreen or windowed fullscreen",
           colors=self.button_colors,
           main_font=self.main_font,
       ).get_input()

By making these changes, the script now correctly handles 4K resolution. I appreciate your help in guiding me through these adjustments.

E1Bos commented 4 months ago

Hello, I'm very glad you managed to make VALocker work properly given it wasn't designed for other resolutions.

While changing the resolution checking to also accept 4k, the main use of it is to disable the "Tools", namely Auto-Drop Spike from enabling, which can cause issues since it uses pure-white as a detection color and sends keyboard commands with no cooldown (i.e. will spam keys). That being said, just be wary with the "Auto-Drop Spike" tool, "Anti-AFK" should work just fine.

Also, upon further inspection, it seems that the pixel locations are a multiple of the original 1920x1080 location, off by a digit or so, which makes sense. I assume you're playing at 16:9. This is very helpful, as I may be able to calculate the location for certain resolutions.

If you have any other questions or have any feedback about the UI, feature implementation, or possible future features, please feel free to reach out to me via another issue or otherwise.

I'll also link this issue in the project readme for anyone interested in making VALocker work with some other resolution.

E1Bos commented 4 months ago

@Brownwarrior47, I am about to release VALocker v2.0.0, and as the only person who opened an actual issue related to other resolutions, I thought it would be nice to inform you and help you migrate the locking config you provided here to the new system I have currently implemented. I have no way to verify if the file works, so I can't add it as an official file just yet.

I do suggest you also read the guide, as it'll help you fully automate VALocker, I hope I've made it as easy to follow as one could hope.

Heres the file brown-warrior-47-config.yaml file:

# If the configuration is custom, do NOT change
# VALocker will attempt to update the configuration file
# if the configuration is not custom, this may crash the program
custom: True
# --------------------------------------------------
# Title of the configuration
title: 4k - Brown Warrior 47
# --------------------------------------------------
# The location of the agent buttons
# size: size of the agent buttons
# columns: number of columns
# xDistance: x distance between the columns
# yDistance: y distance between the rows
# start: the top left corner of the first agent button
agentButtons:
  size: 147
  columns: 9 # Default value, may be different
  xDistance: 25
  yDistance: 25
  start: [1176, 1610]
# --------------------------------------------------
# The location of the lock button
# size: size of the lock button
# location: the top left corner of the lock button
lockButton:
  size: [469, 117]
  location: [1685, 1403]
# --------------------------------------------------
# Regions that are checked to see when to initiate the lock
# xCoord: x coordinate of the top left corner of the region
# yCoord: y coordinate of the top left corner of the region
# width: width of the region
# height: height of the region
# color: color of the pixel in the region to match
lockRegion:
  xCoord: 1892
  yCoord: 1565
  width: 1 # Default value, may be different
  height: 1 # Default value, may be different
  color: [234, 238, 178] # Default value, may be different
# --------------------------------------------------
# Regions that are checked to see when the user is not in a game
# xCoord: x coordinate of the top left corner of the region
# yCoord: y coordinate of the top left corner of the region
# width: width of the region
# height: height of the region
# color: color of the pixel in the region to match
waitingRegions:
  # - xCoord: <x Coordinate, [x]>
  #   yCoord: <y Coordinate, [x]>
  #   width: <Width, [x]>
  #   height: <Height, [x]>
  #   color: <Color, [r, g, b]>
  # - xCoord: <x Coordinate, [x]>
  #   yCoord: <y Coordinate, [x]>
  #   width: <Width, [x]>
  #   height: <Height, [x]>
  #   color: <Color, [r, g, b]>
  # - xCoord: <x Coordinate, [x]>
  #   yCoord: <y Coordinate, [x]>
  #   width: <Width, [x]>
  #   height: <Height, [x]>
  #   color: <Color, [r, g, b]>
  # - xCoord: <x Coordinate, [x]>
  #   yCoord: <y Coordinate, [x]>
  #   width: <Width, [x]>
  #   height: <Height, [x]>
  #   color: <Color, [r, g, b]>
  # - xCoord: <x Coordinate, [x]>
  #   yCoord: <y Coordinate, [x]>
  #   width: <Width, [x]>
  #   height: <Height, [x]>
  #   color: <Color, [r, g, b]>
# --------------------------------------------------

Also, I've added an easy way to compile VALocker into a .exe yourself.