-
-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #88 from stayintarkov/fix-loot
Loot management improvement
- Loading branch information
Showing
2 changed files
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |