lengran / OpenPrefirePrac

An open-source CounterStrikeSharp powered server-side practicing plugin for CS2. It provides multiple prefire practices on competitive maps and support multiplayer practicing simultaneously.
MIT License
86 stars 11 forks source link

[Bug] Routes fail to spawn bots after first route #13

Closed Bims-sh closed 7 months ago

Bims-sh commented 7 months ago

Tested on version: v0.1.28

After playing one route (no matter if it's finished or not), then running !prefire again and choosing another route by using !1, the route will get loaded and teleport the player to the beginning of the selected route but fails to spawn any bots at all. Using !6 to exit the route will not fix this behaviour. Screenshot and logs attached below.

Steps to reproduce:

  1. Start any route on any map
  2. Run the !prefire command again
  3. Choose another route to play

image


[Allies Chat][Bims (434807599)]: !prefire
[Allies Chat][Bims (434807599)]: !1
[Allies Chat][Bims (434807599)]: !3
[OpenPrefirePrac] Values of convars saved.
[OpenPrefirePrac] Values of convars set.
[OpenPrefirePrac] Creating 7 bots.
20:25:48 [EROR] (cssharp:Core) Error invoking callback
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
 ---> System.ArgumentException: An item with the same key has already been added. Key: CounterStrikeSharp.API.Core.CCSPlayerController
   at System.Collections.Generic.Dictionary`2.TryInsert(TKey key, TValue value, InsertionBehavior behavior)
   at System.Collections.Generic.Dictionary`2.Add(TKey key, TValue value)
   at OpenPrefirePrac.OpenPrefirePrac.AddBot(CCSPlayerController player, Int32 numberOfBots) in /home/runner/work/OpenPrefirePrac/OpenPrefirePrac/OpenPrefirePrac.cs:line 746
   at OpenPrefirePrac.OpenPrefirePrac.OnRouteSelect(CCSPlayerController player, ChatMenuOption option) in /home/runner/work/OpenPrefirePrac/OpenPrefirePrac/OpenPrefirePrac.cs:line 450
   at CounterStrikeSharp.API.Modules.Menu.BaseMenuInstance.OnKeyPress(CCSPlayerController player, Int32 key) in /home/runner/work/CounterStrikeSharp/CounterStrikeSharp/managed/CounterStrikeSharp.API/Modules/Menu/BaseMenu.cs:line 132
   at CounterStrikeSharp.API.Modules.Menu.MenuManager.OnKeyPress(CCSPlayerController player, Int32 key) in /home/runner/work/CounterStrikeSharp/CounterStrikeSharp/managed/CounterStrikeSharp.API/Modules/Menu/MenuManager.cs:line 72
   at CounterStrikeSharp.API.Core.Application.<>c.<Start>b__16_0(CCSPlayerController player, CommandInfo info) in /home/runner/work/CounterStrikeSharp/CounterStrikeSharp/managed/CounterStrikeSharp.API/Core/Application.cs:line 101
   at CounterStrikeSharp.API.Core.Commands.CommandManager.HandleCommandInternal(Int32 playerSlot, IntPtr commandInfo) in /home/runner/work/CounterStrikeSharp/CounterStrikeSharp/managed/CounterStrikeSharp.API/Core/Commands/CommandManager.cs:line 159
   at InvokeStub_Action`2.Invoke(Object, Span`1)
   at System.Reflection.MethodBaseInvoker.InvokeWithFewArgs(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   --- End of inner exception stack trace ---
   at System.Reflection.MethodBaseInvoker.InvokeWithFewArgs(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.Delegate.DynamicInvokeImpl(Object[] args)
   at CounterStrikeSharp.API.Core.FunctionReference.<CreateWrappedCallback>b__18_0(fxScriptContext* context) in /home/runner/work/CounterStrikeSharp/CounterStrikeSharp/managed/CounterStrikeSharp.API/Core/FunctionReference.cs:line 100
"Bims<0><[U:1:434807599]><TERRORIST>" OnPreResetRound => CTMDBG, team 2  will switch 0 108.17
Using spawn points configuration 0xC421628D```
Bims-sh commented 7 months ago

After some more testing I noticed that this only happens on some routes, for example the ones in the logs above.

lengran commented 7 months ago

I don't see the full log but I assume this is because a previous practice which didn't get all the bot it needed and was stuck there. Many practices require more than 5 bots, so "-maxplayers_override 64" must be set in the bash command when you start a server. Could you please confirm this?

Bims-sh commented 7 months ago

I did indeed set the args on server launch, if I use a route in full mode it spawns all the bots as well.

lengran commented 7 months ago

Would you mind uploading the full log so I can have a better understanding of the problem?

Bims-sh commented 7 months ago

I'm not home right now, I can send the log later :)

lengran commented 7 months ago

Ok. Meanwhile I just come up with a method that might be able to avoid this from happening regardless of the reason behind it. I'll let you know when a test build is available.

lengran commented 7 months ago

Tested on version: v0.1.28

After playing one route (no matter if it's finished or not), then running !prefire again and choosing another route by using !1, the route will get loaded and teleport the player to the beginning of the selected route but fails to spawn any bots at all. Using !6 to exit the route will not fix this behaviour. Screenshot and logs attached below.

Steps to reproduce:

1. Start any route on any map

2. Run the `!prefire` command again

3. Choose another route to play

image

[Allies Chat][Bims (434807599)]: !prefire
[Allies Chat][Bims (434807599)]: !1
[Allies Chat][Bims (434807599)]: !3
[OpenPrefirePrac] Values of convars saved.
[OpenPrefirePrac] Values of convars set.
[OpenPrefirePrac] Creating 7 bots.
20:25:48 [EROR] (cssharp:Core) Error invoking callback
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
 ---> System.ArgumentException: An item with the same key has already been added. Key: CounterStrikeSharp.API.Core.CCSPlayerController
   at System.Collections.Generic.Dictionary`2.TryInsert(TKey key, TValue value, InsertionBehavior behavior)
   at System.Collections.Generic.Dictionary`2.Add(TKey key, TValue value)
   at OpenPrefirePrac.OpenPrefirePrac.AddBot(CCSPlayerController player, Int32 numberOfBots) in /home/runner/work/OpenPrefirePrac/OpenPrefirePrac/OpenPrefirePrac.cs:line 746
   at OpenPrefirePrac.OpenPrefirePrac.OnRouteSelect(CCSPlayerController player, ChatMenuOption option) in /home/runner/work/OpenPrefirePrac/OpenPrefirePrac/OpenPrefirePrac.cs:line 450
   at CounterStrikeSharp.API.Modules.Menu.BaseMenuInstance.OnKeyPress(CCSPlayerController player, Int32 key) in /home/runner/work/CounterStrikeSharp/CounterStrikeSharp/managed/CounterStrikeSharp.API/Modules/Menu/BaseMenu.cs:line 132
   at CounterStrikeSharp.API.Modules.Menu.MenuManager.OnKeyPress(CCSPlayerController player, Int32 key) in /home/runner/work/CounterStrikeSharp/CounterStrikeSharp/managed/CounterStrikeSharp.API/Modules/Menu/MenuManager.cs:line 72
   at CounterStrikeSharp.API.Core.Application.<>c.<Start>b__16_0(CCSPlayerController player, CommandInfo info) in /home/runner/work/CounterStrikeSharp/CounterStrikeSharp/managed/CounterStrikeSharp.API/Core/Application.cs:line 101
   at CounterStrikeSharp.API.Core.Commands.CommandManager.HandleCommandInternal(Int32 playerSlot, IntPtr commandInfo) in /home/runner/work/CounterStrikeSharp/CounterStrikeSharp/managed/CounterStrikeSharp.API/Core/Commands/CommandManager.cs:line 159
   at InvokeStub_Action`2.Invoke(Object, Span`1)
   at System.Reflection.MethodBaseInvoker.InvokeWithFewArgs(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   --- End of inner exception stack trace ---
   at System.Reflection.MethodBaseInvoker.InvokeWithFewArgs(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.Delegate.DynamicInvokeImpl(Object[] args)
   at CounterStrikeSharp.API.Core.FunctionReference.<CreateWrappedCallback>b__18_0(fxScriptContext* context) in /home/runner/work/CounterStrikeSharp/CounterStrikeSharp/managed/CounterStrikeSharp.API/Core/FunctionReference.cs:line 100
"Bims<0><[U:1:434807599]><TERRORIST>" OnPreResetRound => CTMDBG, team 2  will switch 0 108.17
Using spawn points configuration 0xC421628D```

I just made a patch. You can download it from here. This might solve the crash issue. If it works, could you please confirm that you have 7 bots added in the practice you used as an example?

Bims-sh commented 7 months ago

Here is the log.txt.

The new version works fine now, haven't encountered any issues anymore.

Bims-sh commented 7 months ago

Oh also, I noticed a few lines going through the ground on route 1 Ancient. image image

lengran commented 7 months ago

Here is the log.txt.

The new version works fine now, haven't encountered any issues anymore.

Could you post your start-server bash command here (don't forget to censor your GSLT)? The log suggests that you are not using the recommended args from README.md. So all these problems could be from a misconfigured command line argument.

Bims-sh commented 7 months ago

Here, this should theoretically work no?

./cs2 -dedicated -ip 0.0.0.0 -port 27015 -console -usercon -maxplayers 64 +game_type 0 +game_mode 1 +mapgroup mg_active +map de_mirage +sv_setsteamaccount XXXXX +sv_lan 0 +game_alias competitive -maxplayers_override 64
lengran commented 7 months ago

Here, this should theoretically work no?

./cs2 -dedicated -ip 0.0.0.0 -port 27015 -console -usercon -maxplayers 64 +game_type 0 +game_mode 1 +mapgroup mg_active +map de_mirage +sv_setsteamaccount XXXXX +sv_lan 0 +game_alias competitive -maxplayers_override 64

According to my knowledge, you should always use "-maxplayers_override" and remove "-maxplayers". The latter one only sets number of slots in the server while the first one breaks the limit on number of players in each team as well. And if you have "+game_alias" specified, "+game_type" and "+game_mode" will not be needed. There are other args such as "+map_group" that are necessary for CSGO dedicated servers but not needed by CS2. You can check the official wiki to see details.