forked from holalula/HaiBinQiangJia
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ChocoboFFXIV.cpp
226 lines (190 loc) · 5.85 KB
/
ChocoboFFXIV.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
#include "ChocoboFFXIV.h"
#include "ui_ChocoboFFXIV.h"
#include <cstdlib>
#include "QDoubleValidator"
#include "EXPORT.h"
#include "IMPORT.h"
#include "ITEMINFO.h"
#include <QTimer>
#include <QTime>
#include <QMessageBox>
ChocoboFFXIV::ChocoboFFXIV(QWidget *parent)
: QMainWindow(parent)
{
if (!IsRunasAdmin()) {
QMessageBox::warning(this, "WARNING", QStringLiteral("请以管理员身份运行!"));
exit(0);
}
ui.setupUi(this);
//if (RegisterHotKey(HWND(this->winId()), 1, MOD_CONTROL | MOD_NOREPEAT, VK_F12))
fp.GetPidByName(L"最终幻想XIV");
fp.OpenProcessByPid();
fp.GetBaseAddressByPid();
if(fp.GetPid()!=0){
ui.tlabel->setText(QStringLiteral("已启动FFXIV"));
timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(updatePos()));
timer2 = new QTimer(this);
connect(timer2, SIGNAL(timeout()), this, SLOT(checkwhere()));
timer2->start(500);
{
double pos_bottom = -100.0;
double pos_top = 100.0;
ui.le_px->setValidator(new QDoubleValidator(pos_bottom, pos_top, 3, this));
ui.le_py->setValidator(new QDoubleValidator(pos_bottom, pos_top, 3, this));
ui.le_pz->setValidator(new QDoubleValidator(pos_bottom, pos_top, 3, this));
}
{
connect(ui.cb_placeanywhere, SIGNAL(stateChanged(int)), this, SLOT(cb_placeanywhere_on_stateChanged(int)));
connect(ui.cb_activepos, SIGNAL(stateChanged(int)), this, SLOT(cb_activepos_on_stateChanged(int)));
connect(ui.le_px, SIGNAL(editingFinished()), this, SLOT(le_px_on_editingFinished()));
connect(ui.le_py, SIGNAL(editingFinished()), this, SLOT(le_py_on_editingFinished()));
connect(ui.le_pz, SIGNAL(editingFinished()), this, SLOT(le_pz_on_editingFinished()));
connect(ui.pb_export, SIGNAL(clicked()), this, SLOT(pb_export_on_clicked()));
connect(ui.pb_import, SIGNAL(clicked()), this, SLOT(pb_import_on_clicked()));
connect(ui.pb_copy, SIGNAL(clicked()), this, SLOT(pb_copy_on_clicked()));
connect(ui.le_px, SIGNAL(textEdited()), this, SLOT(le_px_on_textEdited()));
connect(ui.le_py, SIGNAL(textEdited()), this, SLOT(le_py_on_textEdited()));
connect(ui.le_pz, SIGNAL(textEdited()), this, SLOT(le_pz_on_textEdited()));
}
}
else {
ui.tlabel->setText(QStringLiteral("未启动FFXIV,请确保开启dx11并以管理员开启本程序"));
}
}
ChocoboFFXIV::~ChocoboFFXIV() {
UnregisterHotKey(HWND(this->winId()), 1);
}
void ChocoboFFXIV::labelDebug(QString str) {
}
bool ChocoboFFXIV::nativeEvent(const QByteArray& eventType, void* message, long* result) {
if (eventType == "windows_generic_MSG")
{
MSG* pMsg = reinterpret_cast<MSG*>(message);
if (pMsg->message == WM_HOTKEY)
{
if (pMsg->wParam == 1) {
//ui.tlabel->setText(QStringLiteral("已按下ctrl+f12"));
}
}
}
return QWidget::nativeEvent(eventType, message, result);
}
void ChocoboFFXIV::cb_placeanywhere_on_stateChanged(int a) {
if (a == Qt::Checked) {
fp.InjectPlaceAnywhere();
}
else {
fp.reInjectPlaceAnywhere();
}
}
void ChocoboFFXIV::checkwhere() {
int iw = fp.IsWarehouse();
if (iw == 2) {
ui.iswarehouse->setText(QStringLiteral("已布置"));
}
else if (iw == 1) {
ui.iswarehouse->setText(QStringLiteral("仓库"));
}
else if (iw == -1) {
ui.iswarehouse->setText(QStringLiteral("庭院"));
QString title = "???????";
qsrand(QTime(0, 0, 0).secsTo(QTime::currentTime()));
int tt = qrand()%3; //02
QString info;
if (tt == 0) {
info = QStringLiteral("人女天下第一!");
}
else if (tt == 1) {
info = QStringLiteral("拉拉肥是什么东西啊!");
}
else if (tt == 2) {
info = QStringLiteral("猫娘爪巴!");
}
QMessageBox::critical(this, title, info);
exit(0);
}
else {
ui.iswarehouse->setText(QStringLiteral("未检测到_"));
}
}
void ChocoboFFXIV::updatePos() {
vector<float> pos = fp.GetActiveItemPos();
float npx, npy, npz;
npx = pos[0];
npy = pos[1];
npz = pos[2];
ui.l_px->setText(QString::number(npx,'f',3));
ui.l_py->setText(QString::number(npy, 'f', 3));
ui.l_pz->setText(QString::number(npz, 'f', 3));
}
void ChocoboFFXIV::cb_activepos_on_stateChanged(int a) {
if (a == Qt::Checked) {
vector<float> pos = fp.GetActiveItemPos();
ui.le_px->setText(QString::number(pos[0], 'f', 3));
ui.le_py->setText(QString::number(pos[1], 'f', 3));
ui.le_pz->setText(QString::number(pos[2], 'f', 3));
ui.l_px->setText(QString::number(pos[0], 'f', 3));
ui.l_py->setText(QString::number(pos[1], 'f', 3));
ui.l_pz->setText(QString::number(pos[2], 'f', 3));
timer->start(200);
}
else {
timer->stop();
}
}
void ChocoboFFXIV::le_px_on_editingFinished() {
fp.SetActiveItemX(ui.le_px->text().toFloat());
}
void ChocoboFFXIV::le_py_on_editingFinished() {
fp.SetActiveItemY(ui.le_py->text().toFloat());
}
void ChocoboFFXIV::le_pz_on_editingFinished() {
fp.SetActiveItemZ(ui.le_pz->text().toFloat());
}
void ChocoboFFXIV::pb_export_on_clicked() {
EXPORT* ExportWindow = new EXPORT(Q_NULLPTR);
ExportWindow->SetFp(&fp);
ExportWindow->setWindowFlags(Qt::WindowStaysOnTopHint);
ExportWindow->show();
}
void ChocoboFFXIV::pb_import_on_clicked() {
IMPORT* ImportWindow = new IMPORT(Q_NULLPTR);
ImportWindow->SetFp(&fp);
ImportWindow->setWindowFlags(Qt::WindowStaysOnTopHint);
ImportWindow->show();
}
void ChocoboFFXIV::pb_copy_on_clicked(){
//ui.l_px.
ui.le_px->setText(ui.l_px->text());
ui.le_py->setText(ui.l_py->text());
ui.le_pz->setText(ui.l_pz->text());
}
BOOL ChocoboFFXIV::IsRunasAdmin()
{
BOOL bElevated = FALSE;
HANDLE hToken = NULL;
// Get current process token
if (!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &hToken))
return FALSE;
TOKEN_ELEVATION tokenEle;
DWORD dwRetLen = 0;
// Retrieve token elevation information
if (GetTokenInformation(hToken, TokenElevation, &tokenEle, sizeof(tokenEle), &dwRetLen))
{
if (dwRetLen == sizeof(tokenEle))
{
bElevated = tokenEle.TokenIsElevated;
}
}
CloseHandle(hToken);
return bElevated;
}
/*
void ChocoboFFXIV::le_px_on_textEdited() {
}
void ChocoboFFXIV::le_py_on_textEdited() {
}
void ChocoboFFXIV::le_pz_on_textEdited() {
}//textEdited
*/