-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathl4d2_global_shadow_fix.sp
More file actions
195 lines (156 loc) · 5.99 KB
/
l4d2_global_shadow_fix.sp
File metadata and controls
195 lines (156 loc) · 5.99 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
/*
* Global Shadow Fix
* Copyright (C) 2022 Silvers
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU 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 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 <https://www.gnu.org/licenses/>.
*/
#define PLUGIN_VERSION "1.3"
/*=======================================================================================
Plugin Info:
* Name : [L4D2] Global Shadow Fix
* Author : SilverShot
* Descp : Corrects the global shadow position on some official maps.
* Link : https://forums.alliedmods.net/showthread.php?t=149041
* Plugins : https://sourcemod.net/plugins.php?exact=exact&sortby=title&search=1&author=Silvers
========================================================================================
Change Log:
1.3 (11-Dec-2022)
- Changes to fix compile warnings on SourceMod 1.11.
1.2 (10-May-2020)
- Various changes to tidy up code.
1.1 (05-May-2018)
- Converted plugin source to the latest syntax utilizing methodmaps. Requires SourceMod 1.8 or newer.
1.0 (01-Feb-2011)
- Initial release.
======================================================================================*/
#pragma semicolon 1
#pragma newdecls required
#define ALLOW_EDITING false // Enables the "sm_shadow*" commands to move the shadow position
#include <sourcemod>
#include <sdktools>
// ====================================================================================================
// PLUGIN INFO / START
// ====================================================================================================
public Plugin myinfo =
{
name = "[L4D2] Global Shadow Fix",
author = "SilverShot",
description = "Corrects the global shadow position on some official maps.",
version = PLUGIN_VERSION,
url = "https://forums.alliedmods.net/showthread.php?t=149041"
}
public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max)
{
EngineVersion test = GetEngineVersion();
if( test != Engine_Left4Dead2 )
{
strcopy(error, err_max, "Plugin only supports Left 4 Dead 2.");
return APLRes_SilentFailure;
}
return APLRes_Success;
}
public void OnPluginStart()
{
// Cvars
CreateConVar("l4d2_global_shadow_fix_version", PLUGIN_VERSION, "Shadow Fix version.", FCVAR_NOTIFY|FCVAR_DONTRECORD);
// Reset to the new values and manually change the shadow direction
#if ALLOW_EDITING
RegAdminCmd("sm_shadows", CmdSh, ADMFLAG_ROOT);
RegAdminCmd("sm_shadowx", CmdShX, ADMFLAG_ROOT);
RegAdminCmd("sm_shadowy", CmdShY, ADMFLAG_ROOT);
RegAdminCmd("sm_shadowz", CmdShZ, ADMFLAG_ROOT);
#endif
}
// ====================================================================================================
// PLUGIN INFO / START
// ====================================================================================================
public void OnConfigsExecuted()
{
SetPos();
}
bool SetPos()
{
float fCorrected[3];
char sMap[64];
GetCurrentMap(sMap, sizeof(sMap));
// Dead Center:
if( strcmp(sMap, "c1m1_hotel", false) == 0 ) //-0.612372 0.353553 -0.707106
fCorrected = view_as<float>({ 0.587627, 0.353553, -0.207106 });
else if( strcmp(sMap, "c1m2_streets") == 0 ) //0.150383 0.086824 -0.984807
fCorrected = view_as<float>({ 0.750383, 0.486824, -0.484807 });
else if( strcmp(sMap, "c1m3_mall") == 0 ) //01.187627 0.553553 -0.707106
fCorrected = view_as<float>({ 2.587627, 0.953553, -0.207106 });
else if( strcmp(sMap, "c1m4_atrium") == 0 ) //-0.612372 0.353553 -0.707106
fCorrected = view_as<float>({ 2.587627, 0.353553, -0.207106 });
// Hard Rain:
else if( strcmp(sMap, "c4m1_milltown_a") == 0 ) //0.330366 -0.088521 -0.939692
fCorrected = view_as<float>({ 1.130365, 0.711478, -0.439692 });
else
return false; // No other maps
int ent = -1;
while( (ent = FindEntityByClassname(ent, "shadow_control")) != INVALID_ENT_REFERENCE )
{
SetEntPropVector(ent, Prop_Send, "m_shadowDirection", fCorrected);
}
return true;
}
// ====================================================================================================
// COMMANDS
// ====================================================================================================
#if ALLOW_EDITING
Action CmdSh(int client, int args)
{
if( SetPos() == true )
PrintToChat(client, "\x04[\x01Shadow Fix\x04]\x01 Corrected!");
else
PrintToChat(client, "\x04[\x01Shadow Fix\x04]\x01 Wrong Map!");
return Plugin_Handled;
}
Action CmdShX(int client, int args)
{
SetShadow(client, 1, args);
return Plugin_Handled;
}
Action CmdShY(int client, int args)
{
SetShadow(client, 2, args);
return Plugin_Handled;
}
Action CmdShZ(int client, int args)
{
SetShadow(client, 3, args);
return Plugin_Handled;
}
void SetShadow(int client, int type, any ...)
{
char arg1[32];
GetCmdArg(1, arg1, sizeof(arg1));
int entity = -1;
float fCorrected[3];
float fDistance = StringToFloat(arg1);
while( (entity = FindEntityByClassname(entity, "shadow_control")) != INVALID_ENT_REFERENCE )
{
GetEntPropVector(entity, Prop_Send, "m_shadowDirection", fCorrected);
PrintToChat(client, "\x04[\x01Shadow Fix\x04]\x01 Was: %f %f %f", fCorrected[0], fCorrected[1], fCorrected[2]);
switch(type)
{
case 1: fCorrected[0] += fDistance;
case 2: fCorrected[1] += fDistance;
case 3: fCorrected[2] += fDistance;
}
SetEntPropVector(entity, Prop_Send, "m_shadowDirection", fCorrected);
PrintToChat(client, "\x04[\x01Shadow Fix\x04]\x01 Now: %f %f %f", fCorrected[0], fCorrected[1], fCorrected[2]);
}
}
#endif