Thema: [C#] Config Tool
-
06.01.2012, 15:03 #1
- Registriert seit
- 19.12.2011
- Beiträge
- 356
Thanked 164 Times in 101 Posts[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<String, String> DICT;
Byte[] hashkey = new Byte[8];
public string getAll()
{
if(DICT.Count==0) return "";
String output = "";
int lol = 0;
foreach(KeyValuePair<string, string> pair in DICT)
{
if(lol!=0) output+="\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 key, string value)
{
if (DICT.ContainsKey(key)) DICT[key] = value;
else DICT.Add(key, value);
saveFile(getAll());
}
public ConfigTool(string file)
{
filename = file;
string tmp = getCPU();
for (int i = 0; i < 8; i++)
{
string hex = tmp.Substring(i * 2, 2).Trim();
Byte dig = Byte.Parse(hex, System.Globalization.NumberStyles.HexNumber);
if (dig == 0 && i != 0) dig = (Byte)(hashkey[i - 1] / i);
hashkey[i] = dig;
}
DICT = new Dictionary<string, string>();
file = file.Replace("\\", "/");
file = file.Replace("../", "");
file = file.Replace(":/", "");
String[] paths = file.Split('/');
string path = "";
for (int i = 0; i < paths.Length - 1; i++)
{
path += paths[i]+"/";
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
}
if (!File.Exists(file))
File.Create(file).Close();
loadFile();
}
private char hashchar(char B, int i)
{
i = i % 8;
return (char)(B ^ hashkey[i]);
}
private void loadFile()
{
string fileSrc = File.ReadAllText(filename);
Char[] filesrc = fileSrc.ToArray();
for (int i = 0; i < filesrc.Length; i++)
{
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(0, i);
string value = line.Substring(i + 1);
DICT.Add(key, value);
}
}
private void saveFile(String con)
{
Char[] filesrc = con.ToArray();
for (int i = 0; i < filesrc.Length; i++)
{
filesrc[i] = hashchar(filesrc[i], i);
}
String tmp = new String(filesrc);
File.WriteAllText(filename, tmp);
}
}
}
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(0, i);
string value = inp.Substring(i + 1);
CT.setValue(key, value);
}
}
}
}
}
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);
}
Multiupload.com - upload your files to multiple file hosting sites!Geändert von DeKaDeNz (07.01.2012 um 13:46 Uhr)
Ähnliche Themen
-
[CS 1.6] Gute Config?
Von !lkay im Forum Counter StrikeAntworten: 1Letzter Beitrag: 12.12.2012, 14:26 -
[CS:S] Config lädt nicht mehr.
Von h00r4y im Forum Counter StrikeAntworten: 4Letzter Beitrag: 31.07.2012, 17:29 -
cs 1.6 Config
Von sL1tchK0ss im Forum Counter StrikeAntworten: 1Letzter Beitrag: 22.04.2012, 09:43 -
Css high fps config
Von CAKEBUILDER im Forum Counter StrikeAntworten: 6Letzter Beitrag: 09.02.2012, 22:50 -
CS:S high FPS Config.
Von Bossgen im Forum Counter StrikeAntworten: 1Letzter Beitrag: 21.01.2012, 10:34
Diese Seite nutzt Cookies, um das Nutzererlebnis zu verbessern. Klicken Sie hier, um das Cookie-Tracking zu deaktivieren.