Skip to content

Commit

Permalink
Merge branch 'dev' into 1.20.1/stable
Browse files Browse the repository at this point in the history
  • Loading branch information
jellysquid3 committed Jan 27, 2024
2 parents 5d8886b + 6af3d20 commit 54dd861
Show file tree
Hide file tree
Showing 22 changed files with 699 additions and 118 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Used when a commit is pushed to the repository
# This makes use of caching for faster builds and uploads the resulting artifacts
name: build-snapshot
name: build-commit

on: [ push ]

Expand Down Expand Up @@ -28,9 +28,9 @@ jobs:
~/.gradle/caches
~/.gradle/loom-cache
~/.gradle/wrapper
key: ${{ runner.os }}-build-snapshot-${{ hashFiles('gradle/wrapper/gradle-wrapper.properties') }}
key: ${{ runner.os }}-build-commit-${{ hashFiles('gradle/wrapper/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-build-snapshot-
${{ runner.os }}-build-commit-
- name: Build artifacts
run: ./gradlew build
- name: Upload artifacts
Expand Down
43 changes: 43 additions & 0 deletions .github/workflows/build-tag.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Used when a commit is tagged and pushed to the repository
# This makes use of caching for faster builds and uploads the resulting artifacts
name: build-tag

on:
push:
tags:
- '*'

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Extract current branch name
shell: bash
# bash pattern expansion to grab branch name without slashes
run: ref="${GITHUB_REF#refs/heads/}" && echo "branch=${ref////-}" >> $GITHUB_OUTPUT
id: ref
- name: Checkout sources
uses: actions/checkout@v3
- name: Set up JDK
uses: actions/setup-java@v2
with:
distribution: 'temurin'
java-version: 17
- name: Initialize caches
uses: actions/cache@v3
with:
path: |
~/.gradle/caches
~/.gradle/loom-cache
~/.gradle/wrapper
key: ${{ runner.os }}-build-tag-${{ hashFiles('gradle/wrapper/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-build-tag-
- name: Build artifacts
run: ./gradlew build -Pbuild.release=true
- name: Upload artifacts
uses: actions/upload-artifact@v2
with:
name: sodium-artifacts-${{ steps.ref.outputs.branch }}
path: build/libs/*.jar
53 changes: 30 additions & 23 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,13 @@ plugins {
// is not reachable for some reason, and it makes builds much more reproducible. Observation also shows that it
// really helps to improve startup times on slow connections.
id 'fabric-loom' version '1.4.1'

// This dependency is only used to determine the state of the Git working tree so that build artifacts can be
// more easily identified. TODO: Lazily load GrGit via a service only when builds are performed.
id 'org.ajoberstar.grgit' version '5.2.0'
}

apply from: "${rootProject.projectDir}/gradle/fabric.gradle"
apply from: "${rootProject.projectDir}/gradle/java.gradle"

archivesBaseName = "${project.archives_base_name}-mc${project.minecraft_version}"
version = "${project.mod_version}${getVersionMetadata()}"
archivesBaseName = project.archives_base_name
version = createVersionString()
group = project.maven_group

loom {
Expand Down Expand Up @@ -93,30 +89,41 @@ dependencies {
modIncludeImplementation(fabricApi.module("fabric-api-base", project.fabric_version))
modIncludeImplementation(fabricApi.module("fabric-block-view-api-v2", project.fabric_version))
modIncludeImplementation(fabricApi.module("fabric-rendering-fluids-v1", project.fabric_version))
// `fabricApi.module` does not work with deprecated modules, so add the module dependency manually.
// This is planned to be fixed in Loom 1.4.
modIncludeImplementation(fabricApi.module("fabric-rendering-data-attachment-v1", project.fabric_version))
modIncludeImplementation(fabricApi.module("fabric-resource-loader-v0", project.fabric_version))
}

def getVersionMetadata() {
// CI builds only
if (project.hasProperty("build.release")) {
return "" // no tag whatsoever
}
def createVersionString() {
var builder = new StringBuilder()

if (grgit != null) {
def head = grgit.head()
def id = head.abbreviatedId
boolean release = project.hasProperty("build.release")

// Flag the build if the build tree is not clean
if (!grgit.status().clean) {
id += "-dirty"
String build_id = System.getenv("GITHUB_RUN_NUMBER")
String mod_version = project.mod_version as String

if (release) {
builder.append(mod_version)
} else {
// Strip the existing pre-release version
if (mod_version.contains('-')) {
builder.append(mod_version.substring(0, mod_version.indexOf('-')))
} else {
builder.append(mod_version)
}

return "+git.${id}"
builder.append("-snapshot")
}

// No tracking information could be found about the build
return "+unknown"
}
var minecraft_version = (project.minecraft_version as String)
builder.append("+mc").append(minecraft_version)

if (!release) {
if (build_id != null) {
builder.append("-build.${build_id}")
} else {
builder.append("-local")
}
}

return builder.toString()
}
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ loader_version=0.15.6
fabric_version=0.91.0+1.20.1

# Mod Properties
mod_version=0.5.6
mod_version=0.5.6-rc.3
maven_group=me.jellysquid.mods
archives_base_name=sodium-fabric
main_class=net.caffeinemc.mods.sodium.desktop.LaunchWarn
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package net.caffeinemc.mods.sodium.desktop.utils.browse;

import java.io.IOException;
import java.util.Objects;

class GNOMEImpl implements BrowseUrlHandler {
public static boolean isSupported() {
return XDGImpl.isSupported() && System.getenv("XDG_CURRENT_DESKTOP").equals("GNOME");
return XDGImpl.isSupported() && Objects.equals(System.getenv("XDG_CURRENT_DESKTOP"), "GNOME");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package net.caffeinemc.mods.sodium.desktop.utils.browse;

import java.io.IOException;
import java.util.Objects;

class KDEImpl implements BrowseUrlHandler {
public static boolean isSupported() {
return XDGImpl.isSupported() && System.getenv("XDG_CURRENT_DESKTOP").equals("KDE");
return XDGImpl.isSupported() && Objects.equals(System.getenv("XDG_CURRENT_DESKTOP"), "KDE");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package me.jellysquid.mods.sodium.client;

import me.jellysquid.mods.sodium.client.gui.SodiumGameOptions;
import me.jellysquid.mods.sodium.client.data.fingerprint.FingerprintMeasure;
import me.jellysquid.mods.sodium.client.data.fingerprint.HashedFingerprint;
import me.jellysquid.mods.sodium.client.gui.console.Console;
import me.jellysquid.mods.sodium.client.gui.console.message.MessageLevel;
import me.jellysquid.mods.sodium.client.util.FlawlessFrames;
Expand Down Expand Up @@ -33,6 +35,12 @@ public void onInitializeClient() {
CONFIG = loadConfig();

FlawlessFrames.onClientInitialization();

try {
updateFingerprint();
} catch (Throwable t) {
LOGGER.error("Failed to update fingerprint", t);
}
}

public static SodiumGameOptions options() {
Expand Down Expand Up @@ -84,4 +92,33 @@ public static String getVersion() {

return MOD_VERSION;
}

private static void updateFingerprint() {
var current = FingerprintMeasure.create();

if (current == null) {
return;
}

HashedFingerprint saved = null;

try {
saved = HashedFingerprint.loadFromDisk();
} catch (Throwable t) {
LOGGER.error("Failed to load existing fingerprint", t);
}

if (saved == null || !current.looselyMatches(saved)) {
HashedFingerprint.writeToDisk(current.hashed());

CONFIG.notifications.hasSeenDonationPrompt = false;
CONFIG.notifications.hasClearedDonationButton = false;

try {
SodiumGameOptions.writeToDisk(CONFIG);
} catch (IOException e) {
LOGGER.error("Failed to update config file", e);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,10 @@ private static void checkRTSSModules() {
}
}

private static final Pattern RTSS_VERSION_PATTERN = Pattern.compile("^(?<x>\\d*), (?<y>\\d*), (?<z>\\d*), (?<w>\\d*)$");
// BUG: For some reason, the version string can either be in the format of "X.Y.Z.W" or "X, Y, Z, W"...
// This does not make sense, and probably points to our handling of code pages being wrong. But for the time being,
// the regex has been made to handle both formats, because looking at Win32 code any longer is going to break me.
private static final Pattern RTSS_VERSION_PATTERN = Pattern.compile("^(?<x>\\d*)(, |\\.)(?<y>\\d*)(, |\\.)(?<z>\\d*)(, |\\.)(?<w>\\d*)$");

private static boolean isRTSSCompatible(String version) {
var matcher = RTSS_VERSION_PATTERN.matcher(version);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ private static void printCompatibilityReport(Map<String, ScanResults> scanResult
var path = entry.getKey();
var result = entry.getValue();

if (result.shaderPrograms.isEmpty() && result.shaderIncludes.isEmpty()) {
continue;
}

builder.append("- Resource pack: ").append(getResourcePackName(path)).append("\n");

if (!result.shaderPrograms.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package me.jellysquid.mods.sodium.mixin;
package me.jellysquid.mods.sodium.client.data.config;

import me.jellysquid.mods.sodium.mixin.MixinOption;
import net.fabricmc.loader.api.FabricLoader;
import net.fabricmc.loader.api.ModContainer;
import net.fabricmc.loader.api.metadata.CustomValue;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package me.jellysquid.mods.sodium.client.data.fingerprint;

import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.client.MinecraftClient;
import org.apache.commons.codec.binary.Hex;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.SecureRandom;
import java.time.Instant;
import java.util.Objects;

public record FingerprintMeasure(@NotNull String uuid, @NotNull String path) {
private static final int SALT_LENGTH = 64;

public static @Nullable FingerprintMeasure create() {
var uuid = MinecraftClient.getInstance().getSession().getUuidOrNull();
var path = FabricLoader.getInstance().getGameDir();

if (uuid == null || path == null) {
return null;
}

return new FingerprintMeasure(uuid.toString(), path.toAbsolutePath().toString());
}

public HashedFingerprint hashed() {
var date = Instant.now();
var salt = createSalt();

var uuidHashHex = sha512(salt, this.uuid());
var pathHashHex = sha512(salt, this.path());

return new HashedFingerprint(HashedFingerprint.CURRENT_VERSION, salt, uuidHashHex, pathHashHex, date.getEpochSecond());
}

public boolean looselyMatches(HashedFingerprint hashed) {
var uuidHashHex = sha512(hashed.saltHex(), this.uuid());
var pathHashHex = sha512(hashed.saltHex(), this.path());

return Objects.equals(uuidHashHex, hashed.uuidHashHex()) || Objects.equals(pathHashHex, hashed.pathHashHex());
}

private static String sha512(@NotNull String salt, @NotNull String message) {
MessageDigest md;

try {
md = MessageDigest.getInstance("SHA-512");
md.update(Hex.decodeHex(salt));
md.update(message.getBytes(StandardCharsets.UTF_8));
} catch (Throwable t) {
throw new RuntimeException("Failed to hash value", t);
}

return Hex.encodeHexString(md.digest());
}

private static String createSalt() {
var rng = new SecureRandom();

var salt = new byte[SALT_LENGTH];
rng.nextBytes(salt);

return Hex.encodeHexString(salt);
}
}
Loading

0 comments on commit 54dd861

Please sign in to comment.