mirror of
https://github.com/sp-tarkov/modules.git
synced 2025-02-13 03:10:45 -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:
parent
a124ace054
commit
a48e40b481
@ -61,9 +61,10 @@ namespace Aki.Custom
|
|||||||
new BTRTurretDefaultAimingPositionPatch().Enable();
|
new BTRTurretDefaultAimingPositionPatch().Enable();
|
||||||
new BTRIsDoorsClosedPath().Enable();
|
new BTRIsDoorsClosedPath().Enable();
|
||||||
new BTRPatch().Enable();
|
new BTRPatch().Enable();
|
||||||
|
new BTRSpawnBotAtRaidStartPatch().Enable();
|
||||||
new BTRTransferItemsPatch().Enable();
|
new BTRTransferItemsPatch().Enable();
|
||||||
new BTREndRaidItemDeliveryPatch().Enable();
|
new BTREndRaidItemDeliveryPatch().Enable();
|
||||||
new BTRBaseLocalGameStopPatch().Enable();
|
new BTRDestroyAtRaidEndPatch().Enable();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
@ -161,7 +161,6 @@ namespace Aki.Custom.BTR
|
|||||||
var botsController = Singleton<IBotGame>.Instance.BotsController;
|
var botsController = Singleton<IBotGame>.Instance.BotsController;
|
||||||
btrBotService = botsController.BotTradersServices.BTRServices;
|
btrBotService = botsController.BotTradersServices.BTRServices;
|
||||||
btrController.method_3(); // spawns server-side BTR game object
|
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
|
// Initial BTR configuration
|
||||||
btrServerSide = btrController.BtrVehicle;
|
btrServerSide = btrController.BtrVehicle;
|
||||||
|
@ -25,63 +25,67 @@ namespace Aki.Custom.BTR.Patches
|
|||||||
return AccessTools.Method(typeof(BTRTurretView), nameof(BTRTurretView.method_1));
|
return AccessTools.Method(typeof(BTRTurretView), nameof(BTRTurretView.method_1));
|
||||||
}
|
}
|
||||||
|
|
||||||
[PatchPostfix]
|
[PatchPrefix]
|
||||||
private static void PatchPostfix(BTRTurretView __instance, int btrBotId, ref bool __result)
|
private static bool PatchPrefix(BTRTurretView __instance, int btrBotId, ref bool __result)
|
||||||
{
|
{
|
||||||
var gameWorld = Singleton<GameWorld>.Instance;
|
var gameWorld = Singleton<GameWorld>.Instance;
|
||||||
if (gameWorld == null)
|
if (gameWorld == null)
|
||||||
{
|
{
|
||||||
Logger.LogError("[AKI-BTR] BTRBotInitPatch - GameWorld is null");
|
Logger.LogError("[AKI-BTR] BTRBotInitPatch - GameWorld is null");
|
||||||
return;
|
__result = false;
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
var alivePlayersList = gameWorld.AllAlivePlayersList;
|
var alivePlayersList = gameWorld.AllAlivePlayersList;
|
||||||
bool doesBtrBotExist = alivePlayersList.Exists(x => x.Id == btrBotId);
|
bool doesBtrBotExist = alivePlayersList.Exists(x => x.Id == btrBotId);
|
||||||
if (doesBtrBotExist)
|
if (!doesBtrBotExist)
|
||||||
{
|
{
|
||||||
try
|
__result = false;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Player player = alivePlayersList.First(x => x.Id == btrBotId);
|
||||||
|
|
||||||
|
Renderer[] array = player.GetComponentsInChildren<Renderer>();
|
||||||
|
for (int i = 0; i < array.Length; i++)
|
||||||
{
|
{
|
||||||
Player player = alivePlayersList.First(x => x.Id == btrBotId);
|
array[i].enabled = false;
|
||||||
|
|
||||||
Renderer[] array = player.GetComponentsInChildren<Renderer>();
|
|
||||||
for (int i = 0; i < array.Length; i++)
|
|
||||||
{
|
|
||||||
array[i].enabled = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
var aiFirearmController = player.gameObject.GetComponent<Player.FirearmController>();
|
|
||||||
var currentWeaponPrefab = (WeaponPrefab)AccessTools.Field(aiFirearmController.GetType(), "weaponPrefab_0").GetValue(aiFirearmController);
|
|
||||||
if (currentWeaponPrefab.RemoveChildrenOf != null)
|
|
||||||
{
|
|
||||||
foreach (var text in currentWeaponPrefab.RemoveChildrenOf)
|
|
||||||
{
|
|
||||||
var transform = currentWeaponPrefab.transform.FindTransform(text);
|
|
||||||
transform.gameObject.SetActive(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
foreach (var renderer in currentWeaponPrefab.GetComponentsInChildren<Renderer>())
|
|
||||||
{
|
|
||||||
if (renderer.name == "MuzzleJetCombinedMesh")
|
|
||||||
{
|
|
||||||
renderer.transform.localPosition = new Vector3(0.18f, 0f, -0.095f);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
renderer.enabled = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var tuple = new ValueTuple<ObservedPlayerView, bool>(new ObservedPlayerView(), true);
|
|
||||||
var btrTurretViewTupleField = AccessTools.Field(__instance.GetType(), "valueTuple_0");
|
|
||||||
btrTurretViewTupleField.SetValue(__instance, tuple);
|
|
||||||
|
|
||||||
__result = true;
|
|
||||||
}
|
}
|
||||||
catch
|
|
||||||
|
var aiFirearmController = player.gameObject.GetComponent<Player.FirearmController>();
|
||||||
|
var currentWeaponPrefab = (WeaponPrefab)AccessTools.Field(aiFirearmController.GetType(), "weaponPrefab_0").GetValue(aiFirearmController);
|
||||||
|
if (currentWeaponPrefab.RemoveChildrenOf != null)
|
||||||
{
|
{
|
||||||
ConsoleScreen.LogError("[AKI-BTR] BtrBot initialization failed, BtrBot will be visible ingame. Check logs.");
|
foreach (var text in currentWeaponPrefab.RemoveChildrenOf)
|
||||||
throw;
|
{
|
||||||
|
var transform = currentWeaponPrefab.transform.FindTransform(text);
|
||||||
|
transform.gameObject.SetActive(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
foreach (var renderer in currentWeaponPrefab.GetComponentsInChildren<Renderer>())
|
||||||
|
{
|
||||||
|
if (renderer.name == "MuzzleJetCombinedMesh")
|
||||||
|
{
|
||||||
|
renderer.transform.localPosition = new Vector3(0.18f, 0f, -0.095f);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
renderer.enabled = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var tuple = new ValueTuple<ObservedPlayerView, bool>(new ObservedPlayerView(), true);
|
||||||
|
var btrTurretViewTupleField = AccessTools.Field(__instance.GetType(), "valueTuple_0");
|
||||||
|
btrTurretViewTupleField.SetValue(__instance, tuple);
|
||||||
|
|
||||||
|
__result = true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
ConsoleScreen.LogError("[AKI-BTR] BtrBot initialization failed, BtrBot will be visible ingame. Check logs.");
|
||||||
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,7 @@ using Object = UnityEngine.Object;
|
|||||||
|
|
||||||
namespace Aki.Custom.BTR.Patches
|
namespace Aki.Custom.BTR.Patches
|
||||||
{
|
{
|
||||||
public class BTRBaseLocalGameStopPatch : ModulePatch
|
public class BTRDestroyAtRaidEndPatch : ModulePatch
|
||||||
{
|
{
|
||||||
protected override MethodBase GetTargetMethod()
|
protected override MethodBase GetTargetMethod()
|
||||||
{
|
{
|
||||||
@ -26,7 +26,7 @@ namespace Aki.Custom.BTR.Patches
|
|||||||
var btrManager = gameWorld.GetComponent<BTRManager>();
|
var btrManager = gameWorld.GetComponent<BTRManager>();
|
||||||
if (btrManager != null)
|
if (btrManager != null)
|
||||||
{
|
{
|
||||||
Logger.LogWarning("[AKI-BTR] BTRBaseLocalGameStopPatch - Raid Ended: Destroying BTRManager");
|
Logger.LogWarning("[AKI-BTR] BTRDestroyAtRaidEndPatch - Raid Ended: Destroying BTRManager");
|
||||||
Object.Destroy(btrManager);
|
Object.Destroy(btrManager);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user