Skip to content

Commit

Permalink
1.2.14 fix and change
Browse files Browse the repository at this point in the history
  • Loading branch information
3093FengMing committed Jul 30, 2023
1 parent 1897265 commit d247ff1
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 51 deletions.
35 changes: 9 additions & 26 deletions src/main/java/me/fengming/vaultpatcher_asm/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,42 +28,25 @@ public static List<ITransformer.Target> addTargetClasses() {
VaultPatcherConfig.getClasses().forEach(s -> list.add(ITransformer.Target.targetClass(s.replace(".", "/"))));
for (VaultPatcherPatch vpp : vpps) {
for (TranslationInfo translationInfo : vpp.getTranslationInfoList()) {
String name = translationInfo.getTargetClassInfo().getName();
if (name.isEmpty()) continue;
list.add(ITransformer.Target.targetClass(translationInfo.getTargetClassInfo().getName().replace(".", "/")));
}
}
return list;
}

public static List<String> getClassNameByJar(String jarPath, boolean childPackage) {
public static List<String> getClassNameByJar(String jarPath) {
List<String> retClassName = new ArrayList<>();
String[] jarInfo = jarPath.split("!");
String jarFilePath = jarInfo[0].substring(jarInfo[0].indexOf("/"));
String packagePath = jarInfo[1].substring(1);
try {
JarFile jarFile = new JarFile(jarFilePath);
JarFile jarFile = new JarFile(jarPath);
Enumeration<JarEntry> entrys = jarFile.entries();
while (entrys.hasMoreElements()) {
JarEntry jarEntry = entrys.nextElement();
String entryName = jarEntry.getName();
if (entryName.endsWith(".class")) {
if (childPackage) {
if (entryName.startsWith(packagePath)) {
entryName = entryName.replace("/", ".").substring(0, entryName.lastIndexOf("."));
retClassName.add(entryName);
}
} else {
int index = entryName.lastIndexOf("/");
String myPackagePath;
if (index != -1) {
myPackagePath = entryName.substring(0, index);
} else {
myPackagePath = entryName;
}
if (myPackagePath.equals(packagePath)) {
entryName = entryName.replace("/", ".").substring(0, entryName.lastIndexOf("."));
retClassName.add(entryName);
}
}
JarEntry entry = entrys.nextElement();
String name = entry.getName();
if (name.isEmpty()) continue;
if (name.endsWith(".class")) {
retClassName.add(name);
}
}
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,9 @@ public void readJson(JsonReader reader) throws IOException {
reader.beginObject();
while (reader.peek() != JsonToken.END_OBJECT) {
switch (reader.nextName()) {
case "name":
setName(reader.nextString());
break;
case "method":
setMethod(reader.nextString());
break;
default:
reader.skipValue();
break;
case "name" -> setName(reader.nextString());
case "method" -> setMethod(reader.nextString());
default -> reader.skipValue();
}
}
reader.endObject();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,28 +84,27 @@ public static void readConfig(Path path) throws IOException {
jr.beginObject();
while (jr.peek() != JsonToken.END_OBJECT) {
switch (jr.nextName()) {
case "debug_mode":
case "debug_mode" -> {
if (jr.peek() == JsonToken.BEGIN_OBJECT) {
debug.readJson(jr);
}
break;
case "mods":
}
case "mods" -> {
if (jr.peek() == JsonToken.BEGIN_ARRAY) {
mods = GSON.fromJson(jr, new TypeToken<List<String>>(){}.getType());
mods = GSON.fromJson(jr, new TypeToken<List<String>>() {}.getType());
}
break;
case "classes":
}
case "classes" -> {
if (jr.peek() == JsonToken.BEGIN_ARRAY) {
classes = GSON.fromJson(jr, new TypeToken<List<String>>(){}.getType());
classes = GSON.fromJson(jr, new TypeToken<List<String>>() {}.getType());
}
break;
case "apply_mods":
}
case "apply_mods" -> {
if (jr.peek() == JsonToken.BEGIN_ARRAY) {
applyMods = GSON.fromJson(jr, new TypeToken<List<String>>(){}.getType());
applyMods = GSON.fromJson(jr, new TypeToken<List<String>>() {}.getType());
}
default:
jr.skipValue();
break;
}
default -> jr.skipValue();
}
}
jr.endObject();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ public void read(JsonReader reader) throws IOException {

PatchInfo patchInfo = new PatchInfo();
patchInfo.readJson(reader);
VaultPatcher.LOGGER.warn("[VaultPatcher] Loading {}!", patchInfo.getName());
VaultPatcher.LOGGER.warn("[VaultPatcher] About Information:\nAuthor(s): {}\nApply to Mod(s): {}\nDescription: {}", patchInfo.getAuthors(), patchInfo.getMods(), patchInfo.getDesc());
VaultPatcher.LOGGER.info("[VaultPatcher] Loading {}!", patchInfo.getName());
VaultPatcher.LOGGER.info("[VaultPatcher] About Information:\nAuthor(s): {}\nApply to Mod(s): {}\nDescription: {}", patchInfo.getAuthors(), patchInfo.getMods(), patchInfo.getDesc());

Map<String, List<TranslationInfo>> m = new HashMap<>();
while (reader.peek() != JsonToken.END_ARRAY) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ private static void fieldReplace(ClassNode input, TranslationInfo info, DebugMod
Set<Target> targetModClasses = new HashSet<>();
List<String> targetMods = VaultPatcherConfig.getApplyMods();
for (String targetMod : targetMods) {
List<String> classes = Utils.getClassNameByJar(Utils.mcPath.resolve("mods").resolve(targetMod + ".jar").toString(), true);
List<String> classes = Utils.getClassNameByJar(Utils.mcPath.resolve("mods").resolve(targetMod + ".jar").toString());
classes.forEach((s) -> targetModClasses.add(Target.targetClass(s)));
}
HashSet<Target> targets = new HashSet<>();
Expand Down

0 comments on commit d247ff1

Please sign in to comment.