Skip to content
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

Implementing EntityKeyValues #615

Open
wants to merge 43 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
d9ad31c
feat: `CBaseEntity_DispatchSpawn` in unmanaged
KillStr3aK Oct 6, 2024
34a4b4b
feat: entity keyvalues unmanaged implementation
KillStr3aK Oct 6, 2024
787809b
feat: entity keyvalues managed implementation
KillStr3aK Oct 6, 2024
4b10307
feat: overload `DispatchSpawn`
KillStr3aK Oct 6, 2024
10768f6
chore: adjusted codestyle
KillStr3aK Oct 6, 2024
ffc0320
chore: adjusted codestyle and cleanup
KillStr3aK Oct 6, 2024
7ed06c4
feat: inherit from dictionary to use indexing, adjustments
KillStr3aK Oct 6, 2024
a279da3
chore: edit summary
KillStr3aK Oct 6, 2024
548c76d
fix: reimplement getter/setter natives and fully expose `CEntityKeyVa…
KillStr3aK Oct 8, 2024
e1225ba
chore: FIX GETTER REGION
KillStr3aK Oct 8, 2024
71de499
feat: default implementations for `Vector2D`, `Vector4D`, `Quaternion…
KillStr3aK Oct 8, 2024
62089d2
tweak: adjust changes
KillStr3aK Oct 8, 2024
4c09221
fix: adjusted natives
KillStr3aK Oct 8, 2024
321782f
feat: overload `SetVector`
KillStr3aK Oct 8, 2024
84fe54c
feat: overloaded `ToString` method
KillStr3aK Oct 8, 2024
1fb3803
tweak: replaced with `CUtlStringToken`
KillStr3aK Oct 8, 2024
78e1bf2
fix: Added `Color` to `ScriptContext.GetResult`
KillStr3aK Oct 8, 2024
f064354
fix: these should return a pointer instead
KillStr3aK Oct 8, 2024
c42319c
fix: *GetInt64
KillStr3aK Oct 8, 2024
13fb3af
feat: `CEntityKeyValues`.`HasValue`
KillStr3aK Oct 8, 2024
aa1dc6b
feat: indexing operator
KillStr3aK Oct 8, 2024
a9085b7
fix: wrong types
KillStr3aK Oct 8, 2024
8261147
fix: indentation
KillStr3aK Oct 8, 2024
9d03cea
fix: now works with CEntityHandle
KillStr3aK Oct 8, 2024
79cdd92
chore: added text
KillStr3aK Oct 8, 2024
76d48c1
fix: matrix3x4_t being passed correctly
KillStr3aK Oct 8, 2024
8b5dc87
feat: properties for accessing values
KillStr3aK Oct 8, 2024
b684fef
tweak: adjusted matrix3x4_t changes
KillStr3aK Oct 8, 2024
7d346df
fix: changed from `CUtlStringToken` to `uint`
KillStr3aK Oct 8, 2024
d9fcb7e
Merge branch 'main' into feature/entitykeyvalues
KillStr3aK Oct 11, 2024
6812f62
Merge branch 'main' into feature/entitykeyvalues
KillStr3aK Oct 13, 2024
817a158
Merge branch 'main' into feature/entitykeyvalues
KillStr3aK Oct 17, 2024
d81c8f0
Merge branch 'main' into feature/entitykeyvalues
KillStr3aK Oct 17, 2024
eb52035
Merge branch 'main' into feature/entitykeyvalues
KillStr3aK Oct 19, 2024
7a83255
Merge branch 'main' into feature/entitykeyvalues
KillStr3aK Oct 21, 2024
d3209cb
Merge branch 'main' into feature/entitykeyvalues
KillStr3aK Nov 6, 2024
0697b7c
Merge branch 'main' into feature/entitykeyvalues
KillStr3aK Nov 13, 2024
e210a27
Merge branch 'main' into feature/entitykeyvalues
KillStr3aK Nov 26, 2024
b517713
Merge branch 'main' into feature/entitykeyvalues
KillStr3aK Dec 3, 2024
59dffad
Merge branch 'main' into feature/entitykeyvalues
KillStr3aK Jan 5, 2025
58f1f4c
Merge branch 'main' into feature/entitykeyvalues
KillStr3aK Jan 16, 2025
51020e4
Merge branch 'main' into feature/entitykeyvalues
KillStr3aK Jan 24, 2025
2dda73a
Merge branch 'main' into feature/entitykeyvalues
KillStr3aK Jan 27, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 102 additions & 0 deletions managed/CounterStrikeSharp.API/Core/API.cs
Original file line number Diff line number Diff line change
Expand Up @@ -780,6 +780,68 @@ public static void AddEntityIoEvent(IntPtr ptarget, string inputname, IntPtr act
}
}

public static void DispatchSpawn(IntPtr entity, IntPtr keyvalues){
lock (ScriptContext.GlobalScriptContext.Lock) {
ScriptContext.GlobalScriptContext.Reset();
ScriptContext.GlobalScriptContext.Push(entity);
ScriptContext.GlobalScriptContext.Push(keyvalues);
ScriptContext.GlobalScriptContext.SetIdentifier(0xAE01E931);
ScriptContext.GlobalScriptContext.Invoke();
ScriptContext.GlobalScriptContext.CheckErrors();
}
}

public static IntPtr EntityKeyValuesNew(){
lock (ScriptContext.GlobalScriptContext.Lock) {
ScriptContext.GlobalScriptContext.Reset();
ScriptContext.GlobalScriptContext.SetIdentifier(0x445FE212);
ScriptContext.GlobalScriptContext.Invoke();
ScriptContext.GlobalScriptContext.CheckErrors();
return (IntPtr)ScriptContext.GlobalScriptContext.GetResult(typeof(IntPtr));
}
}

public static T EntityKeyValuesGetValue<T>(IntPtr keyvalues, string key, uint type){
lock (ScriptContext.GlobalScriptContext.Lock) {
ScriptContext.GlobalScriptContext.Reset();
ScriptContext.GlobalScriptContext.Push(keyvalues);
ScriptContext.GlobalScriptContext.Push(key);
ScriptContext.GlobalScriptContext.Push(type);
ScriptContext.GlobalScriptContext.SetIdentifier(0xA9A569AC);
ScriptContext.GlobalScriptContext.Invoke();
ScriptContext.GlobalScriptContext.CheckErrors();
return (T)ScriptContext.GlobalScriptContext.GetResult(typeof(T));
}
}

public static void EntityKeyValuesSetValue(IntPtr keyvalues, string key, uint type, object[] arguments){
lock (ScriptContext.GlobalScriptContext.Lock) {
ScriptContext.GlobalScriptContext.Reset();
ScriptContext.GlobalScriptContext.Push(keyvalues);
ScriptContext.GlobalScriptContext.Push(key);
ScriptContext.GlobalScriptContext.Push(type);
foreach (var obj in arguments)
{
ScriptContext.GlobalScriptContext.Push(obj);
}
ScriptContext.GlobalScriptContext.SetIdentifier(0x60234AB8);
ScriptContext.GlobalScriptContext.Invoke();
ScriptContext.GlobalScriptContext.CheckErrors();
}
}

public static bool EntityKeyValuesHasValue(IntPtr keyvalues, string key){
lock (ScriptContext.GlobalScriptContext.Lock) {
ScriptContext.GlobalScriptContext.Reset();
ScriptContext.GlobalScriptContext.Push(keyvalues);
ScriptContext.GlobalScriptContext.Push(key);
ScriptContext.GlobalScriptContext.SetIdentifier(0xD3E04DA0);
ScriptContext.GlobalScriptContext.Invoke();
ScriptContext.GlobalScriptContext.CheckErrors();
return (bool)ScriptContext.GlobalScriptContext.GetResult(typeof(bool));
}
}

public static void HookEvent(string name, InputArgument callback, bool ispost){
lock (ScriptContext.GlobalScriptContext.Lock) {
ScriptContext.GlobalScriptContext.Reset();
Expand Down Expand Up @@ -1657,6 +1719,46 @@ public static IntPtr VectorNew(){
}
}

public static IntPtr Vector2dNew(){
lock (ScriptContext.GlobalScriptContext.Lock) {
ScriptContext.GlobalScriptContext.Reset();
ScriptContext.GlobalScriptContext.SetIdentifier(0x2CD71169);
ScriptContext.GlobalScriptContext.Invoke();
ScriptContext.GlobalScriptContext.CheckErrors();
return (IntPtr)ScriptContext.GlobalScriptContext.GetResult(typeof(IntPtr));
}
}

public static IntPtr Vector4dNew(){
lock (ScriptContext.GlobalScriptContext.Lock) {
ScriptContext.GlobalScriptContext.Reset();
ScriptContext.GlobalScriptContext.SetIdentifier(0x16585EAF);
ScriptContext.GlobalScriptContext.Invoke();
ScriptContext.GlobalScriptContext.CheckErrors();
return (IntPtr)ScriptContext.GlobalScriptContext.GetResult(typeof(IntPtr));
}
}

public static IntPtr Matrix3x4New(){
lock (ScriptContext.GlobalScriptContext.Lock) {
ScriptContext.GlobalScriptContext.Reset();
ScriptContext.GlobalScriptContext.SetIdentifier(0xA2E1A42);
ScriptContext.GlobalScriptContext.Invoke();
ScriptContext.GlobalScriptContext.CheckErrors();
return (IntPtr)ScriptContext.GlobalScriptContext.GetResult(typeof(IntPtr));
}
}

public static IntPtr QuaternionNew(){
lock (ScriptContext.GlobalScriptContext.Lock) {
ScriptContext.GlobalScriptContext.Reset();
ScriptContext.GlobalScriptContext.SetIdentifier(0xD27D7946);
ScriptContext.GlobalScriptContext.Invoke();
ScriptContext.GlobalScriptContext.CheckErrors();
return (IntPtr)ScriptContext.GlobalScriptContext.GetResult(typeof(IntPtr));
}
}

public static IntPtr AngleNew(){
lock (ScriptContext.GlobalScriptContext.Lock) {
ScriptContext.GlobalScriptContext.Reset();
Expand Down
14 changes: 10 additions & 4 deletions managed/CounterStrikeSharp.API/Core/Model/CBaseEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,17 @@ public void Teleport(Vector? position = null, QAngle? angles = null, Vector? vel
}

/// <exception cref="InvalidOperationException">Entity is not valid</exception>
public void DispatchSpawn()
public void DispatchSpawn(CEntityKeyValues? keyValues = null)
{
Guard.IsValidEntity(this);

VirtualFunctions.CBaseEntity_DispatchSpawn(Handle, IntPtr.Zero);
Guard.IsValidEntity(this);

if (keyValues != null)
{
NativeAPI.DispatchSpawn(Handle, keyValues.Handle);
} else
{
VirtualFunctions.CBaseEntity_DispatchSpawn(Handle, IntPtr.Zero);
}
}

/// <summary>
Expand Down
15 changes: 14 additions & 1 deletion managed/CounterStrikeSharp.API/Core/ScriptContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
* under GNU Lesser General Public License, version 2.
*/

using System;
using System.Collections.Concurrent;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Security;
using System.Text;
Expand Down Expand Up @@ -449,6 +449,19 @@ internal unsafe object GetResult(Type type, byte* ptr)
return Activator.CreateInstance(type, pointer);
}

if (type == typeof(Color))
{
var pointer = (IntPtr)GetResult(typeof(IntPtr), ptr);
return Marshaling.ColorMarshaler.NativeToManaged(pointer);
}
Comment on lines +452 to +456
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one should be there since the beginning I believe haha


// this one only works if the 'Raw'/uint is passed, otherwise big bum
// maybe do this with a marshaler?!
if (type == typeof(CEntityHandle))
{
return new CEntityHandle((uint)GetResult(typeof(uint), ptr));
}
Comment on lines +460 to +463
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hope this one fits?


if (type == typeof(object))
{
// var dataPtr = *(IntPtr*)&ptr[0];
Expand Down
Loading
Loading