Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package intent.extensions;
- import java.io.BufferedReader;
- import java.io.File;
- import java.io.FileReader;
- import java.io.FileWriter;
- import java.io.PrintWriter;
- import java.util.HashSet;
- import java.util.Iterator;
- import java.util.Map.Entry;
- import com.google.common.collect.Sets;
- import com.google.gson.JsonElement;
- import com.google.gson.JsonObject;
- import intent.Frickin;
- import intent.modules.Module;
- import intent.modules.Module.Category;
- import intent.modules.render.ClickGUI;
- import intent.modules.render.TabGUI;
- import intent.settings.Setting;
- import intent.ui.MainMenu;
- import intent.util.JsonUtils;
- import net.minecraft.client.Minecraft;
- import net.minecraft.client.gui.FontRenderer;
- import net.minecraft.client.gui.Gui;
- import net.minecraft.client.gui.GuiScreen;
- import net.minecraft.client.renderer.GlStateManager;
- import javax.swing.JOptionPane;
- public class FileManager {
- public static File ROOT_DIR = new File(Frickin.name);
- public static File MODULE_BASE_DIR = new File(ROOT_DIR, "modules");
- public static File clickgui = new File(ROOT_DIR, "clickgui.json");
- public FileManager() {
- super();
- }
- public void init() {
- // Root Dir
- if(!ROOT_DIR.exists()) ROOT_DIR.mkdirs();
- // Modules saving
- if(!MODULE_BASE_DIR.exists()){
- saveMods();
- }
- //ClickGUI
- if(!clickgui.exists()){
- saveClickGui();
- }
- if(MODULE_BASE_DIR.exists() && clickgui.exists()){
- loadAll();
- }
- }
- // Blacklisted Modules
- private HashSet<String> modulesBlacklist = Sets.newHashSet(
- ClickGUI.class.getName(),
- TabGUI.class.getName()
- );
- public boolean isModuleBlacklisted(Module m){
- return modulesBlacklist.contains(m.getClass().getName());
- }
- public static void WARNINGBOX(String infoMessage, String titleBar)
- {
- JOptionPane.showMessageDialog(null, infoMessage, "["+Frickin.name+"]: " + titleBar, JOptionPane.WARNING_MESSAGE);
- }
- private void saveClickGui() {
- try{
- JsonObject json = new JsonObject();
- for (Category c : Module.Category.values()){
- JsonObject jsonCategory = new JsonObject();
- try{
- if (c.x != 0){
- jsonCategory.addProperty("x", c.x);
- jsonCategory.addProperty("y", c.y);
- jsonCategory.addProperty("x2", c.x2);
- jsonCategory.addProperty("y2", c.y2);
- jsonCategory.addProperty("extended", c.extended);
- }
- }catch(Exception e) { }
- json.add(c.name(), jsonCategory);
- }
- if(!ROOT_DIR.exists()) ROOT_DIR.mkdirs();
- PrintWriter save = new PrintWriter(new FileWriter(clickgui));
- save.println(JsonUtils.prettyGson.toJson(json));
- save.close();
- } catch(Exception e) {
- WARNINGBOX("Failed to save data for ClickGUI:\n"+e.toString(), "File Manager");
- e.printStackTrace();
- }
- }
- public void saveMods() {
- try{
- JsonObject json = new JsonObject();
- for(Module m : Frickin.modules) {
- File module = new File(MODULE_BASE_DIR, m.getName() + ".json");
- JsonObject jsonMod = new JsonObject();
- jsonMod.addProperty("enabled", m.isEnabled());
- jsonMod.addProperty("keybind", m.keyCode.getKeyCode());
- if (Frickin.setmgr.getSettingsByMod(m) != null){
- for (de.Hero.settings.Setting s : Frickin.setmgr.getSettingsByMod(m)){
- try{
- boolean isCombo = s.isCombo();
- boolean isCheck = s.isCheck();
- boolean isSlider = s.isSlider();
- if (isCombo){
- jsonMod.addProperty(s.getName(), s.getValString());
- }
- if (isCheck){
- jsonMod.addProperty(s.getName(), s.getValBoolean());
- }
- if (isSlider) {
- jsonMod.addProperty(s.getName(), s.getValDouble());
- }
- }catch(Exception e) { }
- }
- }
- json.add(m.getName(), jsonMod);
- if(!ROOT_DIR.exists()) ROOT_DIR.mkdirs();
- PrintWriter save = new PrintWriter(new FileWriter(module));
- save.println(JsonUtils.prettyGson.toJson(json));
- save.close();
- }
- } catch(Exception e) {
- WARNINGBOX("Failed to save data for modules:\n"+e.toString(), "File Manager");
- e.printStackTrace();
- }
- saveClickGui();
- }
- private void loadAll() {
- try{
- BufferedReader loadCat = new BufferedReader(new FileReader(clickgui));
- JsonObject jsonCat = (JsonObject)JsonUtils.jsonParser.parse(loadCat);
- loadCat.close();
- Iterator<Entry<String, JsonElement>> itrCat = jsonCat.entrySet().iterator();
- while(itrCat.hasNext()) {
- Entry<String, JsonElement> entryCat = itrCat.next();
- JsonObject jsonCategory = (JsonObject)entryCat.getValue();
- if (Category.isInEnum(entryCat.getKey())){
- Category c = Category.valueOf(entryCat.getKey());
- try{
- c.x = jsonCategory.get("x").getAsDouble();
- c.y = jsonCategory.get("y").getAsDouble();
- c.x2 = jsonCategory.get("x2").getAsDouble();
- c.y2 = jsonCategory.get("y2").getAsDouble();
- c.extended = jsonCategory.get("extended").getAsBoolean();
- }catch(Exception e){ e.printStackTrace(); }
- }
- }
- for (Module m : modules) {
- BufferedReader load = new BufferedReader(new FileReader(new File(MODULE_BASE_DIR, m.getName() + ".json")));
- JsonObject json = (JsonObject)JsonUtils.jsonParser.parse(load);
- load.close();
- Iterator<Entry<String, JsonElement>> itr = json.entrySet().iterator();
- if (m != null && !isModuleBlacklisted(m)) {
- JsonObject jsonModule = (JsonObject)entry.getValue();
- boolean enabled = jsonModule.get("enabled").getAsBoolean();
- int keybind = jsonModule.get("keybind").getAsInt();
- if (Frickin.setmgr.getSettingsByMod(m) != null){
- for (de.Hero.settings.Setting s : Frickin.setmgr.getSettingsByMod(m)){
- try{
- boolean isCombo = s.isCombo();
- boolean isCheck = s.isCheck();
- boolean isSlider = s.isSlider();
- if (isCombo){
- Frickin.setmgr.getSettingByName(s.getName()).setValString( jsonModule.get(s.getName()).getAsString() );
- }
- if (isCheck){
- Frickin.setmgr.getSettingByName(s.getName()).setValBoolean( jsonModule.get(s.getName()).getAsBoolean() );
- }
- if (isSlider) {
- if (s.onlyInt())
- Frickin.setmgr.getSettingByName(s.getName()).setValDouble( jsonModule.get(s.getName()).getAsInt() );
- else Frickin.setmgr.getSettingByName(s.getName()).setValDouble( jsonModule.get(s.getName()).getAsDouble() );
- }
- }catch(Exception ignored) { }
- }
- }
- if(enabled) {
- m.toggle();
- }
- m.keyCode.setKeyCode(keybind);
- }
- }
- } catch(Exception e) {
- WARNINGBOX("Failed to load saved data for modules & ClickGUI, please try relaunching the client or report this issue to the developers:\n"+e.toString(), "File Manager");
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment