-
Notifications
You must be signed in to change notification settings - Fork 173
Expand file tree
/
Copy pathmapmigrations.cpp
More file actions
198 lines (163 loc) · 7.85 KB
/
Copy pathmapmigrations.cpp
File metadata and controls
198 lines (163 loc) · 7.85 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
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
/**
* =============================================================================
* CS2Fixes
* Copyright (C) 2023-2026 Source2ZE
* =============================================================================
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, version 3.0, as published by the
* Free Software Foundation.
*
* 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 General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "mapmigrations.h"
#include "cs2fixes.h"
#include "entity.h"
#include "entity/cbasetoggle.h"
#include "map_votes.h"
#include "utils.h"
#include "vprof.h"
CMapMigrations* g_pMapMigrations = nullptr;
const time_t g_time20260121 = 1769036239;
const time_t g_time20260420 = 1776725888;
const time_t g_time20260922 = 1790120204;
CConVar<int> g_cvarMapMigrations20260121("cs2f_mapmigrations_20260121", FCVAR_NONE, "Current mode for 2026-01-21 CS2 update map migrations. [0 = Force disabled, 1 = Force enabled, 2 = Automatically enabled for maps updated before 2026-01-21 & disabled if updated after]", 2);
CConVar<int> g_cvarMapMigrations20260420("cs2f_mapmigrations_20260420", FCVAR_NONE, "Current mode for 2026-04-20 CS2 update map migrations. [0 = Force disabled, 1 = Force enabled, 2 = Automatically enabled for maps updated before 2026-04-20 & disabled if updated after]", 2);
CConVar<int> g_cvarMapMigrations20260922("cs2f_mapmigrations_20260922", FCVAR_NONE, "Current mode for 2026-09-22 CS2 update map migrations. [0 = Force disabled, 1 = Force enabled, 2 = Automatically enabled for maps updated before 2026-09-22 & disabled if updated after]", 2);
void CMapMigrations::PreLevelLoad(uint64 iWorkshopId)
{
m_timeMapUpdated = std::numeric_limits<time_t>::max();
// Don't run on default maps
if (iWorkshopId != 0)
{
if (m_mapUpdateTimes.contains(iWorkshopId))
m_timeMapUpdated = m_mapUpdateTimes[iWorkshopId];
else
Message("Skipping pre-load map migrations for %llu, update time is not available\n", iWorkshopId);
}
}
void CMapMigrations::ApplyGameSettings(uint64 iWorkshopId)
{
// If map update time wasn't available before map load, try to get the update time anyways, for later migrations
if (iWorkshopId != 0 && !m_mapUpdateTimes.contains(iWorkshopId))
CMapSystemWorkshopDetailsQuery::Create(iWorkshopId);
}
void CMapMigrations::OnRoundPrestart()
{
m_vecEquippedWeapons.clear();
}
void CMapMigrations::OnEquipWeapon(CBasePlayerWeapon* pWeapon)
{
if (Migrations20260420Enabled())
Migrations_20260420(pWeapon);
}
bool CMapMigrations::Detour_CEntityIdentity_AcceptInput(CEntityIdentity* pThis, CUtlSymbolLarge* pInputName, CEntityInstance* pActivator, CEntityInstance* pCaller, variant_t* value)
{
if (g_cvarMapMigrations20260922.Get() == 1 || (g_cvarMapMigrations20260922.Get() == 2 && m_timeMapUpdated < g_time20260922))
return Migrations_20260922(pThis, pInputName, pActivator, pCaller, value);
return false;
}
void CMapMigrations::RunMigrations(CUtlVector<CEntityKeyValues*>* pVecEntityKeyValues)
{
if (g_cvarMapMigrations20260121.Get() > 0)
Migrations_Rendermode(pVecEntityKeyValues);
if (g_cvarMapMigrations20260121.Get() == 1 || (g_cvarMapMigrations20260121.Get() == 2 && m_timeMapUpdated < g_time20260121))
Migrations_20260121(pVecEntityKeyValues);
}
void CMapMigrations::Migrations_Rendermode(CUtlVector<CEntityKeyValues*>* pVecEntityKeyValues)
{
FOR_EACH_VEC(*pVecEntityKeyValues, i)
{
auto pKeyValues = (*pVecEntityKeyValues)[i];
if (!pKeyValues->HasValue("rendermode"))
continue;
int renderMode = V_StringToInt32(pKeyValues->GetString("rendermode"), -1, NULL, NULL, PARSING_FLAG_SKIP_WARNING);
// Enum-named render modes already migrate correctly
if (renderMode == -1)
continue;
if (renderMode == 4)
pKeyValues->SetString("rendermode", "kRenderTransAlpha");
else if (renderMode == 10)
pKeyValues->SetString("rendermode", "kRenderNone");
// All other removed render modes, fall back to normal
else if (renderMode > kRenderNormal)
pKeyValues->SetString("rendermode", "kRenderNormal");
}
}
void CMapMigrations::Migrations_20260121(CUtlVector<CEntityKeyValues*>* pVecEntityKeyValues)
{
FOR_EACH_VEC(*pVecEntityKeyValues, i)
{
auto pKeyValues = (*pVecEntityKeyValues)[i];
if (!V_strcasecmp(pKeyValues->GetString("classname"), "func_door_rotating") && pKeyValues->HasValue("spawnflags"))
{
uint32 spawnFlags = pKeyValues->GetUint("spawnflags");
pKeyValues->SetUint("spawnflags", spawnFlags | SF_DOOR_ONEWAY);
}
}
}
void CMapMigrations::Migrations_20260420(CBasePlayerWeapon* pWeapon)
{
VPROF("CMapMigrations::Migrations_20260420");
// We only care about map-spawned weapons
if (!V_strcmp(pWeapon->m_sUniqueHammerID().Get(), ""))
return;
// And only their first equip
for (int i = 0; i < m_vecEquippedWeapons.size(); i++)
if (m_vecEquippedWeapons[i] == pWeapon->GetHandle())
return;
m_vecEquippedWeapons.push_back(pWeapon->GetHandle());
CBaseEntity* pTarget = nullptr;
// Entities parented to weapons being held by players were offset by +40 units following the AG2 update
// Since that doesn't affect in-world weapons, this migration is delayed until weapon equip to prevent breaking strip triggers etc
// Alternatively, we may want to track weapon children ahead of time via OnEntityParentChanged if this ends up becoming a performance concern
while ((pTarget = UTIL_FindEntityByClassname(pTarget, "*")))
{
CGameSceneNode* pParentSceneNode = pTarget->m_CBodyComponent()->m_pSceneNode()->m_pParent();
if (pParentSceneNode && pParentSceneNode->m_pOwner() == pWeapon)
{
Vector newOrigin = pTarget->GetAbsOrigin();
const char* pszClass = pTarget->GetClassname();
newOrigin.z -= 40.0f;
pTarget->Teleport(&newOrigin, nullptr, nullptr);
// If child inherits CBaseToggle, there's further bullshit we have to offset
// There's also some more obscure entities + all of CBaseTrigger, but these seem unnecessary to fixup
if (!V_strcasecmp(pszClass, "func_button") || !V_strcasecmp(pszClass, "func_physical_button") || !V_strcasecmp(pszClass, "func_rot_button") || !V_strcasecmp(pszClass, "momentary_rot_button") || !V_strcasecmp(pszClass, "func_movelinear") || !V_strcasecmp(pszClass, "func_door") || !V_strcasecmp(pszClass, "func_door_rotating"))
{
CBaseToggle* pToggle = (CBaseToggle*)pTarget;
pToggle->m_vecPosition1().z -= 40.0f;
pToggle->m_vecPosition2().z -= 40.0f;
}
}
}
}
bool CMapMigrations::Migrations_20260922(CEntityIdentity* pThis, CUtlSymbolLarge* pInputName, CEntityInstance* pActivator, CEntityInstance* pCaller, variant_t* value)
{
// Fix stringified Pulse argument packs formatting float decimals breaking logic_case matching post 2026-09-22 CS2 update
if (value->m_type == FIELD_FLOAT32 && !V_strcasecmp(pInputName->String(), "InValue") && !V_strcasecmp(pThis->GetClassname(), "logic_case"))
{
char szValue[32];
V_snprintf(szValue, sizeof(szValue), "%g", value->m_float32);
// Back up through CEntityInstance_AcceptInput so we can just worry about variant_t
((CBaseEntity*)pThis->m_pInstance)->AcceptInput(pInputName->String(), szValue, pActivator, pCaller);
return true;
}
return false;
}
bool CMapMigrations::Migrations20260420Enabled()
{
return g_cvarMapMigrations20260420.Get() == 1 || (g_cvarMapMigrations20260420.Get() == 2 && m_timeMapUpdated < g_time20260420);
}
void CMapMigrations::UpdateMapUpdateTime(uint64 iWorkshopId, time_t timeMapUpdated)
{
m_mapUpdateTimes[iWorkshopId] = timeMapUpdated;
// If we get triggered through ApplyGameSettings
if (g_pMapVoteSystem->GetCurrentMap() && g_pMapVoteSystem->GetCurrentMap()->GetWorkshopId() == iWorkshopId)
m_timeMapUpdated = timeMapUpdated;
}