Coder Social home page Coder Social logo

electricitymachine / scr-sgplus Goto Github PK

View Code? Open in Web Editor NEW
11.0 3.0 6.0 1.02 MB

A Python macro script that allows signallers in the ROBLOX game SCR to speed up commonly performed actions, such as signal changes.

License: GNU Affero General Public License v3.0

Python 97.63% Batchfile 2.37%
macros python roblox scr

scr-sgplus's Introduction

SG+: an SCR signalling macro

What is it?

SG+ is a Python macro script that speeds up your signalling by allowing you to open the camera view, toggle rollback settings, and change signal aspects with one button and no mouse clicking.

But won't this get me demoted?

You will not be banned or demoted just for using this script. The responsibility is still on the signaller to route trains in a safe and proper manner. It is not an exploit and does not automate signalling entirely; it only speeds up common actions. If you've encountered trouble with a member of staff while using this script, contact me as soon as possible or open an issue.

Installation

Binary (preferred)

  1. Download sgplus.exe from the latest releases page
  2. Run sgplus.exe. Some antiviruses may detect the program as malware. If you receive a SmartScreen popup, click "More Info" then press "Run Anyway." This is a false-positive, you may have to add an exclusion to your antivirus software for the program to run. Any binary attached to a release is the same as the one built automatically here

From Source

This method is intended for those who want to contribute to the project or modify the script.

  1. Download and install the latest Python 3 installer from the Python Downloads Page
    • Make sure to check the box during installation which adds Python to PATH. Labeled something like Add Python 3.X to PATH
  2. Download the latest release in the Releases section of this repo. Click on "Source Code (zip)"
    • Note: If you want the development release with all the latest changes, press the green "Code" button on the main page of this repo and press "Download ZIP". The following instructions still apply.
  3. Extract the folder to your desired location. You can do this natively in Windows by opening the .zip folder and pressing "Extract all" at the top.
    • Note: If you are updating from an older version, please delete the old version of the script before extracting the new version. Failure to do so may cause conflicts and bugs.
  4. Run install.bat and answer the prompts.

Usage

  • Launch the program by running the .exe or start.bat
  • Mouse over a signal, then:
    • press 1, 2, or 3, corresponding to the desired signal aspect.
    • press C to enter camera view, press C again to exit.
    • press R to toggle rollback.
    • press F to enter or exit the signal's side menu.
  • Press F1 to enable or disable the script.
  • Use numpad 1-7 (1 is A, 2 is B, etc.) to copy zone opening messages to your clipboard.

Configuration

After your first startup, a config.toml file will be placed in the directory the script is located in. If you want to change the default keybinds, speed up/slow down the script, or change the zone opening messages, you can edit this file. Although most of it should be self-explanatory, there is a caveat with the keybinds:

  • Because of how the script interfaces with the keyboard, setting a key as "1" will also trigger anything bound to Num 1, and vice versa. To solve this, SG+'s default configuration uses scancodes, identifying the specific key we want to bind to. Here is a list of all Windows scancodes.
    • Example: If I want to change the camera button to F, I would go into config.toml and edit toggle_signal_camera = "C" to toggle_signal_camera = "F", or using scancodes from that webpage, toggle_signal_camera = 46.
  • A future release of SG+ will greatly simplify this procedure.

I've found an issue!

Great! Please open an issue or contact me below.

Some issues include (but are not limited to):

  • Script fails to run or install
  • Certain signals do not respond to the script when trying to change aspects or enter/exit camera view
  • Entering/exiting camera view or toggling rollback does not work
  • Script locks up after some time (#60)

Roadmap

  • TRTS Audible Warning
  • Visual script status indicator (#36)
  • Automatic terminus station setup
  • Interactive keybind prompts/config (#34)
  • Automatic rollback preferences (#37)
  • Become FPS-independent
  • (Possibly) Rewrite in Rust or another performant language

See the open issues for a full list of proposed features (and known issues).

License

By using this script, you must adhere to the license terms in the LICENSE file.

Contact information

Discord: @electricity.machine ROBLOX: Electricity_Machine

scr-sgplus's People

Contributors

aliceford avatar cvbnxx avatar electricitymachine avatar polax3 avatar renovate[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

scr-sgplus's Issues

Add auto updater

Not sure if this is even possible, but it would be cool if the script could fetch the release from Github and replace itself.

Have screen_grab function return numpy array

Instead of converting an image to a numpy array in the color check functions, we might be able to reduce lag by returning a numpy array instead of a Pillow image. Doing this would require us to change how we crop images, but a special function could be used to make this easier. This is because cropping an image already in the numpy array format requires slicing, as opposed to the current method.

Feature request: automatic toggle for chatting

( By cdexstra1 ) :

Add a setting (or integrate), that the script will toggle OFF automatically when you press "/" (Default keybind for opening chat)
and toggle ON automatically when you press "enter" (Default keybind for sending a message)

This should make communication easier, and it will remove the need to constantly press F1 to toggle while communicating and signalling at the same time.

Add known SCR issue re: backspace not closing dialog to README

Occasionally, pressing backspace brings up the "Return to menu" prompt instead of closing the signal dialog box or any other desk menus. This requires the user to switch servers. The documentation should be updated to alert users to this bug as it is not the script's fault.

This bug has been experienced by myself and 3 others have reported it so far. A workaround may be available, but the chance of getting into a bugged server is random chance.

Use funcName in logger

In the current implementation, function names are manually specified in each logger.debug call. logging provides funcName as an attribute that can be referenced when formatting log output.

Add script status indicator

It would be helpful to have a visual status indicator for the script instead of it being audio only. Could be as simple as a bar at the top of the user's screen/ROBLOX window.

Add option to use legacy timing method

Due to increased reports of frametime-based waiting periods causing issues out of the box, we should give users the option to switch to the older but potentially more reliable method of waiting a set period of time instead of a number of frames.

Zone message key bindings are incorrect

In v0.4.1 a regression was introduced that caused the zone message keybinds to be assigned to the Insert, Delete, End, and Pg Dn keys. This was caused by me not being able to read, or more specifically, failing to double-check the scancodes while writing the new configuration. Affected lines:

SCR-SGPlus/script.py

Lines 495 to 501 in 52c683d

"zone_a_message": 79,
"zone_b_message": 80,
"zone_c_message": 81,
"zone_d_message": 82,
"zone_e_message": 83,
"zone_f_message": 84,
"zone_g_message": 85,

The fix for this will require automatic configuration migration that's dependent on previous version.

Thanks to LookUp8393 on the SCR Discord for alerting me to this issue!

Additionally, there was an epic SemVer fail by not incrementing the MINOR version when a feature was added (config update). Oops!

Script fails to detect dialogbox at smallest window size

If you make the ROBLOX window the smallest it can be and use CTRL + scroll to zoom in all the way, you will find that the script fails to recognize the dialogbox when the mouse cursor is positioned around the bottom 2 pixels of the signal's clickbox. See screenshot.

DEBUG: click_signal: called
DEBUG: sleep_frames: Sleeping for 3 frame(s)
DEBUG: scan_for_dialog: called
DEBUG: find_controlled_sig_dialog: called
DEBUG: find_controlled_sig_dialog: made it to generator
DEBUG: check_color_percentage_single: called
DEBUG: check_color_percentage_single: not enough white pixels found for array size. numpixels: 0.0
DEBUG: check_color_percentage_single: called
DEBUG: check_color_percentage_single: not enough white pixels found for array size. numpixels: 0.0
DEBUG: find_controlled_sig_dialog: result: False

Disabling status indicator throws an error

If you set enable_status_indicator to false and press the keybind to toggle the macro, the following exception is thrown:

Traceback (most recent call last):
  File "threading.py", line 1073, in _bootstrap_inner
  File "threading.py", line 1010, in run
  File "keyboard\_generic.py", line 58, in process
  File "keyboard\__init__.py", line 218, in pre_process_event
  File "keyboard\__init__.py", line 649, in <lambda>
  File "script.py", line 671, in <lambda>
  File "script.py", line 285, in toggle_disable
  File "script.py", line 74, in update_label
NameError: name 'label' is not defined

This causes the script to stop working entirely.

Update to Python 3.12

  • Upgrade modules to minimum supported version for 3.12
  • Verify functionality and performance
  • Update README

Evaluate support for Python 3.9+

It would be cool to support multiple Python versions once tests are written and benchmarking is easier to perform.

I may also investigate any performance benefit with switching to PyPy 3.10 versus 3.12. I am unable to find CPython 3.12 vs latest PyPy benchmarks, but this should be trivial to do ourselves for image processing and other expensive functions.

Use numpy instead of Pillow image functions

Currently, we convert images to numpy arrays multiple times when checking for colors. If we start working with a numpy array from the beginning, i.e. the screenshot function returns a numpy array, there could be a significant speed increase.

Compare versions properly in update checker

Currently, we check if the latest release tag from Github is the same as the string that's specified in the script. Instead, it should be properly compared to see if the user's script is actually older than the current release. This would allow development versions to keep the update checker enabled.

Account for function calls in sleep_frames

Potentially low IQ suggestion, just put it here to help me remember for the future.

To account for slower functions blocking script actions, a minor optimization could be implemented that counts the execution time of function calls in addition to frames when calling sleep_frames. For example:

SCR-SGPlus/script.py

Lines 123 to 133 in 928f0d9

def click_signal(sig: str) -> None:
logging.debug("called")
coord = mouse.get_position()
mouse.click("left")
sleep_frames(3)
result, image = scan_for_dialog("signal", coord[0], coord[1])
if result:
logging.debug("scan_for_dialog returned true")
sleep_frames(3)
press_and_release(sig)
press_and_release("backspace")

In this function, we click the left mouse, then scan for the dialogbox, and if found, sleep another 3 frames before changing the signal and pressing backspace. Instead, we could sleep for the execution time, in frames, of scan_for_dialog + some const.

Say that scan_for_dialog takes 0.5 frames, and we want to wait 3 frames in total (current method's intentions). We end up waiting for 3.5 frames instead of just 3, because we do not take execution time into account. If this feature is implemented, we would only need to artificially wait for 2.5 frames (3 - function time) to meet our 3 frame threshold. This would lead to more uniform timing across different systems and function calls, and could help lay the groundwork for #45. Might also depend on #56, in case this method is less reliable and needs broader testing.

Default AVG_FPS should be 30

In order to cover a wider range of computer specs, the default FPS value should be 30 instead of 40, based on some communications with users having issues with the script. Requirement for #26.

Save and restore rollback preferences

From cdexstra1:
"considering everyone only wants to change less then about 10 signals per zone on their rollback preferences, maybe you could add a way for this to be done automatically?"

This would depend on the methods required for automatic terminus setup, which may be in scope for a future version. The user would be able to enter a zone setup mode where the script automatically enables or disables rollbacks based on a previous config. This would require setting the zoom level, location, and keeping track/knowing which signals to manipulate.

Add release workflow to GHA

Instead of having to manually upload a binary and fill out a changelog, it would be cool if I could write the changelog ahead of time, then press a button to automatically tag and release a new version.

It would be best to implement unit tests before this.

Combine controlled and uncontrolled signal check into one function

If colors are found, return True like normal. If colors are not found, but the white dots of an uncontrolled box are found, return True. If nothing is found, return False. This has the benefit of using one less capture and potentially speeding up uncontrolled signal functions, such as C and F for camera and sidemenu, since it doesn't have to repeat the screengrab. We can return an enum, maybe, for what type of signal box we've found (SIGNAL_DIALOG_CONTROLLED, SIGNAL_DIALOG_UNCONTROLLED, None).

Essentially, it's a better version of 9c135fa.

Once implemented, closes #27.

Reduce number of screen captures across all functions

According to some recent profiling runs, screen captures take a significant amount of time, repeated multiple times per function. This explains why click_camera() is so slow on uncontrolled signals, because it captures the screen a total of 4 times. Screen captures are expensive, thus, reducing the number of captures would lead to an increase in performance.

Add keybind for opening and closing signal side menu

Can reuse the camera button logic for finding the side menu. This should be implemented so you can view trains in the signal block and estimated departure time without having to click on the signal, press the menu, then click again to close it.

Default keybind as F would be convenient, but may result in fat-fingering when moving around the zone. Not sure what else it could be.

Zone D message is censored

Roblox is censoring "Zone D (Morganstown to Leighton West) is now under manual signaling control."
and you should probably change it to "Zone D (Morganstown to LW) is now under manual signaling control."
See screenshot for more details
Capture d'écran 2024-01-21 154629

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

github-actions
.github/workflows/build.yaml
  • crazy-max/ghaction-upx v3
  • actions/checkout v4
  • actions/setup-python v5
  • actions/upload-artifact v4
.github/workflows/lint.yml
  • actions/checkout v4
  • actions/setup-python v5
  • ubuntu 22.04
pip_requirements
requirements.txt
  • certifi ==2024.2.2
  • charset-normalizer ==3.3.2
  • colorama ==0.4.6
  • idna ==3.6
  • keyboard ==0.13.5
  • mouse ==0.7.1
  • mss ==9.0.1
  • numpy ==1.26.3
  • PyAutoIt ==0.6.5
  • pillow ==10.3.0
  • pyperclip ==1.8.2
  • pywin32 ==306
  • requests ==2.31.0
  • semver ==3.0.2
  • tomli_w ==1.0.0
  • urllib3 ==2.2.0

  • Check this box to trigger a request for Renovate to run again on this repository

Script randomly stops working

I have noticed this on multiple versions, including 928f0d9. It will stop responding to user inputs and not function correctly after a random amount of time. I am unable to reproduce the issue when enabling debug mode.

Dialogbox offset doesn't work properly at lower resolutions

As the window height lowers, the x coordinate seems to not compensate properly for the change in scale. This causes the offset to not be applied correctly. More testing will be needed.

Capture from controlled signal (dialogbox was detected)

capture2

Capture from uncontrolled signal (dialogbox not detected)

capture

Add support for station cameras

Depends on #65 for a more generic implementation of the dialog scanning function. Adding yet another color and area to check for may lead to lag, and it's debatable whether station cameras are useful to begin with. Additional optimization may be necessary (for example, potentially moving away from numpy) to add this without slowing the script down too much.

Interactive configuration handler

After #26, it might be nice to have a terminal configuration helper, whereby you press a button to enter config mode, and can remap keys. This would address the problem of user-configurable keybinds and allow us to operate exclusively on scancodes instead of the keyboard module's canonical names, which would fix a potential issue if a user specifies "1" in addition to "Num 1", since they evaluate to the same thing.

Settings should be configurable by the user

Related to #7, the user should be able to easily configure FPS, ping, and keybinds via a JSON or ini file. The config file must be generated at runtime if one is not found. Doing so would allow users of the binary to adjust settings to their liking.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.