Skip to content

Commit

Permalink
Merge pull request #88 from stayintarkov/fix-loot
Browse files Browse the repository at this point in the history
Loot management improvement
  • Loading branch information
paulov-t authored Dec 10, 2023
2 parents 678e2b8 + a707b99 commit 98e01f2
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Source/Coop/CoopPatches.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using BepInEx.Logging;
using StayInTarkov.Coop.Session;
using StayInTarkov.Coop.ItemControllerPatches;
using StayInTarkov.Coop.LocalGame;
using StayInTarkov.Coop.Matchmaker;
Expand Down Expand Up @@ -44,6 +45,7 @@ internal static void Run(BepInEx.Configuration.ConfigFile config)
new NonWaveSpawnScenarioPatch(m_Config).Enable();
new WaveSpawnScenarioPatch(m_Config).Enable();
new LocalGame_Weather_Patch().Enable();
new LoadLocationLootPatch().Enable();


// ------ MATCHMAKER -------------------------
Expand Down
64 changes: 64 additions & 0 deletions Source/Coop/Session/LoadLocationLoot_Patch.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
using Aki.Custom.Airdrops.Models;
using EFT;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using StayInTarkov.Coop.Matchmaker;
using StayInTarkov.Networking;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using UnityEngine.Networking.Match;
using UnityEngine.Profiling;

namespace StayInTarkov.Coop.Session
{
public class LocationDataRequest()
{
[JsonProperty("data")]
public LocationSettings.Location Data { get; set; }
}

public class LoadLocationLootPatch : ModulePatch
{
protected override MethodBase GetTargetMethod()
{
var method = ReflectionHelpers.GetMethodForType(typeof(Session1), "LoadLocationLoot");

Logger.LogDebug($"{GetType().Name} Method: {method?.Name}");

return method;
}

[PatchPrefix]
private static bool PatchPrefix(string locationId, int variantId, ref Task<LocationSettings.Location> __result)
{
Logger.LogDebug("LoadLocationLoot PatchPrefix");

if (MatchmakerAcceptPatches.MatchingType == EMatchmakerType.Single)
{
return true;
}

string serverId = MatchmakerAcceptPatches.GetGroupId();

var objectToSend = new Dictionary<string, object>
{
{ "locationId", locationId }
, { "variantId", variantId }
, { "serverId", serverId }
};

__result = Task.Run(() =>
{
var result = AkiBackendCommunication.Instance.PostJson($"/coop/location/getLoot", JsonConvert.SerializeObject(objectToSend));
result.TrySITParseJson(out LocationDataRequest locationDataRequest);
return locationDataRequest.Data;
});

return false;
}
}
}

0 comments on commit 98e01f2

Please sign in to comment.