Skip to content

Commit

Permalink
2.4.0 (#443)
Browse files Browse the repository at this point in the history
  • Loading branch information
misternebula authored Jun 6, 2022
1 parent 5c4f6e2 commit 729092e
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 14 deletions.
5 changes: 5 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 8 additions & 1 deletion src/OWML.Common/Interfaces/IModInteraction.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;

namespace OWML.Common
{
Expand All @@ -10,8 +11,14 @@ public interface IModInteraction

IList<IModBehaviour> GetDependencies(string uniqueName);

IModBehaviour TryGetMod(string uniqueName);

TInterface TryGetModApi<TInterface>(string uniqueName) where TInterface : class;

[Obsolete("Use TryGetMod")]
IModBehaviour GetMod(string uniqueName);

[Obsolete("Use TryGetModApi")]
TInterface GetModApi<TInterface>(string uniqueName) where TInterface : class;

bool ModExists(string uniqueName);
Expand Down
2 changes: 1 addition & 1 deletion src/OWML.Launcher/OWML.Manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
9 changes: 5 additions & 4 deletions src/OWML.ModHelper.Assets/ModAssets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
36 changes: 33 additions & 3 deletions src/OWML.ModHelper.Interaction/ModInteraction.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Linq;
using OWML.Common;

Expand Down Expand Up @@ -65,12 +66,41 @@ public IList<IModBehaviour> 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<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) =>
_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<TInterface>(string uniqueName) where TInterface : class
{
var api = GetApi(uniqueName);
Expand Down
17 changes: 12 additions & 5 deletions src/OWML.Utils/JsonHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,27 @@ namespace OWML.Utils
{
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))
{
return default;
}

var json = File.ReadAllText(path)
.Replace("\\\\", "/")
.Replace("\\", "/");
var json = File.ReadAllText(path);

if (fixBackslashes)
{
json = json
.Replace("\\\\", "/")
.Replace("\\", "/");
}

try
{
return JsonConvert.DeserializeObject<T>(json);
return settings != null
? JsonConvert.DeserializeObject<T>(json, settings)
: JsonConvert.DeserializeObject<T>(json);
}
catch (Exception)
{
Expand Down

0 comments on commit 729092e

Please sign in to comment.