Skip to content

Commit c62382b

Browse files
committed
add skyclient repo
1 parent c6d3698 commit c62382b

File tree

4 files changed

+55
-65
lines changed

4 files changed

+55
-65
lines changed

src/main/kotlin/cc/woverflow/crashpatch/CrashPatch.kt

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,28 @@ import net.minecraft.client.Minecraft
55
import net.minecraftforge.fml.common.Mod
66
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent
77
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent
8+
import org.apache.logging.log4j.LogManager
89
import java.io.File
910

1011
@Mod(modid = CrashPatch.MODID, version = CrashPatch.VERSION, name = CrashPatch.NAME, modLanguageAdapter = "gg.essential.api.utils.KotlinAdapter")
1112
object CrashPatch {
12-
lateinit var jarFile: File
1313
lateinit var modDir: File
1414
const val MODID = "crashpatch"
1515
const val NAME = "CrashPatch"
1616
const val VERSION = "@VERSION@"
17+
var useOldRepo = false
18+
private set
1719

1820
@Mod.EventHandler
1921
fun onPreInit(e: FMLPreInitializationEvent) {
2022
modDir = File(File(Minecraft.getMinecraft().mcDataDir, "W-OVERFLOW"), NAME)
2123
if (!modDir.exists()) modDir.mkdirs()
22-
Updater.addToUpdater(e.sourceFile)
24+
Updater.addToUpdater(e.sourceFile, NAME, MODID, VERSION, "W-OVERFLOW/$MODID")
2325
}
2426

2527
@Mod.EventHandler
2628
fun onPostInitialization(event: FMLPostInitializationEvent) {
27-
29+
useOldRepo = File(modDir, "useoldrepo").exists()
2830
}
29-
}
31+
}
32+
val logger = LogManager.getLogger()

src/main/kotlin/cc/woverflow/crashpatch/crashes/CrashHelper.kt

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
package cc.woverflow.crashpatch.crashes
22

3-
import com.google.gson.JsonArray
4-
import gg.essential.api.utils.WebUtil
3+
import cc.woverflow.crashpatch.CrashPatch
4+
import cc.woverflow.crashpatch.logger
55
import cc.woverflow.crashpatch.utils.asJsonObject
66
import cc.woverflow.crashpatch.utils.get
77
import cc.woverflow.crashpatch.utils.keys
8+
import com.google.gson.JsonArray
9+
import gg.essential.api.utils.WebUtil
810
import java.util.regex.Pattern
911

1012
object CrashHelper {
@@ -14,7 +16,7 @@ object CrashHelper {
1416
@JvmStatic
1517
fun scanReport(report: String): CrashScan? {
1618
try {
17-
val responses = getResponses(report)
19+
val responses = if (!CrashPatch.useOldRepo) getResponses(report) else getOldResponses(report)
1820

1921
if (responses.isEmpty()) return null
2022
return CrashScan(responses)
@@ -25,6 +27,45 @@ object CrashHelper {
2527
}
2628

2729
private fun getResponses(report: String): Map<String, ArrayList<String>> {
30+
val issues = WebUtil.fetchString("https://raw.githubusercontent.com/SkyblockClient/CrashData/main/crashes.json")?.asJsonObject() ?: return emptyMap()
31+
val responses = linkedMapOf<String, ArrayList<String>>()
32+
33+
val fixTypes = issues["fixtypes"].asJsonArray
34+
for (type in fixTypes) {
35+
responses[type.asJsonObject["name"].asString] = arrayListOf()
36+
}
37+
38+
val fixes = issues["fixes"].asJsonArray
39+
40+
for (solution in fixes) {
41+
val solutionJson = solution.asJsonObject
42+
val causes = solutionJson["causes"].asJsonArray
43+
var trigger = false
44+
for (cause in causes) {
45+
val causeJson = cause.asJsonObject
46+
when (causeJson["method"].asString) {
47+
"contains" -> {
48+
if (report.contains(causeJson["value"].asString)) {
49+
trigger = true
50+
}
51+
}
52+
"regex" -> {
53+
if (Pattern.compile(causeJson["value"].asString, Pattern.CASE_INSENSITIVE).matcher(report).find()) {
54+
trigger = true
55+
}
56+
}
57+
}
58+
}
59+
if (trigger) {
60+
responses[ArrayList(responses.keys)[if (solutionJson.has("fixtype")) solutionJson["fixtype"].asInt else 0]]?.add(solutionJson["fix"].asString)
61+
}
62+
}
63+
return responses
64+
}
65+
66+
67+
private fun getOldResponses(report: String): Map<String, ArrayList<String>> {
68+
logger.warn("Using the isXander MinecraftIssues repo is not supported! Use at your own risk.")
2869
val issues = WebUtil.fetchString("https://raw.githubusercontent.com/isXander/MinecraftIssues/main/issues.json")?.asJsonObject() ?: return linkedMapOf()
2970
val responses = linkedMapOf<String, ArrayList<String>>()
3071

src/main/kotlin/cc/woverflow/crashpatch/crashes/ModIdentifier.kt

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,24 @@
11
package cc.woverflow.crashpatch.crashes
22

3+
import cc.woverflow.crashpatch.logger
34
import net.minecraft.launchwrapper.Launch
45
import net.minecraft.launchwrapper.LaunchClassLoader
56
import net.minecraftforge.fml.common.Loader
67
import net.minecraftforge.fml.common.ModContainer
7-
import org.apache.logging.log4j.LogManager
88
import java.io.File
99
import java.io.IOException
1010
import java.net.URISyntaxException
1111
import java.net.URL
1212

1313
object ModIdentifier {
14-
private val log = LogManager.getLogger()
1514

1615
fun identifyFromStacktrace(e: Throwable?): ModContainer? {
1716
val modMap = makeModMap()
1817

1918
// Get the set of classes
2019
val classes = LinkedHashSet<String>()
2120
e?.stackTrace?.forEachIndexed { index, stackTraceElement ->
22-
if (index < 4) {
21+
if (index < 4) { // everything after the first 3 lines are basically useless and only leads to false detections
2322
classes.add(stackTraceElement.className)
2423
}
2524
}
@@ -40,9 +39,9 @@ object ModIdentifier {
4039
// Get the URL of the class
4140
val untrasformedName = untransformName(Launch.classLoader, className)
4241
var url = Launch.classLoader.getResource(untrasformedName.replace('.', '/') + ".class")
43-
log.debug("$className = $untrasformedName = $url")
42+
logger.debug("$className = $untrasformedName = $url")
4443
if (url == null) {
45-
log.warn("Failed to identify $className (untransformed name: $untrasformedName)")
44+
logger.warn("Failed to identify $className (untransformed name: $untrasformedName)")
4645
return emptySet()
4746
}
4847

src/main/kotlin/cc/woverflow/crashpatch/gui/GuiDownload.kt

Lines changed: 0 additions & 53 deletions
This file was deleted.

0 commit comments

Comments
 (0)