Skip to content
This repository has been archived by the owner on Oct 15, 2024. It is now read-only.

Commit

Permalink
v3.0.0-rc.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Chasmical committed Jul 9, 2021
1 parent 87eab7a commit 190f3d5
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 0 deletions.
19 changes: 19 additions & 0 deletions RogueLibsCore/Patches/Patches_Misc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ public void PatchMisc()
// IDoFixedUpdate.FixedUpdate
Patcher.Postfix(typeof(Updater), nameof(Updater.FixedUpdate));

// load prepared AudioClips
Patcher.Prefix(typeof(AudioHandler), nameof(AudioHandler.SetupDics), nameof(AudioHandler_SetupDics_Prefix));
Patcher.Postfix(typeof(AudioHandler), nameof(AudioHandler.SetupDics));

// remove 99 nuggets limit
Patcher.Prefix(typeof(Unlocks), nameof(Unlocks.AddNuggets));
}
Expand Down Expand Up @@ -149,6 +153,21 @@ public static void Updater_FixedUpdate()
catch (Exception e) { RogueFramework.LogError(e, "IDoFixedUpdate.FixedUpdate", obj, item); }
}

public static void AudioHandler_SetupDics_Prefix(AudioHandler __instance, ref bool __state)
=> __state = __instance.loadedDics;
internal static List<AudioClip> preparedClips = new List<AudioClip>();
public static void AudioHandler_SetupDics(AudioHandler __instance, ref bool __state)
{
if (__state) return;
foreach (AudioClip clip in preparedClips)
{
__instance.audioClipRealList.Add(clip);
__instance.audioClipList.Add(clip.name);
__instance.audioClipDic.Add(clip.name, clip);
}
preparedClips = null;
}

public static bool Unlocks_AddNuggets(int numNuggets)
{
GameController.gameController.sessionDataBig.nuggets += numNuggets;
Expand Down
31 changes: 31 additions & 0 deletions RogueLibsCore/RogueLibs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using UnityEngine;
using System.IO;
using System.Threading;
using UnityEngine.Networking;
using BepInEx;

namespace RogueLibsCore
{
Expand Down Expand Up @@ -77,6 +81,33 @@ public static RogueSprite CreateCustomSprite(string name, SpriteScope scope, byt
return sprite;
}

internal static string audioCachePath;
public static AudioClip CreateCustomAudio(string name, byte[] rawData)
{
string myPath = Path.Combine(audioCachePath, name + ".ogg.request");
try
{
File.WriteAllBytes(myPath, rawData);

UnityWebRequest request = UnityWebRequestMultimedia.GetAudioClip("file:///" + myPath, AudioType.OGGVORBIS);
request.SendWebRequest();
while (!request.isDone) Thread.Sleep(1);
AudioClip clip = DownloadHandlerAudioClip.GetContent(request);
clip.name = name;
if (GameController.gameController?.audioHandler != null)
{
GameController.gameController.audioHandler.audioClipList.Add(name);
GameController.gameController.audioHandler.audioClipRealList.Add(clip);
GameController.gameController.audioHandler.audioClipDic.Add(name, clip);
}
else RogueLibsPlugin.preparedClips.Add(clip);
return clip;
}
finally
{
File.Delete(myPath);
}
}

public static CustomName CreateCustomName(string name, string type, CustomNameInfo info)
=> NameProvider.AddName(name, type, info);
Expand Down
8 changes: 8 additions & 0 deletions RogueLibsCore/RogueLibsPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using UnityEngine;
using BepInEx;
using HarmonyLib;
using System.IO;

namespace RogueLibsCore
{
Expand All @@ -23,6 +24,13 @@ public void Awake()
RogueFramework.Plugin = this;
RogueFramework.Logger = Logger;

RogueLibs.audioCachePath = Path.Combine(Paths.CachePath, "RogueLibs Audio");
Directory.CreateDirectory(RogueLibs.audioCachePath);
foreach (string file in Directory.EnumerateFiles(RogueLibs.audioCachePath))
File.Delete(file);
foreach (string directory in Directory.EnumerateDirectories(RogueLibs.audioCachePath))
Directory.Delete(directory, true);

Patcher = new RoguePatcher(this) { EnableStopwatch = true };

PatchItems();
Expand Down

0 comments on commit 190f3d5

Please sign in to comment.