0
0
mirror of https://github.com/sp-tarkov/modules.git synced 2025-02-13 03:30:44 -05:00

Delayed spawning BTR bot to GameWorld.OnGameStarted (!69)

Honestly this is just a shot in the dark hotfix. I've tested it and these changes still work fine for me.

Let me know if this fixes the BTR not working, Chomp

Reviewed-on: SPT-AKI/Modules#69
Co-authored-by: Arys <arys@noreply.dev.sp-tarkov.com>
Co-committed-by: Arys <arys@noreply.dev.sp-tarkov.com>
This commit is contained in:
Arys 2024-01-27 09:05:33 +00:00 committed by chomp
parent a124ace054
commit a48e40b481
5 changed files with 85 additions and 47 deletions

View File

@ -61,9 +61,10 @@ namespace Aki.Custom
new BTRTurretDefaultAimingPositionPatch().Enable();
new BTRIsDoorsClosedPath().Enable();
new BTRPatch().Enable();
new BTRSpawnBotAtRaidStartPatch().Enable();
new BTRTransferItemsPatch().Enable();
new BTREndRaidItemDeliveryPatch().Enable();
new BTRBaseLocalGameStopPatch().Enable();
new BTRDestroyAtRaidEndPatch().Enable();
}
catch (Exception ex)
{

View File

@ -161,7 +161,6 @@ namespace Aki.Custom.BTR
var botsController = Singleton<IBotGame>.Instance.BotsController;
btrBotService = botsController.BotTradersServices.BTRServices;
btrController.method_3(); // spawns server-side BTR game object
botsController.BotSpawner.SpawnBotBTR(); // spawns the scav bot which controls the BTR's turret
// Initial BTR configuration
btrServerSide = btrController.BtrVehicle;

View File

@ -25,20 +25,24 @@ namespace Aki.Custom.BTR.Patches
return AccessTools.Method(typeof(BTRTurretView), nameof(BTRTurretView.method_1));
}
[PatchPostfix]
private static void PatchPostfix(BTRTurretView __instance, int btrBotId, ref bool __result)
[PatchPrefix]
private static bool PatchPrefix(BTRTurretView __instance, int btrBotId, ref bool __result)
{
var gameWorld = Singleton<GameWorld>.Instance;
if (gameWorld == null)
{
Logger.LogError("[AKI-BTR] BTRBotInitPatch - GameWorld is null");
return;
__result = false;
return false;
}
var alivePlayersList = gameWorld.AllAlivePlayersList;
bool doesBtrBotExist = alivePlayersList.Exists(x => x.Id == btrBotId);
if (doesBtrBotExist)
if (!doesBtrBotExist)
{
__result = false;
return false;
}
try
{
Player player = alivePlayersList.First(x => x.Id == btrBotId);
@ -76,6 +80,7 @@ namespace Aki.Custom.BTR.Patches
btrTurretViewTupleField.SetValue(__instance, tuple);
__result = true;
return false;
}
catch
{
@ -84,5 +89,4 @@ namespace Aki.Custom.BTR.Patches
}
}
}
}
}

View File

@ -7,7 +7,7 @@ using Object = UnityEngine.Object;
namespace Aki.Custom.BTR.Patches
{
public class BTRBaseLocalGameStopPatch : ModulePatch
public class BTRDestroyAtRaidEndPatch : ModulePatch
{
protected override MethodBase GetTargetMethod()
{
@ -26,7 +26,7 @@ namespace Aki.Custom.BTR.Patches
var btrManager = gameWorld.GetComponent<BTRManager>();
if (btrManager != null)
{
Logger.LogWarning("[AKI-BTR] BTRBaseLocalGameStopPatch - Raid Ended: Destroying BTRManager");
Logger.LogWarning("[AKI-BTR] BTRDestroyAtRaidEndPatch - Raid Ended: Destroying BTRManager");
Object.Destroy(btrManager);
}
}

View File

@ -0,0 +1,34 @@
using Aki.Reflection.Patching;
using Comfort.Common;
using EFT;
using HarmonyLib;
using System.Reflection;
namespace Aki.Custom.BTR.Patches
{
public class BTRSpawnBotAtRaidStartPatch : ModulePatch
{
protected override MethodBase GetTargetMethod()
{
return AccessTools.Method(typeof(GameWorld), nameof(GameWorld.OnGameStarted));
}
[PatchPostfix]
private static void PatchPostfix(GameWorld __instance)
{
var btrManager = __instance.GetComponent<BTRManager>();
if (btrManager == null)
{
return;
}
var botGame = Singleton<IBotGame>.Instance;
if (botGame == null)
{
return;
}
botGame.BotsController.BotSpawner.SpawnBotBTR();
}
}
}