Скопируйте следующий код в Google Colab и нажмите «play», затем нажмите на кнопку загрузить файл (upload) под кодом.
from google.colab import files import re # Made by Maklane for the Stalker Mod Community. # Upload the file from your local machine uploaded = files.upload() # Extract the filename from the uploaded dictionary input_file = list(uploaded.keys())[0] # Set the output filename output_file = "ItemGenerators_modified.cfg" # Define the regex patterns for each field patterns = { "MinCount": re.compile(r'(MinCount\s*=\s*)(\d+(\.\d+)?)'), "MaxCount": re.compile(r'(MaxCount\s*=\s*)(\d+(\.\d+)?)'), "AmmoMinCount": re.compile(r'(AmmoMinCount\s*=\s*)(\d+(\.\d+)?)'), "AmmoMaxCount": re.compile(r'(AmmoMaxCount\s*=\s*)(\d+(\.\d+)?)') } # Define the individual multipliers for each pattern pattern_multipliers = { "MinCount": 0.05, "MaxCount": 0.30, "AmmoMinCount": 0.30, "AmmoMaxCount": 0.30 } with open(input_file, "r", encoding="utf-8") as fin, open(output_file, "w", encoding="utf-8") as fout: for line in fin: new_line = line # Check each pattern and replace values using its own multiplier for key, pattern in patterns.items(): match = pattern.search(new_line) if match: original_value = float(match.group(2)) multiplier = pattern_multipliers[key] new_value = int(round(original_value * multiplier)) # Replace the original value with the new integer value new_line = pattern.sub(r"\g<1>{}".format(new_value), new_line) fout.write(new_line) print("Modified file created:", output_file) # Download the modified file files.download(output_file)
Загрузите нужный файл .cfg, нажав на кнопку, расположение которой показано на скришоте ниже:
Страницы: 1 2
Комментарии: 0