Decompiled source of WKCinema v0.2.31
BepInEx/plugins/WKCinema/WKCinema.dll
Decompiled 5 days ago
The result has been truncated due to the large size, download it to view full contents!
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.IO; using System.Linq; using System.Reflection; using System.Reflection.Emit; using System.Runtime.CompilerServices; using System.Security.Cryptography; using System.Text; using BepInEx; using BepInEx.Configuration; using HarmonyLib; using Steamworks; using UnityEngine; using UnityEngine.Audio; using UnityEngine.Rendering; using UnityEngine.SceneManagement; using UnityEngine.Sprites; using WKModUI; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: AssemblyTitle("WK Cinema")] [assembly: AssemblyDescription("Independent camera and filming tools for White Knuckle")] [assembly: AssemblyCompany("Ilylllk1n5")] [assembly: AssemblyFileVersion("0.2.31.0")] [assembly: AssemblyVersion("0.2.31.0")] namespace WKModUI { internal static class SharedLanguage { internal const string Protocol = "ilya.whiteknuckle.shared-language.v1"; private static Dictionary<string, object> State => AppDomain.CurrentDomain.GetData("ilya.whiteknuckle.shared-language.v1") as Dictionary<string, object>; internal static string Current { get { Dictionary<string, object> state = State; if (state != null) { return (string)state["resolved"]; } return "en"; } } internal static string Label { get { if (!(Current == "ru")) { return "ENG"; } return "RU"; } } private static SortedDictionary<string, object[]> Clients(Dictionary<string, object> state) { return (SortedDictionary<string, object[]>)state["clients"]; } internal static string Normalize(string language) { language = (language ?? "").Trim().ToLowerInvariant().Replace('_', '-'); switch (language) { default: if (!language.StartsWith("ru-", StringComparison.Ordinal)) { return "en"; } break; case "ru": case "russian": case "русский": break; } return "ru"; } private static string Choice(string value) { if (!(value == "ru") && !(value == "en")) { return "auto"; } return value; } internal static void Connect(string id, Action<string> apply, Func<bool> visible, string automatic, string legacy, Func<object[]> settings, Action<Exception> error) { Dictionary<string, object> dictionary = State; if (dictionary == null) { object[] array = settings(); dictionary = new Dictionary<string, object>(StringComparer.Ordinal) { { "clients", new SortedDictionary<string, object[]>(StringComparer.Ordinal) }, { "read", array[1] }, { "write", array[2] }, { "choice", Choice(((Func<string>)array[1])()) }, { "allowLegacy", !(bool)array[0] }, { "resolved", "en" } }; AppDomain.CurrentDomain.SetData("ilya.whiteknuckle.shared-language.v1", dictionary); } Clients(dictionary)[id] = new object[4] { apply, visible, Normalize(automatic), error }; if ((bool)dictionary["allowLegacy"] && (legacy == "ru" || legacy == "en")) { SetChoice(legacy); } Refresh(dictionary); Apply(Clients(dictionary)[id], (string)dictionary["resolved"]); } internal static void Disconnect(string id) { Dictionary<string, object> state = State; if (state != null) { Clients(state).Remove(id); Refresh(state); } } internal static void Automatic(string id, string language) { Dictionary<string, object> state = State; if (state != null && Clients(state).TryGetValue(id, out var value)) { value[2] = Normalize(language); state["choice"] = Choice(((Func<string>)state["read"])()); Refresh(state); } } internal static void Toggle() { SetChoice((Current == "ru") ? "en" : "ru"); } internal static void SetChoice(string choice) { if (choice != "auto" && choice != "ru" && choice != "en") { throw new ArgumentException("Expected auto, ru or en.", "choice"); } Dictionary<string, object> state = State; if (state == null) { return; } state["allowLegacy"] = false; state["choice"] = choice; try { ((Action<string>)state["write"])(choice); } catch (Exception exception) { foreach (object[] value in Clients(state).Values) { Report(value, exception); } } Refresh(state); } internal static bool OwnsButton(string id) { Dictionary<string, object> state = State; if (state == null) { return false; } foreach (KeyValuePair<string, object[]> item in Clients(state)) { bool flag = false; try { flag = ((Func<bool>)item.Value[1])(); } catch (Exception exception) { Report(item.Value, exception); } if (flag) { return item.Key == id; } } return false; } private static void Refresh(Dictionary<string, object> state) { string text = (string)state["choice"]; if (text == "auto") { text = "en"; using SortedDictionary<string, object[]>.ValueCollection.Enumerator enumerator = Clients(state).Values.GetEnumerator(); if (enumerator.MoveNext()) { text = (string)enumerator.Current[2]; } } if ((string)state["resolved"] == text) { return; } state["resolved"] = text; foreach (object[] item in new List<object[]>(Clients(state).Values)) { Apply(item, text); } } private static void Apply(object[] client, string language) { try { ((Action<string>)client[0])(language); } catch (Exception exception) { Report(client, exception); } } private static void Report(object[] client, Exception exception) { if (client[3] is Action<Exception> action) { try { action(exception); } catch (Exception) { } } } } internal static class SharedLanguageConfig { internal const string Filename = "ilya.whiteknuckle.shared-language.cfg"; internal static object[] Open(string directory) { //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Expected O, but got Unknown //IL_0070: Unknown result type (might be due to invalid IL or missing references) //IL_007a: Expected O, but got Unknown string text = Path.Combine(directory, "ilya.whiteknuckle.shared-language.cfg"); bool flag = File.Exists(text); ConfigFile file = new ConfigFile(text, false) { SaveOnConfigSet = false }; ConfigEntry<string> choice = file.Bind<string>("General", "Language", "auto", new ConfigDescription("Language for all compatible Ilyushkins WK mods. RU/ENG switches every connected mod. auto follows the game; ru = Russian; en = English. / Язык всех совместимых WK-модов Илюшкинса. RU/ENG переключает все подключённые моды. auto = язык игры; ru = русский; en = английский.", (AcceptableValueBase)(object)new AcceptableValueList<string>(new string[3] { "auto", "ru", "en" }), Array.Empty<object>())); if (!flag) { file.Save(); } return new object[3] { flag, (Func<string>)(() => choice.Value), (Action<string>)delegate(string value) { choice.Value = value; file.Save(); } }; } } } namespace WhiteKnuckle.Cinema { internal sealed class BlackoutGlobals { private static readonly string[] Floats = new string[3] { "_LIGHTMAPMULT", "_LIGHTOFFSET", "_FULLBRIGHT" }; private static readonly string[] Colors = new string[3] { "_WORLDMIN", "_FOGCOLORTOP", "_FOGCOLORBOTTOM" }; private readonly float[] floats = new float[Floats.Length]; private readonly Color[] colors = (Color[])(object)new Color[Colors.Length]; private int dither; private Vector4 fog; private bool saved; internal void Apply() { //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_0047: Unknown result type (might be due to invalid IL or missing references) //IL_0071: Unknown result type (might be due to invalid IL or missing references) //IL_0076: Unknown result type (might be due to invalid IL or missing references) //IL_00b1: Unknown result type (might be due to invalid IL or missing references) //IL_00f4: Unknown result type (might be due to invalid IL or missing references) if (!saved) { for (int i = 0; i < floats.Length; i++) { floats[i] = Shader.GetGlobalFloat(Floats[i]); } for (int j = 0; j < colors.Length; j++) { colors[j] = Shader.GetGlobalColor(Colors[j]); } dither = Shader.GetGlobalInt("_DITHERMINIMUM"); fog = Shader.GetGlobalVector("_FOG"); saved = true; for (int k = 0; k < floats.Length; k++) { Shader.SetGlobalFloat(Floats[k], 0f); } for (int l = 0; l < colors.Length; l++) { Shader.SetGlobalColor(Colors[l], Color.black); } Shader.SetGlobalInt("_DITHERMINIMUM", 0); Shader.SetGlobalVector("_FOG", new Vector4(0f, 0f, 0f, fog.w)); } } internal void Restore() { //IL_004e: Unknown result type (might be due to invalid IL or missing references) //IL_0053: Unknown result type (might be due to invalid IL or missing references) //IL_006d: Unknown result type (might be due to invalid IL or missing references) //IL_00a7: Unknown result type (might be due to invalid IL or missing references) //IL_00c6: Unknown result type (might be due to invalid IL or missing references) //IL_00d8: Unknown result type (might be due to invalid IL or missing references) if (!saved) { return; } for (int i = 0; i < floats.Length; i++) { if (Shader.GetGlobalFloat(Floats[i]) == 0f) { Shader.SetGlobalFloat(Floats[i], floats[i]); } } for (int j = 0; j < colors.Length; j++) { if (Shader.GetGlobalColor(Colors[j]) == Color.black) { Shader.SetGlobalColor(Colors[j], colors[j]); } } if (Shader.GetGlobalInt("_DITHERMINIMUM") == 0) { Shader.SetGlobalInt("_DITHERMINIMUM", dither); } if (Shader.GetGlobalVector("_FOG") == new Vector4(0f, 0f, 0f, fog.w)) { Shader.SetGlobalVector("_FOG", fog); } saved = false; } } internal sealed class BlackoutMaterialRule { internal int Id; internal ShaderPropertyType Type; internal float Value; internal bool PreserveAlpha; private static readonly HashSet<string> Zero = new HashSet<string>(StringComparer.Ordinal) { "_Emission", "_EmissionMultiplier", "_EmissionMult", "_EmissionColor", "_Emissive", "_EmissiveColor", "_EmissiveAmount", "_BaseEmissive", "_FresnelGlow", "_Shimmer", "_ShimmerOver", "_ShimmerColor", "_Bright", "_Brightness", "_StaminaTextureEmissive", "_ReflectStrength", "_Glossiness", "_Metallic", "_OverlayAddAmount", "_EmissiveIgnoreLightmap", "_EmissiveIgnoreNegative" }; internal static BlackoutMaterialRule[] For(Shader shader) { //IL_0078: Unknown result type (might be due to invalid IL or missing references) //IL_007d: Unknown result type (might be due to invalid IL or missing references) //IL_00d6: Unknown result type (might be due to invalid IL or missing references) //IL_00d9: Invalid comparison between Unknown and I4 //IL_00ef: Unknown result type (might be due to invalid IL or missing references) //IL_00f1: Unknown result type (might be due to invalid IL or missing references) List<BlackoutMaterialRule> list = new List<BlackoutMaterialRule>(); string name = ((Object)shader).name; if (name.IndexOf("UI/", StringComparison.OrdinalIgnoreCase) >= 0 || name.IndexOf("TextMesh", StringComparison.OrdinalIgnoreCase) >= 0) { return list.ToArray(); } bool flag = name.IndexOf("Unlit", StringComparison.OrdinalIgnoreCase) >= 0 || name.IndexOf("SHDR_Beam", StringComparison.OrdinalIgnoreCase) >= 0 || name.IndexOf("Transparent Effects", StringComparison.OrdinalIgnoreCase) >= 0; for (int i = 0; i < shader.GetPropertyCount(); i++) { string propertyName = shader.GetPropertyName(i); ShaderPropertyType propertyType = shader.GetPropertyType(i); bool flag2 = flag && (propertyName == "_Color" || propertyName == "_TintColor" || propertyName == "_BaseColor"); bool flag3 = propertyName == "_Shading"; if ((Zero.Contains(propertyName) || flag2 || flag3) && (int)propertyType != 4) { list.Add(new BlackoutMaterialRule { Id = Shader.PropertyToID(propertyName), Type = propertyType, Value = (flag3 ? 1 : 0), PreserveAlpha = flag2 }); } } return list.ToArray(); } internal void Apply(MaterialPropertyBlock block, Material material) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0009: Unknown result type (might be due to invalid IL or missing references) //IL_000f: Invalid comparison between Unknown and I4 //IL_0034: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_0071: Unknown result type (might be due to invalid IL or missing references) //IL_0077: Invalid comparison between Unknown and I4 //IL_0039: Unknown result type (might be due to invalid IL or missing references) //IL_007a: Unknown result type (might be due to invalid IL or missing references) //IL_0080: Invalid comparison between Unknown and I4 //IL_005f: Unknown result type (might be due to invalid IL or missing references) //IL_0065: Unknown result type (might be due to invalid IL or missing references) if ((int)Type == 0 || (int)Type == 1) { Color val = (block.HasProperty(Id) ? block.GetColor(Id) : material.GetColor(Id)); block.SetColor(Id, new Color(0f, 0f, 0f, PreserveAlpha ? val.a : 0f)); } else if ((int)Type == 2 || (int)Type == 3) { block.SetFloat(Id, Value); } } } internal static class CameraMath { internal static bool Finite(double v) { if (!double.IsNaN(v)) { return !double.IsInfinity(v); } return false; } internal static double Clamp(double v, double lo, double hi) { return Math.Max(lo, Math.Min(hi, v)); } internal static double Smooth(double t) { t = Clamp(t, 0.0, 1.0); return t * t * (3.0 - 2.0 * t); } internal static double Progress(int frame, int frames) { return Clamp((double)frame / (double)Math.Max(1, frames), 0.0, 1.0); } internal static double Curve(double a, double b, double c, double d, double t) { return 0.5 * (2.0 * b + (0.0 - a + c) * t + (2.0 * a - 5.0 * b + 4.0 * c - d) * t * t + (0.0 - a + 3.0 * b - 3.0 * c + d) * t * t * t); } internal static double Angle(double start, double speed, double seconds, bool clockwise) { return Wrap(start + speed * seconds * (double)(clockwise ? 1 : (-1))); } internal static double Wrap(double angle) { return (angle % 360.0 + 360.0) % 360.0; } internal static void Orbit(double radius, double height, double angle, out double x, out double y, out double z) { if (!Finite(radius) || radius < 0.25 || !Finite(height) || !Finite(angle)) { throw new ArgumentOutOfRangeException("radius", "Invalid orbit coordinates"); } double num = Wrap(angle) * Math.PI / 180.0; x = radius * Math.Sin(num); y = height; z = radius * Math.Cos(num); } } internal sealed class CameraOrbit { private readonly CinemaPlugin p; private readonly TakeClock clock = new TakeClock(); private Camera camera; private double radius; private double height; private double speed; private double start; private bool clockwise; private bool loop; private float fov; internal bool Paused; internal bool HasCenter { get; private set; } internal Vector3 Center { get; private set; } internal int Revision { get; private set; } internal bool Playing { get; private set; } internal double DelayRemaining => clock.DelayRemaining; internal CameraOrbit(CinemaPlugin plugin) { p = plugin; } internal void SetCenter(Vector3 point) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Unknown result type (might be due to invalid IL or missing references) if (!CameraRoute.ValidPosition(point)) { p.Status = Loc.Text("Центр должен иметь конечные координаты в пределах ±1000000.", "Center coordinates must be finite and within ±1000000."); return; } p.StopTakes(); Center = point; HasCenter = true; Revision++; p.Status = Loc.Text("Центр облёта сохранён. Настрой радиус и скорость, затем запускай.", "Orbit center saved. Set the radius and speed, then start."); } internal void CaptureHere() { //IL_0038: Unknown result type (might be due to invalid IL or missing references) Camera viewCamera = CinemaPlugin.ViewCamera; if (!CL_GameManager.IsInGame() || (Object)(object)viewCamera == (Object)null) { p.Status = Loc.Text("Сначала начни забег.", "Start a run first."); } else { SetCenter(((Component)viewCamera).transform.position); } } internal void CaptureLookedAt() { //IL_0037: Unknown result type (might be due to invalid IL or missing references) //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_006a: Unknown result type (might be due to invalid IL or missing references) //IL_006f: Unknown result type (might be due to invalid IL or missing references) //IL_00fc: Unknown result type (might be due to invalid IL or missing references) //IL_0101: Unknown result type (might be due to invalid IL or missing references) //IL_0105: Unknown result type (might be due to invalid IL or missing references) //IL_00c1: Unknown result type (might be due to invalid IL or missing references) //IL_00af: Unknown result type (might be due to invalid IL or missing references) //IL_00b4: Unknown result type (might be due to invalid IL or missing references) Camera viewCamera = CinemaPlugin.ViewCamera; if (!CL_GameManager.IsInGame() || (Object)(object)viewCamera == (Object)null) { p.Status = Loc.Text("Сначала начни забег.", "Start a run first."); return; } RaycastHit[] array = Physics.RaycastAll(((Component)viewCamera).transform.position, ((Component)viewCamera).transform.forward, 10000f, -1, (QueryTriggerInteraction)1); RaycastHit? val = null; ENT_Player playerObject = ENT_Player.playerObject; RaycastHit[] array2 = array; RaycastHit value2; for (int i = 0; i < array2.Length; i++) { RaycastHit value = array2[i]; if ((Object)(object)playerObject != (Object)null && (Object)(object)((RaycastHit)(ref value)).transform != (Object)null && ((RaycastHit)(ref value)).transform.IsChildOf(((Component)playerObject).transform)) { continue; } if (val.HasValue) { float distance = ((RaycastHit)(ref value)).distance; value2 = val.Value; if (!(distance < ((RaycastHit)(ref value2)).distance)) { continue; } } val = value; } if (!val.HasValue) { p.Status = Loc.Text("Под взглядом нет поверхности. Подлети к центру и выбери «Центр здесь» или введи XYZ.", "No surface under the crosshair. Fly to the center and choose 'Center at camera', or enter XYZ."); return; } value2 = val.Value; SetCenter(((RaycastHit)(ref value2)).point); FitToCamera(); p.Status = Loc.Text("Центр выбран на поверхности объекта под взглядом. Его можно уточнить по XYZ.", "Center placed on the surface under the crosshair. Adjust its XYZ coordinates if needed."); } internal void FitToCamera() { //IL_0043: Unknown result type (might be due to invalid IL or missing references) //IL_0049: Unknown result type (might be due to invalid IL or missing references) //IL_004e: Unknown result type (might be due to invalid IL or missing references) //IL_0053: Unknown result type (might be due to invalid IL or missing references) //IL_0054: Unknown result type (might be due to invalid IL or missing references) //IL_005a: Unknown result type (might be due to invalid IL or missing references) //IL_0061: Unknown result type (might be due to invalid IL or missing references) //IL_0067: Unknown result type (might be due to invalid IL or missing references) //IL_00a0: Unknown result type (might be due to invalid IL or missing references) //IL_00cd: Unknown result type (might be due to invalid IL or missing references) //IL_00d4: Unknown result type (might be due to invalid IL or missing references) Camera viewCamera = CinemaPlugin.ViewCamera; if (!HasCenter || (Object)(object)viewCamera == (Object)null) { p.Status = Loc.Text("Сначала выбери центр облёта.", "Choose an orbit center first."); return; } p.StopTakes(); Vector3 val = ((Component)viewCamera).transform.position - Center; float num = Mathf.Sqrt(val.x * val.x + val.z * val.z); p.OrbitRadius.Value = Mathf.Clamp(num, 0.25f, 10000f); p.OrbitHeight.Value = Mathf.Clamp(val.y, -10000f, 10000f); if (num >= 0.25f) { p.OrbitStartAngle.Value = (float)CameraMath.Wrap(Math.Atan2(val.x, val.z) * 180.0 / Math.PI); } p.Status = Loc.Text("Радиус, высота и начальная сторона взяты по текущей камере.", "Radius, height and start angle copied from the current camera view."); } private bool Prepare() { if (!HasCenter) { p.Status = Loc.Text("Сначала выбери центр облёта.", "Choose an orbit center first."); return false; } if (!p.EnsureFreecam()) { return false; } p.StopTakes(); camera = CameraTools.FreeCamera; radius = p.OrbitRadius.Value; height = p.OrbitHeight.Value; speed = p.OrbitSpeed.Value; start = p.OrbitStartAngle.Value; clockwise = p.OrbitClockwise.Value; loop = p.OrbitLoop.Value; fov = camera.fieldOfView; return true; } internal void Preview() { //IL_0053: Unknown result type (might be due to invalid IL or missing references) if (Prepare()) { Apply(0.0); camera = null; p.Menu.Close(resume: true); p.Status = Loc.Text("Камера в начале круга. {0} — запустить облёт.", "Camera at the orbit start. {0} — start orbit.", p.OrbitPlayKey.Value); } } internal void Play() { //IL_0075: Unknown result type (might be due to invalid IL or missing references) if (Prepare()) { clock.Start(p.StartDelay.Value); Playing = true; Paused = false; Apply(0.0); p.Menu.Close(resume: true); p.Status = Loc.Text("Облёт запущен. Камера смотрит в центр. {0} — остановить.", "Orbit started. The camera faces the center. {0} — stop.", p.OrbitPlayKey.Value); } } internal void Tick() { if (!Playing) { return; } if ((Object)(object)camera == (Object)null || (Object)(object)camera != (Object)(object)CameraTools.FreeCamera) { Stop(); return; } clock.Maintain(); if (!p.HoldTake && !Paused) { double num = clock.Seconds; if (!loop) { num = Math.Min(num, 360.0 / speed); } Apply(num); if (!loop && num >= 360.0 / speed) { Stop(); p.Status = Loc.Text("Полный круг завершён. Камера осталась в начальном ракурсе.", "Full orbit complete. The camera is at the starting view."); } else { clock.Advance(); } } } private void Apply(double seconds) { //IL_0043: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_0049: Unknown result type (might be due to invalid IL or missing references) //IL_004e: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Unknown result type (might be due to invalid IL or missing references) //IL_0054: Unknown result type (might be due to invalid IL or missing references) //IL_0059: Unknown result type (might be due to invalid IL or missing references) CameraMath.Orbit(radius, height, CameraMath.Angle(start, speed, seconds, clockwise), out var x, out var y, out var z); Vector3 val = default(Vector3); ((Vector3)(ref val))..ctor((float)x, (float)y, (float)z); CameraTools.ApplyPose(camera, Center + val, Quaternion.LookRotation(-val, Vector3.up), fov); } internal void Stop() { Playing = false; Paused = false; clock.Stop(); camera = null; } internal void Clear() { Stop(); HasCenter = false; Revision++; } internal void Offset(float amount) { //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Unknown result type (might be due to invalid IL or missing references) if (HasCenter) { Center += Vector3.up * amount; Revision++; } } } internal struct CameraMark { internal Vector3 Position; internal Quaternion Rotation; internal float Fov; } internal sealed class CameraRoute { private readonly List<CameraMark> marks = new List<CameraMark>(); private readonly List<CameraMark[]> history = new List<CameraMark[]>(); private readonly CinemaPlugin p; private readonly TakeClock clock = new TakeClock(); private Camera camera; private float duration; internal bool Paused; internal bool Playing { get; private set; } internal double DelayRemaining => clock.DelayRemaining; internal int Revision { get; private set; } internal int Count => marks.Count; internal bool CanUndo => history.Count > 0; internal double Progress => CameraMath.Clamp(clock.Seconds / (double)Math.Max(1f, duration), 0.0, 1.0); internal CameraRoute(CinemaPlugin plugin) { p = plugin; } private bool Valid(int i) { if (i >= 0) { return i < marks.Count; } return false; } internal CameraMark At(int i) { return marks[i]; } private void Remember() { p.StopTakes(); if (history.Count == 20) { history.RemoveAt(0); } history.Add(marks.ToArray()); Revision++; } internal void Add() { //IL_005a: Unknown result type (might be due to invalid IL or missing references) //IL_005f: Unknown result type (might be due to invalid IL or missing references) //IL_006c: Unknown result type (might be due to invalid IL or missing references) //IL_0071: Unknown result type (might be due to invalid IL or missing references) if (marks.Count >= 100) { p.Status = Loc.Text("Максимум 100 точек в маршруте.", "A path can contain up to 100 points."); } else if (p.EnsureFreecam()) { Camera freeCamera = CameraTools.FreeCamera; Remember(); marks.Add(new CameraMark { Position = ((Component)freeCamera).transform.position, Rotation = ((Component)freeCamera).transform.rotation, Fov = freeCamera.fieldOfView }); p.Status = Loc.Text("Точка {0} добавлена: координаты, взгляд и угол обзора.", "Point {0} added: position, rotation and field of view.", Count); } } internal void Undo() { if (CanUndo) { p.StopTakes(); CameraMark[] collection = history[history.Count - 1]; history.RemoveAt(history.Count - 1); marks.Clear(); marks.AddRange(collection); Revision++; p.Status = Loc.Text("Последнее изменение маршрута отменено.", "Last path edit undone."); } } internal void Remove(int i) { if (Valid(i)) { Remember(); marks.RemoveAt(i); p.Status = Loc.Text("Точка удалена. Можно отменить.", "Point deleted. You can undo this change."); } } internal void Move(int i, int direction) { int num = i + direction; if (Valid(i) && Valid(num)) { Remember(); CameraMark value = marks[i]; marks[i] = marks[num]; marks[num] = value; p.Status = Loc.Text("Порядок точек изменён.", "Point order changed."); } } internal static bool ValidPosition(Vector3 pos) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Unknown result type (might be due to invalid IL or missing references) //IL_004e: Unknown result type (might be due to invalid IL or missing references) if (CameraMath.Finite(pos.x) && CameraMath.Finite(pos.y) && CameraMath.Finite(pos.z) && Math.Abs(pos.x) <= 1000000f && Math.Abs(pos.y) <= 1000000f) { return Math.Abs(pos.z) <= 1000000f; } return false; } internal void Edit(int i, Vector3 position, Vector3 angles, float fov) { //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_0068: Unknown result type (might be due to invalid IL or missing references) //IL_0069: Unknown result type (might be due to invalid IL or missing references) //IL_0070: Unknown result type (might be due to invalid IL or missing references) //IL_0071: Unknown result type (might be due to invalid IL or missing references) //IL_0076: Unknown result type (might be due to invalid IL or missing references) if (Valid(i)) { if (!ValidPosition(position) || !ValidPosition(angles) || !CameraMath.Finite(fov) || fov < 10f || fov > 140f) { p.Status = Loc.Text("Проверь координаты и углы. Угол обзора: от 10 до 140°.", "Check the coordinates and angles. Field of view must be 10–140°."); return; } Remember(); marks[i] = new CameraMark { Position = position, Rotation = Quaternion.Euler(angles), Fov = fov }; p.Status = Loc.Text("Точка {0} сохранена.", "Point {0} saved.", i + 1); } } internal void ReplaceFromCamera(int i) { //IL_003a: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Unknown result type (might be due to invalid IL or missing references) //IL_004c: Unknown result type (might be due to invalid IL or missing references) //IL_0051: Unknown result type (might be due to invalid IL or missing references) if (Valid(i) && p.EnsureFreecam()) { Camera freeCamera = CameraTools.FreeCamera; Remember(); marks[i] = new CameraMark { Position = ((Component)freeCamera).transform.position, Rotation = ((Component)freeCamera).transform.rotation, Fov = freeCamera.fieldOfView }; p.Status = Loc.Text("Точка {0} заменена текущим ракурсом.", "Point {0} replaced with the current view.", i + 1); } } internal void GoTo(int i) { //IL_0035: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Unknown result type (might be due to invalid IL or missing references) if (Valid(i) && p.EnsureFreecam()) { p.StopTakes(); CameraMark cameraMark = marks[i]; CameraTools.ApplyPose(CameraTools.FreeCamera, cameraMark.Position, cameraMark.Rotation, cameraMark.Fov); p.Status = Loc.Text("Камера в точке {0}. Закрой меню для уточнения ракурса.", "Camera at point {0}. Close the menu to adjust the view.", i + 1); } } internal void ClearEditable() { if (marks.Count != 0) { Remember(); marks.Clear(); p.Status = Loc.Text("Маршрут очищен. Очистку можно отменить.", "Path cleared. You can undo this change."); } } internal void Clear() { Stop(); marks.Clear(); history.Clear(); Revision++; } internal void Play() { //IL_00cf: Unknown result type (might be due to invalid IL or missing references) if (marks.Count < 2) { p.Status = Loc.Text("Для маршрута нужны хотя бы две точки.", "A path needs at least two points."); } else if (p.EnsureFreecam()) { p.StopTakes(); camera = CameraTools.FreeCamera; duration = p.RouteDuration.Value; clock.Start(p.StartDelay.Value); Playing = true; Paused = false; Apply(0.0); p.Menu.Close(resume: true); p.Status = Loc.Text("Проезд запущен. {0} — остановить.", "Path started. {0} — stop.", p.RoutePlayKey.Value); } } internal void Tick() { if (!Playing) { return; } if ((Object)(object)camera == (Object)null || (Object)(object)camera != (Object)(object)CameraTools.FreeCamera) { Stop(); return; } clock.Maintain(); if (!p.HoldTake && !Paused) { double progress = Progress; Apply(progress); if (progress >= 1.0) { Stop(); p.Status = Loc.Text("Проезд завершён. Повтор запускается с той же точки.", "Path complete. Replaying starts from the same point."); } else { clock.Advance(); } } } private void Apply(double progress) { //IL_007a: Unknown result type (might be due to invalid IL or missing references) //IL_0087: Unknown result type (might be due to invalid IL or missing references) //IL_0094: Unknown result type (might be due to invalid IL or missing references) //IL_00a1: Unknown result type (might be due to invalid IL or missing references) //IL_00b5: Unknown result type (might be due to invalid IL or missing references) //IL_00c2: Unknown result type (might be due to invalid IL or missing references) //IL_00cf: Unknown result type (might be due to invalid IL or missing references) //IL_00dc: Unknown result type (might be due to invalid IL or missing references) //IL_00f0: Unknown result type (might be due to invalid IL or missing references) //IL_00fd: Unknown result type (might be due to invalid IL or missing references) //IL_010a: Unknown result type (might be due to invalid IL or missing references) //IL_0117: Unknown result type (might be due to invalid IL or missing references) //IL_0135: Unknown result type (might be due to invalid IL or missing references) //IL_0139: Unknown result type (might be due to invalid IL or missing references) //IL_0140: Unknown result type (might be due to invalid IL or missing references) //IL_0146: Unknown result type (might be due to invalid IL or missing references) double num = CameraMath.Smooth(progress) * (double)(Count - 1); int num2 = Math.Min(Count - 2, (int)num); float num3 = (float)(num - (double)num2); CameraMark cameraMark = marks[Math.Max(0, num2 - 1)]; CameraMark cameraMark2 = marks[num2]; CameraMark cameraMark3 = marks[num2 + 1]; CameraMark cameraMark4 = marks[Math.Min(Count - 1, num2 + 2)]; Vector3 position = default(Vector3); ((Vector3)(ref position))..ctor((float)CameraMath.Curve(cameraMark.Position.x, cameraMark2.Position.x, cameraMark3.Position.x, cameraMark4.Position.x, num3), (float)CameraMath.Curve(cameraMark.Position.y, cameraMark2.Position.y, cameraMark3.Position.y, cameraMark4.Position.y, num3), (float)CameraMath.Curve(cameraMark.Position.z, cameraMark2.Position.z, cameraMark3.Position.z, cameraMark4.Position.z, num3)); CameraTools.ApplyPose(camera, position, Quaternion.Slerp(cameraMark2.Rotation, cameraMark3.Rotation, num3), Mathf.Lerp(cameraMark2.Fov, cameraMark3.Fov, num3)); } internal void Stop() { Playing = false; Paused = false; clock.Stop(); camera = null; } internal void Offset(float amount) { Revision++; foreach (CameraMark[] item in history) { for (int i = 0; i < item.Length; i++) { CameraMark cameraMark = item[i]; cameraMark.Position.y += amount; item[i] = cameraMark; } } for (int j = 0; j < Count; j++) { CameraMark value = marks[j]; value.Position.y += amount; marks[j] = value; } } } internal sealed class CameraTools { private GameObject hiddenCrosshair; private bool originalActive; private DebugCameraController settingsOwner; private bool speedFloorReported; private float oldFov; private float oldSpeed; private float oldTurn; private float oldSmooth; private Vector3 manualStart; internal static bool Freecam { get { if ((Object)(object)CL_GameManager.gMan != (Object)null) { return CL_GameManager.gMan.freecam; } return false; } } internal static Camera FreeCamera { get { //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Unknown result type (might be due to invalid IL or missing references) if (!Freecam) { return null; } DebugCameraController val = FreecamMemory.Controller; if ((Object)(object)val == (Object)null) { DebugCameraController[] array = Resources.FindObjectsOfTypeAll<DebugCameraController>(); foreach (DebugCameraController val2 in array) { Scene scene = ((Component)val2).gameObject.scene; if (((Scene)(ref scene)).IsValid() && ((Behaviour)val2).isActiveAndEnabled) { FreecamMemory.Validate(val2); val = val2; break; } } } Camera val3 = (((Object)(object)val != (Object)null) ? ((Component)val).GetComponent<Camera>() : null); if (!((Object)(object)val3 != (Object)null) || !((Behaviour)val3).isActiveAndEnabled) { return null; } return val3; } } internal void Tick() { CL_UIManager instance = CL_UIManager.instance; GameObject val = (((Object)(object)instance != (Object)null && (Object)(object)instance.crosshairController != (Object)null && (Object)(object)instance.crosshairController.crosshairRoot != (Object)null) ? ((Component)instance.crosshairController.crosshairRoot).gameObject : null); if (!Freecam || (Object)(object)val != (Object)(object)hiddenCrosshair || !CinemaPlugin.Instance.HideCrosshair.Value) { Restore(); } if (Freecam && !((Object)(object)val == (Object)null) && CinemaPlugin.Instance.HideCrosshair.Value) { if ((Object)(object)hiddenCrosshair == (Object)null) { hiddenCrosshair = val; originalActive = val.activeSelf; } val.SetActive(false); } } internal void Restore() { if ((Object)(object)hiddenCrosshair != (Object)null) { hiddenCrosshair.SetActive(originalActive); } hiddenCrosshair = null; } internal void BeginManualMove(DebugCameraController camera) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Unknown result type (might be due to invalid IL or missing references) manualStart = ((Component)camera).transform.position; } internal void FinishManualMove(DebugCameraController camera) { //IL_0039: Unknown result type (might be due to invalid IL or missing references) //IL_0044: Unknown result type (might be due to invalid IL or missing references) //IL_004a: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Unknown result type (might be due to invalid IL or missing references) //IL_0055: Unknown result type (might be due to invalid IL or missing references) //IL_005a: Unknown result type (might be due to invalid IL or missing references) CinemaPlugin instance = CinemaPlugin.Instance; float num = (((Object)(object)instance != (Object)null && instance.Lenses != null) ? instance.Lenses.CameraScale : 1f); if (num != 1f) { ((Component)camera).transform.position = manualStart + (((Component)camera).transform.position - manualStart) * num; } } internal void TrackSettings() { DebugCameraController controller = FreecamMemory.Controller; if (!((Object)(object)controller == (Object)null) && !((Object)(object)controller == (Object)(object)settingsOwner)) { settingsOwner = controller; oldFov = ((Component)controller).GetComponent<Camera>().fieldOfView; oldSpeed = ReadNative("speed"); oldTurn = ReadNative("turnSpeed"); oldSmooth = ReadNative("smoothMovement"); } } internal static float ReadNative(string field) { DebugCameraController controller = FreecamMemory.Controller; if (!((Object)(object)controller == (Object)null)) { return Traverse.Create((object)controller).Field(field).GetValue<float>(); } return 0f; } internal void SetNative(string field, float value) { if (!((Object)(object)FreecamMemory.Controller == (Object)null) && CameraMath.Finite(value)) { TrackSettings(); Traverse.Create((object)FreecamMemory.Controller).Field(field).SetValue((object)value); } } internal void RecoverSpeed(ref float speed, bool resuming) { if (CameraMath.Finite(speed) && speed >= 0.1f) { if (speed > 0.1f) { speedFloorReported = false; } return; } TrackSettings(); float num = speed; speed = ((resuming && (!CameraMath.Finite(speed) || speed <= 0f)) ? 10f : 0.1f); if (resuming || !speedFloorReported) { CinemaPlugin.Instance.LogCamera("WK Cinema: recovered freecam speed " + num + " -> " + speed + (resuming ? " before movement/reset." : " after native wheel input.")); } speedFloorReported = !resuming; } internal void ReportFlight(string reason) { if (!((Object)(object)FreecamMemory.Controller == (Object)null)) { CinemaPlugin.Instance.LogCamera("WK Cinema freecam " + reason + ": speed=" + ReadNative("speed") + "; turn=" + ReadNative("turnSpeed") + "; smoothing=" + ReadNative("smoothMovement") + "; baseFov=" + ((Component)FreecamMemory.Controller).GetComponent<Camera>().fieldOfView); } } internal void RestoreSettings() { if ((Object)(object)settingsOwner != (Object)null) { ((Component)settingsOwner).GetComponent<Camera>().fieldOfView = oldFov; Traverse obj = Traverse.Create((object)settingsOwner); obj.Field("speed").SetValue((object)oldSpeed); obj.Field("turnSpeed").SetValue((object)oldTurn); obj.Field("smoothMovement").SetValue((object)oldSmooth); } settingsOwner = null; } internal static void ApplyPose(Camera camera, Vector3 position, Quaternion rotation, float fov) { //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_0087: Unknown result type (might be due to invalid IL or missing references) //IL_0088: Unknown result type (might be due to invalid IL or missing references) //IL_008d: Unknown result type (might be due to invalid IL or missing references) //IL_008e: Unknown result type (might be due to invalid IL or missing references) //IL_0057: Unknown result type (might be due to invalid IL or missing references) //IL_0077: Unknown result type (might be due to invalid IL or missing references) CinemaPlugin.Instance.CameraTools.TrackSettings(); ((Component)camera).transform.SetPositionAndRotation(position, rotation); camera.fieldOfView = Mathf.Clamp(fov, 10f, 140f); FreecamMemory.SyncLook(rotation); DebugCameraController controller = FreecamMemory.Controller; if ((Object)(object)controller != (Object)null) { Traverse.Create((object)controller).Field("targetMovement").SetValue((object)Vector3.zero); Traverse.Create((object)controller).Field("targetRotation").SetValue((object)FreecamMemory.LookAngles); } FreecamMemory.Position = position; FreecamMemory.Rotation = rotation; FreecamMemory.Fov = camera.fieldOfView; FreecamMemory.Saved = true; } internal static void DrawFrame(Color? mask = null) { //IL_004c: Unknown result type (might be due to invalid IL or missing references) //IL_0051: Unknown result type (might be due to invalid IL or missing references) //IL_005a: Unknown result type (might be due to invalid IL or missing references) //IL_005f: Unknown result type (might be due to invalid IL or missing references) //IL_0061: Unknown result type (might be due to invalid IL or missing references) //IL_0114: Unknown result type (might be due to invalid IL or missing references) //IL_0122: Unknown result type (might be due to invalid IL or missing references) //IL_009e: Unknown result type (might be due to invalid IL or missing references) //IL_0095: Unknown result type (might be due to invalid IL or missing references) //IL_00b9: Unknown result type (might be due to invalid IL or missing references) //IL_00d7: Unknown result type (might be due to invalid IL or missing references) //IL_00ee: Unknown result type (might be due to invalid IL or missing references) //IL_0103: Unknown result type (might be due to invalid IL or missing references) float num = Screen.height; float num2 = Mathf.Min((float)Screen.width, num * 9f / 16f); num = num2 * 16f / 9f; float num3 = ((float)Screen.width - num2) / 2f; float num4 = ((float)Screen.height - num) / 2f; Color color = GUI.color; int depth = GUI.depth; Matrix4x4 matrix = GUI.matrix; GUI.matrix = Matrix4x4.identity; GUI.depth = -9000; try { GUI.color = (Color)(((??)mask) ?? new Color(0.25f, 0.25f, 0.25f, 0.65f)); GUI.DrawTexture(new Rect(0f, 0f, num3, (float)Screen.height), (Texture)(object)Texture2D.whiteTexture); GUI.DrawTexture(new Rect(num3 + num2, 0f, num3, (float)Screen.height), (Texture)(object)Texture2D.whiteTexture); GUI.DrawTexture(new Rect(num3, 0f, num2, num4), (Texture)(object)Texture2D.whiteTexture); GUI.DrawTexture(new Rect(num3, num4 + num, num2, num4), (Texture)(object)Texture2D.whiteTexture); } finally { GUI.color = color; GUI.depth = depth; GUI.matrix = matrix; } } } internal static class FreecamMemory { internal static DebugCameraController Controller; internal static Vector3 Position; internal static Quaternion Rotation; internal static bool Saved; internal static float Fov = 90f; internal static float Roll; internal static Vector3 LookAngles; private static int scene; internal static void Validate(DebugCameraController camera) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_0034: Unknown result type (might be due to invalid IL or missing references) //IL_0039: Unknown result type (might be due to invalid IL or missing references) Scene activeScene = SceneManager.GetActiveScene(); int num = SceneHandle.op_Implicit(((Scene)(ref activeScene)).handle); if ((Object)(object)Controller != (Object)(object)camera || scene != num) { Saved = false; LookAngles = ((Component)camera).transform.eulerAngles; Roll = LookAngles.z; } Controller = camera; scene = num; } internal static void Clear() { //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Unknown result type (might be due to invalid IL or missing references) Controller = null; Saved = false; Roll = 0f; LookAngles = Vector3.zero; } internal static void SyncLook(Quaternion rotation) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Unknown result type (might be due to invalid IL or missing references) if (Quaternion.Angle(Quaternion.Euler(LookAngles), rotation) > 0.01f) { LookAngles = ((Quaternion)(ref rotation)).eulerAngles; } Roll = LookAngles.z; } internal static void Offset(float amount) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Unknown result type (might be due to invalid IL or missing references) if (Saved) { Position += Vector3.up * amount; } } internal static void CancelLookDrift() { //IL_0021: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)Controller != (Object)null) { Traverse.Create((object)Controller).Field("targetRotation").SetValue((object)LookAngles); } } internal static void ResetToPlayer() { //IL_0079: Unknown result type (might be due to invalid IL or missing references) //IL_007e: Unknown result type (might be due to invalid IL or missing references) //IL_008e: Unknown result type (might be due to invalid IL or missing references) //IL_0093: Unknown result type (might be due to invalid IL or missing references) //IL_00bc: Unknown result type (might be due to invalid IL or missing references) //IL_00c1: Unknown result type (might be due to invalid IL or missing references) //IL_00e4: Unknown result type (might be due to invalid IL or missing references) ENT_Player playerObject = ENT_Player.playerObject; if ((Object)(object)playerObject == (Object)null || (Object)(object)playerObject.cam == (Object)null) { CinemaPlugin.Instance.Status = Loc.Text("Сначала начни забег.", "Start a run first."); return; } if ((Object)(object)Controller == (Object)null) { Saved = false; CinemaPlugin.Instance.Status = Loc.Text("При включении фрикам появится у игрока.", "Freecam will start at the player when enabled."); return; } Validate(Controller); Position = ((Component)playerObject.cam).transform.position; Rotation = ((Component)playerObject.cam).transform.rotation; Fov = ((Component)Controller).GetComponent<Camera>().fieldOfView; Saved = true; CameraTools.ApplyPose(((Component)Controller).GetComponent<Camera>(), Position, Rotation, Fov); Traverse.Create((object)Controller).Field("targetMovement").SetValue((object)Vector3.zero); float speed = CameraTools.ReadNative("speed"); CinemaPlugin.Instance.CameraTools.RecoverSpeed(ref speed, resuming: true); CinemaPlugin.Instance.CameraTools.SetNative("speed", speed); CinemaPlugin.Instance.CameraTools.ReportFlight("reset-to-player"); CinemaPlugin.Instance.Status = Loc.Text("Фрикам возвращён к игроку. Ракурс сброшен.", "Freecam returned to the player. Saved view reset."); } } [HarmonyPatch(typeof(DebugCameraController), "ToggleActive")] internal static class FreecamPositionPatch { private static void Prefix(DebugCameraController __instance, bool ___active) { //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Unknown result type (might be due to invalid IL or missing references) FreecamMemory.Validate(__instance); if (___active) { FreecamMemory.Position = ((Component)__instance).transform.position; FreecamMemory.Rotation = ((Component)__instance).transform.rotation; FreecamMemory.Fov = ((Component)__instance).GetComponent<Camera>().fieldOfView; FreecamMemory.Saved = true; } } private static void Postfix(DebugCameraController __instance, bool ___active, ref Vector3 ___targetMovement, ref Vector3 ___targetRotation, ref float ___speed) { //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_004d: Unknown result type (might be due to invalid IL or missing references) //IL_0052: Unknown result type (might be due to invalid IL or missing references) //IL_0058: Unknown result type (might be due to invalid IL or missing references) //IL_005d: Unknown result type (might be due to invalid IL or missing references) //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Unknown result type (might be due to invalid IL or missing references) if (!___active) { if ((Object)(object)CinemaPlugin.Instance != (Object)null) { CinemaPlugin.Instance.StopTakes(); } return; } if (FreecamMemory.Saved) { CameraTools.ApplyPose(((Component)__instance).GetComponent<Camera>(), FreecamMemory.Position, FreecamMemory.Rotation, FreecamMemory.Fov); } FreecamMemory.SyncLook(((Component)__instance).transform.rotation); ___targetMovement = Vector3.zero; ___targetRotation = FreecamMemory.LookAngles; CinemaPlugin instance = CinemaPlugin.Instance; if ((Object)(object)instance != (Object)null) { instance.CameraTools.RecoverSpeed(ref ___speed, resuming: true); instance.CameraTools.ReportFlight("enabled"); } } } [HarmonyPatch(typeof(DebugCameraController), "Update")] internal static class FreecamMenuPatch { private static bool Prefix(DebugCameraController __instance, bool ___active, ref Vector3 ___targetMovement, ref Vector3 ___targetRotation, ref float ___speed, out bool __state) { //IL_0098: Unknown result type (might be due to invalid IL or missing references) //IL_009d: Unknown result type (might be due to invalid IL or missing references) //IL_00a3: Unknown result type (might be due to invalid IL or missing references) //IL_00a8: Unknown result type (might be due to invalid IL or missing references) //IL_0044: Unknown result type (might be due to invalid IL or missing references) //IL_0056: Unknown result type (might be due to invalid IL or missing references) //IL_0068: Unknown result type (might be due to invalid IL or missing references) __state = false; CinemaPlugin instance = CinemaPlugin.Instance; if ((Object)(object)instance == (Object)null || instance.Menu == null || !___active) { return true; } FreecamMemory.Validate(__instance); if (!instance.BlockCameraFrame && !instance.HoldTake && !instance.Automated && !CinemaShortcuts.Pressed(instance.MenuKey.Value) && !CinemaShortcuts.Pressed(instance.RoutePlayKey.Value) && !CinemaShortcuts.Pressed(instance.OrbitPlayKey.Value)) { instance.CameraTools.RecoverSpeed(ref ___speed, resuming: true); instance.CameraTools.BeginManualMove(__instance); __state = true; return true; } ___targetMovement = Vector3.zero; ___targetRotation = FreecamMemory.LookAngles; return false; } private static void Postfix(DebugCameraController __instance, ref Vector3 ___targetRotation, ref float ___speed, bool __state, bool __runOriginal) { //IL_0076: Unknown result type (might be due to invalid IL or missing references) CinemaPlugin instance = CinemaPlugin.Instance; if (__state && __runOriginal && !((Object)(object)instance == (Object)null) && CameraTools.Freecam && ((Behaviour)__instance).isActiveAndEnabled) { instance.CameraTools.RecoverSpeed(ref ___speed, resuming: false); instance.CameraTools.FinishManualMove(__instance); ((Component)__instance).transform.rotation = FreecamLook.Step(ref ___targetRotation, ref FreecamMemory.LookAngles, FreecamMemory.Roll, (instance.Lenses != null) ? instance.Lenses.LookSeconds(freecam: true) : instance.LookSmoothing.Value, Time.unscaledDeltaTime); } } } [HarmonyPatch] internal static class AmbientPlaybackPatch { internal static IEnumerable<MethodBase> TargetMethods() { foreach (MethodInfo declaredMethod in AccessTools.GetDeclaredMethods(typeof(AudioManager))) { if (declaredMethod.Name == "PlaySound") { yield return declaredMethod; } } yield return AccessTools.Method(typeof(ENV_Radio), "Play", (Type[])null, (Type[])null); yield return AccessTools.Method(typeof(AnnouncementSource), "PlayAnnouncement", (Type[])null, (Type[])null); yield return AccessTools.Method(typeof(AnnouncementSource), "ForceAnnouncement", (Type[])null, (Type[])null); yield return AccessTools.Method(typeof(UT_SoundtrackMixer), "Play", (Type[])null, (Type[])null); yield return AccessTools.Method(typeof(UT_RandomAudio), "Play", (Type[])null, (Type[])null); yield return AccessTools.Method(typeof(AudioSet), "PlaySound", (Type[])null, (Type[])null); } internal static void Play(AudioSource source) { CinemaAmbientAudio.BeforePlay(source); source.Play(); } internal static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions) { MethodInfo play = AccessTools.Method(typeof(AudioSource), "Play", new Type[0], (Type[])null); MethodInfo wrapped = AccessTools.Method(typeof(AmbientPlaybackPatch), "Play", (Type[])null, (Type[])null); foreach (CodeInstruction instruction in instructions) { if ((instruction.opcode == OpCodes.Callvirt || instruction.opcode == OpCodes.Call) && object.Equals(instruction.operand, play)) { instruction.opcode = OpCodes.Call; instruction.operand = wrapped; } yield return instruction; } } } [HarmonyPatch(typeof(AudioManager), "GetPooledAudioSource")] internal static class AmbientPoolPatch { internal static void Postfix(AudioSource __result) { CinemaPlugin instance = CinemaPlugin.Instance; if ((Object)(object)instance != (Object)null && instance.AmbientAudio != null) { instance.AmbientAudio.Release(__result); } } } internal sealed class CinemaAmbientAudio { private readonly CinemaPlugin p; internal readonly ConfigEntry<bool> Muted; private readonly List<AudioSource> sources = new List<AudioSource>(); private readonly HashSet<AudioSource> radioSources = new HashSet<AudioSource>(); private readonly Dictionary<AudioSource, bool> originalMute = new Dictionary<AudioSource, bool>(); private readonly List<AudioSource> released = new List<AudioSource>(); private float scanAt; internal int MutedCount => originalMute.Count; private bool Active { get { if (((Behaviour)p).isActiveAndEnabled && Muted.Value) { return CL_GameManager.IsInGame(); } return false; } } internal CinemaAmbientAudio(CinemaPlugin plugin) { p = plugin; Muted = ((BaseUnityPlugin)p).Config.Bind<bool>("Audio", "MuteAmbient", false, Loc.Config("Заглушать радио, объявления и эмбиент во время забега. Запоминается между запусками.", "Mute radio, announcements and ambience during a run. Remembered between launches.")); } internal void SetMuted(bool value) { Muted.Value = value; scanAt = 0f; Tick(); p.Status = (value ? Loc.Text("Радио, объявления и эмбиент заглушены.", "Radio, announcements and ambience muted.") : Loc.Text("Фоновые звуки возвращены.", "Background sounds restored.")); } internal void Tick() { if (!Active) { Clear(); return; } if (Time.realtimeSinceStartup >= scanAt) { Discover(); } released.Clear(); foreach (KeyValuePair<AudioSource, bool> item in originalMute) { if ((Object)(object)item.Key == (Object)null || !Ambient(item.Key)) { released.Add(item.Key); } } foreach (AudioSource item2 in released) { Release(item2); } foreach (AudioSource source in sources) { SyncSource(source); } } private void Discover() { //IL_0035: Unknown result type (might be due to invalid IL or missing references) //IL_003a: Unknown result type (might be due to invalid IL or missing references) //IL_004a: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Unknown result type (might be due to invalid IL or missing references) //IL_00a2: Unknown result type (might be due to invalid IL or missing references) //IL_00a7: Unknown result type (might be due to invalid IL or missing references) //IL_00b8: Unknown result type (might be due to invalid IL or missing references) //IL_00bd: Unknown result type (might be due to invalid IL or missing references) sources.Clear(); radioSources.Clear(); AudioSource[] array = Object.FindObjectsByType<AudioSource>((FindObjectsInactive)1, (FindObjectsSortMode)0); Scene scene; foreach (AudioSource val in array) { if (!((Object)(object)val != (Object)null)) { continue; } scene = ((Component)val).gameObject.scene; if (((Scene)(ref scene)).IsValid()) { scene = ((Component)val).gameObject.scene; if (((Scene)(ref scene)).isLoaded) { sources.Add(val); } } } ENV_Radio[] array2 = Object.FindObjectsByType<ENV_Radio>((FindObjectsInactive)1, (FindObjectsSortMode)0); foreach (ENV_Radio val2 in array2) { if (!((Object)(object)val2 != (Object)null) || !((Object)(object)val2.aud != (Object)null)) { continue; } scene = ((Component)val2).gameObject.scene; if (((Scene)(ref scene)).IsValid()) { scene = ((Component)val2).gameObject.scene; if (((Scene)(ref scene)).isLoaded) { radioSources.Add(val2.aud); } } } scanAt = Time.realtimeSinceStartup + 0.5f; } private bool Ambient(AudioSource source) { if ((Object)(object)source == (Object)null) { return false; } if (radioSources.Contains(source) || (Object)(object)((Component)source).GetComponent<AnnouncementSource>() != (Object)null) { return true; } ENV_Radio componentInParent = ((Component)source).GetComponentInParent<ENV_Radio>(true); if ((Object)(object)componentInParent != (Object)null && (Object)(object)componentInParent.aud == (Object)(object)source) { return true; } AudioMixerGroup outputAudioMixerGroup = source.outputAudioMixerGroup; AudioManager instance = AudioManager.instance; if ((Object)(object)outputAudioMixerGroup == (Object)null || (Object)(object)instance == (Object)null || (Object)(object)outputAudioMixerGroup.audioMixer != (Object)(object)instance.mixer) { return false; } if (!(((Object)outputAudioMixerGroup).name == "Radio") && !(((Object)outputAudioMixerGroup).name == "Announcer")) { return ((Object)outputAudioMixerGroup).name == "Ambience"; } return true; } internal void SyncSource(AudioSource source) { if ((Object)(object)source == (Object)null) { return; } if (!Active || !Ambient(source)) { Release(source); return; } if (!originalMute.ContainsKey(source)) { if (source.mute) { return; } originalMute.Add(source, value: false); } source.mute = true; } internal void Release(AudioSource source) { if (source != null && originalMute.TryGetValue(source, out var value)) { if ((Object)(object)source != (Object)null && source.mute) { source.mute = value; } originalMute.Remove(source); } } internal void Clear() { foreach (KeyValuePair<AudioSource, bool> item in originalMute) { if ((Object)(object)item.Key != (Object)null && item.Key.mute) { item.Key.mute = item.Value; } } originalMute.Clear(); sources.Clear(); radioSources.Clear(); released.Clear(); scanAt = 0f; } internal static void BeforePlay(AudioSource source) { CinemaPlugin instance = CinemaPlugin.Instance; if ((Object)(object)instance != (Object)null && instance.AmbientAudio != null) { instance.AmbientAudio.SyncSource(source); } } } internal sealed class CinemaBinding { internal readonly string Id; internal readonly LocalizedText Name; internal readonly ConfigEntry<KeyboardShortcut> Entry; internal readonly KeyboardShortcut Default; internal readonly bool Required; internal readonly bool Wheel; internal CinemaBinding(string id, LocalizedText name, ConfigEntry<KeyboardShortcut> entry, KeyboardShortcut standard, bool required = false, bool wheel = false) { //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Unknown result type (might be due to invalid IL or missing references) Id = id; Name = name; Entry = entry; Default = standard; Required = required; Wheel = wheel; } } internal sealed class CinemaBindings { private readonly CinemaPlugin p; internal readonly List<CinemaBinding> Items = new List<CinemaBinding>(); internal readonly ConfigEntry<KeyboardShortcut> PortraitKey; internal readonly ConfigEntry<KeyboardShortcut> HideLeftKey; internal readonly ConfigEntry<KeyboardShortcut> HideRightKey; internal readonly ConfigEntry<KeyboardShortcut> PlaceLightKey; internal readonly ConfigEntry<KeyboardShortcut> ZoomKey; internal readonly ConfigEntry<KeyboardShortcut> ZoomWheelKey; internal readonly ConfigEntry<KeyboardShortcut> ZoomResetKey; internal readonly ConfigEntry<KeyboardShortcut> SmoothLookKey; private KeyboardShortcut? wheelCandidate; private int wheelCandidateCount; private static readonly KeyCode[] keys = (KeyCode[])Enum.GetValues(typeof(KeyCode)); internal CinemaBinding Capturing { get; private set; } internal CinemaBindings(CinemaPlugin plugin) { //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_0078: Unknown result type (might be due to invalid IL or missing references) //IL_00ae: Unknown result type (might be due to invalid IL or missing references) //IL_00ed: Unknown result type (might be due to invalid IL or missing references) //IL_012c: Unknown result type (might be due to invalid IL or missing references) //IL_016b: Unknown result type (might be due to invalid IL or missing references) //IL_0237: Unknown result type (might be due to invalid IL or missing references) //IL_0256: Unknown result type (might be due to invalid IL or missing references) //IL_027d: Unknown result type (might be due to invalid IL or missing references) //IL_02d6: Unknown result type (might be due to invalid IL or missing references) //IL_02f5: Unknown result type (might be due to invalid IL or missing references) //IL_031c: Unknown result type (might be due to invalid IL or missing references) //IL_0295: Unknown result type (might be due to invalid IL or missing references) //IL_035e: Unknown result type (might be due to invalid IL or missing references) //IL_0396: Unknown result type (might be due to invalid IL or missing references) //IL_0334: Unknown result type (might be due to invalid IL or missing references) p = plugin; Add("menu", Loc.Text("Открыть / закрыть меню", "Open / close menu"), p.MenuKey, new KeyboardShortcut((KeyCode)292, Array.Empty<KeyCode>()), required: true); Add("freecam", Loc.Text("Игрок / фрикам", "Player / freecam"), p.FreecamKey, new KeyboardShortcut((KeyCode)284, Array.Empty<KeyCode>())); Add("point", Loc.Text("Добавить точку камеры", "Add camera point"), p.RoutePointKey, new KeyboardShortcut((KeyCode)285, Array.Empty<KeyCode>())); Add("path", Loc.Text("Запустить / остановить маршрут", "Start / stop path"), p.RoutePlayKey, new KeyboardShortcut((KeyCode)284, (KeyCode[])(object)new KeyCode[1] { (KeyCode)304 })); Add("center", Loc.Text("Выбрать центр облёта", "Pick orbit center"), p.OrbitCenterKey, new KeyboardShortcut((KeyCode)285, (KeyCode[])(object)new KeyCode[1] { (KeyCode)304 })); Add("orbit", Loc.Text("Запустить / остановить облёт", "Start / stop orbit"), p.OrbitPlayKey, new KeyboardShortcut((KeyCode)284, (KeyCode[])(object)new KeyCode[1] { (KeyCode)306 })); PortraitKey = Extra("PortraitMode", Loc.Text("Вертикальный режим игрока", "Player portrait mode")); HideLeftKey = Extra("HideLeftHand", Loc.Text("Скрыть / показать левую руку", "Hide / show left hand")); HideRightKey = Extra("HideRightHand", Loc.Text("Скрыть / показать правую руку", "Hide / show right hand")); PlaceLightKey = Extra("PlaceLight", Loc.Text("Поставить источник света здесь", "Place a light here")); LocalizedText name = Loc.Text("Запустить / остановить зум текущего вида", "Start / stop zoom for the active view"); KeyboardShortcut val = default(KeyboardShortcut); ((KeyboardShortcut)(ref val))..ctor((KeyCode)285, (KeyCode[])(object)new KeyCode[1] { (KeyCode)306 }); ZoomKey = ((BaseUnityPlugin)p).Config.Bind<KeyboardShortcut>("Controls", "ZoomPlay", val, name.Bilingual); Add("ZoomPlay", name, ZoomKey, val); if (Conflict(Items[Items.Count - 1], ZoomKey.Value) != null) { ZoomKey.Value = new KeyboardShortcut((KeyCode)0, Array.Empty<KeyCode>()); } LocalizedText name2 = Loc.Text("Зум колёсиком: удерживать клавишу", "Wheel zoom: hold key"); KeyboardShortcut val2 = default(KeyboardShortcut); ((KeyboardShortcut)(ref val2))..ctor((KeyCode)308, Array.Empty<KeyCode>()); ZoomWheelKey = ((BaseUnityPlugin)p).Config.Bind<KeyboardShortcut>("Controls", "ZoomWheelHold", val2, name2.Bilingual); Add("ZoomWheelHold", name2, ZoomWheelKey, val2, required: false, wheel: true); if (Conflict(Items[Items.Count - 1], ZoomWheelKey.Value) != null) { ZoomWheelKey.Value = new KeyboardShortcut((KeyCode)0, Array.Empty<KeyCode>()); } ZoomResetKey = DefaultAction("ZoomReset", Loc.Text("Сбросить зум текущего вида до ×1", "Reset active view zoom to ×1"), new KeyboardShortcut((KeyCode)283, Array.Empty<KeyCode>())); SmoothLookKey = DefaultAction("SmoothLookToggle", Loc.Text("Включить / выключить плавный поворот", "Toggle smooth turning"), new KeyboardShortcut((KeyCode)283, (KeyCode[])(object)new KeyCode[1] { (KeyCode)304 })); } private ConfigEntry<KeyboardShortcut> DefaultAction(string id, LocalizedText name, KeyboardShortcut standard) { //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_0058: Unknown result type (might be due to invalid IL or missing references) ConfigEntry<KeyboardShortcut> val = ((BaseUnityPlugin)p).Config.Bind<KeyboardShortcut>("Controls", id, standard, name.Bilingual); Add(id, name, val, standard); if (Conflict(Items[Items.Count - 1], val.Value) != null) { val.Value = new KeyboardShortcut((KeyCode)0, Array.Empty<KeyCode>()); } return val; } private ConfigEntry<KeyboardShortcut> Extra(string id, LocalizedText name) { //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Unknown result type (might be due to invalid IL or missing references) ConfigEntry<KeyboardShortcut> val = ((BaseUnityPlugin)p).Config.Bind<KeyboardShortcut>("Controls", id, new KeyboardShortcut((KeyCode)0, Array.Empty<KeyCode>()), name.Bilingual); Add(id, name, val, new KeyboardShortcut((KeyCode)0, Array.Empty<KeyCode>())); return val; } private void Add(string id, LocalizedText name, ConfigEntry<KeyboardShortcut> entry, KeyboardShortcut standard, bool required = false, bool wheel = false) { //IL_0009: Unknown result type (might be due to invalid IL or missing references) Items.Add(new CinemaBinding(id, name, entry, standard, required, wheel)); } internal void Begin(CinemaBinding target) { if (target != null && Items.Contains(target)) { Capturing = target; wheelCandidate = null; wheelCandidateCount = 0; p.Status = (target.Wheel ? Loc.Text("Нажми клавишу или сочетание для зума колёсиком. Для одного Ctrl / Shift / Alt нажми и отпусти его. Esc — отмена, Backspace — убрать.", "Press a key or chord for wheel zoom. To use Ctrl / Shift / Alt alone, press and release it. Esc cancels; Backspace unbinds.") : Loc.Text("Нажми клавишу для «{0}». Ctrl / Shift / Alt поддерживаются. Esc — отмена, Backspace — убрать.", "Press a key for {0}. Ctrl / Shift / Alt are supported. Esc cancels; Backspace unbinds.", target.Name)); } } internal void Cancel(bool announce = false) { Capturing = null; wheelCandidate = null; if (announce) { p.Status = Loc.Text("Переназначение отменено. Прежняя клавиша сохранена.", "Rebinding cancelled. The previous shortcut is retained."); } } private static int Modifiers(KeyboardShortcut value) { //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Unknown result type (might be due to invalid IL or missing references) int num = 0; foreach (KeyCode modifier in ((KeyboardShortcut)(ref value)).Modifiers) { num |= CinemaShortcuts.Group(modifier); } return num; } internal static bool Same(KeyboardShortcut a, KeyboardShortcut b) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Unknown result type (might be due to invalid IL or missing references) if ((int)((KeyboardShortcut)(ref a)).MainKey != 0 && ((KeyboardShortcut)(ref a)).MainKey == ((KeyboardShortcut)(ref b)).MainKey) { return Modifiers(a) == Modifiers(b); } return false; } internal CinemaBinding Conflict(CinemaBinding target, KeyboardShortcut value) { //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0025: Unknown result type (might be due to invalid IL or missing references) foreach (CinemaBinding item in Items) { if (item != target && Same(item.Entry.Value, value)) { return item; } } return null; } internal bool Assign(CinemaBinding target, KeyboardShortcut value) { //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_0049: Invalid comparison between Unknown and I4 //IL_004d: Unknown result type (might be due to invalid IL or missing references) //IL_0057: Invalid comparison between Unknown and I4 //IL_008d: Unknown result type (might be due to invalid IL or missing references) //IL_0097: Invalid comparison between Unknown and I4 //IL_007f: Unknown result type (might be due to invalid IL or missing references) //IL_00c5: Unknown result type (might be due to invalid IL or missing references) //IL_009b: Unknown result type (might be due to invalid IL or missing references) //IL_00a5: Invalid comparison between Unknown and I4 //IL_0105: Unknown result type (might be due to invalid IL or missing references) //IL_0164: Unknown result type (might be due to invalid IL or missing references) //IL_015c: Unknown result type (might be due to invalid IL or missing references) if (target == null || !Items.Contains(target)) { return false; } if ((int)((KeyboardShortcut)(ref value)).MainKey == 0 && target.Required) { p.Status = Loc.Text("Клавишу меню нельзя убрать. Назначь другую или нажми Esc.", "The menu shortcut cannot be removed. Assign another key or press Esc."); return false; } if ((int)((KeyboardShortcut)(ref value)).MainKey == 27 || (int)((KeyboardShortcut)(ref value)).MainKey == 286) { p.Status = Loc.Text("Esc оставлен для закрытия меню, F5 занят отладкой игры. Выбери другую клавишу.", "Esc is reserved for closing menus; F5 opens native debugging. Choose another key."); return false; } if ((!target.Wheel && CinemaShortcuts.Group(((KeyboardShortcut)(ref value)).MainKey) != 0) || ((int)((KeyboardShortcut)(ref value)).MainKey >= 323 && (int)((KeyboardShortcut)(ref value)).MainKey <= 329)) { p.Status = Loc.Text("Выбери клавишу клавиатуры; модификатор можно добавить к ней.", "Choose a keyboard key; you may add a modifier to it."); return false; } CinemaBinding cinemaBinding = Conflict(target, value); if (cinemaBinding != null) { p.Status = Loc.Text("Сочетание уже занято: «{0}». Выбери другое или сначала переназначь это действие.", "Shortcut already used by {0}. Choose another or rebind that action first.", cinemaBinding.Name); return false; } target.Entry.Value = value; ((BaseUnityPlugin)p).Config.Save(); Capturing = null; wheelCandidate = null; p.Status = Loc.Text("{0}: {1}", "{0}: {1}", target.Name, target.Wheel ? DisplayWheel(value) : Display(value)); return true; } internal unsafe static string Display(KeyboardShortcut value) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) if ((int)((KeyboardShortcut)(ref value)).MainKey != 0) { return ((object)(*(KeyboardShortcut*)(&value))/*cast due to .constrained prefix*/).ToString(); } return Loc.Text("Не назначено", "Unassigned"); } internal static string DisplayWheel(KeyboardShortcut value) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_0009: Unknown result type (might be due to invalid IL or missing references) if ((int)((KeyboardShortcut)(ref value)).MainKey != 0) { return Display(value) + Loc.Text(" + колёсико", " + wheel"); } return Display(value); } internal void CaptureTick() { //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_0104: Unknown result type (might be due to invalid IL or missing references) //IL_0106: Unknown result type (might be due to invalid IL or missing references) //IL_011c: Unknown result type (might be due to invalid IL or missing references) //IL_010f: Unknown result type (might be due to invalid IL or missing references) //IL_0120: Unknown result type (might be due to invalid IL or missing references) //IL_0127: Invalid comparison between Unknown and I4 //IL_018d: Unknown result type (might be due to invalid IL or missing references) //IL_0132: Unknown result type (might be due to invalid IL or missing references) //IL_0129: Unknown result type (might be due to invalid IL or missing references) //IL_0130: Invalid comparison between Unknown and I4 //IL_01c7: Unknown result type (might be due to invalid IL or missing references) //IL_014e: Unknown result type (might be due to invalid IL or missing references) //IL_0156: Unknown result type (might be due to invalid IL or missing references) //IL_01fb: Unknown result type (might be due to invalid IL or missing references) //IL_0200: Unknown result type (might be due to invalid IL or missing references) //IL_0215: Unknown result type (might be due to invalid IL or missing references) if (Capturing == null) { return; } if (!Application.isFocused) { Cancel(announce: true); return; } if (Input.GetKeyDown((KeyCode)27)) { Cancel(announce: true); return; } if (Input.GetKeyDown((KeyCode)8)) { Assign(Capturing, new KeyboardShortcut((KeyCode)0, Array.Empty<KeyCode>())); return; } List<KeyCode> list = new List<KeyCode>(4); if (Input.GetKey((KeyCode)306) || Input.GetKey((KeyCode)305)) { list.Add((KeyCode)306); } if (Input.GetKey((KeyCode)304) || Input.GetKey((KeyCode)303)) { list.Add((KeyCode)304); } if (Input.GetKey((KeyCode)308) || Input.GetKey((KeyCode)307)) { list.Add((KeyCode)308); } if (Input.GetKey((KeyCode)310) || Input.GetKey((KeyCode)309) || Input.GetKey((KeyCode)311) || Input.GetKey((KeyCode)312)) { list.Add((KeyCode)310); } bool flag = false; KeyCode[] array = keys; foreach (KeyCode val in array) { if (CinemaShortcuts.Group(val) != 0) { if (Input.GetKeyDown(val)) { flag = true; } } else if ((int)val != 0 && ((int)val < 323 || (int)val > 329) && Input.GetKeyDown(val)) { wheelCandidate = null; Assign(Capturing, new KeyboardShortcut(val, list.ToArray())); return; } } if (!Capturing.Wheel) { return; } if (list.Count > 0 && flag) { KeyboardShortcut value = default(KeyboardShortcut); ((KeyboardShortcut)(ref value))..ctor(list[0], list.GetRange(1, list.Count - 1).ToArray()); if (!wheelCandidate.HasValue || list.Count >= wheelCandidateCount) { wheelCandidate = value; wheelCandidateCount = list.Count; } } else if (list.Count == 0 && wheelCandidate.HasValue) { KeyboardShortcut value2 = wheelCandidate.Value; wheelCandidate = null; Assign(Capturing, value2); } } internal void Defaults() { //IL_0046: Unknown result type (might be due to invalid IL or missing references) Cancel(); bool saveOnConfigSet = ((BaseUnityPlugin)p).Config.SaveOnConfigSet; ((BaseUnityPlugin)p).Config.SaveOnConfigSet = false; try { foreach (CinemaBinding item in Items) { item.Entry.Value = item.Default; } ((BaseUnityPlugin)p).Config.Save(); } finally { ((BaseUnityPlugin)p).Config.SaveOnConfigSet = saveOnConfigSet; } p.Status = Loc.Text("Стандартные клавиши WKCinema восстановлены.", "Default WKCinema shortcuts restored."); } internal void Hotkeys() { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_004a: Unknown result type (might be due to invalid IL or missing references) //IL_006c: Unknown result type (might be due to invalid IL or missing references) //IL_008e: Unknown result type (might be due to invalid IL or missing references) //IL_00d9: Unknown result type (might be due to invalid IL or missing references) //IL_0118: Unknown result type (might be due to invalid IL or missing references) if (CinemaShortcuts.Pressed(ZoomResetKey.Value)) { p.Lenses.ResetActiveZoom(); } if (CinemaShortcuts.Pressed(SmoothLookKey.Value)) { p.Lenses.ToggleActiveSmoothing(); } if (CinemaShortcuts.Pressed(ZoomKey.Value)) { p.Lenses.ToggleZoom(); } if (CinemaShortcuts.Pressed(PlaceLightKey.Value)) { p.Lights.AddHere(); } if (CinemaShortcuts.Pressed(PortraitKey.Value)) { p.Portrait.Enabled.Value = !p.Portrait.Enabled.Value; p.BlockCameraFrame = true; } if (CinemaShortcuts.Pressed(HideLeftKey.Value)) { p.Portrait.HideLeft.Value = !p.Portrait.HideLeft.Value; } if (CinemaShortcuts.Pressed(HideRightKey.Value)) { p.Portrait.HideRight.Value = !p.Portrait.HideRight.Value; } } } internal sealed class CinemaBlackout { private sealed class Surface { internal Renderer Renderer; internal LightProbeUsage LightProbes; internal ReflectionProbeUsage ReflectionProbes; internal bool Applied; internal Material[] Materials; internal readonly List<Slot> Slots = new List<Slot>(); } private sealed class Slot { internal int Index; internal Material Material; internal BlackoutMaterialRule[] Rules; internal bool Applied; internal MaterialPropertyBlock Block = new MaterialPropertyBlock(); internal MaterialPropertyBlock Original = new MaterialPropertyBlock(); } private readonly CinemaPlugin p; private readonly List<Light> unityLights = new List<Light>(); private readonly List<Light> disabledLights = new List<Light>(); private readonly List<Surface> surfaces = new List<Surface>(); private readonly Dictionary<Shader, BlackoutMaterialRule[]> rules = new Dictionary<Shader, BlackoutMaterialRule[]>(); private readonly BlackoutGlobals globals = new BlackoutGlobals(); private Camera rendering; private bool connected; private bool ambientSaved; private bool cameraSaved; private CameraClearFlags clearFlags; private Color background; private float scanAt; private Color ambientLight; private Color ambientSky; private Color ambientEquator; private Color ambientGround; private float ambientIntensity; private float reflectionIntensity; private AmbientMode ambientMode; private SphericalHarmonicsL2 ambientProbe; private LightmapData[] originalMaps; private LightmapData[] darkMaps; internal bool Active { get { if ((Object)(object)rendering != (Object)null) { return p.SceneLights.Blackout; } return false; } } internal CinemaBlackout(CinemaPlugin plugin) { p = plugin; } internal void Connect() { //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Expected O, but got Unknown //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0029: Expected O, but got Unknown //IL_0035: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Expected O, but got Unknown //IL_003f: Unknown result type (might be due to invalid IL or missing references) //IL_0049: Expected O, but got Unknown if (!connected) { Camera.onPreCull = (CameraCallback)Delegate.Combine((Delegate?)(object)Camera.onPreCull, (Delegate?)new CameraCallback(Before)); Camera.onPostRender = (CameraCallback)Delegate.Combine((Delegate?)(object)Camera.onPostRender, (Delegate?)new CameraCallback(After)); connected = true; } } internal void Disconnect() { //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Expected O, but got Unknown //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0028: Expected O, but got Unknown //IL_0034: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Expected O, but got Unknown //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Expected O, but got Unknown if (connected) { Camera.onPreCull = (CameraCallback)Delegate.Remove((Delegate?)(object)Camera.onPreCull, (Delegate?)new CameraCallback(Before)); Camera.onPostRender = (CameraCallback)Delegate.Remove((Delegate?)(object)Camera.onPostRender, (Delegate?)new CameraCallback(After)); connected = false; } Clear(); } internal void Clear() { Restore(); surfaces.Clear(); unityLights.Clear(); rules.Clear(); scanAt = 0f; darkMaps = null; } internal void Tick() { Restore(); if (!p.SceneLights.Blackout) { scanAt = 0f; } else if (Time.realtimeSinceStartup >= scanAt) { Refresh(); } } private void Refresh() { //IL_0090: Unknown result type (might be due to invalid IL or missing references) //IL_0095: Unknown result type (might be due to invalid IL or missing references) //IL_00aa: Unknown result type (might be due to invalid IL or missing references) //IL_00af: Unknown result type (might be due to invalid IL or missing references) //IL_0200: Unknown result type (might be due to invalid IL or missing references) //IL_0205: Unknown result type (might be due to invalid IL or missing references) //IL_0217: Unknown result type (might be due to invalid IL or missing references) //IL_021c: Unknown result type (might be due to invalid IL or missing references) Dictionary<Renderer, Surface> dictionary = new Dictionary<Renderer, Surface>(); foreach (Surface surface in surfaces) { if ((Object)(object)surface.Renderer != (Object)null) { dictionary[surface.Renderer] = surface; } } surfaces.Clear(); unityLights.Clear(); Renderer[] array = Object.FindObjectsByType<Renderer>((FindObjectsInactive)1, (FindObjectsSortMode)0); Scene scene; foreach (Renderer val in array) { if ((Object)(object)val == (Object)null) { continue; } scene = ((Component)val).gameObject.scene; if (!((Scene)(ref scene)).IsValid()) { continue; } scene = ((Component)val).gameObject.scene; if (!((Scene)(ref scene)).isLoaded || (Object)(object)((Component)val).GetComponentInParent<Canvas>(true) != (Object)null) { continue; } Material[] sharedMaterials = val.sharedMaterials; if (dictionary.TryGetValue(val, out var value) && SameMaterials(value.Materials, sharedMaterials)) { surfaces.Add(value); continue; } value = new Surface { Renderer = val, Materials = sharedMaterials }; for (int j = 0; j < sharedMaterials.Length; j++) { Material val2 = sharedMaterials[j]; if (!((Object)(object)val2 == (Object)null) && !((Object)(object)val2.shader == (Object)null)) { if (!rules.TryGetValue(val2.shader, out var value2)) { value2 = BlackoutMaterialRule.For(val2.shader); rules[val2.shader] = value2; } if (value2.Length != 0) { value.Slots.Add(new Slot { Index = j, Material = val2, Rules = value2 }); } } } surfaces.Add(value); } Light[] array2 = Object.FindObjectsByType<Light>((FindObjectsInactive)1, (FindObjectsSortMode)0); foreach (Light val3 in array2) { if (!((Object)(object)val3 != (Object)null)) { continue; } scene = ((Component)val3).gameObject.scene; if (((Scene)(ref scene)).IsValid()) { scene = ((Component)val3).gameObject.scene; if (((Scene)(ref scene)).isLoaded) { unityLights.Add(val3); } } } scanAt = Time.realtimeSinceStartup + 1f; } private static bool SameMaterials(Material[] a, Material[] b) { if (a.Length != b.Length) { return false; } for (int i = 0; i < a.Length; i++) { if ((Object)(object)a[i] != (Object)(object)b[i]) { return false; } } return true; } internal void Before(Camera camera) { //IL_0078: Unknown result type (might be due to invalid IL or missing references) //IL_007d: Unknown result type (might be due to invalid IL or missing references) //IL_0084: Unknown result type (might be due to invalid IL or missing references) //IL_0089: Unknown result type (might be due to invalid IL or missing references) //IL_009d: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)camera == (Object)null || !((Behaviour)p).isActiveAndEnabled || !p.SceneLights.Blackout || !p.LightingStore.Ready || !CL_GameManager.IsInGame() || CL_GameManager.IsLoading() || (Object)(object)camera != (Object)(object)CinemaPlugin.ViewCamera) { return; } Restore(); rendering = camera; try { if (Time.realtimeSinceStartup >= scanAt) { Refresh(); } clearFlags = camera.clearFlags; background = camera.backgroundColor; cameraSaved = true; camera.clearFlags = (CameraClearFlags)2; camera.backgroundColor = Color.black; SaveAmbient(); foreach (Light unityLight in unityLights) { if ((Object)(object)unityLight != (Object)null && ((Behaviour)unityLight).enabled) { disabledLights.Add(unityLight); ((Behaviour)unityLight).enabled = false; } } foreach (Surface surface in surfaces) { ApplySurface(surface); } globals.Apply(); } catch (Exception ex) { Restore(); p.LogLighting("Blackout render failed; restored lighting: " + ex); } } private void SaveAmbient() { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_0043: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_004e: Unknown result type (might be due to invalid IL or missing references) //IL_0053: Unknown result type (might be due to invalid IL or missing references) //IL_0070: Unknown result type (might be due to invalid IL or missing references) //IL_007a: Unknown result type (might be due to invalid IL or missing references) //IL_007f: Unknown result type (might be due to invalid IL or missing references) //IL_0085: Unknown result type (might be due to invalid IL or missing references) //IL_00a6: Unknown result type (might be due to invalid IL or missing references) //IL_00ac: Unknown result type (might be due to invalid IL or missing references) //IL_00fe: Unknown result type (might be due to invalid IL or missing references) //IL_0103: Unknown result type (might be due to invalid IL or missing references) //IL_010e: Unknown result type (might be due to invalid IL or missing references) //IL_0119: Unknown result type (might be due to invalid IL or missing references) //IL_0125: Expected O, but got Unknown ambientLight = RenderSettings.ambientLight; ambientSky = RenderSettings.ambientSkyColor; ambientEquator = RenderSettings.ambientEquatorColor; ambientGround = RenderSettings.ambientGroundColor; ambientIntensity = RenderSettings.ambientIntensity; reflectionIntensity = RenderSettings.reflectionIntensity; ambientMode = RenderSettings.ambientMode; ambientProbe = RenderSettings.ambientProbe; originalMaps = LightmapSettings.lightmaps; ambientSaved = true; RenderSettings.ambientMode = (AmbientMode)3; RenderSettings.ambientLight = Color.black; RenderSettings.ambientSkyColor = (RenderSettings.ambientEquatorColor = (RenderSettings.ambientGroundColor = Color.black)); RenderSettings.ambientIntensity = 0f; RenderSettings.reflectionIntensity = 0f; RenderSettings.ambientProbe = default(SphericalHarmonicsL2); if (originalMaps == null || originalMaps.Length == 0) { return; } if (darkMaps == null || darkMaps.Length != originalMaps.Length) { darkMaps = (LightmapData[])(object)new LightmapData[originalMaps.Length]; for (int i = 0; i < darkMaps.Length; i++) { darkMaps[i] = new LightmapData { lightmapColor = Texture2D.blackTexture, lightmapDir = Texture2D.blackTexture, shadowMask = Texture2D.whiteTexture }; } } LightmapSettings.lightmaps = darkMaps; } private void ApplySurface(Surface frame) { //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_0034: Unknown result type (might be due to invalid IL or missing references) //IL_0039: Unknown result type (might be due to invalid IL or missing references) Renderer renderer = frame.Renderer; if ((Object)(object)renderer == (Object)null || !renderer.enabled || !((Component)renderer).gameObject.activeInHierarchy) { return; } frame.LightProbes = renderer.lightProbeUsage; frame.ReflectionProbes = renderer.reflectionProbeUsage; frame.Applied = true; renderer.lightProbeUsage = (LightProbeUsage)0; renderer.reflectionProbeUsage = (ReflectionProbeUsage)0; foreach (Slot slot in frame.Slots) { if (!((Object)(object)slot.Material == (Object)null)) { renderer.GetPropertyBlock(slot.Original, slot.Index); renderer.GetPropertyBlock(slot.Block, slot.Index); if (slot.Block.isEmpty) { renderer.GetPropertyBlock(slot.Block); } BlackoutMaterialRule[] array = slot.Rules; for (int i = 0; i < array.Length; i++) { array[i].Apply(slot.Block, slot.Material); } slot.Applied = true; renderer.SetPropertyBlock(slot.Block, slot.Index); } } } internal void BeforeNativeFX() { if (Active) { globals.Restore(); } } internal void AfterNativeFX() { if (Active) { globals.Apply(); } } internal void After(Camera camera) { if ((Object)(object)camera == (Object)(object)rendering) { Restore(); } } internal void Restore() { //IL_00b6: Unknown result type (might be due to invalid IL or missing references) //IL_0159: Unknown result type (might be due to invalid IL or missing references) //IL_0164: Unknown result type (might be due to invalid IL or missing references) //IL_016f: Unknown result type (might be due to invalid IL or missing references) //IL_017a: Unknown result type (might be due to invalid IL or missing references) //IL_0185: Unknown result type (might be due to invalid IL or missing references) //IL_01a6: Unknown result type (might be due to invalid IL or missing references) //IL_00ca: Unknown result type (might be due to invalid IL or missing references) //IL_00bf: Unknown result type (might be due to invalid IL or missing references) //IL_00d3: Unknown result type (might be due to invalid IL or missing references) //IL_01e5: Unknown result type (might be due to invalid IL or missing references) //IL_01eb: Invalid comparison between Unknown and I4 //IL_0204: Unknown result type (might be due to invalid IL or missing references) //IL_0209: Unknown result type (might be due to invalid IL or missing references) //IL_01f4: Unknown result type (might be due to invalid IL or missing references) //IL_021c: Unknown result type (might be due to invalid IL or missing references) globals.Restore(); foreach (Surface surface in surfaces) { Renderer renderer = surface.Renderer; if (!surface.Applied) { continue; } surface.Applied = false; foreach (Slot slot in surface.Slots) { if (slot.Applied) { slot.Applied = false; if ((Object)(object)renderer != (Object)null) { renderer.SetPropertyBlock(slot.Original.isEmpty ? null : slot.Original, slot.Index); } } } if (!((Object)(object)renderer == (Object)null)) { if ((int)renderer.lightProbeUsage == 0) { renderer.lightProbeUsage = surface.LightProbes; } if ((int)renderer.reflectionProbeUsage == 0) { renderer.reflectionProbeUsage = surface.ReflectionProbes; } } } foreach (Light disabledLight in disabledLights) { if ((Object)(object)disabledLight != (Object)null && !((Behaviour)disabledLight).enabled) { ((Behaviour)disabledLight).enabled = true; } } disabledLights.Clear(); if (ambientSaved) { RenderSettings.ambientMode = ambientMode; RenderSettings.ambientLight = ambientLight; RenderSettings.ambientSkyColor = ambientSky; RenderSettings.ambientEquatorColor = ambientEquator; RenderSettings.ambientGroundColor = ambientGround; RenderSettings.ambientIntensity = ambientIntensity; RenderSettings.reflectionIntensity = reflectionIntensity; RenderSettings.ambientProbe = ambientProbe; LightmapSettings.lightmaps = originalMaps; originalMaps = null; ambientSaved = false; } if (cameraSaved && (Object)(object)rendering != (Object)null) { if ((int)rendering.clearFlags == 2) { rendering.clearFlags = clearFlags; } if (rendering.backgroundColor == Color.black) { rendering.backgroundColor = background; } } cameraSaved = false; rendering = null; } } [HarmonyPatch(typeof(FXManager), "FXRender")] internal static class BlackoutFXPatch { internal static void Prefix() { CinemaPlugin instance = CinemaPlugin.Instance; if ((Object)(object)instance != (Object)null && instance.Blackout != null) { instance.Blackout.BeforeNativeFX(); } } internal static Exception Finalizer(Exception __exception) { CinemaPlugin instance = CinemaPlugin.Instance; if ((Object)(object)instance != (Object)null && instance.Blackout != null) { if (__exception == null) { instance.Blackout.AfterNativeFX(); } else { instance.Blackout.Restore(); } } return __exception; } } internal