-
Notifications
You must be signed in to change notification settings - Fork 0
/
sundry.cpp
105 lines (89 loc) · 1.96 KB
/
sundry.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#include "sundry.h"
#include "runtimeexception.h"
#include <QDebug>
/**
* @brief 互斥锁
*/
QMutex Sundry::m_mutex;
/**
* @brief 唯一实例
*/
Sundry *Sundry::m_instance = nullptr;
/**
* @brief 构造函数
*/
Sundry::Sundry(QObject *parent) : QObject(parent)
, m_goldAddress({0X2AC044, 0x0C, 0x0, 0x10, 0x10, 0x08, 0x0, 0x04, 0x0C, 0x14})
{
m_common = new GameCommon(this);
}
/**
* @brief 初始化
*/
void Sundry::initialize()
{
m_common->getProcessHandle("TWKPLAYER");
// rgss300.dll 模块地址
m_goldAddress.prepend(m_common->getModuleBaseAddress("rgss300.dll"));
}
/**
* @brief 单列模式
*
* @return 实例化
*/
Sundry *Sundry::getInstance()
{
if (!m_instance)
{
// 加锁
QMutexLocker lock(&m_mutex);
// 第二次检查
if (!m_instance)
{
m_instance = new Sundry;
m_instance->initialize();
}
}
return m_instance;
}
/**
* @brief 获取金币的值
*
* @return 金币的值
*/
int Sundry::getGoldValue()
{
QMutexLocker lock(&m_mutex);
// 获取基址
int value = m_common->readProcessMemoryValue<int>(m_goldAddress[0] + m_goldAddress[1]);
// 基址 + 偏移
for (int i = 2; i < m_goldAddress.size(); i++)
{
value = m_common->readProcessMemoryValue<int>(value + m_goldAddress[i]);
}
return value / 2;
}
/**
* @brief 设置金币
*
* @param[in] amount 数量
*/
void Sundry::setGoldValue(int amount)
{
amount = (amount *= 2) + 1;
// 获取基址
int value = m_common->readProcessMemoryValue<int>(m_goldAddress[0] + m_goldAddress[1]);
// 基址 + 偏移
for (int i = 2; i < m_goldAddress.size(); i++)
{
if (i == m_goldAddress.size() - 1)
{
value += m_goldAddress[i];
}
else
{
value = m_common->readProcessMemoryValue<int>(value + m_goldAddress[i]);
}
}
m_common->writeProcessMemoryValue<int>(value,&amount);
}