1. #1

    Registriert seit
    19.12.2011
    Beiträge
    356
    Thanked 164 Times in 101 Posts

    Standard [C#] Config Tool

    Dieser kleine Code erlaubt es Konfiguration verschlüsselt auf den PC zu speichern. Die Verschlüsselung ist je nach PC unterschiedlich, da die Seriennummer des Prozessors dafür benutzt wird.
    PHP-Code:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.IO;
    using System.Management;
    using System.Security.Cryptography;


    namespace 
    KNDeKaDeNz
    {
        public class 
    ConfigTool
        
    {


            public static 
    String getCPU()
            {
                
    string cpuInfo string.Empty;
                
    ManagementClass mc = new ManagementClass("win32_processor");
                
    ManagementObjectCollection moc mc.GetInstances();

                foreach (
    ManagementObject mo in moc)
                {
                    if (
    cpuInfo == "")
                    {
                        
    //Get only the first CPU's ID (MULTICORE)
                        
    cpuInfo mo.Properties["processorID"].Value.ToString();
                        break;
                    }
                }
                return 
    cpuInfo;
            }



            
    string filename "";
            
    Dictionary<StringStringDICT;
            
    Byte[] hashkey = new Byte[8];


            public 
    string getAll()
            {
                if(
    DICT.Count==0) return "";
                
    String output "";
                
    int lol 0;
                foreach(
    KeyValuePair<stringstringpair in DICT)
                {
                    if(
    lol!=0output+="\n";
                    
    output += pair.Key " " pair.Value;
                    
    lol++;
                }
                return 
    output;
            }


            public 
    string getValue(string key)
            {
                if (
    DICT.ContainsKey(key)) return DICT[key];
                else return 
    null;
            }

            public 
    void setValue(string keystring value)
            {
                if (
    DICT.ContainsKey(key)) DICT[key] = value;
                else 
    DICT.Add(keyvalue);
                
    saveFile(getAll());
            }

            public 
    ConfigTool(string file)
            {
                
    filename file;
                
    string tmp getCPU();
                for (
    int i 08i++)
                {
                    
    string hex tmp.Substring(22).Trim();
                    
    Byte dig Byte.Parse(hexSystem.Globalization.NumberStyles.HexNumber);
                    if (
    dig == && != 0dig = (Byte)(hashkey[1] / i);
                    
    hashkey[i] = dig;
                }




                
    DICT = new Dictionary<stringstring>();

                
    file file.Replace("\\""/");
                
    file file.Replace("../""");
                
    file file.Replace(":/""");
                
    String[] paths file.Split('/');
                
    string path "";
                for (
    int i 0paths.Length 1i++)
                {
                    
                    
                    
    path += paths[i]+"/";
                    if (!
    Directory.Exists(path))
                    {
                        
    Directory.CreateDirectory(path);
                    }
                }



                if (!
    File.Exists(file))
                    
    File.Create(file).Close();
                
    loadFile();
            }

            private 
    char hashchar(char Bint i)
            {
                
    8;
                return (
    char)(hashkey[i]);
            }

            private 
    void loadFile()
            {
                
    string fileSrc File.ReadAllText(filename);

                
    Char[] filesrc fileSrc.ToArray();
                for (
    int i 0filesrc.Lengthi++)
                {
                    
    filesrc[i] = hashchar(filesrc[i], i);
                }
                
    String tmp = new String(filesrc);

                
    String[] lines tmp.Split('\n');
                
                foreach (
    string line in lines)
                {
                    if (
    line.Trim() == "") continue;

                    
    int i line.IndexOf(' ');
                    
    string key line.Substring(0i);
                    
    string value line.Substring(1);
                    
    DICT.Add(keyvalue);
                }

                
            }



            private 
    void saveFile(String con)
            {
                
    Char[] filesrc con.ToArray();
                for (
    int i 0filesrc.Lengthi++)
                {
                    
    filesrc[i] = hashchar(filesrc[i], i);
                }
                
    String tmp = new String(filesrc);
                
    File.WriteAllText(filenametmp);
            }
        }


    Beispiel Programm:
    PHP-Code:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    namespace 
    Test.ConfigTool
    {
        class 
    Program
        
    {
            static 
    void Main(string[] args)
            {
                
    KNDeKaDeNz.ConfigTool CT =  new KNDeKaDeNz.ConfigTool("config/log/gay/text.txt");
                while (
    true)
                {
                    
    Console.WriteLine("OUTPUT:\n" CT.getAll());
                    
    string inp Console.ReadLine().Trim();
                    if (
    inp == "!exit") break;
                    if(
    inp.Contains(' '))
                    {
                        
    int i inp.IndexOf(' ');
                        
    string key inp.Substring(0i);
                        
    string value inp.Substring(1);
                        
    CT.setValue(keyvalue);
                    }
                }
            }
        }


    Wie man es in einem Plugin nutzen kann:
    PHP-Code:
    bool first=true;
    public 
    override bool OnReceive(Packet p)
    {
                if (
    first && Parent.getNick() != "?")
                {
                    
    loadConf();
                    
    first false;
                }
    }
    public 
    bool autoKiss=true;
    public 
    void loadConf()
    {
        
    string path "config/DeKaDeNz/kissresponder/" Parent.getNick().ToLower() + ".kisser";
        
    CT = new ConfigTool(path);
        if (
    CT.getValue("autokiss") != null)
            
    autoKiss = (CT.getValue("autokiss").ToLower() == "true" true false);


    DOWNLOAD:
    Multiupload.com - upload your files to multiple file hosting sites!
    Geändert von DeKaDeNz (07.01.2012 um 13:46 Uhr)

Ähnliche Themen

  1. [CS 1.6] Gute Config?
    Von !lkay im Forum Counter Strike
    Antworten: 1
    Letzter Beitrag: 12.12.2012, 14:26
  2. [CS:S] Config lädt nicht mehr.
    Von h00r4y im Forum Counter Strike
    Antworten: 4
    Letzter Beitrag: 31.07.2012, 17:29
  3. cs 1.6 Config
    Von sL1tchK0ss im Forum Counter Strike
    Antworten: 1
    Letzter Beitrag: 22.04.2012, 09:43
  4. Css high fps config
    Von CAKEBUILDER im Forum Counter Strike
    Antworten: 6
    Letzter Beitrag: 09.02.2012, 22:50
  5. CS:S high FPS Config.
    Von Bossgen im Forum Counter Strike
    Antworten: 1
    Letzter Beitrag: 21.01.2012, 10:34
Diese Seite nutzt Cookies, um das Nutzererlebnis zu verbessern. Klicken Sie hier, um das Cookie-Tracking zu deaktivieren.