Made settings save/load

This commit is contained in:
PeytonPlayz595 2023-07-17 04:38:49 -04:00
parent 4f2f4a6cbf
commit 9138a1ee09
18 changed files with 3379 additions and 2503 deletions

4966
js/app.js

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -2,6 +2,9 @@ package com.mojang.minecraft;
import com.mojang.minecraft.gamemode.*; import com.mojang.minecraft.gamemode.*;
import net.PeytonPlayz585.storage.LocalStorageManager;
import net.PeytonPlayz595.nbt.NBTTagCompound;
import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL11;
public final class GameSettings public final class GameSettings
@ -141,103 +144,65 @@ public final class GameSettings
private void load() private void load()
{ {
// try NBTTagCompound settingsFile = LocalStorageManager.gameSettingsStorage;
// {
// if(settingsFile.exists()) if(!settingsFile.hasNoTags()) {
// { if(settingsFile.hasKey("music")) {
// FileReader fileReader = new FileReader(settingsFile); music = settingsFile.getBoolean("music");
// BufferedReader reader = new BufferedReader(fileReader); }
//
// String line = null; if(settingsFile.hasKey("sound")) {
// sound = settingsFile.getBoolean("sound");
// while((line = reader.readLine()) != null) }
// {
// String[] setting = line.split(":"); if(settingsFile.hasKey("invertYMouse")) {
// invertMouse = settingsFile.getBoolean("invertYMouse");
// if(setting[0].equals("music")) }
// {
// music = setting[1].equals("true"); if(settingsFile.hasKey("showFrameRate")) {
// } showFrameRate = settingsFile.getBoolean("showFrameRate");
// }
// if(setting[0].equals("sound"))
// { if(settingsFile.hasKey("viewDistance")) {
// sound = setting[1].equals("true"); viewDistance = settingsFile.getInteger("viewDistance");
// } }
//
// if(setting[0].equals("invertYMouse")) if(settingsFile.hasKey("bobView")) {
// { viewBobbing = settingsFile.getBoolean("bobView");
// invertMouse = setting[1].equals("true"); }
// }
// if(settingsFile.hasKey("anaglyph3d")) {
// if(setting[0].equals("showFrameRate")) anaglyph = settingsFile.getBoolean("anaglyph3d");
// { }
// showFrameRate = setting[1].equals("true");
// } if(settingsFile.hasKey("limitFramerate")) {
// limitFramerate = settingsFile.getBoolean("limitFramerate");
// if(setting[0].equals("viewDistance")) }
// {
// viewDistance = Integer.parseInt(setting[1]); for(int i = 0; i < bindings.length; ++i) {
// } String k = "key_" + bindings[i].name;
// if(settingsFile.hasKey(k)) bindings[i].key = (int)settingsFile.getShort(k) & 0xFFFF;
// if(setting[0].equals("bobView")) }
// { }
// viewBobbing = setting[1].equals("true");
// }
//
// if(setting[0].equals("anaglyph3d"))
// {
// anaglyph = setting[1].equals("true");
// }
//
// if(setting[0].equals("limitFramerate"))
// {
// limitFramerate = setting[1].equals("true");
// }
//
// for(int index = 0; index < this.bindings.length; index++)
// {
// if(setting[0].equals("key_" + bindings[index].name))
// {
// bindings[index].key = Integer.parseInt(setting[1]);
// }
// }
// }
//
// reader.close();
// }
// } catch (Exception e) {
// System.out.println("Failed to load options");
//
// e.printStackTrace();
// }
} }
private void save() private void save()
{ {
// try { NBTTagCompound settingsFile = LocalStorageManager.gameSettingsStorage;
// FileWriter fileWriter = new FileWriter(this.settingsFile); settingsFile.setBoolean("music", music);
// PrintWriter writer = new PrintWriter(fileWriter); settingsFile.setBoolean("sound", sound);
// settingsFile.setBoolean("invertYMouse", invertMouse);
// writer.println("music:" + music); settingsFile.setBoolean("showFrameRate", showFrameRate);
// writer.println("sound:" + sound); settingsFile.setInteger("viewDistance", viewDistance);
// writer.println("invertYMouse:" + invertMouse); settingsFile.setBoolean("bobView", viewBobbing);
// writer.println("showFrameRate:" + showFrameRate); settingsFile.setBoolean("anaglyph3d", anaglyph);
// writer.println("viewDistance:" + viewDistance); settingsFile.setBoolean("limitFramerate", limitFramerate);
// writer.println("bobView:" + viewBobbing);
// writer.println("anaglyph3d:" + anaglyph); for(int i = 0; i < bindings.length; ++i) {
// writer.println("limitFramerate:" + limitFramerate); String k = "key_" + bindings[i].name;
// settingsFile.setShort(k, (short)bindings[i].key);
// for(int binding = 0; binding < bindings.length; binding++) }
// { LocalStorageManager.saveStorageG();
// writer.println("key_" + bindings[binding].name + ":" + bindings[binding].key);
// }
//
// writer.close();
// } catch (Exception e) {
// System.out.println("Failed to save options");
//
// e.printStackTrace();
// }
} }
} }

View File

@ -0,0 +1,81 @@
package net.PeytonPlayz585.storage;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import org.lwjgl.opengl.GL11;
import net.PeytonPlayz595.nbt.NBTBase;
import net.PeytonPlayz595.nbt.NBTTagCompound;
import net.lax1dude.eaglercraft.Base64;
public class LocalStorageManager {
public static NBTTagCompound gameSettingsStorage = null;
public static NBTTagCompound profileSettingsStorage = null;
public static void loadStorage() {
byte[] g = GL11.loadLocalStorage("g");
byte[] p = GL11.loadLocalStorage("p");
if(g != null) {
try {
NBTBase t = NBTBase.readTag(new DataInputStream(new ByteArrayInputStream(g)));
if(t != null && t instanceof NBTTagCompound) {
gameSettingsStorage = (NBTTagCompound)t;
}
}catch(IOException e) {
;
}
}
if(p != null) {
try {
NBTBase t = NBTBase.readTag(new DataInputStream(new ByteArrayInputStream(p)));
if(t != null && t instanceof NBTTagCompound) {
profileSettingsStorage = (NBTTagCompound)t;
}
}catch(IOException e) {
;
}
}
if(gameSettingsStorage == null) gameSettingsStorage = new NBTTagCompound();
if(profileSettingsStorage == null) profileSettingsStorage = new NBTTagCompound();
}
public static void saveStorageG() {
try {
ByteArrayOutputStream s = new ByteArrayOutputStream();
NBTBase.writeTag(gameSettingsStorage, new DataOutputStream(s));
GL11.saveLocalStorage("g", s.toByteArray());
} catch (IOException e) {
;
}
}
public static void saveStorageP() {
try {
ByteArrayOutputStream s = new ByteArrayOutputStream();
NBTBase.writeTag(profileSettingsStorage, new DataOutputStream(s));
GL11.saveLocalStorage("p", s.toByteArray());
} catch (IOException e) {
;
}
}
public static String dumpConfiguration() {
try {
ByteArrayOutputStream s = new ByteArrayOutputStream();
NBTBase.writeTag(gameSettingsStorage, new DataOutputStream(s));
return Base64.encodeBase64String(s.toByteArray());
} catch(Throwable e) {
return "<error>";
}
}
}

View File

@ -0,0 +1,130 @@
package net.PeytonPlayz595.nbt;
import java.io.*;
public abstract class NBTBase {
public NBTBase() {
key = null;
}
abstract void writeTagContents(DataOutput dataoutput) throws IOException;
abstract void readTagContents(DataInput datainput) throws IOException;
public abstract byte getType();
public String getKey() {
if (key == null) {
return "";
} else {
return key;
}
}
public NBTBase setKey(String s) {
key = s;
return this;
}
public static NBTBase readTag(DataInput datainput) throws IOException {
byte byte0 = datainput.readByte();
if (byte0 == 0) {
return new NBTTagEnd();
} else {
NBTBase nbtbase = createTagOfType(byte0);
nbtbase.key = datainput.readUTF();
nbtbase.readTagContents(datainput);
return nbtbase;
}
}
public static void writeTag(NBTBase nbtbase, DataOutput dataoutput) throws IOException {
dataoutput.writeByte(nbtbase.getType());
if (nbtbase.getType() == 0) {
return;
} else {
dataoutput.writeUTF(nbtbase.getKey());
nbtbase.writeTagContents(dataoutput);
return;
}
}
public static NBTBase createTagOfType(byte byte0) {
switch (byte0) {
case 0: // '\0'
return new NBTTagEnd();
case 1: // '\001'
return new NBTTagByte();
case 2: // '\002'
return new NBTTagShort();
case 3: // '\003'
return new NBTTagInt();
case 4: // '\004'
return new NBTTagLong();
case 5: // '\005'
return new NBTTagFloat();
case 6: // '\006'
return new NBTTagDouble();
case 7: // '\007'
return new NBTTagByteArray();
case 8: // '\b'
return new NBTTagString();
case 9: // '\t'
return new NBTTagList();
case 10: // '\n'
return new NBTTagCompound();
}
return null;
}
public static String getTagName(byte byte0) {
switch (byte0) {
case 0: // '\0'
return "TAG_End";
case 1: // '\001'
return "TAG_Byte";
case 2: // '\002'
return "TAG_Short";
case 3: // '\003'
return "TAG_Int";
case 4: // '\004'
return "TAG_Long";
case 5: // '\005'
return "TAG_Float";
case 6: // '\006'
return "TAG_Double";
case 7: // '\007'
return "TAG_Byte_Array";
case 8: // '\b'
return "TAG_String";
case 9: // '\t'
return "TAG_List";
case 10: // '\n'
return "TAG_Compound";
}
return "UNKNOWN";
}
private String key;
}

View File

@ -0,0 +1,31 @@
package net.PeytonPlayz595.nbt;
import java.io.*;
public class NBTTagByte extends NBTBase {
public NBTTagByte() {
}
public NBTTagByte(byte byte0) {
byteValue = byte0;
}
void writeTagContents(DataOutput dataoutput) throws IOException {
dataoutput.writeByte(byteValue);
}
void readTagContents(DataInput datainput) throws IOException {
byteValue = datainput.readByte();
}
public byte getType() {
return 1;
}
public String toString() {
return (new StringBuilder()).append("").append(byteValue).toString();
}
public byte byteValue;
}

View File

@ -0,0 +1,34 @@
package net.PeytonPlayz595.nbt;
import java.io.*;
public class NBTTagByteArray extends NBTBase {
public NBTTagByteArray() {
}
public NBTTagByteArray(byte abyte0[]) {
byteArray = abyte0;
}
void writeTagContents(DataOutput dataoutput) throws IOException {
dataoutput.writeInt(byteArray.length);
dataoutput.write(byteArray);
}
void readTagContents(DataInput datainput) throws IOException {
int i = datainput.readInt();
byteArray = new byte[i];
datainput.readFully(byteArray);
}
public byte getType() {
return 7;
}
public String toString() {
return (new StringBuilder()).append("[").append(byteArray.length).append(" bytes]").toString();
}
public byte byteArray[];
}

View File

@ -0,0 +1,182 @@
package net.PeytonPlayz595.nbt;
import java.io.*;
import java.util.*;
public class NBTTagCompound extends NBTBase {
public NBTTagCompound() {
tagMap = new HashMap();
}
void writeTagContents(DataOutput dataoutput) throws IOException {
NBTBase nbtbase;
for (Iterator iterator = tagMap.values().iterator(); iterator.hasNext(); NBTBase.writeTag(nbtbase,
dataoutput)) {
nbtbase = (NBTBase) iterator.next();
}
dataoutput.writeByte(0);
}
void readTagContents(DataInput datainput) throws IOException {
tagMap.clear();
NBTBase nbtbase;
for (; (nbtbase = NBTBase.readTag(datainput)).getType() != 0; tagMap.put(nbtbase.getKey(), nbtbase)) {
}
}
public byte getType() {
return 10;
}
public void setTag(String s, NBTBase nbtbase) {
tagMap.put(s, nbtbase.setKey(s));
}
public void setByte(String s, byte byte0) {
tagMap.put(s, (new NBTTagByte(byte0)).setKey(s));
}
public void setShort(String s, short word0) {
tagMap.put(s, (new NBTTagShort(word0)).setKey(s));
}
public void setInteger(String s, int i) {
tagMap.put(s, (new NBTTagInt(i)).setKey(s));
}
public void setLong(String s, long l) {
tagMap.put(s, (new NBTTagLong(l)).setKey(s));
}
public void setFloat(String s, float f) {
tagMap.put(s, (new NBTTagFloat(f)).setKey(s));
}
public void setDouble(String s, double d) {
tagMap.put(s, (new NBTTagDouble(d)).setKey(s));
}
public void setString(String s, String s1) {
tagMap.put(s, (new NBTTagString(s1)).setKey(s));
}
public void setByteArray(String s, byte abyte0[]) {
tagMap.put(s, (new NBTTagByteArray(abyte0)).setKey(s));
}
public void setCompoundTag(String s, NBTTagCompound nbttagcompound) {
tagMap.put(s, nbttagcompound.setKey(s));
}
public void setBoolean(String s, boolean flag) {
setByte(s, ((byte) (flag ? 1 : 0)));
}
public boolean hasKey(String s) {
return tagMap.containsKey(s);
}
public byte getByte(String s) {
if (!tagMap.containsKey(s)) {
return 0;
} else {
return ((NBTTagByte) tagMap.get(s)).byteValue;
}
}
public short getShort(String s) {
if (!tagMap.containsKey(s)) {
return 0;
} else {
return ((NBTTagShort) tagMap.get(s)).shortValue;
}
}
public int getInteger(String s) {
if (!tagMap.containsKey(s)) {
return 0;
} else {
return ((NBTTagInt) tagMap.get(s)).intValue;
}
}
public long getLong(String s) {
if (!tagMap.containsKey(s)) {
return 0L;
} else {
return ((NBTTagLong) tagMap.get(s)).longValue;
}
}
public float getFloat(String s) {
if (!tagMap.containsKey(s)) {
return 0.0F;
} else {
return ((NBTTagFloat) tagMap.get(s)).floatValue;
}
}
public double getDouble(String s) {
if (!tagMap.containsKey(s)) {
return 0.0D;
} else {
return ((NBTTagDouble) tagMap.get(s)).doubleValue;
}
}
public String getString(String s) {
if (!tagMap.containsKey(s)) {
return "";
} else {
return ((NBTTagString) tagMap.get(s)).stringValue;
}
}
public byte[] getByteArray(String s) {
if (!tagMap.containsKey(s)) {
return new byte[0];
} else {
return ((NBTTagByteArray) tagMap.get(s)).byteArray;
}
}
public NBTTagCompound getCompoundTag(String s) {
if (!tagMap.containsKey(s)) {
return new NBTTagCompound();
} else {
return (NBTTagCompound) tagMap.get(s);
}
}
public NBTTagList getTagList(String s) {
if (!tagMap.containsKey(s)) {
return new NBTTagList();
} else {
return (NBTTagList) tagMap.get(s);
}
}
public boolean getBoolean(String s) {
return getByte(s) != 0;
}
public String toString() {
return (new StringBuilder()).append("").append(tagMap.size()).append(" entries").toString();
}
public boolean hasNoTags() {
return tagMap.size() == 0;
}
private Map tagMap;
public NBTBase getTag(String s) {
return (NBTBase) tagMap.get(s);
}
public static Map<String,NBTBase> getTagMap(NBTTagCompound nb) {
return nb.tagMap;
}
}

View File

@ -0,0 +1,31 @@
package net.PeytonPlayz595.nbt;
import java.io.*;
public class NBTTagDouble extends NBTBase {
public NBTTagDouble() {
}
public NBTTagDouble(double d) {
doubleValue = d;
}
void writeTagContents(DataOutput dataoutput) throws IOException {
dataoutput.writeDouble(doubleValue);
}
void readTagContents(DataInput datainput) throws IOException {
doubleValue = datainput.readDouble();
}
public byte getType() {
return 6;
}
public String toString() {
return (new StringBuilder()).append("").append(doubleValue).toString();
}
public double doubleValue;
}

View File

@ -0,0 +1,23 @@
package net.PeytonPlayz595.nbt;
import java.io.*;
public class NBTTagEnd extends NBTBase {
public NBTTagEnd() {
}
void readTagContents(DataInput datainput) throws IOException {
}
void writeTagContents(DataOutput dataoutput) throws IOException {
}
public byte getType() {
return 0;
}
public String toString() {
return "END";
}
}

View File

@ -0,0 +1,31 @@
package net.PeytonPlayz595.nbt;
import java.io.*;
public class NBTTagFloat extends NBTBase {
public NBTTagFloat() {
}
public NBTTagFloat(float f) {
floatValue = f;
}
void writeTagContents(DataOutput dataoutput) throws IOException {
dataoutput.writeFloat(floatValue);
}
void readTagContents(DataInput datainput) throws IOException {
floatValue = datainput.readFloat();
}
public byte getType() {
return 5;
}
public String toString() {
return (new StringBuilder()).append("").append(floatValue).toString();
}
public float floatValue;
}

View File

@ -0,0 +1,31 @@
package net.PeytonPlayz595.nbt;
import java.io.*;
public class NBTTagInt extends NBTBase {
public NBTTagInt() {
}
public NBTTagInt(int i) {
intValue = i;
}
void writeTagContents(DataOutput dataoutput) throws IOException {
dataoutput.writeInt(intValue);
}
void readTagContents(DataInput datainput) throws IOException {
intValue = datainput.readInt();
}
public byte getType() {
return 3;
}
public String toString() {
return (new StringBuilder()).append("").append(intValue).toString();
}
public int intValue;
}

View File

@ -0,0 +1,63 @@
package net.PeytonPlayz595.nbt;
import java.io.*;
import java.util.ArrayList;
import java.util.List;
public class NBTTagList extends NBTBase {
public NBTTagList() {
tagList = new ArrayList();
}
void writeTagContents(DataOutput dataoutput) throws IOException {
if (tagList.size() > 0) {
tagType = ((NBTBase) tagList.get(0)).getType();
} else {
tagType = 1;
}
dataoutput.writeByte(tagType);
dataoutput.writeInt(tagList.size());
for (int i = 0; i < tagList.size(); i++) {
((NBTBase) tagList.get(i)).writeTagContents(dataoutput);
}
}
void readTagContents(DataInput datainput) throws IOException {
tagType = datainput.readByte();
int i = datainput.readInt();
tagList = new ArrayList();
for (int j = 0; j < i; j++) {
NBTBase nbtbase = NBTBase.createTagOfType(tagType);
nbtbase.readTagContents(datainput);
tagList.add(nbtbase);
}
}
public byte getType() {
return 9;
}
public String toString() {
return (new StringBuilder()).append("").append(tagList.size()).append(" entries of type ")
.append(NBTBase.getTagName(tagType)).toString();
}
public void setTag(NBTBase nbtbase) {
tagType = nbtbase.getType();
tagList.add(nbtbase);
}
public NBTBase tagAt(int i) {
return (NBTBase) tagList.get(i);
}
public int tagCount() {
return tagList.size();
}
private List tagList;
private byte tagType;
}

View File

@ -0,0 +1,31 @@
package net.PeytonPlayz595.nbt;
import java.io.*;
public class NBTTagLong extends NBTBase {
public NBTTagLong() {
}
public NBTTagLong(long l) {
longValue = l;
}
void writeTagContents(DataOutput dataoutput) throws IOException {
dataoutput.writeLong(longValue);
}
void readTagContents(DataInput datainput) throws IOException {
longValue = datainput.readLong();
}
public byte getType() {
return 4;
}
public String toString() {
return (new StringBuilder()).append("").append(longValue).toString();
}
public long longValue;
}

View File

@ -0,0 +1,31 @@
package net.PeytonPlayz595.nbt;
import java.io.*;
public class NBTTagShort extends NBTBase {
public NBTTagShort() {
}
public NBTTagShort(short word0) {
shortValue = word0;
}
void writeTagContents(DataOutput dataoutput) throws IOException {
dataoutput.writeShort(shortValue);
}
void readTagContents(DataInput datainput) throws IOException {
shortValue = datainput.readShort();
}
public byte getType() {
return 2;
}
public String toString() {
return (new StringBuilder()).append("").append(shortValue).toString();
}
public short shortValue;
}

View File

@ -0,0 +1,36 @@
package net.PeytonPlayz595.nbt;
import java.io.*;
public class NBTTagString extends NBTBase {
public NBTTagString() {
}
public NBTTagString(String s) {
stringValue = s;
if (s == null) {
throw new IllegalArgumentException("Empty string not allowed");
} else {
return;
}
}
void writeTagContents(DataOutput dataoutput) throws IOException {
dataoutput.writeUTF(stringValue);
}
void readTagContents(DataInput datainput) throws IOException {
stringValue = datainput.readUTF();
}
public byte getType() {
return 8;
}
public String toString() {
return (new StringBuilder()).append("").append(stringValue).toString();
}
public String stringValue;
}

View File

@ -13,6 +13,7 @@ import org.teavm.jso.dom.html.HTMLElement;
import com.mojang.minecraft.Minecraft; import com.mojang.minecraft.Minecraft;
import com.mojang.minecraft.SessionData; import com.mojang.minecraft.SessionData;
import net.PeytonPlayz585.storage.LocalStorageManager;
import net.lax1dude.eaglercraft.adapter.EaglerAdapterImpl2; import net.lax1dude.eaglercraft.adapter.EaglerAdapterImpl2;
public class Client { public class Client {
@ -46,6 +47,7 @@ public class Client {
private static void run0() { private static void run0() {
System.out.println(" -------- starting minecraft -------- "); System.out.println(" -------- starting minecraft -------- ");
instance = new Minecraft(); instance = new Minecraft();
LocalStorageManager.loadStorage();
run1(); run1();
} }

View File

@ -63,6 +63,7 @@ import org.teavm.jso.websocket.WebSocket;
import net.lax1dude.eaglercraft.adapter.teavm.WebGLQuery; import net.lax1dude.eaglercraft.adapter.teavm.WebGLQuery;
import net.lax1dude.eaglercraft.adapter.teavm.WebGLVertexArray; import net.lax1dude.eaglercraft.adapter.teavm.WebGLVertexArray;
import net.PeytonPlayz585.math.MathHelper; import net.PeytonPlayz585.math.MathHelper;
import net.PeytonPlayz585.storage.LocalStorageManager;
import net.lax1dude.eaglercraft.AssetRepository; import net.lax1dude.eaglercraft.AssetRepository;
import net.lax1dude.eaglercraft.Base64; import net.lax1dude.eaglercraft.Base64;
import net.lax1dude.eaglercraft.Client; import net.lax1dude.eaglercraft.Client;
@ -114,6 +115,14 @@ public class EaglerAdapterImpl2 {
} }
} }
public static void onWindowUnload() {
LocalStorageManager.saveStorageG();
LocalStorageManager.saveStorageP();
}
@JSBody(params = { }, script = "window.onbeforeunload = function(){javaMethods.get('net.lax1dude.eaglercraft.adapter.EaglerAdapterImpl2.onWindowUnload()V').invoke();return false;};")
private static native void onBeforeCloseRegister();
public static final String[] fileContentsLines(String path) { public static final String[] fileContentsLines(String path) {
String contents = fileContents(path); String contents = fileContents(path);
if(contents == null) { if(contents == null) {
@ -306,10 +315,9 @@ public class EaglerAdapterImpl2 {
forceMouseGrabbed(); forceMouseGrabbed();
} }
}); });
onBeforeCloseRegister();
initFileChooser(); initFileChooser();
//EarlyLoadScreen.paintScreen();
OpenState st = IndexedDBFilesystem.initialize(); OpenState st = IndexedDBFilesystem.initialize();
if(st != OpenState.OPENED) { if(st != OpenState.OPENED) {
if(st == OpenState.LOCKED) { if(st == OpenState.LOCKED) {
@ -328,20 +336,6 @@ public class EaglerAdapterImpl2 {
e.printStackTrace(); e.printStackTrace();
} }
// if(mouseEvents.isEmpty() && keyEvents.isEmpty() && !hasBeenActive()) {
// EarlyLoadScreen.paintEnable();
//
// while(mouseEvents.isEmpty() && keyEvents.isEmpty()) {
// try {
// Thread.sleep(100l);
// } catch (InterruptedException e) {
// ;
// }
// }
// }
audioctx = AudioContext.create();
mouseEvents.clear(); mouseEvents.clear();
keyEvents.clear(); keyEvents.clear();
} }