Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
bestkakkoii authored and bestkakkoii committed Mar 10, 2024
1 parent 2cff173 commit 26774a9
Show file tree
Hide file tree
Showing 13 changed files with 436 additions and 355 deletions.
61 changes: 44 additions & 17 deletions SaSH/form/scriptform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,15 @@ ScriptForm::ScriptForm(long long index, QWidget* parent)
connect(&signalDispatcher, &SignalDispatcher::loadFileToTable, this, &ScriptForm::loadFile, Qt::QueuedConnection);
connect(&signalDispatcher, &SignalDispatcher::reloadScriptList, this, &ScriptForm::onReloadScriptList, Qt::QueuedConnection);
connect(&signalDispatcher, &SignalDispatcher::scriptStarted, this, &ScriptForm::onScriptStarted, Qt::QueuedConnection);
connect(&signalDispatcher, &SignalDispatcher::scriptStoped, this, &ScriptForm::onScriptStoped, Qt::QueuedConnection);

connect(&signalDispatcher, &SignalDispatcher::scriptPaused, this, &ScriptForm::onScriptPausedMode, Qt::QueuedConnection);

connect(&signalDispatcher, &SignalDispatcher::scriptPaused, this, &ScriptForm::onScriptPaused, Qt::QueuedConnection);

connect(&signalDispatcher, &SignalDispatcher::scriptResumed, this, &ScriptForm::onScriptResumedMode, Qt::QueuedConnection);

connect(&signalDispatcher, &SignalDispatcher::scriptResumed, this, &ScriptForm::onScriptResumed, Qt::QueuedConnection);

connect(&signalDispatcher, &SignalDispatcher::scriptBreaked, this, &ScriptForm::onScriptResumed, Qt::QueuedConnection);

connect(&signalDispatcher, &SignalDispatcher::applyHashSettingsToUI, this, &ScriptForm::onApplyHashSettingsToUI, Qt::QueuedConnection);
Expand Down Expand Up @@ -127,14 +133,13 @@ void ScriptForm::onScriptPaused()
if (!gamedevice.IS_SCRIPT_FLAG.get())
return;

if (interpreter_ != nullptr)
{
if (!gamedevice.isScriptPaused())
{
ui.pushButton_script_pause->setText(tr("resume"));
gamedevice.paused();
}
}
if (interpreter_ == nullptr)
return;

if (gamedevice.isScriptPaused())
return;

gamedevice.paused();
}

void ScriptForm::onScriptResumed()
Expand All @@ -143,15 +148,37 @@ void ScriptForm::onScriptResumed()
if (!gamedevice.IS_SCRIPT_FLAG.get())
return;

if (interpreter_ != nullptr)
{
if (interpreter_ == nullptr)
return;

if (gamedevice.isScriptPaused())
{
ui.pushButton_script_pause->setText(tr("pause"));
gamedevice.resumed();
}
}
if (!gamedevice.isScriptPaused())
return;

gamedevice.resumed();
}

void ScriptForm::onScriptPausedMode()
{
GameDevice& gamedevice = GameDevice::getInstance(getIndex());
if (!gamedevice.IS_SCRIPT_FLAG.get())
return;

if (!gamedevice.isScriptPaused())
return;

ui.pushButton_script_pause->setText(tr("resume"));
}

void ScriptForm::onScriptResumedMode()
{
GameDevice& gamedevice = GameDevice::getInstance(getIndex());
if (!gamedevice.IS_SCRIPT_FLAG.get())
return;

if (gamedevice.isScriptPaused())
return;

ui.pushButton_script_pause->setText(tr("pause"));
}

void ScriptForm::onScriptStoped()
Expand Down
4 changes: 4 additions & 0 deletions SaSH/form/scriptform.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,12 @@ private slots:

void onScriptPaused();

void onScriptPausedMode();

void onScriptResumed();

void onScriptResumedMode();

void onScriptStoped();

void onScriptFinished();
Expand Down
96 changes: 96 additions & 0 deletions SaSH/gamedevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,102 @@ bool GameDevice::isHandleValid(long long pid)
return true;
}

bool GameDevice::capture(const QString& fileName) const
{
if (!isValid())
return false;

QFileInfo fileInfo(fileName);
//check is a valid path
if (fileInfo.absolutePath().isEmpty() || fileInfo.fileName().isEmpty())
return false;

//check png suffix
if (fileInfo.suffix().toLower() != "png")
return false;

long long currentIndex = getIndex();

//取桌面指針
QScreen* screen = QGuiApplication::primaryScreen();
if (nullptr == screen)
{
return false;
}

//遊戲後臺滑鼠一移動到左上
LPARAM data = MAKELPARAM(0, 0);
sendMessage(WM_MOUSEMOVE, NULL, data);

//根據HWND擷取窗口後臺圖像
QPixmap pixmap = screen->grabWindow(reinterpret_cast<WId>(getProcessWindow()));

//轉存為QImage
QImage image = pixmap.toImage();

//only take middle part of the image
image = image.copy(269, 226, 102, 29);//368,253

if (QFile::exists(fileName))
QFile::remove(fileName);

return image.save(fileName, "PNG");
}

QString GameDevice::ecbDecrypt(long long address) const
{
mem::VirtualMemory lpDst(processHandle_, 32, true);
sendMessage(kECBCrypt, getProcessModule() + address, lpDst);
return mem::readString(processHandle_, lpDst, 32);
}

QByteArray GameDevice::ecbEncrypt(const QString& str) const
{
mem::VirtualMemory lpSrc(processHandle_, str, mem::VirtualMemory::kAnsi, true);
mem::VirtualMemory lpDst(processHandle_, 32, true);

sendMessage(kECBEncrypt, lpSrc, lpDst);
QByteArray result(32, '\0');
mem::read(processHandle_, lpDst, 32, result.data());
return result;
}

void GameDevice::paused()
{
if (isScriptPaused())
return;

SignalDispatcher& signalDispatcher = SignalDispatcher::getInstance(getIndex());
emit signalDispatcher.scriptPaused();

{
std::unique_lock<std::mutex> lock(scriptPausedMutex_);
isScriptPaused_.on();
}
}

void GameDevice::resumed()
{
if (!isScriptPaused())
return;

{
std::unique_lock<std::mutex> lock(scriptPausedMutex_);
isScriptPaused_.off();
}

scriptPausedCondition_.notify_all();
}

void GameDevice::checkScriptPause()
{
if (isScriptPaused())
{
std::unique_lock<std::mutex> lock(scriptPausedMutex_);
scriptPausedCondition_.wait(lock);
}
}

#if 0
DWORD WINAPI GameDevice::getFunAddr(const DWORD* DllBase, const char* FunName)
{
Expand Down
98 changes: 7 additions & 91 deletions SaSH/gamedevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,115 +177,31 @@ class GameDevice : public QObject, public Indexer

void __fastcall dragto(long long x1, long long y1, long long x2, long long y2) const;

bool __fastcall capture(const QString& fileName) const
{
if (!isValid())
return false;

QFileInfo fileInfo(fileName);
//check is a valid path
if (fileInfo.absolutePath().isEmpty() || fileInfo.fileName().isEmpty())
return false;

//check png suffix
if (fileInfo.suffix().toLower() != "png")
return false;

long long currentIndex = getIndex();

//取桌面指針
QScreen* screen = QGuiApplication::primaryScreen();
if (nullptr == screen)
{
return false;
}

//遊戲後臺滑鼠一移動到左上
LPARAM data = MAKELPARAM(0, 0);
sendMessage(WM_MOUSEMOVE, NULL, data);

//根據HWND擷取窗口後臺圖像
QPixmap pixmap = screen->grabWindow(reinterpret_cast<WId>(getProcessWindow()));

//轉存為QImage
QImage image = pixmap.toImage();

//only take middle part of the image
image = image.copy(269, 226, 102, 29);//368,253

if (QFile::exists(fileName))
QFile::remove(fileName);

return image.save(fileName, "PNG");
}
bool __fastcall capture(const QString& fileName) const;

void __fastcall hide(long long mode = 0) const;

void __fastcall show() const;

QString __fastcall getPointFileName() const;

QString __fastcall ecbDecrypt(long long address) const
{
mem::VirtualMemory lpDst(processHandle_, 32, true);
sendMessage(kECBCrypt, getProcessModule() + address, lpDst);
return mem::readString(processHandle_, lpDst, 32);
}

QByteArray __fastcall ecbEncrypt(const QString& str) const
{
mem::VirtualMemory lpSrc(processHandle_, str, mem::VirtualMemory::kAnsi, true);
mem::VirtualMemory lpDst(processHandle_, 32, true);
QString __fastcall ecbDecrypt(long long address) const;

sendMessage(kECBEncrypt, lpSrc, lpDst);
QByteArray result(32, '\0');
mem::read(processHandle_, lpDst, 32, result.data());
return result;
}
QByteArray __fastcall ecbEncrypt(const QString& str) const;

inline void __fastcall setParentWidget(HWND parentWidget) { parentWidget_ = parentWidget; }

[[nodiscard]] inline HWND __fastcall getParentWidget() const { return parentWidget_; }

inline bool __fastcall isScriptPaused() const { return isScriptPaused_.get(); }

inline void __fastcall checkScriptPause()
{
if (isScriptPaused())
{
std::unique_lock<std::mutex> lock(scriptPausedMutex_);
scriptPausedCondition_.wait(lock);
}
}

inline void __fastcall paused()
{
if (isScriptPaused())
return;

{
std::unique_lock<std::mutex> lock(scriptPausedMutex_);
isScriptPaused_.on();
}
}

inline void __fastcall resumed()
{
if (!isScriptPaused())
return;
void __fastcall checkScriptPause();

{
std::unique_lock<std::mutex> lock(scriptPausedMutex_);
isScriptPaused_.off();
}
void __fastcall paused();

scriptPausedCondition_.notify_all();
}
void __fastcall resumed();

inline void stopScript()
{
IS_SCRIPT_INTERRUPT.on();
}
inline void __fastcall stopScript() { IS_SCRIPT_INTERRUPT.on(); }

private:
static BOOL CALLBACK EnumWindowsCallback(HWND handle, LPARAM lParam)
Expand Down
Loading

0 comments on commit 26774a9

Please sign in to comment.