Decompiled source of CustomCinematicsReplacer v1.0.3

CustomCinematicsReplacer.dll

Decompiled a day ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using UnityEngine;
using UnityEngine.Video;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("CustomCinematicsReplacer")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("CustomCinematicsReplacer")]
[assembly: AssemblyCopyright("Copyright ©  2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("fffcc2a3-0481-4971-8196-e21e9fb8578f")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
[BepInPlugin("Shapoff.CustomCinematicsReplacer", "Custom Cinematics Replacer", "1.0.3")]
public class CustomCinematicsReplacer : BaseUnityPlugin
{
	public static CustomCinematicsReplacer Instance;

	private ConfigEntry<bool> modEnabled;

	private ConfigEntry<float> volume;

	private ConfigEntry<bool> logCinematicDetection;

	private ConfigEntry<bool> disableSubtitles;

	private ConfigEntry<string> disableSubtitlesFor;

	private string videoFolder;

	public static VideoEntry currentVideo;

	private void Awake()
	{
		//IL_0057: Unknown result type (might be due to invalid IL or missing references)
		//IL_0061: Expected O, but got Unknown
		//IL_0120: Unknown result type (might be due to invalid IL or missing references)
		//IL_0126: Expected O, but got Unknown
		Instance = this;
		modEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Включить замену синематиков (true/false)");
		volume = ((BaseUnityPlugin)this).Config.Bind<float>("General", "Volume", 1f, new ConfigDescription("Громкость видео (0.0 - 1.0)", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>()));
		disableSubtitles = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "DisableSubtitles", false, "Главный выключатель субтитров в роликах (true/false).\nЕсли true и список ниже пуст — субтитры отключаются ВЕЗДЕ.\nЕсли true и список заполнен — субтитры отключаются ТОЛЬКО в указанных роликах.");
		disableSubtitlesFor = ((BaseUnityPlugin)this).Config.Bind<string>("General", "DisableSubtitlesFor", "", "Список роликов, где отключить субтитры (через запятую).\nРаботает только если DisableSubtitles = true.\nЕсли пусто — субтитры отключаются везде.\nПример: intro, credits");
		logCinematicDetection = ((BaseUnityPlugin)this).Config.Bind<bool>("Logging", "LogCinematicDetection", false, "Логировать обнаруженные синематики в консоль (true/false).\nИзвестные синематики: intro, outro, credits, ashlands, swamp, deepnorth, mountains, mistlands, blackforest, plains.\nЕсли в игре появится новый синематик — включите эту настройку, запустите игру и дождитесь его. Имя появится в логе BepInEx. Назовите свой видеофайл так же — и он заменит этот синематик.");
		videoFolder = Path.Combine(Paths.PluginPath, "CustomCinematicsReplacer");
		Directory.CreateDirectory(videoFolder);
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Custom Cinematics Replacer loaded");
		((BaseUnityPlugin)this).Logger.LogInfo((object)("Own folder: " + videoFolder));
		Harmony val = new Harmony("Shapoff.CustomCinematicsReplacer");
		val.PatchAll();
	}

	public void Log(string text)
	{
		((BaseUnityPlugin)this).Logger.LogInfo((object)text);
	}

	public void LogDetection(string text)
	{
		if (logCinematicDetection.Value)
		{
			((BaseUnityPlugin)this).Logger.LogInfo((object)text);
		}
	}

	public bool IsModEnabled()
	{
		((BaseUnityPlugin)this).Config.Reload();
		return modEnabled.Value;
	}

	public bool AreSubtitlesDisabledFor(string cinematicName)
	{
		((BaseUnityPlugin)this).Config.Reload();
		if (!disableSubtitles.Value)
		{
			return false;
		}
		if (string.IsNullOrEmpty(disableSubtitlesFor.Value))
		{
			return true;
		}
		if (string.IsNullOrEmpty(cinematicName))
		{
			return false;
		}
		string value = cinematicName.Replace("$cinematics_", "").Replace("$biome_", "").Replace("$boss_", "");
		string[] array = disableSubtitlesFor.Value.Split(new char[1] { ',' });
		string[] array2 = array;
		foreach (string text in array2)
		{
			string text2 = text.Trim();
			if (text2.Equals(cinematicName, StringComparison.OrdinalIgnoreCase) || text2.Equals(value, StringComparison.OrdinalIgnoreCase))
			{
				return true;
			}
		}
		return false;
	}

	public float GetVolume()
	{
		((BaseUnityPlugin)this).Config.Reload();
		return Mathf.Clamp01(volume.Value);
	}

	public void ReplaceCinematic(VideoEntry video)
	{
		//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e7: Expected O, but got Unknown
		//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fa: Expected O, but got Unknown
		if (!IsModEnabled() || video == null || (Object)(object)CinematicsManager.s_instance == (Object)null)
		{
			return;
		}
		string text = FindVideoFile(video.m_name);
		if (text == null)
		{
			Log("No replacement: " + video.m_name);
			return;
		}
		VideoPlayer videoPlayer = CinematicsManager.s_instance.m_videoPlayer;
		if (!((Object)(object)videoPlayer == (Object)null))
		{
			Log("Replacing: " + video.m_name + " -> " + Path.GetFileName(text));
			videoPlayer.Stop();
			videoPlayer.source = (VideoSource)1;
			videoPlayer.url = text;
			videoPlayer.playOnAwake = false;
			videoPlayer.waitForFirstFrame = true;
			videoPlayer.audioOutputMode = (VideoAudioOutputMode)2;
			videoPlayer.prepareCompleted -= new EventHandler(Prepared);
			videoPlayer.prepareCompleted += new EventHandler(Prepared);
			videoPlayer.Prepare();
		}
	}

	private string FindVideoFile(string cinematicName)
	{
		if (string.IsNullOrEmpty(cinematicName))
		{
			return null;
		}
		string text = SearchInFolder(videoFolder, cinematicName);
		if (text != null)
		{
			Log("Found in own folder: " + text);
			return text;
		}
		string[] directories = Directory.GetDirectories(Paths.PluginPath);
		foreach (string text2 in directories)
		{
			if (!(text2 == videoFolder))
			{
				text = SearchInFolder(text2, cinematicName);
				if (text != null)
				{
					Log("Found in other folder: " + text);
					return text;
				}
			}
		}
		text = SearchInFolder(Paths.PluginPath, cinematicName);
		if (text != null)
		{
			Log("Found in plugins root: " + text);
			return text;
		}
		return null;
	}

	private string SearchInFolder(string folder, string cinematicName)
	{
		if (!Directory.Exists(folder))
		{
			return null;
		}
		string text = Path.Combine(folder, cinematicName + ".mp4");
		if (File.Exists(text))
		{
			return text;
		}
		string text2 = cinematicName;
		text2 = text2.Replace("$cinematics_", "");
		text2 = text2.Replace("$biome_", "");
		text2 = text2.Replace("$boss_", "");
		string text3 = Path.Combine(folder, text2 + ".mp4");
		if (File.Exists(text3))
		{
			return text3;
		}
		return null;
	}

	private void Prepared(VideoPlayer player)
	{
		player.SetDirectAudioVolume((ushort)0, GetVolume());
		player.Play();
		Log("Custom cinematic playing");
	}
}
[HarmonyPatch(typeof(CinematicsManager))]
public static class CinematicsManagerPatch
{
	[HarmonyPatch("Play", new Type[]
	{
		typeof(VideoEntry),
		typeof(VideoCompleteAction)
	})]
	[HarmonyPostfix]
	public static void AfterPlay(VideoEntry video)
	{
		if (video != null)
		{
			CustomCinematicsReplacer.Instance.LogDetection("Detected: " + video.m_name);
			CustomCinematicsReplacer.currentVideo = video;
			DelayedReplace();
		}
	}

	private static void DelayedReplace()
	{
		if (CustomCinematicsReplacer.currentVideo != null)
		{
			CustomCinematicsReplacer.Instance.ReplaceCinematic(CustomCinematicsReplacer.currentVideo);
		}
	}
}
[HarmonyPatch(typeof(CinematicsManager))]
public static class CinematicsManager_Play_Subtitles_Patch
{
	private static Dictionary<string, List<SubtitleEntry>> originalSubtitles = new Dictionary<string, List<SubtitleEntry>>();

	[HarmonyPatch("Play", new Type[]
	{
		typeof(VideoEntry),
		typeof(VideoCompleteAction)
	})]
	[HarmonyPrefix]
	public static void Prefix(VideoEntry video)
	{
		if ((Object)(object)CustomCinematicsReplacer.Instance == (Object)null || video == null)
		{
			return;
		}
		if (!originalSubtitles.ContainsKey(video.m_name))
		{
			originalSubtitles[video.m_name] = ((video.m_subtitles != null) ? new List<SubtitleEntry>(video.m_subtitles) : new List<SubtitleEntry>());
		}
		if (CustomCinematicsReplacer.Instance.AreSubtitlesDisabledFor(video.m_name))
		{
			if (video.m_subtitles != null)
			{
				video.m_subtitles.Clear();
			}
			return;
		}
		if (video.m_subtitles == null)
		{
			video.m_subtitles = new List<SubtitleEntry>();
		}
		video.m_subtitles.Clear();
		video.m_subtitles.AddRange(originalSubtitles[video.m_name]);
	}
}