├── .gitignore ├── CSSharpFixes.sln ├── CSSharpFixes.sln.DotSettings ├── CSSharpFixes.sln.DotSettings.user ├── CSSharpFixes ├── CSSharpFixes.cs ├── CSSharpFixes.csproj ├── ConVars.cs ├── Config │ ├── Configuration.cs │ └── ModuleInformation.cs ├── Detours │ ├── BaseHandler.cs │ ├── ProcessUserCmdsHandler.cs │ └── TriggerPushTouchHandler.cs ├── Enums │ └── Detours │ │ └── Mode.cs ├── Extensions │ ├── CBaseEntityExtensions.cs │ ├── CBaseTriggerExtensions.cs │ ├── CGameSceneNodeExtensions.cs │ └── PlayerExtensions.cs ├── Fixes │ ├── BaseFix.cs │ ├── CPhysBoxUseFix.cs │ ├── EntityStringPurgeFix.cs │ ├── FullAllTalkFix.cs │ ├── Interfaces │ │ └── ITickable.cs │ ├── MovementUnlockerFix.cs │ ├── NavmeshLookupLagFix.cs │ ├── NoBlockFix.cs │ ├── SubTickMovementFix.cs │ ├── TeamMessagesFix.cs │ ├── TriggerPushFix.cs │ └── WaterFix.cs ├── Hooks.cs ├── Injection.cs ├── Managers │ ├── DetourManager.cs │ ├── EventManager.cs │ ├── FixManager.cs │ ├── GameDataManager.cs │ └── PatchManager.cs ├── Memory │ ├── DetourMemoryFunctions.cs │ ├── UnixMemoryUtils.cs │ └── WinMemoryUtils.cs ├── Models │ ├── Detour.cs │ └── Patch.cs ├── Schemas │ ├── Interfaces │ │ └── ISizeable.cs │ └── Protobuf │ │ ├── CBaseUserCmdPB.cs │ │ ├── CSubTickMoveStep.cs │ │ ├── CUserCmd.cs │ │ └── Interop │ │ ├── Rep.cs │ │ └── RepeatedPtrField.cs └── Utils.cs ├── LICENSE ├── README.md └── gamedata └── cssharpfixes.json /.gitignore: -------------------------------------------------------------------------------- 1 | bin/ 2 | obj/ 3 | /packages/ 4 | riderModule.iml 5 | /_ReSharper.Caches/ 6 | CSSharpFixes/bin/ 7 | CSSharpFixes/obj/ 8 | .idea/ -------------------------------------------------------------------------------- /CSSharpFixes.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CSSharpFixes", "CSSharpFixes\CSSharpFixes.csproj", "{2805B875-C3D5-4643-96DF-30E5B09984FF}" 4 | EndProject 5 | Global 6 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 7 | Debug|Any CPU = Debug|Any CPU 8 | Release|Any CPU = Release|Any CPU 9 | EndGlobalSection 10 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 11 | {2805B875-C3D5-4643-96DF-30E5B09984FF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 12 | {2805B875-C3D5-4643-96DF-30E5B09984FF}.Debug|Any CPU.Build.0 = Debug|Any CPU 13 | {2805B875-C3D5-4643-96DF-30E5B09984FF}.Release|Any CPU.ActiveCfg = Release|Any CPU 14 | {2805B875-C3D5-4643-96DF-30E5B09984FF}.Release|Any CPU.Build.0 = Release|Any CPU 15 | EndGlobalSection 16 | EndGlobal 17 | -------------------------------------------------------------------------------- /CSSharpFixes.sln.DotSettings: -------------------------------------------------------------------------------- 1 |  2 | CS -------------------------------------------------------------------------------- /CSSharpFixes.sln.DotSettings.user: -------------------------------------------------------------------------------- 1 |  2 | <AssemblyExplorer> 3 | <Assembly Path="C:\Users\admin\.nuget\packages\counterstrikesharp.api\1.0.239\lib\net8.0\CounterStrikeSharp.API.dll" /> 4 | </AssemblyExplorer> -------------------------------------------------------------------------------- /CSSharpFixes/CSSharpFixes.cs: -------------------------------------------------------------------------------- 1 | /* 2 | ============================================================================= 3 | CS#Fixes 4 | Copyright (C) 2023-2024 Charles Barone / hypnos 5 | ============================================================================= 6 | 7 | This program is free software; you can redistribute it and/or modify it under 8 | the terms of the GNU General Public License, version 3.0, as published by the 9 | Free Software Foundation. 10 | 11 | This program is distributed in the hope that it will be useful, but WITHOUT 12 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 13 | FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 14 | details. 15 | 16 | You should have received a copy of the GNU General Public License along with 17 | this program. If not, see . 18 | */ 19 | 20 | using CounterStrikeSharp.API; 21 | using CounterStrikeSharp.API.Core; 22 | using CSSharpFixes.Config; 23 | using CSSharpFixes.Managers; 24 | 25 | namespace CSSharpFixes; 26 | 27 | public partial class CSSharpFixes: BasePlugin 28 | { 29 | public override string ModuleName => _moduleInformation.ModuleName; 30 | public override string ModuleVersion => _moduleInformation.ModuleVersion; 31 | public override string ModuleAuthor => _moduleInformation.ModuleAuthor; 32 | public override string ModuleDescription => _moduleInformation.ModuleDescription; 33 | 34 | private readonly ModuleInformation _moduleInformation; 35 | private readonly Configuration _configuration; 36 | 37 | private readonly GameDataManager _gameDataManager; 38 | private readonly DetourManager _detourManager; 39 | private readonly PatchManager _patchManager; 40 | private readonly EventManager _eventManager; 41 | private readonly FixManager _fixManager; 42 | 43 | public CSSharpFixes(ModuleInformation moduleInformation, GameDataManager gameDataManager, DetourManager detourManager, 44 | PatchManager patchManager, EventManager eventManager, FixManager fixManager, Configuration configuration) 45 | { 46 | _moduleInformation = moduleInformation; 47 | 48 | _gameDataManager = gameDataManager; 49 | _detourManager = detourManager; 50 | _patchManager = patchManager; 51 | _eventManager = eventManager; 52 | _fixManager = fixManager; 53 | 54 | _configuration = configuration; 55 | } 56 | 57 | public override void Load(bool hotReload) 58 | { 59 | RegisterHooks(); 60 | RegisterConVars(); 61 | _gameDataManager.Start(); 62 | _eventManager.Start(); 63 | _detourManager.Start(); 64 | _patchManager.Start(); 65 | _fixManager.Start(); 66 | _configuration.Start(); 67 | 68 | if (hotReload) 69 | { 70 | OnMapStart(Server.MapName); 71 | } 72 | } 73 | 74 | public override void Unload(bool hotReload) 75 | { 76 | UnregisterHooks(); 77 | _fixManager.Stop(); 78 | _patchManager.Stop(); 79 | _detourManager.Stop(); 80 | _eventManager.Stop(); 81 | _gameDataManager.Stop(); 82 | } 83 | } -------------------------------------------------------------------------------- /CSSharpFixes/CSSharpFixes.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | net8.0 5 | enable 6 | enable 7 | true 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /CSSharpFixes/ConVars.cs: -------------------------------------------------------------------------------- 1 | /* 2 | ============================================================================= 3 | CS#Fixes 4 | Copyright (C) 2023-2024 Charles Barone / hypnos 5 | ============================================================================= 6 | 7 | This program is free software; you can redistribute it and/or modify it under 8 | the terms of the GNU General Public License, version 3.0, as published by the 9 | Free Software Foundation. 10 | 11 | This program is distributed in the hope that it will be useful, but WITHOUT 12 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 13 | FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 14 | details. 15 | 16 | You should have received a copy of the GNU General Public License along with 17 | this program. If not, see . 18 | */ 19 | 20 | using CounterStrikeSharp.API.Modules.Cvars; 21 | 22 | namespace CSSharpFixes; 23 | 24 | public partial class CSSharpFixes 25 | { 26 | public FakeConVar EnableWaterFix = new("css_fixes_water_fix", "Fixes being stuck to the floor underwater, allowing players to swim up.", true); 27 | public FakeConVar EnableTriggerPushFix = new("css_fixes_trigger_push_fix", "Reverts trigger_push behaviour to that seen in CS:GO.", false); 28 | public FakeConVar EnableCPhysBoxUseFix = new("css_fixes_cphys_box_use_fix", "Fixes CPhysBox use. Make func_physbox pass itself as the caller in OnPlayerUse.", false); 29 | //public FakeConVar EnableNavmeshLookupLagFix = new("css_fixes_navmesh_lookup_lag_fix", "Some maps with built navmeshes would cause tremendous lag.", false); // Commented out since it seems to cause crashes every time I test it... 30 | public FakeConVar EnableNoBlock = new("css_fixes_no_block", "Prevent players from blocking each other. (Sets debris collision on every player).", false); 31 | //public FakeConVar DisableTeamMessages = new("css_fixes_disable_team_messages", "Disables team join messages.", false); //TODO: NOT FINSIHED! 32 | public FakeConVar DisableSubTickMovement = new("css_fixes_disable_sub_tick_movement", "Disables sub-tick movement.", false); 33 | public FakeConVar EnableMovementUnlocker = new("css_fixes_enable_movement_unlocker", "Enables movement unlocker.", false); 34 | public FakeConVar EnforceFullAlltalk = new("css_fixes_enforce_full_alltalk", "Enforces sv_full_alltalk 1.", false); 35 | //public FakeConVar EnableEntityStringPurge = new("css_fixes_purge_entity_strings", "Enables purge of the EntityNames stringtable on new rounds", false); //TODO: NOT FINSIHED! 36 | 37 | private void RegisterConVars() 38 | { 39 | EnableWaterFix.ValueChanged += (sender, value) => { _configuration.EnableWaterFix = value; }; 40 | EnableTriggerPushFix.ValueChanged += (sender, value) => { _configuration.EnableTriggerPushFix = value; }; 41 | EnableCPhysBoxUseFix.ValueChanged += (sender, value) => { _configuration.EnableCPhysBoxUseFix = value; }; 42 | //EnableNavmeshLookupLagFix.ValueChanged += (sender, value) => { _configuration.EnableNavmeshLookupLagFix = value; }; // Commented out since it seems to cause crashes every time I test it... 43 | EnableNoBlock.ValueChanged += (sender, value) => { _configuration.EnableNoBlock = value; }; 44 | //DisableTeamMessages.ValueChanged += (sender, value) => { _configuration.DisableTeamMessages = value; }; //TODO: NOT FINSIHED! 45 | DisableSubTickMovement.ValueChanged += (sender, value) => { _configuration.DisableSubTickMovement = value; }; 46 | EnableMovementUnlocker.ValueChanged += (sender, value) => { _configuration.EnableMovementUnlocker = value; }; 47 | EnforceFullAlltalk.ValueChanged += (sender, value) => { _configuration.EnforceFullAlltalk = value; }; 48 | //EnableEntityStringPurge.ValueChanged += (sender, value) => { _configuration.EnableEntityStringPurge = value; }; //TODO: NOT FINSIHED! 49 | 50 | RegisterFakeConVars(typeof(ConVar)); 51 | } 52 | } -------------------------------------------------------------------------------- /CSSharpFixes/Config/Configuration.cs: -------------------------------------------------------------------------------- 1 | /* 2 | ============================================================================= 3 | CS#Fixes 4 | Copyright (C) 2023-2024 Charles Barone / hypnos 5 | ============================================================================= 6 | 7 | This program is free software; you can redistribute it and/or modify it under 8 | the terms of the GNU General Public License, version 3.0, as published by the 9 | Free Software Foundation. 10 | 11 | This program is distributed in the hope that it will be useful, but WITHOUT 12 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 13 | FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 14 | details. 15 | 16 | You should have received a copy of the GNU General Public License along with 17 | this program. If not, see . 18 | */ 19 | 20 | using System.ComponentModel; 21 | using System.Runtime.CompilerServices; 22 | using CSSharpFixes.Managers; 23 | using Microsoft.Extensions.Logging; 24 | 25 | namespace CSSharpFixes.Config 26 | { 27 | public class Configuration(ILogger logger, FixManager fixManager) : INotifyPropertyChanged 28 | { 29 | private bool enableWaterFix = true; 30 | private bool enableTriggerPushFix = false; 31 | private bool enableCPhysBoxUseFix = false; 32 | //private bool enableNavmeshLookupLagFix = false; // Commented out since it seems to cause crashes every time I test it... 33 | private bool enableNoBlock = false; 34 | private bool disableTeamMessages = false; 35 | private bool disableSubTickMovement = false; 36 | private bool enableMovementUnlocker = false; 37 | private bool enforceFullAlltalk = false; 38 | private bool enableEntityStringPurge = false; 39 | 40 | public event PropertyChangedEventHandler? PropertyChanged; 41 | 42 | protected virtual void OnPropertyChanged([CallerMemberName] string? propertyName = null) 43 | { 44 | if(propertyName == null) return; 45 | PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); 46 | OnConfigChanged(propertyName, GetType().GetProperty(propertyName)?.GetValue(this, null)); 47 | } 48 | 49 | private void OnConfigChanged(string propertyName, object? newValue) 50 | { 51 | logger.LogInformation($"[CSSharpFixes][Configuration][OnConfigChanged()][Property={propertyName}][Value={newValue}]"); 52 | fixManager.OnConfigChanged(propertyName, newValue); 53 | } 54 | 55 | public void Start() 56 | { 57 | logger.LogInformation("[CSSharpFixes][Configuration][Start()]"); 58 | 59 | // Call OnConfigChanged for each property to apply the initial configuration & trigger the fix manager 60 | foreach (PropertyDescriptor property in TypeDescriptor.GetProperties(this)) 61 | { 62 | OnConfigChanged(property.Name, property.GetValue(this)); 63 | } 64 | } 65 | 66 | public bool EnableWaterFix 67 | { 68 | get => enableWaterFix; 69 | set 70 | { 71 | if (enableWaterFix != value) 72 | { 73 | enableWaterFix = value; 74 | OnPropertyChanged(); 75 | } 76 | } 77 | } 78 | 79 | public bool EnableTriggerPushFix 80 | { 81 | get => enableTriggerPushFix; 82 | set 83 | { 84 | if (enableTriggerPushFix != value) 85 | { 86 | enableTriggerPushFix = value; 87 | OnPropertyChanged(); 88 | } 89 | } 90 | } 91 | 92 | public bool EnableCPhysBoxUseFix 93 | { 94 | get => enableCPhysBoxUseFix; 95 | set 96 | { 97 | if (enableCPhysBoxUseFix != value) 98 | { 99 | enableCPhysBoxUseFix = value; 100 | OnPropertyChanged(); 101 | } 102 | } 103 | } 104 | 105 | // Commented out since it seems to cause crashes every time I test it... 106 | /* public bool EnableNavmeshLookupLagFix 107 | { 108 | get => enableNavmeshLookupLagFix; 109 | set 110 | { 111 | if (enableNavmeshLookupLagFix != value) 112 | { 113 | enableNavmeshLookupLagFix = value; 114 | OnPropertyChanged(); 115 | } 116 | } 117 | } */ 118 | 119 | public bool EnableNoBlock 120 | { 121 | get => enableNoBlock; 122 | set 123 | { 124 | if (enableNoBlock != value) 125 | { 126 | enableNoBlock = value; 127 | OnPropertyChanged(); 128 | } 129 | } 130 | } 131 | 132 | public bool DisableTeamMessages 133 | { 134 | get => disableTeamMessages; 135 | set 136 | { 137 | if (disableTeamMessages != value) 138 | { 139 | disableTeamMessages = value; 140 | OnPropertyChanged(); 141 | } 142 | } 143 | } 144 | 145 | public bool DisableSubTickMovement 146 | { 147 | get => disableSubTickMovement; 148 | set 149 | { 150 | if (disableSubTickMovement != value) 151 | { 152 | disableSubTickMovement = value; 153 | OnPropertyChanged(); 154 | } 155 | } 156 | } 157 | 158 | public bool EnableMovementUnlocker 159 | { 160 | get => enableMovementUnlocker; 161 | set 162 | { 163 | if (enableMovementUnlocker != value) 164 | { 165 | enableMovementUnlocker = value; 166 | OnPropertyChanged(); 167 | } 168 | } 169 | } 170 | 171 | public bool EnforceFullAlltalk 172 | { 173 | get => enforceFullAlltalk; 174 | set 175 | { 176 | if (enforceFullAlltalk != value) 177 | { 178 | enforceFullAlltalk = value; 179 | OnPropertyChanged(); 180 | } 181 | } 182 | } 183 | 184 | public bool EnableEntityStringPurge 185 | { 186 | get => enableEntityStringPurge; 187 | set 188 | { 189 | if (enableEntityStringPurge != value) 190 | { 191 | enableEntityStringPurge = value; 192 | OnPropertyChanged(); 193 | } 194 | } 195 | } 196 | } 197 | } 198 | -------------------------------------------------------------------------------- /CSSharpFixes/Config/ModuleInformation.cs: -------------------------------------------------------------------------------- 1 | /* 2 | ============================================================================= 3 | CS#Fixes 4 | Copyright (C) 2023-2024 Charles Barone / hypnos 5 | ============================================================================= 6 | 7 | This program is free software; you can redistribute it and/or modify it under 8 | the terms of the GNU General Public License, version 3.0, as published by the 9 | Free Software Foundation. 10 | 11 | This program is distributed in the hope that it will be useful, but WITHOUT 12 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 13 | FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 14 | details. 15 | 16 | You should have received a copy of the GNU General Public License along with 17 | this program. If not, see . 18 | */ 19 | 20 | namespace CSSharpFixes.Config; 21 | 22 | public class ModuleInformation 23 | { 24 | public string ModuleName => "CS#Fixes"; 25 | public string ModuleVersion => "1.0.1"; 26 | public string ModuleAuthor => "hypnos "; 27 | public string ModuleDescription => "cs#fixes"; 28 | } -------------------------------------------------------------------------------- /CSSharpFixes/Detours/BaseHandler.cs: -------------------------------------------------------------------------------- 1 | /*/* 2 | ============================================================================= 3 | CS#Fixes 4 | Copyright (C) 2023-2024 Charles Barone / hypnos 5 | ============================================================================= 6 | 7 | This program is free software; you can redistribute it and/or modify it under 8 | the terms of the GNU General Public License, version 3.0, as published by the 9 | Free Software Foundation. 10 | 11 | This program is distributed in the hope that it will be useful, but WITHOUT 12 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 13 | FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 14 | details. 15 | 16 | You should have received a copy of the GNU General Public License along with 17 | this program. If not, see . 18 | */ 19 | 20 | using System.Reflection; 21 | using CounterStrikeSharp.API.Modules.Memory.DynamicFunctions; 22 | using Microsoft.Extensions.Logging; 23 | 24 | namespace CSSharpFixes.Detours; 25 | 26 | public abstract class BaseHandler 27 | { 28 | public string Name { get; set; } 29 | 30 | public abstract Enums.Detours.Mode Mode { get; } 31 | public abstract Models.Detour PreDetour { get; } 32 | public abstract Models.Detour PostDetour { get; } 33 | 34 | protected readonly ILogger _logger; 35 | 36 | public abstract void Start(); 37 | public abstract void Stop(); 38 | protected abstract void UnhookAllDetours(); 39 | 40 | protected BaseHandler(string name, ILogger logger) 41 | { 42 | Name = name ?? throw new ArgumentNullException(nameof(name)); 43 | _logger = logger ?? throw new ArgumentNullException(nameof(logger));; 44 | } 45 | 46 | private static BaseMemoryFunction GetMemoryFunction() where T : BaseHandler 47 | { 48 | MethodInfo? getMemoryFunctionMethod = typeof(T).GetMethod("GetMemoryFunction"); 49 | if(getMemoryFunctionMethod == null) 50 | throw new InvalidOperationException($"Class {typeof(T).Name} must define a static GetMemoryFunction method."); 51 | 52 | return getMemoryFunctionMethod.Invoke(null, null) as BaseMemoryFunction 53 | ?? throw new InvalidOperationException(); 54 | } 55 | 56 | public static T Build(ILogger logger) where T : BaseHandler 57 | { 58 | MethodInfo? buildMethod = typeof(T).GetMethod("Build", new Type[] { typeof(ILogger) }); 59 | if (buildMethod == null || !buildMethod.IsStatic) 60 | throw new InvalidOperationException($"Class {typeof(T).Name} must define a static Build method."); 61 | 62 | return buildMethod.Invoke(null, [logger]) as T ?? throw new InvalidOperationException(); 63 | } 64 | } 65 | 66 | public abstract class PreHandler : BaseHandler 67 | { 68 | public override Enums.Detours.Mode Mode => Enums.Detours.Mode.Pre; 69 | 70 | public override Models.Detour PreDetour { get; } 71 | public override Models.Detour PostDetour 72 | => throw new NotSupportedException("PostDetour is only available if Mode is set to Post or Both."); 73 | 74 | protected override void UnhookAllDetours() 75 | { 76 | if(PreDetour.IsHooked()) PreDetour.Unhook(); 77 | } 78 | 79 | protected PreHandler(string name, Models.Detour preDetour, ILogger logger) : base(name, logger) 80 | { 81 | PreDetour = preDetour ?? throw new ArgumentNullException(nameof(preDetour)); 82 | } 83 | } 84 | 85 | public abstract class PostHandler : BaseHandler 86 | { 87 | public override Enums.Detours.Mode Mode => Enums.Detours.Mode.Post; 88 | 89 | public override Models.Detour PreDetour 90 | => throw new NotSupportedException("PreDetour is only available if Mode is set to Pre or Both."); 91 | public override Models.Detour PostDetour { get; } 92 | 93 | protected override void UnhookAllDetours() 94 | { 95 | if(PostDetour.IsHooked()) PostDetour.Unhook(); 96 | } 97 | 98 | protected PostHandler(string name, Models.Detour postDetour, ILogger logger) : base(name, logger) 99 | { 100 | PostDetour = postDetour ?? throw new ArgumentNullException(nameof(postDetour)); 101 | } 102 | } 103 | 104 | public abstract class PrePostHandler : BaseHandler 105 | { 106 | public override Enums.Detours.Mode Mode => Enums.Detours.Mode.Both; 107 | 108 | public override Models.Detour PreDetour { get; } 109 | public override Models.Detour PostDetour { get; } 110 | 111 | protected override void UnhookAllDetours() 112 | { 113 | if(PreDetour.IsHooked()) PreDetour.Unhook(); 114 | if(PostDetour.IsHooked()) PostDetour.Unhook(); 115 | } 116 | 117 | protected PrePostHandler(string name, Models.Detour preDetour, Models.Detour postDetour, ILogger logger) 118 | : base(name, logger) 119 | { 120 | PreDetour = preDetour ?? throw new ArgumentNullException(nameof(preDetour)); 121 | PostDetour = postDetour ?? throw new ArgumentNullException(nameof(postDetour)); 122 | } 123 | } -------------------------------------------------------------------------------- /CSSharpFixes/Detours/ProcessUserCmdsHandler.cs: -------------------------------------------------------------------------------- 1 | /* 2 | ============================================================================= 3 | CS#Fixes 4 | Copyright (C) 2023-2024 Charles Barone / hypnos 5 | ============================================================================= 6 | 7 | This program is free software; you can redistribute it and/or modify it under 8 | the terms of the GNU General Public License, version 3.0, as published by the 9 | Free Software Foundation. 10 | 11 | This program is distributed in the hope that it will be useful, but WITHOUT 12 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 13 | FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 14 | details. 15 | 16 | You should have received a copy of the GNU General Public License along with 17 | this program. If not, see . 18 | */ 19 | 20 | using CounterStrikeSharp.API; 21 | using CounterStrikeSharp.API.Core; 22 | using CounterStrikeSharp.API.Modules.Memory.DynamicFunctions; 23 | using CSSharpFixes.Extensions; 24 | using CSSharpFixes.Models; 25 | using CSSharpFixes.Schemas.Protobuf; 26 | using Microsoft.Extensions.Logging; 27 | using CBaseUserCmdPB = CSSharpFixes.Schemas.Protobuf.CBaseUserCmdPB; 28 | 29 | namespace CSSharpFixes.Detours; 30 | 31 | public class ProcessUserCmdsHandler : PreHandler 32 | { 33 | private ProcessUserCmdsHandler(string name, Detour preDetour, ILogger logger) 34 | : base(name, preDetour, logger) {} 35 | 36 | ~ProcessUserCmdsHandler() { Stop(); } 37 | 38 | // Gets called in BaseHandler by public static T Build(ILogger logger) where T : BaseHandler 39 | public static ProcessUserCmdsHandler Build(ILogger logger) 40 | { 41 | Detour preDetour = new Detour("ProcessUserCmdsPreDetour", "ProcessUsercmds", HookMode.Pre, logger); 42 | return new ProcessUserCmdsHandler("ProcessUserCmdsHandler", preDetour, logger); 43 | } 44 | 45 | public override void Start() 46 | { 47 | PreDetour.Hook(ProcessUserCmdsPre); 48 | } 49 | 50 | public override void Stop() 51 | { 52 | UnhookAllDetours(); 53 | } 54 | 55 | private HookResult ProcessUserCmdsPre(DynamicHook h) 56 | { 57 | IntPtr playerPtr = h.GetParam(0); 58 | CCSPlayerController tempPlayer = new (playerPtr); 59 | CCSPlayerController? player = Utilities.GetPlayerFromSlot(tempPlayer.Slot); 60 | if(!player.IsCompletelyValid() || !player.IsAlive() || player?.PlayerPawn.Value == null 61 | || player.IsBot || !player.IsOnATeam()) return HookResult.Continue; 62 | 63 | CCSPlayerPawn playerPawn = player.PlayerPawn.Value; 64 | CPlayer_MovementServices? movementServices = playerPawn.MovementServices; 65 | if(movementServices == null) return HookResult.Continue; 66 | 67 | if (playerPawn.MoveType != MoveType_t.MOVETYPE_WALK && playerPawn.MoveType != MoveType_t.MOVETYPE_PUSH) 68 | return HookResult.Continue; 69 | 70 | // get the number of commands 71 | int numCommands = h.GetParam(2); 72 | 73 | // https://github.com/maecry/asphyxia-cs2/blob/master/cstrike/sdk/datatypes/usercmd.h#L262-L291 74 | IntPtr cmdsPtr = h.GetParam(1); 75 | 76 | for (ulong cmdIdx = 0; cmdIdx < (ulong)numCommands; cmdIdx++) 77 | { 78 | IntPtr cmdPtr = (IntPtr)((ulong)cmdsPtr + cmdIdx * CUserCmd.Size()); 79 | CUserCmd cUserCmd = new(cmdPtr); 80 | 81 | // if(cUserCmd.LeftHandDesired != null) 82 | // _logger.LogInformation("[OnProcessUsercmds][cmdIdx={0}][LeftHandDesired={1}]", 83 | // cmdIdx, cUserCmd.LeftHandDesired); 84 | 85 | CBaseUserCmdPB? cBaseUserCmdPb = cUserCmd.Base; 86 | if(cBaseUserCmdPb == null) continue; 87 | 88 | // if(cBaseUserCmdPb.CommandNumber != null && cBaseUserCmdPb.CommandNumber != 0) 89 | // _logger.LogInformation("[OnProcessUsercmds][cmdIdx={0}][CommandNumber={1}]", 90 | // cmdIdx, cBaseUserCmdPb.CommandNumber.Value.ToString() ); 91 | // if(cBaseUserCmdPb.ClientTick != null && cBaseUserCmdPb.ClientTick != 0) 92 | // _logger.LogInformation("[OnProcessUsercmds][cmdIdx={0}][ClientTick={1}]", 93 | // cmdIdx, cBaseUserCmdPb.ClientTick.Value.ToString() ); 94 | // if (cBaseUserCmdPb.ForwardMove != null && cBaseUserCmdPb.ForwardMove != 0.0f) 95 | // _logger.LogInformation("[OnProcessUsercmds][cmdIdx={0}][ForwardMove={1}]", 96 | // cmdIdx, cBaseUserCmdPb.ForwardMove.Value); 97 | // if(cBaseUserCmdPb.SideMove != null && cBaseUserCmdPb.SideMove != 0.0f) 98 | // _logger.LogInformation("[OnProcessUsercmds][cmdIdx={0}][SideMove={1}]", 99 | // cmdIdx, cBaseUserCmdPb.SideMove.Value ); 100 | // if(cBaseUserCmdPb.UpMove != null && cBaseUserCmdPb.UpMove != 0.0f) 101 | // _logger.LogInformation("[OnProcessUsercmds][cmdIdx={0}][UpMove={1}]", 102 | // cmdIdx, cBaseUserCmdPb.UpMove.Value ); 103 | // if(cBaseUserCmdPb.Impulse != null && cBaseUserCmdPb.Impulse != 0) 104 | // _logger.LogInformation("[OnProcessUsercmds][cmdIdx={0}][Impulse={1}]", 105 | // cmdIdx, cBaseUserCmdPb.Impulse.Value.ToString() ); 106 | // if(cBaseUserCmdPb.WeaponSelect != null && cBaseUserCmdPb.WeaponSelect != 0) 107 | // _logger.LogInformation("[OnProcessUsercmds][cmdIdx={0}][WeaponSelect={1}]", 108 | // cmdIdx, cBaseUserCmdPb.WeaponSelect.Value.ToString() ); 109 | 110 | // if(*currentSize > 0) _logger.LogInformation("[OnProcessUsercmds][cmdIdx={0}][currentSize={1}]", 111 | // cmdIdx, *currentSize); 112 | 113 | Schemas.Protobuf.Interop.RepeatedPtrField? subTickMoves = cBaseUserCmdPb.SubtickMoves; 114 | if(subTickMoves == null) continue; 115 | if(subTickMoves.CurrentSize == null || subTickMoves.CurrentSize == 0) continue; 116 | 117 | // if(subTickMoves.CurrentSize != null && subTickMoves.CurrentSize != 0) 118 | // _logger.LogInformation("[OnProcessUsercmds][cmdIdx={0}][CurrentSize={1}]", 119 | // cmdIdx, subTickMoves.CurrentSize.Value ); 120 | // if(subTickMoves.TotalSize != null && subTickMoves.TotalSize != 0) 121 | // _logger.LogInformation("[OnProcessUsercmds][cmdIdx={0}][TotalSize={1}]", 122 | // cmdIdx, subTickMoves.TotalSize.Value ); 123 | 124 | Schemas.Protobuf.Interop.Rep? rep = subTickMoves.Rep; 125 | if(rep == null) continue; 126 | 127 | // if(rep.AllocatedSize != null && rep.AllocatedSize != 0) 128 | // _logger.LogInformation("[OnProcessUsercmds][cmdIdx={0}][AllocatedSize={1}]", 129 | // cmdIdx, rep.AllocatedSize.Value ); 130 | 131 | for (int subTickMoveIdx = 0; subTickMoveIdx < subTickMoves.CurrentSize; subTickMoveIdx++) 132 | { 133 | IntPtr? subTickMoveAddress = subTickMoves[subTickMoveIdx]; 134 | if(subTickMoveAddress == null) continue; 135 | CSubTickMoveStep subTickMove = new((IntPtr)subTickMoveAddress); 136 | if(subTickMove.Pressed == null) continue; 137 | if(subTickMove.When == null) continue; 138 | 139 | if(subTickMove.When > 0.0f) 140 | { 141 | // There's some weird case where this can happen if you constantly walk against a trigger push. 142 | // This should never be a huge number if it is, skip it... 143 | if(subTickMove.When > 1000.0f) continue; 144 | if(subTickMove.When < 0.0001) continue; 145 | 146 | // if(subTickMove.Pressed != null && subTickMove.Pressed == true) 147 | // _logger.LogInformation("[OnProcessUsercmds][cmdIdx={0}][subTickMoveIdx={1}][Pressed={2}]", 148 | // cmdIdx, subTickMoveIdx, subTickMove.Pressed.Value); 149 | 150 | // _logger.LogInformation("[OnProcessUsercmds][cmdIdx={0}][subTickMoveIdx={1}][whenPre={2}]", 151 | // cmdIdx, subTickMoveIdx, subTickMove.When); 152 | 153 | subTickMove.When = 0.0f; 154 | 155 | // _logger.LogInformation("[OnProcessUsercmds][cmdIdx={0}][subTickMoveIdx={1}][whenPost={2}]", 156 | // cmdIdx, subTickMoveIdx, subTickMove.When); 157 | } 158 | } 159 | } 160 | return HookResult.Changed; 161 | } 162 | } -------------------------------------------------------------------------------- /CSSharpFixes/Detours/TriggerPushTouchHandler.cs: -------------------------------------------------------------------------------- 1 | /* 2 | ============================================================================= 3 | CS#Fixes 4 | Copyright (C) 2023-2024 Charles Barone / hypnos 5 | ============================================================================= 6 | 7 | This program is free software; you can redistribute it and/or modify it under 8 | the terms of the GNU General Public License, version 3.0, as published by the 9 | Free Software Foundation. 10 | 11 | This program is distributed in the hope that it will be useful, but WITHOUT 12 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 13 | FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 14 | details. 15 | 16 | You should have received a copy of the GNU General Public License along with 17 | this program. If not, see . 18 | */ 19 | 20 | using CounterStrikeSharp.API; 21 | using CounterStrikeSharp.API.Core; 22 | using CounterStrikeSharp.API.Modules.Memory; 23 | using CounterStrikeSharp.API.Modules.Memory.DynamicFunctions; 24 | using CounterStrikeSharp.API.Modules.Utils; 25 | using CSSharpFixes.Extensions; 26 | using CSSharpFixes.Models; 27 | using Microsoft.Extensions.Logging; 28 | 29 | namespace CSSharpFixes.Detours; 30 | 31 | public class TriggerPushTouchHandler : PreHandler 32 | { 33 | private TriggerPushTouchHandler(string name, Detour preDetour, ILogger logger) 34 | : base(name, preDetour, logger) {} 35 | 36 | ~TriggerPushTouchHandler() { Stop(); } 37 | 38 | // Gets called in BaseHandler by public static T Build(ILogger logger) where T : BaseHandler 39 | public static TriggerPushTouchHandler Build(ILogger logger) 40 | { 41 | Detour preDetour = new Detour("TriggerPushTouchPreDetour", "TriggerPush_Touch", HookMode.Pre, logger); 42 | return new TriggerPushTouchHandler("TriggerPushTouchHandler", preDetour, logger); 43 | } 44 | 45 | public override void Start() 46 | { 47 | PreDetour.Hook(TriggerPushTouchPre); 48 | } 49 | 50 | public override void Stop() 51 | { 52 | UnhookAllDetours(); 53 | } 54 | 55 | private static readonly uint SF_TRIG_PUSH_ONCE = 0x80; 56 | 57 | private HookResult TriggerPushTouchPre(DynamicHook h) 58 | { 59 | // Get the trigger_push entity 60 | IntPtr triggerPushPtr = h.GetParam(0); 61 | if(triggerPushPtr == IntPtr.Zero) return HookResult.Continue; 62 | CTriggerPush triggerPush = new(triggerPushPtr); 63 | 64 | // This trigger pushes only once (and kills itself) or pushes only on StartTouch, 65 | // both of which are fine already, return to the original function 66 | if(!triggerPush.IsValid) return HookResult.Continue; 67 | if((triggerPush.Spawnflags & SF_TRIG_PUSH_ONCE) > 0) return HookResult.Continue; 68 | if(triggerPush.TriggerOnStartTouch) return HookResult.Continue; 69 | 70 | // Get the entity being pushed 71 | IntPtr otherPtr = h.GetParam(1); 72 | if(otherPtr == IntPtr.Zero) return HookResult.Continue; 73 | CBaseEntity other = new(otherPtr); 74 | if(!other.IsValid) return HookResult.Continue; 75 | 76 | // Get the entity's move type. 77 | MoveType_t moveType = other.ActualMoveType; 78 | 79 | // VPhysics handling doesn't need any changes 80 | if(moveType == MoveType_t.MOVETYPE_VPHYSICS) return HookResult.Continue; 81 | 82 | // Do not push entities that have these move types 83 | if (moveType == MoveType_t.MOVETYPE_NONE || moveType == MoveType_t.MOVETYPE_PUSH || 84 | moveType == MoveType_t.MOVETYPE_NOCLIP) 85 | return HookResult.Handled; 86 | 87 | // Do not push entities that are not solid 88 | CCollisionProperty? collision = other.Collision; 89 | if(collision == null) return HookResult.Handled; 90 | if(!Utils.IsSolid(collision)) return HookResult.Handled; 91 | 92 | if(!triggerPush.PassesTriggerFilters(other.Handle)) return HookResult.Handled; 93 | 94 | // Cancel if the entity being pushed has a parent scene node 95 | CBodyComponent? otherBodyComponent = other.CBodyComponent; 96 | if(otherBodyComponent == null) return HookResult.Handled; 97 | CGameSceneNode? otherSceneNode = otherBodyComponent.SceneNode; 98 | if(otherSceneNode == null) return HookResult.Handled; 99 | CGameSceneNode? parentSceneNode = otherSceneNode.PParent; 100 | if(parentSceneNode != null) return HookResult.Handled; 101 | 102 | // Get the push entity's scene node 103 | CBodyComponent? pushBodyComponent = triggerPush.CBodyComponent; 104 | if(pushBodyComponent == null) return HookResult.Handled; 105 | CGameSceneNode? pushSceneNode = pushBodyComponent.SceneNode; 106 | if(pushSceneNode == null) return HookResult.Handled; 107 | 108 | Vector vecAbsDir = new(); 109 | // matrix3x4_t 110 | float[,]? matTransform = pushSceneNode.EntityToWorldTransform(); 111 | if(matTransform == null) return HookResult.Handled; 112 | 113 | // _logger.LogInformation("[TriggerPushFix] moveType = {moveType}", moveType); 114 | 115 | Vector vecPushDir = triggerPush.PushDirEntitySpace; 116 | // _logger.LogInformation("[TriggerPushFix] vecPushDir = {vecPushDir}", vecPushDir); 117 | Utils.VectorRotate(vecPushDir, matTransform, ref vecAbsDir); 118 | // _logger.LogInformation("[TriggerPushFix] vecAbsDir = {vecAbsDir}", vecAbsDir); 119 | 120 | Vector vecPush = vecAbsDir * triggerPush.Speed; 121 | // _logger.LogInformation("[TriggerPushFix] triggerPush.Speed = {triggerPushSpeed}", triggerPush.Speed); 122 | // _logger.LogInformation("[TriggerPushFix] vecPush = {vecPush}", vecPush); 123 | 124 | uint flags = other.Flags; 125 | // _logger.LogInformation("[TriggerPushFix] flags = {flags}", flags); 126 | // _logger.LogInformation("[TriggerPushFix] other.BaseVelocity = {BaseVelocity}", other.BaseVelocity); 127 | 128 | // FL_BASEVELOCITY missing from CS# PlayerFlags Enum 129 | //https://github.com/alliedmodders/hl2sdk/blob/67ba01d05038f55448fa792c09c9aae3d0bb8263/public/const.h#L133 130 | const uint flBasevelocity = 1 << 23; 131 | if((flags & flBasevelocity) > 0) vecPush += other.BaseVelocity; 132 | // _logger.LogInformation("[TriggerPushFix] vecPush = {vecPush}", vecPush); 133 | 134 | if(vecPush.Z > 0.0f && (flags & (uint)PlayerFlags.FL_ONGROUND) > 0) 135 | { 136 | other.SetGroundEntity(IntPtr.Zero); 137 | Vector? origin = other.AbsOrigin; 138 | if (origin != null) 139 | { 140 | origin.Z += 1.0f; 141 | other.TeleportPositionOnly(origin); 142 | } 143 | } 144 | 145 | // Vector vecOriginalPush = vecAbsDir * triggerPush.Speed; 146 | // _logger.LogInformation( 147 | // "[TriggerPushFix] Pushing entity {entity} | entity basevelocity {flag} = {entBaseVel} | original push velocity = {original} | final push velocity = {final}", 148 | // other.Index, 149 | // (flags & flBasevelocity) > 0 ? "WITH FLAG":"", 150 | // other.BaseVelocity, 151 | // vecOriginalPush, 152 | // vecPush 153 | // ); 154 | 155 | // _logger.LogInformation("[TriggerPushFix] PRE other.BaseVelocity = {BaseVelocity}", other.BaseVelocity); 156 | other.SetBaseVelocity(vecPush); 157 | Utilities.SetStateChanged(other, "CBaseEntity", "m_vecBaseVelocity"); 158 | // _logger.LogInformation("[TriggerPushFix] POST other.BaseVelocity = {BaseVelocity}", other.BaseVelocity); 159 | 160 | flags |= flBasevelocity; 161 | other.Flags = flags; 162 | 163 | // _logger.LogInformation("TriggerPushTouch [Finished Fix]"); 164 | return HookResult.Handled; 165 | } 166 | } -------------------------------------------------------------------------------- /CSSharpFixes/Enums/Detours/Mode.cs: -------------------------------------------------------------------------------- 1 | /* 2 | ============================================================================= 3 | CS#Fixes 4 | Copyright (C) 2023-2024 Charles Barone / hypnos 5 | ============================================================================= 6 | 7 | This program is free software; you can redistribute it and/or modify it under 8 | the terms of the GNU General Public License, version 3.0, as published by the 9 | Free Software Foundation. 10 | 11 | This program is distributed in the hope that it will be useful, but WITHOUT 12 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 13 | FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 14 | details. 15 | 16 | You should have received a copy of the GNU General Public License along with 17 | this program. If not, see . 18 | */ 19 | 20 | namespace CSSharpFixes.Enums.Detours; 21 | 22 | public enum Mode 23 | { 24 | Pre, 25 | Post, 26 | Both 27 | } -------------------------------------------------------------------------------- /CSSharpFixes/Extensions/CBaseEntityExtensions.cs: -------------------------------------------------------------------------------- 1 | /* 2 | ============================================================================= 3 | CS#Fixes 4 | Copyright (C) 2023-2024 Charles Barone / hypnos 5 | ============================================================================= 6 | 7 | This program is free software; you can redistribute it and/or modify it under 8 | the terms of the GNU General Public License, version 3.0, as published by the 9 | Free Software Foundation. 10 | 11 | This program is distributed in the hope that it will be useful, but WITHOUT 12 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 13 | FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 14 | details. 15 | 16 | You should have received a copy of the GNU General Public License along with 17 | this program. If not, see . 18 | */ 19 | 20 | using CounterStrikeSharp.API.Core; 21 | using CounterStrikeSharp.API.Modules.Memory; 22 | using CounterStrikeSharp.API.Modules.Memory.DynamicFunctions; 23 | using CounterStrikeSharp.API.Modules.Utils; 24 | 25 | namespace CSSharpFixes.Extensions; 26 | 27 | public static class CBaseEntityExtensions 28 | { 29 | public static void SetGroundEntity(this CBaseEntity? baseEntity, IntPtr groundEntityHandle) 30 | { 31 | if (baseEntity is null) return; 32 | 33 | MemoryFunctionVoid setGroundEntityFunc = new(GameData.GetSignature("SetGroundEntity")); 34 | Action setGroundEntity = setGroundEntityFunc.Invoke; 35 | setGroundEntity(baseEntity.Handle, groundEntityHandle, IntPtr.Zero); 36 | } 37 | 38 | // Add a setter for BaseVelocity to CBaseEntity so it can be set with a Vector in 1 line 39 | public static void SetBaseVelocity(this CBaseEntity? baseEntity, Vector baseVelocity) 40 | { 41 | if(baseEntity is null) return; 42 | if(!baseEntity.IsValid) return; 43 | baseEntity.BaseVelocity.X = baseVelocity.X; 44 | baseEntity.BaseVelocity.Y = baseVelocity.Y; 45 | baseEntity.BaseVelocity.Z = baseVelocity.Z; 46 | } 47 | 48 | public static void TeleportPositionOnly(this CBaseEntity? baseEntity, Vector position) 49 | { 50 | if(baseEntity is null) return; 51 | if(!baseEntity.IsValid) return; 52 | VirtualFunction.CreateVoid(baseEntity.Handle, GameData.GetOffset("CBaseEntity_Teleport"))( 53 | baseEntity.Handle, position.Handle, IntPtr.Zero, IntPtr.Zero); 54 | } 55 | } -------------------------------------------------------------------------------- /CSSharpFixes/Extensions/CBaseTriggerExtensions.cs: -------------------------------------------------------------------------------- 1 | /* 2 | ============================================================================= 3 | CS#Fixes 4 | Copyright (C) 2023-2024 Charles Barone / hypnos 5 | ============================================================================= 6 | 7 | This program is free software; you can redistribute it and/or modify it under 8 | the terms of the GNU General Public License, version 3.0, as published by the 9 | Free Software Foundation. 10 | 11 | This program is distributed in the hope that it will be useful, but WITHOUT 12 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 13 | FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 14 | details. 15 | 16 | You should have received a copy of the GNU General Public License along with 17 | this program. If not, see . 18 | */ 19 | 20 | using CounterStrikeSharp.API.Core; 21 | using CounterStrikeSharp.API.Modules.Memory; 22 | 23 | namespace CSSharpFixes.Extensions; 24 | 25 | public static class CBaseTriggerExtensions 26 | { 27 | public static bool PassesTriggerFilters(this CBaseTrigger? trigger, IntPtr pOther) 28 | { 29 | if (trigger is null || !trigger.IsValid) return false; 30 | return VirtualFunction.Create(trigger.Handle, GameData.GetOffset("PassesTriggerFilters"))( 31 | trigger.Handle, pOther); 32 | } 33 | } -------------------------------------------------------------------------------- /CSSharpFixes/Extensions/CGameSceneNodeExtensions.cs: -------------------------------------------------------------------------------- 1 | /* 2 | ============================================================================= 3 | CS#Fixes 4 | Copyright (C) 2023-2024 Charles Barone / hypnos 5 | ============================================================================= 6 | 7 | This program is free software; you can redistribute it and/or modify it under 8 | the terms of the GNU General Public License, version 3.0, as published by the 9 | Free Software Foundation. 10 | 11 | This program is distributed in the hope that it will be useful, but WITHOUT 12 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 13 | FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 14 | details. 15 | 16 | You should have received a copy of the GNU General Public License along with 17 | this program. If not, see . 18 | */ 19 | 20 | using CounterStrikeSharp.API.Core; 21 | using CounterStrikeSharp.API.Modules.Utils; 22 | 23 | namespace CSSharpFixes.Extensions; 24 | 25 | public static class CGameSceneNodeExtensions 26 | { 27 | public static float[,]? EntityToWorldTransform(this CGameSceneNode? sceneNode) 28 | { 29 | if (sceneNode is null) return null; 30 | 31 | // matrix3x4_t 32 | float[,] mat = new float[3, 4]; 33 | 34 | QAngle angles = sceneNode.AbsRotation; 35 | float sr, sp, sy, cr, cp, cy; 36 | 37 | Utils.SinCos(Utils.DegToRad(angles.Y), out sy, out cy); // YAW 38 | Utils.SinCos(Utils.DegToRad(angles.X), out sp, out cp); // PITCH 39 | Utils.SinCos(Utils.DegToRad(angles.Z), out sr, out cr); // ROLL 40 | 41 | mat[0, 0] = cp * cy; 42 | mat[1, 0] = cp * sy; 43 | mat[2, 0] = -sp; 44 | 45 | float crcy = cr * cy; 46 | float crsy = cr * sy; 47 | float srcy = sr * cy; 48 | float srsy = sr * sy; 49 | 50 | mat[0, 1] = sp * srcy - crsy; 51 | mat[1, 1] = sp * srsy + crcy; 52 | mat[2, 1] = sr * cp; 53 | 54 | mat[0, 2] = sp * crcy + srsy; 55 | mat[1, 2] = sp * crsy - srcy; 56 | mat[2, 2] = cr * cp; 57 | 58 | Vector pos = sceneNode.AbsOrigin; 59 | mat[0, 3] = pos.X; 60 | mat[1, 3] = pos.Y; 61 | mat[2, 3] = pos.Z; 62 | 63 | return mat; 64 | } 65 | } -------------------------------------------------------------------------------- /CSSharpFixes/Extensions/PlayerExtensions.cs: -------------------------------------------------------------------------------- 1 | /* 2 | ============================================================================= 3 | CS#Fixes 4 | Copyright (C) 2023-2024 Charles Barone / hypnos 5 | ============================================================================= 6 | 7 | This program is free software; you can redistribute it and/or modify it under 8 | the terms of the GNU General Public License, version 3.0, as published by the 9 | Free Software Foundation. 10 | 11 | This program is distributed in the hope that it will be useful, but WITHOUT 12 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 13 | FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 14 | details. 15 | 16 | You should have received a copy of the GNU General Public License along with 17 | this program. If not, see . 18 | */ 19 | 20 | using System.Diagnostics.CodeAnalysis; 21 | using CounterStrikeSharp.API; 22 | using CounterStrikeSharp.API.Core; 23 | using CounterStrikeSharp.API.Modules.Entities.Constants; 24 | using CounterStrikeSharp.API.Modules.Utils; 25 | 26 | namespace CSSharpFixes.Extensions; 27 | 28 | public static class PlayerExtensions 29 | { 30 | public static bool IsCompletelyValid(this CCSPlayerController? player, 31 | [MaybeNullWhen(false)] out CCSPlayerPawn playerPawn, 32 | [MaybeNullWhen(false)] out CBasePlayerPawn pawn 33 | ) 34 | { 35 | playerPawn = null; 36 | pawn = null; 37 | if (player is null) return false; 38 | 39 | if (!player.IsCompletelyValid(out playerPawn)) return false; 40 | 41 | if (!player.Pawn.IsValid) return false; 42 | pawn = player.Pawn.Value; 43 | 44 | if (pawn is null) return false; 45 | return pawn.Handle != IntPtr.Zero; 46 | } 47 | 48 | public static bool IsCompletelyValid(this CCSPlayerController? player, 49 | [MaybeNullWhen(false)] out CCSPlayerPawn playerPawn 50 | ) 51 | { 52 | playerPawn = null; 53 | if (player is null) return false; 54 | 55 | if (!player.IsCompletelyValid()) return false; 56 | if (!player.PlayerPawn.IsValid) return false; 57 | 58 | 59 | playerPawn = player.PlayerPawn.Value; 60 | if (playerPawn is null) return false; 61 | 62 | return playerPawn.Handle != IntPtr.Zero; 63 | } 64 | 65 | public static bool IsCompletelyValid(this CCSPlayerController? player) 66 | { 67 | if (player is null) return false; 68 | if (!player.IsValid) return false; 69 | if (player.Handle == IntPtr.Zero) return false; 70 | if (player.Connected != PlayerConnectedState.PlayerConnected) return false; 71 | return true; 72 | } 73 | 74 | public static bool IsAlive(this CCSPlayerController? player) 75 | { 76 | if (!player.IsCompletelyValid(out var playerPawn)) return false; 77 | return playerPawn.LifeState == (int)LifeState_t.LIFE_ALIVE; 78 | } 79 | 80 | public static bool IsDying(this CCSPlayerController? player) 81 | { 82 | if (!player.IsCompletelyValid(out var playerPawn)) return false; 83 | return playerPawn.LifeState == (int)LifeState_t.LIFE_DYING; 84 | } 85 | 86 | public static bool IsDead(this CCSPlayerController? player) 87 | { 88 | if (!player.IsCompletelyValid(out var playerPawn)) return false; 89 | return playerPawn.LifeState == (int)LifeState_t.LIFE_DEAD; 90 | } 91 | 92 | public static bool IsTerrorist(this CCSPlayerController? player) 93 | { 94 | return player.IsOnTeam(CsTeam.Terrorist); 95 | } 96 | 97 | public static bool IsCounterTerrorist(this CCSPlayerController? player) 98 | { 99 | return player.IsOnTeam(CsTeam.CounterTerrorist); 100 | } 101 | 102 | public static bool IsOnATeam(this CCSPlayerController? player) 103 | { 104 | return player.IsTerrorist() || player.IsCounterTerrorist(); 105 | } 106 | 107 | public static bool IsOnTeam(this CCSPlayerController? player, CsTeam team) 108 | { 109 | if (!player.IsCompletelyValid(out var playerPawn)) return false; 110 | return playerPawn.TeamNum == (byte)team; 111 | } 112 | 113 | public static void SetCollisionGroup(this CCSPlayerPawn playerPawn, CollisionGroup collisionGroup) 114 | { 115 | if(!playerPawn.IsValid) return; 116 | 117 | playerPawn.Collision.CollisionAttribute.CollisionGroup = (byte)collisionGroup; 118 | playerPawn.Collision.CollisionGroup = (byte)collisionGroup; 119 | 120 | Utilities.SetStateChanged(playerPawn, "CCollisionProperty", "m_CollisionGroup"); 121 | Utilities.SetStateChanged(playerPawn, "CCollisionProperty", "m_collisionAttribute"); 122 | 123 | } 124 | } -------------------------------------------------------------------------------- /CSSharpFixes/Fixes/BaseFix.cs: -------------------------------------------------------------------------------- 1 | /* 2 | ============================================================================= 3 | CS#Fixes 4 | Copyright (C) 2023-2024 Charles Barone / hypnos 5 | ============================================================================= 6 | 7 | This program is free software; you can redistribute it and/or modify it under 8 | the terms of the GNU General Public License, version 3.0, as published by the 9 | Free Software Foundation. 10 | 11 | This program is distributed in the hope that it will be useful, but WITHOUT 12 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 13 | FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 14 | details. 15 | 16 | You should have received a copy of the GNU General Public License along with 17 | this program. If not, see . 18 | */ 19 | 20 | namespace CSSharpFixes.Fixes; 21 | 22 | public abstract class BaseFix 23 | { 24 | public string Name = String.Empty; 25 | public string ConfigurationProperty = String.Empty; 26 | public List PatchNames = new(); 27 | public List DetourHandlerNames = new(); 28 | public Dictionary Events = new(); 29 | public Boolean Enabled = false; 30 | } -------------------------------------------------------------------------------- /CSSharpFixes/Fixes/CPhysBoxUseFix.cs: -------------------------------------------------------------------------------- 1 | /* 2 | ============================================================================= 3 | CS#Fixes 4 | Copyright (C) 2023-2024 Charles Barone / hypnos 5 | ============================================================================= 6 | 7 | This program is free software; you can redistribute it and/or modify it under 8 | the terms of the GNU General Public License, version 3.0, as published by the 9 | Free Software Foundation. 10 | 11 | This program is distributed in the hope that it will be useful, but WITHOUT 12 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 13 | FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 14 | details. 15 | 16 | You should have received a copy of the GNU General Public License along with 17 | this program. If not, see . 18 | */ 19 | 20 | namespace CSSharpFixes.Fixes; 21 | 22 | public class CPhysBoxUseFix: BaseFix 23 | { 24 | public CPhysBoxUseFix() 25 | { 26 | Name = "CPhysBoxUseFix"; 27 | ConfigurationProperty = "EnableCPhysBoxUseFix"; 28 | PatchNames = 29 | [ 30 | "CPhysBox_Use" 31 | ]; 32 | } 33 | } -------------------------------------------------------------------------------- /CSSharpFixes/Fixes/EntityStringPurgeFix.cs: -------------------------------------------------------------------------------- 1 | /* 2 | ============================================================================= 3 | CS#Fixes 4 | Copyright (C) 2023-2024 Charles Barone / hypnos 5 | ============================================================================= 6 | 7 | This program is free software; you can redistribute it and/or modify it under 8 | the terms of the GNU General Public License, version 3.0, as published by the 9 | Free Software Foundation. 10 | 11 | This program is distributed in the hope that it will be useful, but WITHOUT 12 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 13 | FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 14 | details. 15 | 16 | You should have received a copy of the GNU General Public License along with 17 | this program. If not, see . 18 | */ 19 | 20 | using CounterStrikeSharp.API.Core; 21 | using CounterStrikeSharp.API.Modules.Events; 22 | using Microsoft.Extensions.Logging; 23 | 24 | namespace CSSharpFixes.Fixes; 25 | 26 | public class EntityStringPurgeFix: BaseFix 27 | { 28 | public EntityStringPurgeFix() 29 | { 30 | Name = "EntityStringPurgeFix"; 31 | ConfigurationProperty = "EnableEntityStringPurge"; 32 | Events = new Dictionary 33 | { 34 | { "OnRoundStartPre", OnRoundStartPre } 35 | }; 36 | } 37 | 38 | public HookResult OnRoundStartPre(GameEvent @event, GameEventInfo info, ILogger logger) 39 | { 40 | if(@event is not EventRoundPrestart roundPrestartEvent) return HookResult.Continue; 41 | logger.LogInformation("[CSSharpFixes][Fix][EntityStringPurgeFix][OnRoundStartPre()][NOT IMPLEMENTED]"); 42 | 43 | //TODO: Finish implementing this. requires adding to C++ side of CounterStrikeSharp to finish. 44 | 45 | return HookResult.Continue; 46 | } 47 | } -------------------------------------------------------------------------------- /CSSharpFixes/Fixes/FullAllTalkFix.cs: -------------------------------------------------------------------------------- 1 | /* 2 | ============================================================================= 3 | CS#Fixes 4 | Copyright (C) 2023-2024 Charles Barone / hypnos 5 | ============================================================================= 6 | 7 | This program is free software; you can redistribute it and/or modify it under 8 | the terms of the GNU General Public License, version 3.0, as published by the 9 | Free Software Foundation. 10 | 11 | This program is distributed in the hope that it will be useful, but WITHOUT 12 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 13 | FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 14 | details. 15 | 16 | You should have received a copy of the GNU General Public License along with 17 | this program. If not, see . 18 | */ 19 | 20 | using CounterStrikeSharp.API; 21 | using CounterStrikeSharp.API.Core; 22 | using CounterStrikeSharp.API.Modules.Events; 23 | using Microsoft.Extensions.Logging; 24 | 25 | namespace CSSharpFixes.Fixes; 26 | 27 | public class FullAllTalkFix: BaseFix 28 | { 29 | public FullAllTalkFix() 30 | { 31 | Name = "FullAllTalkFix"; 32 | ConfigurationProperty = "EnforceFullAlltalk"; 33 | Events = new Dictionary 34 | { 35 | { "OnRoundStart", OnRoundStart }, 36 | }; 37 | } 38 | 39 | public HookResult OnRoundStart(GameEvent @event, GameEventInfo info, ILogger logger) 40 | { 41 | Server.ExecuteCommand("sv_full_alltalk 1"); 42 | logger.LogInformation("[CSSharpFixes][Fix][FullAllTalkFix][OnRoundStart()][sv_full_alltalk set to 1]"); 43 | return HookResult.Continue; 44 | } 45 | } -------------------------------------------------------------------------------- /CSSharpFixes/Fixes/Interfaces/ITickable.cs: -------------------------------------------------------------------------------- 1 | /* 2 | ============================================================================= 3 | CS#Fixes 4 | Copyright (C) 2023-2024 Charles Barone / hypnos 5 | ============================================================================= 6 | 7 | This program is free software; you can redistribute it and/or modify it under 8 | the terms of the GNU General Public License, version 3.0, as published by the 9 | Free Software Foundation. 10 | 11 | This program is distributed in the hope that it will be useful, but WITHOUT 12 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 13 | FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 14 | details. 15 | 16 | You should have received a copy of the GNU General Public License along with 17 | this program. If not, see . 18 | */ 19 | 20 | using CounterStrikeSharp.API.Core; 21 | 22 | namespace CSSharpFixes.Fixes.Interfaces; 23 | 24 | public interface ITickable 25 | { 26 | void OnTick(List players); 27 | } -------------------------------------------------------------------------------- /CSSharpFixes/Fixes/MovementUnlockerFix.cs: -------------------------------------------------------------------------------- 1 | /* 2 | ============================================================================= 3 | CS#Fixes 4 | Copyright (C) 2023-2024 Charles Barone / hypnos 5 | ============================================================================= 6 | 7 | This program is free software; you can redistribute it and/or modify it under 8 | the terms of the GNU General Public License, version 3.0, as published by the 9 | Free Software Foundation. 10 | 11 | This program is distributed in the hope that it will be useful, but WITHOUT 12 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 13 | FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 14 | details. 15 | 16 | You should have received a copy of the GNU General Public License along with 17 | this program. If not, see . 18 | */ 19 | 20 | namespace CSSharpFixes.Fixes; 21 | 22 | public class MovementUnlockerFix: BaseFix 23 | { 24 | public MovementUnlockerFix() 25 | { 26 | Name = "MovementUnlockerFix"; 27 | ConfigurationProperty = "EnableMovementUnlocker"; 28 | PatchNames = 29 | [ 30 | "ServerMovementUnlock" 31 | ]; 32 | } 33 | } -------------------------------------------------------------------------------- /CSSharpFixes/Fixes/NavmeshLookupLagFix.cs: -------------------------------------------------------------------------------- 1 | /* 2 | ============================================================================= 3 | CS#Fixes 4 | Copyright (C) 2023-2024 Charles Barone / hypnos 5 | ============================================================================= 6 | 7 | This program is free software; you can redistribute it and/or modify it under 8 | the terms of the GNU General Public License, version 3.0, as published by the 9 | Free Software Foundation. 10 | 11 | This program is distributed in the hope that it will be useful, but WITHOUT 12 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 13 | FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 14 | details. 15 | 16 | You should have received a copy of the GNU General Public License along with 17 | this program. If not, see . 18 | */ 19 | 20 | namespace CSSharpFixes.Fixes; 21 | 22 | public class NavmeshLookupLagFix: BaseFix 23 | { 24 | public NavmeshLookupLagFix() 25 | { 26 | Name = "NavmeshLookupLagFix"; 27 | ConfigurationProperty = "EnableNavmeshLookupLagFix"; 28 | PatchNames = 29 | [ 30 | "BotNavIgnore" 31 | ]; 32 | } 33 | } -------------------------------------------------------------------------------- /CSSharpFixes/Fixes/NoBlockFix.cs: -------------------------------------------------------------------------------- 1 | /* 2 | ============================================================================= 3 | CS#Fixes 4 | Copyright (C) 2023-2024 Charles Barone / hypnos 5 | ============================================================================= 6 | 7 | This program is free software; you can redistribute it and/or modify it under 8 | the terms of the GNU General Public License, version 3.0, as published by the 9 | Free Software Foundation. 10 | 11 | This program is distributed in the hope that it will be useful, but WITHOUT 12 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 13 | FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 14 | details. 15 | 16 | You should have received a copy of the GNU General Public License along with 17 | this program. If not, see . 18 | */ 19 | 20 | using CounterStrikeSharp.API.Core; 21 | using CounterStrikeSharp.API.Modules.Entities.Constants; 22 | using CounterStrikeSharp.API.Modules.Events; 23 | using CSSharpFixes.Extensions; 24 | using CSSharpFixes.Fixes.Interfaces; 25 | using Microsoft.Extensions.Logging; 26 | 27 | namespace CSSharpFixes.Fixes; 28 | 29 | public class NoBlockFix: BaseFix, ITickable 30 | { 31 | public NoBlockFix() 32 | { 33 | Name = "NoBlockFix"; 34 | ConfigurationProperty = "EnableNoBlock"; 35 | // Events = new Dictionary 36 | // { 37 | // { "OnPlayerSpawn", OnPlayerSpawn }, 38 | // }; 39 | } 40 | 41 | public void ApplyNoBlock(CCSPlayerController? player) 42 | { 43 | if(!player.IsCompletelyValid(out var playerPawn)) return; 44 | CollisionGroup collisionGroup = (CollisionGroup)playerPawn.Collision.CollisionAttribute.CollisionGroup; 45 | if(collisionGroup == CollisionGroup.COLLISION_GROUP_DEBRIS) return; 46 | playerPawn.SetCollisionGroup(CollisionGroup.COLLISION_GROUP_DEBRIS); 47 | } 48 | 49 | public void OnTick(List players) 50 | { 51 | if(!Enabled) return; 52 | 53 | foreach(CCSPlayerController player in players) 54 | { 55 | ApplyNoBlock(player); 56 | } 57 | } 58 | 59 | // public HookResult OnPlayerSpawn(GameEvent @event, GameEventInfo info, ILogger logger) 60 | // { 61 | // if(@event is not EventPlayerSpawn playerSpawnEvent) return HookResult.Continue; 62 | // // logger.LogInformation("[CSSharpFixes][Fix][NoBlockFix][OnPlayerSpawn()]"); 63 | // ApplyNoBlock(playerSpawnEvent.Userid); 64 | // return HookResult.Continue; 65 | // } 66 | } -------------------------------------------------------------------------------- /CSSharpFixes/Fixes/SubTickMovementFix.cs: -------------------------------------------------------------------------------- 1 | /* 2 | ============================================================================= 3 | CS#Fixes 4 | Copyright (C) 2023-2024 Charles Barone / hypnos 5 | ============================================================================= 6 | 7 | This program is free software; you can redistribute it and/or modify it under 8 | the terms of the GNU General Public License, version 3.0, as published by the 9 | Free Software Foundation. 10 | 11 | This program is distributed in the hope that it will be useful, but WITHOUT 12 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 13 | FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 14 | details. 15 | 16 | You should have received a copy of the GNU General Public License along with 17 | this program. If not, see . 18 | */ 19 | 20 | namespace CSSharpFixes.Fixes; 21 | 22 | /* 23 | * Description: Disables subtick movement for all players on the server. 24 | * 25 | * This fix is not "really" a fix, but rather it disables subtick movement. 26 | * This is a prerequisite for TriggerPushFix. 27 | */ 28 | public class SubTickMovementFix: BaseFix 29 | { 30 | public SubTickMovementFix() 31 | { 32 | Name = "SubTickMovementFix"; 33 | ConfigurationProperty = "DisableSubTickMovement"; 34 | DetourHandlerNames = 35 | [ 36 | "ProcessUserCmdsHandler" 37 | ]; 38 | } 39 | } -------------------------------------------------------------------------------- /CSSharpFixes/Fixes/TeamMessagesFix.cs: -------------------------------------------------------------------------------- 1 | /* 2 | ============================================================================= 3 | CS#Fixes 4 | Copyright (C) 2023-2024 Charles Barone / hypnos 5 | ============================================================================= 6 | 7 | This program is free software; you can redistribute it and/or modify it under 8 | the terms of the GNU General Public License, version 3.0, as published by the 9 | Free Software Foundation. 10 | 11 | This program is distributed in the hope that it will be useful, but WITHOUT 12 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 13 | FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 14 | details. 15 | 16 | You should have received a copy of the GNU General Public License along with 17 | this program. If not, see . 18 | */ 19 | 20 | using CounterStrikeSharp.API.Core; 21 | using CounterStrikeSharp.API.Modules.Events; 22 | using Microsoft.Extensions.Logging; 23 | 24 | namespace CSSharpFixes.Fixes; 25 | 26 | public class TeamMessagesFix: BaseFix 27 | { 28 | public TeamMessagesFix() 29 | { 30 | Name = "TeamMessagesFix"; 31 | ConfigurationProperty = "DisableTeamMessages"; 32 | Events = new Dictionary 33 | { 34 | { "OnPlayerTeam", OnPlayerTeam }, 35 | }; 36 | } 37 | 38 | //TODO: This currently isn't working -_- ;( 39 | public HookResult OnPlayerTeam(GameEvent @event, GameEventInfo info, ILogger logger) 40 | { 41 | if(@event is not EventPlayerTeam playerTeamEvent) return HookResult.Continue; 42 | logger.LogInformation("[CSSharpFixes][Fix][TeamMessagesFix][OnPlayerTeam()]"); 43 | playerTeamEvent.Silent = true; 44 | return HookResult.Handled; 45 | } 46 | } -------------------------------------------------------------------------------- /CSSharpFixes/Fixes/TriggerPushFix.cs: -------------------------------------------------------------------------------- 1 | /* 2 | ============================================================================= 3 | CS#Fixes 4 | Copyright (C) 2023-2024 Charles Barone / hypnos 5 | ============================================================================= 6 | 7 | This program is free software; you can redistribute it and/or modify it under 8 | the terms of the GNU General Public License, version 3.0, as published by the 9 | Free Software Foundation. 10 | 11 | This program is distributed in the hope that it will be useful, but WITHOUT 12 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 13 | FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 14 | details. 15 | 16 | You should have received a copy of the GNU General Public License along with 17 | this program. If not, see . 18 | */ 19 | 20 | namespace CSSharpFixes.Fixes; 21 | 22 | public class TriggerPushFix: BaseFix 23 | { 24 | public TriggerPushFix() 25 | { 26 | Name = "TriggerPushFix"; 27 | ConfigurationProperty = "EnableTriggerPushFix"; 28 | DetourHandlerNames = 29 | [ 30 | "TriggerPushTouchHandler" 31 | ]; 32 | } 33 | } -------------------------------------------------------------------------------- /CSSharpFixes/Fixes/WaterFix.cs: -------------------------------------------------------------------------------- 1 | /* 2 | ============================================================================= 3 | CS#Fixes 4 | Copyright (C) 2023-2024 Charles Barone / hypnos 5 | ============================================================================= 6 | 7 | This program is free software; you can redistribute it and/or modify it under 8 | the terms of the GNU General Public License, version 3.0, as published by the 9 | Free Software Foundation. 10 | 11 | This program is distributed in the hope that it will be useful, but WITHOUT 12 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 13 | FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 14 | details. 15 | 16 | You should have received a copy of the GNU General Public License along with 17 | this program. If not, see . 18 | */ 19 | 20 | namespace CSSharpFixes.Fixes; 21 | 22 | public class WaterFix: BaseFix 23 | { 24 | public WaterFix() 25 | { 26 | Name = "WaterFix"; 27 | ConfigurationProperty = "EnableWaterFix"; 28 | PatchNames = 29 | [ 30 | "FixWaterFloorJump", 31 | "WaterLevelGravity", 32 | "CategorizeUnderwater" 33 | ]; 34 | } 35 | } -------------------------------------------------------------------------------- /CSSharpFixes/Hooks.cs: -------------------------------------------------------------------------------- 1 | /* 2 | ============================================================================= 3 | CS#Fixes 4 | Copyright (C) 2023-2024 Charles Barone / hypnos 5 | ============================================================================= 6 | 7 | This program is free software; you can redistribute it and/or modify it under 8 | the terms of the GNU General Public License, version 3.0, as published by the 9 | Free Software Foundation. 10 | 11 | This program is distributed in the hope that it will be useful, but WITHOUT 12 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 13 | FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 14 | details. 15 | 16 | You should have received a copy of the GNU General Public License along with 17 | this program. If not, see . 18 | */ 19 | 20 | using CounterStrikeSharp.API.Core; 21 | using CounterStrikeSharp.API.Core.Attributes.Registration; 22 | using CounterStrikeSharp.API.Modules.Events; 23 | using CounterStrikeSharp.API.Modules.Utils; 24 | using Microsoft.Extensions.Logging; 25 | 26 | namespace CSSharpFixes; 27 | 28 | public partial class CSSharpFixes 29 | { 30 | public delegate HookResult GameEventHandler(GameEvent gameEvent, GameEventInfo gameEventInfo, ILogger logger); 31 | 32 | private void RegisterHooks() 33 | { 34 | RegisterListener(OnMapEnd); 35 | RegisterListener(OnMapStart); 36 | RegisterListener(OnServerPrecacheResources); 37 | RegisterListener(OnTick); 38 | } 39 | 40 | private void UnregisterHooks() 41 | { 42 | RemoveListener(OnMapEnd); 43 | RemoveListener(OnMapStart); 44 | RemoveListener(OnServerPrecacheResources); 45 | } 46 | 47 | private void OnServerPrecacheResources(ResourceManifest manifest) 48 | { 49 | //manifest.AddResource("models/food/pizza/pizza_1.vmdl"); 50 | } 51 | 52 | [GameEventHandler] 53 | public HookResult OnRoundStart(EventRoundStart @event, GameEventInfo info) => 54 | _eventManager.OnRoundStart(@event, info); 55 | 56 | [GameEventHandler] 57 | public HookResult OnPlayerSpawn(EventPlayerSpawn @event, GameEventInfo info) => 58 | _eventManager.OnPlayerSpawn(@event, info); 59 | 60 | [GameEventHandler] 61 | public HookResult OnPlayerTeam(EventPlayerTeam @event, GameEventInfo info) => 62 | _eventManager.OnPlayerTeam(@event, info); 63 | 64 | [GameEventHandler] 65 | public HookResult OnRoundStartPre(EventRoundPrestart @event, GameEventInfo info) => 66 | _eventManager.OnRoundStartPre(@event, info); 67 | 68 | private void OnTick() => _fixManager.OnTick(); 69 | 70 | private void OnMapEnd() 71 | { 72 | 73 | } 74 | 75 | private void OnMapStart(string mapName) 76 | { 77 | 78 | } 79 | } -------------------------------------------------------------------------------- /CSSharpFixes/Injection.cs: -------------------------------------------------------------------------------- 1 | /* 2 | ============================================================================= 3 | CS#Fixes 4 | Copyright (C) 2023-2024 Charles Barone / hypnos 5 | ============================================================================= 6 | 7 | This program is free software; you can redistribute it and/or modify it under 8 | the terms of the GNU General Public License, version 3.0, as published by the 9 | Free Software Foundation. 10 | 11 | This program is distributed in the hope that it will be useful, but WITHOUT 12 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 13 | FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 14 | details. 15 | 16 | You should have received a copy of the GNU General Public License along with 17 | this program. If not, see . 18 | */ 19 | 20 | using CounterStrikeSharp.API.Core; 21 | using CSSharpFixes.Config; 22 | using CSSharpFixes.Managers; 23 | using Microsoft.Extensions.DependencyInjection; 24 | 25 | namespace CSSharpFixes; 26 | 27 | public class Injection : IPluginServiceCollection 28 | { 29 | public void ConfigureServices(IServiceCollection serviceCollection) 30 | { 31 | serviceCollection.AddSingleton(); 32 | serviceCollection.AddSingleton(); 33 | serviceCollection.AddSingleton(); 34 | serviceCollection.AddSingleton(); 35 | serviceCollection.AddSingleton(); 36 | serviceCollection.AddSingleton(); 37 | serviceCollection.AddSingleton(); 38 | } 39 | } -------------------------------------------------------------------------------- /CSSharpFixes/Managers/DetourManager.cs: -------------------------------------------------------------------------------- 1 | /* 2 | ============================================================================= 3 | CS#Fixes 4 | Copyright (C) 2023-2024 Charles Barone / hypnos 5 | ============================================================================= 6 | 7 | This program is free software; you can redistribute it and/or modify it under 8 | the terms of the GNU General Public License, version 3.0, as published by the 9 | Free Software Foundation. 10 | 11 | This program is distributed in the hope that it will be useful, but WITHOUT 12 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 13 | FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 14 | details. 15 | 16 | You should have received a copy of the GNU General Public License along with 17 | this program. If not, see . 18 | */ 19 | 20 | using CSSharpFixes.Detours; 21 | using Microsoft.Extensions.Logging; 22 | 23 | namespace CSSharpFixes.Managers; 24 | 25 | public class DetourManager 26 | { 27 | private readonly ILogger _logger; 28 | 29 | private Dictionary _handlers = new(); 30 | 31 | public DetourManager(ILogger logger) 32 | { 33 | _logger = logger; 34 | } 35 | 36 | public void Start() 37 | { 38 | _handlers.Add("ProcessUserCmdsHandler", BaseHandler.Build(_logger)); 39 | _handlers.Add("TriggerPushTouchHandler", BaseHandler.Build(_logger)); 40 | } 41 | 42 | public void Stop() 43 | { 44 | StopAllHandlers(); 45 | _handlers.Clear(); 46 | } 47 | 48 | private void StartAllHandlers() { foreach(BaseHandler handler in _handlers.Values) handler.Start(); } 49 | private void StopAllHandlers() { foreach(BaseHandler handler in _handlers.Values) handler.Stop(); } 50 | 51 | public void StartHandler(string name) 52 | { 53 | if(_handlers.TryGetValue(name, out BaseHandler? handler)) handler.Start(); 54 | } 55 | 56 | public void StopHandler(string name) 57 | { 58 | if(_handlers.TryGetValue(name, out BaseHandler? handler)) handler.Stop(); 59 | } 60 | 61 | 62 | } -------------------------------------------------------------------------------- /CSSharpFixes/Managers/EventManager.cs: -------------------------------------------------------------------------------- 1 | /* 2 | ============================================================================= 3 | CS#Fixes 4 | Copyright (C) 2023-2024 Charles Barone / hypnos 5 | ============================================================================= 6 | 7 | This program is free software; you can redistribute it and/or modify it under 8 | the terms of the GNU General Public License, version 3.0, as published by the 9 | Free Software Foundation. 10 | 11 | This program is distributed in the hope that it will be useful, but WITHOUT 12 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 13 | FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 14 | details. 15 | 16 | You should have received a copy of the GNU General Public License along with 17 | this program. If not, see . 18 | */ 19 | 20 | using CounterStrikeSharp.API.Core; 21 | using CounterStrikeSharp.API.Modules.Events; 22 | using Microsoft.Extensions.Logging; 23 | 24 | namespace CSSharpFixes.Managers; 25 | 26 | public class EventManager 27 | { 28 | private readonly ILogger _logger; 29 | 30 | private Dictionary> _events = new(); 31 | 32 | public EventManager(ILogger logger) 33 | { 34 | _logger = logger; 35 | } 36 | 37 | public void Start() 38 | { 39 | _events.Add("OnRoundStart", new List()); 40 | _events.Add("OnPlayerSpawn", new List()); 41 | _events.Add("OnPlayerTeam", new List()); 42 | _events.Add("OnRoundStartPre", new List()); 43 | } 44 | 45 | public void Stop() 46 | { 47 | foreach (var eventPair in _events) 48 | { 49 | eventPair.Value.Clear(); 50 | } 51 | _events.Clear(); 52 | } 53 | 54 | public void RegisterEvent(string name, CSSharpFixes.GameEventHandler gameEventHandler) 55 | { 56 | if(_events.TryGetValue(name, out List? handlers)) 57 | { 58 | handlers.Add(gameEventHandler); 59 | } 60 | } 61 | 62 | public void UnregisterEvent(string name, CSSharpFixes.GameEventHandler gameEventHandler) 63 | { 64 | if(_events.TryGetValue(name, out List? handlers)) 65 | { 66 | handlers.Remove(gameEventHandler); 67 | } 68 | } 69 | 70 | public HookResult ProcessEvent(GameEvent @event, GameEventInfo info, string eventName) 71 | { 72 | HookResult returnValue = HookResult.Continue; 73 | 74 | foreach(CSSharpFixes.GameEventHandler handler in _events[eventName]) 75 | { 76 | switch(handler(@event, info, _logger)) 77 | { 78 | case HookResult.Continue: 79 | continue; 80 | case HookResult.Changed: 81 | returnValue = HookResult.Changed; 82 | break; 83 | case HookResult.Handled: 84 | returnValue = HookResult.Handled; 85 | break; 86 | case HookResult.Stop: 87 | return HookResult.Stop; 88 | } 89 | } 90 | 91 | return returnValue; 92 | } 93 | 94 | public HookResult OnRoundStart(EventRoundStart @event, GameEventInfo info) => 95 | ProcessEvent(@event, info, "OnRoundStart"); 96 | 97 | public HookResult OnPlayerSpawn(EventPlayerSpawn @event, GameEventInfo info) => 98 | ProcessEvent(@event, info, "OnPlayerSpawn"); 99 | 100 | public HookResult OnPlayerTeam(EventPlayerTeam @event, GameEventInfo info) => 101 | ProcessEvent(@event, info, "OnPlayerTeam"); 102 | 103 | public HookResult OnRoundStartPre(EventRoundPrestart @event, GameEventInfo info) => 104 | ProcessEvent(@event, info, "OnRoundStartPre"); 105 | } -------------------------------------------------------------------------------- /CSSharpFixes/Managers/FixManager.cs: -------------------------------------------------------------------------------- 1 | /* 2 | ============================================================================= 3 | CS#Fixes 4 | Copyright (C) 2023-2024 Charles Barone / hypnos 5 | ============================================================================= 6 | 7 | This program is free software; you can redistribute it and/or modify it under 8 | the terms of the GNU General Public License, version 3.0, as published by the 9 | Free Software Foundation. 10 | 11 | This program is distributed in the hope that it will be useful, but WITHOUT 12 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 13 | FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 14 | details. 15 | 16 | You should have received a copy of the GNU General Public License along with 17 | this program. If not, see . 18 | */ 19 | 20 | using CounterStrikeSharp.API; 21 | using CounterStrikeSharp.API.Core; 22 | using CSSharpFixes.Fixes; 23 | using CSSharpFixes.Fixes.Interfaces; 24 | using Microsoft.Extensions.Logging; 25 | 26 | namespace CSSharpFixes.Managers; 27 | 28 | public class FixManager(PatchManager patchManager, DetourManager detourManager, EventManager eventManager, 29 | ILogger logger) 30 | { 31 | private List _fixes = new(); 32 | 33 | public void OnConfigChanged(string propertyName, object? newValue) 34 | { 35 | int index = _fixes.FindIndex(fix => fix.ConfigurationProperty == propertyName); 36 | if (newValue == null) 37 | { 38 | StopFix(index); 39 | return; 40 | } 41 | 42 | if(newValue is not bool value) return; 43 | 44 | if(value) StartFix(index); 45 | else StopFix(index); 46 | } 47 | 48 | private void StartFix(int index) 49 | { 50 | if(index < 0 || index >= _fixes.Count) return; 51 | 52 | foreach(string patchName in _fixes[index].PatchNames) patchManager.PerformPatch(patchName); 53 | foreach(string detourHandlerName in _fixes[index].DetourHandlerNames) detourManager.StartHandler(detourHandlerName); 54 | foreach(var eventPair in _fixes[index].Events) eventManager.RegisterEvent(eventPair.Key, eventPair.Value); 55 | 56 | _fixes[index].Enabled = true; 57 | } 58 | 59 | private void StopFix(int index) 60 | { 61 | if(index < 0 || index >= _fixes.Count) return; 62 | 63 | foreach(string patchName in _fixes[index].PatchNames) patchManager.UndoPatch(patchName); 64 | foreach(string detourHandlerName in _fixes[index].DetourHandlerNames) detourManager.StopHandler(detourHandlerName); 65 | foreach(var eventPair in _fixes[index].Events) eventManager.UnregisterEvent(eventPair.Key, eventPair.Value); 66 | 67 | _fixes[index].Enabled = false; 68 | } 69 | 70 | public void OnTick() 71 | { 72 | List players = Utilities.GetPlayers(); 73 | 74 | foreach (BaseFix fix in _fixes) 75 | { 76 | if(fix is ITickable tickable) tickable.OnTick(players); 77 | } 78 | } 79 | 80 | public void Start() 81 | { 82 | logger.LogInformation("[CSSharpFixes][FixManager][Start()]"); 83 | 84 | _fixes.Add(new WaterFix()); 85 | _fixes.Add(new TriggerPushFix()); 86 | _fixes.Add(new CPhysBoxUseFix()); 87 | // _fixes.Add(new NavmeshLookupLagFix()); // Commented out since it seems to cause crashes every time I test it... 88 | _fixes.Add(new NoBlockFix()); 89 | _fixes.Add(new TeamMessagesFix()); 90 | _fixes.Add(new SubTickMovementFix()); 91 | _fixes.Add(new MovementUnlockerFix()); 92 | _fixes.Add(new FullAllTalkFix()); 93 | _fixes.Add(new EntityStringPurgeFix()); 94 | } 95 | 96 | public void Stop() 97 | { 98 | logger.LogInformation("[CSSharpFixes][FixManager][Stop()]"); 99 | 100 | foreach (BaseFix fix in _fixes) 101 | { 102 | foreach(string patchName in fix.PatchNames) patchManager.UndoPatch(patchName); 103 | foreach(string detourHandlerName in fix.DetourHandlerNames) detourManager.StopHandler(detourHandlerName); 104 | } 105 | 106 | _fixes.Clear(); 107 | } 108 | } -------------------------------------------------------------------------------- /CSSharpFixes/Managers/GameDataManager.cs: -------------------------------------------------------------------------------- 1 | /* 2 | ============================================================================= 3 | CS#Fixes 4 | Copyright (C) 2023-2024 Charles Barone / hypnos 5 | ============================================================================= 6 | 7 | This program is free software; you can redistribute it and/or modify it under 8 | the terms of the GNU General Public License, version 3.0, as published by the 9 | Free Software Foundation. 10 | 11 | This program is distributed in the hope that it will be useful, but WITHOUT 12 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 13 | FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 14 | details. 15 | 16 | You should have received a copy of the GNU General Public License along with 17 | this program. If not, see . 18 | */ 19 | 20 | using CounterStrikeSharp.API.Core; 21 | 22 | namespace CSSharpFixes.Managers; 23 | 24 | public class GameDataManager 25 | { 26 | private Dictionary> _signatures = new(); 27 | 28 | public IntPtr GetAddress(string modulePath, string signature) 29 | { 30 | if (!_signatures.TryGetValue(modulePath, out var signatures)) 31 | { 32 | signatures = new Dictionary(); 33 | _signatures[modulePath] = signatures; 34 | } 35 | 36 | if (!signatures.TryGetValue(signature, out var address)) 37 | { 38 | string byteString = GameData.GetSignature(signature); 39 | // Returns address if found, otherwise a C++ nullptr which is a IntPtr.Zero in C# 40 | address = NativeAPI.FindSignature(modulePath, byteString); 41 | signatures[signature] = address; 42 | } 43 | 44 | return address; 45 | } 46 | 47 | public void Start() 48 | { 49 | 50 | } 51 | 52 | public void Stop() 53 | { 54 | _signatures.Clear(); 55 | } 56 | } -------------------------------------------------------------------------------- /CSSharpFixes/Managers/PatchManager.cs: -------------------------------------------------------------------------------- 1 | /* 2 | ============================================================================= 3 | CS#Fixes 4 | Copyright (C) 2023-2024 Charles Barone / hypnos 5 | ============================================================================= 6 | 7 | This program is free software; you can redistribute it and/or modify it under 8 | the terms of the GNU General Public License, version 3.0, as published by the 9 | Free Software Foundation. 10 | 11 | This program is distributed in the hope that it will be useful, but WITHOUT 12 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 13 | FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 14 | details. 15 | 16 | You should have received a copy of the GNU General Public License along with 17 | this program. If not, see . 18 | */ 19 | 20 | using System.Runtime.InteropServices; 21 | using CounterStrikeSharp.API.Modules.Memory; 22 | using CSSharpFixes.Models; 23 | using Microsoft.Extensions.Logging; 24 | 25 | namespace CSSharpFixes.Managers; 26 | 27 | public class PatchManager 28 | { 29 | private List _patches = new(); 30 | 31 | private readonly GameDataManager _gameDataManager; 32 | private readonly ILogger _logger; 33 | 34 | public PatchManager(GameDataManager gameDataManager, ILogger logger) 35 | { 36 | _gameDataManager = gameDataManager; 37 | _logger = logger; 38 | } 39 | 40 | public void Start() 41 | { 42 | LoadCommonPatches(); 43 | } 44 | 45 | public void Stop() 46 | { 47 | foreach (Patch patch in _patches) 48 | { 49 | patch.UndoPatch(); 50 | } 51 | 52 | _patches.Clear(); 53 | } 54 | 55 | // https://github.com/Source2ZE/CS2Fixes/blob/main/gamedata/cs2fixes.games.txt 56 | private void LoadCommonPatches() 57 | { 58 | if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) 59 | { 60 | // Water Fix 61 | AddServerPatch("FixWaterFloorJump", "CheckJumpButtonWater", "11 43"); 62 | AddServerPatch("WaterLevelGravity", "WaterLevelGravity", "3C 02"); 63 | AddServerPatch("CategorizeUnderwater", "CategorizeUnderwater", "0F 42"); 64 | 65 | // CPhysBox_Use Fix 66 | // Make func_physbox pass itself as the caller in OnPlayerUse 67 | // pCaller = inputdata->pCaller -> pCaller = this 68 | // Linux: mov rdx, [r12+8] -> mov rdx, rbx 69 | AddServerPatch("CPhysBox_Use", "CPhysBox_Use", "48 89 DA 90 90"); 70 | 71 | // Server Movement Unlocker 72 | AddServerPatch("ServerMovementUnlock", "ServerMovementUnlock", "90 90 90 90 90 90"); 73 | 74 | // BotNavIgnore Fix 75 | // According to src code of CS2Fixes, we should run BotNavIgnore patch 3 times on Linux??? 76 | // Commented out since it seems to cause crashes every time I test it... 77 | //AddServerPatch("BotNavIgnore", "BotNavIgnore", "E9 15 00 00 00"); 78 | //AddServerPatch("BotNavIgnore2", "BotNavIgnore", "E9 15 00 00 00"); 79 | //AddServerPatch("BotNavIgnore3", "BotNavIgnore", "E9 15 00 00 00"); 80 | } 81 | else 82 | { 83 | // Water Fix 84 | AddServerPatch("FixWaterFloorJump", "CheckJumpButtonWater", "11 43"); 85 | AddServerPatch("WaterLevelGravity", "WaterLevelGravity", "3C 02"); 86 | AddServerPatch("CategorizeUnderwater", "CategorizeUnderwater", "73"); 87 | 88 | // CPhysBox_Use Fix 89 | // Make func_physbox pass itself as the caller in OnPlayerUse 90 | // pCaller = inputdata->pCaller -> pCaller = this 91 | // Windows: mov r8, [rdi+8] -> mov r8, rbx 92 | AddServerPatch("CPhysBox_Use", "CPhysBox_Use", "49 89 D8 90"); 93 | 94 | // Server Movement Unlocker 95 | AddServerPatch("ServerMovementUnlock", "ServerMovementUnlock", "EB"); 96 | 97 | // BotNavIgnore Fix 98 | // Commented out since it seems to cause crashes every time I test it... 99 | //AddServerPatch("BotNavIgnore", "BotNavIgnore", "E9 2C 00 00 00 90"); 100 | } 101 | } 102 | 103 | private void AddServerPatch(string name, string signature, string bytesHex) 104 | { 105 | _patches.Add(new Patch(name, Addresses.ServerPath, signature, bytesHex, _gameDataManager, _logger)); 106 | } 107 | 108 | 109 | public void PerformPatch(string name) 110 | { 111 | // Find Patch by name 112 | int patch = _patches.FindIndex(patch => patch.GetPatchName() == name); 113 | if (patch == -1) 114 | { 115 | _logger.LogError( 116 | "[CSSharpFixes][PatchManager][PerformPatch()][Patch={patchName}] Error: Patch not found.", 117 | patch); 118 | return; 119 | } 120 | 121 | _patches[patch].PerformPatch(); 122 | 123 | // Commented out since it seems to cause crashes every time I test it... 124 | // According to src code of CS2Fixes, we should run BotNavIgnore patch 3 times on Linux??? 125 | /* if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) && name == "BotNavIgnore") 126 | { 127 | int patch2 = _patches.FindIndex(patch2 => patch2.GetPatchName() == "BotNavIgnore2"); 128 | _patches[patch2].PerformPatch(); 129 | int patch3 = _patches.FindIndex(patch3 => patch3.GetPatchName() == "BotNavIgnore3"); 130 | _patches[patch3].PerformPatch(); 131 | } */ 132 | } 133 | 134 | public void UndoPatch(string name) 135 | { 136 | // Find Patch by name 137 | int patch = _patches.FindIndex(patch => patch.GetPatchName() == name); 138 | if (patch == -1) 139 | { 140 | _logger.LogError( 141 | "[CSSharpFixes][PatchManager][UndoPatch()][Patch={patchName}] Error: Patch not found.", 142 | patch); 143 | return; 144 | } 145 | 146 | // Commented out since it seems to cause crashes every time I test it... 147 | // According to src code of CS2Fixes, we should run BotNavIgnore patch 3 times on Linux??? 148 | /* if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) && name == "BotNavIgnore") 149 | { 150 | int patch3 = _patches.FindIndex(patch3 => patch3.GetPatchName() == "BotNavIgnore3"); 151 | _patches[patch3].UndoPatch(); 152 | int patch2 = _patches.FindIndex(patch2 => patch2.GetPatchName() == "BotNavIgnore2"); 153 | _patches[patch2].UndoPatch(); 154 | } */ 155 | 156 | _patches[patch].UndoPatch(); 157 | } 158 | } -------------------------------------------------------------------------------- /CSSharpFixes/Memory/DetourMemoryFunctions.cs: -------------------------------------------------------------------------------- 1 | /* 2 | ============================================================================= 3 | CS#Fixes 4 | Copyright (C) 2023-2024 Charles Barone / hypnos 5 | ============================================================================= 6 | 7 | This program is free software; you can redistribute it and/or modify it under 8 | the terms of the GNU General Public License, version 3.0, as published by the 9 | Free Software Foundation. 10 | 11 | This program is distributed in the hope that it will be useful, but WITHOUT 12 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 13 | FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 14 | details. 15 | 16 | You should have received a copy of the GNU General Public License along with 17 | this program. If not, see . 18 | */ 19 | 20 | using CounterStrikeSharp.API.Modules.Memory.DynamicFunctions; 21 | 22 | namespace CSSharpFixes.Memory; 23 | 24 | public static class DetourMemoryFunctions 25 | { 26 | static DetourMemoryFunctions() 27 | { 28 | Add>("ProcessUsercmds"); 29 | Add>("TriggerPush_Touch"); 30 | } 31 | 32 | private static Dictionary _memoryFunctions = new(); 33 | 34 | private static void Add(string signatureName) where T: BaseMemoryFunction 35 | { 36 | _memoryFunctions.Add(signatureName, Utils.BuildMemoryFunction(signatureName)); 37 | } 38 | 39 | public static BaseMemoryFunction Get(string signatureName) 40 | { 41 | if(!_memoryFunctions.TryGetValue(signatureName, out BaseMemoryFunction? memoryFunction)) 42 | throw new InvalidOperationException($"Memory function for signature {signatureName} not found."); 43 | 44 | return memoryFunction; 45 | } 46 | } -------------------------------------------------------------------------------- /CSSharpFixes/Memory/UnixMemoryUtils.cs: -------------------------------------------------------------------------------- 1 | /* 2 | ============================================================================= 3 | CS#Fixes 4 | Copyright (C) 2023-2024 Charles Barone / hypnos 5 | ============================================================================= 6 | 7 | This program is free software; you can redistribute it and/or modify it under 8 | the terms of the GNU General Public License, version 3.0, as published by the 9 | Free Software Foundation. 10 | 11 | This program is distributed in the hope that it will be useful, but WITHOUT 12 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 13 | FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 14 | details. 15 | 16 | You should have received a copy of the GNU General Public License along with 17 | this program. If not, see . 18 | */ 19 | 20 | using System.Diagnostics; 21 | using System.Runtime.InteropServices; 22 | 23 | namespace CSSharpFixes.Memory; 24 | 25 | // Based on https://github.com/Source2ZE/CS2Fixes/blob/main/src/utils/plat_unix.cpp 26 | public class UnixMemoryUtils 27 | { 28 | static int ParseProt(string s) 29 | { 30 | int prot = 0; 31 | 32 | foreach (var c in s) 33 | { 34 | switch (c) 35 | { 36 | case '-': 37 | break; 38 | case 'r': 39 | prot |= NativeMethods.PROT_READ; 40 | break; 41 | case 'w': 42 | prot |= NativeMethods.PROT_WRITE; 43 | break; 44 | case 'x': 45 | prot |= NativeMethods.PROT_EXEC; 46 | break; 47 | case 's': 48 | break; 49 | case 'p': 50 | break; 51 | default: 52 | break; 53 | } 54 | } 55 | 56 | return prot; 57 | } 58 | 59 | static int GetProt(IntPtr pAddr, uint nSize) 60 | { 61 | using (var f = File.OpenRead("/proc/self/maps")) 62 | using (var reader = new StreamReader(f)) 63 | { 64 | while (!reader.EndOfStream) 65 | { 66 | var line = reader.ReadLine(); 67 | if (line == null) 68 | continue; 69 | 70 | var parts = line.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); 71 | if (parts.Length < 5) 72 | continue; 73 | 74 | var range = parts[0]; 75 | var prot = parts[1]; 76 | 77 | var startEnd = range.Split('-'); 78 | if (startEnd.Length != 2) 79 | continue; 80 | 81 | var start = Convert.ToUInt64(startEnd[0], 16); 82 | var end = Convert.ToUInt64(startEnd[1], 16); 83 | 84 | if (start < (ulong)pAddr && end > (ulong)pAddr + nSize) 85 | { 86 | return ParseProt(prot); 87 | } 88 | } 89 | } 90 | 91 | return 0; 92 | } 93 | 94 | public static void PatchBytesAtAddress(IntPtr pPatchAddress, byte[] pPatch, int iPatchSize) 95 | { 96 | if (!RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) return; 97 | 98 | var oldProt = GetProt(pPatchAddress, (uint)iPatchSize); 99 | 100 | var pageSize = (ulong)NativeMethods.sysconf(NativeMethods._SC_PAGESIZE); 101 | var alignAddr = (IntPtr)((long)pPatchAddress & ~(long)(pageSize - 1)); 102 | 103 | var end = (IntPtr)((long)pPatchAddress + iPatchSize); 104 | var alignSize = (ulong)((long)end - (long)alignAddr); 105 | 106 | var result = NativeMethods.mprotect(alignAddr, alignSize, NativeMethods.PROT_READ | NativeMethods.PROT_WRITE); 107 | 108 | Marshal.Copy(pPatch, 0, pPatchAddress, iPatchSize); 109 | 110 | result = NativeMethods.mprotect(alignAddr, alignSize, oldProt); 111 | } 112 | 113 | private static byte[]? ReadProcessMemory(int pid, long address, int size) 114 | { 115 | if (!RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) return null; 116 | 117 | byte[] buffer = new byte[size]; 118 | 119 | NativeMethods.Iovec local = new NativeMethods.Iovec 120 | { 121 | iov_base = Marshal.UnsafeAddrOfPinnedArrayElement(buffer, 0), 122 | iov_len = new IntPtr(size) 123 | }; 124 | 125 | NativeMethods.Iovec remote = new NativeMethods.Iovec 126 | { 127 | iov_base = new IntPtr(address), 128 | iov_len = new IntPtr(size) 129 | }; 130 | 131 | long bytesRead = NativeMethods.process_vm_readv(pid, new NativeMethods.Iovec[] { local }, 1, new NativeMethods.Iovec[] { remote }, 1, 0); 132 | if (bytesRead == -1) 133 | { 134 | throw new Exception($"process_vm_readv failed with error {Marshal.GetLastPInvokeError()}"); 135 | } 136 | 137 | return buffer; 138 | } 139 | 140 | public static byte[]? ReadMemory(IntPtr address, int size) 141 | { 142 | if (!RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) return null; 143 | 144 | return ReadProcessMemory(Process.GetCurrentProcess().Id, (long)address, size); 145 | } 146 | 147 | #pragma warning disable CS0649 // Field is never assigned to, and will always have its default value 148 | #pragma warning disable CS8981 // The type name only contains lower-cased ascii characters. Such names may become reserved for the language. 149 | static class NativeMethods 150 | { 151 | public const int O_RDONLY = 0; 152 | public const int PROT_READ = 0x1; 153 | public const int PROT_WRITE = 0x2; 154 | public const int PROT_EXEC = 0x4; 155 | public const int MAP_PRIVATE = 0x2; 156 | public const int PT_LOAD = 1; 157 | public const int PF_X = 0x1; 158 | public const int _SC_PAGESIZE = 30; 159 | public const int RTLD_DI_LINKMAP = 2; 160 | 161 | [DllImport("libc")] 162 | public static extern int dlinfo(IntPtr handle, int request, out link_map lmap); 163 | 164 | [DllImport("libc")] 165 | public static extern int dlclose(IntPtr handle); 166 | 167 | [DllImport("libc")] 168 | public static extern int open(string pathname, int flags); 169 | 170 | [DllImport("libc")] 171 | public static extern int fstat(int fd, out stat buf); 172 | 173 | [DllImport("libc")] 174 | public static extern IntPtr mmap(IntPtr addr, ulong length, int prot, int flags, int fd, ulong offset); 175 | 176 | [DllImport("libc")] 177 | public static extern int munmap(IntPtr addr, ulong length); 178 | 179 | [DllImport("libc")] 180 | public static extern int mprotect(IntPtr addr, ulong len, int prot); 181 | 182 | [DllImport("libc")] 183 | public static extern long sysconf(int name); 184 | 185 | [DllImport("libc")] 186 | public static extern long process_vm_readv(int pid, Iovec[] local_iov, ulong liovcnt, Iovec[] remote_iov, ulong riovcnt, ulong flags); 187 | 188 | [StructLayout(LayoutKind.Sequential)] 189 | public struct Iovec 190 | { 191 | public IntPtr iov_base; 192 | public IntPtr iov_len; 193 | } 194 | 195 | [StructLayout(LayoutKind.Sequential)] 196 | public struct link_map 197 | { 198 | public IntPtr l_addr; 199 | public IntPtr l_name; 200 | } 201 | 202 | [StructLayout(LayoutKind.Sequential)] 203 | public struct ElfW 204 | { 205 | public struct Ehdr 206 | { 207 | public byte e_shnum; 208 | public uint e_shoff; 209 | public ushort e_phnum; 210 | public uint e_phoff; 211 | } 212 | 213 | public struct Phdr 214 | { 215 | public int p_type; 216 | public int p_flags; 217 | 218 | public ulong p_vaddr; 219 | public ulong p_filesz; 220 | } 221 | 222 | public struct Shdr 223 | { 224 | public uint sh_name; 225 | public uint sh_offset; 226 | public uint sh_size; 227 | public ulong sh_addr; 228 | } 229 | } 230 | 231 | [StructLayout(LayoutKind.Sequential)] 232 | 233 | public struct stat 234 | { 235 | public ulong st_size; 236 | } 237 | } 238 | #pragma warning restore CS8981 // The type name only contains lower-cased ascii characters. Such names may become reserved for the language. 239 | #pragma warning restore CS0649 // Field is never assigned to, and will always have its default value 240 | } -------------------------------------------------------------------------------- /CSSharpFixes/Memory/WinMemoryUtils.cs: -------------------------------------------------------------------------------- 1 | /* 2 | ============================================================================= 3 | CS#Fixes 4 | Copyright (C) 2023-2024 Charles Barone / hypnos 5 | ============================================================================= 6 | 7 | This program is free software; you can redistribute it and/or modify it under 8 | the terms of the GNU General Public License, version 3.0, as published by the 9 | Free Software Foundation. 10 | 11 | This program is distributed in the hope that it will be useful, but WITHOUT 12 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 13 | FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 14 | details. 15 | 16 | You should have received a copy of the GNU General Public License along with 17 | this program. If not, see . 18 | */ 19 | 20 | using System.Diagnostics; 21 | using System.Runtime.InteropServices; 22 | 23 | namespace CSSharpFixes.Memory; 24 | 25 | // Based on https://github.com/Source2ZE/CS2Fixes/blob/main/src/utils/plat_win.cpp 26 | public class WinMemoryUtils 27 | { 28 | [DllImport("kernel32.dll", SetLastError = true)] 29 | static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, byte[] lpBuffer, uint nSize, out IntPtr lpNumberOfBytesWritten); 30 | 31 | public static void PatchBytesAtAddress(IntPtr pPatchAddress, byte[] pPatch, int iPatchSize) 32 | { 33 | if(!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) return; 34 | 35 | IntPtr bytesWritten; 36 | WriteProcessMemory(Process.GetCurrentProcess().Handle, pPatchAddress, pPatch, (uint)iPatchSize, out bytesWritten); 37 | } 38 | 39 | [DllImport("kernel32.dll", SetLastError = true)] 40 | private static extern IntPtr OpenProcess(int processAccess, bool bInheritHandle, int processId); 41 | 42 | [DllImport("kernel32.dll", SetLastError = true)] 43 | private static extern bool ReadProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, [Out] byte[] lpBuffer, int dwSize, out int lpNumberOfBytesRead); 44 | 45 | public static byte[]? ReadMemory(IntPtr address, int size) 46 | { 47 | if(!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) return null; 48 | 49 | byte[] buffer = new byte[size]; 50 | int bytesRead; 51 | ReadProcessMemory(Process.GetCurrentProcess().Handle, address, buffer, size, out bytesRead); 52 | return buffer; 53 | } 54 | } -------------------------------------------------------------------------------- /CSSharpFixes/Models/Detour.cs: -------------------------------------------------------------------------------- 1 | /* 2 | ============================================================================= 3 | CS#Fixes 4 | Copyright (C) 2023-2024 Charles Barone / hypnos 5 | ============================================================================= 6 | 7 | This program is free software; you can redistribute it and/or modify it under 8 | the terms of the GNU General Public License, version 3.0, as published by the 9 | Free Software Foundation. 10 | 11 | This program is distributed in the hope that it will be useful, but WITHOUT 12 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 13 | FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 14 | details. 15 | 16 | You should have received a copy of the GNU General Public License along with 17 | this program. If not, see . 18 | */ 19 | 20 | using CounterStrikeSharp.API.Core; 21 | using CounterStrikeSharp.API.Modules.Memory.DynamicFunctions; 22 | using CSSharpFixes.Memory; 23 | using Microsoft.Extensions.Logging; 24 | 25 | namespace CSSharpFixes.Models; 26 | 27 | public class Detour 28 | { 29 | private string _name; 30 | private string _signatureName; 31 | private HookMode _hookMode; 32 | private bool _isHooked; 33 | public BaseMemoryFunction MemoryFunction; 34 | private List> _handlers; 35 | 36 | private readonly ILogger _logger; 37 | 38 | public Detour(string name, string signatureName, HookMode hookMode, ILogger logger) 39 | { 40 | _name = name; 41 | _signatureName = signatureName; 42 | _hookMode = hookMode; 43 | _logger = logger; 44 | _isHooked = false; 45 | _handlers = new List>(); 46 | MemoryFunction = DetourMemoryFunctions.Get(_signatureName); 47 | } 48 | 49 | ~Detour() 50 | { 51 | if(_isHooked) 52 | { 53 | Unhook(); 54 | } 55 | } 56 | 57 | public bool IsHooked() { return _isHooked; } 58 | public string GetName() { return _name; } 59 | public string GetSignatureName() { return _signatureName; } 60 | public string GetSignature() { return GameData.GetSignature(_signatureName); } 61 | public HookMode GetHookMode() { return _hookMode; } 62 | 63 | public void Hook(Func handler, bool hookOnce = false) 64 | { 65 | if(hookOnce && _isHooked) return; 66 | MemoryFunction.Hook(handler, _hookMode); 67 | _isHooked = true; 68 | _handlers.Add(handler); 69 | } 70 | 71 | public void Unhook() 72 | { 73 | if(!_isHooked) return; 74 | 75 | foreach(Func handler in _handlers) 76 | { 77 | MemoryFunction.Unhook(handler, _hookMode); 78 | } 79 | 80 | _handlers.Clear(); 81 | _isHooked = false; 82 | } 83 | } -------------------------------------------------------------------------------- /CSSharpFixes/Models/Patch.cs: -------------------------------------------------------------------------------- 1 | /* 2 | ============================================================================= 3 | CS#Fixes 4 | Copyright (C) 2023-2024 Charles Barone / hypnos 5 | ============================================================================= 6 | 7 | This program is free software; you can redistribute it and/or modify it under 8 | the terms of the GNU General Public License, version 3.0, as published by the 9 | Free Software Foundation. 10 | 11 | This program is distributed in the hope that it will be useful, but WITHOUT 12 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 13 | FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 14 | details. 15 | 16 | You should have received a copy of the GNU General Public License along with 17 | this program. If not, see . 18 | */ 19 | 20 | using CSSharpFixes.Managers; 21 | using Microsoft.Extensions.Logging; 22 | 23 | namespace CSSharpFixes.Models; 24 | 25 | public class Patch 26 | { 27 | private string _patchName; 28 | private string _modulePath; 29 | private string _signatureName; 30 | private List? _originalBytes; 31 | private string _bytesHex; 32 | private List _bytes; 33 | private bool _isPatched; 34 | 35 | private readonly GameDataManager _gameDataManager; 36 | private readonly ILogger _logger; 37 | 38 | public Patch(string patchName, string modulePath, string signatureName, string bytesHex, 39 | GameDataManager gameDataManager, ILogger logger) 40 | { 41 | _patchName = patchName; 42 | _modulePath = modulePath; 43 | _signatureName = signatureName; 44 | _bytesHex = bytesHex; 45 | _bytes = Utils.HexToByte(_bytesHex); 46 | _gameDataManager = gameDataManager; 47 | _logger = logger; 48 | _isPatched = false; 49 | } 50 | 51 | ~Patch() 52 | { 53 | if(_isPatched) 54 | { 55 | UndoPatch(); 56 | } 57 | 58 | _bytes.Clear(); 59 | } 60 | 61 | public bool IsPatched() { return _isPatched; } 62 | public string GetPatchName() { return _patchName; } 63 | public string GetModulePath() { return _modulePath; } 64 | public string GetSignatureName() { return _signatureName; } 65 | public string GetBytesHex() { return _bytesHex; } 66 | public List GetBytes() { return _bytes; } 67 | public List? GetOriginalBytes() { return _originalBytes; } 68 | 69 | public void PerformPatch() 70 | { 71 | if(_isPatched) return; 72 | 73 | IntPtr address = _gameDataManager.GetAddress(_modulePath, _signatureName); 74 | if(address == IntPtr.Zero) 75 | { 76 | _logger.LogError( 77 | "[CSSharpFixes][Patch][PerformPatch()][Patch={patchName}][Signature={signatureName}] Error: Address not found.", 78 | _patchName, _signatureName); 79 | return; 80 | } 81 | 82 | // Backup original bytes at address with length of _bytes.Count 83 | _originalBytes = Utils.ReadBytesFromAddress(address, _bytes.Count); 84 | 85 | // Log the bytes in hex 86 | _logger.LogInformation("[CSSharpFixes][Patch][PerformPatch()][Patch={patchName}][Signature={signatureName}][OriginalBytes={originalBytes}]", 87 | _patchName, _signatureName, Utils.ByteToHex(_originalBytes)); 88 | 89 | Utils.WriteBytesToAddress(address, _bytes); 90 | 91 | _isPatched = true; 92 | 93 | _logger.LogInformation( 94 | "[CSSharpFixes][Patch][PerformPatch()][Patch={patchName}][Signature={signatureName}][PatchedBytes={bytes}] Successful", 95 | _patchName, _signatureName, Utils.ByteToHex(_bytes)); 96 | } 97 | 98 | public void UndoPatch() 99 | { 100 | if(!_isPatched) return; 101 | 102 | IntPtr address = _gameDataManager.GetAddress(_modulePath, _signatureName); 103 | if(address == IntPtr.Zero) 104 | { 105 | _logger.LogError( 106 | "[CSSharpFixes][Patch][UndoPatch()][Patch={patchName}][Signature={signatureName}] Error: Address not found.", 107 | _patchName, _signatureName); 108 | return; 109 | } 110 | 111 | if(_originalBytes == null) 112 | { 113 | _logger.LogError( 114 | "[CSSharpFixes][Patch][UndoPatch()][Patch={patchName}][Signature={signatureName}] Error: Original bytes are null.", 115 | _patchName, _signatureName); 116 | return; 117 | } 118 | 119 | Utils.WriteBytesToAddress(address, _originalBytes); 120 | 121 | _logger.LogInformation( 122 | "[CSSharpFixes][Patch][UndoPatch()][Patch={patchName}][Signature={signatureName}][OriginalBytes={originalBytes}] Successful", 123 | _patchName, _signatureName, Utils.ByteToHex(_originalBytes)); 124 | 125 | _originalBytes.Clear(); 126 | _originalBytes = null; 127 | 128 | _isPatched = false; 129 | } 130 | 131 | } -------------------------------------------------------------------------------- /CSSharpFixes/Schemas/Interfaces/ISizeable.cs: -------------------------------------------------------------------------------- 1 | /* 2 | ============================================================================= 3 | CS#Fixes 4 | Copyright (C) 2023-2024 Charles Barone / hypnos 5 | ============================================================================= 6 | 7 | This program is free software; you can redistribute it and/or modify it under 8 | the terms of the GNU General Public License, version 3.0, as published by the 9 | Free Software Foundation. 10 | 11 | This program is distributed in the hope that it will be useful, but WITHOUT 12 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 13 | FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 14 | details. 15 | 16 | You should have received a copy of the GNU General Public License along with 17 | this program. If not, see . 18 | */ 19 | 20 | namespace CSSharpFixes.Schemas.Interfaces; 21 | 22 | public interface ISizeable 23 | { 24 | static abstract ulong Size(); 25 | } -------------------------------------------------------------------------------- /CSSharpFixes/Schemas/Protobuf/CBaseUserCmdPB.cs: -------------------------------------------------------------------------------- 1 | /* 2 | ============================================================================= 3 | CS#Fixes 4 | Copyright (C) 2023-2024 Charles Barone / hypnos 5 | ============================================================================= 6 | 7 | This program is free software; you can redistribute it and/or modify it under 8 | the terms of the GNU General Public License, version 3.0, as published by the 9 | Free Software Foundation. 10 | 11 | This program is distributed in the hope that it will be useful, but WITHOUT 12 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 13 | FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 14 | details. 15 | 16 | You should have received a copy of the GNU General Public License along with 17 | this program. If not, see . 18 | */ 19 | 20 | namespace CSSharpFixes.Schemas.Protobuf; 21 | 22 | public class CBaseUserCmdPB: Interfaces.ISizeable 23 | { 24 | public static ulong Size() => 0x80; 25 | 26 | private IntPtr _address; 27 | private Dictionary _offsets = new(); 28 | 29 | public CBaseUserCmdPB(IntPtr address) 30 | { 31 | if (address == IntPtr.Zero) throw new ArgumentException("Address cannot be zero."); 32 | _address = address; 33 | 34 | // CBasePB size = 0x18 35 | _offsets.Add("SubtickMoves", 0x18); // RepeatedPtrField 36 | // std::string* strMoveCrc; offset = 0x30. size = 0x8 37 | // CInButtonStatePB* pInButtonState; offset = 0x38. size = 0x8 38 | // CMsgQAngle* pViewAngles; offset = 0x40. size = 0x8 39 | _offsets.Add("CommandNumber", 0x48); // int 40 | _offsets.Add("ClientTick", 0x4C); // int 41 | _offsets.Add("ForwardMove", 0x50); // float 42 | _offsets.Add("SideMove", 0x54); // float 43 | _offsets.Add("UpMove", 0x58); // float 44 | _offsets.Add("Impulse", 0x5C); // int 45 | _offsets.Add("WeaponSelect", 0x60); // int 46 | _offsets.Add("RandomSeed", 0x64); // int 47 | _offsets.Add("MouseX", 0x68); // int 48 | _offsets.Add("MouseY", 0x6C); // int 49 | _offsets.Add("ConsumedServerAngleChanges", 0x70); // uint 50 | _offsets.Add("CmdFlags", 0x74); // int 51 | _offsets.Add("PawnEntityHandle", 0x78); // uint 52 | } 53 | 54 | ~CBaseUserCmdPB() 55 | { 56 | _address = IntPtr.Zero; 57 | _offsets.Clear(); 58 | } 59 | 60 | public Schemas.Protobuf.Interop.RepeatedPtrField? SubtickMoves 61 | { 62 | get 63 | { 64 | IntPtr subtickMovesPtr = (IntPtr)((ulong)_address + _offsets["SubtickMoves"]); 65 | if(subtickMovesPtr == IntPtr.Zero) return null; 66 | return new Schemas.Protobuf.Interop.RepeatedPtrField(subtickMovesPtr); 67 | } 68 | } 69 | 70 | public int? ClientTick 71 | { 72 | get 73 | { 74 | IntPtr clientTickPtr = (IntPtr)((ulong)_address + _offsets["ClientTick"]); 75 | if(clientTickPtr == IntPtr.Zero) return null; 76 | 77 | unsafe 78 | { 79 | int* clientPtr = (int*)clientTickPtr.ToPointer(); 80 | return *clientPtr; 81 | } 82 | } 83 | } 84 | 85 | public int? CommandNumber 86 | { 87 | get 88 | { 89 | IntPtr commandNumberPtr = (IntPtr)((ulong)_address + _offsets["CommandNumber"]); 90 | if(commandNumberPtr == IntPtr.Zero) return null; 91 | 92 | unsafe 93 | { 94 | int* commandNumber = (int*)commandNumberPtr.ToPointer(); 95 | return *commandNumber; 96 | } 97 | } 98 | } 99 | 100 | public float? ForwardMove 101 | { 102 | get 103 | { 104 | IntPtr forwardMovePtr = (IntPtr)((ulong)_address + _offsets["ForwardMove"]); 105 | if(forwardMovePtr == IntPtr.Zero) return null; 106 | 107 | unsafe 108 | { 109 | float* forwardMove = (float*)forwardMovePtr.ToPointer(); 110 | return *forwardMove; 111 | } 112 | } 113 | } 114 | 115 | public float? SideMove 116 | { 117 | get 118 | { 119 | IntPtr sideMovePtr = (IntPtr)((ulong)_address + _offsets["SideMove"]); 120 | if(sideMovePtr == IntPtr.Zero) return null; 121 | 122 | unsafe 123 | { 124 | float* sideMove = (float*)sideMovePtr.ToPointer(); 125 | return *sideMove; 126 | } 127 | } 128 | } 129 | 130 | public float? UpMove 131 | { 132 | get 133 | { 134 | IntPtr upMovePtr = (IntPtr)((ulong)_address + _offsets["UpMove"]); 135 | if(upMovePtr == IntPtr.Zero) return null; 136 | 137 | unsafe 138 | { 139 | float* upMove = (float*)upMovePtr.ToPointer(); 140 | return *upMove; 141 | } 142 | } 143 | } 144 | 145 | public int? Impulse 146 | { 147 | get 148 | { 149 | IntPtr impulsePtr = (IntPtr)((ulong)_address + _offsets["Impulse"]); 150 | if(impulsePtr == IntPtr.Zero) return null; 151 | 152 | unsafe 153 | { 154 | int* impulse = (int*)impulsePtr.ToPointer(); 155 | return *impulse; 156 | } 157 | } 158 | } 159 | 160 | public int? WeaponSelect 161 | { 162 | get 163 | { 164 | IntPtr weaponSelectPtr = (IntPtr)((ulong)_address + _offsets["WeaponSelect"]); 165 | if(weaponSelectPtr == IntPtr.Zero) return null; 166 | 167 | unsafe 168 | { 169 | int* weaponSelect = (int*)weaponSelectPtr.ToPointer(); 170 | return *weaponSelect; 171 | } 172 | } 173 | } 174 | 175 | public int? RandomSeed 176 | { 177 | get 178 | { 179 | IntPtr randomSeedPtr = (IntPtr)((ulong)_address + _offsets["RandomSeed"]); 180 | if(randomSeedPtr == IntPtr.Zero) return null; 181 | 182 | unsafe 183 | { 184 | int* randomSeed = (int*)randomSeedPtr.ToPointer(); 185 | return *randomSeed; 186 | } 187 | } 188 | } 189 | 190 | public int? MouseX 191 | { 192 | get 193 | { 194 | IntPtr mouseXPtr = (IntPtr)((ulong)_address + _offsets["MouseX"]); 195 | if(mouseXPtr == IntPtr.Zero) return null; 196 | 197 | unsafe 198 | { 199 | int* mouseX = (int*)mouseXPtr.ToPointer(); 200 | return *mouseX; 201 | } 202 | } 203 | } 204 | 205 | public int? MouseY 206 | { 207 | get 208 | { 209 | IntPtr mouseYPtr = (IntPtr)((ulong)_address + _offsets["MouseY"]); 210 | if(mouseYPtr == IntPtr.Zero) return null; 211 | 212 | unsafe 213 | { 214 | int* mouseY = (int*)mouseYPtr.ToPointer(); 215 | return *mouseY; 216 | } 217 | } 218 | } 219 | } -------------------------------------------------------------------------------- /CSSharpFixes/Schemas/Protobuf/CSubTickMoveStep.cs: -------------------------------------------------------------------------------- 1 | /* 2 | ============================================================================= 3 | CS#Fixes 4 | Copyright (C) 2023-2024 Charles Barone / hypnos 5 | ============================================================================= 6 | 7 | This program is free software; you can redistribute it and/or modify it under 8 | the terms of the GNU General Public License, version 3.0, as published by the 9 | Free Software Foundation. 10 | 11 | This program is distributed in the hope that it will be useful, but WITHOUT 12 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 13 | FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 14 | details. 15 | 16 | You should have received a copy of the GNU General Public License along with 17 | this program. If not, see . 18 | */ 19 | 20 | namespace CSSharpFixes.Schemas.Protobuf; 21 | 22 | public class CSubTickMoveStep: Interfaces.ISizeable 23 | { 24 | 25 | public static ulong Size() => 0x30; 26 | 27 | private IntPtr _address; 28 | private Dictionary _offsets = new(); 29 | 30 | public CSubTickMoveStep(IntPtr address) 31 | { 32 | if (address == IntPtr.Zero) throw new ArgumentException("Address cannot be zero."); 33 | _address = address; 34 | 35 | // CBasePB size = 0x18 36 | _offsets.Add("Button", 0x18); // ulong 37 | _offsets.Add("Pressed", 0x20); // bool 38 | // 0x3 bytes padding (to align bool) 39 | _offsets.Add("When", 0x24); // float 40 | _offsets.Add("AnalogForwardDelta", 0x28); // float 41 | _offsets.Add("AnalogLeftDelta", 0x2C); // float 42 | } 43 | 44 | ~CSubTickMoveStep() 45 | { 46 | _address = IntPtr.Zero; 47 | _offsets.Clear(); 48 | } 49 | 50 | public ulong? Button 51 | { 52 | get 53 | { 54 | IntPtr buttonPtr = (IntPtr)((ulong)_address + _offsets["Button"]); 55 | if(buttonPtr == IntPtr.Zero) return null; 56 | 57 | unsafe 58 | { 59 | ulong* button = (ulong*)buttonPtr.ToPointer(); 60 | return *button; 61 | } 62 | } 63 | } 64 | 65 | public bool? Pressed 66 | { 67 | get 68 | { 69 | IntPtr pressedPtr = (IntPtr)((ulong)_address + _offsets["Pressed"]); 70 | if(pressedPtr == IntPtr.Zero) return null; 71 | 72 | unsafe 73 | { 74 | bool* pressed = (bool*)pressedPtr.ToPointer(); 75 | return *pressed; 76 | } 77 | } 78 | } 79 | 80 | public float? When 81 | { 82 | get 83 | { 84 | IntPtr whenPtr = (IntPtr)((ulong)_address + _offsets["When"]); 85 | if(whenPtr == IntPtr.Zero) return null; 86 | 87 | unsafe 88 | { 89 | float* when = (float*)whenPtr.ToPointer(); 90 | return *when; 91 | } 92 | } 93 | set 94 | { 95 | IntPtr whenPtr = (IntPtr)((ulong)_address + _offsets["When"]); 96 | if(whenPtr == IntPtr.Zero) return; 97 | if (value == null) return; 98 | 99 | unsafe 100 | { 101 | float* when = (float*)whenPtr.ToPointer(); 102 | *when = (float)value; 103 | } 104 | } 105 | } 106 | 107 | public float? AnalogForwardDelta 108 | { 109 | get 110 | { 111 | IntPtr analogForwardDeltaPtr = (IntPtr)((ulong)_address + _offsets["AnalogForwardDelta"]); 112 | if(analogForwardDeltaPtr == IntPtr.Zero) return null; 113 | 114 | unsafe 115 | { 116 | float* analogForwardDelta = (float*)analogForwardDeltaPtr.ToPointer(); 117 | return *analogForwardDelta; 118 | } 119 | } 120 | } 121 | 122 | public float? AnalogLeftDelta 123 | { 124 | get 125 | { 126 | IntPtr analogLeftDeltaPtr = (IntPtr)((ulong)_address + _offsets["AnalogLeftDelta"]); 127 | if(analogLeftDeltaPtr == IntPtr.Zero) return null; 128 | 129 | unsafe 130 | { 131 | float* analogLeftDelta = (float*)analogLeftDeltaPtr.ToPointer(); 132 | return *analogLeftDelta; 133 | } 134 | } 135 | } 136 | } -------------------------------------------------------------------------------- /CSSharpFixes/Schemas/Protobuf/CUserCmd.cs: -------------------------------------------------------------------------------- 1 | /* 2 | ============================================================================= 3 | CS#Fixes 4 | Copyright (C) 2023-2024 Charles Barone / hypnos 5 | ============================================================================= 6 | 7 | This program is free software; you can redistribute it and/or modify it under 8 | the terms of the GNU General Public License, version 3.0, as published by the 9 | Free Software Foundation. 10 | 11 | This program is distributed in the hope that it will be useful, but WITHOUT 12 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 13 | FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 14 | details. 15 | 16 | You should have received a copy of the GNU General Public License along with 17 | this program. If not, see . 18 | */ 19 | 20 | using System.Runtime.InteropServices; 21 | 22 | namespace CSSharpFixes.Schemas.Protobuf; 23 | 24 | public class CUserCmd: Interfaces.ISizeable 25 | { 26 | public static ulong Size() => RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? (ulong)0x88 : (ulong)0x80; 27 | 28 | private IntPtr _address; 29 | private Dictionary _offsets = new(); 30 | 31 | public CUserCmd(IntPtr address) 32 | { 33 | if (address == IntPtr.Zero) throw new ArgumentException("Address cannot be zero."); 34 | _address = address; 35 | 36 | // CBasePB + RepeatedPtrField_t 37 | // 0x18 + 0x18 = 0x30 38 | _offsets.Add("Base", 0x30); //CBasePB + RepeatedPtrField_t 39 | _offsets.Add("LeftHandDesired", 0x38); 40 | } 41 | 42 | ~CUserCmd() 43 | { 44 | _address = IntPtr.Zero; 45 | _offsets.Clear(); 46 | } 47 | 48 | public CBaseUserCmdPB? Base 49 | { 50 | get 51 | { 52 | IntPtr baseAddressPtr = (IntPtr)((ulong)_address + _offsets["Base"]); 53 | if(baseAddressPtr == IntPtr.Zero) return null; 54 | IntPtr baseAddress = Marshal.ReadIntPtr(baseAddressPtr); 55 | if(baseAddress == IntPtr.Zero) return null; 56 | return new CBaseUserCmdPB(baseAddress); 57 | } 58 | } 59 | 60 | public Boolean? LeftHandDesired 61 | { 62 | get 63 | { 64 | IntPtr leftHandDesiredPtr = (IntPtr)((ulong)_address + _offsets["LeftHandDesired"]); 65 | if(leftHandDesiredPtr == IntPtr.Zero) return null; 66 | 67 | unsafe 68 | { 69 | Boolean* leftHandDesired = (Boolean*)leftHandDesiredPtr.ToPointer(); 70 | return *leftHandDesired; 71 | } 72 | } 73 | } 74 | } -------------------------------------------------------------------------------- /CSSharpFixes/Schemas/Protobuf/Interop/Rep.cs: -------------------------------------------------------------------------------- 1 | /* 2 | ============================================================================= 3 | CS#Fixes 4 | Copyright (C) 2023-2024 Charles Barone / hypnos 5 | ============================================================================= 6 | 7 | This program is free software; you can redistribute it and/or modify it under 8 | the terms of the GNU General Public License, version 3.0, as published by the 9 | Free Software Foundation. 10 | 11 | This program is distributed in the hope that it will be useful, but WITHOUT 12 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 13 | FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 14 | details. 15 | 16 | You should have received a copy of the GNU General Public License along with 17 | this program. If not, see . 18 | */ 19 | 20 | using System.Runtime.InteropServices; 21 | 22 | namespace CSSharpFixes.Schemas.Protobuf.Interop; 23 | 24 | public class Rep where T : class 25 | { 26 | private IntPtr _address; 27 | private Dictionary _offsets = new(); 28 | 29 | public Rep(IntPtr address) 30 | { 31 | if (address == IntPtr.Zero) throw new ArgumentException("Address cannot be zero."); 32 | _address = address; 33 | 34 | _offsets.Add("AllocatedSize", 0x0); 35 | // 0x4 of padding 36 | _offsets.Add("ElementsAddress", 0x8); 37 | } 38 | 39 | ~Rep() 40 | { 41 | _address = IntPtr.Zero; 42 | _offsets.Clear(); 43 | } 44 | 45 | public int? AllocatedSize 46 | { 47 | get 48 | { 49 | IntPtr allocatedSizePtr = (IntPtr)((ulong)_address + _offsets["AllocatedSize"]); 50 | if(allocatedSizePtr == IntPtr.Zero) return null; 51 | 52 | unsafe 53 | { 54 | int* allocatedSize = (int*)allocatedSizePtr.ToPointer(); 55 | return *allocatedSize; 56 | } 57 | } 58 | } 59 | 60 | public IntPtr? ElementsAddress 61 | { 62 | get 63 | { 64 | IntPtr elementsAddressPtr = (IntPtr)((ulong)_address + _offsets["ElementsAddress"]); 65 | if(elementsAddressPtr == IntPtr.Zero) return null; 66 | IntPtr elementsAddress = Marshal.ReadIntPtr(elementsAddressPtr); 67 | return elementsAddress; 68 | } 69 | } 70 | } -------------------------------------------------------------------------------- /CSSharpFixes/Schemas/Protobuf/Interop/RepeatedPtrField.cs: -------------------------------------------------------------------------------- 1 | /* 2 | ============================================================================= 3 | CS#Fixes 4 | Copyright (C) 2023-2024 Charles Barone / hypnos 5 | ============================================================================= 6 | 7 | This program is free software; you can redistribute it and/or modify it under 8 | the terms of the GNU General Public License, version 3.0, as published by the 9 | Free Software Foundation. 10 | 11 | This program is distributed in the hope that it will be useful, but WITHOUT 12 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 13 | FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 14 | details. 15 | 16 | You should have received a copy of the GNU General Public License along with 17 | this program. If not, see . 18 | */ 19 | 20 | using System.Runtime.InteropServices; 21 | 22 | namespace CSSharpFixes.Schemas.Protobuf.Interop; 23 | 24 | public class RepeatedPtrField where T : class, Interfaces.ISizeable 25 | { 26 | public static ulong Size() => 0x18; 27 | 28 | private IntPtr _address; 29 | private Dictionary _offsets = new(); 30 | 31 | public RepeatedPtrField(IntPtr address) 32 | { 33 | if (address == IntPtr.Zero) throw new ArgumentException("Address cannot be zero."); 34 | _address = address; 35 | 36 | _offsets.Add("ArenaAddress", 0x0); 37 | _offsets.Add("CurrentSize", 0x8); 38 | _offsets.Add("TotalSize", 0xC); 39 | _offsets.Add("Rep", 0x10); 40 | } 41 | 42 | ~RepeatedPtrField() 43 | { 44 | _address = IntPtr.Zero; 45 | _offsets.Clear(); 46 | } 47 | 48 | public IntPtr? ArenaAddress 49 | { 50 | get 51 | { 52 | IntPtr arenaAddressPtr = (IntPtr)((ulong)_address + _offsets["Arena"]); 53 | if(arenaAddressPtr == IntPtr.Zero) return null; 54 | IntPtr arenaAddress = Marshal.ReadIntPtr(arenaAddressPtr); 55 | if(arenaAddress == IntPtr.Zero) return null; 56 | return arenaAddress; 57 | } 58 | } 59 | 60 | public int? CurrentSize 61 | { 62 | get 63 | { 64 | IntPtr currentSizePtr = (IntPtr)((ulong)_address + _offsets["CurrentSize"]); 65 | if(currentSizePtr == IntPtr.Zero) return null; 66 | 67 | unsafe 68 | { 69 | int* currentSize = (int*)currentSizePtr.ToPointer(); 70 | return *currentSize; 71 | } 72 | } 73 | } 74 | 75 | public int? TotalSize 76 | { 77 | get 78 | { 79 | IntPtr totalSizePtr = (IntPtr)((ulong)_address + _offsets["TotalSize"]); 80 | if(totalSizePtr == IntPtr.Zero) return null; 81 | 82 | unsafe 83 | { 84 | int* totalSize = (int*)totalSizePtr.ToPointer(); 85 | return *totalSize; 86 | } 87 | } 88 | } 89 | 90 | public Rep? Rep 91 | { 92 | get 93 | { 94 | IntPtr repAddressPtr = (IntPtr)((ulong)_address + _offsets["Rep"]); 95 | if(repAddressPtr == IntPtr.Zero) return null; 96 | IntPtr repAddress = Marshal.ReadIntPtr(repAddressPtr); 97 | if(repAddress == IntPtr.Zero) return null; 98 | return new Rep(repAddress); 99 | } 100 | } 101 | 102 | public int Length 103 | { 104 | get 105 | { 106 | if(CurrentSize == null) return 0; 107 | return (int)CurrentSize; 108 | } 109 | } 110 | 111 | public IntPtr? this[int index] 112 | { 113 | get 114 | { 115 | if(index < 0 || index >= Length) return null; 116 | 117 | Rep? rep = Rep; 118 | if(rep == null) return null; 119 | IntPtr? elementsPtr = rep.ElementsAddress; 120 | if(elementsPtr == null) return null; 121 | 122 | IntPtr tPtr = (IntPtr)((ulong)elementsPtr + (ulong)index * T.Size()); 123 | if(tPtr == IntPtr.Zero) return null; 124 | 125 | return tPtr; 126 | } 127 | } 128 | 129 | 130 | } -------------------------------------------------------------------------------- /CSSharpFixes/Utils.cs: -------------------------------------------------------------------------------- 1 | /* 2 | ============================================================================= 3 | CS#Fixes 4 | Copyright (C) 2023-2024 Charles Barone / hypnos 5 | ============================================================================= 6 | 7 | This program is free software; you can redistribute it and/or modify it under 8 | the terms of the GNU General Public License, version 3.0, as published by the 9 | Free Software Foundation. 10 | 11 | This program is distributed in the hope that it will be useful, but WITHOUT 12 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 13 | FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 14 | details. 15 | 16 | You should have received a copy of the GNU General Public License along with 17 | this program. If not, see . 18 | */ 19 | 20 | using System.Runtime.InteropServices; 21 | using System.Text; 22 | using CounterStrikeSharp.API.Core; 23 | using CounterStrikeSharp.API.Modules.Memory.DynamicFunctions; 24 | using CounterStrikeSharp.API.Modules.Utils; 25 | 26 | namespace CSSharpFixes; 27 | 28 | public class Utils 29 | { 30 | public static T BuildMemoryFunction(string signatureName) where T : BaseMemoryFunction 31 | { 32 | if (string.IsNullOrEmpty(signatureName)) 33 | throw new ArgumentException("Signature name must not be null or empty", nameof(signatureName)); 34 | 35 | string? signature = null; 36 | try 37 | { 38 | signature = GameData.GetSignature(signatureName); 39 | } 40 | catch (Exception ex) 41 | { 42 | throw new InvalidOperationException($"Failed to build memory function of type {typeof(T).FullName}. There was an error attempting to get the signature '{signatureName}'.", ex); 43 | } 44 | 45 | if (string.IsNullOrEmpty(signature)) 46 | throw new InvalidOperationException($"Failed to build memory function of type {typeof(T).FullName}. The signature '{signatureName}' was found but is empty."); 47 | 48 | object? instance = Activator.CreateInstance(typeof(T), signature); 49 | 50 | if (instance == null) 51 | throw new InvalidOperationException($"Failed to build memory function of type {typeof(T).FullName}. The instance of type {typeof(T).FullName} was null."); 52 | 53 | return (T)instance; 54 | } 55 | 56 | // Mimic the behavior of the C++ function std::vector CGameConfig::HexToByte(std::string_view src) 57 | public static List HexToByte(string src) 58 | { 59 | if (string.IsNullOrEmpty(src)) 60 | { 61 | return new List(); 62 | } 63 | 64 | Func hexCharToByte = c => 65 | { 66 | if (c >= '0' && c <= '9') return (byte)(c - '0'); 67 | if (c >= 'A' && c <= 'F') return (byte)(c - 'A' + 10); 68 | if (c >= 'a' && c <= 'f') return (byte)(c - 'a' + 10); 69 | return 0xFF; // Invalid hex character 70 | }; 71 | 72 | List result = new List(); 73 | bool isCodeStyle = src[0] == '\\'; 74 | string pattern = isCodeStyle ? "\\x" : " "; 75 | string wildcard = isCodeStyle ? "2A" : "?"; 76 | int pos = 0; 77 | 78 | while (pos < src.Length) 79 | { 80 | int found = src.IndexOf(pattern, pos); 81 | if (found == -1) 82 | { 83 | found = src.Length; 84 | } 85 | 86 | string str = src.Substring(pos, found - pos); 87 | pos = found + pattern.Length; 88 | 89 | if (string.IsNullOrEmpty(str)) continue; 90 | 91 | string byteStr = str; 92 | 93 | if (byteStr.Substring(0, wildcard.Length) == wildcard) 94 | { 95 | result.Add(0xFF); // Representing wildcard as 0xFF 96 | continue; 97 | } 98 | 99 | if (byteStr.Length < 2) 100 | { 101 | return new List(); // Invalid byte length 102 | } 103 | 104 | byte high = hexCharToByte(byteStr[0]); 105 | byte low = hexCharToByte(byteStr[1]); 106 | 107 | if (high == 0xFF || low == 0xFF) 108 | { 109 | return new List(); // Invalid hex character 110 | } 111 | 112 | result.Add((byte)((high << 4) | low)); 113 | } 114 | 115 | return result; 116 | } 117 | 118 | public static string ByteToHex(List bytes, bool useCodeStyle = false) 119 | { 120 | if (bytes == null || bytes.Count == 0) 121 | { 122 | return string.Empty; 123 | } 124 | 125 | Func byteToHexChar = b => 126 | { 127 | if (b < 10) return (char)(b + '0'); 128 | return (char)(b - 10 + 'A'); 129 | }; 130 | 131 | StringBuilder result = new StringBuilder(); 132 | string pattern = useCodeStyle ? "\\x" : " "; 133 | 134 | foreach (byte b in bytes) 135 | { 136 | if (b == 0xFF) // Wildcard representation 137 | { 138 | result.Append(useCodeStyle ? "\\x2A" : "??"); 139 | } 140 | else 141 | { 142 | result.Append(byteToHexChar((byte)(b >> 4))); // High nibble 143 | result.Append(byteToHexChar((byte)(b & 0x0F))); // Low nibble 144 | if (useCodeStyle) 145 | { 146 | result.Append(pattern); // Separator 147 | } 148 | } 149 | } 150 | 151 | // Remove the trailing separator if using code style 152 | if (useCodeStyle && result.Length > 0) 153 | { 154 | result.Remove(result.Length - pattern.Length, pattern.Length); 155 | } 156 | 157 | return result.ToString(); 158 | } 159 | 160 | public static List ReadBytesFromAddress(IntPtr address, int length) 161 | { 162 | List result = new List(); 163 | for (int i = 0; i < length; i++) 164 | { 165 | result.Add(ReadByteFromAddress(address + i)); 166 | } 167 | 168 | return result; 169 | } 170 | 171 | public static unsafe byte ReadByteFromAddress(IntPtr address) 172 | { 173 | return *(byte*)address.ToPointer(); 174 | } 175 | 176 | public static void WriteBytesToAddress(IntPtr address, List bytes) 177 | { 178 | int patchSize = bytes.Count; 179 | if(patchSize == 0) throw new ArgumentException("Patch bytes list cannot be empty."); 180 | 181 | if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) 182 | { 183 | Memory.UnixMemoryUtils.PatchBytesAtAddress(address, bytes.ToArray(), patchSize); 184 | } 185 | else 186 | { 187 | Memory.WinMemoryUtils.PatchBytesAtAddress(address, bytes.ToArray(), patchSize); 188 | } 189 | } 190 | 191 | public static List FloatToByteArray(float value) 192 | { 193 | byte[] bytes = BitConverter.GetBytes(value); 194 | return bytes.ToList(); 195 | } 196 | 197 | public static byte[] ReadMemory(IntPtr address, int size) 198 | { 199 | byte[] buffer = new byte[size]; 200 | Marshal.Copy(address, buffer, 0, size); 201 | return buffer; 202 | } 203 | 204 | public static bool IsSolid(CCollisionProperty collision) 205 | { 206 | return (collision.SolidType != SolidType_t.SOLID_NONE 207 | && !SolidFlagIsSet(collision, 0x4)); // FSOLID_NOT_SOLID = 0x4 208 | } 209 | 210 | public static bool SolidFlagIsSet(CCollisionProperty collision, byte flag) 211 | { 212 | return (collision.SolidFlags & flag) > 0; 213 | } 214 | 215 | public static void SinCos(float radians, out float sine, out float cosine) 216 | { 217 | sine = (float)Math.Sin(radians); 218 | cosine = (float)Math.Cos(radians); 219 | } 220 | 221 | public static float DegToRad(float degrees) 222 | { 223 | return (float)(Math.PI / 180) * degrees; 224 | } 225 | 226 | public static void VectorRotate(Vector vecIn, float[,] matIn, ref Vector vecOut) 227 | { 228 | vecOut.X = vecIn.X * matIn[0, 0] + vecIn.Y * matIn[0, 1] + vecIn.Z * matIn[0, 2]; 229 | vecOut.Y = vecIn.X * matIn[1, 0] + vecIn.Y * matIn[1, 1] + vecIn.Z * matIn[1, 2]; 230 | vecOut.Z = vecIn.X * matIn[2, 0] + vecIn.Y * matIn[2, 1] + vecIn.Z * matIn[2, 2]; 231 | } 232 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 |  GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # CS#Fixes 2 | 3 | CS#Fixes is a CounterStrikeSharp plugin that fixes some bugs in Counter-Strike 2 and adds some commonly requested 4 | features. This plugin is intended to replace CS2Fixes for servers that run CS# since CS2Fixes often conflicts with 5 | CS# plugins. (Unlike cs2fixes, every feature in this plugin is optional and can be enabled or disabled via ConVars). 6 | 7 | ## Features 8 | 9 | - Water Fix: Fixes being stuck to the floor underwater, allowing players to swim up. 10 | - trigger_push Fix: Reverts trigger_push behaviour to that seen in CS:GO. 11 | - CPhysBox Use Patch: Fixes CPhysBox use. Makes func_physbox pass itself as the caller in OnPlayerUse. 12 | - No Block: Prevent players from blocking each other. (Sets debris collision on every player). 13 | - Disable Subtick Movement: Disables sub-tick movement. 14 | - Movement Unlocker: Enables movement unlocker. 15 | - Force Full Alltalk: Enforces sv_full_alltalk 1. 16 | 17 | ## ConVars 18 | 19 | - css_fixes_water_fix: Enable or disable the water fix. Default is 1. 20 | - css_fixes_trigger_push_fix: Enable or disable the trigger_push fix. Default is 0. 21 | - css_fixes_cphys_box_use_fix: Enable or disable the CPhysBox use patch. Default is 0. 22 | - css_fixes_no_block: Enable or disable the no block feature. Default is 0. 23 | - css_fixes_disable_sub_tick_movement: Enable or disable the disable subtick movement feature. Default is 0. 24 | - css_fixes_enable_movement_unlocker: Enable or disable the movement unlocker feature. Default is 0. 25 | - css_fixes_enforce_full_alltalk: Enable or disable the force full alltalk feature. Default is 0. 26 | 27 | ## Why make this plugin when CS2Fixes already exists? 28 | 29 | The primary motive for making this plugin was because I wanted the water fix from cs2fixes, but I couldn't run cs2fixes 30 | on my server because it conflicted with other plugins. Specifically it consumed chat commands in a way that conflicted 31 | with command handling in CS#. Additionally, I could have forked cs2fixes and kept it as a MetaMod plugin, but then I 32 | would have had the problem of maintaining a C++ plugin for both windows and linux, whereas with CS# I can just compile 33 | one plugin that is platform-agnostic, thus lowering the maintenance burden. Additionally, there are more developers 34 | making plugins for CS# than there are for MetaMod, so I figured it would be easier for others to assist in maintaining 35 | the plugin if it were written in C#. Also, it should be noted that unlike CS2Fixes, this plugin is not made for the 36 | Zombie Escape gamemode, thus it doesn't have the features that are specific to that gamemode or that I felt should 37 | probably be implemented in their own plugins like administrative features and ZE specific features. -------------------------------------------------------------------------------- /gamedata/cssharpfixes.json: -------------------------------------------------------------------------------- 1 | { 2 | "WaterLevelGravity": { 3 | "signatures": { 4 | "library": "server", 5 | "windows": "3C 01 49 8B 5B 10 49 8B 7B 18 0F 97 C0 41 0F 28", 6 | "linux": "3C 01 0F 97 C0 48 81 C4 50 01" 7 | } 8 | }, 9 | "CheckJumpButtonWater": { 10 | "signatures": { 11 | "library": "server", 12 | "windows": "C8 42 EB ? 48 8B 4B 30", 13 | "linux": "C8 42 66 0F EF DB 41 0F 2F 5D" 14 | } 15 | }, 16 | "CategorizeUnderwater": { 17 | "signatures": { 18 | "library": "server", 19 | "windows": "75 ? B3 01 EB ? 32 DB 45 32 ?", 20 | "linux": "0F 45 C2 4D 85 C0 0F 95 C2 20 C2" 21 | } 22 | }, 23 | "CPhysBox_Use": { 24 | "signatures": { 25 | "library": "server", 26 | "windows": "4C 8B 47 08 48 8D 8B ? ? ? ? 48 8B 17 4C 8D 4C 24 ?", 27 | "linux": "49 8B 54 24 08 48 8D 4D E0 48 C7 45 ? ? ? ? ?" 28 | } 29 | }, 30 | "BotNavIgnore": { 31 | "signatures": { 32 | "library": "server", 33 | "windows": "0F 84 ? ? ? ? 80 B8 ? ? ? ? 00 0F 84 ? ? ? ? 80 3D ? ? ? ? 00 74 15", 34 | "linux": "0F 45 C2 4D 85 C0 0F 95 C2 20 C2" 35 | } 36 | }, 37 | "ServerMovementUnlock": { 38 | "signatures": { 39 | "library": "server", 40 | "windows": "76 ? F2 0F 10 57 ? 0F 28 ? F3 0F ? ? 0F 28 ?", 41 | "linux": "0F 87 ? ? ? ? 49 8B 7C 24 ? E8 ? ? ? ? 66 0F EF ED 66 0F D6 85" 42 | } 43 | }, 44 | "ProcessUsercmds": { 45 | "signatures": { 46 | "library": "server", 47 | "windows": "48 8B C4 44 88 48 20 44 89 40 18 48 89 50 10 53", 48 | "linux": "55 48 89 E5 41 57 41 56 41 89 D6 41 55 41 54 49 89 FC 53 48 83 EC 38" 49 | } 50 | }, 51 | "TriggerPush_Touch": { 52 | "signatures": { 53 | "library": "server", 54 | "windows": "48 89 74 24 18 48 89 7C 24 20 55 48 8D AC 24 40 E0 FF FF", 55 | "linux": "55 48 89 E5 41 57 41 56 41 55 49 89 F5 41 54 49 89 FC 53 48 81 EC ? ? ? ? E8 ? ? ? ? 84 C0 74 ?" 56 | } 57 | }, 58 | "SetGroundEntity": { 59 | "signatures": { 60 | "library": "server", 61 | "windows": "48 89 5C 24 10 48 89 6C 24 18 56 57 41 55 41 56 41 57 48 83 EC 20 33 ED", 62 | "linux": "55 48 89 E5 41 57 41 56 49 89 D6 41 55 49 89 F5 41 54 49 89 FC 53 48 83 EC 18 8B 97 B4 06 00 00" 63 | } 64 | }, 65 | "PassesTriggerFilters": { 66 | "offsets": { 67 | "windows": 258, 68 | "linux": 259 69 | } 70 | } 71 | } --------------------------------------------------------------------------------