11package com.lambda.loader
22
33import com.lambda.loader.config.ConfigManager
4+ import net.fabricmc.loader.api.metadata.ModOrigin
45import java.io.File
56import java.io.IOException
67import java.nio.file.Files
@@ -22,19 +23,22 @@ class LoaderUpdater(
2223 */
2324 private fun getCurrentLoaderJarPath (): File ? {
2425 return try {
25- val codeSource = this ::class .java.protectionDomain.codeSource
26- if (codeSource != null ) {
27- val location = codeSource.location
28- val path = location.toURI().path
29- val file = File (path)
30-
31- if (file.exists() && file.name.endsWith(" .jar" )) {
32- if (ConfigManager .config.debug) logger.info(" Current loader JAR: ${file.absolutePath} " )
33- return file
26+ val fabricLoader = net.fabricmc.loader.api.FabricLoader .getInstance()
27+ val loaderMod = fabricLoader.getModContainer(" lambda-loader" )
28+
29+ if (loaderMod.isPresent) {
30+ val origin = loaderMod.get().origin
31+ if (origin.kind == ModOrigin .Kind .PATH ) {
32+ val paths = origin.paths
33+ if (paths.isNotEmpty()) {
34+ val file = paths[0 ].toFile()
35+ if (ConfigManager .config.debug) logger.info(" Current loader JAR: ${file.absolutePath} " )
36+ return file
37+ }
3438 }
3539 }
3640
37- logger.warning(" Could not determine loader JAR path from code source " )
41+ logger.warning(" Could not determine loader JAR path from Fabric Loader metadata " )
3842 null
3943 } catch (e: Exception ) {
4044 logger.warning(" Error getting current loader JAR path: ${e.message} " )
0 commit comments