Last active
December 18, 2020 22:08
-
-
Save TheCurle/ba95a27c76d69d707d3418c5fdbb2587 to your computer and use it in GitHub Desktop.
RetroGradle scripts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
############### | |
# RETROGRADLE # | |
# BY CURLE # | |
# 2020 # | |
############### | |
# This file allows you to split an MCP joined.exc file up to the MCPConfig files | |
# constructors.txt, access.txt and exceptions.txt. | |
# Part seven of eight in the RetroGradle series. | |
import re | |
ctrRegStr = "(\.<init>)(\(\S*)(=\S*\|p_i)(\d*)" | |
exceptionRegStr = "(\(\S*\)\S*)=(\S*)\|" | |
accessRegStr = "(\S*)\.(\S*)(\(\S*\)\S*)-Access=(\S*)" | |
def main(): | |
print("Converting exc to MCPConfig Data:") | |
ctrReg = re.compile(ctrRegStr) | |
exceptionReg = re.compile(exceptionRegStr) | |
accessReg = re.compile(accessRegStr) | |
try: | |
excFile = open("joined.exc", "r") | |
constructorsFile = open("constructors.txt", "w") | |
exceptionsFile = open("exceptions.txt", "w") | |
accessFile = open("access.txt", "w") | |
excLines = excFile.readlines() | |
print("There are " + str(len(excLines)) + " lines of exc") | |
lineNo = 0 | |
constructorLines = [] | |
exceptionsLines = [] | |
accessLines = [] | |
for excLine in excLines: | |
lineType = 0 | |
lineNo += 1 | |
constructorLine = [] | |
exceptionsLine = [] | |
accessLine = [] | |
constructorMatches = re.search(ctrReg, excLine) | |
exceptionsMatches = re.search(exceptionReg, excLine) | |
accessMatches = re.search(accessReg, excLine) | |
# If we match ".<init>" we're a constructor. | |
if isinstance(constructorMatches, re.Match): | |
# constructors.txt lines are in the form | |
# SRG CLASS SIGNATURE | |
# Matches are in the order | |
# .<init> SIGNATURE =|p_i SRG | |
# CLASS is line[0]..match0 | |
constructorLine.append(constructorMatches[4]) | |
className = excLine[0:constructorMatches.start(0)] | |
#print("Processing constructor of class " + className) | |
constructorLine.append(className) | |
constructorLine.append(constructorMatches[2]) | |
constructorLineString = " ".join(constructorLine) | |
constructorLines.append(constructorLineString) | |
lineType = 1 | |
# if we match (SOMETHING)SOMETHING=SOMETHING|, we're an exception line | |
if isinstance(exceptionsMatches, re.Match): | |
# exceptions.txt is in the form | |
# CLASS/FUNCTION (PARAMS)RETURN EXCEPTION | |
# Matches are in the order | |
# (PARAMS)RETURN = EXCEPTION | | |
matches = exceptionsMatches.groups() | |
className = excLine[0:exceptionsMatches.start(0)].replace(".", "/") | |
#print("Processing exception of class " + className + ": " + str(matches)) | |
exceptionsLine.append(className) | |
exceptionsLine.append(matches[0]) | |
exceptionsLine.append(matches[1]) | |
exceptionsLineStr = " ".join(exceptionsLine) | |
exceptionsLines.append(exceptionsLineStr) | |
lineType = 2 | |
if isinstance(accessMatches, re.Match): | |
# access.txt is in the form | |
# ACCESS CLASS OBJECT SIGNATURE | |
# accessMatches is in the form | |
# CLASS OBJECT SIGNATURE ACCESS | |
matches = accessMatches.groups() | |
print("Handling access modifier for " + matches[1] + " to " + matches[3]) | |
accessLine.append(matches[3]) | |
accessLine.append(matches[0]) | |
accessLine.append(matches[1]) | |
accessLine.append(matches[2]) | |
accessLineStr = " ".join(accessLine) | |
accessLines.append(accessLineStr) | |
lineType = 3 | |
if lineType == 0: | |
print("No useful data on line " + str(lineNo)) | |
continue | |
constructorLines.sort() | |
constructorsFile.write("\n".join(constructorLines)) | |
exceptionsLines.sort() | |
exceptionsFile.write("\n".join(exceptionsLines)) | |
accessLines.sort() | |
accessFile.write("\n".join(accessLines)) | |
finally: | |
excFile.close() | |
constructorsFile.close() | |
accessFile.close() | |
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
############### | |
# RETROGRADLE # | |
# BY CURLE # | |
# 2020 # | |
############### | |
# This file allows you to convert MCP patches to MCPConfig patches. | |
# This does not expand the name of the file to the folder structure. | |
# Part one of eight in the RetroGradle series. | |
import os | |
def getListOfFiles(dirName): | |
# create a list of file and sub directories | |
# names in the given directory | |
listOfFile = os.listdir(dirName) | |
allFiles = list() | |
# Iterate over all the entries | |
for entry in listOfFile: | |
# Create full path | |
fullPath = os.path.join(dirName, entry) | |
# If entry is a directory then get the list of files in this directory | |
if os.path.isdir(fullPath): | |
allFiles = allFiles + getListOfFiles(fullPath) | |
else: | |
allFiles.append(fullPath) | |
return allFiles | |
cwd = os.getcwd() | |
files = getListOfFiles(cwd) | |
for file in files: | |
lines = [] | |
with open(file, "r+") as wfile: | |
if file[-1] == 'h': # dirty dirty hack to make sure we're only modifying .java.patc>h< files | |
lines = wfile.readlines() | |
if lines[0].startswith('diff'): | |
print(lines.pop(0) + " removed.") | |
# Lines 1 and 2 use the form: | |
# --- a\net\minecraft\command\CommandSpreadPlayers.java | |
# +++ b\net\minecraft\command\CommandSpreadPlayers.java | |
# We need the separators to be / , for cross-compatibility. | |
lines[0] = lines[0].replace("\\", '/') | |
lines[1] = lines[1].replace("\\", '/') | |
# MCP Patches use the form: | |
# --- minecraft\net\minecraft\command\CommandSpreadPlayers.java | |
# +++ minecraft_patched\net\minecraft\command\CommandSpreadPlayers.java | |
# We need to replace the minecraft, minecraft_patched | |
# with the format a, b seen above. | |
# | |
# Unfortunately, it's not as simple as just swapping out the text, | |
# as there is also: | |
# --- minecraft_server\net\minecraft\command\CommandSpreadPlayers.java | |
# +++ minecraft_server_patched\net\minecraft\command\CommandSpreadPlayers.java | |
# So, we need to look for "minecraft/" (so that minecraft_patched doesn't match) | |
# etc etc. | |
if "minecraft_server/" in lines[0]: | |
print("Replacing server headers..") | |
# if the first line contains "minecraft_server" then | |
# the second line must contain "minecraft_server_patched". | |
lines[0] = lines[0].replace("minecraft_server/", "a/", 1) | |
lines[1] = lines[1].replace("minecraft_server_patched/", "b/", 1) | |
# These two checks must be mutually exclusive, else | |
# minecraft_server/net/>minecraft/< will match | |
elif "minecraft/" in lines[0]: | |
print("Replacing client/joined headers..") | |
# likewise, if the first line contains "minecraft/" then the second line must contain | |
# "minecraft_patched", so we take care of them both here. | |
lines[0] = lines[0].replace("minecraft/", "a/", 1) | |
lines[1] = lines[1].replace("minecraft_patched/", "b/", 1) | |
with open(file, "w") as wfile: | |
wfile.write(''.join(lines)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment