Commit 71879cd01475b79460697b9f8c167835b7306866

Authored by Mumfrey
1 parent 58356f00

LiteLoader 1.6.2_04 - fixed non-saving key bindings and added getLoadedMods() fu…

…nction to list all successfully loaded mods
java/com/mumfrey/liteloader/core/LiteLoader.java
1 1 package com.mumfrey.liteloader.core;
2 2  
3   -import java.io.BufferedReader;
4   -import java.io.File;
5   -import java.io.FileInputStream;
6   -import java.io.FileNotFoundException;
7   -import java.io.FileWriter;
8   -import java.io.FilenameFilter;
9   -import java.io.IOException;
10   -import java.io.InputStream;
11   -import java.io.InputStreamReader;
12   -import java.io.PrintStream;
13   -import java.io.UnsupportedEncodingException;
  3 +import java.io.*;
14 4 import java.lang.reflect.Method;
15 5 import java.net.MalformedURLException;
16 6 import java.net.URISyntaxException;
... ... @@ -19,6 +9,8 @@ import java.net.URLClassLoader;
19 9 import java.net.URLDecoder;
20 10 import java.nio.charset.Charset;
21 11 import java.util.ArrayList;
  12 +import java.util.Arrays;
  13 +import java.util.Collections;
22 14 import java.util.HashMap;
23 15 import java.util.Iterator;
24 16 import java.util.LinkedList;
... ... @@ -63,14 +55,14 @@ import com.mumfrey.liteloader.util.PrivateFields;
63 55 * lightweight mods
64 56 *
65 57 * @author Adam Mummery-Smith
66   - * @version 1.6.2_03
  58 + * @version 1.6.2_04
67 59 */
68 60 public final class LiteLoader implements FilenameFilter, IPlayerUsage
69 61 {
70 62 /**
71 63 * Liteloader version
72 64 */
73   - private static final LiteLoaderVersion VERSION = LiteLoaderVersion.MC_1_6_2_R2;
  65 + private static final LiteLoaderVersion VERSION = LiteLoaderVersion.MC_1_6_2_R3;
74 66  
75 67 /**
76 68 * Maximum recursion depth for mod discovery
... ... @@ -191,11 +183,16 @@ public final class LiteLoader implements FilenameFilter, IPlayerUsage
191 183 private String loadedModsList = "none";
192 184  
193 185 /**
194   - * Global list of mods which we have loaded
  186 + * Global list of mods which we can loaded
195 187 */
196 188 private LinkedList<LiteMod> mods = new LinkedList<LiteMod>();
197 189  
198 190 /**
  191 + * Global list of mods which we have loaded
  192 + */
  193 + private LinkedList<LiteMod> loadedMods = new LinkedList<LiteMod>();
  194 +
  195 + /**
199 196 * List of mods which implement Tickable interface and will receive tick
200 197 * events
201 198 */
... ... @@ -294,12 +291,42 @@ public final class LiteLoader implements FilenameFilter, IPlayerUsage
294 291 */
295 292 private static PermissionsManagerClient permissionsManager = PermissionsManagerClient.getInstance();
296 293  
  294 + /**
  295 + * True while initialising mods if we need to do a resource manager reload once the process is completed
  296 + */
297 297 private boolean pendingResourceReload;
298 298  
  299 + /**
  300 + * Read from the properties file, if true we will inhibit the sound manager reload during startup to avoid getting in trouble with OpenAL
  301 + */
299 302 private boolean inhibitSoundManagerReload = true;
300 303  
  304 + /**
  305 + * If inhibit is enabled, this object is used to reflectively inhibit the sound manager's reload process during startup by removing it from the reloadables list
  306 + */
301 307 private SoundManagerReloadInhibitor soundManagerReloadInhibitor;
302 308  
  309 + /**
  310 + * File in which we will store mod key mappings
  311 + */
  312 + private File keyMapSettingsFile = null;
  313 +
  314 + /**
  315 + * Properties object which stores mod key mappings
  316 + */
  317 + private Properties keyMapSettings = new Properties();
  318 +
  319 + /**
  320 + * List of all registered mod keys
  321 + */
  322 + private List<KeyBinding> modKeys = new ArrayList<KeyBinding>();
  323 +
  324 + /**
  325 + * Map of mod key bindings to their key codes, stored so that we don't need to cast from
  326 + * string in the properties file every tick
  327 + */
  328 + private Map<KeyBinding, Integer> storedModKeyBindings = new HashMap<KeyBinding, Integer>();
  329 +
303 330 public static final void init(File gameDirectory, File assetsDirectory, String profile, List<String> modNameFilter)
304 331 {
305 332 if (instance == null)
... ... @@ -579,6 +606,17 @@ public final class LiteLoader implements FilenameFilter, IPlayerUsage
579 606 {
580 607 this.localProperties = new Properties(this.internalProperties);
581 608 }
  609 +
  610 + this.keyMapSettingsFile = new File(this.configBaseFolder, "litemodkeys.properties");
  611 +
  612 + if (this.keyMapSettingsFile.exists())
  613 + {
  614 + try
  615 + {
  616 + this.keyMapSettings.load(new FileReader(this.keyMapSettingsFile));
  617 + }
  618 + catch (Exception ex) {}
  619 + }
582 620 }
583 621  
584 622 /**
... ... @@ -707,7 +745,7 @@ public final class LiteLoader implements FilenameFilter, IPlayerUsage
707 745 }
708 746  
709 747 /**
710   - * Used for crash reporting
  748 + * Used for crash reporting, returns a text list of all loaded mods
711 749 *
712 750 * @return List of loaded mods as a string
713 751 */
... ... @@ -717,6 +755,14 @@ public final class LiteLoader implements FilenameFilter, IPlayerUsage
717 755 }
718 756  
719 757 /**
  758 + * Get a list containing all loaded mods
  759 + */
  760 + public List<LiteMod> getLoadedMods()
  761 + {
  762 + return Collections.unmodifiableList(this.loadedMods);
  763 + }
  764 +
  765 + /**
720 766 * Used to get the name of the modpack being used
721 767 *
722 768 * @return name of the modpack in use or null if no pack
... ... @@ -1192,7 +1238,7 @@ public final class LiteLoader implements FilenameFilter, IPlayerUsage
1192 1238 logger.info("Discovered " + this.modsToLoad.size() + " total mod(s)");
1193 1239  
1194 1240 this.pendingResourceReload = false;
1195   - this.soundManagerReloadInhibitor = new SoundManagerReloadInhibitor((SimpleReloadableResourceManager)minecraft.getResourceManager(), minecraft.sndManager);
  1241 + this.soundManagerReloadInhibitor = new SoundManagerReloadInhibitor((SimpleReloadableResourceManager)minecraft.func_110442_L(), minecraft.sndManager); // TODO adamsrc -> getResourceManager
1196 1242 if (this.inhibitSoundManagerReload) this.soundManagerReloadInhibitor.inhibit();
1197 1243  
1198 1244 for (Class<? extends LiteMod> mod : this.modsToLoad.values())
... ... @@ -1353,6 +1399,7 @@ public final class LiteLoader implements FilenameFilter, IPlayerUsage
1353 1399 permissionsManager.registerPermissible((Permissible)mod);
1354 1400 }
1355 1401  
  1402 + this.loadedMods.add(mod);
1356 1403 this.loadedModsList += String.format("\n - %s version %s", modName, mod.getVersion());
1357 1404 loadedModsCount++;
1358 1405 }
... ... @@ -1889,9 +1936,13 @@ public final class LiteLoader implements FilenameFilter, IPlayerUsage
1889 1936 // Flag indicates whether we are in game at the moment
1890 1937 boolean inGame = this.minecraft.renderViewEntity != null && this.minecraft.renderViewEntity.worldObj != null;
1891 1938  
1892   - // Tick the permissions manager
1893 1939 if (tick)
  1940 + {
  1941 + // Tick the permissions manager
1894 1942 permissionsManager.onTick(this.minecraft, partialTicks, inGame);
  1943 +
  1944 + this.checkAndStoreKeyBindings();
  1945 + }
1895 1946  
1896 1947 // Iterate tickable mods
1897 1948 for (Tickable tickable : this.tickListeners)
... ... @@ -2137,4 +2188,70 @@ public final class LiteLoader implements FilenameFilter, IPlayerUsage
2137 2188 PrivateFields.minecraftProfiler.setFinal(this.minecraft, this.profilerHook);
2138 2189 }
2139 2190 }
  2191 +
  2192 + public void registerModKey(KeyBinding binding)
  2193 + {
  2194 + LinkedList<KeyBinding> keyBindings = new LinkedList<KeyBinding>();
  2195 + keyBindings.addAll(Arrays.asList(this.minecraft.gameSettings.keyBindings));
  2196 +
  2197 + if (!keyBindings.contains(binding))
  2198 + {
  2199 + if (this.keyMapSettings.containsKey(binding.keyDescription))
  2200 + {
  2201 + try
  2202 + {
  2203 + binding.keyCode = Integer.parseInt(this.keyMapSettings.getProperty(binding.keyDescription, String.valueOf(binding.keyCode)));
  2204 + }
  2205 + catch (NumberFormatException ex) {}
  2206 + }
  2207 +
  2208 + keyBindings.add(binding);
  2209 + this.minecraft.gameSettings.keyBindings = keyBindings.toArray(new KeyBinding[0]);
  2210 + this.modKeys.add(binding);
  2211 +
  2212 + this.updateBinding(binding);
  2213 + this.storeBindings();
  2214 + }
  2215 + }
  2216 +
  2217 + /**
  2218 + * Checks for changed mod keybindings and stores any that have changed
  2219 + */
  2220 + private void checkAndStoreKeyBindings()
  2221 + {
  2222 + boolean updated = false;
  2223 +
  2224 + for (KeyBinding binding : this.modKeys)
  2225 + {
  2226 + if (binding.keyCode != this.storedModKeyBindings.get(binding))
  2227 + {
  2228 + this.updateBinding(binding);
  2229 + updated = true;
  2230 + }
  2231 + }
  2232 +
  2233 + if (updated)
  2234 + this.storeBindings();
  2235 + }
  2236 +
  2237 + /**
  2238 + * @param binding
  2239 + */
  2240 + private void updateBinding(KeyBinding binding)
  2241 + {
  2242 + this.keyMapSettings.setProperty(binding.keyDescription, String.valueOf(binding.keyCode));
  2243 + this.storedModKeyBindings.put(binding, Integer.valueOf(binding.keyCode));
  2244 + }
  2245 +
  2246 + /**
  2247 + * Writes mod bindings to disk
  2248 + */
  2249 + protected void storeBindings()
  2250 + {
  2251 + try
  2252 + {
  2253 + this.keyMapSettings.store(new FileWriter(this.keyMapSettingsFile), "Mod key mappings for LiteLoader mods, stored here to avoid losing settings stored in options.txt");
  2254 + }
  2255 + catch (IOException ex) {}
  2256 + }
2140 2257 }
2141 2258 \ No newline at end of file
... ...
java/com/mumfrey/liteloader/core/LiteLoaderVersion.java
... ... @@ -7,7 +7,7 @@ import java.util.Set;
7 7 * LiteLoader version table
8 8 *
9 9 * @author Adam Mummery-Smith
10   - * @version 1.6.2_02
  10 + * @version 1.6.2_04
11 11 */
12 12 public enum LiteLoaderVersion
13 13 {
... ... @@ -17,7 +17,8 @@ public enum LiteLoaderVersion
17 17 MC_1_6_1_R0(11, "1.6.1", "1.6.1", "1.6.1", "1.6.r1"),
18 18 MC_1_6_2_R0(12, "1.6.2", "1.6.2", "1.6.2", "1.6.r2"),
19 19 MC_1_6_2_R1(13, "1.6.2", "1.6.2_02", "1.6.2", "1.6.r2"),
20   - MC_1_6_2_R2(13, "1.6.2", "1.6.2_03", "1.6.2", "1.6.r2");
  20 + MC_1_6_2_R2(13, "1.6.2", "1.6.2_03", "1.6.2", "1.6.r2"),
  21 + MC_1_6_2_R3(13, "1.6.2", "1.6.2_04", "1.6.2", "1.6.r2");
21 22  
22 23 private int revision;
23 24  
... ...
java/com/mumfrey/liteloader/core/SoundManagerReloadInhibitor.java
... ... @@ -103,7 +103,7 @@ public class SoundManagerReloadInhibitor
103 103 if (reload)
104 104 {
105 105 LiteLoader.getLogger().info("Reloading sound manager");
106   - this.soundManager.onReload(this.resourceManager);
  106 + this.soundManager.func_110549_a(this.resourceManager); // TODO adamsrc -> onReload
107 107 }
108 108  
109 109 this.inhibited = false;
... ...
java/com/mumfrey/liteloader/gui/GuiControlsPaginated.java
... ... @@ -105,17 +105,17 @@ public class GuiControlsPaginated extends GuiScreen
105 105 {
106 106 this.getLegacyControlList().add(this.btnNext = new GuiButton(201, this.getWidth() / 2 - 51, buttonY, 50, 20, ">>"));
107 107 this.getLegacyControlList().add(this.btnPrevious = new GuiButton(202, this.getWidth() / 2 - 103, buttonY, 50, 20, "<<"));
108   - this.getLegacyControlList().add(new GuiButton(200, this.getWidth() / 2 + 1, buttonY, 100, 20, I18n.func_135053_a("gui.done")));
  108 + this.getLegacyControlList().add(new GuiButton(200, this.getWidth() / 2 + 1, buttonY, 100, 20, I18n.func_135053_a("gui.done"))); // TODO adamsrc -> translate
109 109  
110 110 this.btnNext.enabled = this.startIndex < this.endIndex;
111 111 this.btnPrevious.enabled = this.startIndex > 0;
112 112 }
113 113 else
114 114 {
115   - this.getLegacyControlList().add(new GuiButton(200, this.getWidth() / 2 - 100, buttonY, I18n.func_135053_a("gui.done")));
  115 + this.getLegacyControlList().add(new GuiButton(200, this.getWidth() / 2 - 100, buttonY, I18n.func_135053_a("gui.done"))); // TODO adamsrc -> translate
116 116 }
117 117  
118   - this.screenTitle = I18n.func_135053_a("controls.title");
  118 + this.screenTitle = I18n.func_135053_a("controls.title"); // TODO adamsrc -> translate
119 119 }
120 120  
121 121 /**
... ...
java/com/mumfrey/liteloader/util/ModUtilities.java
... ... @@ -120,19 +120,7 @@ public abstract class ModUtilities
120 120 */
121 121 public static void registerKey(KeyBinding newBinding)
122 122 {
123   - Minecraft mc = Minecraft.getMinecraft();
124   -
125   - if (mc == null || mc.gameSettings == null) return;
126   -
127   - LinkedList<KeyBinding> keyBindings = new LinkedList<KeyBinding>();
128   - keyBindings.addAll(Arrays.asList(mc.gameSettings.keyBindings));
129   -
130   - if (!keyBindings.contains(newBinding))
131   - {
132   - keyBindings.add(newBinding);
133   - mc.gameSettings.keyBindings = keyBindings.toArray(new KeyBinding[0]);
134   - mc.gameSettings.loadOptions();
135   - }
  123 + LiteLoader.getInstance().registerModKey(newBinding);
136 124 }
137 125  
138 126 /**
... ...