Skip to content

Commit

Permalink
Update to .Net4.7.2
Browse files Browse the repository at this point in the history
Add SceneManagerPatcher
Fix Stuff for it to work correctly
- Add CueHolder
Up Version Number
  • Loading branch information
SFGrenade committed Jun 7, 2021
1 parent 8179f11 commit 9de8d8b
Show file tree
Hide file tree
Showing 13 changed files with 746 additions and 101 deletions.
31 changes: 17 additions & 14 deletions Generics/FullSettingsMod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,24 @@

namespace SFCore.Generics
{
public abstract class FullSettingsMod<TSave, TGlobal> : Mod where TSave : ModSettings, new() where TGlobal : ModSettings, new()
public abstract class FullSettingsMod<TSave, TGlobal> : Mod, ILocalSettings<TSave>, IGlobalSettings<TGlobal> where TSave : new() where TGlobal : new()
{
public override ModSettings SaveSettings
{
get => _saveSettings;
set => _saveSettings = (TSave) value;
}
public override ModSettings GlobalSettings
{
get => _globalSettings;
set => _globalSettings = (TGlobal) value;
}
protected TSave _saveSettings = new TSave();
protected Type _saveSettingsType = typeof(TSave);
protected TGlobal _globalSettings = new TGlobal();
// The global settings for this mod. The settings load will only occur once
// so a static field should be used to prevent loss of data
public static TGlobal _globalSettings { get; protected set; }
// Implement the GlobalSettings interface.
// This method gets called when the mod loader loads the global settings.
public void OnLoadGlobal(TGlobal s) => _globalSettings = s;
// This method gets called when the mod loader needs to save the global settings.
public TGlobal OnSaveGlobal() => _globalSettings;

// The save data specific to a certain savefile. This setting will be loaded each time a save is opened.
public TSave _saveSettings { get; protected set; }
// Implement the LocalSettings interface.
// This method gets called when a save is loaded.
public void OnLoadLocal(TSave s) => this._saveSettings = s;
// This method gets called when the player saves their file.
public TSave OnSaveLocal() => this._saveSettings;

public FullSettingsMod() {}
public FullSettingsMod(string name) : base(name) {}
Expand Down
20 changes: 10 additions & 10 deletions Generics/GlobalSettingsMod.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
using System;
using Modding;
using Modding;

namespace SFCore.Generics
{
public abstract class GlobalSettingsMod<TGlobal> : Mod where TGlobal : ModSettings, new()
public abstract class GlobalSettingsMod<TGlobal> : Mod, IGlobalSettings<TGlobal> where TGlobal : new()
{
public override ModSettings GlobalSettings
{
get => _globalSettings;
set => _globalSettings = (TGlobal) value;
}
protected TGlobal _globalSettings = new TGlobal();
protected Type _globalSettingsType = typeof(TGlobal);
// The global settings for this mod. The settings load will only occur once
// so a static field should be used to prevent loss of data
public static TGlobal _globalSettings { get; protected set; }
// Implement the GlobalSettings interface.
// This method gets called when the mod loader loads the global settings.
public void OnLoadGlobal(TGlobal s) => _globalSettings = s;
// This method gets called when the mod loader needs to save the global settings.
public TGlobal OnSaveGlobal() => _globalSettings;

public GlobalSettingsMod() { }
public GlobalSettingsMod(string name) : base(name) { }
Expand Down
19 changes: 9 additions & 10 deletions Generics/SaveSettingsMod.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
using System;
using Modding;
using Modding;

namespace SFCore.Generics
{
public abstract class SaveSettingsMod<TSave> : Mod where TSave : ModSettings, new()
public abstract class SaveSettingsMod<TSave> : Mod, ILocalSettings<TSave> where TSave : new()
{
public override ModSettings SaveSettings
{
get => _saveSettings;
set => _saveSettings = (TSave) value;
}
protected TSave _saveSettings = new TSave();
protected Type _saveSettingsType = typeof(TSave);
// The save data specific to a certain savefile. This setting will be loaded each time a save is opened.
public TSave _saveSettings { get; protected set; }
// Implement the LocalSettings interface.
// This method gets called when a save is loaded.
public void OnLoadLocal(TSave s) => this._saveSettings = s;
// This method gets called when the player saves their file.
public TSave OnSaveLocal() => this._saveSettings;

public SaveSettingsMod() { }
public SaveSettingsMod(string name) : base(name) { }
Expand Down
9 changes: 5 additions & 4 deletions ItemHelper.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using SFCore.Utils;
using System;
using SFCore.Utils;
using UnityEngine;
using HutongGames.PlayMaker;
using HutongGames.PlayMaker.Actions;
Expand Down Expand Up @@ -59,9 +60,9 @@ static ItemHelper()

langStrings = new LanguageStrings(Assembly.GetExecutingAssembly(), "SFCore.Resources.Language.json", Encoding.UTF8);

ModHooks.Instance.LanguageGetHook += LanguageGetHook;
ModHooks.Instance.GetPlayerBoolHook += GetPlayerBoolHook;
ModHooks.Instance.GetPlayerIntHook += GetPlayerIntHook;
ModHooks.LanguageGetHook += LanguageGetHook;
ModHooks.GetPlayerBoolHook += GetPlayerBoolHook;
ModHooks.GetPlayerIntHook += GetPlayerIntHook;
On.GameCameras.Start += GameCamerasOnStart;
}

Expand Down
4 changes: 3 additions & 1 deletion MonoBehaviours/BlurPlanePatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ public void Start()
blurPlaneMaterials[0].SetInt(Shader.PropertyToID("_StencilReadMask"), 255);
}

var bp = gameObject.AddComponent<BlurPlane>();
var bp = gameObject.GetComponent<BlurPlane>();
if (bp == null)
bp = gameObject.AddComponent<BlurPlane>();
var mr = gameObject.GetComponent<MeshRenderer>();
mr.materials = blurPlaneMaterials;
mr.material = blurPlaneMaterials[0];
Expand Down
61 changes: 61 additions & 0 deletions MonoBehaviours/CueHolder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using HutongGames.PlayMaker.Actions;
using SFCore.Utils;
using UnityEngine;
using UnityEngine.Audio;

namespace SFCore.MonoBehaviours
{
internal static class CueHolder
{
public static Dictionary<string, MusicCue> MusicCues = new Dictionary<string, MusicCue>();
public static Dictionary<string, AtmosCue> AtmosCues = new Dictionary<string, AtmosCue>();

public static MusicCue GetMusicCue(string set, AudioMixerSnapshot snapshot, AudioClip[] clips, SceneManagerPatcher.MusicChannelSync[] syncs)
{
if (!MusicCues.ContainsKey(set))
{
var tmpMC = ScriptableObject.CreateInstance<MusicCue>();
tmpMC.SetAttr<MusicCue, string>("originalMusicEventName", "CROSSROADS");
tmpMC.SetAttr<MusicCue, int>("originalMusicTrackNumber", 2);
tmpMC.SetAttr<MusicCue, AudioMixerSnapshot>("snapshot", snapshot);
tmpMC.SetAttr<MusicCue, MusicCue.Alternative[]>("alternatives", null);
MusicCue.MusicChannelInfo[] musicChannelInfos = new MusicCue.MusicChannelInfo[]
{
new MusicCue.MusicChannelInfo(), new MusicCue.MusicChannelInfo(),
new MusicCue.MusicChannelInfo(), new MusicCue.MusicChannelInfo(),
new MusicCue.MusicChannelInfo(), new MusicCue.MusicChannelInfo()
};
musicChannelInfos[(int) MusicChannels.Main].SetAttr("clip", clips[(int) MusicChannels.Main]);
musicChannelInfos[(int) MusicChannels.Action].SetAttr("clip", clips[(int) MusicChannels.Action]);
musicChannelInfos[(int) MusicChannels.Sub].SetAttr("clip", clips[(int) MusicChannels.Sub]);
musicChannelInfos[(int) MusicChannels.Tension].SetAttr("clip", clips[(int) MusicChannels.Tension]);
musicChannelInfos[(int) MusicChannels.MainAlt].SetAttr("clip", clips[(int) MusicChannels.MainAlt]);
musicChannelInfos[(int) MusicChannels.Extra].SetAttr("clip", clips[(int) MusicChannels.Extra]);
musicChannelInfos[(int) MusicChannels.Main].SetAttr("sync", (MusicChannelSync) syncs[(int) MusicChannels.Main]);
musicChannelInfos[(int) MusicChannels.Action].SetAttr("sync", (MusicChannelSync) syncs[(int) MusicChannels.Action]);
musicChannelInfos[(int) MusicChannels.Sub].SetAttr("sync", (MusicChannelSync) syncs[(int) MusicChannels.Sub]);
musicChannelInfos[(int) MusicChannels.Tension].SetAttr("sync", (MusicChannelSync) syncs[(int) MusicChannels.Tension]);
musicChannelInfos[(int) MusicChannels.MainAlt].SetAttr("sync", (MusicChannelSync) syncs[(int) MusicChannels.MainAlt]);
musicChannelInfos[(int) MusicChannels.Extra].SetAttr("sync", (MusicChannelSync) syncs[(int) MusicChannels.Extra]);
tmpMC.SetAttr<MusicCue, MusicCue.MusicChannelInfo[]>("channelInfos", musicChannelInfos);
MusicCues.Add(set, tmpMC);
}
return MusicCues[set];
}
public static AtmosCue GetAtmosCue(string set, AudioMixerSnapshot snapshot, bool[] isChannelEnabled)
{
if (!AtmosCues.ContainsKey(set))
{
var tmpAC = ScriptableObject.CreateInstance<AtmosCue>();
tmpAC.SetAttr("snapshot", snapshot);
tmpAC.SetAttr("isChannelEnabled", isChannelEnabled);
AtmosCues.Add(set, tmpAC);
}
return AtmosCues[set];
}
}
}
9 changes: 4 additions & 5 deletions MonoBehaviours/PatchMusicRegions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ namespace SFCore.MonoBehaviours
public class PatchMusicRegions : MonoBehaviour
{
private static AudioMixer am = null;
private static Dictionary<string, MusicCue> cues = new Dictionary<string, MusicCue>();

public bool useAlts = false;
public static bool altMusic = false;
Expand Down Expand Up @@ -63,16 +62,16 @@ public void Start()
mr.exitMusicSnapshot = null;
mr.exitTrackEvent = "";
mr.exitTransitionTime = 0;
if (!cues.ContainsKey(MusicRegionSet))
if (!CueHolder.MusicCues.ContainsKey(MusicRegionSet))
{
var tmpMC = ScriptableObject.CreateInstance<MusicCue>();
tmpMC.SetAttr<MusicCue, string>("originalMusicEventName", EnterTrackEvent);
tmpMC.SetAttr<MusicCue, int>("originalMusicTrackNumber", 2);
tmpMC.SetAttr<MusicCue, AudioMixerSnapshot>("snapshot", am.FindSnapshot("Normal"));
tmpMC.SetAttr<MusicCue, AudioMixerSnapshot>("snapshot", snapshot);
tmpMC.SetAttr<MusicCue, MusicCue.Alternative[]>("alternatives", null);
cues.Add(MusicRegionSet, tmpMC);
CueHolder.MusicCues.Add(MusicRegionSet, tmpMC);
}
mr.enterMusicCue = cues[MusicRegionSet];
mr.enterMusicCue = CueHolder.MusicCues[MusicRegionSet];

MusicCue.MusicChannelInfo[] musicChannelInfos = new MusicCue.MusicChannelInfo[]
{
Expand Down
Loading

0 comments on commit 9de8d8b

Please sign in to comment.