md-5 / SpecialSource

Automatic generator and renamer of jar obfuscation mappings.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Method override is not being remapped for subclasses in different modules

willkroboth opened this issue · comments

I have some classes set up like this:

Before mapping:

Module 1_19-common

pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <parent>
        <artifactId>ConfigCommands-nms</artifactId>
        <groupId>me.willkroboth</groupId>
        <version>3.0.0</version>
    </parent>

    <artifactId>ConfigCommands-1_19-common</artifactId>

    <properties>
        <spigot.version>1.19-R0.1-SNAPSHOT</spigot.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.spigotmc</groupId>
            <artifactId>spigot</artifactId>
            <version>${spigot.version}</version>
            <classifier>remapped-mojang</classifier>
            <scope>provided</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <executions>
                    <execution>
                        <id>Mojang-Mapped</id>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                        <configuration>
                            <classifier>mojang-mapped</classifier>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>net.md-5</groupId>
                <artifactId>specialsource-maven-plugin</artifactId>
                <version>1.2.4</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>remap</goal>
                        </goals>
                        <id>remap-obf</id>
                        <configuration>
                            <srgIn>org.spigotmc:minecraft-server:${spigot.version}:txt:maps-mojang</srgIn>
                            <reverse>true</reverse>
                            <remappedDependencies>org.spigotmc:spigot:${spigot.version}:jar:remapped-mojang</remappedDependencies>
                            <remappedArtifactAttached>true</remappedArtifactAttached>
                            <remappedClassifierName>remapped-obf</remappedClassifierName>
                        </configuration>
                    </execution>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>remap</goal>
                        </goals>
                        <id>remap-spigot</id>
                        <configuration>
                            <inputFile>${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar</inputFile>
                            <srgIn>org.spigotmc:minecraft-server:${spigot.version}:csrg:maps-spigot</srgIn>
                            <remappedDependencies>org.spigotmc:spigot:${spigot.version}:jar:remapped-obf</remappedDependencies>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

PlayerOpSender1_19_common.java:

import net.minecraft.server.level.ServerPlayer;

public abstract class PlayerOpSender1_19_common ... {
    ...
    protected abstract static class ServerPlayerOpWrapper extends ServerPlayer {
        ...
    }
    ...
}

Module 1_19

pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <parent>
        <artifactId>ConfigCommands-nms</artifactId>
        <groupId>me.willkroboth</groupId>
        <version>3.0.0</version>
    </parent>

    <artifactId>ConfigCommands-1_19</artifactId>

    <properties>
        <spigot.version>1.19-R0.1-SNAPSHOT</spigot.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.spigotmc</groupId>
            <artifactId>spigot</artifactId>
            <version>${spigot.version}</version>
            <classifier>remapped-mojang</classifier>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>me.willkroboth</groupId>
            <artifactId>ConfigCommands-1_19-common</artifactId>
            <version>${project.version}</version>
            <classifier>mojang-mapped</classifier>
            <scope>provided</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>net.md-5</groupId>
                <artifactId>specialsource-maven-plugin</artifactId>
                <version>1.2.4</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>remap</goal>
                        </goals>
                        <id>remap-obf</id>
                        <configuration>
                            <srgIn>org.spigotmc:minecraft-server:${spigot.version}:txt:maps-mojang</srgIn>
                            <reverse>true</reverse>
                            <remappedDependencies>org.spigotmc:spigot:${spigot.version}:jar:remapped-mojang</remappedDependencies>
                            <remappedArtifactAttached>true</remappedArtifactAttached>
                            <remappedClassifierName>remapped-obf</remappedClassifierName>
                        </configuration>
                    </execution>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>remap</goal>
                        </goals>
                        <id>remap-spigot</id>
                        <configuration>
                            <inputFile>${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar</inputFile>
                            <srgIn>org.spigotmc:minecraft-server:${spigot.version}:csrg:maps-spigot</srgIn>
                            <remappedDependencies>org.spigotmc:spigot:${spigot.version}:jar:remapped-obf</remappedDependencies>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

PlayerOpSender1_19.java:

public class PlayerOpSender1_19 extends PlayerOpSender1_19_common ... {
    ...
    protected static class ServerPlayerOpWrapper extends PlayerOpSender1_19_common.ServerPlayerOpWrapper{
        ...
        @Override
        public CommandSourceStack createCommandSourceStack() {
            return OpSender1_19_common.modifyStack(super.createCommandSourceStack(), source);
        }
    }
}

Module 1_19_1

pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <parent>
        <artifactId>ConfigCommands-nms</artifactId>
        <groupId>me.willkroboth</groupId>
        <version>3.0.0</version>
    </parent>

    <artifactId>ConfigCommands-1_19_1</artifactId>
    <properties>
        <spigot.version>1.19.1-R0.1-SNAPSHOT</spigot.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.spigotmc</groupId>
            <artifactId>spigot</artifactId>
            <version>${spigot.version}</version>
            <classifier>remapped-mojang</classifier>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>me.willkroboth</groupId>
            <artifactId>ConfigCommands-1_19-common</artifactId>
            <version>${project.version}</version>
            <classifier>mojang-mapped</classifier>
            <scope>provided</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>net.md-5</groupId>
                <artifactId>specialsource-maven-plugin</artifactId>
                <version>1.2.4</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>remap</goal>
                        </goals>
                        <id>remap-obf</id>
                        <configuration>
                            <srgIn>org.spigotmc:minecraft-server:${spigot.version}:txt:maps-mojang</srgIn>
                            <reverse>true</reverse>
                            <remappedDependencies>org.spigotmc:spigot:${spigot.version}:jar:remapped-mojang</remappedDependencies>
                            <remappedArtifactAttached>true</remappedArtifactAttached>
                            <remappedClassifierName>remapped-obf</remappedClassifierName>
                        </configuration>
                    </execution>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>remap</goal>
                        </goals>
                        <id>remap-spigot</id>
                        <configuration>
                            <inputFile>${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar</inputFile>
                            <srgIn>org.spigotmc:minecraft-server:${spigot.version}:csrg:maps-spigot</srgIn>
                            <remappedDependencies>org.spigotmc:spigot:${spigot.version}:jar:remapped-obf</remappedDependencies>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

PlayerOpSender1_19_1.java:

public class PlayerOpSender1_19_1 extends PlayerOpSender1_19_common ... {
    ...
    protected static class ServerPlayerOpWrapper extends PlayerOpSender1_19_common.ServerPlayerOpWrapper{
        ...
        @Override
        public CommandSourceStack createCommandSourceStack() {
            return OpSender1_19_common.modifyStack(super.createCommandSourceStack(), source);
        }
    }
}

After mapping:

PlayerOpSender1_19_common.java:

import net.minecraft.server.level.EntityPlayer;

public abstract class PlayerOpSender1_19_common ... {
    ...
    // ServerPlayer has become EntityPlayer
    protected abstract static class ServerPlayerOpWrapper extends EntityPlayer {
        ...
    }
    ...
}

PlayerOpSender1_19.java:

public class PlayerOpSender1_19 extends PlayerOpSender1_19_common ... {
    ...
    protected static class ServerPlayerOpWrapper extends PlayerOpSender1_19_common.ServerPlayerOpWrapper{
        ...
        // CommandSourceStack is now CommandListenerWrapper
        // createCommandSourceStack should have become cU
        @Override
        public CommandListenerWrapper createCommandSourceStack() {
            return OpSender1_19_common.modifyStack(super.createCommandSourceStack(), source);
        }
    }
}

PlayerOpSender1_19_1.java:

public class PlayerOpSender1_19_1 extends PlayerOpSender1_19_common ... {
    ...
    protected static class ServerPlayerOpWrapper extends PlayerOpSender1_19_common.ServerPlayerOpWrapper{
        ...
        // CommandSourceStack is now CommandListenerWrapper
        // createCommandSourceStack should have become cT
        @Override
        public CommandListenerWrapper createCommandSourceStack() {
            return OpSender1_19_common.modifyStack(super.createCommandSourceStack(), source);
        }
    }
}

I've set up special source to map PlayerOpSender1_19 with 1.19 mappings and PlayerOpSender1_19_1 with 1.19.1 mappings.

However, the method overrides for createCommandSourceStack aren't being mapped correctly. In 1.19 it should become cU, while in 1.19.1 is should become cT. Parts of the file are being remapped, such as CommandSourceStack becoming CommmandListenerWrapper, but the method override is not changing.

It seems that the way the classes are inherited is preventing special source from realizing it needs to change these methods. It might also have something to do with the way the classes are split up across maven modules.

I figured this out on my side by shading 1_19-common into 1_19 and 1_19_1. This seems to help special source realize that ServerPlayerOpWrapper extends ServerPlayer and it remaps the method override.

I'll leave this issue open for now because it seems that there is a problem where special source is not considering dependencies when finding classes and methods to remap. Doing it the shading way I found requires quite a bit of hacky finagling that really shouldn't happen.