Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upstreamify profiles #2390

Merged
merged 3 commits into from
Dec 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,8 @@ public static List<String> getJavaArgs(Context ctx) {

"-Dext.net.resolvPath=" +new File(Tools.DIR_DATA,"resolv.conf").getAbsolutePath(),

"-Dlog4j2.formatMsgNoLookups=true", //Log4j RCE mitigation

"-Dnet.minecraft.clientmodname=" + Tools.APP_NAME,
"-Dfml.earlyprogresswindow=false" //Forge 1.14+ workaround
};
Expand Down Expand Up @@ -538,7 +540,6 @@ private static int getDetectedVersion() {
public static native void setupExitTrap(Context context);
// Obtain AWT screen pixels to render on Android SurfaceView
public static native int[] renderAWTScreenFrame(/* Object canvas, int width, int height */);

static {
System.loadLibrary("pojavexec");
System.loadLibrary("pojavexec_awt");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
import java.io.IOException;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;

public class MCOptionUtils
{
Expand Down Expand Up @@ -56,9 +58,28 @@ public static void set(String key, String value) {
parameterMap.put(key,value);
}

/** Set an array of String, instead of a simple value. Not supported on all options */
public static void set(String key, List<String> values){
parameterMap.put(key, values.toString());
}

public static String get(String key){
return parameterMap.get(key);
}

/** @return A list of values from an array stored as a string */
public static List<String> getAsList(String key){
String value = get(key);

// Fallback if the value doesn't exist
if (value == null) return new ArrayList<>();

// Remove the edges
value = value.replace("[", "").replace("]", "");
if (value.isEmpty()) return new ArrayList<>();

return Arrays.asList(value.split(","));
}

public static void save() {
StringBuilder result = new StringBuilder();
Expand Down Expand Up @@ -89,6 +110,8 @@ public static int getMcScale() {
return guiScale;
}

/** Add a file observer to reload options on file change
* Listeners get notified of the change */
private static void setupFileObserver(){
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q){
fileObserver = new FileObserver(new File(Tools.DIR_GAME_NEW + "/options.txt"), FileObserver.MODIFY) {
Expand All @@ -111,6 +134,7 @@ public void onEvent(int i, @Nullable String s) {
fileObserver.startWatching();
}

/** Notify the option listeners */
public static void notifyListeners(){
for(WeakReference<MCOptionListener> weakReference : optionListeners){
MCOptionListener optionListener = weakReference.get();
Expand All @@ -120,10 +144,12 @@ public static void notifyListeners(){
}
}

/** Add an option listener, notice how we don't have a reference to it */
public static void addMCOptionListener(MCOptionListener listener){
optionListeners.add(new WeakReference<>(listener));
}

/** Remove a listener from existence, or at least, its reference here */
public static void removeMCOptionListener(MCOptionListener listener){
for(WeakReference<MCOptionListener> weakReference : optionListeners){
MCOptionListener optionListener = weakReference.get();
Expand Down