
# -*- coding: utf-8 -*-

import sys

def lire_fichier_bin(file_path):
    """ Lit un fichier binaire et renvoie son contenu. """
    with open(file_path, 'rb') as file:
        return file.read()

def ecrire_fichier_bin(file_path, data):
    """ Écrit des données dans un fichier binaire. """
    with open(file_path, 'wb') as file:
        file.write(data)

def modifier_donnees(original_data):
    """ Modifie les données du fichier binaire selon les spécifications. """
    modified_data = bytearray(original_data)
    
    # Liste complète des modifications à appliquer
    modifications = [
        (130, 0x6e),
        (131, 0x74),
        (136, 0x70),
        (137, 0x07),
        (138, 0x11),
        (139, 0x11),
        (140, 0x11),
        (141, 0x11),
        (142, 0xff),
        (252, 0x6e),
        (253, 0xa3),
        (254, 0xc3),
        (255, 0x83),
        (258, 0x81),
        (259, 0xf4),
        (264, 0x70),
        (265, 0x07),
        (266, 0x11),
        (267, 0x11),
        (268, 0x11),
        (269, 0x11),
        (270, 0xff),
        (380, 0x6e),
        (381, 0xa3),
        (382, 0xc3),
        (383, 0x83),
        (32898, 0x29),
        (32899, 0xb5),
        (32904, 0x70),
        (32905, 0x07),
        (32906, 0x11),
        (32907, 0x11),
        (32908, 0x11),
        (32909, 0x11),
        (32910, 0xff),
        (33020, 0x6e),
        (33021, 0xa3),
        (33022, 0xc3),
        (33023, 0x83),
        (33026, 0xc6),
        (33027, 0x35),
        (33032, 0x70),
        (33033, 0x07),
        (33034, 0x11),
        (33035, 0x11),
        (33036, 0x11),
        (33037, 0x11),
        (33038, 0xff),
        (33148, 0x6e),
        (33149, 0xa3),
        (33150, 0xc3),
        (33151, 0x83)
        # Ajoutez ici toute autre modification nécessaire
    ]

    print("Application des modifications...")
    for adresse, valeur in modifications:
        modified_data[adresse] = valeur
        print(f"Modification à l'adresse {adresse}: {original_data[adresse]} -> {valeur}")

    return modified_data

def process_file(original_file_path, modified_file_path):
    """ Lit, modifie et écrit le fichier de cartographie moteur. """
    print(f"Lecture du fichier original : {original_file_path}")
    original_data = lire_fichier_bin(original_file_path)

    print("Modification des données...")
    modified_data = modifier_donnees(original_data)

    print(f"Écriture des données modifiées dans : {modified_file_path}")
    ecrire_fichier_bin(modified_file_path, modified_data)
    print("Les modifications ont été appliquées avec succès.")

if __name__ == "__main__":
    if len(sys.argv) != 3:
        print("Usage: python app.py <chemin_fichier_original> <chemin_fichier_modifie>")
    else:
        process_file(sys.argv[1], sys.argv[2])
