-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathl4d2_Hunter_pounce_alignment_fix.sp
179 lines (149 loc) · 5.55 KB
/
l4d2_Hunter_pounce_alignment_fix.sp
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
/*
* Fixes for gamebreaking bugs and stupid gameplay aspects
* Copyright (C) 2019 LuxLuma [email protected]
*
* 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/>.
*/
//Requires https://github.com/nosoop/SMExt-SourceScramble
#pragma semicolon 1
#include <sourcemod>
#include <sdktools>
#include <sdkhooks>
#pragma newdecls required
#define GAMEDATA "hunter_pounce_alignment_fix"
#define PLUGIN_VERSION "2.0"
#define MAX_PATCH_SIZE 16 //highest amount of patch bytes needed
#define LINUX_PATCH_SIZE 16
#define WINDOWS_PATCH_SIZE 12
Address SetAbsOrigin_address;
int SetAbsOrigin_bytes[MAX_PATCH_SIZE];
Handle g_hSetAbsOrigin;
Handle g_hSetAbsVelocity;
enum OS_Type
{
OS_windows = 0,
OS_linux
}
public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max)
{
if(GetEngineVersion() != Engine_Left4Dead2)
{
strcopy(error, err_max, "Plugin only supports Left 4 Dead 2");
return APLRes_SilentFailure;
}
return APLRes_Success;
}
public Plugin myinfo =
{
name = "猎人突袭位置修复",
author = "Lux",
description = "Restores l4d1 style hunter alignment.",
version = PLUGIN_VERSION,
url = "https://github.com/LuxLuma/Left-4-fix/tree/master/left%204%20fix/hunter/Hunter_pounce_alignment_fix"
};
public void OnPluginStart()
{
CreateConVar("hunter_pounce_alignment_fix_version", PLUGIN_VERSION, "", FCVAR_NOTIFY|FCVAR_DONTRECORD);
Handle hGamedata = LoadGameConfigFile(GAMEDATA);
if(hGamedata == null)
SetFailState("Failed to load \"%s.txt\" gamedata.", GAMEDATA);
StartPrepSDKCall(SDKCall_Entity);
if(!PrepSDKCall_SetFromConf(hGamedata, SDKConf_Signature, "CBaseEntity::SetAbsOrigin"))
SetFailState("Error finding the 'CBaseEntity::SetAbsOrigin' signature.");
PrepSDKCall_AddParameter(SDKType_Vector, SDKPass_Pointer);
g_hSetAbsOrigin = EndPrepSDKCall();
if(g_hSetAbsOrigin == null)
SetFailState("Unable to prep SDKCall 'CBaseEntity::SetAbsOrigin'");
StartPrepSDKCall(SDKCall_Entity);
if(!PrepSDKCall_SetFromConf(hGamedata, SDKConf_Signature, "CBaseEntity::SetAbsVelocity"))
SetFailState("Error finding the 'CBaseEntity::SetAbsVelocity' signature.");
PrepSDKCall_AddParameter(SDKType_Vector, SDKPass_Pointer);
g_hSetAbsVelocity = EndPrepSDKCall();
if(g_hSetAbsVelocity == null)
SetFailState("Unable to prep SDKCall 'CBaseEntity::SetAbsVelocity'");
//nop it :)
UpdatePounce_Patch(hGamedata);
delete hGamedata;
}
void UpdatePounce_Patch(Handle &hGamedata)
{
OS_Type os = view_as<OS_Type>(GameConfGetOffset(hGamedata, "OS"));
SetAbsOrigin_address = GameConfGetAddress(hGamedata, "CTerrorPlayer::UpdatePounce::SetAbsVelocity");
if(SetAbsOrigin_address == Address_Null)
{
LogError("Failed to find address 'CTerrorPlayer::UpdatePounce::SetAbsVelocity'");
return;
}
for(int i = 0; i < MAX_PATCH_SIZE; i++)
{
SetAbsOrigin_bytes[i] = LoadFromAddress(SetAbsOrigin_address + view_as<Address>(i), NumberType_Int8);
}
switch(os)
{
case OS_windows:
{
for(int i = 0; i < WINDOWS_PATCH_SIZE; i++)
{
StoreToAddress(SetAbsOrigin_address + view_as<Address>(i), 0x90, NumberType_Int8);
}
}
case OS_linux:
{
for(int i = 0; i < LINUX_PATCH_SIZE; i++)
{
StoreToAddress(SetAbsOrigin_address + view_as<Address>(i), 0x90, NumberType_Int8);
}
}
}
PrintToServer("Patched 'CTerrorPlayer::UpdatePounce->CBaseEntity::SetAbsVelocity'");
}
public void OnPluginEnd()
{
if(SetAbsOrigin_address != Address_Null)
{
for(int i = 0; i < MAX_PATCH_SIZE; i++)
{
StoreToAddress(SetAbsOrigin_address + view_as<Address>(i), SetAbsOrigin_bytes[i], NumberType_Int8);
}
PrintToServer("Restored 'CTerrorPlayer::UpdatePounce->CBaseEntity::SetAbsVelocity'");
}
}
public void OnEntityCreated(int iEntity, const char[] sClassname)
{
if(sClassname[0] == 'h' && StrEqual(sClassname, "hunter", false))
SDKHook(iEntity, SDKHook_PostThink, PostThinkHunter);
}
public void OnClientPutInServer(int iClient)
{
if(!IsFakeClient(iClient))
SDKHook(iClient, SDKHook_PostThink, PostThinkHunter);
}
public void PostThinkHunter(int iHunter)
{
if(!IsPlayerAlive(iHunter) || GetClientTeam(iHunter) != 3)
return;
int iPounceVictim = GetEntPropEnt(iHunter, Prop_Send, "m_pounceVictim");
if(iPounceVictim < 1 || !IsPlayerAlive(iPounceVictim) ||
GetEntPropEnt(iPounceVictim, Prop_Send, "m_pounceAttacker") != iHunter)// just incase
return;
//copy all the victims origin and velocity data so velocity interpolation can happen clientside
//and lagcomp is as correct as it can be
static float vecPos[3];
static float vecVel[3];
GetEntPropVector(iPounceVictim, Prop_Data, "m_vecAbsOrigin", vecPos);//worldspace origin
GetEntPropVector(iPounceVictim, Prop_Data, "m_vecAbsVelocity", vecVel);
//TeleportEntity seems to make the hunter's outline flash to avoid this don't use it :P
SDKCall(g_hSetAbsOrigin, iHunter, vecPos);
SDKCall(g_hSetAbsVelocity, iHunter, vecVel);
}