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

Support code mods #37

Merged
merged 6 commits into from
Mar 23, 2023
Merged

Support code mods #37

merged 6 commits into from
Mar 23, 2023

Conversation

yihleego
Copy link
Contributor

@yihleego yihleego commented Feb 9, 2023

1. ProjectXBootstrap.java (New)

Add ProjectXBootstrap to replace ProjectXApp, which is used to boot and load jar mods, such as replacing deployment.properties at runtime.

2. LauncherDigester.java (New)

Add LauncherDigester to modify getdown.txt and digest.txt before SK starts.

getdown.txt:

...
# KnightLauncher resources
code = KnightLauncher.jar
class = com.lucasallegri.bootstrap.ProjectXBootstrap
client.class = com.lucasallegri.bootstrap.ProjectXBootstrap

digest.txt

...
KnightLauncher.jar = ...
digest.txt = ...

3. ModLoader.java (Modified)

It now reads the jar mods correctly

4. GameSettings.java (Modified)

GameSettings.loadConnectionSettings() is no longer used, it is replaced by ProjectXBootstrap.loadConnectionSettings().

static void loadConnectionSettings() throws Exception {
// com.threerings.projectx.util.DeploymentConfig
Field configField = Class.forName("com.threerings.projectx.util.a").getDeclaredField("akf");
configField.setAccessible(true);
Object config = configField.get(null);
// com.samskivert.util.Config
Field propsField = Class.forName("com.samskivert.util.m").getDeclaredField("AQ");
propsField.setAccessible(true);
// deployment.properties
Properties properties = (Properties) propsField.get(config);
// Replace connection settings
Map<String, String> mapping = new HashMap<>();
mapping.put("server_host", "game.endpoint");
mapping.put("server_ports", "game.port");
mapping.put("datagram_ports", "game.port");
mapping.put("key.public", "game.publicKey");
mapping.put("client_root_url", "game.getdownURL");
for (Map.Entry<String, String> e : mapping.entrySet()) {
String newConf = configs.getProperty(e.getValue());
if (newConf == null) {
continue;
}
newConf = newConf.trim();
String oldConf = properties.getProperty(e.getKey());
if (newConf.length() > 0 && !newConf.equals(oldConf)) {
properties.setProperty(e.getKey(), newConf);
System.out.println("[deployment.properties] Replace [" + e.getKey() + "] '" + oldConf + "' -> '" + newConf + "'");
} else {
System.out.println("[deployment.properties] No change [" + e.getKey() + "] '" + oldConf + "'");
}
}
}

5. LauncherGlobals.java (Modified)

Modify LauncherGlobals to detect the jvm path and use com.lucasallegri.bootstrap.ProjectXBootstrap instead of com.threerings.projectx.client.ProjectXApp.


I tested it on Mac and Windows 10 (except Linux), both zip mods and jar mods work:
image

@lucasluqui
Copy link
Owner

Please wait for a bit. I will be reviewing this in the upcoming days and hopefully merging and testing for a later release.

@yihleego
Copy link
Contributor Author

Currently KL is based on Java 8, so starting SK through ProjectXBootstrap requires the users' jvm to also be Java 8.

Do we need to split ProjectXBootstrap from KL project and compile with Java 5 or 6?

@Crowfunder
Copy link
Contributor

What is the proposed code mod structure? It needs to be generalized and kept relatively simple to make creating such mods easier.

@yihleego yihleego changed the title Support JAR mods Support code mods Feb 17, 2023
@yihleego
Copy link
Contributor Author

yihleego commented Feb 17, 2023

What is the proposed code mod structure? It needs to be generalized and kept relatively simple to make creating such mods easier.

Making code mods requires proficiency in Java, developers need to read the client code, and then try to modify the code. So I think the hardest thing is reading the code.

I don't have a best standard project layout, I am waiting for @lucasluqui to design one.
Or you can design one yourself, KL will not limit it in my opinion.

See also mods I made: The core provides tools for creating classes, modifying classes, modifying methods, and adding fields, and also provides APIs for quickly adding commands, example:
https://github.com/spiralstudio/mods/blob/96d011ed687df1eddcd3374fcbb0654981bd9aa4/camera/src/main/java/com/spiralstudio/mod/camera/Main.java#L34-L53
https://github.com/spiralstudio/mods/blob/96d011ed687df1eddcd3374fcbb0654981bd9aa4/camera/src/main/java/com/spiralstudio/mod/camera/Main.java#L137-L160

@The-File
Copy link

Code mods might be required for running the latest JVM as well, depending on how you launch projectx.

Trying to use default getdown, you'll need to block "jvmarg = -XX:+AggressiveOpts" from being set, this can be done with a simple code mod. Of course, you could also just ship your own getdown build and do it there.

You'll also need to swap out native libs for LWJGL with their latest 2.9.X variant, for compatibility purposes.

You'll also need to specify "--add-opens=java.*****=ALL-UNNAMED" type arguments for every single internal JDK API used for Java 16+.

That said, Java 20 is possible and runs SK perfectly fine:

image

@lucasluqui
Copy link
Owner

Code mods might be required for running the latest JVM as well, depending on how you launch projectx.

Trying to use default getdown, you'll need to block "jvmarg = -XX:+AggressiveOpts" from being set, this can be done with a simple code mod. Of course, you could also just ship your own getdown build and do it there.

You'll also need to swap out native libs for LWJGL with their latest 2.9.X variant, for compatibility purposes.

You'll also need to specify "--add-opens=java.*****=ALL-UNNAMED" type arguments for every single internal JDK API used for Java 16+.

That said, Java 20 is possible and runs SK perfectly fine:

image

I understand where the enthusiasm of getting the game running on bleeding edge, much more modern Java versions comes from but the gains of going through all the hoops is less than 1%, at most.

Given all the issues that'd rise from supporting everything above Java 8 -on top of the ones we already have- Knight Launcher does not aim to support anything higher than so.

Of course this would not hinder the possibility of tackling it on your own and getting all set up manually, it's just not going to be supported by default nor given assistance by us.

@The-File
Copy link

The-File commented Mar 22, 2023

That said, there should still be modifications put in place to allow the option of running the latest Java, even if you don't install or provide such.

Additionally, there are quite a few Garbage Collection changes that may interest people, that aren't available for older Java variants.

@lucasluqui
Copy link
Owner

Code mods are not a requirement for Java 8+ VMs to function. I won't merge or implement any VM compatibility specific modifications into KL or the proposed code mods functionality by leego for the reason I detailed above.

Users that really want to go the extra mile are free to do so just not through KL.

@The-File
Copy link

...and with that said, that's why it was brought up in this thread, as it would be a use case for code modding.

@lucasluqui lucasluqui merged commit 31425d5 into lucasluqui:master Mar 23, 2023
@The-File
Copy link

Getdown code modification found to be unnecessary for running bleeding edge Java.

As per The-File/SK-Fixed#2

@The-File
Copy link

The-File commented Sep 3, 2023

ProjectXBootstrap.java is dependent on the version of spiral knights being utilized.

Specifically because the game client uses ProGuard obfuscation for method/class/field/etc obfuscation. The smallest change to an irrelevant part of the client will cause the obfuscator in the build script to be run again and thus create class files that are mutable even with no functional changes.

@The-File
Copy link

The-File commented Sep 3, 2023

You'd need to resolve for fields/methods/class names dynamically rather than in source code.

@The-File
Copy link

The-File commented Sep 3, 2023

In other words, if Spiral Knights ever updates in the future due to a one line change in the client to a part knight launcher nor code mods touch, nor should care about, ProjectXBootstrap.java would likely fail to work.

Repository owner locked as off-topic and limited conversation to collaborators Sep 8, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants