0
0
mirror of https://github.com/sp-tarkov/modules.git synced 2025-02-13 06:30:43 -05:00

Experimentlal fix for LocationId patch breaking hideout

This commit is contained in:
Terkoiz 2024-01-04 11:19:11 +02:00
parent 33e6c151af
commit 2878279ce9

View File

@ -16,6 +16,7 @@ namespace Aki.Custom.Patches
public class SetLocationIdOnRaidStartPatch : ModulePatch public class SetLocationIdOnRaidStartPatch : ModulePatch
{ {
private static PropertyInfo _locationProperty; private static PropertyInfo _locationProperty;
protected override MethodBase GetTargetMethod() protected override MethodBase GetTargetMethod()
{ {
Type localGameBaseType = PatchConstants.LocalGameType.BaseType; Type localGameBaseType = PatchConstants.LocalGameType.BaseType;
@ -24,21 +25,27 @@ namespace Aki.Custom.Patches
_locationProperty = localGameBaseType.GetProperties(PatchConstants.PrivateFlags).Single(x => x.PropertyType == typeof(Location)); _locationProperty = localGameBaseType.GetProperties(PatchConstants.PrivateFlags).Single(x => x.PropertyType == typeof(Location));
// Find the TimeAndWeatherSettings handling method // Find the TimeAndWeatherSettings handling method
return localGameBaseType.GetMethods(PatchConstants.PrivateFlags).SingleOrDefault(m => IsTargetMethod(m)); return localGameBaseType.GetMethods(PatchConstants.PrivateFlags).SingleOrDefault(IsTargetMethod);
} }
private static bool IsTargetMethod(MethodInfo mi) private static bool IsTargetMethod(MethodInfo mi)
{ {
// Find method_3(TimeAndWeatherSettings timeAndWeather) // Find method_3(TimeAndWeatherSettings timeAndWeather)
var parameters = mi.GetParameters(); var parameters = mi.GetParameters();
return (parameters.Length == 1 return (parameters.Length == 1 && parameters[0].ParameterType == typeof(TimeAndWeatherSettings));
&& parameters[0].ParameterType == typeof(TimeAndWeatherSettings));
} }
[PatchPostfix] [PatchPostfix]
private static void PatchPostfix(AbstractGame __instance) private static void PatchPostfix(AbstractGame __instance)
{ {
var gameWorld = Singleton<GameWorld>.Instance; var gameWorld = Singleton<GameWorld>.Instance;
// EFT.HideoutGame is an internal class, so we can't do static type checking :(
if (__instance.GetType().Name.Contains("HideoutGame"))
{
return;
}
Location location = _locationProperty.GetValue(__instance) as Location; Location location = _locationProperty.GetValue(__instance) as Location;
gameWorld.LocationId = location.Id; gameWorld.LocationId = location.Id;
} }