Skip to content

Commit

Permalink
drap
Browse files Browse the repository at this point in the history
  • Loading branch information
HIllya51 committed Nov 12, 2024
1 parent e600d05 commit 7de2923
Show file tree
Hide file tree
Showing 25 changed files with 395 additions and 351 deletions.
74 changes: 40 additions & 34 deletions cpp/LunaHook/LunaHook/engine32/utawarerumono.cpp
Original file line number Diff line number Diff line change
@@ -1,55 +1,61 @@
#include"utawarerumono.h"
#include "utawarerumono.h"

bool utawarerumonoh() {
bool utawarerumonoh()
{
const BYTE bytes[] = {
0x80,XX,0x5C,
0x80, XX, 0x5C,
0x75
//*a2 != 92 || a2[1] != 107
//*a2 != 92 || a2[1] != 107
};
const BYTE bytes2[] = {
0x80,XX,XX,XX,0x5C,
0x75
};
0x80, XX, XX, XX, 0x5C,
0x75};
auto addr1 = MemDbg::findBytes(bytes, sizeof(bytes), processStartAddress, processStopAddress);
auto addr2 = MemDbg::findBytes(bytes2, sizeof(bytes2), processStartAddress, processStopAddress);
auto succ=false;
for (auto addr : { addr1,addr2 }) {
if (addr == 0)continue;
auto succ = false;
for (auto addr : {addr1, addr2})
{
if (addr == 0)
continue;
const BYTE funcstart[] = {
0x51,0x53
};
0x51, 0x53};
addr = reverseFindBytes(funcstart, sizeof(funcstart), addr - 0x100, addr);
if (addr == 0)return false;
if (addr == 0)
return false;
HookParam hp;
hp.address = addr;
hp.offset=get_stack(1);
hp.newlineseperator = L"\\n";
hp.offset = get_stack(1);
hp.type = CODEC_UTF8 | USING_STRING | NO_CONTEXT;
ConsoleOutput("utawarerumono");
succ|=NewHook(hp, "utawarerumono");
}
succ |= NewHook(hp, "utawarerumono");
}
return succ;
}
bool utawarerumonoh2() {
bool utawarerumonoh2()
{
const BYTE bytes2[] = {
0x8b,0xca,
0xc1,0xe9,0x02,
0xf3,0xa5
};
auto addr2 = Util::SearchMemory(bytes2, sizeof(bytes2),PAGE_EXECUTE, processStartAddress, processStopAddress);
auto succ=false;
for (auto addr : addr2) {
0x8b, 0xca,
0xc1, 0xe9, 0x02,
0xf3, 0xa5};
auto addr2 = Util::SearchMemory(bytes2, sizeof(bytes2), PAGE_EXECUTE, processStartAddress, processStopAddress);
auto succ = false;
for (auto addr : addr2)
{
HookParam hp;
hp.address = addr+2;
hp.offset=get_reg(regs::esi);
hp.type = CODEC_UTF8 | USING_STRING|NO_CONTEXT;
ConsoleOutput("utawarerumono %p",addr);
succ|=NewHook(hp, "utawarerumono");
hp.address = addr + 2;
hp.offset = get_reg(regs::esi);
hp.type = CODEC_UTF8 | USING_STRING | NO_CONTEXT;
hp.newlineseperator = L"\\n";
ConsoleOutput("utawarerumono %p", addr);
succ |= NewHook(hp, "utawarerumono");
}
return succ;
}

bool utawarerumono::attach_function() {
bool b1=utawarerumonoh();
bool b2=utawarerumonoh2();
return b1||b2;
}
bool utawarerumono::attach_function()
{
bool b1 = utawarerumonoh();
bool b2 = utawarerumonoh2();
return b1 || b2;
}
4 changes: 2 additions & 2 deletions cpp/version.cmake
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

set(VERSION_MAJOR 5)
set(VERSION_MINOR 57)
set(VERSION_PATCH 4)
set(VERSION_MINOR 58)
set(VERSION_PATCH 0)
set(VERSION_REVISION 0)
add_definitions(-DVERSION_MAJOR=${VERSION_MAJOR})
add_definitions(-DVERSION_MINOR=${VERSION_MINOR})
Expand Down
120 changes: 103 additions & 17 deletions cpp/winsharedutils/webview2_extra.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,35 @@ using namespace Microsoft::WRL;
if (FAILED((x))) \
return x;

DECLARE_API void set_transparent_background(void* m_host){
DECLARE_API void set_transparent_background(void *m_host)
{
COREWEBVIEW2_COLOR color;
ZeroMemory(&color,sizeof(color));
ZeroMemory(&color, sizeof(color));
wil::com_ptr<ICoreWebView2Controller> m_controller(reinterpret_cast<ICoreWebView2Controller *>(m_host));
wil::com_ptr<ICoreWebView2Controller2> coreWebView2 =
m_controller.try_query<ICoreWebView2Controller2>();
if(coreWebView2){
m_controller.try_query<ICoreWebView2Controller2>();
if (coreWebView2)
{
coreWebView2->put_DefaultBackgroundColor(color);
}
}

DECLARE_API HRESULT put_PreferredColorScheme(void *m_host, COREWEBVIEW2_PREFERRED_COLOR_SCHEME scheme)
DECLARE_API void put_PreferredColorScheme(void *m_host, COREWEBVIEW2_PREFERRED_COLOR_SCHEME scheme)
{

wil::com_ptr<ICoreWebView2Controller> m_controller(reinterpret_cast<ICoreWebView2Controller *>(m_host));
wil::com_ptr<ICoreWebView2> coreWebView2;
CHECK_FAILURE(m_controller->get_CoreWebView2(&coreWebView2));
auto webView2_13 = coreWebView2.try_query<ICoreWebView2_13>();
if (webView2_13)
[&]()
{
wil::com_ptr<ICoreWebView2Profile> profile;
CHECK_FAILURE(webView2_13->get_Profile(&profile));
CHECK_FAILURE(profile->put_PreferredColorScheme(scheme));
}
return S_FALSE;
CHECK_FAILURE(m_controller->get_CoreWebView2(&coreWebView2));
auto webView2_13 = coreWebView2.try_query<ICoreWebView2_13>();
if (webView2_13)
{
wil::com_ptr<ICoreWebView2Profile> profile;
CHECK_FAILURE(webView2_13->get_Profile(&profile));
CHECK_FAILURE(profile->put_PreferredColorScheme(scheme));
}
return S_OK;
}();
}
DECLARE_API void *add_ZoomFactorChanged(void *m_host, void (*signal)(double))
{
Expand All @@ -60,9 +64,9 @@ DECLARE_API void *add_ZoomFactorChanged(void *m_host, void (*signal)(double))
}
DECLARE_API void remove_ZoomFactorChanged(void *m_host, void *m_zoomFactorChangedToken)
{

reinterpret_cast<ICoreWebView2Controller *>(m_host)->remove_ZoomFactorChanged(*reinterpret_cast<EventRegistrationToken *>(m_zoomFactorChangedToken));
delete m_zoomFactorChangedToken;
auto token = reinterpret_cast<EventRegistrationToken *>(m_zoomFactorChangedToken);
reinterpret_cast<ICoreWebView2Controller *>(m_host)->remove_ZoomFactorChanged(*token);
delete token;
}
DECLARE_API double get_ZoomFactor(void *m_host)
{
Expand All @@ -73,4 +77,86 @@ DECLARE_API double get_ZoomFactor(void *m_host)
DECLARE_API void put_ZoomFactor(void *m_host, double zoomFactor)
{
reinterpret_cast<ICoreWebView2Controller *>(m_host)->put_ZoomFactor(zoomFactor);
}
// https://github.com/MicrosoftEdge/WebView2Feedback/blob/main/specs/WebMessageObjects.md
DECLARE_API void remove_WebMessageReceived(void *m_host, void *m_webMessageReceivedToken)
{
auto token = reinterpret_cast<EventRegistrationToken *>(m_webMessageReceivedToken);
wil::com_ptr<ICoreWebView2Controller> m_controller(reinterpret_cast<ICoreWebView2Controller *>(m_host));
wil::com_ptr<ICoreWebView2> m_webView;
[&]()
{
CHECK_FAILURE(m_controller->get_CoreWebView2(&m_webView));
CHECK_FAILURE(m_webView->remove_WebMessageReceived(*token));
return S_OK;
}();
delete token;
}

DECLARE_API void *add_WebMessageReceived(void *m_host, void (*callback)(const wchar_t *))
{
wil::com_ptr<ICoreWebView2Controller> m_controller(reinterpret_cast<ICoreWebView2Controller *>(m_host));
wil::com_ptr<ICoreWebView2Controller4> coreWebView4 =
m_controller.try_query<ICoreWebView2Controller4>();
if (coreWebView4)
{
coreWebView4->put_AllowExternalDrop(true);
}
wil::com_ptr<ICoreWebView2> m_webView;
EventRegistrationToken *m_webMessageReceivedToken = new EventRegistrationToken;
[&]()
{
CHECK_FAILURE(m_controller->get_CoreWebView2(&m_webView));
CHECK_FAILURE(m_webView->add_WebMessageReceived(
Callback<ICoreWebView2WebMessageReceivedEventHandler>(
[=](ICoreWebView2 *sender, ICoreWebView2WebMessageReceivedEventArgs *args) noexcept
{
wil::unique_cotaskmem_string message;
CHECK_FAILURE(args->TryGetWebMessageAsString(&message));
if (std::wstring(L"FilesDropped") == message.get())
{
wil::com_ptr<ICoreWebView2WebMessageReceivedEventArgs2> args2 =
wil::com_ptr<ICoreWebView2WebMessageReceivedEventArgs>(args)
.query<ICoreWebView2WebMessageReceivedEventArgs2>();
if (args2)
{
wil::com_ptr<ICoreWebView2ObjectCollectionView>
objectsCollection;
CHECK_FAILURE(args2->get_AdditionalObjects(&objectsCollection));
unsigned int length;
CHECK_FAILURE(objectsCollection->get_Count(&length));
std::vector<std::wstring> paths;

for (unsigned int i = 0; i < length; i++)
{
wil::com_ptr<IUnknown> object;
CHECK_FAILURE(objectsCollection->GetValueAtIndex(i, &object));
// Note that objects can be null.
if (object)
{
wil::com_ptr<ICoreWebView2File> file =
object.query<ICoreWebView2File>();
if (file)
{
// Add the file to message to be sent back to webview
wil::unique_cotaskmem_string path;
CHECK_FAILURE(file->get_Path(&path));
paths.push_back(path.get());
}
}
}
// ProcessPaths(paths);
if (paths.size())
{
callback(paths[0].c_str());
}
}
}
return S_OK;
})
.Get(),
m_webMessageReceivedToken));
return S_OK;
}();
return m_webMessageReceivedToken;
}
6 changes: 3 additions & 3 deletions py/LunaTranslator/LunaTranslator.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
set_font_default,
_TR,
)
from ctypes import c_int, CFUNCTYPE, c_void_p
from myutils.utils import (
minmaxmoveobservefunc,
parsemayberegexreplace,
Expand Down Expand Up @@ -260,7 +259,6 @@ def displayinfomessage(self, text, infotype):
return
else:
msgs = [
("<msg_info_not_refresh>", False, False),
("<msg_info_refresh>", False, True),
("<msg_error_not_refresh>", True, False),
("<msg_error_refresh>", True, True),
Expand Down Expand Up @@ -1099,7 +1097,9 @@ def __init__(__, parent) -> None:
threading.Thread(
target=minmaxmoveobservefunc, args=(self.translation_ui,)
).start()
self.messagecallback__ = CFUNCTYPE(None, c_int, c_void_p)(self.messagecallback)
self.messagecallback__ = winsharedutils.globalmessagelistener_cb(
self.messagecallback
)
winsharedutils.globalmessagelistener(self.messagecallback__)
self.inittray()
self.playtimemanager = playtimemanager()
Expand Down
8 changes: 2 additions & 6 deletions py/LunaTranslator/LunaTranslator_main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import sys, os
from ctypes import windll, wintypes


def dopathexists(file: str):
Expand All @@ -12,10 +11,7 @@ def dopathexists(file: str):
file = windows.check_maybe_unc_file(file)
if not file:
return False
PathFileExists = windll.Shlwapi.PathFileExistsW
PathFileExists.argtypes = (wintypes.LPCWSTR,)
PathFileExists.restype = wintypes.BOOL
return bool(PathFileExists(os.path.abspath(file)))
return bool(windows.PathFileExists(os.path.abspath(file)))


def overridepathexists():
Expand All @@ -28,7 +24,7 @@ def prepareqtenv():

# win7 no vcredist2015
windows.addenvpath("./files/runtime/")
windows.loadlibrary("./files/runtime/PyQt5/Qt5/bin/Qt5Core.dll")
windows.LoadLibraryW("./files/runtime/PyQt5/Qt5/bin/Qt5Core.dll")

from qtsymbols import QApplication, isqt5, Qt, QFont, QLocale

Expand Down
7 changes: 5 additions & 2 deletions py/LunaTranslator/gui/rangeselect.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,14 +176,14 @@ def __init__(self, parent=None):
self.setAttribute(Qt.WidgetAttribute.WA_TranslucentBackground)
self.backlabel = QLabel(self)
self.rectlabel = QLabel(self)
self.backlabel.move(0, 0)
# self.setWindowOpacity(0.5)
self.setMouseTracking(True)
self.setCursor(Qt.CursorShape.CrossCursor)
self.reset()

def reset(self):
winsharedutils.maximum_window(int(self.winId()))
winsharedutils.maximum_window(int(self.backlabel.winId()))
self.once = True
self.is_drawing = False
self.start_point = QPoint()
Expand All @@ -200,6 +200,9 @@ def reset(self):
"background-color: rgba(255,255,255, %s)" % globalconfig["ocrselectalpha"]
)

def resizeEvent(self, e: QResizeEvent):
self.backlabel.resize(e.size())

def paintEvent(self, event):

if self.is_drawing:
Expand All @@ -224,7 +227,7 @@ def paintEvent(self, event):

def mousePressEvent(self, event):
if event.button() == Qt.MouseButton.RightButton:
self.once = False
self.once = False
self.close()
elif event.button() == Qt.MouseButton.LeftButton:
if self.startauto:
Expand Down
8 changes: 7 additions & 1 deletion py/LunaTranslator/gui/textbrowser.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
from qtsymbols import *
from myutils.config import globalconfig
import importlib, copy
import importlib, copy, os
from webviewpy import webview_exception
from gui.usefulwidget import getQMessageBox
from traceback import print_exc


class Textbrowser(QFrame):
contentsChanged = pyqtSignal(QSize)
dropfilecallback = pyqtSignal(str)

def resizeEvent(self, event: QResizeEvent):
self.textbrowser.resize(event.size())
Expand All @@ -24,6 +25,7 @@ def loadinternal(self):
if self.textbrowser:
self.textbrowser.hide()
self.textbrowser.contentsChanged.disconnect()
self.textbrowser.dropfilecallback.disconnect()
self.textbrowser.deleteLater()
if __ == "QWebEngine":
__ = "webview"
Expand Down Expand Up @@ -51,6 +53,7 @@ def loadinternal(self):
self.textbrowser.move(0, 0)
self.textbrowser.setMouseTracking(True)
self.textbrowser.contentsChanged.connect(self._contentsChanged)
self.textbrowser.dropfilecallback.connect(self.normdropfilepath)
self.textbrowser.resize(size)
self.textbrowser.show()
self.textbrowser.setselectable(globalconfig["selectable"])
Expand All @@ -59,6 +62,9 @@ def loadinternal(self):
self.textbrowser.showhidetranslate(globalconfig["showfanyi"])
self.refreshcontent()

def normdropfilepath(self, file):
self.dropfilecallback.emit(os.path.normpath(file))

def refreshcontent(self):
traces = self.trace.copy()
self.clear()
Expand Down
Loading

0 comments on commit 7de2923

Please sign in to comment.