From afd3f0f861ebe7f8957eb6abc6e19f92c7b5896a Mon Sep 17 00:00:00 2001 From: Linnea Gräf Date: Fri, 12 Apr 2024 14:32:41 +0200 Subject: Add in-game updater (#1050) Co-authored-by: IRONM00N <64110067+IRONM00N@users.noreply.github.com> --- .github/workflows/build.yml | 2 +- .github/workflows/publish.yml | 34 +++ .github/workflows/push-to-modrinth.yaml | 28 +++ .github/workflows/send_webhook_update.sh | 4 +- .github/workflows/upload-release.sh | 43 ++++ .gitignore | 3 + CONTRIBUTING.md | 127 +++------- build.gradle.kts | 201 ++++++++-------- buildSrc/generate-public-key.sh | 4 +- buildSrc/moulsign.sh | 2 +- buildSrc/moulsign.sh.asc | 3 + buildSrc/signhash.sh | 34 +++ buildSrc/src/main/kotlin/neubs/customSign.kt | 55 +++++ buildSrc/src/main/kotlin/neubs/versioning.kt | 17 +- .../moulberry/notenoughupdates/VersionConst.java | 24 ++ .../notenoughupdates/NotEnoughUpdates.java | 33 ++- .../listener/NEUEventListener.java | 4 - .../miscfeatures/updater/AutoUpdater.java | 256 --------------------- .../miscfeatures/updater/LinuxBasedUpdater.java | 47 ---- .../miscfeatures/updater/SCUCompatUpdater.java | 100 -------- .../miscfeatures/updater/SigningGithubSource.kt | 64 ++++++ .../miscfeatures/updater/SigningPool.kt | 68 ++++++ .../miscfeatures/updater/UpdateLoader.java | 141 ------------ .../notenoughupdates/options/NEUConfig.java | 8 + .../options/customtypes/ConfigVersionDisplay.java | 27 +++ .../options/separatesections/About.java | 111 +++++++++ .../moulberry/notenoughupdates/util/JarUtil.kt | 68 ++++++ .../commands/dev/DevTestCommand.kt | 1 + .../commands/help/SettingsCommand.kt | 5 + .../notenoughupdates/commands/misc/MiscCommands.kt | 11 - .../miscfeatures/updater/AutoUpdater.kt | 156 +++++++++++++ .../miscfeatures/updater/ConfigVersionGuiOption.kt | 101 ++++++++ .../resources/trusted_team_members/ironmoon.key | Bin 0 -> 294 bytes src/main/resources/trusted_team_members/jani.key | Bin 0 -> 294 bytes .../resources/trusted_team_members/lulonaut.key | Bin 0 -> 294 bytes .../resources/trusted_team_members/moulberry.key | Bin 0 -> 422 bytes src/main/resources/trusted_team_members/nea.key | Bin 0 -> 294 bytes src/main/resources/trusted_team_members/nopo.key | Bin 0 -> 294 bytes .../notenoughupdates/util/BootstrapHook.kt | 4 +- 39 files changed, 1028 insertions(+), 758 deletions(-) create mode 100644 .github/workflows/publish.yml create mode 100644 .github/workflows/push-to-modrinth.yaml create mode 100755 .github/workflows/upload-release.sh create mode 100644 buildSrc/moulsign.sh.asc create mode 100755 buildSrc/signhash.sh create mode 100644 buildSrc/src/main/kotlin/neubs/customSign.kt create mode 100644 src/main/java-templates/io/github/moulberry/notenoughupdates/VersionConst.java delete mode 100644 src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/updater/AutoUpdater.java delete mode 100644 src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/updater/LinuxBasedUpdater.java delete mode 100644 src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/updater/SCUCompatUpdater.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/updater/SigningGithubSource.kt create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/updater/SigningPool.kt delete mode 100644 src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/updater/UpdateLoader.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/options/customtypes/ConfigVersionDisplay.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/options/separatesections/About.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/util/JarUtil.kt create mode 100644 src/main/kotlin/io/github/moulberry/notenoughupdates/miscfeatures/updater/AutoUpdater.kt create mode 100644 src/main/kotlin/io/github/moulberry/notenoughupdates/miscfeatures/updater/ConfigVersionGuiOption.kt create mode 100644 src/main/resources/trusted_team_members/ironmoon.key create mode 100644 src/main/resources/trusted_team_members/jani.key create mode 100644 src/main/resources/trusted_team_members/lulonaut.key create mode 100644 src/main/resources/trusted_team_members/moulberry.key create mode 100644 src/main/resources/trusted_team_members/nea.key create mode 100644 src/main/resources/trusted_team_members/nopo.key diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 0cb85ac0..8242eef3 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -49,7 +49,7 @@ jobs: run: ./gradlew clean test remapJar --no-daemon - uses: actions/upload-artifact@v3 with: - path: build/libs/*-dep.jar + path: build/libs/*.jar - name: Update discord notification if: ${{ env.WEBHOOK_URL && success() }} run: | diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 00000000..de01458a --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,34 @@ +name: Pre-Publish + +on: + push: + tags: + - "*" + +jobs: + build: + env: + GIT_URL: ${{ github.server_url }}/${{ github.repository }}/tree/${{ github.sha }} + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + - name: Set up JDK 17 + uses: actions/setup-java@v3 + with: + java-version: 17 + distribution: temurin + - name: Set up gradle cache + uses: gradle/gradle-build-action@v2 + - name: Build with Gradle + run: ./gradlew clean test includeBackupRepo remapJar --no-daemon + env: + NEU_RELEASE: true + - uses: actions/upload-artifact@v3 + with: + path: build/libs/*.jar + - run: ./.github/workflows/upload-release.sh + env: + GH_TOKEN: ${{ github.token }} diff --git a/.github/workflows/push-to-modrinth.yaml b/.github/workflows/push-to-modrinth.yaml new file mode 100644 index 00000000..930ca13c --- /dev/null +++ b/.github/workflows/push-to-modrinth.yaml @@ -0,0 +1,28 @@ +on: + release: + types: + - published + +jobs: + upload-to-modrinth: + runs-on: ubuntu-latest + steps: + - uses: dsaltares/fetch-gh-release-asset@master + with: + version: ${{ release.id }} + regex: true + file: "*.jar" + token: ${{ secrets.GITHUB_TOKEN }} + - run: | + printf %s "$CHANGELOG" > CHANGELOG.md + env: + CHANGELOG: ${{ release.body }} + - uses: Kir-Antipov/mc-publish@v3.3 + with: + modrinth-id: GGamhqbw + modrinth-token: ${{ secrets.MODRINTH_TOKEN }} + files: "*.jar" + loaders: forge + game-versions: 1.8.9 + version: ${{ release.tag_name }} + # TODO: version-type: release diff --git a/.github/workflows/send_webhook_update.sh b/.github/workflows/send_webhook_update.sh index 7a6f932d..6111b53d 100755 --- a/.github/workflows/send_webhook_update.sh +++ b/.github/workflows/send_webhook_update.sh @@ -35,8 +35,8 @@ case "$STATUS" in SUCCESS) color="$COLOR_SUCCESS" status_message="Build succeeded." - to_upload=$(echo build/libs/*-dep.jar) - upload_name=NotEnoughUpdates-beta-dep.jar + to_upload=$(echo build/libs/*.jar) + upload_name=NotEnoughUpdates-beta.jar ;; esac diff --git a/.github/workflows/upload-release.sh b/.github/workflows/upload-release.sh new file mode 100755 index 00000000..2cbca693 --- /dev/null +++ b/.github/workflows/upload-release.sh @@ -0,0 +1,43 @@ +# +# Copyright (C) 2024 NotEnoughUpdates contributors +# +# This file is part of NotEnoughUpdates. +# +# NotEnoughUpdates is free software: you can redistribute it +# and/or modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation, either +# version 3 of the License, or (at your option) any later version. +# +# NotEnoughUpdates is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with NotEnoughUpdates. If not, see . +# + +last_tag="$(git log --pretty='%H %D'|grep -oE 'tag: [^ ]+'|sed -E 's/tag: ([^ ,]+),?/\1/'|head -2|tail -1)" +echo "Generating notes from $last_tag" +TARGET_NAME="build/libs/NotEnoughUpdates-$GITHUB_REF_NAME.jar" +mv build/libs/*.jar "$TARGET_NAME" + +read -r -d '' extra_notes </dev/null; then + preReleaseParam="--prerelease" +fi + +gh release create -t "NotEnoughUpdates $GITHUB_REF_NAME" --verify-tag "$GITHUB_REF_NAME" --generate-notes \ + --draft --notes-start-tag "$last_tag" $preReleaseParam \ + --notes "$extra_notes" "$TARGET_NAME" + diff --git a/.gitignore b/.gitignore index e02d8fc4..adb09575 100644 --- a/.gitignore +++ b/.gitignore @@ -27,3 +27,6 @@ run infer-out/ ciwork/ .DS_STORE +*.asc +secrets/* + diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index f77d0334..0d8b8ab9 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -49,110 +49,55 @@ For quicker hot swapping or if the above does not work, you can install [Single
Minimized, for your convenience -> **Release Types** -> -> Right now we can create Full Releases, Pre Releases and Hotfixes. -> -> - A Full Release is sent to all users, regardless of update stream. -> - A Pre Release is only sent to users who have opted into receiving beta updates. -> - A Hotfix is only sent to users who have *not* opted into receiving beta updates. -> - Therefore, when a bug is fixed in a hotfix update, it should *also* be fixed in a separate prerelease update. -> On the other hand, not all bugs fixed in a prerelease update need to be also dispatched in a hotfix. - -### Creating a new Full Release - -> Full Releases should be bug free, feature complete, and ideally checked by not only the community, but also by Moulberry himself, if he so desires. - -- Edit `NotEnoughUpdates.java` and change - -```java -public static final String VERSION = "2.2.0-REL"; /* Update the VERSION name */ -public static final int VERSION_ID = 20200; /* Set the VERSION_ID to match the version name like so: MAJOR * 10000 + MINOR * 100 + PATCH */ -public static final int PRE_VERSION_ID = 0; /* Reset the PRE_VERSION_ID back to 0 */ -public static final int HOTFIX_VERSION_ID = 0; /* Reset the HOTFIX_VERSION_ID back to 0 */ -``` +### Preparing a release -- Build a jar from this, either using the CI in GitHub actions, or using `gradle remapJar` directly. - - If building locally, make sure that all your changes are in version control so that the commit hash is set correctly (A non `dirty` jar) -- Create a GitHub release (marked as full release). This should also simultaneously create a tag on which to base future hotfixes. -- Edit the `update.json` in the repository and change - -```json5 -{ - "version": "2.1.0-REL", /* Update to match the VERSION name in java */ - "version_id": 20100, /* Update to match the VERSION_ID in java */ - "update_msg": "§7§m§l--------------------§6§l[§c§lNEU§6§l]§7§m§l--------------------\n\n§7A new version, v§6{version}§7, is now available!\n ", /* Update the version name. Remove old patch notes; Optionally add in a short new patch note. */ - "pre_version": "0.0", /* Reset to 0.0 */ - "pre_version_id": 0, /* Reset to 0 */ - "update_link": "https://github.com/NotEnoughUpdates/NotEnoughUpdates/releases/tag/", /* Change download link to the GitHub release */ - "update_direct": "https://github.com/NotEnoughUpdates/NotEnoughUpdates/releases/download//NotEnoughUpdates-.jar", /* Change direct link to a direct download link */ -} -``` +To prepare a release, first merge all the PRs that you want, and then tag that resulting merge commit using `git tag `. +Do *not* use a `vX.X.X` prefix, just raw-dog the `X.X.X` version. If you want this to be a pre-release set the patch version +to something `!= 0`. Note that we follow normal semver rules here, so `3.1.1 > 3.1.0`. -- Launch the game in an older version with this new repo locally to test the messages look first, then push to the central NEU repo (both `master` and `dangerous`) -- Create an announcement in discord [#neu-download](https://discord.com/channels/516977525906341928/693586404256645231). +GitHub actions will automatically build a JAR and generate a changelog and upload both to a draft release. Now you rally +the troups and get your fellow contributors to sign this JAR. -### Creating a pre-release +### Signing a release -> Pre-releases are intended to be mostly feature complete, mostly bug free releases that either don't have enough changes to justify a new Full Release, or have outstanding PRs that are probably merged soon. +The generated draft release should contain a sha256 hash sum. Copy that hash sum for later. -- Edit `NotEnoughUpdates.java` and change +Make sure you have [generated a key](#generating-a-key). -```java -public static final String VERSION = "2.2.0-REL"; /* The VERSION name should still be the same as the latest previously released FULL release */ -public static final int VERSION_ID = 20200; /* Same as VERSION name */ -public static final int PRE_VERSION_ID = 1; /* Increment the PRE_VERSION_ID */ -``` +Run `./gradlew signRelease`. Paste in the sha256 hash from earlier. It will generate a `.asc` signature for every +`secret/` you have. -- Build a jar from this, either using the CI in GitHub actions, or using `gradle remapJar` directly. - - If building locally, make sure that all your changes are in version control so that the commit hash is set correctly (A non `dirty` jar) -- Create a GitHub release (marked as pre-release) -- Edit the `update.json` in the repository and change - -```json5 -{ - "version": "2.1.0-REL", /* The VERSION name should still be the same as the latest previously released FULL release */ - "version_id": 20100, /* Same as VERSION name */ - "pre_update_msg": "§7§m§l--------------------§5§l[§c§lNEU§5§l]§7§m§l--------------------\n\n§7A new pre-release, v§52.0-PRE{pre_version}§7, is now available!\n ", /* Update the version name. Remove old patch notes; Optionally add in a short new patch note. */ - "pre_version": "0.0", /* Set to a new string (preferably increase the major version every time, except for hotfixes on the prerelease stream) */ - "pre_version_id": 0, /* Set to PRE_VERSION_ID from java */ - "pre_update_link": "https://github.com/NotEnoughUpdates/NotEnoughUpdates/releases/tag/", /* Change download link to the GitHub release */ - "pre_update_direct": "https://github.com/NotEnoughUpdates/NotEnoughUpdates/releases/download//NotEnoughUpdates-.jar", /* Change direct link to a direct download link */ -} -``` +Copy those secrets into the draft release. -- Launch the game in an older version with this new repo locally to test the messages look first, then push to the central NEU repo (both `master` and `dangerous`, as some prerelease people sadly don't know how to change repo branches) -- Create an announcement in discord [#unofficial-prereleases](https://discord.com/channels/516977525906341928/837679819487313971). +### Publishing a release -### Creating a Hotfix +Once all relevant personnel have signed off on the release, the release can be published. It should be automatically +available to all people with an auto updater, and be automatically published on modrinth too. The release needs to be +manually uploaded to discord. -> Hotfixes spring off of a Full Release and intend to fix bugs and security flaws. They can, but ideally shouldn't, contain features from pre-releases and are intended as a drop in replacement of the current full release of NEU. These bug fixes should ideally also be released as a pre-release in tandem with the hotfix. +### Generating a key -- Edit `NotEnoughUpdates.java` and change +If you haven't generated a key yet, and you have been told to get one, this is how. -```java -public static final String VERSION = "2.2.0-REL"; /* The VERSION name should still be the same as the latest previously released FULL release */ -public static final int VERSION_ID = 20200; /* Same as VERSION name */ -public static final int PRE_VERSION_ID = 0; /* The PRE_VERSION_ID should still be 0 (as this is based off a full release) */ -public static final int HOTFIX_VERSION_ID = 1; /* Increment the HOTFIX_VERSION_ID */ -``` +For your first key generation, you will need to use openssl. -- Build a jar from this, either using the CI in GitHub actions, or using `gradle remapJar` directly. - - If building locally, make sure that all your changes are in version control so that the commit hash is set correctly (A non `dirty` jar) -- Create a GitHub release (marked as full release) -- Edit the previous FULL release on GitHub with a link to the new release. -- Edit the `update.json` in the repository and change - -```json5 -{ - "version": "2.1.0-REL", /* This version should still remain the same as the last full release */ - "version_id": 20100, /* Same as version */ - "update_msg": "§7§m§l--------------------§6§l[§c§lNEU§6§l]§7§m§l--------------------\n\n§7A new version, v§6{version}§7, is now available!\n ", /* Update the version name. Don't remove old patch notes; Optionally add in a short new patch note. Indicate that there is a hotfix present */ - "update_link": "https://github.com/NotEnoughUpdates/NotEnoughUpdates/releases/tag/", /* Change download link to the GitHub release */ - "update_direct": "https://github.com/NotEnoughUpdates/NotEnoughUpdates/releases/download//NotEnoughUpdates-.jar", /* Change direct link to a direct download link */ -} +```bash +# Generate an RSA private key +openssl genpkey -out id_rsa.pem -algorithm RSA # This step can be skipped, if you want to re-use an existing *RSA* key. + +# Convert your RSA key to pkcs8, without a password protection +openssl pkcs8 -in id_rsa.pem -outform DER -out myname.der -topk8 -nocrypt + +# Generate a public key from your pkcs8 private key +openssl rsa -pubout -in id_rsa.pem -outform der -out myname.key ``` -- Launch the game in an older version with this new repo locally to test the messages look first, then push to the central NEU repo (both `master` and `dangerous`) -- Create an announcement in discord [#neu-download](https://discord.com/channels/516977525906341928/693586404256645231). +Now you have 3 files: + +- `id_rsa.pem` is your base private key. Store it safely somewhere else (maybe on a USB stick). Never share this one. +- `myname.der` is your secret. Put it in the `secrets/` folder in your NEU repo. Never share this one. +- `myname.key` is your public key. Put it in the `src/main/resources/trusted_team_members` folder. + +Make sure that the names of the `.der` and the `.key` file match. +
diff --git a/build.gradle.kts b/build.gradle.kts index 5ff7c7ce..087212ef 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -18,10 +18,12 @@ */ +import neubs.CustomSignTask import neubs.NEUBuildFlags import neubs.applyPublishingInformation import neubs.setVersionFromEnvironment import org.apache.commons.lang3.SystemUtils +import org.gradle.api.tasks.testing.logging.TestExceptionFormat import java.net.URL plugins { @@ -35,6 +37,7 @@ plugins { kotlin("jvm") version "1.8.21" id("io.gitlab.arturbosch.detekt") version "1.23.0" id("com.google.devtools.ksp") version "1.8.21-1.0.11" + id("net.kyori.blossom") version "2.1.0" } @@ -44,7 +47,7 @@ apply() group = "io.github.moulberry" -setVersionFromEnvironment("2.1.1") +val baseVersion = setVersionFromEnvironment() // Minecraft configuration: loom { @@ -81,17 +84,18 @@ loom { // Dependencies: repositories { - mavenCentral() - mavenLocal() - maven("https://maven.notenoughupdates.org/releases") - maven("https://repo.spongepowered.org/maven/") - maven("https://pkgs.dev.azure.com/djtheredstoner/DevAuth/_packaging/public/maven/v1") - maven("https://jitpack.io") - maven("https://repo.polyfrost.cc/releases") + mavenCentral() + mavenLocal() + maven("https://maven.notenoughupdates.org/releases") + maven("https://repo.spongepowered.org/maven/") + maven("https://pkgs.dev.azure.com/djtheredstoner/DevAuth/_packaging/public/maven/v1") + maven("https://jitpack.io") + maven("https://repo.nea.moe/releases") + maven("https://repo.polyfrost.cc/releases") } val shadowImplementation: Configuration by configurations.creating { - configurations.implementation.get().extendsFrom(this) + configurations.implementation.get().extendsFrom(this) } val shadowOnly: Configuration by configurations.creating { @@ -99,138 +103,144 @@ val shadowOnly: Configuration by configurations.creating { } val shadowApi: Configuration by configurations.creating { - configurations.api.get().extendsFrom(this) + configurations.api.get().extendsFrom(this) } val devEnv: Configuration by configurations.creating { - configurations.runtimeClasspath.get().extendsFrom(this) - isCanBeResolved = false - isCanBeConsumed = false - isVisible = false + configurations.runtimeClasspath.get().extendsFrom(this) + isCanBeResolved = false + isCanBeConsumed = false + isVisible = false } val kotlinDependencies: Configuration by configurations.creating { - configurations.implementation.get().extendsFrom(this) + configurations.implementation.get().extendsFrom(this) } val mixinRTDependencies: Configuration by configurations.creating { - configurations.implementation.get().extendsFrom(this) + configurations.implementation.get().extendsFrom(this) } val oneconfigQuarantineSourceSet: SourceSet = sourceSets.create("oneconfig") { - java { - srcDir(layout.projectDirectory.dir("src/main/oneconfig")) - } + java { + srcDir(layout.projectDirectory.dir("src/main/oneconfig")) + } } configurations { - val main = getByName(sourceSets.main.get().compileClasspathConfigurationName) - "oneconfigImplementation" { - extendsFrom(main) - } + val main = getByName(sourceSets.main.get().compileClasspathConfigurationName) + "oneconfigImplementation" { + extendsFrom(main) + } } dependencies { - minecraft("com.mojang:minecraft:1.8.9") - mappings("de.oceanlabs.mcp:mcp_stable:22-1.8.9") - forge("net.minecraftforge:forge:1.8.9-11.15.1.2318-1.8.9") + minecraft("com.mojang:minecraft:1.8.9") + mappings("de.oceanlabs.mcp:mcp_stable:22-1.8.9") + forge("net.minecraftforge:forge:1.8.9-11.15.1.2318-1.8.9") - if (project.findProperty("neu.buildflags.oneconfig") == "true") { - shadowOnly("cc.polyfrost:oneconfig-wrapper-launchwrapper:1.0.0-beta+") // Should be included in jar - runtimeOnly("cc.polyfrost:oneconfig-wrapper-launchwrapper:1.0.0-beta+") // Should be included in jar - } + if (project.findProperty("neu.buildflags.oneconfig") == "true") { + shadowOnly("cc.polyfrost:oneconfig-wrapper-launchwrapper:1.0.0-beta+") // Should be included in jar + runtimeOnly("cc.polyfrost:oneconfig-wrapper-launchwrapper:1.0.0-beta+") // Should be included in jar + } - "oneconfigCompileOnly"(project(":oneconfigquarantine", configuration = "namedElements")) - "oneconfigImplementation"(sourceSets.main.get().output) - "runtimeOnly"(oneconfigQuarantineSourceSet.output) + "oneconfigCompileOnly"(project(":oneconfigquarantine", configuration = "namedElements")) + "oneconfigImplementation"(sourceSets.main.get().output) + "runtimeOnly"(oneconfigQuarantineSourceSet.output) - // Please keep this version in sync with KotlinLoadingTweaker - implementation(enforcedPlatform("org.jetbrains.kotlin:kotlin-bom:1.8.0")) - kotlinDependencies(kotlin("stdlib")) - kotlinDependencies(kotlin("reflect")) + // Please keep this version in sync with KotlinLoadingTweaker + implementation(enforcedPlatform("org.jetbrains.kotlin:kotlin-bom:1.8.0")) + kotlinDependencies(kotlin("stdlib")) + kotlinDependencies(kotlin("reflect")) - ksp("dev.zacsweers.autoservice:auto-service-ksp:1.0.0") - implementation("com.google.auto.service:auto-service-annotations:1.0.1") + ksp("dev.zacsweers.autoservice:auto-service-ksp:1.0.0") + implementation("com.google.auto.service:auto-service-annotations:1.0.1") - compileOnly(ksp(project(":annotations"))!!) - compileOnly("org.projectlombok:lombok:1.18.24") - annotationProcessor("org.projectlombok:lombok:1.18.24") - "oneconfigAnnotationProcessor"("org.projectlombok:lombok:1.18.24") + compileOnly(ksp(project(":annotations"))!!) + compileOnly("org.projectlombok:lombok:1.18.24") + annotationProcessor("org.projectlombok:lombok:1.18.24") + "oneconfigAnnotationProcessor"("org.projectlombok:lombok:1.18.24") - shadowImplementation("com.mojang:brigadier:1.0.18") + shadowImplementation("com.mojang:brigadier:1.0.18") + shadowImplementation("moe.nea:libautoupdate:1.2.0") - mixinRTDependencies("org.spongepowered:mixin:0.7.11-SNAPSHOT") { - isTransitive = false // Dependencies of mixin are already bundled by minecraft - } - annotationProcessor("net.fabricmc:sponge-mixin:0.11.4+mixin.0.8.5") - compileOnly("org.jetbrains:annotations:24.0.1") - - modImplementation(libs.moulconfig) - shadowOnly(libs.moulconfig) - - @Suppress("VulnerableLibrariesLocal") - shadowApi("info.bliki.wiki:bliki-core:3.1.0") - testImplementation("org.junit.jupiter:junit-jupiter:5.9.2") - testAnnotationProcessor("net.fabricmc:sponge-mixin:0.11.4+mixin.0.8.5") - detektPlugins("org.notenoughupdates:detektrules:1.0.0") - devEnv("me.djtheredstoner:DevAuth-forge-legacy:1.1.0") + mixinRTDependencies("org.spongepowered:mixin:0.7.11-SNAPSHOT") { + isTransitive = false // Dependencies of mixin are already bundled by minecraft + } + annotationProcessor("net.fabricmc:sponge-mixin:0.11.4+mixin.0.8.5") + compileOnly("org.jetbrains:annotations:24.0.1") + + modImplementation(libs.moulconfig) + shadowOnly(libs.moulconfig) + + @Suppress("VulnerableLibrariesLocal") + shadowApi("info.bliki.wiki:bliki-core:3.1.0") + testImplementation("org.junit.jupiter:junit-jupiter:5.9.2") + testAnnotationProcessor("net.fabricmc:sponge-mixin:0.11.4+mixin.0.8.5") + detektPlugins("org.notenoughupdates:detektrules:1.0.0") + devEnv("me.djtheredstoner:DevAuth-forge-legacy:1.1.0") } java { - withSourcesJar() - toolchain.languageVersion.set(JavaLanguageVersion.of(8)) + withSourcesJar() + toolchain.languageVersion.set(JavaLanguageVersion.of(8)) } // Tasks: tasks.withType(JavaCompile::class) { - options.encoding = "UTF-8" - options.isFork = true + options.encoding = "UTF-8" + options.isFork = true } tasks.named("compileOneconfigJava", JavaCompile::class) { - doFirst { - println("oneconfig args: ${this@named.options.compilerArgs}") - } + doFirst { + println("oneconfig args: ${this@named.options.compilerArgs}") + } } tasks.named("test") { - useJUnitPlatform() - systemProperty("junit.jupiter.extensions.autodetection.enabled", "true") - this.javaLauncher.set(javaToolchains.launcherFor(java.toolchain)) + useJUnitPlatform() + systemProperty("junit.jupiter.extensions.autodetection.enabled", "true") + this.javaLauncher.set(javaToolchains.launcherFor(java.toolchain)) + testLogging { + exceptionFormat = TestExceptionFormat.FULL + } } +val badJars = layout.buildDirectory.dir("badjars") tasks.named("jar", Jar::class) { - from(oneconfigQuarantineSourceSet.output) + from(oneconfigQuarantineSourceSet.output) + archiveClassifier.set("named") + destinationDirectory.set(badJars) } tasks.withType(Jar::class) { - archiveBaseName.set("NotEnoughUpdates") - manifest.attributes.run { - this["Main-Class"] = "NotSkyblockAddonsInstallerFrame" - this["TweakClass"] = "io.github.moulberry.notenoughupdates.loader.NEUDelegatingTweaker" - this["MixinConfigs"] = "mixins.notenoughupdates.json" - this["FMLCorePluginContainsFMLMod"] = "true" - this["ForceLoadAsMod"] = "true" - this["Manifest-Version"] = "1.0" - this["FMLAT"] = "accesstransformer.cfg" - } + archiveBaseName.set("NotEnoughUpdates") + manifest.attributes.run { + this["Main-Class"] = "NotSkyblockAddonsInstallerFrame" + this["TweakClass"] = "io.github.moulberry.notenoughupdates.loader.NEUDelegatingTweaker" + this["MixinConfigs"] = "mixins.notenoughupdates.json" + this["FMLCorePluginContainsFMLMod"] = "true" + this["ForceLoadAsMod"] = "true" + this["Manifest-Version"] = "1.0" + } } val remapJar by tasks.named("remapJar") { - archiveClassifier.set("dep") - from(tasks.shadowJar) - input.set(tasks.shadowJar.get().archiveFile) - doLast { - println("Jar name: ${archiveFile.get().asFile}") - } + archiveClassifier.set("") + from(tasks.shadowJar) + input.set(tasks.shadowJar.get().archiveFile) + doLast { + println("Jar name: ${archiveFile.get().asFile}") + } } tasks.remapSourcesJar { - this.enabled = false + this.enabled = false } /* Bypassing https://github.com/johnrengelman/shadow/issues/111 */ @@ -266,6 +276,7 @@ tasks.register("includeBackupRepo") { tasks.shadowJar { archiveClassifier.set("dep-dev") configurations = listOf(shadowImplementation, shadowApi, shadowOnly) + destinationDirectory.set(badJars) archiveBaseName.set("NotEnoughUpdates") exclude("**/module-info.class", "LICENSE.txt") dependencies { @@ -282,6 +293,7 @@ tasks.shadowJar { fun relocate(name: String) = relocate(name, "io.github.moulberry.notenoughupdates.deps.$name") relocate("com.mojang.brigadier") relocate("io.github.moulberry.moulconfig") + relocate("moe.nea.libautoupdate") mergeServiceFiles() } @@ -321,11 +333,18 @@ idea { } sourceSets.main { - output.setResourcesDir(file("$buildDir/classes/java/main")) + output.setResourcesDir(file("$buildDir/classes/java/main")) + this.blossom { + this.javaSources { + this.property("neuVersion", baseVersion) + } + } } +tasks.register("signRelease", CustomSignTask::class) + applyPublishingInformation( - "deobf" to tasks.jar, - "all" to tasks.remapJar, - "sources" to tasks["sourcesJar"], + "deobf" to tasks.jar, + "all" to tasks.remapJar, + "sources" to tasks["sourcesJar"], ) diff --git a/buildSrc/generate-public-key.sh b/buildSrc/generate-public-key.sh index 3f778c53..d02fde94 100755 --- a/buildSrc/generate-public-key.sh +++ b/buildSrc/generate-public-key.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # # Copyright (C) 2022 NotEnoughUpdates contributors # @@ -19,7 +19,7 @@ # -output="$(dirname $(dirname $(readlink -f "$0")))/src/main/resources/moulberry.key" +output="$(dirname $(dirname $(readlink -f "$0")))/src/main/resources/trusted_team_members/$(basename "$2").key" echo processing rsa input key from $1, and outputting to $output diff --git a/buildSrc/moulsign.sh b/buildSrc/moulsign.sh index dacb8ec3..b5980353 100755 --- a/buildSrc/moulsign.sh +++ b/buildSrc/moulsign.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # # Copyright (C) 2022 NotEnoughUpdates contributors # diff --git a/buildSrc/moulsign.sh.asc b/buildSrc/moulsign.sh.asc new file mode 100644 index 00000000..0c9538b8 --- /dev/null +++ b/buildSrc/moulsign.sh.asc @@ -0,0 +1,3 @@ +QJ'D½ =eCGs7kz =qC[ +n+#7tu.X)ΕUJQZuj iGzgR(.F{AO̢cvLMPSKCqVٻN^8ɴ!#79cl*=jF ҥ)`y#(r4 +SDǚ11kc0s ah[UzW:@o0arkỶ9Pmdаr%mg>5T|@)C14٬|x [ \ No newline at end of file diff --git a/buildSrc/signhash.sh b/buildSrc/signhash.sh new file mode 100755 index 00000000..48172852 --- /dev/null +++ b/buildSrc/signhash.sh @@ -0,0 +1,34 @@ +#!/usr/bin/env bash +# +# Copyright (C) 2024 NotEnoughUpdates contributors +# +# This file is part of NotEnoughUpdates. +# +# NotEnoughUpdates is free software: you can redistribute it +# and/or modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation, either +# version 3 of the License, or (at your option) any later version. +# +# NotEnoughUpdates is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with NotEnoughUpdates. If not, see . +# + +if [[ $# -ne 3 ]]; then + echo "Usage: " + exit 1 +fi + +echo use key $1, label $2, signing hash $3 +work=$(mktemp) +echo $work +echo "$3" | tr '[:lower:]' '[:upper:]' |tr -d '\n ' > "$work" +openssl dgst -sign "$1" "$work" > "_$2.asc" +echo signature saved to "_$2.asc" + + + diff --git a/buildSrc/src/main/kotlin/neubs/customSign.kt b/buildSrc/src/main/kotlin/neubs/customSign.kt new file mode 100644 index 00000000..8140d71b --- /dev/null +++ b/buildSrc/src/main/kotlin/neubs/customSign.kt @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2024 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates is free software: you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * NotEnoughUpdates is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with NotEnoughUpdates. If not, see . + */ + +package neubs + +import org.gradle.api.DefaultTask +import org.gradle.api.tasks.TaskAction +import java.security.KeyFactory +import java.security.Signature +import java.security.spec.PKCS8EncodedKeySpec + +abstract class CustomSignTask : DefaultTask() { + + @TaskAction + fun run() { + println("Hash to sign: ") + val hash = readLine()!!.trim().toUpperCase() + require(hash.matches("[A-F0-9]{64}".toRegex())) { "Please provide a valid sha256 hash" } + val secrets = project.file("secrets").listFiles()?.toList() + ?.filter { !it.name.startsWith(".") } ?: emptyList() + + if (secrets.isEmpty()) error("Could not find any secret files.") + secrets.forEach { require(it.name.endsWith(".der")) { "Invalid secret file ${it.name}" } } + project.file("build/signatures").mkdirs() + for (secret in secrets) { + val keySpec = PKCS8EncodedKeySpec(secret.readBytes()) + val signature = Signature.getInstance("SHA256withRSA") + signature.initSign(KeyFactory.getInstance("RSA").generatePrivate(keySpec)) + signature.update(hash.encodeToByteArray()) + val file = project.file("build/signatures/_${secret.nameWithoutExtension}.asc") + file.writeBytes(signature.sign()) + println("Generated signature at ${file.absolutePath}") + } + } + + init { + outputs.upToDateWhen { false } + } +} diff --git a/buildSrc/src/main/kotlin/neubs/versioning.kt b/buildSrc/src/main/kotlin/neubs/versioning.kt index 9294e164..24e6cc05 100644 --- a/buildSrc/src/main/kotlin/neubs/versioning.kt +++ b/buildSrc/src/main/kotlin/neubs/versioning.kt @@ -22,15 +22,24 @@ package neubs import org.gradle.api.Project import java.io.ByteArrayOutputStream -fun Project.setVersionFromEnvironment(baseVersion: String) { +fun Project.setVersionFromEnvironment(): String { + val baseVersion = run { + val baos = ByteArrayOutputStream() + exec { + commandLine("git", "describe", "--tags", "--abbrev=0") + standardOutput = baos + isIgnoreExitValue = true + } + (baos.toByteArray()).decodeToString().trim() + } val buildExtra = mutableListOf() val buildVersion = properties["BUILD_VERSION"] as? String if (buildVersion != null) buildExtra.add(buildVersion) - if (System.getenv("CI") == "true") buildExtra.add("ci") + if (System.getenv("CI") == "true" && System.getenv("NEU_RELEASE") != "true") buildExtra.add("ci") val stdout = ByteArrayOutputStream() val execResult = exec { - commandLine("git", "describe", "--always", "--first-parent", "--abbrev=7") + commandLine("git", "rev-parse", "--short", "HEAD") standardOutput = stdout isIgnoreExitValue = true } @@ -49,6 +58,6 @@ fun Project.setVersionFromEnvironment(baseVersion: String) { } version = baseVersion + (if (buildExtra.isEmpty()) "" else buildExtra.joinToString(prefix = "+", separator = ".")) - + return baseVersion } diff --git a/src/main/java-templates/io/github/moulberry/notenoughupdates/VersionConst.java b/src/main/java-templates/io/github/moulberry/notenoughupdates/VersionConst.java new file mode 100644 index 00000000..65638aff --- /dev/null +++ b/src/main/java-templates/io/github/moulberry/notenoughupdates/VersionConst.java @@ -0,0 +1,24 @@ +/* + * Copyright (C) 2024 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates is free software: you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * NotEnoughUpdates is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with NotEnoughUpdates. If not, see . + */ + +package io.github.moulberry.notenoughupdates; + +public class VersionConst { + public static final String VERSION = "{{ neuVersion }}"; +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java b/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java index 21a92faa..b129e644 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java @@ -23,6 +23,7 @@ import com.google.common.collect.Sets; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.JsonObject; +import io.github.moulberry.moulconfig.observer.PropertyTypeAdapterFactory; import io.github.moulberry.notenoughupdates.autosubscribe.AutoLoad; import io.github.moulberry.notenoughupdates.autosubscribe.NEUAutoSubscribe; import io.github.moulberry.notenoughupdates.core.BackgroundBlur; @@ -46,7 +47,6 @@ import io.github.moulberry.notenoughupdates.miscfeatures.StorageManager; import io.github.moulberry.notenoughupdates.miscfeatures.customblockzones.CustomBlockSounds; import io.github.moulberry.notenoughupdates.miscfeatures.inventory.MuseumCheapestItemOverlay; import io.github.moulberry.notenoughupdates.miscfeatures.inventory.MuseumItemHighlighter; -import io.github.moulberry.notenoughupdates.miscfeatures.updater.AutoUpdater; import io.github.moulberry.notenoughupdates.mixins.AccessorMinecraft; import io.github.moulberry.notenoughupdates.oneconfig.IOneConfigCompat; import io.github.moulberry.notenoughupdates.options.NEUConfig; @@ -88,6 +88,8 @@ import java.awt.*; import java.io.File; import java.util.HashMap; import java.util.Set; +import java.util.regex.Matcher; +import java.util.regex.Pattern; @NEUAutoSubscribe @Mod( @@ -95,10 +97,29 @@ import java.util.Set; guiFactory = "io.github.moulberry.notenoughupdates.core.config.MoulConfigGuiForgeInterop") public class NotEnoughUpdates { public static final String MODID = "notenoughupdates"; - public static final String VERSION = "2.1.1-PRE"; - public static final int VERSION_ID = 20106; //2.1.1 only so update notif works - public static final int PRE_VERSION_ID = 0; - public static final int HOTFIX_VERSION_ID = 0; + public static final String VERSION = VersionConst.VERSION; + private static final Pattern versionPattern = Pattern.compile("([0-9]+)\\.([0-9]+)\\.([0-9]+)"); + public static final int VERSION_ID = parseVersion(VERSION); + + private static int parseVersion(String versionName) { + Matcher matcher = versionPattern.matcher(versionName); + if (!matcher.matches()) { + return 0; + } + int major = Integer.parseInt(matcher.group(1)); + if (major < 0 || major > 99) { + return 0; + } + int minor = Integer.parseInt(matcher.group(2)); + if (minor < 0 || minor > 99) { + return 0; + } + int patch = Integer.parseInt(matcher.group(3)); + if (patch < 0 || patch > 99) { + return 0; + } + return major * 10000 + minor * 100 + patch; + } public static final Logger LOGGER = LogManager.getLogger("NotEnoughUpdates"); /** @@ -152,6 +173,7 @@ public class NotEnoughUpdates { }}; public static ProfileViewer profileViewer; private final Gson gson = new GsonBuilder().setPrettyPrinting().excludeFieldsWithoutExposeAnnotation() + .registerTypeAdapterFactory(new PropertyTypeAdapterFactory()) .registerTypeAdapterFactory(KotlinTypeAdapterFactory.INSTANCE).create(); public NEUManager manager; public NEUOverlay overlay; @@ -161,7 +183,6 @@ public class NotEnoughUpdates { public long lastOpenedGui = 0; public boolean packDevEnabled = false; public Color[][] colourMap = null; - public AutoUpdater autoUpdater = new AutoUpdater(this); private File configFile; private long lastChatMessage = 0; private long secondLastChatMessage = 0; diff --git a/src/main/java/io/github/moulberry/notenoughupdates/listener/NEUEventListener.java b/src/main/java/io/github/moulberry/notenoughupdates/listener/NEUEventListener.java index 15f1a954..7cb39a96 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/listener/NEUEventListener.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/listener/NEUEventListener.java @@ -215,10 +215,6 @@ public class NEUEventListener { if (!joinedSB) { joinedSB = true; - if (NotEnoughUpdates.INSTANCE.config.notifications.updateChannel != 0) { - NotEnoughUpdates.INSTANCE.autoUpdater.displayUpdateMessageIfOutOfDate(); - } - if (NotEnoughUpdates.INSTANCE.config.notifications.doRamNotif) { long maxMemoryMB = Runtime.getRuntime().maxMemory() / 1024L / 1024L; if (maxMemoryMB > 4100) { diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/updater/AutoUpdater.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/updater/AutoUpdater.java deleted file mode 100644 index ac77d276..00000000 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/updater/AutoUpdater.java +++ /dev/null @@ -1,256 +0,0 @@ -/* - * Copyright (C) 2022 NotEnoughUpdates contributors - * - * This file is part of NotEnoughUpdates. - * - * NotEnoughUpdates is free software: you can redistribute it - * and/or modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation, either - * version 3 of the License, or (at your option) any later version. - * - * NotEnoughUpdates is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with NotEnoughUpdates. If not, see . - */ - -package io.github.moulberry.notenoughupdates.miscfeatures.updater; - -import com.google.common.collect.Iterables; -import com.google.gson.JsonArray; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonPrimitive; -import com.google.gson.JsonSyntaxException; -import io.github.moulberry.notenoughupdates.NotEnoughUpdates; -import io.github.moulberry.notenoughupdates.util.MoulSigner; -import io.github.moulberry.notenoughupdates.util.NotificationHandler; -import io.github.moulberry.notenoughupdates.util.Utils; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.FontRenderer; -import net.minecraft.event.ClickEvent; -import net.minecraft.event.HoverEvent; -import net.minecraft.util.ChatComponentText; -import net.minecraft.util.ChatStyle; -import net.minecraft.util.EnumChatFormatting; -import net.minecraft.util.IChatComponent; -import net.minecraftforge.fml.common.Loader; -import org.apache.commons.lang3.SystemUtils; - -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.net.MalformedURLException; -import java.net.URL; -import java.util.Arrays; -import java.util.zip.ZipEntry; -import java.util.zip.ZipFile; - -public class AutoUpdater { - - NotEnoughUpdates neu; - - public AutoUpdater(NotEnoughUpdates neu) { - this.neu = neu; - } - - public void logProgress(String str) { - logProgress(new ChatComponentText(str)); - } - - public void logProgress(IChatComponent chatComponent) { - Minecraft.getMinecraft().addScheduledTask(() -> { - IChatComponent chatComponent1 = new ChatComponentText(""); - chatComponent1.setChatStyle(new ChatStyle().setColor(EnumChatFormatting.AQUA)); - chatComponent1.appendSibling(chatComponent); - Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText("§e[NEU-AutoUpdater] ").appendSibling( - chatComponent1)); - }); - } - - public UpdateLoader getUpdateLoader(URL url) { - if (SystemUtils.IS_OS_UNIX) { - return new LinuxBasedUpdater(this, url); - } - if (Loader.isModLoaded("skyblockclientupdater") && SCUCompatUpdater.IS_ENABLED) { - return SCUCompatUpdater.tryCreate(this, url); - } - return null; - } - - UpdateLoader updateLoader; - - public void updateFromURL(URL url) { - if (updateLoader != null) { - logProgress( - "There is already an update in progress, so the auto updater cannot process this update (as it might already be installed or is currently being downloaded). Please restart your client to install another update"); - return; - } - if (!"https".equals(url.getProtocol())) { - logProgress("§cInvalid protocol in url: " + url + ". Only https is a valid protocol."); - return; - } - updateLoader = getUpdateLoader(url); - if (updateLoader == null) { - return; - } - updateLoader.greet(); - logProgress(new ChatComponentText("[Start download now]") - .setChatStyle(new ChatStyle() - .setColor(EnumChatFormatting.GREEN) - .setChatHoverEvent(new HoverEvent( - HoverEvent.Action.SHOW_TEXT, - new ChatComponentText("Click to start download.") - )) - .setChatClickEvent(new ClickEvent( - ClickEvent.Action.RUN_COMMAND, - "/neuupdate scheduleDownload" - )))); - } - - public void scheduleDownload() { - if (updateLoader == null) { - logProgress("§cNo update found. Try running /neuupdate check first"); - return; - } - if (updateLoader.getState() != UpdateLoader.State.NOTHING) { - logProgress("§cUpdate download already started. No need to start the download again."); - return; - } - logProgress("Download started."); - updateLoader.scheduleDownload(); - } - - private void displayUpdateMessage( - JsonObject updateJson, - String updateMessage, - String downloadLink, - String directDownload - ) { - int firstWidth = -1; - - for (String line : Iterables.concat(Arrays.asList(updateMessage.split("\n")), Arrays.asList("Download here"))) { - FontRenderer fr = Minecraft.getMinecraft().fontRendererObj; - boolean isDownloadLink = line.equals("Download here"); - int width = fr.getStringWidth(line); - if (firstWidth == -1) { - firstWidth = width; - } - int missingLen = firstWidth - width; - if (missingLen > 0) { - StringBuilder sb = new StringBuilder(missingLen / 4 / 2 + line.length()); - for (int i = 0; i < missingLen / 4 / 2; i++) { /* fr.getCharWidth(' ') == 4 */ - sb.append(" "); - } - sb.append(line); - line = sb.toString(); - } - ChatComponentText cp = new ChatComponentText(line); - if (isDownloadLink) - cp.setChatStyle(Utils.createClickStyle(ClickEvent.Action.OPEN_URL, downloadLink)); - Minecraft.getMinecraft().thePlayer.addChatMessage(cp); - } - neu.displayLinks(updateJson, firstWidth); - NotificationHandler.displayNotification(Arrays.asList( - "", - "§eThere is a new version of NotEnoughUpdates available.", - "§eCheck the chat for more information" - ), false); - try { - if (directDownload != null) - updateFromURL(new URL(directDownload)); - } catch (MalformedURLException e) { - e.printStackTrace(); - } - } - - public void displayUpdateMessageIfOutOfDate() { - File repo = neu.manager.repoLocation; - File updateJson = new File(repo, "update.json"); - if (updateJson.exists()) { - if (!MoulSigner.verifySignature(updateJson)) { - NotEnoughUpdates.LOGGER.error("update.json found without signature"); - Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText( - "§e[NEU] §cThere has been an error checking for updates. Check the log or join the discord for more information.").setChatStyle( - Utils.createClickStyle( - ClickEvent.Action.OPEN_URL, "https://discord.gg/moulberry"))); - return; - } - try { - JsonObject o = neu.manager.getJsonFromFile(updateJson); - - int fullReleaseVersion = - o.has("version_id") && o.get("version_id").isJsonPrimitive() ? o.get("version_id").getAsInt() : -1; - int preReleaseVersion = - o.has("pre_version_id") && o.get("pre_version_id").isJsonPrimitive() ? o.get("pre_version_id").getAsInt() : -1; - int hotfixVersion = - o.has("hotfix_id") && o.get("hotfix_id").isJsonPrimitive() ? o.get("hotfix_id").getAsInt() : -1; - - boolean hasFullReleaseAvailableForUpgrade = fullReleaseVersion > NotEnoughUpdates.VERSION_ID; - boolean hasHotfixAvailableForUpgrade = - fullReleaseVersion == NotEnoughUpdates.VERSION_ID && hotfixVersion > NotEnoughUpdates.HOTFIX_VERSION_ID; - boolean hasPreReleaseAvailableForUpdate = - fullReleaseVersion == NotEnoughUpdates.VERSION_ID && preReleaseVersion > NotEnoughUpdates.PRE_VERSION_ID; - - int updateChannel = NotEnoughUpdates.INSTANCE.config.notifications.updateChannel; /* 1 = Full, 2 = Pre */ - if (hasFullReleaseAvailableForUpgrade || (hasHotfixAvailableForUpgrade && updateChannel == 1)) { - displayUpdateMessage( - o, - o.get("update_msg").getAsString(), - o.get("update_link").getAsString(), - o.has("update_direct") ? o.get("update_direct").getAsString() : null - ); - } else if (hasPreReleaseAvailableForUpdate && updateChannel == 2) { - displayUpdateMessage( - o, - o.get("pre_update_msg").getAsString(), - o.get("pre_update_link").getAsString(), - o.has("pre_update_direct") ? o.get("pre_update_direct").getAsString() : null - ); - } - } catch (Exception e) { - e.printStackTrace(); - Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText( - "§e[NEU] §cThere has been an error checking for updates. Check the log or join the discord for more information.").setChatStyle( - Utils.createClickStyle( - ClickEvent.Action.OPEN_URL, "https://discord.gg/moulberry"))); - } - } - } - - private boolean validateMcModInfo(JsonArray array) { - if (array.size() != 1) return false; - JsonElement jsonElement = array.get(0); - if (!jsonElement.isJsonObject()) return false; - JsonObject jsonObject = jsonElement.getAsJsonObject(); - if (!jsonObject.has("modid")) return false; - JsonElement modid = jsonObject.get("modid"); - if (!modid.isJsonPrimitive()) return false; - JsonPrimitive primitive = modid.getAsJsonPrimitive(); - if (!primitive.isString()) return false; - return "notenoughupdates".equals(primitive.getAsString()); - } - - public boolean isNeuJar(File sus) { - try (ZipFile zipFile = new ZipFile(sus)) { - ZipEntry entry = zipFile.getEntry("mcmod.info"); - if (entry == null) { - return false; - } - try (InputStream inputStream = zipFile.getInputStream(entry)) { - JsonArray jsonArray = neu.manager.gson.fromJson( - new InputStreamReader(inputStream), - JsonArray.class - ); - return validateMcModInfo(jsonArray); - } - } catch (IOException | JsonSyntaxException e) { - e.printStackTrace(); - } - return false; - } -} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/updater/LinuxBasedUpdater.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/updater/LinuxBasedUpdater.java deleted file mode 100644 index 3118b135..00000000 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/updater/LinuxBasedUpdater.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (C) 2022 NotEnoughUpdates contributors - * - * This file is part of NotEnoughUpdates. - * - * NotEnoughUpdates is free software: you can redistribute it - * and/or modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation, either - * version 3 of the License, or (at your option) any later version. - * - * NotEnoughUpdates is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with NotEnoughUpdates. If not, see . - */ - -package io.github.moulberry.notenoughupdates.miscfeatures.updater; - -import java.io.File; -import java.net.URL; -import java.util.List; - -class LinuxBasedUpdater /* Based on what? */ extends UpdateLoader { - - LinuxBasedUpdater(AutoUpdater updater, URL url) { - super(updater, url); - } - - @Override - public void greet() { - updater.logProgress( - "Welcome Aristocrat! Your superior linux system configuration is supported for NEU auto updates."); - } - - @Override - public void deleteFiles(List toDelete) { - for (File toDel : toDelete) { - if (!toDel.delete()) { - updater.logProgress("§cCould not delete old version of NEU: " + toDel + ". Please manually delete file."); - state = State.FAILED; - } - } - } -} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/updater/SCUCompatUpdater.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/updater/SCUCompatUpdater.java deleted file mode 100644 index 3cb600cb..00000000 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/updater/SCUCompatUpdater.java +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Copyright (C) 2022 NotEnoughUpdates contributors - * - * This file is part of NotEnoughUpdates. - * - * NotEnoughUpdates is free software: you can redistribute it - * and/or modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation, either - * version 3 of the License, or (at your option) any later version. - * - * NotEnoughUpdates is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with NotEnoughUpdates. If not, see . - */ - -package io.github.moulberry.notenoughupdates.miscfeatures.updater; - -import java.io.File; -import java.lang.invoke.MethodHandle; -import java.lang.invoke.MethodHandles; -import java.lang.reflect.Field; -import java.lang.reflect.Method; -import java.net.URL; -import java.util.List; - -/* - * Legal considerations: Skyblock Client Updater is licensed under the GNU AGPL v3.0 or later (with modifications). - * https://github.com/My-Name-Is-Jeff/SkyblockClient-Updater/blob/main/LICENSE - * - * However, even tho the AGPL License does not allow conveying covered work in combination with LGPL licensed code - * (such as our own), we do not perceive ourselves as conveying neither an unmodified version of Skyblock Client Updater - * nor a work based on Skyblock Client Updater (modified work) since our work is usable and functional in its entirety - * without presence of Skyblock Client Updater and is not to be distributed along a copy of Skyblock Client Updater - * unless that combined work is licensed with respect of both the LGPL and the AGPL, therefore is not adapting any part - * of Skyblock Client Updater unless already part of a whole distribution. - * - * In case the Copyright owner (Lily aka My-Name-Is-Jeff on Github) disagrees, we are willing to take down this module - * (or only convey this component of our work under a pure GPL license) with or without them providing legal grounds - * for this request. However, due to them not being able to be reached for comment, we will include this - * component for the time being. - * */ -public class SCUCompatUpdater extends UpdateLoader { - - public static final boolean IS_ENABLED = false; - - private SCUCompatUpdater(AutoUpdater updater, URL url) { - super(updater, url); - } - - @Override - public void greet() { - updater.logProgress("Skyblock Client Updater compatibility layer loaded."); - } - - @Override - public void deleteFiles(List toDelete) { - try { - for (File f : toDelete) - ReflectionHolder.deleteFileOnShutdownHandle.invoke(ReflectionHolder.updateCheckerInstance, f, ""); - } catch (Throwable e) { - e.printStackTrace(); - updater.logProgress("Invoking SCU failed. Check the log for more info."); - state = State.FAILED; - } - } - - static class ReflectionHolder { - static boolean isSCUFullyPresent = false; - static Class updateChecker; - static Object updateCheckerInstance; - static Method deleteFileOnShutdown; - static MethodHandle deleteFileOnShutdownHandle; - - static { - try { - updateChecker = Class.forName("mynameisjeff.skyblockclientupdater.utils.UpdateChecker"); - Field instanceField = updateChecker.getDeclaredField("INSTANCE"); - instanceField.setAccessible(true); - updateCheckerInstance = instanceField.get(null); - deleteFileOnShutdown = updateChecker.getDeclaredMethod("deleteFileOnShutdown", File.class, String.class); - deleteFileOnShutdownHandle = MethodHandles.publicLookup().unreflect(deleteFileOnShutdown); - isSCUFullyPresent = true; - } catch (NoSuchFieldException | ClassNotFoundException | IllegalAccessException | NoSuchMethodException e) { - e.printStackTrace(); - } - } - } - - public static UpdateLoader tryCreate(AutoUpdater updater, URL url) { - if (!ReflectionHolder.isSCUFullyPresent) { - updater.logProgress("§cFound Skyclient Updater Mod, however our hooks did not function properly."); - return null; - } - return new SCUCompatUpdater(updater, url); - } -} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/updater/SigningGithubSource.kt b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/updater/SigningGithubSource.kt new file mode 100644 index 00000000..b8c804ff --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/updater/SigningGithubSource.kt @@ -0,0 +1,64 @@ +/* + * Copyright (C) 2024 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates is free software: you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * NotEnoughUpdates is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with NotEnoughUpdates. If not, see . + */ + +package io.github.moulberry.notenoughupdates.miscfeatures.updater + +import moe.nea.libautoupdate.GithubReleaseUpdateSource +import moe.nea.libautoupdate.UpdateData +import java.io.ByteArrayInputStream +import java.io.File +import java.net.URL + +class SigningGithubSource(username: String, repo: String) : + GithubReleaseUpdateSource(username, repo) { + + val hashRegex = "sha256sum: `(?[a-fA-F0-9]{64})`".toPattern() + override fun findAsset(release: GithubRelease): UpdateData? { + var asset = super.findAsset(release) ?: return null + val match = release.body.lines() + .firstNotNullOfOrNull { line -> hashRegex.matcher(line).takeIf { it.matches() } } + ?: return null + // Inject our custom sha256sum + asset = UpdateData(asset.versionName, asset.versionNumber, match.group("hash"), asset.download) + // Verify at least 2 signatures are present on this release + if (!verifyAnySignature(release, asset)) + return null + return asset + } + + private fun verifyAnySignature(release: GithubRelease, asset: UpdateData): Boolean { + val signatories = findValidSignatories(release, asset) + for (signatory in signatories) { + println("Accepted signature from ${signatory.name}") + } + return signatories.size >= 2 + } + + fun findValidSignatories(release: GithubRelease, asset: UpdateData): List { + val signatures = release.assets?.filter { it.name.endsWith(".asc") } ?: emptyList() + return signatures.filter { verifySignature(it, asset) } + } + + fun verifySignature(signatureDownload: GithubRelease.Download, asset: UpdateData): Boolean { + val name = signatureDownload.name.substringBeforeLast('.').removePrefix("_") + val signatureBytes = URL(signatureDownload.browserDownloadUrl).openStream().readBytes() + val hashBytes = ByteArrayInputStream(asset.sha256.uppercase().encodeToByteArray()) + return SigningPool.verifySignature(name, hashBytes, signatureBytes) + } +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/updater/SigningPool.kt b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/updater/SigningPool.kt new file mode 100644 index 00000000..c75806c0 --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/updater/SigningPool.kt @@ -0,0 +1,68 @@ +/* + * Copyright (C) 2024 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates is free software: you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * NotEnoughUpdates is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with NotEnoughUpdates. If not, see . + */ + +package io.github.moulberry.notenoughupdates.miscfeatures.updater + +import io.github.moulberry.notenoughupdates.util.JarUtil +import java.io.InputStream +import java.security.KeyFactory +import java.security.PublicKey +import java.security.Signature +import java.security.spec.X509EncodedKeySpec + + +object SigningPool { + + data class PK( + val name: String, + val publicKey: PublicKey, + ) + + fun load(): List { + val l = JarUtil.access.listFiles("trusted_team_members") + return l.filter { it.endsWith(".key") } + .map { + loadPK( + it.substringBeforeLast('.'), + JarUtil.access.read("trusted_team_members/$it") + ) + } + } + + fun loadPK(name: String, inputStream: InputStream): PK { + val publicKeyBytes = inputStream.readBytes() + val x509EncodedKeySpec = X509EncodedKeySpec(publicKeyBytes) + return PK(name, KeyFactory.getInstance("RSA").generatePublic(x509EncodedKeySpec)) + } + + val keyPool = load().associateBy { it.name } + + fun verifySignature(name: String, inputStream: InputStream, signatureBytes: ByteArray): Boolean { + val signature = Signature.getInstance("SHA256withRSA") + signature.initVerify(keyPool[name]?.publicKey ?: return false) + + val b = ByteArray(4096) + while (true) { + val read = inputStream.read(b) + if (read < 0) break + signature.update(b, 0, read) + } + return signature.verify(signatureBytes) + } +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/updater/UpdateLoader.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/updater/UpdateLoader.java deleted file mode 100644 index 1a1a8504..00000000 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/updater/UpdateLoader.java +++ /dev/null @@ -1,141 +0,0 @@ -/* - * Copyright (C) 2022 NotEnoughUpdates contributors - * - * This file is part of NotEnoughUpdates. - * - * NotEnoughUpdates is free software: you can redistribute it - * and/or modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation, either - * version 3 of the License, or (at your option) any later version. - * - * NotEnoughUpdates is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with NotEnoughUpdates. If not, see . - */ - -package io.github.moulberry.notenoughupdates.miscfeatures.updater; - -import io.github.moulberry.notenoughupdates.util.NetUtils; -import net.minecraft.client.Minecraft; -import org.apache.commons.io.IOUtils; - -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.net.URL; -import java.nio.file.Files; -import java.util.ArrayList; -import java.util.List; - -abstract class UpdateLoader { - - enum State { - NOTHING, DOWNLOAD_STARTED, DOWNLOAD_FINISHED, INSTALLED, FAILED - } - - URL url; - AutoUpdater updater; - - State state = State.NOTHING; - - UpdateLoader(AutoUpdater updater, URL url) { - this.url = url; - this.updater = updater; - } - - public State getState() { - return state; - } - - public void setState(State state) { - this.state = state; - } - - public URL getUrl() { - return url; - } - - public void scheduleDownload() { - state = State.DOWNLOAD_STARTED; - try { - NetUtils.downloadAsync(url, File.createTempFile("NotEnoughUpdates-update", ".jar")) - .handle( - (f, exc) -> { - if (exc != null) { - state = State.FAILED; - updater.logProgress("§cError while downloading. Check your logs for more info."); - exc.printStackTrace(); - return null; - } - state = State.DOWNLOAD_FINISHED; - - updater.logProgress("Download completed. Trying to install"); - launchUpdate(f); - return null; - }); - } catch (IOException e) { - state = State.FAILED; - updater.logProgress("§cError while creating download. Check your logs for more info."); - e.printStackTrace(); - } - } - - public abstract void greet(); - - public void launchUpdate(File file) { - - if (state != State.DOWNLOAD_FINISHED) { - updater.logProgress("§cUpdate is invalid state " + state + " to start update."); - state = State.FAILED; - return; - } - File mcDataDir = new File(Minecraft.getMinecraft().mcDataDir, "mods"); - if (!mcDataDir.exists() || !mcDataDir.isDirectory() || !mcDataDir.canRead()) { - updater.logProgress("§cCould not find mods folder. Searched: " + mcDataDir); - state = State.FAILED; - return; - } - ArrayList toDelete = new ArrayList<>(); - File[] modFiles = mcDataDir.listFiles(); - if (modFiles == null) { - updater.logProgress("§cCould not list minecraft mod folder (" + mcDataDir + ")"); - state = State.FAILED; - return; - } - for (File sus : modFiles) { - if (sus.getName().endsWith(".jar")) { - if (updater.isNeuJar(sus)) { - updater.logProgress("Found old NEU file: " + sus + ". Deleting later."); - toDelete.add(sus); - } - } - } - File dest = new File(mcDataDir, file.getName()); - try ( - InputStream i = Files.newInputStream(file.toPath()); - OutputStream o = Files.newOutputStream(dest.toPath()); - ) { - IOUtils.copyLarge(i, o); - } catch (IOException e) { - e.printStackTrace(); - updater.logProgress( - "§cFailed to copy release JAR. Not making any changes to your mod folder. Consult your logs for more info."); - state = State.FAILED; - } - deleteFiles(toDelete); - if (state != State.FAILED) { - state = State.INSTALLED; - updater.logProgress("Update successful. Thank you for your time."); - return; - } - updater.logProgress("§cFailure to delete some files. Please delte the old NEU version manually from your mods folder."); - } - - public abstract void deleteFiles(List toDelete); - -} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/options/NEUConfig.java b/src/main/java/io/github/moulberry/notenoughupdates/options/NEUConfig.java index 200b1c0c..41486dae 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/options/NEUConfig.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/options/NEUConfig.java @@ -39,6 +39,7 @@ import io.github.moulberry.notenoughupdates.miscgui.customtodos.CustomTodo; import io.github.moulberry.notenoughupdates.options.customtypes.NEUDebugFlag; import io.github.moulberry.notenoughupdates.options.separatesections.AHGraph; import io.github.moulberry.notenoughupdates.options.separatesections.AHTweaks; +import io.github.moulberry.notenoughupdates.options.separatesections.About; import io.github.moulberry.notenoughupdates.options.separatesections.AccessoryBag; import io.github.moulberry.notenoughupdates.options.separatesections.ApiData; import io.github.moulberry.notenoughupdates.options.separatesections.BazaarTweaks; @@ -246,6 +247,13 @@ public class NEUConfig extends Config { } } + @Expose + @Category( + name = "About", + desc = "" + ) + public About about = new About(); + @Expose @Category( name = "Misc", diff --git a/src/main/java/io/github/moulberry/notenoughupdates/options/customtypes/ConfigVersionDisplay.java b/src/main/java/io/github/moulberry/notenoughupdates/options/customtypes/ConfigVersionDisplay.java new file mode 100644 index 00000000..b86f0b3f --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/options/customtypes/ConfigVersionDisplay.java @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2024 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates is free software: you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * NotEnoughUpdates is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with NotEnoughUpdates. If not, see . + */ + +package io.github.moulberry.notenoughupdates.options.customtypes; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +@Retention(RetentionPolicy.RUNTIME) +public @interface ConfigVersionDisplay { +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/options/separatesections/About.java b/src/main/java/io/github/moulberry/notenoughupdates/options/separatesections/About.java new file mode 100644 index 00000000..fc8c4eb8 --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/options/separatesections/About.java @@ -0,0 +1,111 @@ +/* + * Copyright (C) 2024 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates is free software: you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * NotEnoughUpdates is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with NotEnoughUpdates. If not, see . + */ + +package io.github.moulberry.notenoughupdates.options.separatesections; + +import com.google.gson.annotations.Expose; +import io.github.moulberry.moulconfig.annotations.Accordion; +import io.github.moulberry.moulconfig.annotations.ConfigEditorBoolean; +import io.github.moulberry.moulconfig.annotations.ConfigEditorButton; +import io.github.moulberry.moulconfig.annotations.ConfigEditorDropdown; +import io.github.moulberry.moulconfig.annotations.ConfigOption; +import io.github.moulberry.moulconfig.observer.Property; +import io.github.moulberry.notenoughupdates.options.customtypes.ConfigVersionDisplay; +import io.github.moulberry.notenoughupdates.util.Utils; + +public class About { + @ConfigOption(name = "Current Version", desc = "This is the NEU version you are running currently") + @ConfigVersionDisplay + public transient Void currentVersion = null; + + @ConfigOption(name = "Check for Updates", desc = "Automatically check for updates on each startup") + @Expose + @ConfigEditorBoolean + public boolean autoUpdates = true; + + @ConfigOption(name = "Update Stream", desc = "How often do you want to get updates") + @Expose + @ConfigEditorDropdown + public Property updateStream = Property.of(UpdateStream.FULL); + + @ConfigOption(name = "Used Software", desc = "Information about used software and licenses") + @Accordion + @Expose + public Licenses licenses = new Licenses(); + + public enum UpdateStream { + PRE("Full Releases and Beta", "pre"), FULL("Full Releases", "full"), NONE("None", "none"); + public final String stream; + public final String label; + + UpdateStream(String name, String stream) { + this.label = name; + this.stream = stream; + } + + @Override + public String toString() { + return label; + } + } + + public static class Licenses { + + @ConfigOption(name = "Forge", desc = "Forge is available under the LGPL 3.0 license") + @ConfigEditorButton(buttonText = "Source") + public Runnable forge = () -> Utils.openUrl("https://github.com/MinecraftForge/MinecraftForge"); + + @ConfigOption(name = "Mixin", desc = "Mixin is available under the MIT license") + @ConfigEditorButton(buttonText = "Source") + public Runnable mixin = () -> Utils.openUrl("https://github.com/SpongePowered/Mixin/"); + + @ConfigOption(name = "LibAutoUpdate", desc = "LibAutoUpdate is available under the BSD 2 Clause license") + @ConfigEditorButton(buttonText = "Source") + public Runnable libAutoUpdate = () -> Utils.openUrl("https://git.nea.moe/nea/libautoupdate/"); + + @ConfigOption(name = "Kotlin", desc = "Kotlin is available under the Apache 2 license") + @ConfigEditorButton(buttonText = "Source") + public Runnable kotlin = () -> Utils.openUrl("https://github.com/jetbrains/kotlin/"); + + @ConfigOption(name = "AutoService", desc = "auto-service-ksp is available under the Apache 2 license") + @ConfigEditorButton(buttonText = "Source") + public Runnable autoService = () -> Utils.openUrl("https://github.com/ZacSweers/auto-service-ksp/"); + + @ConfigOption(name = "Brigadier", desc = "Brigadier is available under the MIT license") + @ConfigEditorButton(buttonText = "Source") + public Runnable brigadier = () -> Utils.openUrl("https://github.com/Mojang/brigadier/"); + + @ConfigOption(name = "JB Annotations", desc = "Jetbrains annotations is available under the Apache 2 license") + @ConfigEditorButton(buttonText = "Source") + public Runnable annotations = () -> Utils.openUrl("https://github.com/JetBrains/java-annotations"); + + @ConfigOption(name = "MoulConfig", desc = "MoulConfig is available under the LGPL 3.0 license") + @ConfigEditorButton(buttonText = "Source") + public Runnable moulConfig = () -> Utils.openUrl("https://github.com/NotEnoughUpdates/MoulConfig"); + + @ConfigOption(name = "Bliki", desc = "Bliki Core is available under the Eclipse Public License 1.0 license") + @ConfigEditorButton(buttonText = "Source") + public Runnable blikiCore = () -> Utils.openUrl("https://github.com/AaronZhangL/blikiCore/"); + + @ConfigOption(name = "Lombok", desc = "Lombok is available under the MIT license") + @ConfigEditorButton(buttonText = "Website") + public Runnable lombok = () -> Utils.openUrl("https://projectlombok.org/"); + + } +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/util/JarUtil.kt b/src/main/java/io/github/moulberry/notenoughupdates/util/JarUtil.kt new file mode 100644 index 00000000..d25508ba --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/util/JarUtil.kt @@ -0,0 +1,68 @@ +/* + * Copyright (C) 2024 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates is free software: you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * NotEnoughUpdates is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with NotEnoughUpdates. If not, see . + */ + +package io.github.moulberry.notenoughupdates.util + +import io.github.moulberry.notenoughupdates.NotEnoughUpdates +import java.io.File +import java.io.InputStream +import java.net.URL +import java.util.jar.JarFile +import kotlin.io.path.toPath + +object JarUtil { + + interface Access { + fun listFiles(path: String): List + fun read(path: String): InputStream + } + + val access = NotEnoughUpdates::class.java.protectionDomain.codeSource.location.let { + if (it.protocol.equals("jar")) { + val jarFilePath = URL(it.toString().split("!")[0].substring(4)) + .toURI().toPath().toFile() + val jarFile = JarFile(jarFilePath) + object : Access { + override fun listFiles(path: String): List { + return jarFile.entries().toList().filter { it.name.startsWith(path + "/") } + .filter { it.name.indexOf('/', path.length + 1) < 0 } + .map { it.name.substringAfterLast('/') } + } + + override fun read(path: String): InputStream { + return jarFile.getInputStream(jarFile.getJarEntry(path)) + } + } + } else { + val baseFilePath = it.toString().replace("\\", "/") + .replace(NotEnoughUpdates::class.java.getCanonicalName().replace(".", "/") + ".class", "") + val baseFile = URL(baseFilePath).toURI().toPath().toFile() + object : Access { + override fun listFiles(path: String): List { + return baseFile.resolve(path).listFiles()?.map { it.name } ?: listOf() + } + + override fun read(path: String): InputStream { + return baseFile.resolve(path).inputStream() + } + } + } + } + +} diff --git a/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/dev/DevTestCommand.kt b/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/dev/DevTestCommand.kt index e8c12442..53e62045 100644 --- a/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/dev/DevTestCommand.kt +++ b/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/dev/DevTestCommand.kt @@ -43,6 +43,7 @@ import net.minecraft.util.EnumParticleTypes import net.minecraftforge.common.MinecraftForge import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import java.util.function.Predicate +import kotlin.io.path.absolutePathString import kotlin.math.floor @NEUAutoSubscribe diff --git a/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/help/SettingsCommand.kt b/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/help/SettingsCommand.kt index 40919a8e..0e6fb1ff 100644 --- a/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/help/SettingsCommand.kt +++ b/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/help/SettingsCommand.kt @@ -32,7 +32,9 @@ import io.github.moulberry.notenoughupdates.core.config.GuiOptionEditorBlocked import io.github.moulberry.notenoughupdates.events.RegisterBrigadierCommandEvent import io.github.moulberry.notenoughupdates.miscfeatures.EnforcedConfigValues import io.github.moulberry.notenoughupdates.miscfeatures.IQTest +import io.github.moulberry.notenoughupdates.miscfeatures.updater.ConfigVersionGuiOption import io.github.moulberry.notenoughupdates.options.NEUConfig +import io.github.moulberry.notenoughupdates.options.customtypes.ConfigVersionDisplay import io.github.moulberry.notenoughupdates.util.brigadier.* import net.minecraft.client.gui.GuiScreen import net.minecraftforge.fml.common.eventhandler.SubscribeEvent @@ -122,6 +124,9 @@ object SettingsCommand { fun createConfigElement(search: String): MoulConfigEditor { val processor = BlockingMoulConfigProcessor() BuiltinMoulConfigGuis.addProcessors(processor) + processor.registerConfigEditor(ConfigVersionDisplay::class.java) { option, annotation -> + ConfigVersionGuiOption(option) + } ConfigProcessorDriver.processConfig( NotEnoughUpdates.INSTANCE.config.javaClass, NotEnoughUpdates.INSTANCE.config, diff --git a/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/misc/MiscCommands.kt b/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/misc/MiscCommands.kt index 422871b4..70a72342 100644 --- a/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/misc/MiscCommands.kt +++ b/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/misc/MiscCommands.kt @@ -117,17 +117,6 @@ class MiscCommands { } }.withHelp("Look up someones pronouns using their minecraft username") } - event.command("neuupdate", "neuupdates", "enoughupdates") { - thenLiteralExecute("check") { - NotEnoughUpdates.INSTANCE.autoUpdater.displayUpdateMessageIfOutOfDate() - }.withHelp("Check for updates") - thenLiteralExecute("scheduledownload") { - NotEnoughUpdates.INSTANCE.autoUpdater.scheduleDownload() - }.withHelp("Queue a new version of NEU to be downloaded") - thenLiteralExecute("updatemodes") { - reply("§bTo ensure we do not accidentally corrupt your mod folder, we can only offer support for auto-updates on system with certain capabilities for file deletions (specifically unix systems). You can still manually update your files") - }.withHelp("Display an explanation why you cannot auto update") - } event.command("neudynamiclights", "neudli", "neudynlights", "neudynamicitems") { thenExecute { NotEnoughUpdates.INSTANCE.openGui = DynamicLightItemsEditor() diff --git a/src/main/kotlin/io/github/moulberry/notenoughupdates/miscfeatures/updater/AutoUpdater.kt b/src/main/kotlin/io/github/moulberry/notenoughupdates/miscfeatures/updater/AutoUpdater.kt new file mode 100644 index 00000000..b9ce28b2 --- /dev/null +++ b/src/main/kotlin/io/github/moulberry/notenoughupdates/miscfeatures/updater/AutoUpdater.kt @@ -0,0 +1,156 @@ +/* + * Copyright (C) 2024 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates is free software: you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * NotEnoughUpdates is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with NotEnoughUpdates. If not, see . + */ + +package io.github.moulberry.notenoughupdates.miscfeatures.updater + +import io.github.moulberry.notenoughupdates.NotEnoughUpdates +import io.github.moulberry.notenoughupdates.autosubscribe.NEUAutoSubscribe +import io.github.moulberry.notenoughupdates.events.RegisterBrigadierCommandEvent +import io.github.moulberry.notenoughupdates.util.MinecraftExecutor +import io.github.moulberry.notenoughupdates.util.brigadier.thenExecute +import moe.nea.libautoupdate.CurrentVersion +import moe.nea.libautoupdate.PotentialUpdate +import moe.nea.libautoupdate.UpdateContext +import moe.nea.libautoupdate.UpdateTarget +import net.minecraft.client.Minecraft +import net.minecraft.event.ClickEvent +import net.minecraft.util.ChatComponentText +import net.minecraftforge.common.MinecraftForge +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import net.minecraftforge.fml.common.gameevent.TickEvent +import org.apache.logging.log4j.LogManager +import java.util.concurrent.CompletableFuture + +@NEUAutoSubscribe +object AutoUpdater { + val updateContext = UpdateContext( + SigningGithubSource("NotEnoughUpdates", "NotEnoughUpdates"), + UpdateTarget.deleteAndSaveInTheSameFolder(AutoUpdater::class.java), + CurrentVersion.ofTag(NotEnoughUpdates.VERSION.substringBefore("+")), + "notenoughupdates" + ) + val logger = LogManager.getLogger("NEUUpdater") + private var activePromise: CompletableFuture<*>? = null + set(value) { + field?.cancel(true) + field = value + } + + + var updateState: UpdateState = UpdateState.NONE + private set + + var potentialUpdate: PotentialUpdate? = null + + enum class UpdateState { + AVAILABLE, + QUEUED, + DOWNLOADED, + NONE + } + + fun reset() { + updateState = UpdateState.NONE + activePromise = null + potentialUpdate = null + logger.info("Reset update state") + } + + fun checkUpdate() { + if (updateState != UpdateState.NONE) { + logger.error("Trying to perform update check while another update is already in progress") + return + } + logger.info("Starting update check") + val updateStream = config.updateStream.get() + activePromise = updateContext.checkUpdate(updateStream.stream) + .thenAcceptAsync({ + logger.info("Update check completed") + if (updateState != UpdateState.NONE) { + logger.warn("This appears to be the second update check. Ignoring this one") + return@thenAcceptAsync + } + potentialUpdate = it + if (it.isUpdateAvailable) { + updateState = UpdateState.AVAILABLE + Minecraft.getMinecraft().thePlayer?.addChatMessage(ChatComponentText("§e[NEU] §aNEU found a new update: ${it.update.versionName}. Click here to automatically install this update.").apply { + this.chatStyle = this.chatStyle.setChatClickEvent( + ClickEvent( + ClickEvent.Action.RUN_COMMAND, + "/neuinternalupdatenow" + ) + ) + }) + } + }, MinecraftExecutor.OnThread) + } + + fun queueUpdate() { + if (updateState != UpdateState.AVAILABLE) { + logger.error("Trying to enqueue an update while another one is already downloaded or none is present") + } + updateState = UpdateState.QUEUED + activePromise = CompletableFuture.supplyAsync { + logger.info("Update download started") + potentialUpdate!!.prepareUpdate() + }.thenAcceptAsync({ + logger.info("Update download completed, setting exit hook") + updateState = UpdateState.DOWNLOADED + potentialUpdate!!.executeUpdate() + }, MinecraftExecutor.OnThread) + } + + init { + updateContext.cleanup() + config.updateStream.whenChanged { _, _ -> + reset() + } + } + + fun getCurrentVersion(): String { + return NotEnoughUpdates.VERSION + } + + + val config get() = NotEnoughUpdates.INSTANCE.config.about + + @SubscribeEvent + fun onPlayerAvailableOnce(event: TickEvent.ClientTickEvent) { + val p = Minecraft.getMinecraft().thePlayer ?: return + MinecraftForge.EVENT_BUS.unregister(this) + if (config.autoUpdates) + checkUpdate() + } + + + @SubscribeEvent + fun testCommand(event: RegisterBrigadierCommandEvent) { + event.command("neuinternalupdatenow") { + thenExecute { + queueUpdate() + } + } + } + + fun getNextVersion(): String? { + return potentialUpdate?.update?.versionName + } + + +} diff --git a/src/main/kotlin/io/github/moulberry/notenoughupdates/miscfeatures/updater/ConfigVersionGuiOption.kt b/src/main/kotlin/io/github/moulberry/notenoughupdates/miscfeatures/updater/ConfigVersionGuiOption.kt new file mode 100644 index 00000000..3a920aec --- /dev/null +++ b/src/main/kotlin/io/github/moulberry/notenoughupdates/miscfeatures/updater/ConfigVersionGuiOption.kt @@ -0,0 +1,101 @@ +/* + * Copyright (C) 2024 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates is free software: you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * NotEnoughUpdates is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with NotEnoughUpdates. If not, see . + */ + +package io.github.moulberry.notenoughupdates.miscfeatures.updater + +import io.github.moulberry.moulconfig.gui.GuiOptionEditor +import io.github.moulberry.moulconfig.processor.ProcessedOption +import io.github.moulberry.notenoughupdates.core.util.render.TextRenderUtils +import io.github.moulberry.notenoughupdates.itemeditor.GuiElementButton +import net.minecraft.client.Minecraft +import net.minecraft.client.renderer.GlStateManager +import net.minecraft.util.EnumChatFormatting.* + +import org.lwjgl.input.Mouse + +class ConfigVersionGuiOption(option: ProcessedOption) : GuiOptionEditor(option) { + val button = GuiElementButton("", -1) { } + override fun render(x: Int, y: Int, width: Int) { + val fr = Minecraft.getMinecraft().fontRendererObj + GlStateManager.pushMatrix() + GlStateManager.translate(x.toFloat() + 10, y.toFloat(), 1F) + val width = width - 20 + val nextVersion = AutoUpdater.getNextVersion() + + button.text = when (AutoUpdater.updateState) { + AutoUpdater.UpdateState.AVAILABLE -> "Download update" + AutoUpdater.UpdateState.QUEUED -> "Downloading..." + AutoUpdater.UpdateState.DOWNLOADED -> "Downloaded" + AutoUpdater.UpdateState.NONE -> if (nextVersion == null) "Check for Updates" else "Up to date" + } + button.render(getButtonPosition(width), 10) + + if (AutoUpdater.updateState == AutoUpdater.UpdateState.DOWNLOADED) { + TextRenderUtils.drawStringCentered( + "${GREEN}The update will be installed after your next restart.", + fr, + width / 2F, + 40F, + true, + -1 + ) + } + + val widthRemaining = width - button.width - 10 + + GlStateManager.scale(2F, 2F, 1F) + TextRenderUtils.drawStringCenteredScaledMaxWidth( + "${if (AutoUpdater.updateState == AutoUpdater.UpdateState.NONE) GREEN else RED}${AutoUpdater.getCurrentVersion()}" + + if (nextVersion != null) "➜ ${GREEN}${nextVersion}" else "", + widthRemaining / 4F, + 10F, + true, + widthRemaining / 2, + -1 + ) + + GlStateManager.popMatrix() + } + + fun getButtonPosition(width: Int) = width - button.width + override fun getHeight(): Int { + return 55 + } + + override fun mouseInput(x: Int, y: Int, width: Int, mouseX: Int, mouseY: Int): Boolean { + val width = width - 20 + if (Mouse.getEventButtonState()) { + if ((mouseX - getButtonPosition(width) - x) in (0..button.width) && (mouseY - 10 - y) in (0..button.height)) { + when (AutoUpdater.updateState) { + AutoUpdater.UpdateState.AVAILABLE -> AutoUpdater.queueUpdate() + AutoUpdater.UpdateState.QUEUED -> {} + AutoUpdater.UpdateState.DOWNLOADED -> {} + AutoUpdater.UpdateState.NONE -> AutoUpdater.checkUpdate() + } + return true + } + } + return false + } + + override fun keyboardInput(): Boolean { + return false + } + +} diff --git a/src/main/resources/trusted_team_members/ironmoon.key b/src/main/resources/trusted_team_members/ironmoon.key new file mode 100644 index 00000000..32060125 Binary files /dev/null and b/src/main/resources/trusted_team_members/ironmoon.key differ diff --git a/src/main/resources/trusted_team_members/jani.key b/src/main/resources/trusted_team_members/jani.key new file mode 100644 index 00000000..6880aa9d Binary files /dev/null and b/src/main/resources/trusted_team_members/jani.key differ diff --git a/src/main/resources/trusted_team_members/lulonaut.key b/src/main/resources/trusted_team_members/lulonaut.key new file mode 100644 index 00000000..0bc0bff5 Binary files /dev/null and b/src/main/resources/trusted_team_members/lulonaut.key differ diff --git a/src/main/resources/trusted_team_members/moulberry.key b/src/main/resources/trusted_team_members/moulberry.key new file mode 100644 index 00000000..5a7a3307 Binary files /dev/null and b/src/main/resources/trusted_team_members/moulberry.key differ diff --git a/src/main/resources/trusted_team_members/nea.key b/src/main/resources/trusted_team_members/nea.key new file mode 100644 index 00000000..ec2ff36b Binary files /dev/null and b/src/main/resources/trusted_team_members/nea.key differ diff --git a/src/main/resources/trusted_team_members/nopo.key b/src/main/resources/trusted_team_members/nopo.key new file mode 100644 index 00000000..239df76d Binary files /dev/null and b/src/main/resources/trusted_team_members/nopo.key differ diff --git a/src/test/kotlin/io/github/moulberry/notenoughupdates/util/BootstrapHook.kt b/src/test/kotlin/io/github/moulberry/notenoughupdates/util/BootstrapHook.kt index cab10aaa..7aea2ca6 100644 --- a/src/test/kotlin/io/github/moulberry/notenoughupdates/util/BootstrapHook.kt +++ b/src/test/kotlin/io/github/moulberry/notenoughupdates/util/BootstrapHook.kt @@ -23,6 +23,7 @@ import net.minecraft.block.Block import net.minecraft.block.BlockFire import net.minecraft.init.Bootstrap import net.minecraft.item.Item +import net.minecraft.launchwrapper.Launch import org.junit.jupiter.api.extension.BeforeAllCallback import org.junit.jupiter.api.extension.Extension import org.junit.jupiter.api.extension.ExtensionContext @@ -40,7 +41,8 @@ class BootstrapHook : BeforeAllCallback, Extension { try { if (!bootstrapped) { bootstrapped = true - + Launch.blackboard = HashMap() + Launch.blackboard.put("fml.deobfuscatedEnvironment", true) Bootstrap::class.java.getDeclaredField("alreadyRegistered").also { it.isAccessible = true } .set(null, true) Block.registerBlocks() -- cgit