Skip to content

Commit

Permalink
Merge pull request #241 from SubnauticaModding/dev
Browse files Browse the repository at this point in the history
SMLHelper 2.12.0
  • Loading branch information
Metious authored Aug 21, 2021
2 parents f05306c + 17b9408 commit 059d5de
Show file tree
Hide file tree
Showing 21 changed files with 396 additions and 34 deletions.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
4 changes: 2 additions & 2 deletions Example mod/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("2.11.1.0")]
[assembly: AssemblyFileVersion("2.11.1.0")]
[assembly: AssemblyVersion("2.12.0.0")]
[assembly: AssemblyFileVersion("2.12.0.0")]
2 changes: 1 addition & 1 deletion SMLHelper/Assets/FishPrefab.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public sealed override GameObject GetGameObject()
forces.handleGravity = true;
forces.underwaterDrag = 1f;
forces.underwaterGravity = 0;
#if BELOWZERO || SUBNAUTICA_EXP
#if BELOWZERO
forces.waterDepth = Ocean.GetOceanLevel();
#else
forces.waterDepth = Ocean.main.GetOceanLevel();
Expand Down
49 changes: 38 additions & 11 deletions SMLHelper/Handlers/CustomSoundHandler.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using System;
using FMOD;
using SMLHelper.V2.Interfaces;
using SMLHelper.V2.Patchers;
using SMLHelper.V2.Utility;

namespace SMLHelper.V2.Handlers
namespace SMLHelper.V2.Handlers
{
using FMOD;
using Interfaces;
using Patchers;
using UnityEngine;
using Utility;

/// <summary>
/// A handler class for adding and overriding Sounds.
/// </summary>
Expand All @@ -30,7 +30,7 @@ private CustomSoundHandler()
/// <param name="id">The Id of your custom sound which is used when checking which sounds to play.</param>
/// <param name="filePath">The file path on disk of the sound file to load</param>
/// <param name="soundChannel">The sound channel to get the volume to play the sound at. defaults to <see cref="SoundChannel.Master"/></param>
/// <returns>Returns the <see cref="Sound"/> loaded</returns>
/// <returns>the <see cref="Sound"/> loaded</returns>

Sound ICustomSoundHandler.RegisterCustomSound(string id, string filePath, SoundChannel soundChannel)
{
Expand All @@ -40,6 +40,21 @@ Sound ICustomSoundHandler.RegisterCustomSound(string id, string filePath, SoundC
return sound;
}

/// <summary>
/// Register a custom sound by an <see cref="AudioClip"/> instance. Some vanilla game sounds can be overridden by matching the id to the <see cref="FMODAsset.path"/>.
/// </summary>
/// <param name="id">The Id of your custom sound which is used when checking which sounds to play.</param>
/// <param name="audio">The AudioClip to register.</param>
/// <param name="soundChannel">The sound channel to get the volume to play the sound at. defaults to <see cref="SoundChannel.Master"/></param>
/// <returns>the <see cref="Sound"/> registered.</returns>
Sound ICustomSoundHandler.RegisterCustomSound(string id, AudioClip audio, SoundChannel soundChannel)
{
var sound = AudioUtils.CreateSound(audio);
CustomSoundPatcher.CustomSounds[id] = sound;
CustomSoundPatcher.CustomSoundChannels[id] = soundChannel;
return sound;
}

/// <summary>
/// Register a Custom sound that has been loaded using AudioUtils. Some vanilla game sounds can be overridden by matching the id to the <see cref="FMODAsset.path"/>.
/// </summary>
Expand Down Expand Up @@ -70,7 +85,7 @@ void ICustomSoundHandler.TryPlayCustomSound(string id)
/// </summary>
/// <param name="id">The Id of the custom sound</param>
/// <param name="sound">Outputs the <see cref="Sound"/> if found and null if not found.</param>
/// <returns>Returns true or false depending on if the id was found</returns>
/// <returns>true or false depending on if the id was found</returns>
bool ICustomSoundHandler.TryGetCustomSound(string id, out Sound sound)
{
return CustomSoundPatcher.CustomSounds.TryGetValue(id, out sound);
Expand All @@ -86,13 +101,25 @@ bool ICustomSoundHandler.TryGetCustomSound(string id, out Sound sound)
/// <param name="id">The Id of your custom sound which is used when checking which sounds to play.</param>
/// <param name="filePath">The file path on disk of the sound file to load</param>
/// <param name="soundChannel">The sound channel to get the volume to play the sound at. defaults to <see cref="SoundChannel.Master"/></param>
/// <returns>Returns the <see cref="Sound"/> loaded</returns>
/// <returns>the <see cref="Sound"/> loaded</returns>

public static Sound RegisterCustomSound(string id, string filePath, SoundChannel soundChannel = SoundChannel.Master)
{
return Main.RegisterCustomSound(id, filePath, soundChannel);
}

/// <summary>
/// Register a custom sound by an <see cref="AudioClip"/> instance. Some vanilla game sounds can be overridden by matching the id to the <see cref="FMODAsset.path"/>.
/// </summary>
/// <param name="id">The Id of your custom sound which is used when checking which sounds to play.</param>
/// <param name="audio">The AudioClip to register.</param>
/// <param name="soundChannel">The sound channel to get the volume to play the sound at. defaults to <see cref="SoundChannel.Master"/></param>
/// <returns>the <see cref="Sound"/> registered.</returns>
public static Sound RegisterCustomSound(string id, AudioClip audio, SoundChannel soundChannel = SoundChannel.Master)
{
return Main.RegisterCustomSound(id, audio, soundChannel);
}

/// <summary>
/// Register a Custom sound that has been loaded using AudioUtils. Some vanilla game sounds can be overridden by matching the id to the <see cref="FMODAsset.path"/>.
/// </summary>
Expand All @@ -119,7 +146,7 @@ public static void TryPlayCustomSound(string id)
/// </summary>
/// <param name="id">The Id of the custom sound</param>
/// <param name="sound">Outputs the <see cref="Sound"/> if found and null if not found.</param>
/// <returns>Returns true or false depending on if the id was found</returns>
/// <returns>true or false depending on if the id was found</returns>
public static bool TryGetCustomSound(string id, out Sound sound)
{
return Main.TryGetCustomSound(id, out sound);
Expand Down
22 changes: 16 additions & 6 deletions SMLHelper/Interfaces/ICustomSoundHandler.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
using FMOD;
using SMLHelper.V2.Utility;

namespace SMLHelper.V2.Interfaces
namespace SMLHelper.V2.Interfaces
{
using FMOD;
using UnityEngine;
using Utility;

/// <summary>
/// A handler class for adding and overriding Sounds.
/// </summary>
Expand All @@ -14,9 +15,18 @@ public interface ICustomSoundHandler
/// <param name="id">The Id of your custom sound which is used when checking which sounds to play.</param>
/// <param name="filePath">The file path on disk of the sound file to load</param>
/// <param name="soundChannel">The sound channel to get the volume to play the sound at. defaults to <see cref="SoundChannel.Master"/></param>
/// <returns>Returns the <see cref="Sound"/> loaded</returns>
/// <returns>the <see cref="Sound"/> loaded</returns>
Sound RegisterCustomSound(string id, string filePath, SoundChannel soundChannel = SoundChannel.Master);

/// <summary>
/// Register a custom sound by an <see cref="AudioClip"/> instance. Some vanilla game sounds can be overridden by matching the id to the <see cref="FMODAsset.path"/>.
/// </summary>
/// <param name="id">The Id of your custom sound which is used when checking which sounds to play.</param>
/// <param name="audio">The AudioClip to register.</param>
/// <param name="soundChannel">The sound channel to get the volume to play the sound at. defaults to <see cref="SoundChannel.Master"/></param>
/// <returns>the <see cref="Sound"/> registered.</returns>
Sound RegisterCustomSound(string id, AudioClip audio, SoundChannel soundChannel = SoundChannel.Master);

/// <summary>
/// Register a Custom sound that has been loaded using AudioUtils. Some vanilla game sounds can be overridden by matching the id to the <see cref="FMODAsset.path"/>.
/// </summary>
Expand All @@ -36,7 +46,7 @@ public interface ICustomSoundHandler
/// </summary>
/// <param name="id">The Id of the custom sound</param>
/// <param name="sound">Outputs the <see cref="Sound"/> if found and null if not found.</param>
/// <returns>Returns true or false depending on if the id was found</returns>
/// <returns>true or false depending on if the id was found</returns>
bool TryGetCustomSound(string id, out Sound sound);
}
}
4 changes: 4 additions & 0 deletions SMLHelper/Json/ConfigFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ public abstract class ConfigFile : IJsonFile
new FloatConverter(),
new StringEnumConverter(),
new VersionConverter(),
new Vector2Converter(),
new Vector3Converter(),
new Vector4Converter(),
new Vector2IntConverter(),
new Vector3IntConverter(),
new QuaternionConverter()
};

Expand Down
56 changes: 56 additions & 0 deletions SMLHelper/Json/Converters/Vector2Converter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using System;
using UnityEngine;
#if SUBNAUTICA_STABLE
using Oculus.Newtonsoft.Json;
#else
using Newtonsoft.Json;
#endif
namespace SMLHelper.V2.Json.Converters
{
/// <summary>
/// A Vector2 json converter that simplifies the Vector2 to only x,y serialization.
/// </summary>
public class Vector2Converter : JsonConverter
{
/// <summary>
/// A method that determines when this converter should process.
/// </summary>
/// <param name="objectType">the current object type</param>
/// <returns></returns>
public override bool CanConvert(Type objectType)
{
return objectType == typeof(Vector2);
}

/// <summary>
/// A method that tells Newtonsoft how to Serialize the current object.
/// </summary>
/// <param name="writer"></param>
/// <param name="value"></param>
/// <param name="serializer"></param>
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
var vector2 = (Vector2)value;
serializer.Serialize(writer, (Vector2Json)vector2);
}

/// <summary>
/// A method that tells Newtonsoft how to Deserialize and read the current object.
/// </summary>
/// <param name="reader"></param>
/// <param name="objectType"></param>
/// <param name="existingValue"></param>
/// <param name="serializer"></param>
/// <returns></returns>
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
return (Vector2)serializer.Deserialize<Vector2Json>(reader);
}
}

internal record Vector2Json(float X, float Y)
{
public static explicit operator Vector2(Vector2Json v) => new(v.X, v.Y);
public static explicit operator Vector2Json(Vector2 v) => new(v.x, v.y);
}
}
56 changes: 56 additions & 0 deletions SMLHelper/Json/Converters/Vector2IntConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using System;
using UnityEngine;
#if SUBNAUTICA_STABLE
using Oculus.Newtonsoft.Json;
#else
using Newtonsoft.Json;
#endif
namespace SMLHelper.V2.Json.Converters
{
/// <summary>
/// A Vector2Int json converter that simplifies the Vector2Int to only x,y serialization.
/// </summary>
public class Vector2IntConverter : JsonConverter
{
/// <summary>
/// A method that determines when this converter should process.
/// </summary>
/// <param name="objectType">the current object type</param>
/// <returns></returns>
public override bool CanConvert(Type objectType)
{
return objectType == typeof(Vector2Int);
}

/// <summary>
/// A method that tells Newtonsoft how to Serialize the current object.
/// </summary>
/// <param name="writer"></param>
/// <param name="value"></param>
/// <param name="serializer"></param>
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
var vector2Int = (Vector2Int)value;
serializer.Serialize(writer, (Vector2IntJson)vector2Int);
}

/// <summary>
/// A method that tells Newtonsoft how to Deserialize and read the current object.
/// </summary>
/// <param name="reader"></param>
/// <param name="objectType"></param>
/// <param name="existingValue"></param>
/// <param name="serializer"></param>
/// <returns></returns>
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
return (Vector2Int)serializer.Deserialize<Vector2IntJson>(reader);
}
}

internal record Vector2IntJson(int X, int Y)
{
public static explicit operator Vector2Int(Vector2IntJson v) => new(v.X, v.Y);
public static explicit operator Vector2IntJson(Vector2Int v) => new(v.x, v.y);
}
}
56 changes: 56 additions & 0 deletions SMLHelper/Json/Converters/Vector3IntConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using System;
using UnityEngine;
#if SUBNAUTICA_STABLE
using Oculus.Newtonsoft.Json;
#else
using Newtonsoft.Json;
#endif
namespace SMLHelper.V2.Json.Converters
{
/// <summary>
/// A Vector3Int json converter that simplifies the Vector3Int to only x,y,z serialization.
/// </summary>
public class Vector3IntConverter : JsonConverter
{
/// <summary>
/// A method that determines when this converter should process.
/// </summary>
/// <param name="objectType">the current object type</param>
/// <returns></returns>
public override bool CanConvert(Type objectType)
{
return objectType == typeof(Vector3Int);
}

/// <summary>
/// A method that tells Newtonsoft how to Serialize the current object.
/// </summary>
/// <param name="writer"></param>
/// <param name="value"></param>
/// <param name="serializer"></param>
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
var vector3Int = (Vector3Int)value;
serializer.Serialize(writer, (Vector3IntJson)vector3Int);
}

/// <summary>
/// A method that tells Newtonsoft how to Deserialize and read the current object.
/// </summary>
/// <param name="reader"></param>
/// <param name="objectType"></param>
/// <param name="existingValue"></param>
/// <param name="serializer"></param>
/// <returns></returns>
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
return (Vector3Int)serializer.Deserialize<Vector3IntJson>(reader);
}
}

internal record Vector3IntJson(int X, int Y, int Z)
{
public static explicit operator Vector3Int(Vector3IntJson v) => new(v.X, v.Y, v.Z);
public static explicit operator Vector3IntJson(Vector3Int v) => new(v.x, v.y, v.z);
}
}
56 changes: 56 additions & 0 deletions SMLHelper/Json/Converters/Vector4Converter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using System;
using UnityEngine;
#if SUBNAUTICA_STABLE
using Oculus.Newtonsoft.Json;
#else
using Newtonsoft.Json;
#endif
namespace SMLHelper.V2.Json.Converters
{
/// <summary>
/// A Vector4 json converter that simplifies the Vector4 to only x,y,z,w serialization.
/// </summary>
public class Vector4Converter : JsonConverter
{
/// <summary>
/// A method that determines when this converter should process.
/// </summary>
/// <param name="objectType">the current object type</param>
/// <returns></returns>
public override bool CanConvert(Type objectType)
{
return objectType == typeof(Vector4);
}

/// <summary>
/// A method that tells Newtonsoft how to Serialize the current object.
/// </summary>
/// <param name="writer"></param>
/// <param name="value"></param>
/// <param name="serializer"></param>
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
var vector4 = (Vector4)value;
serializer.Serialize(writer, (Vector4Json)vector4);
}

/// <summary>
/// A method that tells Newtonsoft how to Deserialize and read the current object.
/// </summary>
/// <param name="reader"></param>
/// <param name="objectType"></param>
/// <param name="existingValue"></param>
/// <param name="serializer"></param>
/// <returns></returns>
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
return (Vector4)serializer.Deserialize<Vector4Json>(reader);
}
}

internal record Vector4Json(float X, float Y, float Z, float W)
{
public static explicit operator Vector4(Vector4Json v) => new(v.X, v.Y, v.Z, v.W);
public static explicit operator Vector4Json(Vector4 v) => new(v.x, v.y, v.z, v.w);
}
}
Loading

0 comments on commit 059d5de

Please sign in to comment.