mirror of
https://github.com/sp-tarkov/modules.git
synced 2025-02-13 09:50:43 -05:00
Move setting of gameWorld.LocationId to its own patch (!49)
Since gameWorld.LocationId can be used by multiple things (And may be used by more in the future), move it to its own patch instead of as part of the BTR patch. Target `method_3` in `BaseLocalGame` to assign it as close to where a live game would set it Co-authored-by: DrakiaXYZ <565558+TheDgtl@users.noreply.github.com> Reviewed-on: SPT-AKI/Modules#49 Co-authored-by: DrakiaXYZ <drakiaxyz@noreply.dev.sp-tarkov.com> Co-committed-by: DrakiaXYZ <drakiaxyz@noreply.dev.sp-tarkov.com>
This commit is contained in:
parent
45d053e300
commit
a31f19755f
@ -45,6 +45,7 @@ namespace Aki.Custom
|
|||||||
new QTEPatch().Enable();
|
new QTEPatch().Enable();
|
||||||
new PmcFirstAidPatch().Enable();
|
new PmcFirstAidPatch().Enable();
|
||||||
new SettingsLocationPatch().Enable();
|
new SettingsLocationPatch().Enable();
|
||||||
|
new SetLocationIdOnRaidStartPatch().Enable();
|
||||||
//new RankPanelPatch().Enable();
|
//new RankPanelPatch().Enable();
|
||||||
new RagfairFeePatch().Enable();
|
new RagfairFeePatch().Enable();
|
||||||
new ScavQuestPatch().Enable();
|
new ScavQuestPatch().Enable();
|
||||||
|
46
project/Aki.Custom/Patches/SetLocationIdOnRaidStartPatch.cs
Normal file
46
project/Aki.Custom/Patches/SetLocationIdOnRaidStartPatch.cs
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
using Aki.Reflection.Patching;
|
||||||
|
using Aki.Reflection.Utils;
|
||||||
|
using EFT;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Reflection;
|
||||||
|
using Comfort.Common;
|
||||||
|
using System;
|
||||||
|
using static LocationSettingsClass;
|
||||||
|
|
||||||
|
namespace Aki.Custom.Patches
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Local games do not set the locationId property like a network game does, `LocationId` is used by various bsg systems
|
||||||
|
/// e.g. btr/lightkeeper services
|
||||||
|
/// </summary>
|
||||||
|
public class SetLocationIdOnRaidStartPatch : ModulePatch
|
||||||
|
{
|
||||||
|
private static PropertyInfo _locationProperty;
|
||||||
|
protected override MethodBase GetTargetMethod()
|
||||||
|
{
|
||||||
|
Type localGameBaseType = PatchConstants.LocalGameType.BaseType;
|
||||||
|
|
||||||
|
// At this point, gameWorld.MainPlayer isn't set, so we need to use the LocalGame's `Location_0` property
|
||||||
|
_locationProperty = localGameBaseType.GetProperties(PatchConstants.PrivateFlags).Single(x => x.PropertyType == typeof(Location));
|
||||||
|
|
||||||
|
// Find the TimeAndWeatherSettings handling method
|
||||||
|
return localGameBaseType.GetMethods(PatchConstants.PrivateFlags).SingleOrDefault(m => IsTargetMethod(m));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static bool IsTargetMethod(MethodInfo mi)
|
||||||
|
{
|
||||||
|
// Find method_3(TimeAndWeatherSettings timeAndWeather)
|
||||||
|
var parameters = mi.GetParameters();
|
||||||
|
return (parameters.Length == 1
|
||||||
|
&& parameters[0].ParameterType == typeof(TimeAndWeatherSettings));
|
||||||
|
}
|
||||||
|
|
||||||
|
[PatchPostfix]
|
||||||
|
private static void PatchPostfix(AbstractGame __instance)
|
||||||
|
{
|
||||||
|
var gameWorld = Singleton<GameWorld>.Instance;
|
||||||
|
Location location = _locationProperty.GetValue(__instance) as Location;
|
||||||
|
gameWorld.LocationId = location.Id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -26,7 +26,6 @@ namespace Aki.Debugging.Patches
|
|||||||
}
|
}
|
||||||
|
|
||||||
var botGame = Singleton<IBotGame>.Instance;
|
var botGame = Singleton<IBotGame>.Instance;
|
||||||
gameWorld.LocationId = gameWorld.MainPlayer.Location;
|
|
||||||
|
|
||||||
if (gameWorld.BtrController == null)
|
if (gameWorld.BtrController == null)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user