Compare commits

...

10 Commits
v286 ... v293

Author SHA1 Message Date
Michael Wilson
ba860a92d2 fix: temporary patch hl2sdk entity listeners 2024-12-20 12:37:50 +00:00
Ian Lucas
461fc0ea67 Fix GiveNamedItem and CanAcquire signatures (#713) 2024-12-20 22:12:14 +10:00
Michael Wilson
6349c11d07 fix: revert base entity teleport changes, add warning to player controller (#688) 2024-11-27 21:25:12 +10:00
ZoNiCaL
b2046b21c4 [no ci] Shuffle player documentation, add to game event documentation (#685) 2024-11-25 10:48:25 +10:00
Michael Wilson
3c6be481c5 [no ci] Update publish-docs.yml 2024-11-25 10:48:05 +10:00
Michael Wilson
0a6fe0946d [no ci] Allow manual publish-docs.yml 2024-11-25 10:47:01 +10:00
schwarper
79297511e3 Added hitgroup to CTakeDamageInfo (#665)
Co-authored-by: Michael Wilson <roflmuffin@users.noreply.github.com>
2024-11-23 10:55:22 +00:00
schwarper
c6d3988902 CBaseEntity player teleport adjustment update (#661)
Co-authored-by: Michael Wilson <roflmuffin@users.noreply.github.com>
2024-11-23 10:07:12 +00:00
schwarper
8a063f4fb6 Added PluginConfigExtensions (#675) 2024-11-23 20:00:39 +10:00
Gold KingZ
6cf124bfb6 System.ArgumentException: Player with slot X not found (#667) 2024-11-13 08:08:47 +00:00
13 changed files with 141 additions and 17 deletions

View File

@@ -2,6 +2,7 @@ on:
push:
branches:
- main
workflow_dispatch:
permissions:
contents: read

2
.gitmodules vendored
View File

@@ -1,6 +1,6 @@
[submodule "libraries/hl2sdk-cs2"]
path = libraries/hl2sdk-cs2
url = https://github.com/alliedmodders/hl2sdk
url = https://github.com/roflmuffin/hl2sdk
branch = cs2
[submodule "libraries/metamod-source"]
path = libraries/metamod-source

View File

@@ -57,7 +57,7 @@
"signatures": {
"library": "server",
"windows": "48 89 5C 24 ? 48 89 74 24 ? 55 57 41 ? 41 ? 41 ? 48 ? ? ? ? 48 ? ? ? ? ? ? 4D ? ? 48",
"linux": "55 48 89 E5 41 57 41 56 49 89 D6 41 55 49 89 CD 41 54 49 89 F4 53 48 89 FB 48 8D 3D"
"linux": "55 48 89 E5 41 57 41 56 4D 89 C6 41 55 49 89 D5 41 54 49 89 F4"
}
},
"UTIL_Remove": {
@@ -91,7 +91,7 @@
"CCSPlayer_ItemServices_CanAcquire": {
"signatures": {
"library": "server",
"windows": "48 8B C4 44 89 40 ? 48 89 50 ? 48 89 48",
"windows": "44 89 44 24 ? 48 89 54 24 ? 48 89 4C 24 ? 55 56 57 41 54 41 55 41 56 41 57 48 8B EC",
"linux": "55 48 89 E5 41 57 41 56 41 55 49 89 CD 41 54 53 48 83 EC"
}
},

View File

@@ -54,6 +54,9 @@ The specific subclass of `GameEvent` will provide strongly typed parameters from
These event properties are mutable so you can update them as normal and they will update in the event instance.
> [!CAUTION]
> `GameEvent` instances and their properties will cease to exist after the event listener function is called, which means that you will encounter errors when accessing properties in timers and functions like `Server.NextFrame()`. You should store the value of properties in variables before calling functions like `Server.NextFrame()` so you can read the data safely.
## Preventing Broadcast
You can modify a game event so that it does not get broadcast to clients by modifying the `bool info.DontBroadcast` property. e.g.

View File

@@ -6,3 +6,6 @@
- name: Dependency Injection
href: dependency-injection.md
- name: Referencing Players
href: referencing-players.md

View File

@@ -1,5 +1,2 @@
- name: Core Configuration
href: core-configuration.md
- name: Referencing Players
href: referencing-players.md
href: core-configuration.md

View File

@@ -12,15 +12,17 @@ public partial class CBaseEntity
public void Teleport(Vector? position = null, QAngle? angles = null, Vector? velocity = null)
{
Guard.IsValidEntity(this);
if (position == null && angles == null && velocity == null)
throw new ArgumentNullException("No valid argument");
nint _position = position?.Handle ?? 0;
nint _angles = angles?.Handle ?? 0;
nint _velocity = velocity?.Handle ?? 0;
VirtualFunction.CreateVoid<IntPtr, IntPtr, IntPtr, IntPtr>(Handle, GameData.GetOffset("CBaseEntity_Teleport"))(Handle, _position, _angles, _velocity);
nint _handle = Handle;
VirtualFunction.CreateVoid<IntPtr, IntPtr, IntPtr, IntPtr>(_handle, GameData.GetOffset("CBaseEntity_Teleport"))(_handle, _position,
_angles, _velocity);
}
/// <exception cref="InvalidOperationException">Entity is not valid</exception>

View File

@@ -340,4 +340,11 @@ public partial class CCSPlayerController
NativeAPI.SetClientVoiceFlags(Handle, (Byte)value);
}
}
[Obsolete(
"You are trying to call Teleport on a non-physical player. Maybe you mean Pawn? (See: https://docs.cssharp.dev/docs/guides/referencing-players.html#controllers--pawns)")]
public new void Teleport(Vector? position = null, QAngle? angles = null, Vector? velocity = null)
{
base.Teleport(position, angles, velocity);
}
}

View File

@@ -0,0 +1,32 @@
using System.Runtime.InteropServices;
namespace CounterStrikeSharp.API.Core;
public partial class CTakeDamageInfo
{
/// <summary>
/// Retrieves the hitgroup
/// </summary>
/// <returns>
/// Returns a <see cref="HitGroup_t"/> enumeration representing the player's current hit group,
/// or <see cref="HitGroup_t.HITGROUP_INVALID"/> if the hit group cannot be determined.
/// </returns>
public HitGroup_t GetHitGroup()
{
IntPtr v4 = Marshal.ReadIntPtr(Handle, 0x78);
if (v4 == nint.Zero)
{
return HitGroup_t.HITGROUP_INVALID;
}
IntPtr v1 = Marshal.ReadIntPtr(v4, 16);
if (v1 == nint.Zero)
{
return HitGroup_t.HITGROUP_GENERIC;
}
return (HitGroup_t)Marshal.ReadInt32(v1, 56);
}
}

View File

@@ -0,0 +1,81 @@
using System.Text.Json;
using System.Reflection;
namespace CounterStrikeSharp.API.Modules.Extensions;
public static class PluginConfigExtensions
{
private static readonly JsonSerializerOptions _jsonSerializerOptions = new()
{
WriteIndented = true
};
public static JsonSerializerOptions JsonSerializerOptions => _jsonSerializerOptions;
/// <summary>
/// Gets the configuration file path
/// </summary>
/// <typeparam name="T">Type of the plugin configuration.</typeparam>
/// <param name="_">Current configuration instance</param>
public static string GetConfigPath<T>(this T _) where T : BasePluginConfig, new()
{
string assemblyName = typeof(T).Assembly.GetName().Name ?? string.Empty;
return Path.Combine(Server.GameDirectory, "csgo", "addons", "counterstrikesharp", "configs", "plugins", assemblyName, $"{assemblyName}.json");
}
/// <summary>
/// Updates the configuration file
/// </summary>
/// <typeparam name="T">Type of the plugin configuration.</typeparam>
/// <param name="config">Current configuration instance</param>
public static void Update<T>(this T config) where T : BasePluginConfig, new()
{
var configPath = config.GetConfigPath();
try
{
using var stream = new FileStream(configPath, FileMode.Create, FileAccess.Write, FileShare.None);
using var writer = new StreamWriter(stream);
writer.Write(JsonSerializer.Serialize(config, JsonSerializerOptions));
}
catch (Exception ex)
{
throw new Exception($"Failed to update configuration file at '{configPath}'.", ex);
}
}
/// <summary>
/// Reloads the configuration file and updates current configuration instance.
/// </summary>
/// <typeparam name="T">Type of the plugin configuration.</typeparam>
/// <param name="config">Current configuration instance</param>
public static void Reload<T>(this T config) where T : BasePluginConfig, new()
{
var configPath = config.GetConfigPath();
try
{
if (!File.Exists(configPath))
{
throw new FileNotFoundException($"Configuration file '{configPath} not found.");
}
var configContent = File.ReadAllText(configPath);
var newConfig = JsonSerializer.Deserialize<T>(configContent)
?? throw new JsonException($"Deserialization failed for configuration file '{configPath}'.");
foreach (var property in typeof(T).GetProperties(BindingFlags.Instance | BindingFlags.Public))
{
if (property.CanWrite)
{
property.SetValue(config, property.GetValue(newConfig));
}
}
}
catch (Exception ex)
{
throw new Exception($"Failed to reload configuration file at '{configPath}'.", ex);
}
}
}

View File

@@ -101,13 +101,11 @@ public class RecipientFilter : IList<CCSPlayerController>, IMarshalToNative
public void Add(int slot)
{
var player = Utilities.GetPlayerFromSlot(slot);
if (player == null)
if (player != null)
{
throw new ArgumentException($"Player with slot {slot} not found");
_recipients.Add(player);
CollectionChanged?.Invoke();
}
_recipients.Add(player);
CollectionChanged?.Invoke();
}
public void AddAllPlayers()