-
Notifications
You must be signed in to change notification settings - Fork 11
/
utils.cpp
147 lines (121 loc) · 3.66 KB
/
utils.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
/*
THIS FILE IS A PART OF GTA V SCRIPT HOOK SDK
http://dev-c.com
(C) Alexander Blade 2015
*/
#include "utils.h"
#include <windows.h>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <vector>
#include "script.h"
extern "C" IMAGE_DOS_HEADER __ImageBase; // MSVC specific, with other compilers use HMODULE from DllMain
std::string cachedModulePath;
std::string GetCurrentModulePath()
{
if (cachedModulePath.empty())
{
// get module path
char modPath[MAX_PATH];
memset(modPath, 0, sizeof(modPath));
GetModuleFileNameA((HMODULE)&__ImageBase, modPath, sizeof(modPath));
for (size_t i = strlen(modPath); i > 0; i--)
{
if (modPath[i - 1] == '\\')
{
modPath[i] = 0;
break;
}
}
cachedModulePath = modPath;
}
return cachedModulePath;
}
std::string roundNumber(float number)
{
std::ostringstream out;
out << std::setprecision(1) << std::fixed << std::showpoint << number;
std::string roundResult = out.str();
return roundResult;
}
float actionInputFloat()
{
GAMEPLAY::DISPLAY_ONSCREEN_KEYBOARD(true, "FMMC_KEY_TIP8", "", "", "", "", "", 6);
while (GAMEPLAY::UPDATE_ONSCREEN_KEYBOARD() == 0) {
WAIT(0);
}
if (GAMEPLAY::IS_STRING_NULL_OR_EMPTY(GAMEPLAY::GET_ONSCREEN_KEYBOARD_RESULT())) {
log_to_file("Got null keyboard value");
return -1.0f;
}
char * keyboardValue = GAMEPLAY::GET_ONSCREEN_KEYBOARD_RESULT();
std::string strValue = std::string(keyboardValue);
log_to_file("Got keyboard value " + strValue);
return atof(keyboardValue);
}
DWORD actionInputDword()
{
GAMEPLAY::DISPLAY_ONSCREEN_KEYBOARD(true, "FMMC_KEY_TIP8", "", "", "", "", "", 6);
while (GAMEPLAY::UPDATE_ONSCREEN_KEYBOARD() == 0) {
WAIT(0);
}
if (GAMEPLAY::IS_STRING_NULL_OR_EMPTY(GAMEPLAY::GET_ONSCREEN_KEYBOARD_RESULT())) {
log_to_file("Got null keyboard value");
return 0;
}
char * keyboardValue = GAMEPLAY::GET_ONSCREEN_KEYBOARD_RESULT();
std::string strValue = std::string(keyboardValue);
log_to_file("Got keyboard value " + strValue);
return atoi(keyboardValue);
}
std::string actionInputString(int maxLength)
{
GAMEPLAY::DISPLAY_ONSCREEN_KEYBOARD(true, "FMMC_KEY_TIP8", "", "", "", "", "", maxLength);
while (GAMEPLAY::UPDATE_ONSCREEN_KEYBOARD() == 0) {
WAIT(0);
}
if (GAMEPLAY::IS_STRING_NULL_OR_EMPTY(GAMEPLAY::GET_ONSCREEN_KEYBOARD_RESULT())) {
log_to_file("Got null keyboard value");
return std::string();
}
char * keyboardValue = GAMEPLAY::GET_ONSCREEN_KEYBOARD_RESULT();
std::string strValue = std::string(keyboardValue);
log_to_file("Got keyboard value " + strValue);
return strValue;
}
//from http://stackoverflow.com/a/236803
Vector3 MathUtils::rotationToDirection(Vector3 rotation)
{
//big thanks to camxxcore's C# code https://github.com/CamxxCore/ScriptCamTool/blob/master/GTAV_ScriptCamTool/Utils.cs
float retZ = rotation.z * 0.01745329f;
float retX = rotation.x * 0.01745329f;
float absX = abs(cos(retX));
Vector3 retVector = { 0.0,0.0,0.0 };
retVector.x = (float)-(sin(retZ) * absX);
retVector.y = (float)cos(retZ) * absX;
retVector.z = (float)sin(retX);
return retVector;
}
Vector3 MathUtils::crossProduct(Vector3 a, Vector3 b)
{
//http://onlinemschool.com/math/assistance/vector/multiply1/
Vector3 retVector = { 0.0,0.0,0.0 };
retVector.x = a.y*b.z - a.z*b.y;
retVector.y = a.z*b.x - a.x*b.z;
retVector.z = a.x*b.y - a.y*b.x;
return retVector;
}
void StringUtils::split(const std::string &s, char delim, std::vector<std::string> &elems) {
std::stringstream ss;
ss.str(s);
std::string item;
while (std::getline(ss, item, delim)) {
elems.push_back(item);
}
}
std::vector<std::string> StringUtils::split(const std::string &s, char delim) {
std::vector<std::string> elems;
split(s, delim, elems);
return elems;
}