mirror of
https://github.com/roflmuffin/CounterStrikeSharp.git
synced 2025-12-06 08:03:12 -08:00
Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ba860a92d2 | ||
|
|
461fc0ea67 | ||
|
|
6349c11d07 | ||
|
|
b2046b21c4 | ||
|
|
3c6be481c5 | ||
|
|
0a6fe0946d | ||
|
|
79297511e3 | ||
|
|
c6d3988902 | ||
|
|
8a063f4fb6 | ||
|
|
6cf124bfb6 |
1
.github/workflows/publish-docs.yml
vendored
1
.github/workflows/publish-docs.yml
vendored
@@ -2,6 +2,7 @@ on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
workflow_dispatch:
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
2
.gitmodules
vendored
2
.gitmodules
vendored
@@ -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
|
||||
|
||||
@@ -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"
|
||||
}
|
||||
},
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -6,3 +6,6 @@
|
||||
|
||||
- name: Dependency Injection
|
||||
href: dependency-injection.md
|
||||
|
||||
- name: Referencing Players
|
||||
href: referencing-players.md
|
||||
@@ -1,5 +1,2 @@
|
||||
- name: Core Configuration
|
||||
href: core-configuration.md
|
||||
|
||||
- name: Referencing Players
|
||||
href: referencing-players.md
|
||||
href: core-configuration.md
|
||||
Submodule libraries/hl2sdk-cs2 updated: fc4b98f1a7...12c2d58783
@@ -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>
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
32
managed/CounterStrikeSharp.API/Core/Model/CTakeDamageInfo.cs
Normal file
32
managed/CounterStrikeSharp.API/Core/Model/CTakeDamageInfo.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user