package im.expensive.config;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import net.minecraft.client.Minecraft;
import org.apache.commons.io.FileUtils;
import java.io.*;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.zip.DataFormatException;
import java.util.zip.Deflater;
import java.util.zip.Inflater;
public class ConfigStorage {
public final Logger logger = Logger.getLogger(ConfigStorage.class.getName());
public final File CONFIG_DIR = new File(Minecraft.getInstance().gameDir, "\\expensive\\configs");
public final File AUTOCFG_DIR = new File(CONFIG_DIR, "system.cfg");
public final JsonParser jsonParser = new JsonParser();
public void init() throws IOException {
setupFolder();
}
public void setupFolder() {
if (!CONFIG_DIR.exists()) {
CONFIG_DIR.mkdirs();
} else if (AUTOCFG_DIR.exists()) {
loadConfiguration("system");
logger.log(Level.SEVERE, "Load system configuration...");
} else {
logger.log(Level.SEVERE, "Creating system configuration...");
try {
AUTOCFG_DIR.createNewFile();
FileUtils.write(AUTOCFG_DIR, "{\n" +
" \"functions\": {\n" +
" \"antiafk\": {\n" +
" \"bind\": 0,\n" +
" \"state\": false\n" +
" },\n" +
" \"antibot\": {\n" +
" \"bind\": 0,\n" +
" \"state\": false\n" +
" },\n" +
" \"antipush\": {\n" +
" \"bind\": 0,\n" +
" \"state\": false,\n" +
" \"Тип\": {\n" +
" \"Игроки\": true,\n" +
" \"Вода\": false,\n" +
" \"Блоки\": true\n" +
" }\n" +
" },\n" +
" \"autoaccept\": {\n" +
" \"bind\": 0,\n" +
" \"state\": false,\n" +
" \"Только друзья\": true\n" +
" },\n" +
" \"autoarmor\": {\n" +
" \"bind\": 0,\n" +
" \"state\": false,\n" +
" \"Задержка\": 100.0\n" +
" },\n" +
" \"autobuyui\": {\n" +
" \"bind\": 0,\n" +
" \"state\": false,\n" +
" \"Кнопка открытия\": -1\n" +
" },\n" +
" \"autoexplosion\": {\n" +
" \"bind\": 0,\n" +
" \"state\": false,\n" +
" \"Не взрывать себя\": true\n" +
" },\n" +
" \"autofish\": {\n" +
" \"bind\": 0,\n" +
" \"state\": false\n" +
" },\n" +
" \"autogapple\": {\n" +
" \"bind\": 0,\n" +
" \"state\": false,\n" +
" \"Здоровье\": 16.0,\n" +
" \"Съесть в начале\": true\n" +
" },\n" +
" \"autoleave\": {\n" +
" \"bind\": 0,\n" +
" \"state\": false,\n" +
" \"Действие\": \"Kick\",\n" +
" \"Дистанция\": 50.0\n" +
" },\n" +
" \"autopotion\": {\n" +
" \"bind\": 0,\n" +
" \"state\": false\n" +
" },\n" +
" \"autorespawn\": {\n" +
" \"bind\": 0,\n" +
" \"state\": false\n" +
" },\n" +
" \"autosprint\": {\n" +
" \"bind\": 0,\n" +
" \"state\": false,\n" +
" \"Сохранять спринт\": true\n" +
" },\n" +
" \"autoswap\": {\n" +
" \"bind\": 0,\n" +
" \"state\": false,\n" +
" \"Тип\": \"Умный\",\n" +
" \"Предмет\": \"Щит\",\n" +
" \"Свапать на\": \"Геплы\",\n" +
" \"Кнопка\": -1,\n" +
" \"Здоровье\": 11.0\n" +
" },\n" +
" \"autotool\": {\n" +
" \"bind\": 0,\n" +
" \"state\": false,\n" +
" \"Незаметный\": true\n" +
" },\n" +
" \"autototem\": {\n" +
" \"bind\": 0,\n" +
" \"state\": false,\n" +
" \"Мод\": \"Обычный\",\n" +
" \"Здоровье\": 3.5,\n" +
" \"Возвращать предмет\": true,\n" +
" \"Сохранять зачарованные\": true,\n" +
" \"Не брать если шар в руке\": false,\n" +
" \"Учитывать\": {\n" +
" \"Золотые сердца\": true,\n" +
" \"Кристаллы\": true,\n" +
" \"Якорь\": false,\n" +
" \"Падение\": false\n" +
" }\n" +
" },\n" +
" \"autotransfer\": {\n" +
" \"bind\": 0,\n" +
" \"state\": false,\n" +
" \"Анархия\": \"\",\n" +
" \"Количество предметов\": \"\",\n" +
" \"Цена\": \"\"\n" +
" },\n" +
" \"backtrack\": {\n" +
" \"bind\": 0,\n" +
" \"state\": false,\n" +
" \"Сбросить\": 0,\n" +
" \"Дистанция\": 3.0,\n" +
" \"Задержка\": 500.0\n" +
" },\n" +
" \"betterminecraft\": {\n" +
" \"bind\": 0,\n" +
" \"state\": false,\n" +
" \"Плавная камера\": true,\n" +
" \"Улучшенный таб\": true\n" +
" },\n" +
" \"cheststealer\": {\n" +
" \"bind\": 0,\n" +
" \"state\": false,\n" +
" \"Задержка\": 100.0\n" +
" },\n" +
" \"china hat\": {\n" +
" \"bind\": 0,\n" +
" \"state\": false\n" +
" },\n" +
" \"clickfriend\": {\n" +
" \"bind\": 0,\n" +
" \"state\": false,\n" +
" \"Кнопка\": -98\n" +
" },\n" +
" \"clickpearl\": {\n" +
" \"bind\": 0,\n" +
" \"state\": false,\n" +
" \"Кнопка\": -98\n" +
" },\n" +
" \"clientsounds\": {\n" +
" \"bind\": 0,\n" +
" \"state\": false,\n" +
" \"Тип\": \"Обычный\",\n" +
" \"Громкость\": 70.0\n" +
" },\n" +
" \"crosshair\": {\n" +
" \"bind\": 0,\n" +
" \"state\": false,\n" +
" \"Вид\": \"Орбиз\",\n" +
" \"Статический\": false\n" +
" },\n" +
" \"esp\": {\n" +
" \"bind\": 0,\n" +
" \"state\": true,\n" +
" \"Убрать\": {\n" +
" \"Боксы\": false,\n" +
" \"Полоску хп\": false,\n" +
" \"Текст хп\": false,\n" +
" \"Зачарования\": false,\n" +
" \"Список эффектов\": false\n" +
" }\n" +
" },\n" +
" \"elytrafly\": {\n" +
" \"bind\": 0,\n" +
" \"state\": false\n" +
" },\n" +
" \"elytrahelper\": {\n" +
" \"bind\": 0,\n" +
" \"state\": false,\n" +
" \"Кнопка свапа\": -1,\n" +
" \"Кнопка феерверков\": -1,\n" +
" \"Авто взлёт\": true\n" +
" },\n" +
" \"fly\": {\n" +
" \"bind\": 0,\n" +
" \"state\": false,\n" +
" \"Мод\": \"Vanilla\",\n" +
" \"По горизонтали\": 0.5,\n" +
" \"По вертикали\": 0.5\n" +
" },\n" +
" \"freecam\": {\n" +
" \"bind\": 0,\n" +
" \"state\": false,\n" +
" \"Скорость по XZ\": 1.0,\n" +
" \"Скорость по Y\": 0.5\n" +
" },\n" +
" \"glass hand\": {\n" +
" \"bind\": 0,\n" +
" \"state\": false\n" +
" },\n" +
" \"griefhelper\": {\n" +
" \"bind\": 0,\n" +
" \"state\": false,\n" +
" \"Тип\": {\n" +
" \"Использование по бинду\": true,\n" +
" \"Закрывать меню\": true\n" +
" },\n" +
" \"Кнопка дезориентации\": -1,\n" +
" \"Кнопка трапки\": -1\n" +
" },\n" +
" \"hud\": {\n" +
" \"bind\": 0,\n" +
" \"state\": false,\n" +
" \"Элементы\": {\n" +
" \"Ватермарка\": true,\n" +
" \"Список модулей\": true,\n" +
" \"Координаты\": true,\n" +
" \"Эффекты\": true,\n" +
" \"Список модерации\": true,\n" +
" \"Активные бинды\": true,\n" +
" \"Активный таргет\": true,\n" +
" \"Броня\": true\n" +
" }\n" +
" },\n" +
" \"hitbox\": {\n" +
" \"bind\": 0,\n" +
" \"state\": false,\n" +
" \"Размер\": 0.2,\n" +
" \"Видимые\": false\n" +
" },\n" +
" \"hitsound\": {\n" +
" \"bind\": 0,\n" +
" \"state\": false,\n" +
" \"Звук\": \"bell\",\n" +
" \"Громкость\": 35.0\n" +
" },\n" +
" \"inventorymove\": {\n" +
" \"bind\": 0,\n" +
" \"state\": false\n" +
" },\n" +
" \"itemphysic\": {\n" +
" \"bind\": 0,\n" +
" \"state\": false\n" +
" },\n" +
" \"itemscroller\": {\n" +
" \"bind\": 0,\n" +
" \"state\": false\n" +
" },\n" +
" \"itemswapfix\": {\n" +
" \"bind\": 0,\n" +
" \"state\": false\n" +
" },\n" +
" \"itemscooldown\": {\n" +
" \"bind\": 0,\n" +
" \"state\": false,\n" +
" \"Предметы\": {\n" +
" \"Геплы\": true,\n" +
" \"Перки\": true,\n" +
" \"Хорусы\": true,\n" +
" \"Чарки\": false\n" +
" },\n" +
" \"Кулдаун гепла\": 4.5,\n" +
" \"Кулдаун перок\": 14.05,\n" +
" \"Кулдаун хорусов\": 2.3,\n" +
" \"Кулдаун чарок\": 4.5,\n" +
" \"Только в PVP\": true\n" +
" },\n" +
" \"jumpcircle\": {\n" +
" \"bind\": 0,\n" +
" \"state\": false\n" +
" },\n" +
" \"killaura\": {\n" +
" \"bind\": 0,\n" +
" \"state\": false,\n" +
" \"Тип\": \"Плавная\",\n" +
" \"Дистанция аттаки\": 3.0,\n" +
" \"Таргеты\": {\n" +
" \"Игроки\": true,\n" +
" \"Голые\": true,\n" +
" \"Мобы\": false,\n" +
" \"Животные\": false,\n" +
" \"Друзья\": false,\n" +
" \"Голые невидимки\": true,\n" +
" \"Невидимки\": true\n" +
" },\n" +
" \"Опции\": {\n" +
" \"Только криты\": true,\n" +
" \"Ломать щит\": true,\n" +
" \"Отжимать щит\": true,\n" +
" \"Ускорять ротацию при атаке\": false,\n" +
" \"Синхронизировать атаку с ТПС\": false,\n" +
" \"Фокусировать одну цель\": true,\n" +
" \"Коррекция движения\": true\n" +
" },\n" +
" \"Тип коррекции\": \"Незаметный\"\n" +
" },\n" +
" \"leavetracker\": {\n" +
" \"bind\": 0,\n" +
" \"state\": false\n" +
" },\n" +
" \"longjump\": {\n" +
" \"bind\": 0,\n" +
" \"state\": false,\n" +
" \"Мод\": \"Slap\"\n" +
" },\n" +
" \"nameprotect\": {\n" +
" \"bind\": 0,\n" +
" \"state\": false,\n" +
" \"Заменяемое Имя\": \"dedinside\"\n" +
" },\n" +
" \"noclip\": {\n" +
" \"bind\": 0,\n" +
" \"state\": false\n" +
" },\n" +
" \"noentitytrace\": {\n" +
" \"bind\": 0,\n" +
" \"state\": false\n" +
" },\n" +
" \"nointeract\": {\n" +
" \"bind\": 0,\n" +
" \"state\": false,\n" +
" \"Обьекты\": {\n" +
" \"Стойки\": true,\n" +
" \"Сундуки\": true,\n" +
" \"Двери\": true,\n" +
" \"Кнопки\": true,\n" +
" \"Воронки\": true,\n" +
" \"Раздатчики\": true,\n" +
" \"Нотные блоки\": true,\n" +
" \"Верстаки\": true,\n" +
" \"Люки\": true,\n" +
" \"Печки\": true,\n" +
" \"Калитки\": true,\n" +
" \"Наковальни\": true,\n" +
" \"Рычаги\": true\n" +
" },\n" +
" \"Все блоки\": false\n" +
" },\n" +
" \"nojumpdelay\": {\n" +
" \"bind\": 0,\n" +
" \"state\": false\n" +
" },\n" +
" \"norender\": {\n" +
" \"bind\": 0,\n" +
" \"state\": false,\n" +
" \"Удалять\": {\n" +
" \"Огонь на экране\": true,\n" +
" \"Линия босса\": true,\n" +
" \"Анимация тотема\": true,\n" +
" \"Тайтлы\": true,\n" +
" \"Таблица\": true,\n" +
" \"Туман\": true,\n" +
" \"Тряску камеры\": true,\n" +
" \"Плохие эффекты\": true,\n" +
" \"Дождь\": true\n" +
" }\n" +
" },\n" +
" \"norotate\": {\n" +
" \"bind\": 0,\n" +
" \"state\": false\n" +
" },\n" +
" \"noslow\": {\n" +
" \"bind\": 0,\n" +
" \"state\": false,\n" +
" \"Мод\": \"Matrix\"\n" +
" },\n" +
" \"parkour\": {\n" +
" \"bind\": 0,\n" +
" \"state\": false\n" +
" },\n" +
" \"particles\": {\n" +
" \"bind\": 0,\n" +
" \"state\": false,\n" +
" \"Вид\": \"Сердечки\",\n" +
" \"Кол-во за удар\": 20.0\n" +
" },\n" +
" \"phase\": {\n" +
" \"bind\": 0,\n" +
" \"state\": false\n" +
" },\n" +
" \"pointers\": {\n" +
" \"bind\": 0,\n" +
" \"state\": false\n" +
" },\n" +
" \"portalgodmode\": {\n" +
" \"bind\": 0,\n" +
" \"state\": false\n" +
" },\n" +
" \"predictions\": {\n" +
" \"bind\": 0,\n" +
" \"state\": false\n" +
" },\n" +
" \"rwhelper\": {\n" +
" \"bind\": 0,\n" +
" \"state\": false,\n" +
" \"Функции\": {\n" +
" \"Блокировать запрещенные слова\": true,\n" +
" \"Закрывать меню\": true,\n" +
" \"Авто точка\": true,\n" +
" \"Уведомления\": true\n" +
" }\n" +
" },\n" +
" \"seeinvisibles\": {\n" +
" \"bind\": 0,\n" +
" \"state\": false\n" +
" },\n" +
" \"selfdestruct\": {\n" +
" \"bind\": 0,\n" +
" \"state\": false\n" +
" },\n" +
" \"snow\": {\n" +
" \"bind\": 0,\n" +
" \"state\": false,\n" +
" \"Вид\": \"Орбизы\"\n" +
" },\n" +
" \"spider\": {\n" +
" \"bind\": 0,\n" +
" \"state\": false,\n" +
" \"Speed\": 2.0,\n" +
" \"Mode\": \"Grim\"\n" +
" },\n" +
" \"storageesp\": {\n" +
" \"bind\": 0,\n" +
" \"state\": false\n" +
" },\n" +
" \"strafe\": {\n" +
" \"bind\": 0,\n" +
" \"state\": false,\n" +
" \"Буст с дамагом\": false,\n" +
" \"Значение буста\": 0.7\n" +
" },\n" +
" \"swinganimation\": {\n" +
" \"bind\": 0,\n" +
" \"state\": false,\n" +
" \"Мод\": \"1\",\n" +
" \"Сила\": 5.0,\n" +
" \"Скорость\": 10.0,\n" +
" \"Размер\": 1.0,\n" +
" \"Только с киллаурой\": true\n" +
" },\n" +
" \"targetesp\": {\n" +
" \"bind\": 0,\n" +
" \"state\": false\n" +
" },\n" +
" \"targetstrafe\": {\n" +
" \"bind\": 0,\n" +
" \"state\": false,\n" +
" \"Дистанция\": 1.0,\n" +
" \"Буст с дамагом\": true,\n" +
" \"Время буста\": 10.0,\n" +
" \"Сохранять цель\": true\n" +
" },\n" +
" \"timer\": {\n" +
" \"bind\": 0,\n" +
" \"state\": false,\n" +
" \"Скорость\": 2.0\n" +
" },\n" +
" \"tracers\": {\n" +
" \"bind\": 0,\n" +
" \"state\": false,\n" +
" \"Игнорировать голых\": true\n" +
" },\n" +
" \"trails\": {\n" +
" \"bind\": 0,\n" +
" \"state\": false\n" +
" },\n" +
" \"triggerbot\": {\n" +
" \"bind\": 0,\n" +
" \"state\": false,\n" +
" \"Игроки\": true,\n" +
" \"Мобы\": true,\n" +
" \"Животные\": true,\n" +
" \"Только криты\": true,\n" +
" \"Ломать щит\": false\n" +
" },\n" +
" \"velocity\": {\n" +
" \"bind\": 0,\n" +
" \"state\": false,\n" +
" \"Mode\": \"Cancel\"\n" +
" },\n" +
" \"viewmodel\": {\n" +
" \"bind\": 0,\n" +
" \"state\": false,\n" +
" \"RightX\": 0.0,\n" +
" \"RightY\": 0.0,\n" +
" \"RightZ\": 0.0,\n" +
" \"LeftX\": 0.0,\n" +
" \"LeftY\": 0.0,\n" +
" \"LeftZ\": 0.0\n" +
" },\n" +
" \"world\": {\n" +
" \"bind\": 0,\n" +
" \"state\": false,\n" +
" \"Time\": \"Day\"\n" +
" },\n" +
" \"xray bypass\": {\n" +
" \"bind\": 0,\n" +
" \"state\": false,\n" +
" \"Радиус\": 20.0,\n" +
" \"Вверх\": 5.0,\n" +
" \"Вниз\": 5.0,\n" +
" \"Задержка\": 13.0,\n" +
" \"Пропуск\": 3.0,\n" +
" \"Искать\": {\n" +
" \"Уголь\": false,\n" +
" \"Железо\": false,\n" +
" \"Редстоун\": false,\n" +
" \"Золото\": false,\n" +
" \"Эмеральды\": false,\n" +
" \"Алмазы\": false,\n" +
" \"Незерит\": false\n" +
" }\n" +
" },\n" +
" \"xcarry\": {\n" +
" \"bind\": 0,\n" +
" \"state\": false\n" +
" }\n" +
" },\n" +
" \"styles\": {\n" +
" \"Морской\": {\n" +
" \"selected\": true\n" +
" },\n" +
" \"Малиновый\": {\n" +
" \"selected\": false\n" +
" },\n" +
" \"Черничный\": {\n" +
" \"selected\": false\n" +
" },\n" +
" \"Необычный\": {\n" +
" \"selected\": false\n" +
" },\n" +
" \"Огненный\": {\n" +
" \"selected\": false\n" +
" },\n" +
" \"Металлический\": {\n" +
" \"selected\": false\n" +
" },\n" +
" \"Прикольный\": {\n" +
" \"selected\": false\n" +
" },\n" +
" \"Новогодний\": {\n" +
" \"selected\": false\n" +
" }\n" +
" }\n" +
"}", "UTF-8");
logger.log(Level.SEVERE, "Created!");
} catch (IOException e) {
logger.log(Level.SEVERE, "Failed to create system configuration file", e);
}
}
}
public boolean isEmpty() {
return getConfigs().isEmpty();
}
public List<Config> getConfigs() {
List<Config> configs = new ArrayList<>();
File[] configFiles = CONFIG_DIR.listFiles();
if (configFiles != null) {
for (File configFile : configFiles) {
if (configFile.isFile() && configFile.getName().endsWith(".cfg")) {
String configName = configFile.getName().replace(".cfg", "");
Config config = findConfig(configName);
if (config != null) {
configs.add(config);
}
}
}
}
return configs;
}
public void loadConfiguration(String configuration) {
Config config = findConfig(configuration);
try {
FileReader reader = new FileReader(config.getFile());
JsonParser parser = new JsonParser();
JsonObject object = (JsonObject) parser.parse(reader);
config.loadConfig(object);
} catch (FileNotFoundException e) {
logger.log(Level.WARNING, "Not Found Exception", e);
} catch (NullPointerException pointerException) {
logger.log(Level.WARNING, "Fatal error in Config!", pointerException);
}
}
public void saveConfiguration(String configuration) {
Config config = new Config(configuration);
String contentPrettyPrint = new GsonBuilder().setPrettyPrinting().create().toJson(config.saveConfig());
try {
FileWriter writer = new FileWriter(config.getFile());
writer.write(contentPrettyPrint);
writer.close();
} catch (IOException e) {
logger.log(Level.WARNING, "File not found!", e);
} catch (NullPointerException e) {
logger.log(Level.WARNING, "Fatal Error in Config!", e);
}
}
public Config findConfig(String configName) {
if (configName == null) return null;
if (new File(CONFIG_DIR, configName + ".cfg").exists())
return new Config(configName);
return null;
}
}