Skip to content

Commit

Permalink
<feature> improve unpack function, add options and fix stuck problem …
Browse files Browse the repository at this point in the history
…due to path

update version to v2.3.4
  • Loading branch information
anonymousException committed Jun 4, 2024
1 parent a1c11f2 commit c1c8b3b
Show file tree
Hide file tree
Showing 63 changed files with 7,154 additions and 639 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/Nuitak-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ jobs:
- run: xcopy src\qm dist\windows\qm\
- run: xcopy src\custom_engine dist\windows\custom_engine\
- run: copy src\custom.txt dist\windows\custom.txt
- run: copy src\UnRen-forall.bat dist\windows\UnRen-forall.bat
- run: copy src\hook_unrpa.rpy dist\windows\hook_unrpa.rpy
- run: copy src\expand.exe dist\windows\expand.exe
- run: copy src\openai_model.txt dist\windows\openai_model.txt
- run: copy src\hook_extract.rpy dist\windows\hook_extract.rpy
- run: copy src\hook_add_change_language_entrance.rpy dist\windows\hook_add_change_language_entrance.rpy
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/Pyinstaller-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ jobs:
- run: cp -r src/supported_language src/dist/windows/main
- run: cp -r src/qm src/dist/windows/main
- run: cp src/custom.txt src/dist/windows/main/custom.txt
- run: cp src/UnRen-forall.bat src/dist/windows/main/UnRen-forall.bat
- run: cp src/hook_unrpa.rpy src/dist/windows/main/hook_unrpa.rpy
- run: cp src/expand.exe src/dist/windows/main/expand.exe
- run: cp src/openai_model.txt src/dist/windows/main/openai_model.txt
- run: cp src/hook_extract.rpy src/dist/windows/main/hook_extract.rpy
- run: cp src/hook_add_change_language_entrance.rpy src/dist/windows/main/hook_add_change_language_entrance.rpy
Expand Down
499 changes: 0 additions & 499 deletions src/UnRen-forall.bat

This file was deleted.

8 changes: 7 additions & 1 deletion src/call_game_python.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import platform
import shutil


def is_64_bit():
Expand Down Expand Up @@ -29,4 +30,9 @@ def get_python_path(game_path):

def get_py_path(game_path):
base_name = os.path.splitext(game_path)[0]
return base_name + '.py'
return base_name + '.py'


def copy_files_under_directory_to_directory(src_dir, desc_dir):
shutil.copytree(src_dir, desc_dir, dirs_exist_ok=True)

Binary file removed src/expand.exe
Binary file not shown.
13 changes: 11 additions & 2 deletions src/game_unpacker.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Ui_GameUnpackerDialog(object):
def setupUi(self, GameUnpackerDialog):
if not GameUnpackerDialog.objectName():
GameUnpackerDialog.setObjectName(u"GameUnpackerDialog")
GameUnpackerDialog.resize(661, 260)
GameUnpackerDialog.resize(661, 323)
self.label = QLabel(GameUnpackerDialog)
self.label.setObjectName(u"label")
self.label.setGeometry(QRect(20, 40, 71, 61))
Expand All @@ -39,7 +39,7 @@ def setupUi(self, GameUnpackerDialog):
self.unpackBtn.setGeometry(QRect(100, 130, 491, 24))
self.autoCheckBox = QCheckBox(GameUnpackerDialog)
self.autoCheckBox.setObjectName(u"autoCheckBox")
self.autoCheckBox.setGeometry(QRect(100, 220, 551, 20))
self.autoCheckBox.setGeometry(QRect(20, 290, 551, 20))
self.autoCheckBox.setChecked(True)
self.label_2 = QLabel(GameUnpackerDialog)
self.label_2.setObjectName(u"label_2")
Expand All @@ -49,6 +49,13 @@ def setupUi(self, GameUnpackerDialog):
self.maxThreadsLineEdit.setObjectName(u"maxThreadsLineEdit")
self.maxThreadsLineEdit.setGeometry(QRect(200, 188, 391, 20))
self.maxThreadsLineEdit.setPlaceholderText(u"")
self.overwriteCheckBox = QCheckBox(GameUnpackerDialog)
self.overwriteCheckBox.setObjectName(u"overwriteCheckBox")
self.overwriteCheckBox.setGeometry(QRect(20, 230, 571, 20))
self.unpackAllCheckBox = QCheckBox(GameUnpackerDialog)
self.unpackAllCheckBox.setObjectName(u"unpackAllCheckBox")
self.unpackAllCheckBox.setGeometry(QRect(20, 260, 631, 20))
self.unpackAllCheckBox.setChecked(False)

self.retranslateUi(GameUnpackerDialog)

Expand All @@ -65,5 +72,7 @@ def retranslateUi(self, GameUnpackerDialog):
self.selectFileText.setPlaceholderText(QCoreApplication.translate("GameUnpackerDialog", u"input or choose or drag the game you want to unpack it's rpa files.Example:F:/DemoGame.exe", None))
self.unpackBtn.setText(QCoreApplication.translate("GameUnpackerDialog", u"Unpack", None))
self.autoCheckBox.setText(QCoreApplication.translate("GameUnpackerDialog", u"Auto close the game after unpacked", None))
self.overwriteCheckBox.setText(QCoreApplication.translate("GameUnpackerDialog", u"Overwrite the rpy file if exsits", None))
self.unpackAllCheckBox.setText(QCoreApplication.translate("GameUnpackerDialog", u"Unpack all files (if disabled only script files will be unpacked)", None))
# retranslateUi

35 changes: 32 additions & 3 deletions src/game_unpacker.ui
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>661</width>
<height>260</height>
<height>323</height>
</rect>
</property>
<property name="windowTitle">
Expand Down Expand Up @@ -74,8 +74,8 @@
<widget class="QCheckBox" name="autoCheckBox">
<property name="geometry">
<rect>
<x>100</x>
<y>220</y>
<x>20</x>
<y>290</y>
<width>551</width>
<height>20</height>
</rect>
Expand Down Expand Up @@ -113,6 +113,35 @@
<string notr="true"/>
</property>
</widget>
<widget class="QCheckBox" name="overwriteCheckBox">
<property name="geometry">
<rect>
<x>20</x>
<y>230</y>
<width>571</width>
<height>20</height>
</rect>
</property>
<property name="text">
<string>Overwrite the rpy file if exsits</string>
</property>
</widget>
<widget class="QCheckBox" name="unpackAllCheckBox">
<property name="geometry">
<rect>
<x>20</x>
<y>260</y>
<width>631</width>
<height>20</height>
</rect>
</property>
<property name="text">
<string>Unpack all files (if disabled only script files will be unpacked)</string>
</property>
<property name="checked">
<bool>false</bool>
</property>
</widget>
</widget>
<resources/>
<connections/>
Expand Down
71 changes: 59 additions & 12 deletions src/game_unpacker_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
import my_log
from renpy_fonts import GenGuiFonts
from game_unpacker import Ui_GameUnpackerDialog
from call_game_python import *
from unzipdir import zip_dir, unzip_file

bat = 'UnRen-forall.bat'
hook_script = 'hook_unrpa.rpy'
finish_flag = '/unpack.finish'
pid_flag = '/game.pid'
expand_file = 'expand.exe'


def set_window_on_top(hwnd):
Expand All @@ -38,24 +38,60 @@ def set_window_on_top(hwnd):
pass


def get_unrpyc_command(game_path):
python_path = get_python_path(game_path)
game_dir = os.path.dirname(game_path)
unrpyc_path = game_dir + '/unrpyc.py'
command = python_path + ' "' + unrpyc_path + '" "' + game_dir + '"'
return command


def clean_unrpyc(dir):
try:
shutil.rmtree(dir + '/renpy/common')
except FileNotFoundError:
pass
try:
shutil.rmtree(dir + '/__pycache__')
except FileNotFoundError:
pass
shutil.rmtree(dir + '/decompiler')
unzip_file(dir + '/common_backup.zip', dir + '/renpy/common')
os.remove(dir + '/common_backup.zip')
os.remove(dir + '/deobfuscate.py')
os.remove(dir + '/unrpyc.py')
if os.path.isfile(dir + '/unrpyc.pyo'):
os.remove(dir + '/unrpyc.pyo')
if os.path.isfile(dir + '/deobfuscate.pyo'):
os.remove(dir + '/deobfuscate.pyo')


class unrpycThread(threading.Thread):
def __init__(self, dir, p, is_auto_close):
def __init__(self, dir, path, p, is_over_write, is_auto_close):
threading.Thread.__init__(self)
self.dir = dir
self.p = p
self.path = path
self.is_over_write = is_over_write
self.is_auto_close = is_auto_close

def run(self):
try:
if self.is_auto_close and self.p is not None:
subprocess.Popen("taskkill /F /T /PID " + self.p, shell=True,
creationflags=0x08000000, text=True, encoding='utf-8')
dir = self.dir
bat = '"' + os.getcwd() + '/UnRen-forall.bat' + '"'
command = bat
p = subprocess.Popen(command, shell=False, stdout=my_log.f, stderr=my_log.f,
creationflags=0x08000000, text=True, cwd=dir, encoding='utf-8')
zip_dir(self.dir + '/renpy/common', self.dir + '/common_backup.zip')
copy_files_under_directory_to_directory(os.getcwd() + '/unrpyc', self.dir)
command = get_unrpyc_command(self.path)
if self.is_over_write:
command = command + ' --clobber'
log_print(command)
p = subprocess.Popen(command, shell=True, stdout=my_log.f, stderr=my_log.f,
creationflags=0x08000000, text=True, encoding='utf-8')
p.wait()
time.sleep(1)
clean_unrpyc(self.dir)
io.open(self.dir + '/unren.finish', mode='w', encoding='utf-8').close()
except Exception as e:
msg = traceback.format_exc()
log_print(msg)
Expand All @@ -78,11 +114,17 @@ def __init__(self, parent=None):
_read_lines = f.readlines()
f.close()
max_thread_num = 12
is_script_only = True
for idx, _line in enumerate(_read_lines):
if _line.startswith(' MAX_UNPACK_THREADS = '):
max_thread_num = _line[len(' MAX_UNPACK_THREADS = '):].strip().strip('\n')
break
for idx, _line in enumerate(_read_lines):
if _line.startswith(' SCRIPT_ONLY = '):
is_script_only = _line[len(' SCRIPT_ONLY = '):].strip().strip('\n') == 'True'
break
self.maxThreadsLineEdit.setText(str(max_thread_num))
self.unpackAllCheckBox.setChecked(not is_script_only)
_thread.start_new_thread(self.update, ())

def closeEvent(self, event):
Expand Down Expand Up @@ -110,18 +152,23 @@ def unpack(self):
if os.path.isfile(path):
if path.endswith('.exe'):
dir = os.path.dirname(path)
#shutil.copyfile(hook_script, dir + '/game/' + hook_script)
# shutil.copyfile(hook_script, dir + '/game/' + hook_script)
f = io.open(hook_script, mode='r', encoding='utf-8')
_read_lines = f.readlines()
f.close()
for idx, _line in enumerate(_read_lines):
if _line.startswith(' MAX_UNPACK_THREADS = '):
_read_lines[idx] = f' MAX_UNPACK_THREADS = {self.maxThreadsLineEdit.text()}\n'
break
for idx, _line in enumerate(_read_lines):
if _line.startswith(' SCRIPT_ONLY = '):
_read_lines[idx] = f' SCRIPT_ONLY = {str(not self.unpackAllCheckBox.isChecked())}\n'
break

f = io.open(dir + '/game/' + hook_script, mode='w', encoding='utf-8')
f.writelines(_read_lines)
f.close()
f = io.open( hook_script, mode='w', encoding='utf-8')
f = io.open(hook_script, mode='w', encoding='utf-8')
f.writelines(_read_lines)
f.close()
command = path
Expand Down Expand Up @@ -172,11 +219,11 @@ def update_progress(self):
target = dir + pid_flag
pid = None
if os.path.isfile(target):
f = io.open(target, 'r',encoding='utf-8')
f = io.open(target, 'r', encoding='utf-8')
pid = f.read()
f.close()
os.remove(target)
t = unrpycThread(dir, pid, self.autoCheckBox.isChecked())
t = unrpycThread(dir, self.path, pid, self.overwriteCheckBox.isChecked(), self.autoCheckBox.isChecked())
t.start()
self.path = None
self.dir = dir
Expand Down
5 changes: 4 additions & 1 deletion src/hook_unrpa.rpy
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ init python early hide:

unpack_file_threads = []
MAX_UNPACK_THREADS = 12
SCRIPT_ONLY = False
unpack_semaphore = threading.Semaphore(MAX_UNPACK_THREADS)
non_ascii_file_list = []

Expand Down Expand Up @@ -69,7 +70,9 @@ init python early hide:
_read = rv.readall()
else:
return rv

if SCRIPT_ONLY:
if not name.endswith('.rpy') and not name.endswith('.rpyc'):
return rv
current_file_path = os.path.abspath(sys.argv[0])
current_dir_path = os.path.dirname(current_file_path)
path = current_dir_path + '/game/' + name
Expand Down
39 changes: 24 additions & 15 deletions src/one_key_translate.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Ui_OneKeyTranslateDialog(object):
def setupUi(self, OneKeyTranslateDialog):
if not OneKeyTranslateDialog.objectName():
OneKeyTranslateDialog.setObjectName(u"OneKeyTranslateDialog")
OneKeyTranslateDialog.resize(1039, 623)
OneKeyTranslateDialog.resize(1039, 679)
self.selectFileBtn = QPushButton(OneKeyTranslateDialog)
self.selectFileBtn.setObjectName(u"selectFileBtn")
self.selectFileBtn.setGeometry(QRect(520, 25, 81, 91))
Expand Down Expand Up @@ -58,17 +58,17 @@ def setupUi(self, OneKeyTranslateDialog):
self.label_10.setGeometry(QRect(30, 280, 41, 31))
self.localGlossaryCheckBox = QCheckBox(OneKeyTranslateDialog)
self.localGlossaryCheckBox.setObjectName(u"localGlossaryCheckBox")
self.localGlossaryCheckBox.setGeometry(QRect(30, 400, 571, 20))
self.localGlossaryCheckBox.setGeometry(QRect(30, 450, 571, 20))
self.selectFontBtn = QPushButton(OneKeyTranslateDialog)
self.selectFontBtn.setObjectName(u"selectFontBtn")
self.selectFontBtn.setGeometry(QRect(520, 520, 81, 91))
self.selectFontBtn.setGeometry(QRect(520, 570, 81, 91))
self.label_4 = QLabel(OneKeyTranslateDialog)
self.label_4.setObjectName(u"label_4")
self.label_4.setGeometry(QRect(30, 550, 71, 31))
self.label_4.setGeometry(QRect(30, 600, 71, 31))
self.label_4.setWordWrap(True)
self.selectFontText = QTextEdit(OneKeyTranslateDialog)
self.selectFontText.setObjectName(u"selectFontText")
self.selectFontText.setGeometry(QRect(110, 520, 411, 91))
self.selectFontText.setGeometry(QRect(110, 570, 411, 91))
self.unpackCheckBox = QCheckBox(OneKeyTranslateDialog)
self.unpackCheckBox.setObjectName(u"unpackCheckBox")
self.unpackCheckBox.setGeometry(QRect(620, 30, 411, 20))
Expand All @@ -95,49 +95,56 @@ def setupUi(self, OneKeyTranslateDialog):
self.translateCheckBox.setChecked(True)
self.filterCheckBox = QCheckBox(OneKeyTranslateDialog)
self.filterCheckBox.setObjectName(u"filterCheckBox")
self.filterCheckBox.setGeometry(QRect(30, 430, 261, 20))
self.filterCheckBox.setGeometry(QRect(30, 480, 261, 20))
self.filterCheckBox.setChecked(True)
self.filterLengthLineEdit = QLineEdit(OneKeyTranslateDialog)
self.filterLengthLineEdit.setObjectName(u"filterLengthLineEdit")
self.filterLengthLineEdit.setGeometry(QRect(500, 430, 101, 20))
self.filterLengthLineEdit.setGeometry(QRect(500, 480, 101, 20))
self.filterLengthLineEdit.setText(u"8")
self.filterLengthLineEdit.setAlignment(Qt.AlignCenter)
self.label_14 = QLabel(OneKeyTranslateDialog)
self.label_14.setObjectName(u"label_14")
self.label_14.setGeometry(QRect(290, 432, 201, 16))
self.label_14.setGeometry(QRect(290, 482, 201, 16))
self.label_14.setAlignment(Qt.AlignCenter)
self.startButton = QPushButton(OneKeyTranslateDialog)
self.startButton.setObjectName(u"startButton")
self.startButton.setGeometry(QRect(620, 420, 401, 191))
self.startButton.setGeometry(QRect(620, 420, 401, 241))
self.officialExtractionCheckBox = QCheckBox(OneKeyTranslateDialog)
self.officialExtractionCheckBox.setObjectName(u"officialExtractionCheckBox")
self.officialExtractionCheckBox.setGeometry(QRect(620, 150, 411, 20))
self.officialExtractionCheckBox.setChecked(True)
self.filterCheckBox_2 = QCheckBox(OneKeyTranslateDialog)
self.filterCheckBox_2.setObjectName(u"filterCheckBox_2")
self.filterCheckBox_2.setGeometry(QRect(30, 490, 261, 20))
self.filterCheckBox_2.setGeometry(QRect(30, 540, 261, 20))
self.filterCheckBox_2.setChecked(True)
self.filterLengthLineEdit_2 = QLineEdit(OneKeyTranslateDialog)
self.filterLengthLineEdit_2.setObjectName(u"filterLengthLineEdit_2")
self.filterLengthLineEdit_2.setGeometry(QRect(500, 488, 101, 20))
self.filterLengthLineEdit_2.setGeometry(QRect(500, 538, 101, 20))
self.filterLengthLineEdit_2.setText(u"3")
self.filterLengthLineEdit_2.setAlignment(Qt.AlignCenter)
self.label_15 = QLabel(OneKeyTranslateDialog)
self.label_15.setObjectName(u"label_15")
self.label_15.setGeometry(QRect(290, 490, 201, 16))
self.label_15.setGeometry(QRect(290, 540, 201, 16))
self.label_15.setAlignment(Qt.AlignCenter)
self.underlineCheckBox = QCheckBox(OneKeyTranslateDialog)
self.underlineCheckBox.setObjectName(u"underlineCheckBox")
self.underlineCheckBox.setGeometry(QRect(30, 460, 581, 20))
self.underlineCheckBox.setGeometry(QRect(30, 510, 581, 20))
self.underlineCheckBox.setChecked(True)
self.maxThreadsLineEdit = QLineEdit(OneKeyTranslateDialog)
self.maxThreadsLineEdit.setObjectName(u"maxThreadsLineEdit")
self.maxThreadsLineEdit.setGeometry(QRect(210, 370, 391, 20))
self.maxThreadsLineEdit.setGeometry(QRect(210, 350, 391, 20))
self.maxThreadsLineEdit.setPlaceholderText(u"")
self.label_2 = QLabel(OneKeyTranslateDialog)
self.label_2.setObjectName(u"label_2")
self.label_2.setGeometry(QRect(30, 372, 161, 16))
self.label_2.setGeometry(QRect(30, 352, 161, 16))
self.label_2.setText(u"MAX_UNPACK_THREADS : ")
self.overwriteCheckBox = QCheckBox(OneKeyTranslateDialog)
self.overwriteCheckBox.setObjectName(u"overwriteCheckBox")
self.overwriteCheckBox.setGeometry(QRect(30, 390, 571, 20))
self.unpackAllCheckBox = QCheckBox(OneKeyTranslateDialog)
self.unpackAllCheckBox.setObjectName(u"unpackAllCheckBox")
self.unpackAllCheckBox.setGeometry(QRect(30, 420, 561, 20))
self.unpackAllCheckBox.setChecked(False)

self.retranslateUi(OneKeyTranslateDialog)

Expand Down Expand Up @@ -174,5 +181,7 @@ def retranslateUi(self, OneKeyTranslateDialog):
self.filterCheckBox_2.setText(QCoreApplication.translate("OneKeyTranslateDialog", u"Enable filter for translate", None))
self.label_15.setText(QCoreApplication.translate("OneKeyTranslateDialog", u"filter length less than", None))
self.underlineCheckBox.setText(QCoreApplication.translate("OneKeyTranslateDialog", u"Skip extract the contents which include underline", None))
self.overwriteCheckBox.setText(QCoreApplication.translate("OneKeyTranslateDialog", u"Overwrite the rpy file if exsits", None))
self.unpackAllCheckBox.setText(QCoreApplication.translate("OneKeyTranslateDialog", u"Unpack all files (if disabled only script files will be unpacked)", None))
# retranslateUi

Loading

0 comments on commit c1c8b3b

Please sign in to comment.