-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUtils.cpp
169 lines (155 loc) · 3.82 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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#pragma once
#include <Windows.h>
#include <TlHelp32.h>
#include "Utils.h"
#include <utility>
#include <string>
#include <locale>
#include <codecvt>
#include <algorithm>
#include <cwctype>
namespace Utils {
unsigned long GetProcessIdByName(const wchar_t* ProcName) {
PROCESSENTRY32 pe32{ sizeof(PROCESSENTRY32) };
HANDLE hSnapshot = NULL;
unsigned long result = 0;
hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if (Process32First(hSnapshot, &pe32)) {
do {
if (wcscmp(ProcName, pe32.szExeFile) == 0) {
result = pe32.th32ProcessID;
break;
}
} while (Process32Next(hSnapshot, &pe32));
}
CloseHandle(hSnapshot);
return result;
}
void TransposeMatrix(float* matrix) {
std::swap(*(matrix + 1), *(matrix + 4));
std::swap(*(matrix + 2), *(matrix + 8));
std::swap(*(matrix + 3), *(matrix + 12));
std::swap(*(matrix + 6), *(matrix + 9));
std::swap(*(matrix + 7), *(matrix + 13));
std::swap(*(matrix + 11), *(matrix + 14));
}
float LerpF(float a, float b, float t) {
return a + t * (b - a);
}
const std::wstring GetRoleName(int role) {
switch (role) {
case 5:
case 8:
case 12:
case 13:
case 14:
case 15:
case 16:
case 30:
{
return L"Minion";
}
case 0:
{
return L"Sniper";
}
case 1:
{
return L"Assault";
}
case 3:
{
return L"Reshala";
}
case 6:
{
return L"Killa";
}
case 7:
{
return L"P. Sherman";
}
case 9:
{
return L"Raider";
}
case 10:
{
return L"CAssault";
}
case 11:
{
return L"Gluhar";
}
case 17:
{
return L"Sanitar";
}
case 19:
{
return L"GAssault";
}
case 20:
{
return L"Cultist";
}
case 21:
{
return L"Priest";
}
case 22:
{
return L"Tagilla";
}
case 24:
{
return L"Rogue";
}
case 25:
{
return L"Santa";
}
case 26:
{
return L"Knight";
}
case 27:
{
return L"Big Pipe";
}
case 28:
{
return L"Bird Eye";
}
case 29:
{
return L"Sriracha";
}
}
return L"Unknown";
}
bool IsValidWChar(wchar_t value) {
return
value >= 48 && value <= 57 || // 0-9
value >= 65 && value <= 90 || // A-Z
value >= 97 && value <= 122 || // a-z
value == L'-' || value == L'_'; // only special characters I know of that can be used
}
unsigned int HashString(const std::string& input) {
const unsigned int FNV_PRIME = 16777619;
const unsigned int OFFSET_BASIS = 2166136261;
unsigned int hash = OFFSET_BASIS;
for (char c : input) {
hash ^= static_cast<unsigned int>(c);
hash *= FNV_PRIME;
}
return hash;
}
bool ContainsIgnoreCase(const std::wstring& str, const std::wstring& substr) {
std::wstring strLower = str;
std::wstring substrLower = substr;
std::transform(strLower.begin(), strLower.end(), strLower.begin(), std::towlower);
std::transform(substrLower.begin(), substrLower.end(), substrLower.begin(), std::towlower);
return strLower.find(substrLower) != std::wstring::npos;
}
}