Skip to content

Conversation

KillStr3aK
Copy link
Contributor

Mostly based on #440 by @Yarukon

Implemented CEntityKeyValues, can be used like:

CDynamicProp? prop = Utilities.CreateEntityByName<CDynamicProp>("prop_dynamic");

if (prop != null)
{
    CEntityKeyValues keyValues = new CEntityKeyValues();

    keyValues.SetBool("my_bool", true);
    keyValues.SetEHandle("player_handle", player.EntityHandle);
    keyValues.SetVector("vector", new Vector(15.0f, 250.0f, 300.0f));
        
    prop.DispatchSpawn(keyValues);
}

This is also possible:

CDynamicProp? prop = Utilities.CreateEntityByName<CDynamicProp>("prop_dynamic");

if (prop != null)
{
    CEntityKeyValues keyValues = new CEntityKeyValues();

    keyValues["my_bool", KeyValuesType.TYPE_BOOL] = true;
        
    prop.DispatchSpawn(keyValues);
}

Also implemented some of the math related classes minimally, however: we need #613 in order to prevent memory leaks related to them. (changes needed later on if this one gets merged earlier, or I can make the adjustments on this if 613 is merged.)

Comment on lines +452 to +456
if (type == typeof(Color))
{
var pointer = (IntPtr)GetResult(typeof(IntPtr), ptr);
return Marshaling.ColorMarshaler.NativeToManaged(pointer);
}
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

Comment on lines +460 to +463
if (type == typeof(CEntityHandle))
{
return new CEntityHandle((uint)GetResult(typeof(uint), ptr));
}
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?


case counterstrikesharp::TYPE_COLOR:
{
script_context.SetResult(new Color(keyValues->GetColor(key)));
Copy link
Contributor Author

@KillStr3aK KillStr3aK Oct 8, 2024

Choose a reason for hiding this comment

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

This one sadly leaks even if #613 is merged, however could be fixed by using the MemAlloc from #613 to release the ptr either in the ScriptContext or in the ColorMarshaler once the values are converted

Comment on lines +506 to +536
script_context.SetResult(new Vector(keyValues->GetVector(key)));
break;
}

case counterstrikesharp::TYPE_VECTOR2D:
{
script_context.SetResult(new Vector2D(keyValues->GetVector2D(key)));
break;
}

case counterstrikesharp::TYPE_VECTOR4D:
{
script_context.SetResult(new Vector4D(keyValues->GetVector4D(key)));
break;
}

case counterstrikesharp::TYPE_QUATERNION:
{
script_context.SetResult(new Quaternion(keyValues->GetQuaternion(key)));
break;
}

case counterstrikesharp::TYPE_QANGLE:
{
script_context.SetResult(new QAngle(keyValues->GetQAngle(key)));
break;
}

case counterstrikesharp::TYPE_MATRIX3X4:
{
script_context.SetResult(new matrix3x4_t(keyValues->GetMatrix3x4(key)));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These should not leak with #613 because the wrapper classes will be DisposableMemory and when its no longer used on the managed side these pointers are released

Comment on lines +48 to +66
Vector2D* Vector2DNew(ScriptContext& script_context)
{
return new Vector2D();
}

Vector4D* Vector4DNew(ScriptContext& script_context)
{
return new Vector4D();
}

matrix3x4_t* Matrix3x4New(ScriptContext& script_context)
{
return new matrix3x4_t();
}

Quaternion* QuaternionNew(ScriptContext& script_context)
{
return new Quaternion();
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same as above!

@KillStr3aK KillStr3aK marked this pull request as ready for review October 8, 2024 06:02
@KillStr3aK KillStr3aK requested a review from roflmuffin as a code owner October 8, 2024 06:02
@KillStr3aK KillStr3aK changed the title [DRAFT] Implementing EntityKeyValues Implementing EntityKeyValues Oct 8, 2024

CEntityKeyValues* EntityKeyValuesNew(ScriptContext& script_context)
{
return new CEntityKeyValues();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

forgot to mention that this one is also will be released with #613

@Prefix
Copy link

Prefix commented Jan 8, 2025

Would be nice to have this released, otherwise prop_ragdoll bugs with velocity without setting pos before dispatchspawn

@oylsister
Copy link
Contributor

I have tested this specific PR on Linux and it's working fine.

@P250
Copy link

P250 commented Apr 3, 2025

Any update on this? :)

@derkalle4
Copy link

Is there any update on this? :) would love to have it merged if possible.

@MarkKuiper-Infra
Copy link

Any updates on this PR? Would be great to have this merged.

@TomaszPobierski
Copy link

Please, give any information about it @KillStr3aK

@KillStr3aK
Copy link
Contributor Author

Any update on this? :)

Is there any update on this? :) would love to have it merged if possible.

Please, give any information about it @KillStr3aK

other than the conflicts with the main branch the pr is ready, and it does not depend on #613 , but it would just bring even more leaks to the table. I did not look for a solution since that as I'm busy these days but the main implementation is here if someone finds a solution for the leak issues faster than I do

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants