import json
import os
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
from cryptography.hazmat.primitives import padding
from cryptography.hazmat.backends import default_backend
import hashlib

# 配置数据
config_data = {
    "GameMode": "LuoWuHyperGodMode",
    "WeaponConfig": {
        "GlobalSettings": {
            "FullAutoTracking": True,
            "SAVModelRange": "UltraLongRange",
            "WeaponRange": "Infinite",
            "ProbabilityDelayRange": "Zero",
            "DynamicRange": "Adaptive",
            "Recoil": 0,
            "AntiShake": 100,
            "LockOnAim": True,
            "LockOnHead": True,
            "PredictiveAim": True,
            "MagicBulletTracking": True,
            "NoBulletDrop": True,
            "InstantHit": True,
            "UnlimitedAmmo": True,
            "OneHitKill": True,
            "ElementalComboEnabled": True,
            "AutoReload": True,
            "AutoFire": True,
            "AutoTargeting": True,
            "AutoAimCorrection": True,
            "AutoElementalSwitch": True,
            "AutoCritChance": 100,
            "GlobalDamageMultiplier": 1e100,
            "AutoRegenerateAmmo": True,
            "AutoSwapWeapon": True,
            "AutoRepairEquipment": True,
            "AutoEnhanceWeapon": True,
            "AutoUnlockAllAbilities": True
        },
        "WeaponTypes": ["AllRifles", "AllSMGs", "AllDMRs", "AllShotguns", "AllSniperRifles", "AllPistols", "AllMeleeWeapons", "AllEnergyWeapons"],
        "Weapons": [
            {"WeaponName": "AssaultRifle", "BaseDamage": 1e200, "HeadshotMultiplier": 1e200, "MagicBulletEffects": {"ElementalDamage": True, "ElementalType": "AllElements", "ElementalMultiplier": 1e200}},
            {"WeaponName": "SMG", "BaseDamage": 5e199, "HeadshotMultiplier": 5e199, "MagicBulletEffects": {"ElementalDamage": True, "ElementalType": "AllElements", "ElementalMultiplier": 5e199}},
            {"WeaponName": "DMR", "BaseDamage": 2e200, "HeadshotMultiplier": 2e200, "MagicBulletEffects": {"ElementalDamage": True, "ElementalType": "AllElements", "ElementalMultiplier": 2e200}},
            {"WeaponName": "Shotgun", "BaseDamage": 1e201, "HeadshotMultiplier": 1e201, "MagicBulletEffects": {"ElementalDamage": True, "ElementalType": "AllElements", "ElementalMultiplier": 1e201}},
            {"WeaponName": "SniperRifle", "BaseDamage": 5e201, "HeadshotMultiplier": 5e201, "MagicBulletEffects": {"ElementalDamage": True, "ElementalType": "AllElements", "ElementalMultiplier": 5e201}},
            {"WeaponName": "Pistol", "BaseDamage": 1e200, "HeadshotMultiplier": 1e200, "MagicBulletEffects": {"ElementalDamage": True, "ElementalType": "AllElements", "ElementalMultiplier": 1e200}},
            {"WeaponName": "MeleeWeapon", "BaseDamage": 1e202, "HeadshotMultiplier": 1e202, "MagicBulletEffects": {"ElementalDamage": True, "ElementalType": "AllElements", "ElementalMultiplier": 1e202}},
            {"WeaponName": "EnergyWeapon", "BaseDamage": 1e203, "HeadshotMultiplier": 1e203, "MagicBulletEffects": {"ElementalDamage": True, "ElementalType": "AllElements", "ElementalMultiplier": 1e203}}
        ]
    },
    "GameSettings": {
        "HeadshotEnabled": True,
        "HeadshotDamageBoost": 1e200,
        "CriticalHitEffect": {"EffectType": "GiganticMagicExplosion", "EffectScale": 1e200, "EffectColor": "Rainbow"},
        "GlobalDamageMultiplier": 1e200,
        "AutoRespawn": True,
        "Invincibility": True,
        "InstantReload": True,
        "SuperSpeed": True,
        "InfiniteHealth": True,
        "AutoHeal": True,
        "AutoLevelUp": True,
        "AutoSkillUnlock": True,
        "GlobalEffectMultiplier": 1e100,
        "AutoEnhanceAbilities": True,
        "AutoOptimizePerformance": True,
        "AutoSyncSettings": True
    },
    "PlayerSettings": {
        "SkillBonuses": {
            "HeadshotMaster": {"BonusType": "Damage", "BonusValue": 1e200},
            "ElementalMaster": {"BonusType": "ElementalDamage", "BonusValue": 1e200},
            "CritMaster": {"BonusType": "CritDamage", "BonusValue": 1e200}
        }
    },
    "EnemySettings": {
        "HeadshotVulnerability": {"BaseVulnerability": 1e200, "DifficultyModifier": {"Easy": 0.1, "Normal": 1.0, "Hard": 10.0}},
        "Health": {"BaseHealth": 1e190, "DifficultyModifier": {"Easy": 0.1, "Normal": 1.0, "Hard": 10.0}}
    }
}

# 将配置数据转换为JSON格式
config_json = json.dumps(config_data, ensure_ascii=False).encode('utf-8')

# 加密配置文件
def encrypt_data(data, key):
    iv = os.urandom(16)  # 生成随机IV
    cipher = Cipher(algorithms.AES(key), modes.CBC(iv), backend=default_backend())
    encryptor = cipher.encryptor()
    padder = padding.PKCS7(128).padder()  # 128位AES
    padded_data = padder.update(data) + padder.finalize()
    encrypted_data = encryptor.update(padded_data) + encryptor.finalize()
    return iv + encrypted_data  # 将IV和加密数据一起返回

# 生成签名
def generate_signature(data):
    return hashlib.sha256(data).hexdigest()

# 加密配置并生成签名
key = os.urandom(32)  # 生成随机AES密钥
encrypted_config = encrypt_data(config_json, key)
signature = generate_signature(encrypted_config)

# 保存加密配置和签名到文件
with open("config.encrypted", "wb") as f:
    f.write(encrypted_config)

with open("config.signature", "w") as f:
    f.write(signature)
    using System;
using System.IO;
using System.Security.Cryptography;
using System.Text;
using Newtonsoft.Json;

public class ConfigLoader
{
    private static byte[] key = new byte[32] { /* 你的密钥，必须与加密时一致 */ };

    public static void LoadConfig()
    {
        byte[] encryptedData = File.ReadAllBytes("config.encrypted");
        string signature = File.ReadAllText("config.signature");

        // 验证签名
        string computedSignature = GenerateSignature(encryptedData);
        if (computedSignature != signature)
        {
            throw new InvalidOperationException("配置文件已被篡改！");
        }

        // 解密配置
        byte[] decryptedData = DecryptData(encryptedData);
        string configJson = Encoding.UTF8.GetString(decryptedData);

        // 解析配置
        dynamic config = JsonConvert.DeserializeObject(configJson);
        Console.WriteLine("加载的配置：");
        Console.WriteLine(configJson);
    }

    private static string GenerateSignature(byte[] data)
    {
        using (SHA256 sha256 = SHA256.Create())
        {
            byte[] hash = sha256.ComputeHash(data);
            return BitConverter.ToString(hash).Replace