Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ultimate Aki 3.8 & Native Mod Support Package #291

Merged
merged 12 commits into from
Apr 28, 2024
Binary file modified References/Assembly-CSharp.dll
Binary file not shown.
64 changes: 32 additions & 32 deletions Source/AI/BlockerErrorFixPatch.cs
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
using EFT;
using HarmonyLib;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading.Tasks;
//using EFT;
//using HarmonyLib;
//using System;
//using System.Collections.Generic;
//using System.Linq;
//using System.Reflection;
//using System.Security.Cryptography.X509Certificates;
//using System.Text;
//using System.Threading.Tasks;

namespace StayInTarkov.AI
{
/// <summary>
/// Paulov: Stay in Tarkov causes an error with the phrase BLOCKER ERROR caused by spt WildSpawnTypes
/// This patch resolves this error by adding the spt WildSpawnTypes to the ServerBotSettingsClass
/// LICENSE: This patch is only for use in Stay In Tarkov
/// </summary>
public sealed class BlockerErrorFixPatch : ModulePatch
{
protected override MethodBase GetTargetMethod()
{
return AccessTools.GetDeclaredMethods(typeof(ServerBotSettingsClass)).First(x => x.Name == nameof(ServerBotSettingsClass.Init));
}
//namespace StayInTarkov.AI
//{
// /// <summary>
// /// Paulov: Stay in Tarkov causes an error with the phrase BLOCKER ERROR caused by spt WildSpawnTypes
// /// This patch resolves this error by adding the spt WildSpawnTypes to the ServerBotSettingsClass
// /// LICENSE: This patch is only for use in Stay In Tarkov
// /// </summary>
// public sealed class BlockerErrorFixPatch : ModulePatch
// {
// protected override MethodBase GetTargetMethod()
// {
// return AccessTools.GetDeclaredMethods(typeof(ServerBotSettingsClass)).First(x => x.Name == nameof(ServerBotSettingsClass.Init));
// }

[PatchPrefix]
public static bool Prefix(Dictionary<WildSpawnType, ServerBotSettingsValuesClass> ___dictionary_0)
{
var enumValues = Enum.GetValues(typeof(WildSpawnType));
___dictionary_0.Add((WildSpawnType)enumValues.GetValue(enumValues.Length - 2), new ServerBotSettingsValuesClass(false, false, true, "ScavRole/PmcBot"));
___dictionary_0.Add((WildSpawnType)enumValues.GetValue(enumValues.Length - 1), new ServerBotSettingsValuesClass(false, false, true, "ScavRole/PmcBot"));
return true;
}
}
}
// [PatchPrefix]
// public static bool Prefix(Dictionary<WildSpawnType, ServerBotSettingsValuesClass> ___dictionary_0)
// {
// var enumValues = Enum.GetValues(typeof(WildSpawnType));
// ___dictionary_0.Add((WildSpawnType)enumValues.GetValue(enumValues.Length - 2), new ServerBotSettingsValuesClass(false, false, true, "ScavRole/PmcBot"));
// ___dictionary_0.Add((WildSpawnType)enumValues.GetValue(enumValues.Length - 1), new ServerBotSettingsValuesClass(false, false, true, "ScavRole/PmcBot"));
// return true;
// }
// }
//}
9 changes: 5 additions & 4 deletions Source/AkiSupport/Airdrops/Utils/AirdropUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using UnityEngine;
using Random = UnityEngine.Random;

namespace StayInTarkov.AkiSupport.Airdrops.Utils
{
public static class AirdropUtil
{
public static AirdropConfigModel GetConfigFromServer()
public static async Task<AirdropConfigModel> GetConfigFromServer()
{
string json = AkiBackendCommunication.Instance.GetJson("/singleplayer/airdrop/config");
string json = await AkiBackendCommunication.Instance.GetJsonAsync("/singleplayer/airdrop/config");
return JsonConvert.DeserializeObject<AirdropConfigModel>(json);
}

Expand Down Expand Up @@ -79,9 +80,9 @@ public static bool ShouldAirdropOccur(int dropChance, List<AirdropPoint> airdrop
return airdropPoints.Count > 0 && Random.Range(0, 100) <= dropChance;
}

public static AirdropParametersModel InitAirdropParams(GameWorld gameWorld, bool isFlare)
public static async Task<AirdropParametersModel> InitAirdropParams(GameWorld gameWorld, bool isFlare)
{
var serverConfig = GetConfigFromServer();
var serverConfig = await GetConfigFromServer();
if (serverConfig == null)
return new AirdropParametersModel() { Config = serverConfig, AirdropAvailable = false };

Expand Down
5 changes: 3 additions & 2 deletions Source/AkiSupport/Airdrops/Utils/ItemFactoryUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Newtonsoft.Json;
using StayInTarkov.Networking;
using System.Linq;
using System.Threading.Tasks;
using UnityEngine;

namespace Aki.Custom.Airdrops.Utils
Expand Down Expand Up @@ -60,9 +61,9 @@ public async void AddLoot(LootableContainer container, AirdropLootResultModel lo
}
}

public AirdropLootResultModel GetLoot()
public async Task<AirdropLootResultModel> GetLoot()
{
var json = AkiBackendCommunication.Instance.GetJson("/client/location/getAirdropLoot");
var json = await AkiBackendCommunication.Instance.GetJsonAsync("/client/location/getAirdropLoot");
var result = JsonConvert.DeserializeObject<AirdropLootResultModel>(json);

return result;
Expand Down
3 changes: 2 additions & 1 deletion Source/AkiSupport/Custom/BotDifficultyPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using StayInTarkov.Networking;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;

namespace StayInTarkov.AkiSupport.Custom
{
Expand All @@ -23,7 +24,7 @@ protected override MethodBase GetTargetMethod()
[PatchPrefix]
private static bool PatchPrefix(ref string __result, BotDifficulty botDifficulty, WildSpawnType role)
{
__result = AkiBackendCommunication.Instance.GetJson($"/singleplayer/settings/bot/difficulty/{role}/{botDifficulty}");
__result = AkiBackendCommunication.Instance.GetJsonBLOCKING($"/singleplayer/settings/bot/difficulty/{role}/{botDifficulty}");
return string.IsNullOrWhiteSpace(__result);
}
}
Expand Down
2 changes: 1 addition & 1 deletion Source/AkiSupport/Custom/CoreDifficultyPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ protected override MethodBase GetTargetMethod()
[PatchPrefix]
private static bool PatchPrefix(ref string __result)
{
__result = AkiBackendCommunication.Instance.GetJson("/singleplayer/settings/bot/difficulty/core/core");
__result = AkiBackendCommunication.Instance.GetJsonBLOCKING("/singleplayer/settings/bot/difficulty/core/core");
return string.IsNullOrWhiteSpace(__result);
}
}
Expand Down
2 changes: 1 addition & 1 deletion Source/AkiSupport/Custom/QTEPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class QTEPatch : ModulePatch
[PatchPostfix]
private static void PatchPostfix(HideoutPlayerOwner __instance)
{
AkiBackendCommunication.Instance.PostJson("/client/hideout/workout", new
AkiBackendCommunication.Instance.PostJsonBLOCKING("/client/hideout/workout", new
{
skills = __instance.HideoutPlayer.Skills,
effects = __instance.HideoutPlayer.HealthController.BodyPartEffects
Expand Down
4 changes: 2 additions & 2 deletions Source/AkiSupport/Custom/SettingsLocationPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ public static void Enable()
Directory.CreateDirectory(_sptPath);

// Screenshot
FieldInfo DocumentsSettings = ReflectionHelpers.GetFieldFromType(typeof(SettingsManager), "string_0");
FieldInfo DocumentsSettings = ReflectionHelpers.GetFieldFromType(typeof(SharedGameSettingsClass), "string_0");

// Game Settings
FieldInfo ApplicationDataSettings = ReflectionHelpers.GetFieldFromType(typeof(SettingsManager), "string_1");
FieldInfo ApplicationDataSettings = ReflectionHelpers.GetFieldFromType(typeof(SharedGameSettingsClass), "string_1");

// They are 'static' variables, not needed to give a instance.
DocumentsSettings.SetValue(null, _sptPath);
Expand Down
2 changes: 1 addition & 1 deletion Source/AkiSupport/Singleplayer/AkiSingleplayerPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace StayInTarkov.AkiSupport.Singleplayer
/// Credit SPT-Aki team
/// Paulov. I have removed a lot of unused patches
/// </summary>
[BepInPlugin("com.spt-aki.singleplayer", "AKI.Singleplayer", "1.0.0.0")]
[BepInPlugin("com.stayintarkov.aki.sp", "SIT.Aki.SPT", "1.0.0.0")]
class AkiSingleplayerPlugin : BaseUnityPlugin
{
public void Awake()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ private static void PatchPostfix(Player __instance)
{
if (__instance.IsYourPlayer)
{
__instance.Profile.EftStats.SessionCounters.AddLong(1L, ASessionCounterManager.AmmoUsed);
__instance.Profile.EftStats.SessionCounters.AddLong(1L, SessionCounterTypesAbstractClass.AmmoUsed);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ private static void PatchPostfix(DamageInfo damageInfo)
if (template is AmmoTemplate bulletTemplate)
{
float absorbedDamage = (float)Math.Round(bulletTemplate.Damage - damageInfo.Damage);
damageInfo.Player.iPlayer.Profile.EftStats.SessionCounters.AddFloat(absorbedDamage, ASessionCounterManager.CauseArmorDamage);
damageInfo.Player.iPlayer.Profile.EftStats.SessionCounters.AddFloat(absorbedDamage, SessionCounterTypesAbstractClass.CauseArmorDamage);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ private static void PatchPostfix()
}

var inventoryController = Traverse.Create(player).Field<InventoryControllerClass>("_inventoryController").Value;
ItemMovementHandler.Remove(accessCardItem, inventoryController, false, true);
InteractionsHandlerClass.Remove(accessCardItem, inventoryController, false, true);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public class IsHostileToEverybodyPatch : ModulePatch
{
protected override MethodBase GetTargetMethod()
{
var desiredType = typeof(ServerBotSettingsClass);
var desiredType = typeof(BotSettingsRepoClass);
var desiredMethod = desiredType.GetMethod("IsHostileToEverybody", BindingFlags.Public | BindingFlags.Static);

return desiredMethod;
Expand All @@ -16,7 +16,7 @@ protected override MethodBase GetTargetMethod()
[PatchPrefix]
private static bool PatchPrefix(WildSpawnType role, ref bool __result)
{
if (role == WildSpawnType.sptUsec || role == WildSpawnType.sptBear)
if ((int)role == 49 || (int)role == 50)
{
__result = true;
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ private static bool PatchPrefix(ref RaidSettings ____raidSettings)

// Create request and send to server, parse response
var request = new RaidTimeRequest(____raidSettings.Side, currentMapId);
var json = AkiBackendCommunication.Instance.PostJson("/singleplayer/settings/getRaidTime", Json.Serialize(request));
var json = AkiBackendCommunication.Instance.PostJsonBLOCKING("/singleplayer/settings/getRaidTime", Json.Serialize(request));
var serverResult = Json.Deserialize<RaidTimeResponse>(json);

// Capture the changes that will be made to the raid so they can be easily accessed by modders
Expand Down
9 changes: 5 additions & 4 deletions Source/Coop/Airdrops/SITAirdropsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
using StayInTarkov.Networking;
using System.Collections;
using System.Collections.Generic;
using System.Threading.Tasks;
using UnityEngine;

namespace Aki.Custom.Airdrops
Expand Down Expand Up @@ -67,7 +68,7 @@ public async void Start()

// The server will generate stuff ready for the packet

AirdropParameters = AirdropUtil.InitAirdropParams(gameWorld, isFlareDrop);
AirdropParameters = await AirdropUtil.InitAirdropParams(gameWorld, isFlareDrop);

if (!AirdropParameters.AirdropAvailable)
{
Expand Down Expand Up @@ -98,7 +99,7 @@ public async void Start()

SetDistanceToDrop();

BuildLootContainer(AirdropParameters.Config);
await BuildLootContainer(AirdropParameters.Config);

StartCoroutine(SendParamsToClients());

Expand Down Expand Up @@ -232,12 +233,12 @@ private void StartBox()
public AirdropConfigModel ClientAirdropConfigModel { get; private set; }
public bool ClientLootBuilt { get; private set; }

private void BuildLootContainer(AirdropConfigModel config)
private async Task BuildLootContainer(AirdropConfigModel config)
{
if (SITMatchmaking.IsClient)
return;

var lootData = factory.GetLoot();
var lootData = await factory.GetLoot();

// Get the lootData. Sent to Clients.
if (SITMatchmaking.IsServer)
Expand Down
2 changes: 1 addition & 1 deletion Source/Coop/Components/ActionPacketHandlerComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ void ReplicateArmoredTrainTime(Dictionary<string, object> packet)

if (coopGameComponent.LocalGameInstance is CoopSITGame coopGame)
{
Timer1 gameTimer = coopGame.GameTimer;
var gameTimer = coopGame.GameTimer;

// Process only after raid began.
if (gameTimer.StartDateTime.HasValue && gameTimer.SessionTime.HasValue)
Expand Down
17 changes: 5 additions & 12 deletions Source/Coop/Components/CoopGameComponents/SITGameComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,14 +150,7 @@ public static bool TryGetCoopGameComponent(out SITGameComponent coopGameComponen

public static string GetServerId()
{
var coopGC = GetCoopGameComponent();
if (coopGC == null)
{
StayInTarkovHelperConstants.Logger.LogError($"Attempted to use {nameof(GetServerId)} before {nameof(SITGameComponent)} has been created.");
return null;
}

return coopGC.ServerId;
return SITMatchmaking.GetGroupId();
}
#endregion

Expand Down Expand Up @@ -521,7 +514,7 @@ private IEnumerator EverySecondCoroutine()
}

// Add players who have joined to the AI Enemy Lists
var botController = (BotsController)ReflectionHelpers.GetFieldFromTypeByFieldType(typeof(BaseLocalGame<EftGamePlayerOwner>), typeof(BotsController)).GetValue(Singleton<ISITGame>.Instance);
var botController = (BotsController)ReflectionHelpers.GetFieldFromTypeByFieldType(typeof(BaseLocalGame<GamePlayerOwner>), typeof(BotsController)).GetValue(Singleton<ISITGame>.Instance);
if (botController != null)
{
while (PlayersForAIToTarget.TryDequeue(out var otherPlayer))
Expand Down Expand Up @@ -1404,8 +1397,8 @@ private LocalPlayer SpawnCharacter(Profile profile, Vector3 position, int player
// Cant use ObservedPlayerMode, it causes the player to fall through the floor and die
, BackendConfigManager.Config.CharacterController.ObservedPlayerMode
//, BackendConfigManager.Config.CharacterController.ClientPlayerMode
, () => Singleton<SettingsManager>.Instance.Control.Settings.MouseSensitivity
, () => Singleton<SettingsManager>.Instance.Control.Settings.MouseAimingSensitivity
, () => Singleton<SharedGameSettingsClass>.Instance.Control.Settings.MouseSensitivity
, () => Singleton<SharedGameSettingsClass>.Instance.Control.Settings.MouseAimingSensitivity
, FilterCustomizationClass.Default
, null
, isYourPlayer: false
Expand Down Expand Up @@ -1559,7 +1552,7 @@ public void SetWeaponInHandsOfNewPlayer(EFT.Player person, Action successCallbac

public float LocalTime => 0;

public BaseLocalGame<EftGamePlayerOwner> LocalGameInstance { get; internal set; }
public BaseLocalGame<GamePlayerOwner> LocalGameInstance { get; internal set; }

//public bool HighPingMode { get; set; } = false;
public bool ServerHasStopped { get; set; }
Expand Down
12 changes: 6 additions & 6 deletions Source/Coop/Components/CoopGameComponents/SITGameGUIComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ private void OnGUI_DrawPlayerFriendlyTags(Rect rect)
return;
}

if (FPSCamera.Instance == null)
if (CameraClass.Instance == null)
return;

if (Players == null)
Expand All @@ -206,8 +206,8 @@ private void OnGUI_DrawPlayerFriendlyTags(Rect rect)
if (!Singleton<GameWorld>.Instantiated)
return;

if (FPSCamera.Instance.SSAA != null && FPSCamera.Instance.SSAA.isActiveAndEnabled)
screenScale = FPSCamera.Instance.SSAA.GetOutputWidth() / (float)FPSCamera.Instance.SSAA.GetInputWidth();
if (CameraClass.Instance.SSAA != null && CameraClass.Instance.SSAA.isActiveAndEnabled)
screenScale = CameraClass.Instance.SSAA.GetOutputWidth() / (float)CameraClass.Instance.SSAA.GetInputWidth();

var ownPlayer = Singleton<GameWorld>.Instance.MainPlayer;
if (ownPlayer == null)
Expand Down Expand Up @@ -290,7 +290,7 @@ private void OnGUI_DrawPlayerEnemyTags(Rect rect)
return;
}

if (FPSCamera.Instance == null)
if (CameraClass.Instance == null)
return;

if (Players == null)
Expand All @@ -306,8 +306,8 @@ private void OnGUI_DrawPlayerEnemyTags(Rect rect)
return;


if (FPSCamera.Instance.SSAA != null && FPSCamera.Instance.SSAA.isActiveAndEnabled)
screenScale = FPSCamera.Instance.SSAA.GetOutputWidth() / (float)FPSCamera.Instance.SSAA.GetInputWidth();
if (CameraClass.Instance.SSAA != null && CameraClass.Instance.SSAA.isActiveAndEnabled)
screenScale = CameraClass.Instance.SSAA.GetOutputWidth() / (float)CameraClass.Instance.SSAA.GetInputWidth();

var ownPlayer = Singleton<GameWorld>.Instance.MainPlayer;
if (ownPlayer == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ void Update()

TimeAndWeatherPacket packet = new TimeAndWeatherPacket();

var sitGame = Singleton<ISITGame>.Instance as BaseLocalGame<EftGamePlayerOwner>;
var sitGame = Singleton<ISITGame>.Instance as BaseLocalGame<GamePlayerOwner>;

if (sitGame.GameDateTime != null)
packet.GameDateTime = sitGame.GameDateTime.Calculate().Ticks;
Expand Down
Loading
Loading