Skip to content

Commit

Permalink
fork11
Browse files Browse the repository at this point in the history
fork11
  • Loading branch information
wangyu2333333 committed May 29, 2024
1 parent 29cae6f commit 9cac9c9
Show file tree
Hide file tree
Showing 2,064 changed files with 41,504 additions and 38,868 deletions.
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
package io.gitlab.dwarfyassassin.lotrucp.core;

import java.util.HashSet;

import org.objectweb.asm.*;
import org.objectweb.asm.tree.ClassNode;

import cpw.mods.fml.relauncher.*;
import cpw.mods.fml.relauncher.FMLLaunchHandler;
import cpw.mods.fml.relauncher.ReflectionHelper;
import io.gitlab.dwarfyassassin.lotrucp.core.patches.base.Patcher;
import net.minecraft.launchwrapper.IClassTransformer;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.tree.ClassNode;

import java.util.Collection;
import java.util.HashSet;

public class UCPClassTransformer implements IClassTransformer {
static {
FMLLaunchHandler launchHandler = (FMLLaunchHandler) ReflectionHelper.getPrivateValue(FMLLaunchHandler.class, null, "INSTANCE");
FMLLaunchHandler launchHandler = ReflectionHelper.getPrivateValue(FMLLaunchHandler.class, null, "INSTANCE");
ReflectionHelper.getPrivateValue(FMLLaunchHandler.class, launchHandler, "classLoader");
}

Expand All @@ -33,7 +35,7 @@ public byte[] transform(String name, String transformedName, byte[] classBytes)
classBytes = writer.toByteArray();
}
if (ran) {
HashSet<Patcher> removes = new HashSet<>();
Collection<Patcher> removes = new HashSet<>();
for (Patcher patcher : UCPCoreMod.activePatches) {
if (!patcher.isDone()) {
continue;
Expand Down
52 changes: 26 additions & 26 deletions src/main/java/io/gitlab/dwarfyassassin/lotrucp/core/UCPCoreMod.java
Original file line number Diff line number Diff line change
@@ -1,41 +1,21 @@
package io.gitlab.dwarfyassassin.lotrucp.core;

import java.util.*;

import io.gitlab.dwarfyassassin.lotrucp.core.patches.base.Patcher;
import org.apache.logging.log4j.Logger;

import io.gitlab.dwarfyassassin.lotrucp.core.patches.base.Patcher;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class UCPCoreMod {
public static Logger log;
public static List<Patcher> activePatches;
public static List<Patcher> modPatches;
public static List<Patcher> activePatches = new ArrayList<>();
public static List<Patcher> modPatches = new ArrayList<>();

static {
activePatches = new ArrayList<>();
modPatches = new ArrayList<>();
System.out.println("LOTR-UCP: Found core mod.");
}

public String getAccessTransformerClass() {
return null;
}

public String[] getASMTransformerClass() {
return new String[] { UCPClassTransformer.class.getName() };
}

public String getModContainerClass() {
return null;
}

public String getSetupClass() {
return UCPCoreSetup.class.getName();
}

public void injectData(Map<String, Object> data) {
}

public static void loadModPatches() {
int i = 0;
for (Patcher patcher : modPatches) {
Expand All @@ -56,4 +36,24 @@ public static void registerPatcher(Patcher patcher) {
modPatches.add(patcher);
}
}

public String getAccessTransformerClass() {
return null;
}

public String[] getASMTransformerClass() {
return new String[]{UCPClassTransformer.class.getName()};
}

public String getModContainerClass() {
return null;
}

public String getSetupClass() {
return UCPCoreSetup.class.getName();
}

@SuppressWarnings("all")
public void injectData(Map<String, Object> data) {
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
package io.gitlab.dwarfyassassin.lotrucp.core;

import java.util.Map;

import cpw.mods.fml.relauncher.IFMLCallHook;
import io.gitlab.dwarfyassassin.lotrucp.core.patches.BotaniaPatcher;
import io.gitlab.dwarfyassassin.lotrucp.core.patches.FMLPatcher;
import io.gitlab.dwarfyassassin.lotrucp.core.patches.ScreenshotEnhancedPatcher;
import io.gitlab.dwarfyassassin.lotrucp.core.patches.ThaumcraftPatcher;
import org.apache.logging.log4j.LogManager;

import cpw.mods.fml.relauncher.IFMLCallHook;
import io.gitlab.dwarfyassassin.lotrucp.core.patches.*;
import java.util.Map;

public class UCPCoreSetup implements IFMLCallHook {
@Override
public Void call() throws Exception {
public Void call() {
UCPCoreMod.log = LogManager.getLogger("LOTR-UCP");
UCPCoreMod.registerPatcher(new FMLPatcher());
UCPCoreMod.registerPatcher(new BotaniaPatcher());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
package io.gitlab.dwarfyassassin.lotrucp.core.hooks;

import java.util.*;

import cpw.mods.fml.common.registry.*;
import cpw.mods.fml.common.registry.GameData;
import cpw.mods.fml.common.registry.RegistryDelegate;
import cpw.mods.fml.relauncher.ReflectionHelper;
import net.minecraft.block.Block;
import net.minecraft.item.*;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraftforge.oredict.OreDictionary;

import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Map;

public class GenericModHooks {
public static void removeBlockFromOreDictionary(Block block) {
GenericModHooks.removeItemFromOreDictionary(Item.getItemFromBlock(block));
removeItemFromOreDictionary(Item.getItemFromBlock(block));
}

public static void removeItemFromOreDictionary(Item item) {
Expand All @@ -19,13 +24,13 @@ public static void removeItemFromOreDictionary(Item item) {
}
ItemStack stack = new ItemStack(item, 1, 32767);
int[] oreIDs = OreDictionary.getOreIDs(stack);
List oreIdToStacks = (List) ReflectionHelper.getPrivateValue(OreDictionary.class, null, "idToStack");
List oreIdToStacks = ReflectionHelper.getPrivateValue(OreDictionary.class, null, "idToStack");
for (int oreID : oreIDs) {
ArrayList<ItemStack> oreStacks = (ArrayList) oreIdToStacks.get(oreID);
Collection<ItemStack> oreStacks = (Collection<ItemStack>) oreIdToStacks.get(oreID);
if (oreStacks == null) {
continue;
}
HashSet<ItemStack> toRemove = new HashSet<>();
Collection<ItemStack> toRemove = new HashSet<>();
for (ItemStack oreStack : oreStacks) {
if (oreStack.getItem() != stack.getItem()) {
continue;
Expand All @@ -39,7 +44,7 @@ public static void removeItemFromOreDictionary(Item item) {
return;
}
int stackId = GameData.getItemRegistry().getId(registryName);
Map stackIdToOreId = (Map) ReflectionHelper.getPrivateValue(OreDictionary.class, null, "stackToId");
Map stackIdToOreId = ReflectionHelper.getPrivateValue(OreDictionary.class, null, "stackToId");
stackIdToOreId.remove(stackId);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
package io.gitlab.dwarfyassassin.lotrucp.core.hooks;

import java.lang.reflect.*;
import java.util.*;

import com.mojang.authlib.GameProfile;

import cpw.mods.fml.relauncher.ReflectionHelper;
import io.gitlab.dwarfyassassin.lotrucp.core.UCPCoreMod;
import io.gitlab.dwarfyassassin.lotrucp.server.util.PlayerUtils;
import lotr.common.*;
import lotr.common.LOTRBannerProtection;
import lotr.common.LOTRReflection;
import lotr.common.entity.item.LOTREntityBanner;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.world.World;
import net.minecraftforge.common.util.FakePlayer;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.List;
import java.util.UUID;

public class ThaumcraftHooks {
public static boolean doneReflection = false;
public static boolean doneReflection;
public static Class class_golem;
public static Method method_getOwnerName;

Expand Down Expand Up @@ -64,14 +66,14 @@ public static LOTRBannerProtection.ProtectType thaumcraftGolemBannerProtection(E
e.printStackTrace();
}
if (uuid == null) {
UCPCoreMod.log.error("Was unable to find the player UUID from Thaumcraft EntityGolemBase.getOwnerName - UUID is %s", uuid);
UCPCoreMod.log.error("Was unable to find the player UUID from Thaumcraft EntityGolemBase.getOwnerName - UUID is %s", (Object) null);
return null;
}
try {
LOTRReflection.setFinalField(GameProfile.class, profile, uuid, "id");
ReflectionHelper.setPrivateValue(Entity.class, fakePlayer, (Object) uuid, "entityUniqueID", "field_96093_i");
} catch (Exception e) {
UCPCoreMod.log.error("Was unable to set a FakeThaumcraftGolem player uuid to " + uuid.toString());
UCPCoreMod.log.error("Was unable to set a FakeThaumcraftGolem player uuid to " + uuid);
e.printStackTrace();
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
package io.gitlab.dwarfyassassin.lotrucp.core.patches;

import org.objectweb.asm.tree.*;

import io.gitlab.dwarfyassassin.lotrucp.core.UCPCoreMod;
import io.gitlab.dwarfyassassin.lotrucp.core.patches.base.*;
import io.gitlab.dwarfyassassin.lotrucp.core.patches.base.ModPatcher;
import io.gitlab.dwarfyassassin.lotrucp.core.utils.ASMUtils;
import org.objectweb.asm.tree.AbstractInsnNode;
import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.MethodNode;
import org.objectweb.asm.tree.TypeInsnNode;

public class BotaniaPatcher extends ModPatcher {
public BotaniaPatcher() {
super("Botania", "Botania");
classes.put("vazkii.botania.common.block.subtile.generating.SubTileKekimurus", new Patcher.ConsumerImplBecauseNoLambdas<ClassNode>() {

@Override
public void accept(ClassNode node) {
BotaniaPatcher.this.patchKekimurus(node);
}
});
classes.put("vazkii.botania.common.block.subtile.generating.SubTileKekimurus", this::patchKekimurus);
}

public void patchKekimurus(ClassNode classNode) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
package io.gitlab.dwarfyassassin.lotrucp.core.patches;

import org.objectweb.asm.tree.*;

import io.gitlab.dwarfyassassin.lotrucp.core.UCPCoreMod;
import io.gitlab.dwarfyassassin.lotrucp.core.patches.base.Patcher;
import io.gitlab.dwarfyassassin.lotrucp.core.utils.ASMUtils;
import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.MethodInsnNode;
import org.objectweb.asm.tree.MethodNode;

public class FMLPatcher extends Patcher {
public FMLPatcher() {
super("FML");
classes.put("cpw.mods.fml.common.LoadController", new Patcher.ConsumerImplBecauseNoLambdas<ClassNode>() {

@Override
public void accept(ClassNode node) {
FMLPatcher.this.patchLoadController(node);
}
});
classes.put("cpw.mods.fml.common.LoadController", this::patchLoadController);
}

public void patchLoadController(ClassNode classNode) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,15 @@
package io.gitlab.dwarfyassassin.lotrucp.core.patches;

import org.objectweb.asm.tree.*;

import io.gitlab.dwarfyassassin.lotrucp.core.UCPCoreMod;
import io.gitlab.dwarfyassassin.lotrucp.core.patches.base.*;
import io.gitlab.dwarfyassassin.lotrucp.core.patches.base.ModPatcher;
import io.gitlab.dwarfyassassin.lotrucp.core.utils.ASMUtils;
import net.minecraftforge.classloading.FMLForgePlugin;
import org.objectweb.asm.tree.*;

public class ScreenshotEnhancedPatcher extends ModPatcher {
public ScreenshotEnhancedPatcher() {
super("Screenshots Enhanced", "screenshots");
classes.put("lotr.client.render.entity.LOTRRenderScrapTrader", new Patcher.ConsumerImplBecauseNoLambdas<ClassNode>() {

@Override
public void accept(ClassNode node) {
ScreenshotEnhancedPatcher.this.patchScrapTraderRender(node);
}
});
classes.put("lotr.client.render.entity.LOTRRenderScrapTrader", this::patchScrapTraderRender);
}

public void patchScrapTraderRender(ClassNode classNode) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
public abstract class ModPatcher extends Patcher {
public String modID;

public ModPatcher(String name, String modID) {
protected ModPatcher(String name, String modID) {
super(name);
this.modID = modID;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package io.gitlab.dwarfyassassin.lotrucp.core.patches.base;

import java.util.*;

import org.objectweb.asm.tree.ClassNode;

import java.util.HashMap;
import java.util.Map;

public abstract class Patcher {
public Map<String, ConsumerImplBecauseNoLambdas<ClassNode>> classes = new HashMap<>();
public String patcherName;

public Patcher(String name) {
protected Patcher(String name) {
patcherName = name;
}

Expand Down Expand Up @@ -37,13 +38,13 @@ public boolean shouldInit() {
return true;
}

public interface ConsumerImplBecauseNoLambdas<T> {
void accept(T var1);
}

public enum LoadingPhase {
CORE_MOD_LOADING, FORGE_MOD_LOADING;
CORE_MOD_LOADING, FORGE_MOD_LOADING

}

public interface ConsumerImplBecauseNoLambdas<T> {
void accept(T var1);
}

}
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package io.gitlab.dwarfyassassin.lotrucp.core.utils;

import org.objectweb.asm.tree.*;

import io.gitlab.dwarfyassassin.lotrucp.core.UCPCoreMod;
import net.minecraftforge.classloading.FMLForgePlugin;
import org.objectweb.asm.tree.AbstractInsnNode;
import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.InsnList;
import org.objectweb.asm.tree.MethodNode;

public class ASMUtils {
public static MethodNode findMethod(ClassNode classNode, String targetMethodName, String targetMethodDesc) {
Expand All @@ -18,7 +20,7 @@ public static MethodNode findMethod(ClassNode classNode, String targetMethodName
}

public static MethodNode findMethod(ClassNode classNode, String targetMethodName, String obfTargetMethodName, String targetMethodDesc) {
return ASMUtils.findMethod(classNode, FMLForgePlugin.RUNTIME_DEOBF ? obfTargetMethodName : targetMethodName, targetMethodDesc);
return findMethod(classNode, FMLForgePlugin.RUNTIME_DEOBF ? obfTargetMethodName : targetMethodName, targetMethodDesc);
}

public static void removePreviousNodes(InsnList list, AbstractInsnNode start, int amount) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package io.gitlab.dwarfyassassin.lotrucp.server.util;

import java.util.*;

import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.server.MinecraftServer;
import net.minecraftforge.common.UsernameCache;

import java.util.Map;
import java.util.UUID;

public class PlayerUtils {
public static UUID getLastKownUUIDFromUsername(String username) {
EntityPlayerMP player = MinecraftServer.getServer().getConfigurationManager().func_152612_a(username);
Expand Down
Loading

0 comments on commit 9cac9c9

Please sign in to comment.