Fix some broken stuff

This commit is contained in:
Dazed 2023-10-12 10:51:47 -05:00
parent 5615071dd0
commit c241a521ba
6 changed files with 168 additions and 59 deletions

View file

@ -265,8 +265,17 @@ def subVars(jaString):
jaString = jaString.replace(var, '<V' + str(count) + '>')
count += 1
# Formatting
count = 0
formatList = re.findall(r'[\\]+[!.]', jaString)
formatList = set(formatList)
if len(formatList) != 0:
for format in formatList:
jaString = jaString.replace(format, '<F' + str(count) + '>')
count += 1
# Put all lists in list and return
allList = [iconList, colorList, nameList, varList]
allList = [iconList, colorList, nameList, varList, formatList]
return [jaString, allList]
def resubVars(translatedText, allList):
@ -293,23 +302,24 @@ def resubVars(translatedText, allList):
# Names
count = 0
if len(allList[1]) != 0:
if len(allList[2]) != 0:
for var in allList[2]:
translatedText = translatedText.replace('<N' + str(count) + '>', var)
count += 1
# Vars
count = 0
if len(allList[1]) != 0:
if len(allList[3]) != 0:
for var in allList[3]:
translatedText = translatedText.replace('<V' + str(count) + '>', var)
count += 1
# Remove Color Variables Spaces
# if '\\c' in translatedText:
# translatedText = re.sub(r'\s*(\\+c\[[1-9]+\])\s*', r' \1', translatedText)
# translatedText = re.sub(r'\s*(\\+c\[0+\])', r'\1', translatedText)
return translatedText
# Formatting
count = 0
if len(allList[4]) != 0:
for var in allList[4]:
translatedText = translatedText.replace('<F' + str(count) + '>', var)
count += 1
@retry(exceptions=Exception, tries=5, delay=5)
def translateGPT(t, history, fullPromptFlag):

View file

@ -197,8 +197,17 @@ def subVars(jaString):
jaString = jaString.replace(var, '<V' + str(count) + '>')
count += 1
# Formatting
count = 0
formatList = re.findall(r'[\\]+[!.]', jaString)
formatList = set(formatList)
if len(formatList) != 0:
for format in formatList:
jaString = jaString.replace(format, '<F' + str(count) + '>')
count += 1
# Put all lists in list and return
allList = [iconList, colorList, nameList, varList]
allList = [iconList, colorList, nameList, varList, formatList]
return [jaString, allList]
def resubVars(translatedText, allList):
@ -225,17 +234,24 @@ def resubVars(translatedText, allList):
# Names
count = 0
if len(allList[1]) != 0:
if len(allList[2]) != 0:
for var in allList[2]:
translatedText = translatedText.replace('<N' + str(count) + '>', var)
count += 1
# Vars
count = 0
if len(allList[1]) != 0:
if len(allList[3]) != 0:
for var in allList[3]:
translatedText = translatedText.replace('<V' + str(count) + '>', var)
count += 1
# Formatting
count = 0
if len(allList[4]) != 0:
for var in allList[4]:
translatedText = translatedText.replace('<F' + str(count) + '>', var)
count += 1
# Remove Color Variables Spaces
# if '\\c' in translatedText:

View file

@ -530,7 +530,11 @@ def searchCodes(page, pbar):
# If there isn't any Japanese in the text just skip
if IGNORETLTEXT == True:
if not re.search(r'[一-龠]+|[ぁ-ゔ]+|[ァ-ヴー]+', jaString):
# Keep textHistory list at length maxHistory
textHistory.append('\"' + jaString + '\"')
if len(textHistory) > maxHistory:
textHistory.pop(0)
currentGroup = []
continue
# Using this to keep track of 401's in a row. Throws IndexError at EndOfList (Expected Behavior)
@ -1371,8 +1375,17 @@ def subVars(jaString):
jaString = jaString.replace(var, '<V' + str(count) + '>')
count += 1
# Formatting
count = 0
formatList = re.findall(r'[\\]+[!.]', jaString)
formatList = set(formatList)
if len(formatList) != 0:
for format in formatList:
jaString = jaString.replace(format, '<F' + str(count) + '>')
count += 1
# Put all lists in list and return
allList = [iconList, colorList, nameList, varList]
allList = [iconList, colorList, nameList, varList, formatList]
return [jaString, allList]
def resubVars(translatedText, allList):
@ -1399,18 +1412,25 @@ def resubVars(translatedText, allList):
# Names
count = 0
if len(allList[1]) != 0:
if len(allList[2]) != 0:
for var in allList[2]:
translatedText = translatedText.replace('<N' + str(count) + '>', var)
count += 1
# Vars
count = 0
if len(allList[1]) != 0:
if len(allList[3]) != 0:
for var in allList[3]:
translatedText = translatedText.replace('<V' + str(count) + '>', var)
count += 1
# Formatting
count = 0
if len(allList[4]) != 0:
for var in allList[4]:
translatedText = translatedText.replace('<F' + str(count) + '>', var)
count += 1
# Remove Color Variables Spaces
# if '\\c' in translatedText:
# translatedText = re.sub(r'\s*(\\+c\[[1-9]+\])\s*', r' \1', translatedText)

View file

@ -43,11 +43,11 @@ CODE401 = True
CODE405 = False
CODE102 = True
CODE122 = False
CODE101 = True
CODE101 = False
CODE355655 = False
CODE357 = False
CODE657 = False
CODE356 = False
CODE356 = True
CODE320 = False
CODE324 = False
CODE111 = False
@ -56,6 +56,7 @@ CODE108 = False
NAMES = False # Output a list of all the character names found
BRFLAG = False # If the game uses <br> instead
FIXTEXTWRAP = True
IGNORETLTEXT = False
def handleMVMZ(filename, estimate):
global ESTIMATE, TOKENS, TOTALTOKENS, TOTALCOST
@ -504,6 +505,8 @@ def searchCodes(page, pbar):
if syncIndex > i:
i = syncIndex
pbar.update(1)
if len(codeList) <= i:
break
### All the codes are here which translate specific functions in the MAP files.
### IF these crash or fail your game will do the same. Use the flags to skip codes.
@ -518,6 +521,16 @@ def searchCodes(page, pbar):
jaString = codeList[i]['parameters'][0]
firstJAString = jaString
# If there isn't any Japanese in the text just skip
if IGNORETLTEXT == True:
if not re.search(r'[一-龠]+|[ぁ-ゔ]+|[ァ-ヴー]+', jaString):
# Keep textHistory list at length maxHistory
textHistory.append('\"' + jaString + '\"')
if len(textHistory) > maxHistory:
textHistory.pop(0)
currentGroup = []
continue
# Using this to keep track of 401's in a row. Throws IndexError at EndOfList (Expected Behavior)
currentGroup.append(jaString)
@ -530,6 +543,10 @@ def searchCodes(page, pbar):
jaString = codeList[i]['parameters'][0]
currentGroup.append(jaString)
# Make sure not the end of the list.
if len(codeList) <= i+1:
break
# Join up 401 groups for better translation.
if len(currentGroup) > 0:
finalJAString = ''.join(currentGroup)
@ -676,11 +693,20 @@ def searchCodes(page, pbar):
finalJAString = finalJAString.replace(ffMatchList[0], '')
nametag += ffMatchList[0]
# Remove \\r codes (Display furigana instead of kanji)
### Remove format codes
# Furigana
rcodeMatch = re.findall(r'([\\]+r\[(.+?),.+?\])', finalJAString)
if len(rcodeMatch) > 0:
for match in rcodeMatch:
finalJAString = finalJAString.replace(match[0],match[1])
# # Formatting Codes
if finalJAString == 'あ、\\!あんな風に、おちんちん入ってるんだ...':
print('t')
formatMatch = re.findall(r'[\\]+[!><.]', finalJAString)
if len(formatMatch) > 0:
for match in formatMatch:
finalJAString = finalJAString.replace(match, '')
# Translate
if speaker == '' and finalJAString != '':
@ -1039,6 +1065,21 @@ def searchCodes(page, pbar):
jaString = codeList[i]['parameters'][0]
oldjaString = jaString
# Grab Speaker
if 'Tachie showName' in jaString:
matchList = re.findall(r'Tachie showName (.+)', jaString)
if len(matchList) > 0:
# Translate
response = translateGPT(matchList[0], 'Reply with the English translation of the NPC name.', True)
translatedText = response[0]
tokens += response[1]
# Set Text
speaker = translatedText
speaker = speaker.replace(' ', ' ')
codeList[i]['parameters'][0] = jaString.replace(matchList[0], speaker)
continue
# If there isn't any Japanese in the text just skip
if not re.search(r'[一-龠]+|[ぁ-ゔ]+|[ァ-ヴー]+', jaString):
continue
@ -1208,6 +1249,8 @@ def searchCodes(page, pbar):
except IndexError as e:
# This is part of the logic so we just pass it
traceback.print_exc()
print(len(codeList))
print(i+1)
# raise Exception(str(e) + '|Line:' + tracebackLineNo)
except Exception as e:
traceback.print_exc()
@ -1446,14 +1489,14 @@ def resubVars(translatedText, allList):
# Names
count = 0
if len(allList[1]) != 0:
if len(allList[2]) != 0:
for var in allList[2]:
translatedText = translatedText.replace('<N' + str(count) + '>', var)
count += 1
# Vars
count = 0
if len(allList[1]) != 0:
if len(allList[3]) != 0:
for var in allList[3]:
translatedText = translatedText.replace('<V' + str(count) + '>', var)
count += 1
@ -1481,7 +1524,7 @@ def translateGPT(t, history, fullPromptFlag):
return(t, 0)
"""Translate text using GPT"""
context = 'Eroge Names Context: Name: なつ == Natsu\nGender: Male,\nName: 琴花 == Kotohana\nGender: Female,\nName: 葵 == Aoi\nGender: Female,\nName: 美咲 == Misaki\nGender: Female,\nName: 小梅 == Koume\nGender: Female,\nName: 千歳 == Chitose\nGender: Female\n'
context = 'Eroge Names Context: Name: セレナ == Selena\nGender: Female,\nName: リン == Rin\nGender: Female,\nName: ロナ == Rona\nGender: Female,\nName: ソフィア == Sophia\nGender: Female,\nName: ジュリア == Julia\nGender: Female,\nName: グルカ == Guruka\nGender: Male,\nName: シン == Shin\nGender: Male'
if fullPromptFlag:
system = PROMPT
user = 'Line to Translate: ' + subbedT
@ -1518,6 +1561,7 @@ def translateGPT(t, history, fullPromptFlag):
translatedText = translatedText.replace('Line to Translate:', '')
translatedText = re.sub(r'\n\nPast Translated Text:.*', '', translatedText, 0, re.DOTALL)
translatedText = re.sub(r'Note:.*', '', translatedText)
translatedText = translatedText.replace('', '')
# Return Translation
if len(translatedText) > 15 * len(t) or "I'm sorry, but I'm unable to assist with that translation" in translatedText:

View file

@ -245,8 +245,17 @@ def subVars(jaString):
jaString = jaString.replace(var, '<V' + str(count) + '>')
count += 1
# Formatting
count = 0
formatList = re.findall(r'[\\]+[!.]', jaString)
formatList = set(formatList)
if len(formatList) != 0:
for format in formatList:
jaString = jaString.replace(format, '<F' + str(count) + '>')
count += 1
# Put all lists in list and return
allList = [iconList, colorList, nameList, varList]
allList = [iconList, colorList, nameList, varList, formatList]
return [jaString, allList]
def resubVars(translatedText, allList):
@ -273,23 +282,24 @@ def resubVars(translatedText, allList):
# Names
count = 0
if len(allList[1]) != 0:
if len(allList[2]) != 0:
for var in allList[2]:
translatedText = translatedText.replace('<N' + str(count) + '>', var)
count += 1
# Vars
count = 0
if len(allList[1]) != 0:
if len(allList[3]) != 0:
for var in allList[3]:
translatedText = translatedText.replace('<V' + str(count) + '>', var)
count += 1
# Remove Color Variables Spaces
# if '\\c' in translatedText:
# translatedText = re.sub(r'\s*(\\+c\[[1-9]+\])\s*', r' \1', translatedText)
# translatedText = re.sub(r'\s*(\\+c\[0+\])', r'\1', translatedText)
return translatedText
# Formatting
count = 0
if len(allList[4]) != 0:
for var in allList[4]:
translatedText = translatedText.replace('<F' + str(count) + '>', var)
count += 1
@retry(exceptions=Exception, tries=5, delay=5)
def translateGPT(t, history, fullPromptFlag):

View file

@ -298,52 +298,61 @@ def subVars(jaString):
jaString = jaString.replace(var, '<V' + str(count) + '>')
count += 1
# Formatting
count = 0
formatList = re.findall(r'[\\]+[!.]', jaString)
formatList = set(formatList)
if len(formatList) != 0:
for format in formatList:
jaString = jaString.replace(format, '<F' + str(count) + '>')
count += 1
# Put all lists in list and return
allList = [iconList, colorList, nameList, varList]
allList = [iconList, colorList, nameList, varList, formatList]
return [jaString, allList]
def subVars(jaString):
jaString = jaString.replace('\u3000', ' ')
def resubVars(translatedText, allList):
# Fix Spacing and ChatGPT Nonsense
matchList = re.findall(r'<\s?.+?\s?>', translatedText)
if len(matchList) > 0:
for match in matchList:
text = match.replace(' ', '')
translatedText = translatedText.replace(match, text)
# Icons
count = 0
iconList = re.findall(r'[\\]+[iI]\[[0-9]+\]', jaString)
iconList = set(iconList)
if len(iconList) != 0:
for icon in iconList:
jaString = jaString.replace(icon, '<I' + str(count) + '>')
if len(allList[0]) != 0:
for var in allList[0]:
translatedText = translatedText.replace('<I' + str(count) + '>', var)
count += 1
# Colors
count = 0
colorList = re.findall(r'[\\]+[cC]\[[0-9]+\]', jaString)
colorList = set(colorList)
if len(colorList) != 0:
for color in colorList:
jaString = jaString.replace(color, '<C' + str(count) + '>')
if len(allList[1]) != 0:
for var in allList[1]:
translatedText = translatedText.replace('<C' + str(count) + '>', var)
count += 1
# Names
count = 0
nameList = re.findall(r'[\\]+[nN]\[[0-9]+\]', jaString)
nameList = set(nameList)
if len(nameList) != 0:
for name in nameList:
jaString = jaString.replace(name, '<N' + str(count) + '>')
if len(allList[2]) != 0:
for var in allList[2]:
translatedText = translatedText.replace('<N' + str(count) + '>', var)
count += 1
# Variables
# Vars
count = 0
varList = re.findall(r'[\\]+[vV]\[[0-9]+\]', jaString)
varList = set(varList)
if len(varList) != 0:
for var in varList:
jaString = jaString.replace(var, '<V' + str(count) + '>')
if len(allList[3]) != 0:
for var in allList[3]:
translatedText = translatedText.replace('<V' + str(count) + '>', var)
count += 1
# Formatting
count = 0
if len(allList[4]) != 0:
for var in allList[4]:
translatedText = translatedText.replace('<F' + str(count) + '>', var)
count += 1
# Put all lists in list and return
allList = [iconList, colorList, nameList, varList]
return [jaString, allList]
@retry(exceptions=Exception, tries=5, delay=5)
def translateGPT(t, history, fullPromptFlag):