aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gq/malwarefight/nosession/mixin/L2Tweaker.java
blob: 8736ca45dbd6ff6b681723f4ca7f07f54e289827 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package gq.malwarefight.nosession.mixin;

import net.minecraft.launchwrapper.ITweaker;
import net.minecraft.launchwrapper.Launch;
import net.minecraft.launchwrapper.LaunchClassLoader;
import net.minecraft.launchwrapper.LogWrapper;
import org.apache.logging.log4j.Level;
import org.spongepowered.asm.launch.MixinBootstrap;

import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

@SuppressWarnings("unused") // is used, but not mentioned directly
public class L2Tweaker implements ITweaker {

    public final ArrayList<ITweaker> allTweakers = new ArrayList<>();

    @Override
    @SuppressWarnings("unchecked")
    public void acceptOptions(List<String> args, File gameDir, File assetsDir, String profile) {
        ArrayList<String> argsCopy = new ArrayList<>(args);
        for (int i = 0; i < argsCopy.size(); i++) {
            if (argsCopy.get(i).equals("--accessToken")) {
                argsCopy.set(i + 1, "<noSessionAccessToken>");
            }
        }

        boolean any = false;
        ArrayList<ITweaker> tweakers = (ArrayList<ITweaker>) Launch.blackboard.get("Tweaks");
        // in order to prevent other mods from seeing the true list of args with the token
        // we will just call all the other tweakers from here
        for (final ITweaker tweaker : tweakers) {
            if (tweaker == this)
                continue;
            LogWrapper.log(Level.INFO, "Calling tweak class %s", tweaker.getClass().getName());
            tweaker.acceptOptions(argsCopy, gameDir, assetsDir, profile);
            tweaker.injectIntoClassLoader(Launch.classLoader);
            allTweakers.add(tweaker);
            tweakers.set(tweakers.indexOf(tweaker), new BlankTweaker());
            any = true;
        }
        if (any) {
            ((ArrayList<String>) Launch.blackboard.get("TweakClasses")).add(0,
                    Utils.getUniqueClassName()
            );
        }
    }

    @Override
    public void injectIntoClassLoader(LaunchClassLoader classLoader) {}

    @Override
    public String getLaunchTarget() {
        return MixinBootstrap.getPlatform().getLaunchTarget();
    }

    @Override
    public String[] getLaunchArguments() {
        ArrayList<String> argsFromOurTweakers = new ArrayList<>();

        for (ITweaker i: allTweakers) {
            argsFromOurTweakers.addAll(Arrays.asList(i.getLaunchArguments()));
        }
        return argsFromOurTweakers.toArray(new String[0]);
    }
}