Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- import re
- filename = "client"
- data = open(filename + ".txt").read() #Or server.txt
- lines = data.splitlines()
- current_line, counter, deobf2obf = 0, 0, {}
- out = ""
- def to_signature(ref):
- # Primitives
- if ref == "boolean":
- return "Z"
- if ref == "byte":
- return "B"
- if ref == "char":
- return "C"
- if ref == "short":
- return "S"
- if ref == "int":
- return "I"
- if ref == "long":
- return "J"
- if ref == "float":
- return "F"
- if ref == "double":
- return "D"
- if ref == "void":
- return "V"
- # Arrays
- if ref.endswith("[]"):
- return "[" + to_signature(ref[0:-2])
- # Mapped Classes
- if ref in deobf2obf:
- return "L" + deobf2obf[ref] + ";"
- # Shouldn't happen, but this can occur if something went wrong during the building of the classname map
- if ref.startswith("net.minecraft"):
- raise Exception("Don't know how to handle " + ref)
- # Classes
- return "L" + ref.replace(".", "/") + ";"
- def build_classname_map():
- for found in re.findall(r'(.+) -> (.+):', data):
- deobf2obf[found[0]] = found[1]
- def convert_class_name():
- global out, counter
- line = next_line()
- result = re.search(r'(.+) -> (.+):', line)
- out += result.group(2).replace(".", "/") + " " + result.group(1).replace(".", "/") + "\n"
- while current_line < len(lines) and lines[current_line].startswith(" "):
- line = next_line()
- method_search = re.search(r'\s*(?:\d+:\d+:)?(.+?)\s(.+)\((.*?)\) -> (.+)', line)
- if method_search is not None:
- if method_search.group(4) in ["<init>", "<clinit>"]:
- continue
- out += " " + method_search.group(4) + " ("
- if method_search.group(3) != "":
- for param in method_search.group(3).split(r","):
- out += to_signature(param)
- out += ")" + to_signature(method_search.group(1)) + " " + method_search.group(2) + "\n"
- continue
- field_search = re.search(r'\s*(.+?)\s(.+?) -> (.+)', line)
- if field_search is not None:
- out += " " + field_search.group(3) + " " + field_search.group(2) + "\n"
- counter += 1
- print("Done " + str(round(counter / len(deobf2obf) * 10000) / 100) + "% : " + str(result.group(1)))
- def next_line():
- global current_line
- line = lines[current_line]
- current_line += 1
- if line.startswith("#") or line == "":
- return next_line()
- return line
- print("Setting up Classname map")
- build_classname_map()
- print("Classname map built! Started conversion.")
- while current_line < len(lines):
- convert_class_name()
- outFile = open(filename + ".tsrg", "w")
- outFile.write(out)
- outFile.close()
- print("Written to " + os.path.abspath(filename + ".tsrg"))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement