mirror of
https://github.com/HIllya51/LunaHook.git
synced 2025-01-12 04:49:37 +08:00
issues/708
This commit is contained in:
parent
892eccb17f
commit
ff1091112d
@ -11,6 +11,24 @@
|
|||||||
extern "C" __declspec(dllexport) const wchar_t* internal_renpy_call_host(const wchar_t* text,int split){
|
extern "C" __declspec(dllexport) const wchar_t* internal_renpy_call_host(const wchar_t* text,int split){
|
||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
|
bool Luna_checkisusingembed(uint64_t address, uint64_t ctx1, uint64_t ctx2)
|
||||||
|
{
|
||||||
|
auto sm = embedsharedmem;
|
||||||
|
if (!sm)
|
||||||
|
return false;
|
||||||
|
for (int i = 0; i < 10; i++)
|
||||||
|
{
|
||||||
|
if (sm->use[i])
|
||||||
|
{
|
||||||
|
if ((sm->addr[i] == address) && (sm->ctx1[i] == ctx1) && (sm->ctx2[i] == ctx2))
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
extern "C" __declspec(dllexport) bool internal_renpy_call_is_embed_using(int split){
|
||||||
|
return Luna_checkisusingembed((uint64_t)internal_renpy_call_host,0,split);
|
||||||
|
}
|
||||||
namespace{
|
namespace{
|
||||||
|
|
||||||
typedef enum {PyGILState_LOCKED, PyGILState_UNLOCKED}
|
typedef enum {PyGILState_LOCKED, PyGILState_UNLOCKED}
|
||||||
@ -45,7 +63,7 @@ void hook_internal_renpy_call_host(){
|
|||||||
hp_internal.address=(uintptr_t)internal_renpy_call_host;
|
hp_internal.address=(uintptr_t)internal_renpy_call_host;
|
||||||
hp_internal.offset=GETARG1;
|
hp_internal.offset=GETARG1;
|
||||||
hp_internal.split=GETARG2;
|
hp_internal.split=GETARG2;
|
||||||
hp_internal.type=USING_SPLIT|USING_STRING|CODEC_UTF16|EMBED_ABLE|EMBED_BEFORE_SIMPLE|EMBED_AFTER_NEW;
|
hp_internal.type=USING_SPLIT|USING_STRING|CODEC_UTF16|EMBED_ABLE|EMBED_BEFORE_SIMPLE|EMBED_AFTER_NEW|NO_CONTEXT;
|
||||||
NewHook(hp_internal, "internal_renpy_call_host");
|
NewHook(hp_internal, "internal_renpy_call_host");
|
||||||
PyRunScript(LoadResData(L"renpy_hook_text",L"PYSOURCE").c_str());
|
PyRunScript(LoadResData(L"renpy_hook_text",L"PYSOURCE").c_str());
|
||||||
}
|
}
|
||||||
|
@ -1,39 +1,72 @@
|
|||||||
def callLunaHost(text,split):
|
def callLunaHost(text, split):
|
||||||
try:
|
try:
|
||||||
import ctypes
|
import ctypes
|
||||||
try:
|
|
||||||
internal_renpy_call_host=ctypes.CDLL('LunaHook64').internal_renpy_call_host
|
|
||||||
except:
|
|
||||||
internal_renpy_call_host=ctypes.CDLL('LunaHook32').internal_renpy_call_host
|
|
||||||
internal_renpy_call_host.argstype=ctypes.c_wchar_p,ctypes.c_int
|
|
||||||
internal_renpy_call_host.restype=ctypes.c_wchar_p
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
_text=text.decode('utf8')
|
internal_renpy_call_host = ctypes.CDLL(
|
||||||
|
"LunaHook64"
|
||||||
|
).internal_renpy_call_host
|
||||||
except:
|
except:
|
||||||
_text=text
|
internal_renpy_call_host = ctypes.CDLL(
|
||||||
text=internal_renpy_call_host(_text,split)
|
"LunaHook32"
|
||||||
|
).internal_renpy_call_host
|
||||||
|
internal_renpy_call_host.argstype = ctypes.c_wchar_p, ctypes.c_int
|
||||||
|
internal_renpy_call_host.restype = ctypes.c_wchar_p
|
||||||
|
|
||||||
|
try:
|
||||||
|
_text = text.decode("utf8")
|
||||||
|
except:
|
||||||
|
_text = text
|
||||||
|
text = internal_renpy_call_host(_text, split)
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
return text
|
return text
|
||||||
|
|
||||||
|
def callLunaIsUsingEmbed(split):
|
||||||
|
try:
|
||||||
|
import ctypes
|
||||||
|
|
||||||
|
try:
|
||||||
|
internal_renpy_call_is_embed_using = ctypes.CDLL(
|
||||||
|
"LunaHook64"
|
||||||
|
).internal_renpy_call_is_embed_using
|
||||||
|
except:
|
||||||
|
internal_renpy_call_is_embed_using = ctypes.CDLL(
|
||||||
|
"LunaHook32"
|
||||||
|
).internal_renpy_call_is_embed_using
|
||||||
|
internal_renpy_call_is_embed_using.argstype = ctypes.c_int,
|
||||||
|
internal_renpy_call_is_embed_using.restype = ctypes.c_bool
|
||||||
|
|
||||||
|
return internal_renpy_call_is_embed_using(split)
|
||||||
|
except:
|
||||||
|
return False
|
||||||
|
|
||||||
try:
|
try:
|
||||||
#6.1.0
|
# 6.1.0
|
||||||
import renpy
|
import renpy
|
||||||
|
|
||||||
def hook_initT0(original_init):
|
def hook_initT0(original_init):
|
||||||
|
|
||||||
def new_init(self, *args, **kwargs):
|
def new_init(self, *args, **kwargs):
|
||||||
|
changed=False
|
||||||
if isinstance(args[0], list):
|
if isinstance(args[0], list):
|
||||||
trs = callLunaHost((args[0][0]),1)
|
trs = []
|
||||||
|
for _ in args[0]:
|
||||||
|
_n=callLunaHost(_, 1)
|
||||||
|
if _n!=_:
|
||||||
|
changed=True
|
||||||
|
trs += [_n]
|
||||||
else:
|
else:
|
||||||
trs = callLunaHost((args[0]),1)
|
trs = callLunaHost(args[0], 1)
|
||||||
|
if args[0]!=trs:
|
||||||
|
changed=True
|
||||||
|
|
||||||
nargs = (trs,) + args[1:]
|
if changed and callLunaIsUsingEmbed(1):
|
||||||
if 'text' in kwargs:
|
args = (trs,) + args[1:]
|
||||||
kwargs['text'] = nargs[0]
|
if "text" in kwargs:
|
||||||
self.mtoolHooked = True
|
kwargs["text"] = trs
|
||||||
|
|
||||||
original_init(self, *nargs, **kwargs)
|
original_init(self, *args, **kwargs)
|
||||||
|
|
||||||
return new_init
|
return new_init
|
||||||
|
|
||||||
@ -45,17 +78,25 @@ try:
|
|||||||
def hook_init_renderT0(original):
|
def hook_init_renderT0(original):
|
||||||
def new_init(self, *args, **kwargs):
|
def new_init(self, *args, **kwargs):
|
||||||
if not hasattr(self, "LunaHooked"):
|
if not hasattr(self, "LunaHooked"):
|
||||||
|
changed=False
|
||||||
if isinstance(self.text, list):
|
if isinstance(self.text, list):
|
||||||
trs = callLunaHost((self.text[0]),2)
|
trs = []
|
||||||
|
for _ in self.text:
|
||||||
|
_n=callLunaHost(_, 2)
|
||||||
|
if _n!=_:
|
||||||
|
changed=True
|
||||||
|
trs += [_n]
|
||||||
else:
|
else:
|
||||||
trs = callLunaHost((self.text),2)
|
trs = callLunaHost(self.text, 2)
|
||||||
self.set_text(trs)
|
if self.text!=trs:
|
||||||
self.LunaHooked = True
|
changed=True
|
||||||
|
if changed and callLunaIsUsingEmbed(2):
|
||||||
|
self.set_text(trs)
|
||||||
|
self.LunaHooked = True
|
||||||
return original(self, *args, **kwargs)
|
return original(self, *args, **kwargs)
|
||||||
|
|
||||||
return new_init
|
return new_init
|
||||||
|
|
||||||
|
|
||||||
if "original_hook_init_renderT0" not in globals():
|
if "original_hook_init_renderT0" not in globals():
|
||||||
original_hook_init_renderT0 = renpy.text.text.Text.render
|
original_hook_init_renderT0 = renpy.text.text.Text.render
|
||||||
|
|
||||||
@ -63,18 +104,18 @@ try:
|
|||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
try:
|
try:
|
||||||
#4.0
|
# 4.0
|
||||||
import renpy
|
import renpy
|
||||||
|
|
||||||
def hook_initT3(original_init):
|
def hook_initT3(original_init):
|
||||||
def new_init(self, *args, **kwargs):
|
def new_init(self, *args, **kwargs):
|
||||||
trs = callLunaHost(str(args[0]),3)
|
trs = callLunaHost(str(args[0]), 3)
|
||||||
|
if callLunaIsUsingEmbed(3):
|
||||||
nargs = (trs,) + args[1:]
|
args = (trs,) + args[1:]
|
||||||
original_init(self, *nargs, **kwargs)
|
original_init(self, *args, **kwargs)
|
||||||
|
|
||||||
return new_init
|
return new_init
|
||||||
|
|
||||||
|
|
||||||
if "original_Text_init_hookT3" not in globals():
|
if "original_Text_init_hookT3" not in globals():
|
||||||
original_Text_init_hookT3 = renpy.exports.Text.__init__
|
original_Text_init_hookT3 = renpy.exports.Text.__init__
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user