-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexportfuncs.cpp
More file actions
128 lines (108 loc) · 3.56 KB
/
Copy pathexportfuncs.cpp
File metadata and controls
128 lines (108 loc) · 3.56 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
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
#include "plugins.h"
#include <fstream>
#include <string>
#include <vector>
#include <cstdio>
static float s_enter_time = 0.f;
static bool s_underwater = false;
static bool s_map_allowed = true;
static float s_original_fps = 100.0f;
static bool s_fps_saved = false;
static std::vector<std::string> s_map_list;
void LoadMapList(void)
{
s_map_list.clear();
std::string path = std::string(g_pMetaHookAPI->GetGameDirectory()) + "/uwFPS/maps.ini";
std::ifstream file(path);
if (!file.is_open()) return;
std::string line;
while (std::getline(file, line)) {
if (line.empty() || line[0] == ';' || line[0] == '#') continue;
size_t first = line.find_first_not_of(" \t\r\n");
if (first == std::string::npos) continue;
size_t last = line.find_last_not_of(" \t\r\n");
s_map_list.push_back(line.substr(first, last - first + 1));
}
}
void RestoreFPS(void)
{
if (!s_fps_saved) return;
float target = (IsCvarExists(uw_fps_normal) && uw_fps_normal->value > 0)
? uw_fps_normal->value : s_original_fps;
char cmd[64];
sprintf_s(cmd, "fps_max %.0f", target);
gEngfuncs.pfnClientCmd(cmd);
s_fps_saved = false;
}
bool IsMapAllowed(const char* mapname)
{
if (!mapname || !mapname[0]) return true;
std::string map = mapname;
if (map.find("maps/") == 0) map.erase(0, 5);
if (map.size() > 4 && map.substr(map.size() - 4) == ".bsp") map.resize(map.size() - 4);
bool found = false;
for (const auto& m : s_map_list) {
if (m == map) { found = true; break; }
}
int mode = IsCvarExists(uw_mode) ? (int)uw_mode->value : 0;
return (mode != 0) ? found : !found;
}
void uw_toggle_f(void)
{
if (!IsCvarExists(uw_auto)) return;
float newVal = (uw_auto->value > 0) ? 0.0f : 1.0f;
gEngfuncs.Cvar_SetValue("uw_auto", newVal);
if (newVal > 0) {
gEngfuncs.pfnCenterPrint("uwFPS: ENABLED");
} else {
gEngfuncs.pfnCenterPrint("uwFPS: DISABLED");
RestoreFPS();
}
gEngfuncs.pfnClientCmd("spk buttons/lightswitch2\n");
}
void HUD_Init(void)
{
uwFPS_Init();
if (g_pfnHUD_Init) g_pfnHUD_Init();
}
int HUD_VidInit(void)
{
LoadMapList();
s_fps_saved = false;
s_underwater = false;
const char* levelname = gEngfuncs.pfnGetLevelName();
if (levelname) s_map_allowed = IsMapAllowed(levelname);
return g_pfnHUD_VidInit ? g_pfnHUD_VidInit() : 1;
}
void HUD_Frame(double time)
{
if (g_pfnHUD_Frame) g_pfnHUD_Frame(time);
}
void V_CalcRefdef(struct ref_params_s* pparams)
{
if (g_pfnV_CalcRefdef) g_pfnV_CalcRefdef(pparams);
if (!IsCvarExists(uw_auto) || uw_auto->value == 0 || !s_map_allowed) return;
if (pparams->spectator != 0 || pparams->health <= 0 || pparams->intermission != 0)
return;
float now = (float)gEngfuncs.GetClientTime();
int threshold = IsCvarExists(uw_trigger_level) ? (int)uw_trigger_level->value : 3;
bool in_water = pparams->waterlevel >= threshold;
if (in_water != s_underwater) {
s_enter_time = now;
s_underwater = in_water;
}
float delay = IsCvarExists(uw_delay) ? uw_delay->value : 0.3f;
if (now - s_enter_time < delay) return;
if (s_underwater) {
if (!s_fps_saved) {
s_original_fps = gEngfuncs.pfnGetCvarFloat("fps_max");
s_fps_saved = true;
float target = IsCvarExists(uw_fps_underwater) ? uw_fps_underwater->value : 20.0f;
char cmd[64];
sprintf_s(cmd, "fps_max %.0f", target);
gEngfuncs.pfnClientCmd(cmd);
}
} else {
RestoreFPS();
}
}