From 8b3d72d24103cc7bfd4cdb37372b80953019d7f5 Mon Sep 17 00:00:00 2001 From: Bjarne Koll Date: Wed, 23 Jul 2025 20:50:36 +0200 Subject: [PATCH] Correctly source param mappings on missing lvt Codebook did not correctly respect the difference between parameter and lvt indexing when sourcing parameter names from mappings on missing lvt tables. This caused parameter mappings to appear shifted after long/double params. --- .../io/papermc/codebook/lvt/LvtNamer.java | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/codebook-lvt/src/main/java/io/papermc/codebook/lvt/LvtNamer.java b/codebook-lvt/src/main/java/io/papermc/codebook/lvt/LvtNamer.java index 083ae87..38b5e01 100644 --- a/codebook-lvt/src/main/java/io/papermc/codebook/lvt/LvtNamer.java +++ b/codebook-lvt/src/main/java/io/papermc/codebook/lvt/LvtNamer.java @@ -216,11 +216,10 @@ private void fillNames0(final MethodData method) throws IOException { } for (int i = 0; i < paramCount; i++) { - // always (i + 1) because abstract methods are never static final int fi = i; @Nullable String paramName = methodMapping - .flatMap(m -> m.getParameterMapping(fi + 1)) + .flatMap(m -> m.getParameterMapping(fromParamToLvtIndex(fi, method))) .map(Mapping::getDeobfuscatedName) .orElse(null); @@ -483,4 +482,26 @@ private static int fromLvtToParamIndex(final int lvtIndex, final MethodData meth return -1; } + + /* + * Transform the given param index into a lvt index. + */ + private static int fromParamToLvtIndex(final int paramIndex, final MethodData method) { + int currentLvtIndex = method.isStatic() ? 0 : 1; + int currentParamIndex = 0; + + for (final JvmType param : method.params()) { + if (currentParamIndex == paramIndex) { + return currentLvtIndex; + } + + currentParamIndex++; + currentLvtIndex++; + if (param == PrimitiveType.LONG || param == PrimitiveType.DOUBLE) { + currentLvtIndex++; + } + } + + return -1; + } }