Skip to content

Commit

Permalink
Compatibility with game version 1.15.1.
Browse files Browse the repository at this point in the history
  • Loading branch information
algernon-A committed Nov 15, 2022
1 parent d6b1d5e commit a10a83a
Show file tree
Hide file tree
Showing 3 changed files with 161 additions and 14 deletions.
24 changes: 21 additions & 3 deletions Code/Loading/AssetLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,22 @@ public IEnumerator LoadCustomContent()
}
}

if (LevelLoader.DLC(2144480u))
{
Package.Asset asset4 = PackageManager.FindAssetByName("System." + DistrictStyle.kModderPack14StyleName);
if (asset4 != null && asset4.isEnabled)
{
DistrictStyle districtStyle = new DistrictStyle(DistrictStyle.kModderPack14StyleName, builtIn: true);
Util.InvokeVoid(Singleton<LoadingManager>.instance, "AddChildrenToBuiltinStyle", GameObject.Find("Modder Pack 14"), districtStyle, false);
if (LSMRSettings.SkipPrefabs)
{
PrefabLoader.RemoveSkippedFromStyle(districtStyle);
}

districtStyles.Add(districtStyle);
}
}

// LSM insert.
// Unload any skipped assets.
if (LSMRSettings.SkipPrefabs)
Expand Down Expand Up @@ -884,7 +900,8 @@ private Package.Asset[] GetLoadQueue(HashSet<string> styleBuildings)
List<Package.Asset> assetRefList = new List<Package.Asset>(8);
HashSet<string> assetNames = new HashSet<string>();
string previousPackageName = string.Empty;
SteamHelper.DLC_BitMask dLC_BitMask = ~SteamHelper.GetOwnedDLCMask();
SteamHelper.ExpansionBitMask ownedExpansionMask = ~SteamHelper.GetOwnedExpansionMask();
SteamHelper.ModderPackBitMask ownedModderPackMask = ~SteamHelper.GetOwnedModderPackMask();

// 'Load enabled' and 'load used' settings.
bool loadEnabled = LSMRSettings.LoadEnabled & !LSMRSettings.EnableDisable;
Expand Down Expand Up @@ -919,7 +936,8 @@ private Package.Asset[] GetLoadQueue(HashSet<string> styleBuildings)
bool isUsed = loadUsed && UsedAssets.Instance.IsUsed(finalAsset, type);

// Disable asset if relevant DLC isn't active.
enabled &= (AssetImporterAssetTemplate.GetAssetDLCMask(assetRefs) & dLC_BitMask) == 0;
AssetImporterAssetTemplate.GetAssetDLCMask(assetRefs, out SteamHelper.ExpansionBitMask expansionMask, out SteamHelper.ModderPackBitMask modderPackMask);
enabled &= (expansionMask & ownedExpansionMask) == 0 & (modderPackMask & ownedModderPackMask) == 0;

// If we're loading used assets, and the main asset isn't used, but there are other assets in the package - check if any of the other assets are used.
if (assetCount > 1 & !isUsed & loadUsed)
Expand Down Expand Up @@ -1523,7 +1541,7 @@ private void EnableDisableAssets()
}

// Iterate through all packages.
foreach (object item in LoadingScreenModRevisited.CustomDeserializer.Instance.AllPackages)
foreach (object item in CustomDeserializer.Instance.AllPackages)
{
// Single-package items.
if (item is Package singlePackage)
Expand Down
124 changes: 115 additions & 9 deletions Code/Loading/CustomDeserializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ public sealed class CustomDeserializer
private const int TypeVehicleInfoDoor = 70;
private const int TypeBuildingInfo = 74;
private const int TypeBuildingInfoSub = 77;
private const int TypeBuildingSpawnPoint = 80;
private const int TypeDepotSpawnPoint = 81;
private const int TypePropInfo = 85;
private const int TypePropInfoEffect = 86;
private const int TypePropInfoVariation = 89;
private const int TypeVehicleInfoMesh = 95;
Expand Down Expand Up @@ -96,7 +98,9 @@ internal CustomDeserializer()
{
[typeof(ModInfo)] = TypeModInfo,
[typeof(TerrainModify.Surface)] = TypeInt32,
#pragma warning disable CS0618 // Type or member is obsolete
[typeof(SteamHelper.DLC_BitMask)] = TypeInt32,
#pragma warning restore CS0618 // Type or member is obsolete
[typeof(ItemClass.Availability)] = TypeInt32,
[typeof(ItemClass.Placement)] = TypeInt32,
[typeof(ItemClass.Service)] = TypeInt32,
Expand Down Expand Up @@ -135,7 +139,9 @@ internal CustomDeserializer()
[typeof(VehicleInfo.VehicleDoor)] = TypeVehicleInfoDoor,
[typeof(BuildingInfo)] = TypeBuildingInfo,
[typeof(BuildingInfo.SubInfo)] = TypeBuildingInfoSub,
[typeof(BuildingAI.SpawnPoint)] = TypeBuildingSpawnPoint,
[typeof(DepotAI.SpawnPoint)] = TypeDepotSpawnPoint,
[typeof(PropInfo)] = TypePropInfo,
[typeof(PropInfo.Effect)] = TypePropInfoEffect,
[typeof(PropInfo.Variation)] = TypePropInfoVariation,
[typeof(VehicleInfo.MeshInfo)] = TypeVehicleInfoMesh,
Expand Down Expand Up @@ -541,9 +547,15 @@ internal object CustomDeserialize(Package package, Type type, PackageReader read
case TypeBuildingInfoSub:
return ReadBuildingInfoSubInfo(package, reader);

case TypeBuildingSpawnPoint:
return ReadBuildingAISpawnPoint(reader);

case TypeDepotSpawnPoint:
return ReadDepotAISpawnPoint(reader);

case TypePropInfo:
return ReadPropInfo(package, reader);

case TypePropInfoEffect:
return ReadPropInfoEffect(reader);

Expand Down Expand Up @@ -683,7 +695,7 @@ private Package.Asset ReadPackageAsset(Package package, PackageReader reader)
/// <returns>New NetInfo.Lane.</returns>
private NetInfo.Lane ReadNetInfoLane(Package package, PackageReader reader)
{
return new NetInfo.Lane
NetInfo.Lane lane = new NetInfo.Lane
{
m_position = reader.ReadSingle(),
m_width = reader.ReadSingle(),
Expand All @@ -700,6 +712,20 @@ private NetInfo.Lane ReadNetInfoLane(Package package, PackageReader reader)
m_centerPlatform = reader.ReadBoolean(),
m_elevated = reader.ReadBoolean(),
};

// 1.15.1 addition.
if (package.version >= 9)
{
lane.m_vehicleCategoryPart1 = (VehicleInfo.VehicleCategoryPart1)reader.ReadInt32();
lane.m_vehicleCategoryPart2 = (VehicleInfo.VehicleCategoryPart2)reader.ReadInt32();
}
else
{
lane.m_vehicleCategoryPart1 = VehicleInfo.VehicleCategoryPart1.All;
lane.m_vehicleCategoryPart2 = VehicleInfo.VehicleCategoryPart2.All;
}

return lane;
}

/// <summary>
Expand Down Expand Up @@ -899,6 +925,32 @@ private NetInfo.Node ReadNetInfoNode(Package package, PackageReader reader)
node.m_directConnect = reader.ReadBoolean();
node.m_emptyTransparent = reader.ReadBoolean();

// 1.15.1 addition.
if (package.version >= 9)
{
node.m_flagsRequired2 = (NetNode.Flags2)reader.ReadInt32();
node.m_flagsForbidden2 = (NetNode.Flags2)reader.ReadInt32();
node.m_tagsRequired = reader.ReadStringArray();
node.m_tagsForbidden = reader.ReadStringArray();
node.m_forbidAnyTags = reader.ReadBoolean();
node.m_minSameTags = reader.ReadByte();
node.m_maxSameTags = reader.ReadByte();
node.m_minOtherTags = reader.ReadByte();
node.m_maxOtherTags = reader.ReadByte();
}
else
{
node.m_flagsRequired2 = NetNode.Flags2.None;
node.m_flagsForbidden2 = NetNode.Flags2.None;
node.m_tagsRequired = new string[0];
node.m_tagsForbidden = new string[0];
node.m_forbidAnyTags = false;
node.m_minSameTags = 0;
node.m_maxSameTags = 7;
node.m_minOtherTags = 0;
node.m_maxOtherTags = 7;
}

return node;
}

Expand Down Expand Up @@ -1106,6 +1158,22 @@ private BuildingInfo.SubInfo ReadBuildingInfoSubInfo(Package package, PackageRea
};
}

/// <summary>
/// Deserializes a BuildingAI.SpawnPoint.
/// </summary>
/// <param name="reader">PackageReader instance.</param>
/// <returns>New BuildingAI.SpawnPoint.</returns>
private BuildingAI.SpawnPoint ReadBuildingAISpawnPoint(PackageReader reader)
{
return new BuildingAI.SpawnPoint
{
m_position = reader.ReadVector3(),
m_target = reader.ReadVector3(),
m_vehicleCategoryPart1 = (VehicleInfo.VehicleCategoryPart1)reader.ReadInt32(),
m_vehicleCategoryPart2 = (VehicleInfo.VehicleCategoryPart2)reader.ReadInt32(),
};
}

/// <summary>
/// Deserializes a DepotAI.SpawnPoint.
/// </summary>
Expand All @@ -1120,6 +1188,23 @@ private DepotAI.SpawnPoint ReadDepotAISpawnPoint(PackageReader reader)
};
}

/// <summary>
/// Deserializes a PropInfo.
/// </summary>
/// <param name="package">Package to deserialize.</param>
/// <param name="reader">PackageReader instance.</param>
/// <returns>New PropInfo.</returns>
private PropInfo ReadPropInfo(Package package, PackageReader reader)
{
// 1.15.1 addition.
if (package.version >= 9)
{
return PrefabCollection<PropInfo>.FindLoaded(reader.ReadString());
}

return null;
}

/// <summary>
/// Deserializes a PropInfo.Effect.
/// </summary>
Expand Down Expand Up @@ -1179,10 +1264,7 @@ private VehicleInfo.MeshInfo ReadVehicleInfoMeshInfo(Package package, PackageRea
GameObject gameObject = AssetDeserializer.Instantiate(package.FindByChecksum(checksum), isMain: true, isTop: false) as GameObject;
meshInfo.m_subInfo = gameObject.GetComponent<VehicleInfoBase>();
gameObject.SetActive(value: false);
if (meshInfo.m_subInfo.m_lodObject != null)
{
meshInfo.m_subInfo.m_lodObject.SetActive(value: false);
}
meshInfo.m_subInfo.m_lodObject?.SetActive(value: false);
}
else
{
Expand Down Expand Up @@ -1213,10 +1295,7 @@ private BuildingInfo.MeshInfo ReadBuildingInfoMeshInfo(Package package, PackageR
GameObject gameObject = AssetDeserializer.Instantiate(package.FindByChecksum(checksum), isMain: true, isTop: false) as GameObject;
meshInfo.m_subInfo = gameObject.GetComponent<BuildingInfoBase>();
gameObject.SetActive(value: false);
if (meshInfo.m_subInfo.m_lodObject != null)
{
meshInfo.m_subInfo.m_lodObject.SetActive(value: false);
}
meshInfo.m_subInfo.m_lodObject?.SetActive(value: false);
}
else
{
Expand All @@ -1226,6 +1305,17 @@ private BuildingInfo.MeshInfo ReadBuildingInfoMeshInfo(Package package, PackageR
// Flags etc.
meshInfo.m_flagsForbidden = (Building.Flags)reader.ReadInt32();
meshInfo.m_flagsRequired = (Building.Flags)reader.ReadInt32();

// 1.15.1 addition.
if (package.version >= 9)
{
meshInfo.m_flagsRequired2 = (Building.Flags2)reader.ReadInt32();
}
else
{
meshInfo.m_flagsRequired2 = Building.Flags2.None;
}

meshInfo.m_position = reader.ReadVector3();
meshInfo.m_angle = reader.ReadSingle();

Expand Down Expand Up @@ -1398,6 +1488,22 @@ private NetLaneProps.Prop ReadNetLaneProp(Package package, PackageReader reader)
prop.m_upgradable = prop.m_tree != null && prop.m_repeatDistance > 0f;
}

// 1.15.1 additions.
if (package.version >= 9)
{
prop.m_startFlagsRequired2 = (NetNode.Flags2)reader.ReadInt32();
prop.m_startFlagsForbidden2 = (NetNode.Flags2)reader.ReadInt32();
prop.m_endFlagsRequired2 = (NetNode.Flags2)reader.ReadInt32();
prop.m_endFlagsForbidden2 = (NetNode.Flags2)reader.ReadInt32();
}
else
{
prop.m_startFlagsRequired2 = NetNode.Flags2.None;
prop.m_startFlagsForbidden2 = NetNode.Flags2.None;
prop.m_endFlagsRequired2 = NetNode.Flags2.None;
prop.m_endFlagsForbidden2 = NetNode.Flags2.None;
}

return prop;
}

Expand Down
27 changes: 25 additions & 2 deletions Code/Loading/LevelLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1078,15 +1078,27 @@ private static List<KeyValuePair<string, float>> SetLevels()
{
prefabScenes.Add(new KeyValuePair<string, float>("Station13Prefabs", 0.01f));
}

if (DLC(1992292u))
{
prefabScenes.Add(new KeyValuePair<string, float>("Station14Prefabs", 0.01f));
}

if (DLC(1992293u))
{
prefabScenes.Add(new KeyValuePair<string, float>("Station15Prefabs", 0.01f));
}

if (DLC(2144483u))
{
prefabScenes.Add(new KeyValuePair<string, float>("Station16Prefabs", 0.01f));
}

if (DLC(2144482u))
{
prefabScenes.Add(new KeyValuePair<string, float>("Station17Prefabs", 0.01f));
}

if (DLC(1992290u))
{
Package.Asset asset4 = PackageManager.FindAssetByName("System." + DistrictStyle.kModderPack11StyleName);
Expand Down Expand Up @@ -1169,6 +1181,16 @@ private static List<KeyValuePair<string, float>> SetLevels()
prefabScenes.Add(new KeyValuePair<string, float>("ModderPack10Prefabs", 0.03f));
}

if (DLC(2144481u))
{
prefabScenes.Add(new KeyValuePair<string, float>("ModderPack13Prefabs", 0.03f));
}

if (DLC(2144480u))
{
prefabScenes.Add(new KeyValuePair<string, float>("ModderPack14Prefabs", 0.03f));
}

Package.Asset europeanStyles = PackageManager.FindAssetByName("System." + DistrictStyle.kEuropeanStyleName);
if (europeanStyles != null && europeanStyles.isEnabled)
{
Expand All @@ -1182,8 +1204,9 @@ private static List<KeyValuePair<string, float>> SetLevels()
}
}

loadingManager.m_ownedMask1 = SteamHelper.GetOwnedDLCMask();
loadingManager.m_ownedMask2 = SteamHelper.GetOwnedDLCMask2();
loadingManager.m_ownedExpansionMask = SteamHelper.GetOwnedExpansionMask();
loadingManager.m_ownedModderPackMask = SteamHelper.GetOwnedModderPackMask();
loadingManager.m_ownedRadioMask = SteamHelper.GetOwnedRadioMask();

return prefabScenes;
}
Expand Down

0 comments on commit a10a83a

Please sign in to comment.