🧩 feat: 调整匹配规则优先级,(有望彻底)解决误报问题

This commit is contained in:
TheWhiteDog9487
2026-09-16 15:35:57 +08:00
parent 6f0f58a715
commit 16b1a01255
6 changed files with 14 additions and 15 deletions
@@ -42,7 +42,4 @@ public class KeyMappingMixin {
|| ClassName.startsWith("kotlin.") || ClassName.startsWith("kotlin.")
|| ClassName.startsWith("net.minecraft") || ClassName.startsWith("net.minecraft")
|| ClassName.startsWith("net.fabricmc") || ClassName.startsWith("net.fabricmc")
|| ClassName.startsWith("org.spongepowered.") || ClassName.startsWith("org.spongepowered."); } }
// ↓ 第三方Mod兼容条目
|| ClassName.startsWith("dev.tr7zw.transition"); } }
@@ -17,17 +17,16 @@ val VanillaMinecraftContainer: ModContainer = FabricLoader
val KeyMappingToMod: HashMap<KeyMapping, ModInfo> = HashMap() val KeyMappingToMod: HashMap<KeyMapping, ModInfo> = HashMap()
val KeyMapping.Provider: ModInfo get() { val KeyMapping.Provider: ModInfo get() {
if (SettingsInstance.SearchInStackTrace) {
KeyMappingToMod[this]?.let { return it } }
val KeyBindTranslationKey = name val KeyBindTranslationKey = name
val CandidateModIds = KeyBindTranslationKey.split(".") val CandidateModIds = KeyBindTranslationKey.split(".")
if (CandidateModIds.size == 1){
return ModInfo(null) }
for (CandidateModId in CandidateModIds) { for (CandidateModId in CandidateModIds) {
val ModContainer = FabricLoader.getInstance().getModContainer(CandidateModId) val ModContainer = FabricLoader.getInstance().getModContainer(CandidateModId)
if (ModContainer.isPresent) { if (ModContainer.isPresent) {
return ModContainer.map(::ModInfo).get() } } return ModContainer.map(::ModInfo).get() } }
if (SettingsInstance.SearchInStackTrace) {
KeyMappingToMod[this]?.let { return it } }
if (CandidateModIds.size == 1){
return ModInfo(null) }
return ModInfo(VanillaMinecraftContainer) } return ModInfo(VanillaMinecraftContainer) }
data class ModInfo(val ModContainerInstance: ModContainer?) { data class ModInfo(val ModContainerInstance: ModContainer?) {
@@ -48,7 +48,7 @@ class ModMenuEntryPoint: ModMenuApi {
Option.createBuilder<Boolean>() Option.createBuilder<Boolean>()
.name(Component.translatable("option.SearchInStackTrace")) .name(Component.translatable("option.SearchInStackTrace"))
.description { OptionDescription.of(Component.translatable("option.SearchInStackTrace.description") ) } .description { OptionDescription.of(Component.translatable("option.SearchInStackTrace.description") ) }
.binding( false, { SettingsInstance.SearchInStackTrace }, { SettingsInstance.SearchInStackTrace = it } ) .binding( true, { SettingsInstance.SearchInStackTrace }, { SettingsInstance.SearchInStackTrace = it } )
.controller(BooleanControllerBuilder::create ) .controller(BooleanControllerBuilder::create )
.build() } .build() }
.option { .option {
@@ -9,6 +9,10 @@ import java.nio.file.Path
import java.nio.file.StandardWatchEventKinds import java.nio.file.StandardWatchEventKinds
const val CurrentConfigurationVersionCode: Long = 0 const val CurrentConfigurationVersionCode: Long = 0
/**
* @see ModMenuEntryPoint\
*/
class Settings { class Settings {
@SerialEntry(comment = @SerialEntry(comment =
""" """
@@ -61,12 +65,11 @@ class Settings {
@SerialEntry(comment = @SerialEntry(comment =
""" """
是否注入KeyMapping构造函数,在每次注册按键绑定时查询线程的调用栈信息来进行强力匹配 是否注入KeyMapping构造函数,在每次注册按键绑定时查询线程的调用栈信息来进行强力匹配
警告:在部分情况下可能产生更多误报,请按需选择
类型:布尔值 类型:布尔值
取值范围:true false 取值范围:true false
默认值:false 默认值:true
""") """)
var SearchInStackTrace = false var SearchInStackTrace = true
@SerialEntry(comment = @SerialEntry(comment =
""" """
@@ -16,7 +16,7 @@
"option.ShowFilePath": "Show File Path", "option.ShowFilePath": "Show File Path",
"option.ShowFilePath.description": "Display the mod file path in the information", "option.ShowFilePath.description": "Display the mod file path in the information",
"option.SearchInStackTrace": "Enable aggressive search via stack trace lookup", "option.SearchInStackTrace": "Enable aggressive search via stack trace lookup",
"option.SearchInStackTrace.description": "Injects into the KeyMapping class constructor and queries the current thread's call stack each time a keybind is registered for aggressive matching\nWarning: In some cases, this may produce more false positives; enable as needed", "option.SearchInStackTrace.description": "Injects into the KeyMapping class constructor and queries the current thread's call stack each time a keybind is registered for aggressive matching",
"tooltip.provided_by": "Provided by: %s", "tooltip.provided_by": "Provided by: %s",
"tooltip.provider_mod_id": "Provider Mod ID: %s", "tooltip.provider_mod_id": "Provider Mod ID: %s",
"tooltip.key_id": "Keybind ID: %s", "tooltip.key_id": "Keybind ID: %s",
@@ -16,7 +16,7 @@
"option.ShowFilePath": "是否显示文件路径", "option.ShowFilePath": "是否显示文件路径",
"option.ShowFilePath.description": "在信息中显示Mod的文件路径", "option.ShowFilePath.description": "在信息中显示Mod的文件路径",
"option.SearchInStackTrace": "是否要通过查询堆栈信息来进行强力搜索", "option.SearchInStackTrace": "是否要通过查询堆栈信息来进行强力搜索",
"option.SearchInStackTrace.description": "注入KeyMapping类的构造函数,在每次注册按键绑定时查询线程的调用栈信息来进行强力匹配\n警告:部分情况下可能产生更多误报,请按需选择", "option.SearchInStackTrace.description": "注入KeyMapping类的构造函数,在每次注册按键绑定时查询线程的调用栈信息来进行强力匹配",
"tooltip.provided_by": "提供者:%s", "tooltip.provided_by": "提供者:%s",
"tooltip.provider_mod_id": "提供者ID%s", "tooltip.provider_mod_id": "提供者ID%s",
"tooltip.key_id": "键位ID%s", "tooltip.key_id": "键位ID%s",