diff --git a/Readme.md b/Readme.md index 4cf0b3629..c193af68c 100644 --- a/Readme.md +++ b/Readme.md @@ -82,6 +82,11 @@ Authors: * [_nebula](https://github.com/misternebula) * [TAImatem](https://github.com/TAImatem) +Contributors: +* [salomj](https://github.com/salomj) - Helped with menus and inputs. +* [artum](https://github.com/artumino) - Helped with menus and patchers. +* [JohnCorby](https://github.com/JohnCorby) - Helped with audio loading stuff. + Special thanks to: * [Outer Wilds](http://www.outerwilds.com) * [Outer Wilds on Reddit](https://www.reddit.com/r/outerwilds) diff --git a/src/OWML.Common/Interfaces/IModInteraction.cs b/src/OWML.Common/Interfaces/IModInteraction.cs index 3a8bd7231..15d6a7648 100644 --- a/src/OWML.Common/Interfaces/IModInteraction.cs +++ b/src/OWML.Common/Interfaces/IModInteraction.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; namespace OWML.Common { @@ -10,8 +11,14 @@ public interface IModInteraction IList GetDependencies(string uniqueName); + IModBehaviour TryGetMod(string uniqueName); + + TInterface TryGetModApi(string uniqueName) where TInterface : class; + + [Obsolete("Use TryGetMod")] IModBehaviour GetMod(string uniqueName); + [Obsolete("Use TryGetModApi")] TInterface GetModApi(string uniqueName) where TInterface : class; bool ModExists(string uniqueName); diff --git a/src/OWML.Launcher/OWML.Manifest.json b/src/OWML.Launcher/OWML.Manifest.json index efaa6fbd5..48e7ee097 100644 --- a/src/OWML.Launcher/OWML.Manifest.json +++ b/src/OWML.Launcher/OWML.Manifest.json @@ -2,7 +2,7 @@ "author": "Alek", "name": "OWML", "uniqueName": "Alek.OWML", - "version": "2.3.3", + "version": "2.4.0", "minGameVersion": "1.1.10.47", "maxGameVersion": "1.1.12.201" } diff --git a/src/OWML.ModHelper.Assets/ModAssets.cs b/src/OWML.ModHelper.Assets/ModAssets.cs index 11e7a0e29..f7a7af096 100644 --- a/src/OWML.ModHelper.Assets/ModAssets.cs +++ b/src/OWML.ModHelper.Assets/ModAssets.cs @@ -101,10 +101,11 @@ public AudioClip GetAudio(string filename) var path = _manifest.ModFolderPath + filename; _console.WriteLine($"Loading audio from {path}"); using var reader = new AudioFileReader(path); - var outputBytes = new float[reader.Length]; - reader.Read(outputBytes, 0, (int)reader.Length); - var clip = AudioClip.Create(path, (int)reader.Length, reader.WaveFormat.Channels, reader.WaveFormat.SampleRate, false); - clip.SetData(outputBytes, 0); + var sampleCount = (int)(reader.Length * 8 / reader.WaveFormat.BitsPerSample); + var outputSamples = new float[sampleCount]; + reader.Read(outputSamples, 0, sampleCount); + var clip = AudioClip.Create(path, sampleCount / reader.WaveFormat.Channels, reader.WaveFormat.Channels, reader.WaveFormat.SampleRate, false); + clip.SetData(outputSamples, 0); return clip; } } diff --git a/src/OWML.ModHelper.Interaction/ModInteraction.cs b/src/OWML.ModHelper.Interaction/ModInteraction.cs index 753e1d794..94c2b9d03 100644 --- a/src/OWML.ModHelper.Interaction/ModInteraction.cs +++ b/src/OWML.ModHelper.Interaction/ModInteraction.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Linq; using OWML.Common; @@ -65,12 +66,41 @@ public IList GetDependencies(string uniqueName) return _dependencyDict[uniqueName]; } + public IModBehaviour TryGetMod(string uniqueName) + => _modList.FirstOrDefault(m => m.ModHelper.Manifest.UniqueName == uniqueName); + + private object TryGetApi(string uniqueName) + { + var mod = TryGetMod(uniqueName); + return mod == default ? default : mod.Api; + } + + public TInterface TryGetModApi(string uniqueName) where TInterface : class + { + var api = TryGetApi(uniqueName); + + if (api == default) + { + return default; + } + + return api switch + { + null => null, + TInterface inter => inter, + _ => _proxyFactory.CreateProxy(api, _manifest.UniqueName, uniqueName) + }; + } + + [Obsolete("Use TryGetMod instead.")] public IModBehaviour GetMod(string uniqueName) => _modList.First(m => m.ModHelper.Manifest.UniqueName == uniqueName); - private object GetApi(string uniqueName) => - GetMod(uniqueName).Api; + [Obsolete("Use TryGetApi instead.")] + private object GetApi(string uniqueName) + => GetMod(uniqueName).Api; + [Obsolete("Use TryGetModApi instead.")] public TInterface GetModApi(string uniqueName) where TInterface : class { var api = GetApi(uniqueName); diff --git a/src/OWML.Utils/JsonHelper.cs b/src/OWML.Utils/JsonHelper.cs index 5c8ef7c0e..1c119076c 100644 --- a/src/OWML.Utils/JsonHelper.cs +++ b/src/OWML.Utils/JsonHelper.cs @@ -6,20 +6,27 @@ namespace OWML.Utils { public static class JsonHelper { - public static T LoadJsonObject(string path) + public static T LoadJsonObject(string path, bool fixBackslashes = true, JsonSerializerSettings settings = null) { if (!File.Exists(path)) { return default; } - var json = File.ReadAllText(path) - .Replace("\\\\", "/") - .Replace("\\", "/"); + var json = File.ReadAllText(path); + + if (fixBackslashes) + { + json = json + .Replace("\\\\", "/") + .Replace("\\", "/"); + } try { - return JsonConvert.DeserializeObject(json); + return settings != null + ? JsonConvert.DeserializeObject(json, settings) + : JsonConvert.DeserializeObject(json); } catch (Exception) {