-
-
Notifications
You must be signed in to change notification settings - Fork 126
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implemented entity transmit feature #608
base: main
Are you sure you want to change the base?
Conversation
# Visual Studio Version 17 | ||
VisualStudioVersion = 17.12.35309.182 | ||
MinimumVisualStudioVersion = 10.0.40219.1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure about these, probably was autogenerated when saving
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {069C4CD4-BACA-446A-A6B8-0194E4F75355} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure about these, probably was autogenerated when saving
managed/CounterStrikeSharp.API/Core/Model/CCheckTransmitInfo.cs
Outdated
Show resolved
Hide resolved
Overall the PR looks great!😍 I am wondering though if we can possibly improve the DX of iterating over the transmit list. Maybe something like this (pseudo-ish code)? RegisterListener<Listeners.CheckTransmit>((CCheckTransmitInfoList infoList, int infoCount) =>
{
// Get the list of the currently available doors (prop_door_rotating)
IEnumerable<CPropDoorRotating> doors = Utilities.FindAllEntitiesByDesignerName<CPropDoorRotating>("prop_door_rotating");
// Do nothing if there is none.
if (!doors.Any())
return;
foreach(var (CFixedBitVecBase transmitEntities, CCSPlayerController? player) in infoList)
{
if (player == null || !ShouldSeeDoors.ContainsKey(player.Slot))
continue;
foreach (CPropDoorRotating door in doors)
{
transmitEntities.Remove(door);
}
}
}); The idea being that if we can provide access to an Example enumerator implementation on public sealed class CCheckTransmitInfoList : NativeObject,
IReadOnlyList<(CFixedBitVecBase TransmitEntities, CCSPlayerController? Player)>
{
private int CheckTransmitPlayerSlotOffset = GameData.GetOffset("CheckTransmitPlayerSlot");
private unsafe nint* Inner => (nint*)base.Handle;
public unsafe CCheckTransmitInfoList(IntPtr pointer) : base(pointer)
{
}
public int Count { get; }
private unsafe (CCheckTransmitInfo, int) Get(int index)
{
return (Marshal.PtrToStructure<CCheckTransmitInfo>(this.Inner[index]),
(int)(*(byte*)(this.Inner[index] + CheckTransmitPlayerSlotOffset)));
}
public IEnumerator<(CFixedBitVecBase TransmitEntities, CCSPlayerController? Player)> GetEnumerator()
{
for (int i = 0; i < this.Count; i++)
{
yield return this[i];
}
}
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
/// <summary>
/// Get transmit info for the given index.
/// </summary>
/// <param name="index">Index of the info you want to retrieve from the list, should be between 0 and 'infoCount' - 1</param>
/// <returns></returns>
public (CFixedBitVecBase TransmitEntities, CCSPlayerController? Player) this[int index]
{
get
{
// Ideally throw here if out of range
var (transmit, slot) = this.Get(index);
CCSPlayerController? player = Utilities.GetPlayerFromSlot(slot);
return (transmit.TransmitEntities, player);
}
}
} |
Great idea! Will take a look on it |
With this implementation, developers are able to control the entity transmit per player
Examples
These are simple examples, but it can be used for way more complex things.