-
Notifications
You must be signed in to change notification settings - Fork 142
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simply fixes the issue where the bullet is misplaced by a single tick, the issue gets less noticable the higher the tickrate, but might as well include it. Notes: - This plugin can easily be improved, but I'm honestly too tired atm to work it out (Basically detect when a client is trying to shoot and is able to, fire the SDKCall, and then use the weapon_fire event to call it again and reset the Vec to the previous tick) - Take the note above with a grain of salt as it's likely to make it even simpler and accurate than that. - Right now, it will "correct" every time a player's weapon is drawn out, when they're shooting, when they're shoving and when they're melee-ing. I am not sure about the possible issues this could cause.
- Loading branch information
Showing
4 changed files
with
221 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
"Games" | ||
{ | ||
"cstrike" | ||
{ | ||
"Offsets" | ||
{ | ||
"Weapon_ShootPosition" | ||
{ | ||
"windows" "265" | ||
"linux" "266" | ||
"mac" "266" | ||
} | ||
} | ||
} | ||
|
||
"csgo" | ||
{ | ||
"Offsets" | ||
{ | ||
"Weapon_ShootPosition" | ||
{ | ||
"windows" "290" | ||
"linux" "291" | ||
"mac" "291" | ||
} | ||
} | ||
} | ||
|
||
"left4dead2" | ||
{ | ||
"Offsets" | ||
{ | ||
"Weapon_ShootPosition" | ||
{ | ||
"windows" "285" | ||
"linux" "286" | ||
"mac" "286" | ||
} | ||
} | ||
} | ||
|
||
"tf" | ||
{ | ||
"Offsets" | ||
{ | ||
"Weapon_ShootPosition" | ||
{ | ||
"windows" "272" | ||
"linux" "273" | ||
"mac" "273" | ||
} | ||
} | ||
} | ||
|
||
"left4dead" | ||
{ | ||
"Offsets" | ||
{ | ||
"Weapon_ShootPosition" | ||
{ | ||
"windows" "264" | ||
"linux" "265" | ||
"mac" "265" | ||
} | ||
} | ||
} | ||
|
||
"dod" | ||
{ | ||
"Offsets" | ||
{ | ||
"Weapon_ShootPosition" | ||
{ | ||
"windows" "265" | ||
"linux" "266" | ||
"mac" "266" | ||
} | ||
} | ||
} | ||
|
||
"nucleardawn" | ||
{ | ||
"Offsets" | ||
{ | ||
"Weapon_ShootPosition" | ||
{ | ||
"windows" "296" | ||
"linux" "297" | ||
"mac" "297" | ||
} | ||
} | ||
} | ||
|
||
"hl2mp" | ||
{ | ||
"Offsets" | ||
{ | ||
"Weapon_ShootPosition" | ||
{ | ||
"windows" "265" | ||
"linux" "266" | ||
"mac" "266" | ||
} | ||
} | ||
} | ||
|
||
"NeotokyoSource" | ||
{ | ||
"Offsets" | ||
{ | ||
"Weapon_ShootPosition" | ||
{ | ||
"windows" "221" | ||
} | ||
} | ||
} | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
#include <sourcemod> | ||
#include <dhooks> | ||
#pragma semicolon 1 | ||
#pragma newdecls required | ||
|
||
DynamicHook g_hWeapon_ShootPosition; | ||
Handle g_hWeapon_ShootPosition_SDKCall; | ||
float g_vecOldWeaponShootPos[MAXPLAYERS + 1][3]; | ||
bool g_bCallingWeapon_ShootPosition; | ||
EngineVersion g_EngineVersion; | ||
|
||
public Plugin myinfo = | ||
{ | ||
name = "Bullet position fix", | ||
author = "xutaxkamay", /* With some slight changes based on reports/suggestions by Krevik/HarryPotter from the same Alliedmodders thread */ | ||
description = "Fixes shoot position", | ||
version = "1.0.3", | ||
url = "https://forums.alliedmods.net/showthread.php?p=2646571" | ||
}; | ||
|
||
public void OnPluginStart() | ||
{ | ||
GameData gameData = new GameData("firebulletsfix.games"); | ||
g_EngineVersion = GetEngineVersion(); | ||
|
||
if (!gameData) | ||
SetFailState("[FireBullets Fix] No game data present"); | ||
|
||
int offset = gameData.GetOffset("Weapon_ShootPosition"); | ||
|
||
if (offset == -1) | ||
SetFailState("[FireBullets Fix] failed to find offset"); | ||
|
||
LogMessage("Found offset for Weapon_ShootPosition %d", offset); | ||
|
||
|
||
StartPrepSDKCall(SDKCall_Player); | ||
|
||
if (!PrepSDKCall_SetFromConf(gameData, SDKConf_Virtual, "Weapon_ShootPosition")) | ||
SetFailState("[FireBullets Fix] couldn't read config for preparing Weapon_ShootPosition SDKCall"); | ||
|
||
PrepSDKCall_SetReturnInfo(SDKType_Vector, SDKPass_ByValue); | ||
g_hWeapon_ShootPosition_SDKCall = EndPrepSDKCall(); | ||
|
||
if (g_hWeapon_ShootPosition_SDKCall == INVALID_HANDLE) | ||
SetFailState("[FireBullets Fix] couldn't prepare Weapon_ShootPosition SDKCall"); | ||
|
||
g_hWeapon_ShootPosition = new DynamicHook(offset, HookType_Entity, ReturnType_Vector, ThisPointer_CBaseEntity); | ||
|
||
if (!g_hWeapon_ShootPosition) | ||
SetFailState("[FireBullets Fix] couldn't hook Weapon_ShootPosition"); | ||
|
||
delete gameData; | ||
|
||
for (int i = 1; i <= MaxClients; i++) | ||
{ | ||
if (IsClientInGame(i)) | ||
OnClientPutInServer(i); | ||
} | ||
} | ||
|
||
public void OnClientPutInServer(int client) | ||
{ | ||
if (!IsFakeClient(client)) | ||
g_hWeapon_ShootPosition.HookEntity(Hook_Post, client, Weapon_ShootPosition_Post); | ||
} | ||
|
||
public Action OnPlayerRunCmd(int client) | ||
{ | ||
if (IsPlayerAlive(client) && !IsFakeClient(client)) | ||
{ | ||
g_bCallingWeapon_ShootPosition = true; | ||
SDKCall(g_hWeapon_ShootPosition_SDKCall, client, g_vecOldWeaponShootPos[client]); | ||
g_bCallingWeapon_ShootPosition = false; | ||
} | ||
return Plugin_Continue; | ||
} | ||
|
||
public MRESReturn Weapon_ShootPosition_Post(int client, DHookReturn hReturn) | ||
{ | ||
if (!g_bCallingWeapon_ShootPosition) | ||
{ | ||
switch(g_EngineVersion) | ||
{ | ||
// Only care about Survivors in Left 4 Dead series due to issues with props hit by Tanks. | ||
case Engine_Left4Dead, Engine_Left4Dead2: | ||
{ | ||
if (GetClientTeam(client) != 2) | ||
return MRES_Ignored; | ||
} | ||
default: { /* Nothing? */ } | ||
} | ||
#if defined DEBUG | ||
float g_vecWeaponShootPos[3]; | ||
hReturn.GetVector(g_vecWeaponShootPos); | ||
PrintToConsoleAll("[FireBullets Fix] Old Weapon_ShootPosition: %.2f, %.2f, %.2f", g_vecOldWeaponShootPos[client][0], g_vecOldWeaponShootPos[client][1], g_vecOldWeaponShootPos[client][2]); | ||
PrintToConsoleAll("[FireBullets Fix] New Weapon_ShootPosition: %.2f, %.2f, %.2f", g_vecWeaponShootPos[0], g_vecWeaponShootPos[1], g_vecWeaponShootPos[2]); | ||
#endif | ||
hReturn.SetVector(g_vecOldWeaponShootPos[client]); | ||
return MRES_Supercede; | ||
} | ||
return MRES_Ignored; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters