Skip to content

Commit

Permalink
Merge pull request #1 from SB15-MD/master
Browse files Browse the repository at this point in the history
Enable Cinema only on specific difficulties, default all, and add support for Miku and Christmas theme
  • Loading branch information
ALLMarvelous authored Jan 11, 2024
2 parents 96267df + 49785df commit 6c6a347
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 12 deletions.
16 changes: 13 additions & 3 deletions CinemaInfo.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
using CustomAlbums;
using Ionic.Zip;
using Newtonsoft.Json.Linq;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Assets.Scripts.Database;
using MelonLoader;
using Unity.Collections.LowLevel.Unsafe;

namespace Cinema
{
Expand All @@ -12,10 +17,10 @@ public class CinemaInfo

private string _fileName = null;
private float _opacity;

private List<int> _activateDifficulties = new List<int> { 1, 2, 3, 4, 5 };
public string FilePath
{
get { return _fileName == null ? null : $"{album.BasePath}/{_fileName}".Replace('\\', '/'); }
get { return _fileName == null ? null : $"{album.BasePath}/{_fileName}".Replace('\\', '/'); }
}

public float Opacity
Expand All @@ -25,7 +30,10 @@ public float Opacity

public bool CinemaEnabled
{
get { return _fileName != null; }
get
{
return _fileName != null && _activateDifficulties.Contains(GlobalDataBase.s_DbBattleStage.selectedDifficulty);
}
}

public CinemaInfo(Album customAlbum)
Expand All @@ -37,6 +45,8 @@ public CinemaInfo(Album customAlbum)

_fileName = jsonData["file_name"].ToString();
_opacity = float.Parse(jsonData["opacity"].ToString());
if (!jsonData.TryGetValue("difficulties", out var list)) return;
_activateDifficulties = list.Values<int>().ToList();
}

public static JObject LoadFromArchive(string filePath)
Expand Down
38 changes: 32 additions & 6 deletions Main.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
using Assets.Scripts.Database;
using System;
using Assets.Scripts.Database;
using Assets.Scripts.PeroTools.Commons;
using CustomAlbums;
using FormulaBase;
using HarmonyLib;
using MelonLoader;
using System.IO;
using System.Linq;
using UnhollowerRuntimeLib;
using GameLogic;
using UnityEngine;
using UnityEngine.Video;
using Object = UnityEngine.Object;

namespace Cinema
{
Expand All @@ -17,6 +19,7 @@ public class Main : MelonMod
public static bool GameStarted = false;
public static VideoPlayer Player;
public static CinemaInfo CinInfo;
public static bool Christmas;

public static void InitCamera()
{
Expand All @@ -27,7 +30,7 @@ public static void InitCamera()
if (currentAlbum == null) return;

CinInfo = new CinemaInfo(currentAlbum);
if (CinInfo.jsonData == null) return;
if (CinInfo.jsonData == null || !CinInfo.CinemaEnabled) return;

byte[] videoBytes = currentAlbum.IsPackaged ? CinInfo.GetArchiveVideoBytes() : File.ReadAllBytes(CinInfo.FilePath);
File.WriteAllBytes(Application.persistentDataPath + "/cinema.mp4", videoBytes);
Expand Down Expand Up @@ -67,7 +70,9 @@ public static void InitCamera()

SingletonMonoBehaviour<GameSceneContainer>.instance.sprLightness.color = new Color(0, 0, 0, 0);

HideAll(currentAlbum.Info.scene);
// Support for Miku scene and Christmas scene
var sceneNumber = currentAlbum.Info.scene.Split('_')[1];
HideAll($"scene_{sceneNumber}{(Christmas && sceneNumber == "05" ? "_christmas" : string.Empty)}");
}

public static void HideAll(string sceneName)
Expand All @@ -94,21 +99,42 @@ private static void Postfix()
}
}

[HarmonyPatch(typeof(GameMusicScene), nameof(GameMusicScene.SceneFestival))]
internal static class SceneFestival_Patch
{
[HarmonyFinalizer]
private static void Finalizer(string __result)
{
// Checks if Christmas scene
Main.Christmas = __result.EndsWith("christmas");
}
}

[HarmonyPatch(typeof(SceneChangeController), "OnControllerStart")]
internal static class OnControllerStart_Patch
{
[HarmonyPrefix]
private static void Prefix()
{
if (Main.Player == null) return;
Main.HideAll($"scene_0{SceneChangeController.curScene}");

// Support for Miku scene and Christmas scene
var sceneSuffix = SceneChangeController.curScene.ToString().Length == 1
? $"0{SceneChangeController.curScene}"
: SceneChangeController.curScene.ToString();
Main.HideAll($"scene_{sceneSuffix}{(Main.Christmas && sceneSuffix == "05" ? "_christmas" : string.Empty)}");
}

[HarmonyPostfix]
private static void Postfix()
{
if (Main.Player == null) return;
Main.HideAll($"scene_0{SceneChangeController.curScene}");

// Support for Miku scene and Christmas scene
var sceneSuffix = SceneChangeController.curScene.ToString().Length == 1
? $"0{SceneChangeController.curScene}"
: SceneChangeController.curScene.ToString();
Main.HideAll($"scene_{sceneSuffix}{(Main.Christmas && sceneSuffix == "05" ? "_christmas" : string.Empty)}");
}
}

Expand Down
6 changes: 3 additions & 3 deletions Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.1.3.0")]
[assembly: AssemblyFileVersion("1.1.3.0")]
[assembly: MelonInfo(typeof(Cinema.Main), "Cinema", "1.1.3", "AshtonMemer")]
[assembly: AssemblyVersion("1.1.4.0")]
[assembly: AssemblyFileVersion("1.1.4.0")]
[assembly: MelonInfo(typeof(Cinema.Main), "Cinema", "1.1.4", "AshtonMemer")]
[assembly: MelonGame("PeroPeroGames", "MuseDash")]
[assembly: MelonColor(System.ConsoleColor.DarkYellow)]

0 comments on commit 6c6a347

Please sign in to comment.