Skip to content

Commit

Permalink
<feature> Support lower version of renpy like 7.1.0
Browse files Browse the repository at this point in the history
update version to v2.2.9
  • Loading branch information
anonymousException committed May 27, 2024
1 parent 50bf1fb commit 10711bf
Show file tree
Hide file tree
Showing 34 changed files with 106 additions and 62 deletions.
17 changes: 12 additions & 5 deletions src/extract_runtime_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,19 @@ def run(self):
p = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
creationflags=0x08000000)
p.wait()
if os.path.exists(target):
os.remove(target)
target = target + 'c'
if os.path.exists(target):
os.remove(target)

target = dir + '/' + hooked_result
while True:
if os.path.isfile(target) and os.path.getsize(target) > 0:
target = dir + '/game/' + hook_script
if os.path.exists(target):
os.remove(target)
target = target + 'c'
if os.path.exists(target):
os.remove(target)
target = dir + '/' + hooked_result
break
time.sleep(1)
if os.path.isfile(target):
f = io.open(target, 'r', encoding='utf-8')
dic = json.load(f)
Expand Down
19 changes: 12 additions & 7 deletions src/game_unpacker_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
bat = 'UnRen-forall.bat'
hook_script = 'hook_unrpa.rpy'
finish_flag = '/unpack.finish'
pid_flag = '/game.pid'
expand_file = 'expand.exe'


Expand All @@ -46,8 +47,9 @@ def __init__(self, dir, p, is_auto_close):

def run(self):
try:
if self.is_auto_close:
self.p.kill()
if self.is_auto_close and self.p is not None:
subprocess.Popen("taskkill /F /T /PID " + self.p, shell=False, stdout=my_log.f, stderr=my_log.f,
creationflags=0x08000000, text=True)
dir = self.dir
bat = '"' + os.getcwd() + '/UnRen-forall.bat' + '"'
command = bat
Expand All @@ -71,7 +73,6 @@ def __init__(self, parent=None):
self.hwnd = win32gui.GetForegroundWindow()
self.parent_hwnd = None
self.path = None
self.p = None
self.dir = None
_thread.start_new_thread(self.update, ())

Expand Down Expand Up @@ -126,9 +127,6 @@ def update(self):

def update_progress(self):
try:
if self.p is not None:
if self.p.poll() is not None:
self.p = None
if self.dir is not None:
if os.path.isfile(self.dir + '/unren.finish'):
os.remove(self.dir + '/unren.finish')
Expand All @@ -149,7 +147,14 @@ def update_progress(self):
if os.path.isfile(hook_script_path + 'c'):
os.remove(hook_script_path + 'c')
set_window_on_top(self.parent_hwnd)
t = unrpycThread(dir, self.p, self.autoCheckBox.isChecked())
target = dir + pid_flag
pid = None
if os.path.isfile(target):
f = io.open(target, 'r',encoding='utf-8')
pid = f.read()
f.close()
os.remove(target)
t = unrpycThread(dir, pid, self.autoCheckBox.isChecked())
t.start()
self.path = None
self.dir = dir
Expand Down
58 changes: 44 additions & 14 deletions src/hook_unrpa.rpy
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,43 @@ init python early hide:
import renpy.loader
import threading
import io
from renpy.loader import file_open_callbacks,load_from_archive,archives
import importlib
import inspect
import os
from renpy.loader import archives

def check_function_exists(module_name, function_name):
try:
module = importlib.import_module(module_name)
function = getattr(module, function_name)
if inspect.isfunction(function):
#print(f"The function '{function_name}' exists in the module '{module_name}'.")
return True
else:
#print(f"The name '{function_name}' exists in the module '{module_name}', but it is not a function.")
return False
except ImportError:
#print(f"The module '{module_name}' does not exist.")
return False
except AttributeError:
#print(f"The function '{function_name}' does not exist in the module '{module_name}'.")
return False

def my_load_from_archive(name):
load_packed_file_source = None
if check_function_exists('renpy.loader','load_from_archive'):
from renpy.loader import load_from_archive as load_packed_file
load_packed_file_source = 'load_from_archive'
elif check_function_exists('renpy.loader','load_core'):
from renpy.loader import load_core as load_packed_file
load_packed_file_source = 'load_core'
else:
print('Error! Can not locate load_packed_file function!')
return None
try:
rv = load_from_archive(name)
rv = load_packed_file(name)
except:
print('load_from_archive : ' + name +' error!')
print(load_packed_file_source + ' : ' + name +' error!')
return None
if rv is None:
return rv
Expand All @@ -20,7 +50,7 @@ init python early hide:
_read = rv.readall()
else:
return rv
#file_open_callbacks.remove(my_load_from_archive)

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 All @@ -33,23 +63,23 @@ init python early hide:
os.makedirs(target_dir)
with open(path, 'wb') as file:
file.write(_read)
if path.endswith((".rpyc", ".rpymc")) and not target_dir.endswith("None") and not base_name=='common':
if path is not None and isinstance(path,str):
print(path)
print(path)

rv = load_from_archive(name)
#file_open_callbacks.append(my_load_from_archive)
rv = load_packed_file(name)
return rv

#file_open_callbacks.remove(load_from_archive)

#file_open_callbacks.append(my_load_from_archive)

for prefix, index in archives:
for name in index.keys():
print(name)
#print(name)
my_load_from_archive(name)

finish_flag = 'unpack.finish'
pid_flag = 'game.pid'
f = io.open(pid_flag, 'w',encoding='utf-8')
if sys.version > '3':
f.write(str(os.getpid()))
else:
f.write(str(os.getpid()).decode('utf-8'))
f.close()
if os.path.isfile(finish_flag):
os.remove(finish_flag)
2 changes: 1 addition & 1 deletion src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ def __del__(self):
self.wait()

def run(self):
f = io.open(log_path, 'r+', encoding='utf-8')
f = io.open(log_path, 'r+')
self.update_date.emit(f.read())
f.close()

Expand Down
14 changes: 8 additions & 6 deletions src/one_key_translate_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ def __init__(self, parent=None):
# is_finished
# is_executed
self.qDic = dict()
self.p = None
self.dir = None
default_font = get_default_font_path()
if default_font is not None:
Expand Down Expand Up @@ -349,7 +348,6 @@ def unpack(self):
log_print('start unpacking...')
p = subprocess.Popen(command, shell=False, stdout=my_log.f, stderr=my_log.f,
creationflags=0x08000000, text=True, cwd=dir, encoding='utf-8')
self.p = p
return
is_finished, is_executed = self.qDic[self.unpack]
is_finished = True
Expand Down Expand Up @@ -493,9 +491,6 @@ def update(self):

def update_progress(self):
try:
if self.p is not None:
if self.p.poll() is not None:
self.p = None
if self.dir is not None:
if os.path.isfile(self.dir + '/unren.finish'):
os.remove(self.dir + '/unren.finish')
Expand All @@ -521,7 +516,14 @@ def update_progress(self):
os.remove(hook_script_path)
if os.path.isfile(hook_script_path + 'c'):
os.remove(hook_script_path + 'c')
t = game_unpacker_form.unrpycThread(dir, self.p, True)
pid = None
target = dir + game_unpacker_form.pid_flag
if os.path.isfile(target):
f = io.open(target, 'r', encoding='utf-8')
pid = f.read()
f.close()
os.remove(target)
t = game_unpacker_form.unrpycThread(dir, pid, True)
t.start()
self.path = None
self.dir = dir
Expand Down
Binary file modified src/qm/arabic.qm
Binary file not shown.
Binary file modified src/qm/bengali.qm
Binary file not shown.
Binary file modified src/qm/chinese.qm
Binary file not shown.
Binary file modified src/qm/french.qm
Binary file not shown.
Binary file modified src/qm/german.qm
Binary file not shown.
Binary file modified src/qm/hindi.qm
Binary file not shown.
Binary file modified src/qm/japanese.qm
Binary file not shown.
Binary file modified src/qm/korean.qm
Binary file not shown.
Binary file modified src/qm/portuguese.qm
Binary file not shown.
Binary file modified src/qm/russian.qm
Binary file not shown.
Binary file modified src/qm/spanish.qm
Binary file not shown.
Binary file modified src/qm/turkish.qm
Binary file not shown.
Binary file modified src/qm/urdu.qm
Binary file not shown.
4 changes: 2 additions & 2 deletions src/ts/arabic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1180,8 +1180,8 @@
</message>
<message>
<location filename="../ui.ui" line="78"/>
<source>Version 2.2.8</source>
<translation>الإصدار2.2.8</translation>
<source>Version 2.2.9</source>
<translation>الإصدار2.2.9</translation>
</message>
<message>
<location filename="../ui.ui" line="113"/>
Expand Down
4 changes: 2 additions & 2 deletions src/ts/bengali.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1180,8 +1180,8 @@
</message>
<message>
<location filename="../ui.ui" line="78"/>
<source>Version 2.2.8</source>
<translation>সংস্করণ 2.2.8</translation>
<source>Version 2.2.9</source>
<translation>সংস্করণ 2.2.9</translation>
</message>
<message>
<location filename="../ui.ui" line="113"/>
Expand Down
4 changes: 2 additions & 2 deletions src/ts/chinese.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1178,8 +1178,8 @@
</message>
<message>
<location filename="../ui.ui" line="78"/>
<source>Version 2.2.8</source>
<translation>版本 2.2.8</translation>
<source>Version 2.2.9</source>
<translation>版本 2.2.9</translation>
</message>
<message>
<location filename="../ui.ui" line="113"/>
Expand Down
2 changes: 1 addition & 1 deletion src/ts/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1253,7 +1253,7 @@
</message>
<message>
<location filename="../ui.ui" line="78"/>
<source>Version 2.2.8</source>
<source>Version 2.2.9</source>
<translation type="unfinished"></translation>
</message>
<message>
Expand Down
4 changes: 2 additions & 2 deletions src/ts/french.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1180,8 +1180,8 @@
</message>
<message>
<location filename="../ui.ui" line="78"/>
<source>Version 2.2.8</source>
<translation>Version 2.2.8</translation>
<source>Version 2.2.9</source>
<translation>Version 2.2.9</translation>
</message>
<message>
<location filename="../ui.ui" line="113"/>
Expand Down
4 changes: 2 additions & 2 deletions src/ts/german.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1288,8 +1288,8 @@
</message>
<message>
<location filename="../ui.ui" line="78"/>
<source>Version 2.2.8</source>
<translation>Version 2.2.8</translation>
<source>Version 2.2.9</source>
<translation>Version 2.2.9</translation>
</message>
<message>
<location filename="../ui.ui" line="391"/>
Expand Down
4 changes: 2 additions & 2 deletions src/ts/hindi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1180,8 +1180,8 @@
</message>
<message>
<location filename="../ui.ui" line="78"/>
<source>Version 2.2.8</source>
<translation>संस्करण 2.2.8</translation>
<source>Version 2.2.9</source>
<translation>संस्करण 2.2.9</translation>
</message>
<message>
<location filename="../ui.ui" line="113"/>
Expand Down
4 changes: 2 additions & 2 deletions src/ts/japanese.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1174,8 +1174,8 @@
</message>
<message>
<location filename="../ui.ui" line="78"/>
<source>Version 2.2.8</source>
<translation>バージョン2.2.8</translation>
<source>Version 2.2.9</source>
<translation>バージョン2.2.9</translation>
</message>
<message>
<location filename="../ui.ui" line="113"/>
Expand Down
4 changes: 2 additions & 2 deletions src/ts/korean.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1288,8 +1288,8 @@
</message>
<message>
<location filename="../ui.ui" line="78"/>
<source>Version 2.2.8</source>
<translation>버전 2.2.8</translation>
<source>Version 2.2.9</source>
<translation>버전 2.2.9</translation>
</message>
<message>
<location filename="../ui.ui" line="391"/>
Expand Down
4 changes: 2 additions & 2 deletions src/ts/portuguese.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1180,8 +1180,8 @@
</message>
<message>
<location filename="../ui.ui" line="78"/>
<source>Version 2.2.8</source>
<translation>Versão 2.2.8</translation>
<source>Version 2.2.9</source>
<translation>Versão 2.2.9</translation>
</message>
<message>
<location filename="../ui.ui" line="113"/>
Expand Down
4 changes: 2 additions & 2 deletions src/ts/russian.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1180,8 +1180,8 @@
</message>
<message>
<location filename="../ui.ui" line="78"/>
<source>Version 2.2.8</source>
<translation>Версия 2.2.8</translation>
<source>Version 2.2.9</source>
<translation>Версия 2.2.9</translation>
</message>
<message>
<location filename="../ui.ui" line="113"/>
Expand Down
4 changes: 2 additions & 2 deletions src/ts/spanish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1180,8 +1180,8 @@
</message>
<message>
<location filename="../ui.ui" line="78"/>
<source>Version 2.2.8</source>
<translation>Versión 2.2.8</translation>
<source>Version 2.2.9</source>
<translation>Versión 2.2.9</translation>
</message>
<message>
<location filename="../ui.ui" line="113"/>
Expand Down
4 changes: 2 additions & 2 deletions src/ts/turkish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1265,8 +1265,8 @@
</message>
<message>
<location filename="../ui.ui" line="78"/>
<source>Version 2.2.8</source>
<translation>Sürüm 2.2.8</translation>
<source>Version 2.2.9</source>
<translation>Sürüm 2.2.9</translation>
</message>
<message>
<location filename="../ui.ui" line="391"/>
Expand Down
4 changes: 2 additions & 2 deletions src/ts/urdu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1180,8 +1180,8 @@
</message>
<message>
<location filename="../ui.ui" line="78"/>
<source>Version 2.2.8</source>
<translation>ورژن 2.2.8</translation>
<source>Version 2.2.9</source>
<translation>ورژن 2.2.9</translation>
</message>
<message>
<location filename="../ui.ui" line="113"/>
Expand Down
2 changes: 1 addition & 1 deletion src/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ def retranslateUi(self, MainWindow):
self.actionpack_game_files.setText(QCoreApplication.translate("MainWindow", u"pack game files", None))
self.clearLogBtn.setText(QCoreApplication.translate("MainWindow", u"clear log", None))
self.copyrightLabel.setText(QCoreApplication.translate("MainWindow", u"\u00a92024 Last moment,All rights reserved.", None))
self.versionLabel.setText(QCoreApplication.translate("MainWindow", u"Version 2.2.8", None))
self.versionLabel.setText(QCoreApplication.translate("MainWindow", u"Version 2.2.9", None))
self.translateBtn.setText(QCoreApplication.translate("MainWindow", u"translate", None))
self.selectFilesBtn.setText(QCoreApplication.translate("MainWindow", u"...", None))
self.label_2.setText(QCoreApplication.translate("MainWindow", u"directory", None))
Expand Down
2 changes: 1 addition & 1 deletion src/ui.ui
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
</size>
</property>
<property name="text">
<string>Version 2.2.8</string>
<string>Version 2.2.9</string>
</property>
</widget>
</item>
Expand Down

0 comments on commit 10711bf

Please sign in to comment.