This commit is contained in:
_nebula 2022-06-06 22:56:59 +01:00 committed by GitHub
parent 5c4f6e207f
commit 729092e747
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 64 additions and 14 deletions

View File

@ -82,6 +82,11 @@ Authors:
* [_nebula](https://github.com/misternebula) * [_nebula](https://github.com/misternebula)
* [TAImatem](https://github.com/TAImatem) * [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: Special thanks to:
* [Outer Wilds](http://www.outerwilds.com) * [Outer Wilds](http://www.outerwilds.com)
* [Outer Wilds on Reddit](https://www.reddit.com/r/outerwilds) * [Outer Wilds on Reddit](https://www.reddit.com/r/outerwilds)

View File

@ -1,4 +1,5 @@
using System.Collections.Generic; using System;
using System.Collections.Generic;
namespace OWML.Common namespace OWML.Common
{ {
@ -10,8 +11,14 @@ namespace OWML.Common
IList<IModBehaviour> GetDependencies(string uniqueName); IList<IModBehaviour> GetDependencies(string uniqueName);
IModBehaviour TryGetMod(string uniqueName);
TInterface TryGetModApi<TInterface>(string uniqueName) where TInterface : class;
[Obsolete("Use TryGetMod")]
IModBehaviour GetMod(string uniqueName); IModBehaviour GetMod(string uniqueName);
[Obsolete("Use TryGetModApi")]
TInterface GetModApi<TInterface>(string uniqueName) where TInterface : class; TInterface GetModApi<TInterface>(string uniqueName) where TInterface : class;
bool ModExists(string uniqueName); bool ModExists(string uniqueName);

View File

@ -2,7 +2,7 @@
"author": "Alek", "author": "Alek",
"name": "OWML", "name": "OWML",
"uniqueName": "Alek.OWML", "uniqueName": "Alek.OWML",
"version": "2.3.3", "version": "2.4.0",
"minGameVersion": "1.1.10.47", "minGameVersion": "1.1.10.47",
"maxGameVersion": "1.1.12.201" "maxGameVersion": "1.1.12.201"
} }

View File

@ -101,10 +101,11 @@ namespace OWML.ModHelper.Assets
var path = _manifest.ModFolderPath + filename; var path = _manifest.ModFolderPath + filename;
_console.WriteLine($"Loading audio from {path}"); _console.WriteLine($"Loading audio from {path}");
using var reader = new AudioFileReader(path); using var reader = new AudioFileReader(path);
var outputBytes = new float[reader.Length]; var sampleCount = (int)(reader.Length * 8 / reader.WaveFormat.BitsPerSample);
reader.Read(outputBytes, 0, (int)reader.Length); var outputSamples = new float[sampleCount];
var clip = AudioClip.Create(path, (int)reader.Length, reader.WaveFormat.Channels, reader.WaveFormat.SampleRate, false); reader.Read(outputSamples, 0, sampleCount);
clip.SetData(outputBytes, 0); var clip = AudioClip.Create(path, sampleCount / reader.WaveFormat.Channels, reader.WaveFormat.Channels, reader.WaveFormat.SampleRate, false);
clip.SetData(outputSamples, 0);
return clip; return clip;
} }
} }

View File

@ -1,4 +1,5 @@
using System.Collections.Generic; using System;
using System.Collections.Generic;
using System.Linq; using System.Linq;
using OWML.Common; using OWML.Common;
@ -65,12 +66,41 @@ namespace OWML.ModHelper.Interaction
return _dependencyDict[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<TInterface>(string uniqueName) where TInterface : class
{
var api = TryGetApi(uniqueName);
if (api == default)
{
return default;
}
return api switch
{
null => null,
TInterface inter => inter,
_ => _proxyFactory.CreateProxy<TInterface>(api, _manifest.UniqueName, uniqueName)
};
}
[Obsolete("Use TryGetMod instead.")]
public IModBehaviour GetMod(string uniqueName) => public IModBehaviour GetMod(string uniqueName) =>
_modList.First(m => m.ModHelper.Manifest.UniqueName == uniqueName); _modList.First(m => m.ModHelper.Manifest.UniqueName == uniqueName);
private object GetApi(string uniqueName) => [Obsolete("Use TryGetApi instead.")]
GetMod(uniqueName).Api; private object GetApi(string uniqueName)
=> GetMod(uniqueName).Api;
[Obsolete("Use TryGetModApi instead.")]
public TInterface GetModApi<TInterface>(string uniqueName) where TInterface : class public TInterface GetModApi<TInterface>(string uniqueName) where TInterface : class
{ {
var api = GetApi(uniqueName); var api = GetApi(uniqueName);

View File

@ -6,20 +6,27 @@ namespace OWML.Utils
{ {
public static class JsonHelper public static class JsonHelper
{ {
public static T LoadJsonObject<T>(string path) public static T LoadJsonObject<T>(string path, bool fixBackslashes = true, JsonSerializerSettings settings = null)
{ {
if (!File.Exists(path)) if (!File.Exists(path))
{ {
return default; return default;
} }
var json = File.ReadAllText(path) var json = File.ReadAllText(path);
.Replace("\\\\", "/")
.Replace("\\", "/"); if (fixBackslashes)
{
json = json
.Replace("\\\\", "/")
.Replace("\\", "/");
}
try try
{ {
return JsonConvert.DeserializeObject<T>(json); return settings != null
? JsonConvert.DeserializeObject<T>(json, settings)
: JsonConvert.DeserializeObject<T>(json);
} }
catch (Exception) catch (Exception)
{ {