Skip to content

Commit

Permalink
final changes
Browse files Browse the repository at this point in the history
  • Loading branch information
BasiqueEvangelist committed Jan 2, 2023
1 parent c5f8549 commit 63ef35b
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 39 deletions.
11 changes: 9 additions & 2 deletions src/main/java/io/wispforest/gadget/Gadget.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import net.fabricmc.api.EnvType;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.loader.api.FabricLoader;
import net.fabricmc.loader.api.entrypoint.EntrypointContainer;
import net.minecraft.util.Identifier;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -26,7 +27,13 @@ public void onInitialize() {
if (FabricLoader.getInstance().getEnvironmentType() == EnvType.SERVER)
MappingsManager.init();

FabricLoader.getInstance().getEntrypoints("gadget:init", GadgetEntrypoint.class)
.forEach(GadgetEntrypoint::onGadgetInit);
for (EntrypointContainer<GadgetEntrypoint> container : FabricLoader.getInstance().getEntrypointContainers("gadget:init", GadgetEntrypoint.class)) {
try {
container.getEntrypoint().onGadgetInit();
} catch (Exception e) {
LOGGER.error("{}'s `gadget:init` entrypoint handler threw an exception",
container.getProvider().getMetadata().getId(), e);
}
}
}
}
11 changes: 9 additions & 2 deletions src/main/java/io/wispforest/gadget/client/GadgetClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import net.fabricmc.fabric.api.client.screen.v1.ScreenEvents;
import net.fabricmc.fabric.api.client.screen.v1.ScreenKeyboardEvents;
import net.fabricmc.loader.api.FabricLoader;
import net.fabricmc.loader.api.entrypoint.EntrypointContainer;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.GameMenuScreen;
import net.minecraft.client.gui.screen.Screen;
Expand Down Expand Up @@ -213,8 +214,14 @@ public void onInitializeClient() {
}
});

FabricLoader.getInstance().getEntrypoints("gadget:client_init", GadgetClientEntrypoint.class)
.forEach(GadgetClientEntrypoint::onGadgetClientInit);
for (EntrypointContainer<GadgetClientEntrypoint> container : FabricLoader.getInstance().getEntrypointContainers("gadget:client_init", GadgetClientEntrypoint.class)) {
try {
container.getEntrypoint().onGadgetClientInit();
} catch (Exception e) {
Gadget.LOGGER.error("{}'s `gadget:client_init` entrypoint handler threw an exception",
container.getProvider().getMetadata().getId(), e);
}
}
}

// 100% not stolen from owo-whats-this
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ protected void build(VerticalFlowLayout verticalFlowLayout) {
verticalFlowLayout.child(scroll.child(main));

main
.padding(Insets.of(15));
.padding(Insets.of(15, 22, 15, 15));

main.child(island.mainContainer());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,33 +49,35 @@ public QuiltflowerHandlerImpl(ProgressToast toast, Consumer<Text> logConsumer) {

try {
MappingsManager.runtimeMappings().accept(mappings);
MappingsManager.displayMappings()
.load(new MappingNsRenamer(mappings, Map.of("named", "target")));
} catch (IOException e) {
throw new RuntimeException(e);
}

mappings.visitNamespaces("intermediary", List.of("source"));
mappings.visitNamespaces("intermediary", List.of("source"));
int srcId = mappings.getNamespaceId("source");

for (MappingTree.ClassMapping c : mappings.getClasses()) {
String cName = c.getName("named");
if (cName == null) cName = c.getName("intermediary");
for (MappingTree.ClassMapping c : mappings.getClasses()) {
String cName = c.getName("named");
if (cName == null) cName = c.getName("intermediary");

c.setDstName(cName, mappings.getNamespaceId("source"));
c.setDstName(cName, srcId);

for (MappingTree.FieldMapping f : c.getFields()) {
String fName = f.getName("named");
if (fName == null) fName = f.getName("intermediary");
for (MappingTree.FieldMapping f : c.getFields()) {
String fName = f.getName("named");
if (fName == null) fName = f.getName("intermediary");

f.setDstName(fName, mappings.getNamespaceId("source"));
}
f.setDstName(fName, srcId);
}

for (MappingTree.MethodMapping m : c.getMethods()) {
String mName = m.getName("named");
if (mName == null) mName = m.getName("intermediary");
for (MappingTree.MethodMapping m : c.getMethods()) {
String mName = m.getName("named");
if (mName == null) mName = m.getName("intermediary");

m.setDstName(mName, mappings.getNamespaceId("source"));
m.setDstName(mName, srcId);
}
}

MappingsManager.displayMappings()
.load(new MappingNsRenamer(mappings, Map.of("named", "target")));
} catch (IOException e) {
throw new RuntimeException(e);
}

this.remapperStore = new RemapperStore(this::getUnmappedClassBytes, logConsumer, mappings,
Expand Down Expand Up @@ -138,7 +140,9 @@ public String decompileClass(Class<?> klass) {
Fernflower fernflower = new Fernflower(resultSaver, Map.of("ind", " "), new GadgetFernflowerLogger(this));

fernflower.addSource(new ClassContextSource(this, klass));
fernflower.addLibrary(new EverythingContextSource(this));

if (Gadget.CONFIG.fullDecompilationContext())
fernflower.addLibrary(new EverythingContextSource(this));

fernflower.decompileContext();
fernflower.clearContext();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public MemberData member(MemberType type, String fName, String fDesc) {

public MemberData openMember(MemberType type, String fName, String fDesc) {
for (var id : declaredMembers(type)) {
if (id.isClosed()
if (!id.isClosed()
&& id.name().equals(fName)
&& id.desc().equals(fDesc)) {
return id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,6 @@ public FieldVisitor visitField(int access, String name, String descriptor, Strin
boolean isClosed = (access & (Opcodes.ACC_PUBLIC | Opcodes.ACC_PROTECTED)) == 0
|| (access & Opcodes.ACC_STATIC) != 0;

if (!isClosed) {
if (superclass != null && superclass.openMember(MemberType.FIELD, name, descriptor) != null)
return null;

for (var iface : interfaces) {
if (iface.openMember(MemberType.FIELD, name, descriptor) != null)
return null;
}
}

declaredFields.add(new MemberData(MemberType.FIELD, this.name, name, descriptor, isClosed));
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public String mapFieldName(String owner, String name, String descriptor) {

if (f == null) return name;

return MappingUtils.fieldTargetName(tree, srcId, dstId, owner, name, descriptor, true);
return MappingUtils.fieldTargetName(tree, srcId, dstId, f.owner(), f.name(), f.desc(), true);

}

Expand All @@ -50,6 +50,11 @@ public String mapMethodName(String owner, String name, String descriptor) {

if (m == null) return name;

return MappingUtils.methodTargetName(tree, srcId, dstId, owner, name, descriptor, true);
return MappingUtils.methodTargetName(tree, srcId, dstId, m.owner(), m.name(), m.desc(), true);
}

@Override
public String mapRecordComponentName(String owner, String name, String descriptor) {
return mapFieldName(owner, name, descriptor);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public static MappingTreeView runtimeMappings() {
if (runtimeMappings != null)
return runtimeMappings;

URL url = MappingsManager.class.getClassLoader().getResource("mappings/mappings.tiny");
URL url = FabricLoader.class.getClassLoader().getResource("mappings/mappings.tiny");

if (url == null) {
return runtimeMappings = new MemoryMappingTree();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public class GadgetConfigModel {
FabricLoader.getInstance().isDevelopmentEnvironment() ? MappingsType.LOCAL : MappingsType.YARN;
public UICounterMode uiCounterMode = UICounterMode.LOG_ON_LONG_UPDATE;
public boolean inspectClasses = true;
public boolean fullDecompilationContext = true;
@Hook public List<String> hiddenFields = new ArrayList<>(List.of(
"java.lang.Enum#name",

Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/assets/gadget/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,8 @@
"text.config.gadget.enum.uICounterMode.log_always": "Always Log",
"text.config.gadget.option.inspectClasses": "Inspect Classes",
"text.config.gadget.option.inspectClasses.tooltip": "Allows you to inspect game classes",
"text.config.gadget.option.fullDecompilationContext": "Full Decompilation Context",
"text.config.gadget.option.fullDecompilationContext.tooltip": "Gives QF all classes for better decompiled sources\nMight result in slower decompiles",
"text.config.gadget.option.hiddenFields": "Hidden Fields",
"text.config.gadget.option.hiddenFields.tooltip": "Fields hidden in field inspections.",

Expand Down

0 comments on commit 63ef35b

Please sign in to comment.