forked from noah-/d2bs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCommandLine.cpp
96 lines (77 loc) · 2.9 KB
/
CommandLine.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
/*
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <windows.h>
#include <shlwapi.h>
#include <stdio.h>
#include <time.h>
#include "Offset.h"
#include "File.h"
#include "CommandLine.h"
#include "ArrayEx.h"
#define ArraySize(x) (sizeof((x)) / sizeof((x)[0]))
CArrayEx<sLine*, sLine*> aCommand;
// Commands.
sLine CLine[] = {{L"-d2c", 0}, {L"-d2x", 0}, {L"-title", 0}, {L"-mpq", 0}, {L"-profile", 0}, {L"-handle", 0}, {L"-multi", 0}, {L"-sleepy", 0}, {L"-cachefix", 0}};
DWORD ParseStringForText(LPWSTR Source, LPWSTR text) {
WCHAR BUF[4059];
memset(BUF, 0x00, 4059);
for (unsigned int x = 0; x < wcslen(Source); x++) {
if (wcslen(text) + x > wcslen(Source))
break;
for (unsigned int y = 0; y < wcslen(text); y++) {
INT cC = Source[x + y];
memcpy(BUF + wcslen(BUF), (LPWSTR)&cC, sizeof(cC));
}
if (!_wcsicmp(BUF, text))
return x;
memset(BUF, 0x00, 4059);
}
return -1;
}
VOID ParseCommandLine(LPWSTR Command) {
for (int x = 0; x < ArraySize(CLine); x++) {
DWORD id = ParseStringForText(Command, CLine[x].Param);
if (id == -1)
continue;
WCHAR szText[200];
BOOL bStart = false;
memset(szText, 0x00, 100);
if (!CLine[x].isBool) {
for (unsigned int y = (id + (wcslen(CLine[x].Param))); y < wcslen(Command); y++) {
if (Command[y] == L'"')
if (bStart) {
bStart = false;
break;
} else {
bStart = true;
y++;
}
int byt = Command[y];
if (bStart)
memcpy(szText + wcslen(szText), (LPWSTR)&byt, sizeof(byt));
}
}
sLine* sl = new sLine;
sl->isBool = CLine[x].isBool;
wcscpy_s(sl->Param, _countof(sl->Param), CLine[x].Param);
if (!sl->isBool)
wcscpy_s(sl->szText, _countof(sl->szText), szText);
aCommand.Add(sl);
}
}
sLine* GetCommand(LPWSTR Param) {
for (int x = 0; x < aCommand.GetSize(); x++)
if (!_wcsicmp(aCommand[x]->Param, Param))
return aCommand[x];
return 0;
}