2014-08-13 14:54:27 +02:00
|
|
|
#include "stdafx.h"
|
2014-08-23 02:16:54 +02:00
|
|
|
#include "rpcs3/Ini.h"
|
2014-08-13 14:54:27 +02:00
|
|
|
#include "AutoPause.h"
|
2014-08-22 16:21:55 +02:00
|
|
|
#include "Utilities/Log.h"
|
2015-04-24 23:38:11 +02:00
|
|
|
#include "Utilities/File.h"
|
2014-08-22 16:21:55 +02:00
|
|
|
#include "Emu/System.h"
|
2014-08-13 14:54:27 +02:00
|
|
|
|
|
|
|
using namespace Debug;
|
|
|
|
|
2015-05-08 11:45:21 +02:00
|
|
|
std::unique_ptr<AutoPause> g_autopause;
|
2014-08-13 14:54:27 +02:00
|
|
|
|
|
|
|
AutoPause& AutoPause::getInstance(void)
|
|
|
|
{
|
2015-05-08 11:45:21 +02:00
|
|
|
if (!g_autopause)
|
2014-08-13 14:54:27 +02:00
|
|
|
{
|
2015-05-08 11:45:21 +02:00
|
|
|
g_autopause.reset(new AutoPause);
|
2014-08-13 14:54:27 +02:00
|
|
|
}
|
2015-05-08 11:45:21 +02:00
|
|
|
|
|
|
|
return *g_autopause;
|
2014-08-13 14:54:27 +02:00
|
|
|
}
|
|
|
|
|
2014-08-17 09:53:09 +02:00
|
|
|
//Still use binary format. Default Setting should be "disable all auto pause".
|
2014-08-13 14:54:27 +02:00
|
|
|
AutoPause::AutoPause(void)
|
|
|
|
{
|
|
|
|
m_pause_function.reserve(16);
|
|
|
|
m_pause_syscall.reserve(16);
|
|
|
|
initialized = false;
|
|
|
|
//Reload(false, false);
|
2014-08-14 17:22:13 +02:00
|
|
|
Reload();
|
2014-08-13 14:54:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//Notice: I would not allow to write the binary to file in this command.
|
|
|
|
AutoPause::~AutoPause(void)
|
|
|
|
{
|
|
|
|
initialized = false;
|
|
|
|
m_pause_function.clear();
|
|
|
|
m_pause_syscall.clear();
|
|
|
|
m_pause_function_enable = false;
|
|
|
|
m_pause_syscall_enable = false;
|
|
|
|
}
|
|
|
|
|
2014-08-17 09:53:09 +02:00
|
|
|
//Load Auto Pause Configuration from file "pause.bin"
|
2014-08-13 14:54:27 +02:00
|
|
|
//This would be able to create in a GUI window.
|
|
|
|
void AutoPause::Reload(void)
|
|
|
|
{
|
2015-04-24 23:38:11 +02:00
|
|
|
if (fs::is_file("pause.bin"))
|
2014-08-13 14:54:27 +02:00
|
|
|
{
|
|
|
|
m_pause_function.clear();
|
|
|
|
m_pause_function.reserve(16);
|
|
|
|
m_pause_syscall.clear();
|
|
|
|
m_pause_syscall.reserve(16);
|
|
|
|
|
2015-04-24 23:38:11 +02:00
|
|
|
fs::file list("pause.bin");
|
2014-08-13 14:54:27 +02:00
|
|
|
//System calls ID and Function calls ID are all u32 iirc.
|
|
|
|
u32 num;
|
2015-04-19 15:19:24 +02:00
|
|
|
size_t fmax = list.size();
|
2014-08-13 14:54:27 +02:00
|
|
|
size_t fcur = 0;
|
2015-04-19 15:19:24 +02:00
|
|
|
list.seek(0);
|
2014-08-13 14:54:27 +02:00
|
|
|
while (fcur <= fmax - sizeof(u32))
|
|
|
|
{
|
2015-04-19 15:19:24 +02:00
|
|
|
list.read(&num, sizeof(u32));
|
2014-08-13 14:54:27 +02:00
|
|
|
fcur += sizeof(u32);
|
|
|
|
if (num == 0xFFFFFFFF) break;
|
|
|
|
|
|
|
|
if (num < 1024)
|
|
|
|
{
|
|
|
|
//Less than 1024 - be regarded as a system call.
|
|
|
|
//emplace_back may not cause reductant move/copy operation.
|
|
|
|
m_pause_syscall.emplace_back(num);
|
2014-09-29 17:38:04 +02:00
|
|
|
LOG_WARNING(HLE, "Auto Pause: Find System Call ID 0x%x", num);
|
2014-08-13 14:54:27 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_pause_function.emplace_back(num);
|
2014-09-29 17:38:04 +02:00
|
|
|
LOG_WARNING(HLE, "Auto Pause: Find Function Call ID 0x%x", num);
|
2014-08-13 14:54:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-04-19 19:14:16 +02:00
|
|
|
|
2014-08-14 17:22:13 +02:00
|
|
|
m_pause_syscall_enable = Ini.DBGAutoPauseSystemCall.GetValue();
|
|
|
|
m_pause_function_enable = Ini.DBGAutoPauseFunctionCall.GetValue();
|
2014-08-13 14:54:27 +02:00
|
|
|
initialized = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AutoPause::TryPause(u32 code) {
|
|
|
|
if (code < 1024)
|
|
|
|
{
|
|
|
|
//Would first check Enable setting. Then the list length.
|
|
|
|
if ((!m_pause_syscall_enable)
|
|
|
|
|| (m_pause_syscall.size() <= 0))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (u32 i = 0; i < m_pause_syscall.size(); ++i)
|
|
|
|
{
|
|
|
|
if (code == m_pause_syscall[i])
|
|
|
|
{
|
|
|
|
Emu.Pause();
|
2014-09-29 17:38:04 +02:00
|
|
|
LOG_ERROR(HLE, "Auto Pause Triggered: System call 0x%x", code); // Used Error
|
2014-08-13 14:54:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//Well similiar.. Seperate the list caused by possible setting difference.
|
|
|
|
if ((!m_pause_function_enable)
|
|
|
|
|| (m_pause_function.size() <= 0))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (u32 i = 0; i < m_pause_function.size(); ++i)
|
|
|
|
{
|
|
|
|
if (code == m_pause_function[i])
|
|
|
|
{
|
|
|
|
Emu.Pause();
|
2014-09-29 17:38:04 +02:00
|
|
|
LOG_ERROR(HLE, "Auto Pause Triggered: Function call 0x%x", code); // Used Error
|
2014-08-13 14:54:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-04-19 19:14:16 +02:00
|
|
|
}
|