diff --git a/README.md b/README.md index 0663c8c..6ed6adf 100644 --- a/README.md +++ b/README.md @@ -1,27 +1,5 @@ -# Among Us regionInfo.dat creator +# among-us-region-info-py -This is a simple python script to generate the regionInfo file needed for custom servers in Among Us. +A simple Python script to generate the regionInfo.dat file, required to add regions to old versions of Among Us. -## Why? - -Compared to most other scripts and programs which all create the same regionInfo file, this program allows you to change the name that shows up in the bottom when in Among Us. - -I've also tried to make the code as readable and simple as possible. - -## Basic usage: - -```sh -python main.py "Server name" 127.0.0.1 -``` - -This will generate a file called regionInfo.dat in your current folder, which could then be placed at: -`C:\Users\username\AppData\LocalLow\Innersloth\Among Us\regionInfo.dat` - -This could for example be used to create a custom name for the server when using the [Impostor server](https://github.com/AeonLucid/Impostor) for among us - - -## Run online: - -You can run this online in [this repl.it project](https://repl.it/@Evla03/among-us-region-info-py) without the need to set up a local python instance. - -After running the program in the shell, [download the project zip from repl.it](https://docs.repl.it/tutorials/02-managing-files-using-repl-it#exporting-our-weather-data-files) and extract the regionInfo.dat file. +This is a fork of the original project: https://github.com/alvesvaren/among-us-region-info-py with a GUI. diff --git a/main.py b/main.py index b8288a5..a9d2d44 100755 --- a/main.py +++ b/main.py @@ -1,19 +1,15 @@ #!/usr/bin/python from sys import argv +import tkinter as tk +from tkinter import ttk, messagebox +import socket -# Currently the only possible value when using the impostor custom server SERVER_SUFFIX = "-Master-1" def gen_stream(region_name: str, ip_address: str = "127.0.0.1", port: int = 22023) -> bytearray: - """ - Generates the bytearray with the specified values. - Port should currently always be 22023 for it to work - """ - server_name = region_name + SERVER_SUFFIX - # Make sure all variables are within the correct length range if len(server_name) > 0xff: raise ValueError("Region name too long") if len(ip_address) > 0xff: @@ -21,26 +17,31 @@ def gen_stream(region_name: str, ip_address: str = "127.0.0.1", port: int = 2202 if port > 0x7fff: raise ValueError("Port too high") - # Append region name data = bytearray(len(region_name).to_bytes(5, "big")) data += region_name.encode("ascii") - # Append ip address string data.append(len(ip_address)) data += ip_address.encode("ascii") data.extend(0x1.to_bytes(4, "little")) - # Append server name data.append(len(server_name)) data += server_name.encode("ascii") - # Append ip address in byte form - ip_address_bytes = bytearray() - for value in ip_address.split("."): - ip_address_bytes.append(int(value)) + try: + ip_address_bytes = bytearray() + for value in ip_address.split("."): + ip_address_bytes.append(int(value)) + except (ValueError, AttributeError): + try: + resolved_ip = socket.gethostbyname(ip_address) + ip_address_bytes = bytearray() + for value in resolved_ip.split("."): + ip_address_bytes.append(int(value)) + except socket.gaierror: + raise ValueError(f"Invalid IP address or hostname: {ip_address}") + data += ip_address_bytes - # Append port data.extend(port.to_bytes(2, "little")) data.extend(0x0.to_bytes(4, "big")) @@ -48,51 +49,123 @@ def gen_stream(region_name: str, ip_address: str = "127.0.0.1", port: int = 2202 def write_file(region_name: str, ip_address: str = "127.0.0.1", file_name: str = "regionInfo.dat", port: int = 22023, *, log_bytes=False): - """ - Creates and writes the among us regionInfo.dat file. - Port should currently always be 22023 for it to work - - - Example: - ```py - try: - write_file("Example server", "127.0.0.1", port=12345)) - print("Success!") - except Exception as error: - print(error) - ``` - """ - - # Generate the file and save to the specified file name data = gen_stream(region_name, ip_address, port) with open(file_name, "wb") as file: file.write(data) - # Log the bytes to the console if specified if log_bytes: print("Writing", content_from_stream(data), "to", file_name) + return content_from_stream(data) + return None def content_from_stream(stream: bytearray) -> str: - """ - Create a string with the bytes in 'stream' - """ hex_array = [] for byte in stream: hex_array.append(hex(byte)) return f"{{{', '.join(hex_array)}}}" -if __name__ == "__main__": - if len(argv) < 2: - print('Usage: python main.py [ip-address] [file-name] [port]') - print('Example: python main.py "Server name" 127.0.0.1') +class AmongUsRegionCreator: + def __init__(self): + self.window = tk.Tk() + self.window.title("Among Us Region Creator") + self.window.geometry("550x450") + self.window.resizable(False, False) - # The standard exit code for usage errors - exit(64) - print(f"Creating file using arguments '{', '.join(argv[1:])}'") - try: - write_file(*argv[1:], log_bytes=True) - except Exception as error: - print("Error:", error) - exit(1) + main_frame = ttk.Frame(self.window, padding="10") + main_frame.grid(row=0, column=0, sticky=(tk.W, tk.E, tk.N, tk.S)) + + title_label = ttk.Label(main_frame, text="Among Us Custom Server Creator", font=("Arial", 14, "bold")) + title_label.grid(row=0, column=0, columnspan=2, pady=(0, 20)) + + ttk.Label(main_frame, text="Region Name:").grid(row=1, column=0, sticky=tk.W, pady=5) + self.region_entry = ttk.Entry(main_frame, width=30) + self.region_entry.grid(row=1, column=1, pady=5, padx=(10, 0)) + self.region_entry.insert(0, "EU") + + ttk.Label(main_frame, text="IP / Domain:").grid(row=2, column=0, sticky=tk.W, pady=5) + self.ip_entry = ttk.Entry(main_frame, width=30) + self.ip_entry.grid(row=2, column=1, pady=5, padx=(10, 0)) + self.ip_entry.insert(0, "127.0.0.1") + + ttk.Label(main_frame, text="Port:").grid(row=3, column=0, sticky=tk.W, pady=5) + self.port_entry = ttk.Entry(main_frame, width=30) + self.port_entry.grid(row=3, column=1, pady=5, padx=(10, 0)) + self.port_entry.insert(0, "22023") + + ttk.Label(main_frame, text="File Name:").grid(row=4, column=0, sticky=tk.W, pady=5) + self.file_entry = ttk.Entry(main_frame, width=30) + self.file_entry.grid(row=4, column=1, pady=5, padx=(10, 0)) + self.file_entry.insert(0, "regionInfo.dat") + + self.create_button = ttk.Button(main_frame, text="Create File", command=self.create_file, width=20) + self.create_button.grid(row=5, column=0, columnspan=2, pady=20) + + ttk.Label(main_frame, text="Output:").grid(row=6, column=0, sticky=tk.W, pady=5) + self.output_text = tk.Text(main_frame, height=10, width=60, font=("Courier", 9)) + self.output_text.grid(row=7, column=0, columnspan=2, pady=5) + self.output_text.config(state=tk.DISABLED) + + self.status_label = ttk.Label(main_frame, text="Ready", foreground="green") + self.status_label.grid(row=8, column=0, columnspan=2, pady=10) + + self.window.bind('', lambda event: self.create_file()) + + def create_file(self): + try: + region_name = self.region_entry.get().strip() + ip_address = self.ip_entry.get().strip() + port = int(self.port_entry.get().strip()) + file_name = self.file_entry.get().strip() + + if not region_name: + raise ValueError("Region name cannot be empty") + if not ip_address: + raise ValueError("IP address/Domain cannot be empty") + if not file_name: + raise ValueError("File name cannot be empty") + + result = write_file(region_name, ip_address, file_name, port, log_bytes=True) + + self.output_text.config(state=tk.NORMAL) + self.output_text.delete(1.0, tk.END) + self.output_text.insert(1.0, f"File created successfully!\n\nBytes written:\n{result}") + self.output_text.config(state=tk.DISABLED) + + self.status_label.config(text=f"File '{file_name}' created successfully!", foreground="green") + messagebox.showinfo("Success", f"File '{file_name}' has been created successfully!") + + except ValueError as e: + self.output_text.config(state=tk.NORMAL) + self.output_text.delete(1.0, tk.END) + self.output_text.insert(1.0, f"Error: {str(e)}") + self.output_text.config(state=tk.DISABLED) + + self.status_label.config(text="Error occurred", foreground="red") + messagebox.showerror("Error", str(e)) + + except Exception as e: + self.output_text.config(state=tk.NORMAL) + self.output_text.delete(1.0, tk.END) + self.output_text.insert(1.0, f"Unexpected error: {str(e)}") + self.output_text.config(state=tk.DISABLED) + + self.status_label.config(text="Error occurred", foreground="red") + messagebox.showerror("Error", f"An unexpected error occurred:\n{str(e)}") + + def run(self): + self.window.mainloop() + + +if __name__ == "__main__": + if len(argv) > 1: + print(f"Creating file using arguments '{', '.join(argv[1:])}'") + try: + write_file(*argv[1:], log_bytes=True) + except Exception as error: + print("Error:", error) + exit(1) + else: + app = AmongUsRegionCreator() + app.run() \ No newline at end of file