-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathpipe.cpp
More file actions
97 lines (74 loc) · 1.54 KB
/
pipe.cpp
File metadata and controls
97 lines (74 loc) · 1.54 KB
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
#include "pipe.h"
int pipe::appid = 0;
_iobuf* pipe::log = 0;
bool pipe::LoadConfig(const char* fn, bool test)
{
_iobuf* f = fopen(format("nanohack/%s", fn), "rb");
if (!f)
return 0;
fseek(f, 0, SEEK_END);
bool ok = 0;
if (ftell(f) == (sizeof(int) * MENU_ITEMS + sizeof(unsigned long) + 1))
{
int sh[MENU_ITEMS];
char h = 0;
//CRC_t m_crc;
rewind(f);
fread(&h, 1, 1, f);
fread(sh, 1, sizeof(sh), f);
//fread(&m_crc, 4, 1, f);
if (ok = (h == 'p' /* && (CRC32_ProcessSingleBuffer(sh, sizeof(sh)) == m_crc) */))
if (!test)
memcpy(menu, sh, sizeof(int) * MENU_ITEMS);
}
fclose(f);
return ok;
}
bool pipe::SaveConfig(const char* fn)
{
_iobuf* f = OpenFile(format("nanohack/%s", fn));
if (!f)
return 0;
//CRC32_t crc = CRC32_ProcessSingleBuffer(menu, sizeof(menu));
fwrite("p", 1, 1, f);
fwrite(menu, 1, sizeof(menu), f);
//fwrite(&crc, sizeof(crc), 1, f);
fclose(f);
return 1;
}
char* pipe::ModQuery()
{
if (!appid)
{
FILE* f = fopen("steam_appid.txt", "r");
if (!f)
return "unknown";
char a[10];
fread(a, 1, 10, f);
appid = atoi(a);
fclose(f);
}
switch (appid)
{
case 240: return "css";
case 300: return "dod";
case 440: return "tf2";
case 4000: return "gmod";
default: return "unknown";
}
}
_iobuf* pipe::OpenFile(const char* fn, const char* m)
{
if (access(fn, 0) == -1)
{
char p[MAX_PATH]; strcpy(p, fn);
for (unsigned i = 0; i < strlen(p); i++)
if (p[i] == '/')
{
char oldch = p[i]; p[i] = 0;
CreateDirectory(p, 0);
p[i] = oldch;
}
}
return fopen(fn, m);
}