roflmuffin / CounterStrikeSharp

CounterStrikeSharp allows you to write server plugins in C# for Counter-Strike 2/Source2/CS2
https://docs.cssharp.dev
Other
756 stars 113 forks source link

Using CEntityInstance Is there an error with AcceptInput? I don't know how to solve the error #366

Closed Nianmou closed 6 months ago

Nianmou commented 6 months ago

`Fatal error. System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt. Repeat 2 times:

at CounterStrikeSharp.API.Core.Helpers.InvokeNative(IntPtr)

at CounterStrikeSharp.API.Core.ScriptContext.InvokeNativeInternal() at CounterStrikeSharp.API.Core.ScriptContext.Invoke() at CounterStrikeSharp.API.Core.NativeAPI.ExecuteVirtualFunction[[System.Canon, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]](IntPtr, System.Object[]) at CounterStrikeSharp.API.Modules.Memory.DynamicFunctions.BaseMemoryFunction.InvokeInternalVoid(System.Object[]) at CounterStrikeSharp.API.Modules.Memory.DynamicFunctions.MemoryFunctionVoid`6[[System.IntPtr, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.Canon, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.IntPtr, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.IntPtr, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.Canon, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.Int32, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].Invoke(IntPtr, System.Canon, IntPtr, IntPtr, System.__Canon, Int32) at CounterStrikeSharp.API.Core.CEntityInstance.AcceptInput(System.String, CounterStrikeSharp.API.Core.CEntityInstance, CounterStrikeSharp.API.Core.CEntityInstance, System.String, Int32)`

code: ` public static void ScheduleCTPositions(Vector position, QAngle angle) {

        var ctSpawns = Utilities.FindAllEntitiesByDesignerName<CBaseEntity>("info_player_terrorist");
        foreach (var entity in ctSpawns)
        {
            if (entity.IsValid)
            {
                entity.AcceptInput("SetDisabled");
            }
        }
        var NewEntity = Utilities.CreateEntityByName<CInfoPlayerTerrorist>("info_player_terrorist");
        NewEntity.Teleport(position, angle, new Vector(0, 0, 0));
        NewEntity.DispatchSpawn();

    }`
Nianmou commented 6 months ago

I don't know what caused the error, I just want to modify the birth point of the camp

Nianmou commented 6 months ago

Do I need to use hook to make this function execute at the beginning of each round?