Skip to content

Commit

Permalink
2022-04-09
Browse files Browse the repository at this point in the history
CustomiseYourStorage:
*) Version number increased to 1.0.0.3
*) Items added to the droppod locker will now be added to KnownTech as well, unlocking any recipes that depend on acquiring those items; simply pulling the items out of the container does not trigger this, and thus blueprints which should logically have been unlocked with those items previously were not.

DWEquipmentBonanza
*) Version increased to 0.13.0.5
*) (SN1 only) Databox added for Headlamp in Jellyshroom Caves
*) Attempted fix for NullReferenceException in VehicleCharger.OnBeforeSerialize() (fix incomplete)
  • Loading branch information
DaWrecka committed Apr 9, 2022
1 parent f099f89 commit 861ebfc
Show file tree
Hide file tree
Showing 16 changed files with 216 additions and 53 deletions.
10 changes: 6 additions & 4 deletions CustomiseOxygen/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,17 @@ private static IEnumerator WaitForSpriteHandler()
bWaitingForSpriteHandler = true;

#if SUBNAUTICA_STABLE
while (SpriteUtils.Get(TechType.Cutefish, null) == null || Language.main == null || uGUI.isLoading || !bMainMenuHasLoaded)
//while (SpriteUtils.Get(TechType.Cutefish, null) == null || Language.main == null || uGUI.isLoading || !bMainMenuHasLoaded)
yield return new WaitUntil(() => (SpriteUtils.Get(TechType.Cutefish, null) == null || Language.main == null || uGUI.isLoading || !bMainMenuHasLoaded));
#elif BELOWZERO
//while (!SpriteManager.hasInitialized || Language.main == null || uGUI.isLoading || !bMainMenuHasLoaded)
while(!bMainMenuHasLoaded)
//while(!bMainMenuHasLoaded)
yield return new WaitUntil(() => bMainMenuHasLoaded);
#endif
{
/*{
Log.LogDebug($"WaitForSpriteHandler() waiting for 0.5 seconds");
yield return new WaitForSecondsRealtime(0.5f);
}
}*/

Log.LogDebug($"WaitForSpriteHandler(): Sprite manager initialisation complete. pendingTanks.Count == {pendingTanks.Count}");
HashSet<TechType> removals = new HashSet<TechType>();
Expand Down
3 changes: 3 additions & 0 deletions CustomiseYourStorage_BZ/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,10 @@ public void Init()
{
TechType tt = TechTypeUtils.GetTechType(s);
if (tt != TechType.None)
{
defaultLifepodLockerInventoryTypes.Add(tt);

}
else
{
Log.LogWarning($"Could not parse string '{s}' as TechType in defaultLifepodLockerInventory");
Expand Down
4 changes: 2 additions & 2 deletions CustomiseYourStorage_BZ/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace CustomiseYourStorage
[QModCore]
public class Main
{
internal const string version = "1.0.0.2";
internal const string version = "1.0.0.3";

internal static DWStorageConfig config { get; } = OptionsPanelHandler.RegisterModOptions<DWStorageConfig>();
//internal static readonly DWStorageConfigNonSML config = DWStorageConfigNonSML.LoadConfig(Path.Combine(new string[] { Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "config.json" }));
Expand All @@ -30,7 +30,7 @@ public class Main
// Similarly, we exclude the planters because they, too, have visuals associated with them that are likely to go ka-ka if we expand the storage.
{
#if SUBNAUTICA_STABLE
"EscapePod.StorageContainer", // We've given the DropPod special treatment, so we're keeping it for the the Lifepod.
"EscapePod.StorageContainer", // We've given the DropPod special treatment, so we're keeping it for the Lifepod.
// This might seem counter-intuitive, blacklisting the Escape Pod locker when we could easily customise it the same way as any other container,
// but the BZ version of this mod was developed before the SN1 version, so the Droppod code was implemented before the SN1 version of the mod.
#elif BELOWZERO
Expand Down
26 changes: 14 additions & 12 deletions CustomiseYourStorage_BZ/Patches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ private static void Postfix(ref StorageContainer __instance)
string lowerID = ContainerID.ToLower();

#if SUBNAUTICA_STABLE
if(lowerID == "escapepod.storagecontainer")
if (lowerID == "escapepod.storagecontainer")
#elif BELOWZERO
if (lowerID == "none.storagecontiner") //(sic)
#endif
Expand All @@ -45,7 +45,7 @@ private static void Postfix(ref StorageContainer __instance)
int X = Main.config.DroppodWidth;
int Y = Main.config.DroppodHeight;
#if !RELEASE
Logger.Log(Logger.Level.Debug, $"Setting LifePod locker to size ({X}, {Y})");
Logger.Log(Logger.Level.Debug, $"Setting LifePod locker to size ({X}, {Y})");
#endif
__instance.Resize(X, Y);
if (Main.config.defaultLifepodLockerInventoryTypes.Count > 0)
Expand All @@ -69,15 +69,15 @@ private static void Postfix(ref StorageContainer __instance)
if (techType == TechType.None)
{
#if !RELEASE
Logger.Log(Logger.Level.Debug, $"Container {name} has TechType of None and is not the Lifepod locker, skipping");
Logger.Log(Logger.Level.Debug, $"Container {name} has TechType of None and is not the Lifepod locker, skipping");
#endif
return;
}

if (Main.StorageBlacklist.Contains(techType))
{
#if !RELEASE
Logger.Log(Logger.Level.Debug, $"Container TechType {techType} present on blacklist, skipping");
Logger.Log(Logger.Level.Debug, $"Container TechType {techType} present on blacklist, skipping");
#endif
return;
}
Expand All @@ -90,7 +90,7 @@ private static void Postfix(ref StorageContainer __instance)
if (Main.config.TryGetModSize(lowerID, out NewSize))
{
#if !RELEASE
Logger.Log(Logger.Level.Debug, $"Configuration for storage container {ContainerID} was found with value of ({NewSize.x}, {NewSize.y})");
Logger.Log(Logger.Level.Debug, $"Configuration for storage container {ContainerID} was found with value of ({NewSize.x}, {NewSize.y})");
#endif
__instance.Resize(NewSize.x, NewSize.y);
return;
Expand All @@ -100,13 +100,13 @@ private static void Postfix(ref StorageContainer __instance)
{
// TryGetModSize returned false, but with a non-zero vector; this should mean that the value was found, but with default value.
#if !RELEASE
Logger.Log(Logger.Level.Debug, $"Storage container {ContainerID} was found, but with default values; nothing to do.");
Logger.Log(Logger.Level.Debug, $"Storage container {ContainerID} was found, but with default values; nothing to do.");
#endif
return;
}
#if !RELEASE

Logger.Log(Logger.Level.Info, $"Storage container identifier {ContainerID} was not found in configuration settings; using default values");
Logger.Log(Logger.Level.Info, $"Storage container identifier {ContainerID} was not found in configuration settings; using default values");
#endif
Main.config.AddContainer(lowerID, __instance.width, __instance.height);
}
Expand All @@ -133,6 +133,8 @@ public static IEnumerator AddLifepodInventory(StorageContainer container, List<T

inventoryItem2.item.Initialize();
container.container.UnsafeAdd(inventoryItem2);
if (!KnownTech.Contains(tt))
KnownTech.Add(tt, true);
}
yield break;
}
Expand Down Expand Up @@ -168,7 +170,7 @@ private static void Postfix(SeamothStorageContainer __instance)
if (techType == TechType.None)
{
#if !RELEASE
Logger.Log(Logger.Level.Info, $"Container {name} has TechType of None and is not the Lifepod locker, skipping");
Logger.Log(Logger.Level.Info, $"Container {name} has TechType of None and is not the Lifepod locker, skipping");
#endif
return;
}
Expand All @@ -178,7 +180,7 @@ private static void Postfix(SeamothStorageContainer __instance)
if (Main.config.TryGetModSize(ContainerID, out NewSize))
{
#if !RELEASE
Logger.Log(Logger.Level.Debug, $"Configuration for items container {ContainerID} was found with value of ({NewSize.x}, {NewSize.y})");
Logger.Log(Logger.Level.Debug, $"Configuration for items container {ContainerID} was found with value of ({NewSize.x}, {NewSize.y})");
#endif
__instance.container.Resize(NewSize.x, NewSize.y);
return;
Expand All @@ -188,13 +190,13 @@ private static void Postfix(SeamothStorageContainer __instance)
{
// TryGetNewSize returned false, but with a non-zero vector; this should mean that the value was found, but with default value.
#if !RELEASE
Logger.Log(Logger.Level.Debug, $"Items container {ContainerID} was found, but with default values; nothing to do.");
Logger.Log(Logger.Level.Debug, $"Items container {ContainerID} was found, but with default values; nothing to do.");
#endif
return;
}
#if !RELEASE

Logger.Log(Logger.Level.Info, $"Items container identifier {ContainerID} was not found in configuration settings; using default values");
Logger.Log(Logger.Level.Info, $"Items container identifier {ContainerID} was not found in configuration settings; using default values");
#endif
Main.config.AddContainer(lowerID, __instance.width, __instance.height);
}
Expand All @@ -209,7 +211,7 @@ private static void Postfix(FiltrationMachine __instance)
int maxWater = Main.config.FiltrationWater;
Vector2int newContainerSize = new Vector2int(Main.config.FiltrationWidth, Main.config.FiltrationHeight);
#if !RELEASE
Logger.Log(Logger.Level.Debug, $"Reconfiguring Filtration Machine {__instance.gameObject.name} with configuration values of: maxSalt {maxSalt}, maxWater {maxWater}, new size ({newContainerSize.x}, {newContainerSize.y})");
Logger.Log(Logger.Level.Debug, $"Reconfiguring Filtration Machine {__instance.gameObject.name} with configuration values of: maxSalt {maxSalt}, maxWater {maxWater}, new size ({newContainerSize.x}, {newContainerSize.y})");
#endif

__instance.maxSalt = maxSalt;
Expand Down
2 changes: 1 addition & 1 deletion CustomiseYourStorage_BZ/mod_BelowZero.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"Id": "CustomiseYourStorage",
"DisplayName": "Customise Your Storage",
"Author": "DaWrecka",
"Version": "1.0.0.2",
"Version": "1.0.0.3",
"Dependencies": [
"SMLHelper"
],
Expand Down
2 changes: 1 addition & 1 deletion CustomiseYourStorage_BZ/mod_Subnautica.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"Id": "CustomiseYourStorage",
"DisplayName": "Customise Your Storage",
"Author": "DaWrecka",
"Version": "1.0.0.2",
"Version": "1.0.0.3",
"Dependencies": [
"SMLHelper"
],
Expand Down
1 change: 1 addition & 0 deletions DWEquipmentBonanza/DWEquipmentBonanza.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
<Compile Include="MonoBehaviours\HoverbikeStructuralIntegrityModifier.cs" />
<Compile Include="MonoBehaviours\HoverbikeUpdater.cs" />
<Compile Include="MonoBehaviours\HoverpadUpdater.cs" />
<Compile Include="MonoBehaviours\OverrideTransform.cs" />
<Compile Include="MonoBehaviours\Powerglide.cs" />
<Compile Include="MonoBehaviours\SeamothUpdater.cs" />
<Compile Include="MonoBehaviours\VehicleQuantumLockerComponent.cs" />
Expand Down
15 changes: 7 additions & 8 deletions DWEquipmentBonanza/Equipables/DiverPerimeterDefenceChip.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using DWEquipmentBonanza.MonoBehaviours;
using SMLHelper.V2.Handlers;
using System.Diagnostics;
using Common.Utility;
#if SUBNAUTICA_STABLE
using RecipeData = SMLHelper.V2.Crafting.TechData;
using Sprite = Atlas.Sprite;
Expand Down Expand Up @@ -206,7 +207,7 @@ public virtual GameObject PreparePrefab(GameObject prefab)
{
System.Reflection.MethodBase thisMethod = System.Reflection.MethodBase.GetCurrentMethod();
Log.LogDebug($"{thisMethod.ReflectedType.Name}.{thisMethod.Name}: begin");
GameObject obj = GameObject.Instantiate<GameObject>(prefab);
GameObject obj = GameObjectUtils.InstantiateInactive(prefab);

DiverPerimeterDefenceBehaviour behaviour = obj.EnsureComponent<DiverPerimeterDefenceBehaviour>();
behaviour.Initialise(this.TechType);
Expand All @@ -218,10 +219,7 @@ public virtual GameObject PreparePrefab(GameObject prefab)

protected override Sprite GetItemSprite()
{
if (icon == null || icon == SpriteManager.defaultSprite)
{
icon = SpriteManager.Get(templateTechType);
}
icon ??= (templateTechType != TechType.None ? SpriteUtils.Get(templateTechType, null) : null);
return icon;
}
protected virtual IEnumerator PostPatchSetup()
Expand Down Expand Up @@ -410,13 +408,14 @@ protected override RecipeData GetBlueprintRecipe()
Ingredients = new List<Ingredient>(new Ingredient[]
{
new Ingredient(Main.GetModTechType("DiverDefenceSystemMk2"), 1),
new Ingredient(TechType.Nickel, 1),
#if SUBNAUTICA_STABLE
new Ingredient(TechType.PrecursorKey_Blue, 1),
new Ingredient(TechType.PrecursorKey_Orange, 1),
new Ingredient(TechType.PrecursorIonCrystal, 1),
#elif BELOWZERO
new Ingredient(Main.GetModTechType("ShadowLeviathanSample"), 1),
#endif
new Ingredient(TechType.Nickel, 1),
new Ingredient(TechType.PrecursorIonBattery, 1)
#endif
}
)
};
Expand Down
8 changes: 5 additions & 3 deletions DWEquipmentBonanza/Equipables/Headwear.cs
Original file line number Diff line number Diff line change
Expand Up @@ -287,9 +287,11 @@ protected override void OnFinishedPatch()
SetUpPrefabs();
}

public FlashlightHelmet(string classID = "FlashlightHelmet",
string friendlyName = "Headlamp",
string Description = "Head-mounted light for hands-free illumination") : base(classID, friendlyName, Description)
internal const string classID = "FlashlightHelmet";
internal const string friendlyName = "Headlamp";
internal const string desc = "Head-mounted light for hands-free illumination";

public FlashlightHelmet() : base(classID, friendlyName, desc)
{ }
}
#endif
Expand Down
37 changes: 31 additions & 6 deletions DWEquipmentBonanza/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,14 @@ namespace DWEquipmentBonanza
{
[FileName("DWEquipmentBonanza")]
[Serializable]
internal class DWDataFile : SaveDataCache
public class DWDataFile : SaveDataCache
{
private HashSet<ISerializationCallbackReceiver> activeReceivers = new HashSet<ISerializationCallbackReceiver>();
public Dictionary<string, float> ModuleCharges = new Dictionary<string, float>();

#if SUBNAUTICA
public Vector3 HeadlampDataboxPosition { get; set; }
public Vector3 HeadlampDataboxRotation { get; set; }
#endif
internal void Init()
{
if (ModuleCharges == null)
Expand All @@ -61,6 +64,9 @@ internal void OnSave()
{
try
{
if (c == null)
continue;

c.OnBeforeSerialize();
}
catch (Exception e)
Expand Down Expand Up @@ -106,16 +112,16 @@ public bool RegisterReceiver(ISerializationCallbackReceiver v)
[QModCore]
public class Main
{
internal const string version = "0.13.0.4";
internal const string version = "0.13.0.5";
internal static bool bVerboseLogging = true;
internal static bool bLogTranspilers = false;
#if SUBNAUTICA_STABLE
public static bool bInAcid = false; // Whether or not the player is currently immersed in acid
public static bool bInAcid { get; internal set; } = false; // Whether or not the player is currently immersed in acid
#endif
public static HashSet<string> playerSlots => Equipment.slotMapping.Keys.ToHashSet<string>();

internal static DWConfig config { get; } = OptionsPanelHandler.RegisterModOptions<DWConfig>();
internal static DWDataFile saveCache { get; private set; }
public static DWDataFile saveCache { get; private set; }

private static readonly Type CustomiseOxygen = Type.GetType("CustomiseOxygen.Main, CustomiseOxygen", false, false);
private static readonly MethodInfo CustomOxyAddExclusionMethod = CustomiseOxygen?.GetMethod("AddExclusion", BindingFlags.Public | BindingFlags.Static);
Expand Down Expand Up @@ -605,7 +611,7 @@ public static void Load()

Databox powerglideDatabox = new Databox()
{
DataboxID = "PowerglideDatabox",
DataboxID = "Powerglide",
PrimaryDescription = PowerglideEquipable.friendlyName + " Databox",
SecondaryDescription = PowerglideEquipable.description,
TechTypeToUnlock = GetModTechType("PowerglideEquipable"),
Expand All @@ -627,6 +633,25 @@ public static void Load()
saveCache = SaveDataHandler.Main.RegisterSaveDataCache<DWDataFile>();
saveCache.Init();

#if SUBNAUTICA_STABLE
Databox headLampDatabox = new Databox()
{
DataboxID = "Headlamp",
PrimaryDescription = FlashlightHelmet.friendlyName + " Databox",
SecondaryDescription = FlashlightHelmet.desc,
TechTypeToUnlock = GetModTechType("FlashlightHelmet"),
CoordinatedSpawns = new List<Spawnable.SpawnLocation>()
{
new Spawnable.SpawnLocation(new Vector3(-403f, -229.8f, -98.48f), Vector3.zero),
},
ModifyGameObject = (Action<GameObject>)(go =>
{
go.EnsureComponent<OverrideTransform>();
})
};
headLampDatabox.Patch();
#endif

var harmony = new Harmony($"DaWrecka_{myAssembly.GetName().Name}");
harmony.PatchAll(myAssembly);
/*if (QModServices.Main.ModPresent("UpgradedVehicles"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,6 @@ public void RuntimeDischargeCheat(int Cheat)

public void Awake()
{
if (thisPickup == null && gameObject.TryGetComponent<Pickupable>(out Pickupable component))
thisPickup = component;
CoroutineHost.StartCoroutine(GetGameObjectAsync());
}

Expand All @@ -118,6 +116,8 @@ private IEnumerator GetGameObjectAsync()
}
yield return new WaitForEndOfFrame();
}
if (thisPickup == null && MyGO.TryGetComponent<Pickupable>(out Pickupable component))
thisPickup = component;
}

public void OnBeforeSerialize()
Expand Down
35 changes: 35 additions & 0 deletions DWEquipmentBonanza/MonoBehaviours/OverrideTransform.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;

namespace DWEquipmentBonanza.MonoBehaviours
{
#if SUBNAUTICA
public class OverrideTransform : MonoBehaviour
{
public IEnumerator Start()
{
GameObject go = this.gameObject;
yield return new WaitUntil(() => (go ??= this.gameObject) != null);
yield return new WaitForEndOfFrame();

if (Main.saveCache.HeadlampDataboxPosition == Vector3.zero)
{
//Common.Log.LogDebug($"Generating new headlamp databox position");
var rng = new System.Random();
// Generate a random position that is within +/- 1.8m of (-403, -232.4, -98.48), and a random rotation around that point
Main.saveCache.HeadlampDataboxPosition = new Vector3((float)(-404.1f + rng.NextDouble() * 1.8f), -232.35f, (float)(-99.38f + rng.NextDouble() * 1.8f));
Main.saveCache.HeadlampDataboxRotation = new Vector3(0f, (float)(rng.NextDouble() * 360f), 0f);
Main.saveCache.Save();
}

go.transform.position = Main.saveCache.HeadlampDataboxPosition;
go.transform.eulerAngles = Main.saveCache.HeadlampDataboxRotation;
}
}
#endif
}
Loading

0 comments on commit 861ebfc

Please sign in to comment.