diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 00000000..7baaf5c3 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "java-cef"] + path = java-cef + url = https://github.com/CinemaMod/java-cef.git \ No newline at end of file diff --git a/build.gradle b/build.gradle index a33198e7..f496d650 100644 --- a/build.gradle +++ b/build.gradle @@ -1,18 +1,12 @@ -buildscript { - repositories { - maven { url = 'https://maven.minecraftforge.net' } - mavenCentral() - maven { url = 'https://repo.spongepowered.org/repository/maven-public/' } - } - dependencies { - classpath group: 'net.minecraftforge.gradle', name: 'ForgeGradle', version: '5.1.+', changing: true - classpath 'org.spongepowered:mixingradle:0.7-SNAPSHOT' - } +import net.minecraftforge.gradle.patcher.tasks.ReobfuscateJar + +plugins { + id "de.undercouch.download" version "5.3.0" + id 'eclipse' + id 'maven-publish' + id 'net.minecraftforge.gradle' version '5.1.+' + id 'org.spongepowered.mixin' version '0.7.+' } -apply plugin: 'net.minecraftforge.gradle' -apply plugin: 'eclipse' -apply plugin: 'maven-publish' -//apply from: 'https://raw.githubusercontent.com/SizableShrimp/Forge-Class-Remapper/main/classremapper.gradle' version = mod_version group = maven_group // http://maven.apache.org/guides/mini/guide-naming-conventions.html @@ -21,88 +15,84 @@ java.toolchain.languageVersion = JavaLanguageVersion.of(17) println('Java: ' + System.getProperty('java.version') + ' JVM: ' + System.getProperty('java.vm.version') + '(' + System.getProperty('java.vendor') + ') Arch: ' + System.getProperty('os.arch')) minecraft { - mappings channel: 'official', version: '1.19' - //accessTransformer = file('src/main/resources/META-INF/accesstransformer.cfg') - runs { - client { - properties 'mixin.env.remapRefMap': 'true' - property 'mixin.env.refMapRemappingFile', "${project.projectDir}/build/createSrgToMcp/output.srg" - workingDirectory project.file('run') - arg "-mixin.config=forgecef.mixins.json" - property 'forge.logging.console.level', 'debug' - - mods { - citadel { - source sourceSets.main - } - } - } - - server { - properties 'mixin.env.remapRefMap': 'true' - property 'mixin.env.refMapRemappingFile', "${project.projectDir}/build/createSrgToMcp/output.srg" - workingDirectory project.file('run') - arg "-mixin.config=forgecef.mixins.json" - - - property 'forge.logging.console.level', 'debug' - - mods { - citadel { - source sourceSets.main - } - } - } - - data { - workingDirectory project.file('run') - properties 'mixin.env.remapRefMap': 'true' - property 'mixin.env.refMapRemappingFile', "${project.projectDir}/build/createSrgToMcp/output.srg" - property 'forge.logging.console.level', 'debug' - args '--mod', 'examplemod', '--all', '--output', file('src/generated/resources/'), '--existing', sourceSets.main.resources.srcDirs[0] - mods { - citadel { - source sourceSets.main - } - } - } - } + mappings channel: 'official', version: '1.19' + //accessTransformer = file('src/main/resources/META-INF/accesstransformer.cfg') + runs { + client { + properties 'mixin.env.remapRefMap': 'true' + property 'mixin.env.refMapRemappingFile', "${project.projectDir}/build/createSrgToMcp/output.srg" + workingDirectory project.file('run') + arg "-mixin.config=forgecef.mixins.json" + property 'forge.logging.console.level', 'debug' + + mods { + citadel { + source sourceSets.main + } + } + } + + server { + properties 'mixin.env.remapRefMap': 'true' + property 'mixin.env.refMapRemappingFile', "${project.projectDir}/build/createSrgToMcp/output.srg" + workingDirectory project.file('run') + arg "-mixin.config=forgecef.mixins.json" + + + property 'forge.logging.console.level', 'debug' + + mods { + citadel { + source sourceSets.main + } + } + } + + data { + workingDirectory project.file('run') + properties 'mixin.env.remapRefMap': 'true' + property 'mixin.env.refMapRemappingFile', "${project.projectDir}/build/createSrgToMcp/output.srg" + property 'forge.logging.console.level', 'debug' + args '--mod', 'examplemod', '--all', '--output', file('src/generated/resources/'), '--existing', sourceSets.main.resources.srcDirs[0] + mods { + citadel { + source sourceSets.main + } + } + } + } } -repositories{ - maven { - name = "CurseMaven" - url = "https://www.cursemaven.com" - content { - includeGroup "curse.maven" - } - } - mavenCentral() +repositories { + maven { + name = "CurseMaven" + url = "https://www.cursemaven.com" + content { + includeGroup "curse.maven" + } + } + mavenCentral() } dependencies { - minecraft 'net.minecraftforge:forge:1.19.2-43.2.6' - annotationProcessor 'org.spongepowered:mixin:0.8.5:processor' -} - -sourceSets { - main.resources.srcDirs += 'src/generated/resources' + minecraft 'net.minecraftforge:forge:1.19.2-43.2.6' + annotationProcessor 'org.spongepowered:mixin:0.8.5:processor' } // Example for how to get properties into the manifest for reading by the runtime.. jar { - manifest { - attributes([ - "Specification-Title": "mcef", - "Specification-Vendor": "forgecef", - "Specification-Version": "1", // We are version 1 of ourselves - "Implementation-Title": project.name, - "Implementation-Version": "${version}", - "Implementation-Vendor" :"forgecef", - "Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ"), - "MixinConfigs": "forgecef.mixins.json" - ]) - } + manifest { + attributes([ + "Specification-Title" : "mcef", + "Specification-Vendor" : "forgecef", + "Specification-Version" : "1", // We are version 1 of ourselves + "Implementation-Title" : project.name, + "Implementation-Version" : "${version}", + "Implementation-Vendor" : "forgecef", + "Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ"), + "MixinConfigs" : "forgecef.mixins.json" + ]) + } } // Example configuration to allow publishing using the maven-publish task @@ -111,29 +101,96 @@ jar { // Note you'll need to add a repository here def reobfFile = file("$buildDir/reobfJar/output.jar") def reobfArtifact = artifacts.add('default', reobfFile) { - type 'jar' - builtBy 'reobfJar' -} -publishing { - publications { - mavenJava(MavenPublication) { - artifact reobfArtifact - } - } - repositories { - maven { - url "file:///${project.projectDir}/mcmodsrepo" - } - } + type 'jar' + builtBy 'reobfJar' } apply plugin: 'org.spongepowered.mixin' mixin { - add sourceSets.main, "forgecef.refmap.json" + add sourceSets.main, "forgecef.refmap.json" } task deobfJar(type: Jar) { - from sourceSets.main.output - classifier = 'deobf' + from sourceSets.main.output + classifier = 'deobf' +} + +sourceSets { + main.resources.srcDirs += 'src/generated/resources' + + jcef { + java { + srcDir "java-cef/java" + exclude "**/tests/**" + } + } + + main { + compileClasspath += jcef.output + runtimeClasspath += jcef.output + } +} + +import org.apache.tools.ant.taskdefs.condition.Os + +// From com.cinemamod.fabric.cef.Platform enum +var platforms = ["linux_amd64", "linux_arm64", "windows_amd64", "windows_arm64", "macos_amd64", "macos_arm64"] + +task downloadJcef { + for (String platform : platforms) { + try { + "https://ewr1.vultrobjects.com/cinemamod-libraries/cef/$cef_branch/$platform/manifest.txt".toURL().text.eachLine { + var fileHash = it.split(" ")[0] + var relFilePath = it.split(" ")[1] + var cefResourceUrl = "https://ewr1.vultrobjects.com/cinemamod-libraries/cef/$cef_branch/$platform/$relFilePath" + download.run { + src cefResourceUrl + dest "src/main/resources/assets/mcef/cef/$platform/$relFilePath" + overwrite false + } + if (Os.isFamily(Os.FAMILY_UNIX)) { + if (relFilePath.contains("chrome-sandbox") || relFilePath.contains("jcef_helper")) { + exec { + commandLine("chmod", "700", "src/main/resources/assets/mcef/cef/$platform/$relFilePath") + } + } + } + } + } catch (Exception e) { + println("Skipping CEF libraries for $cef_branch/$platform") + println(e.getMessage()) + } + } +} + +void createPlatformJarTask(String platform) { + Task platformJarTask = task("jar_$platform", type: ReobfuscateJar, dependsOn: jar) { + input = jar.archiveFile + + onlyIf { + new File("src/main/resources/assets/mcef/cef/$platform").exists() + } + } + + build.dependsOn(platformJarTask) +} + +platforms.forEach(platform -> createPlatformJarTask(platform)) + +// configure the maven publication +publishing { + publications { + mavenJava(MavenPublication) { + from components.java + } + } + + // See https://docs.gradle.org/current/userguide/publishing_maven.html for information on how to set up publishing. + repositories { + // Add repositories to publish to here. + // Notice: This block does NOT have the same function as the block in the top level. + // The repositories here will be used for publishing your artifact, not for + // retrieving dependencies. + } } \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index 476c0eab..da3134f6 100644 --- a/gradle.properties +++ b/gradle.properties @@ -13,3 +13,6 @@ archives_base_name = mcef # Dependencies forge_version=1.19.2-43.2.6 + +# CEF settings +cef_branch=4896 diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 54e9a60b..856da69b 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.3-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists \ No newline at end of file diff --git a/settings.gradle b/settings.gradle new file mode 100644 index 00000000..914d1ff5 --- /dev/null +++ b/settings.gradle @@ -0,0 +1,20 @@ +pluginManagement { + repositories { + gradlePluginPortal() + maven { url = 'https://maven.minecraftforge.net/' } + } + resolutionStrategy { + eachPlugin { + switch (requested.id.toString()) { + case "net.minecraftforge.gradle": { + useModule("${requested.id}:ForgeGradle:${requested.version}") + break + } + case "org.spongepowered.mixin": { + useModule("org.spongepowered:mixingradle:${requested.version}") + break; + } + } + } + } +} \ No newline at end of file diff --git a/src/main/java/net/montoyo/mcef/client/ClientProxy.java b/src/main/java/net/montoyo/mcef/client/ClientProxy.java index 096bbae1..9d579e76 100644 --- a/src/main/java/net/montoyo/mcef/client/ClientProxy.java +++ b/src/main/java/net/montoyo/mcef/client/ClientProxy.java @@ -12,7 +12,6 @@ import net.minecraftforge.event.TickEvent; import net.minecraftforge.event.entity.player.PlayerEvent; import net.minecraftforge.eventbus.api.IEventBus; -import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent; import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; import net.montoyo.mcef.BaseProxy; @@ -41,6 +40,7 @@ import java.io.BufferedReader; import java.io.File; import java.io.InputStreamReader; +import java.nio.file.Paths; import java.util.ArrayList; import java.util.HashMap; import java.util.regex.Matcher; @@ -49,6 +49,7 @@ public class ClientProxy extends BaseProxy { public static String ROOT = "."; + public static String ROOT2 = "."; public static String JCEF_ROOT = "."; public static boolean VIRTUAL = false; @@ -85,16 +86,44 @@ public void onInitializeClient(FMLClientSetupEvent event) { appHandler.setArgs(MCEF.CEF_ARGS); - ROOT = mc.gameDirectory.getAbsolutePath().replaceAll("\\\\", "/"); + ROOT = System.getProperty("user.dir"); + ROOT2 = Minecraft.getInstance().gameDirectory.getAbsolutePath(); + if (ROOT.endsWith(".")) ROOT = ROOT.substring(0, ROOT.length() - 1); if (ROOT.endsWith("/")) ROOT = ROOT.substring(0, ROOT.length() - 1); - JCEF_ROOT = ROOT + "/jcef"; + if (ROOT2.endsWith(".")) + ROOT2 = ROOT2.substring(0, ROOT2.length() - 1); + + if (ROOT2.endsWith("/")) + ROOT2 = ROOT2.substring(0, ROOT2.length() - 1); - File fileListing = new File(new File(ROOT), "config"); + if(ROOT.contains("run")) { + ROOT = ROOT.substring(0, ROOT.length() - 3); + } + + if (OS.isWindows()) { + if(System.getProperty("os.arch").equals("amd64")) { + JCEF_ROOT = ROOT + Paths.get("src/main/resources/assets/mcef/cef/windows_amd64"); + } else { + JCEF_ROOT = ROOT + Paths.get("src/main/resources/assets/mcef/cef/windows_arm64"); + } + } else if (OS.isLinux()) { + if(System.getProperty("os.arch").equals("amd64")) { + JCEF_ROOT = ROOT + Paths.get("src/main/resources/assets/mcef/cef/linux_amd64"); + } else { + JCEF_ROOT = ROOT + Paths.get("src/main/resources/assets/mcef/cef/linux_arm64"); + } + } else { + VIRTUAL = true; + } + + System.out.println(JCEF_ROOT); + + File fileListing = new File(new File(ROOT2), "config"); IProgressListener ipl; RemoteConfig cfg = new RemoteConfig(); @@ -112,11 +141,11 @@ public void onInitializeClient(FMLClientSetupEvent event) { System.out.println("Updating MCEF missing files... "); - if (!cfg.downloadMissing(ipl)) { + /*if (!cfg.downloadMissing(ipl)) { Log.warning("Going in virtual mode; couldn't download resources."); VIRTUAL = true; return; - } + }*/ if (!cfg.updateFileListing(fileListing, true)) Log.warning("There was a problem while updating file list. Uninstall may not delete all files."); diff --git a/src/main/java/org/cef/CefApp.java b/src/main/java/org/cef/CefApp.java index 290d927a..19969bcd 100644 --- a/src/main/java/org/cef/CefApp.java +++ b/src/main/java/org/cef/CefApp.java @@ -15,6 +15,7 @@ import java.nio.file.Path; import java.nio.file.Paths; import java.util.HashSet; +import java.util.List; /** * Exposes static methods for managing the global CEF context. @@ -415,11 +416,11 @@ private final void shutdown() { } boolean isDoingWork = false; - + public boolean isDoingWork() { return isDoingWork; } - + /** * Perform a single message loop iteration. Used on all platforms except * Windows with windowed rendering. @@ -459,7 +460,7 @@ public void actionPerformed(ActionEvent evt) { // Timer has timed out. workTimer_.stop(); workTimer_ = null; - + isDoingWork = true; N_DoMessageLoopWork(); @@ -504,16 +505,32 @@ public static final boolean startup(String[] args) { } private static final String getJcefLibPath() { - Path runtimeDir = Paths.get(""); - final Path jcefPath; - if (OS.isWindows() || OS.isLinux()) { - jcefPath = runtimeDir.resolve("jcef"); - } else if (OS.isMacintosh()) { - jcefPath = runtimeDir.resolve("jcef/jcef_app.app/Contents/Java"); + Path jcefPath; + if (OS.isWindows()) { + if(System.getProperty("os.arch").equals("amd64")) { + jcefPath = Paths.get("src/main/resources/assets/mcef/cef/windows_amd64"); + } else { + jcefPath = Paths.get("src/main/resources/assets/mcef/cef/windows_arm64"); + } + } else if (OS.isLinux()) { + if(System.getProperty("os.arch").equals("amd64")) { + jcefPath = Paths.get("src/main/resources/assets/mcef/cef/linux_amd64"); + } else { + jcefPath = Paths.get("src/main/resources/assets/mcef/cef/linux_arm64"); + } + } else { + return null; + } + + if (jcefPath != null) { + String ROOT = String.valueOf(jcefPath.toAbsolutePath()); + if(ROOT.contains("run")) { + ROOT = ROOT.replaceAll("run", ""); + } + return ROOT; } else { - jcefPath = null; + return null; } - return jcefPath != null ? jcefPath.toAbsolutePath().toString() : null; } /**