Some mods may be broken due to the recent Alloyed Collective update.
Decompiled source of EngineerGaming v1.0.1
EngineerGaming/EngiGaming.dll
Decompiled 3 months agousing System; using System.Diagnostics; using System.IO; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using BepInEx; using Microsoft.CodeAnalysis; using UnityEngine; using UnityEngine.SceneManagement; using UnityEngine.UI; using UnityEngine.Video; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyCompany("EngiGaming")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0")] [assembly: AssemblyProduct("EngiGaming")] [assembly: AssemblyTitle("EngiGaming")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.0.0.0")] [module: UnverifiableCode] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } [BepInPlugin("com.you.hudvideo", "HUD Video (Debuggable)", "0.1.1")] public class EngiVideoPlugin : BaseUnityPlugin { private GameObject _canvasGO; private VideoPlayer _videoPlayer; private RenderTexture _rt; private RawImage _rawImage; private AudioSource _audioSource; private bool _onLeft = true; private string _localRelativePath = Path.Combine("BepInEx", "plugins", "HudVideo", "video.mp4"); private void Awake() { ((BaseUnityPlugin)this).Logger.LogInfo((object)"HudVideoPlugin Awake"); try { string baseDirectory = AppDomain.CurrentDomain.BaseDirectory; string text = Path.Combine(baseDirectory, _localRelativePath); ((BaseUnityPlugin)this).Logger.LogInfo((object)("Base dir: " + baseDirectory)); ((BaseUnityPlugin)this).Logger.LogInfo((object)$"Local video path: {text} exists: {File.Exists(text)}"); } catch (Exception ex) { ((BaseUnityPlugin)this).Logger.LogError((object)("Error while checking path: " + ex)); } CreateVideoHud(); if ((Object)(object)_canvasGO != (Object)null) { _canvasGO.SetActive(false); } SceneManager.sceneLoaded += OnSceneLoaded; } private void CreateVideoHud() { //IL_003a: Unknown result type (might be due to invalid IL or missing references) //IL_0044: Expected O, but got Unknown //IL_009f: Unknown result type (might be due to invalid IL or missing references) //IL_00a5: Expected O, but got Unknown //IL_00df: 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_011b: Unknown result type (might be due to invalid IL or missing references) //IL_0130: Unknown result type (might be due to invalid IL or missing references) //IL_0144: Unknown result type (might be due to invalid IL or missing references) //IL_0163: Unknown result type (might be due to invalid IL or missing references) //IL_0169: Expected O, but got Unknown //IL_018c: Unknown result type (might be due to invalid IL or missing references) //IL_0196: Expected O, but got Unknown //IL_02bc: Unknown result type (might be due to invalid IL or missing references) //IL_02c6: Expected O, but got Unknown //IL_02d3: Unknown result type (might be due to invalid IL or missing references) //IL_02dd: Expected O, but got Unknown //IL_02ea: Unknown result type (might be due to invalid IL or missing references) //IL_02f4: Expected O, but got Unknown //IL_030d: Unknown result type (might be due to invalid IL or missing references) //IL_0317: Expected O, but got Unknown string text = Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), "video.mp4"); if (!File.Exists(text)) { ((BaseUnityPlugin)this).Logger.LogError((object)"Файл video.mp4 не найден!"); return; } _canvasGO = new GameObject("HUDVideoCanvas"); Canvas obj = _canvasGO.AddComponent<Canvas>(); obj.renderMode = (RenderMode)0; obj.sortingOrder = 9999; obj.pixelPerfect = false; _canvasGO.AddComponent<CanvasScaler>(); _canvasGO.AddComponent<GraphicRaycaster>(); Object.DontDestroyOnLoad((Object)(object)_canvasGO); ((BaseUnityPlugin)this).Logger.LogInfo((object)"Canvas created"); GameObject val = new GameObject("VideoRaw"); val.transform.SetParent(_canvasGO.transform, false); _rawImage = val.AddComponent<RawImage>(); _rawImage.texture = (Texture)(object)_rt; ((Graphic)_rawImage).color = Color.white; ((Graphic)_rawImage).raycastTarget = false; RectTransform component = val.GetComponent<RectTransform>(); component.anchorMin = new Vector2(0f, 0.5f); component.anchorMax = new Vector2(0f, 0.5f); component.pivot = new Vector2(0f, 0.5f); component.anchoredPosition = new Vector2(20f, 0f); ((BaseUnityPlugin)this).Logger.LogInfo((object)"RawImage created (anchored bottom-center 270x480)"); GameObject val2 = new GameObject("VideoPlayer"); val2.transform.SetParent(_canvasGO.transform); _rt = new RenderTexture(360, 640, 0, (RenderTextureFormat)7); _rt.Create(); _rawImage.texture = (Texture)(object)_rt; ((Graphic)_rawImage).SetNativeSize(); ((BaseUnityPlugin)this).Logger.LogInfo((object)$"RenderTexture created {((Texture)_rt).width}x{((Texture)_rt).height}"); _videoPlayer = val2.AddComponent<VideoPlayer>(); _videoPlayer.url = text; _videoPlayer.waitForFirstFrame = true; _videoPlayer.playOnAwake = false; _videoPlayer.isLooping = true; _videoPlayer.renderMode = (VideoRenderMode)2; _videoPlayer.targetTexture = _rt; _audioSource = val2.AddComponent<AudioSource>(); _audioSource.playOnAwake = false; _audioSource.spatialBlend = 0f; _audioSource.volume = 1f; _videoPlayer.audioOutputMode = (VideoAudioOutputMode)1; _videoPlayer.SetTargetAudioSource((ushort)0, _audioSource); _videoPlayer.EnableAudioTrack((ushort)0, true); _videoPlayer.prepareCompleted += new EventHandler(OnVideoPrepared); _videoPlayer.loopPointReached += (EventHandler)delegate { ((BaseUnityPlugin)this).Logger.LogInfo((object)"Video loopPointReached"); }; _videoPlayer.started += (EventHandler)delegate { ((BaseUnityPlugin)this).Logger.LogInfo((object)"Video started"); }; _videoPlayer.sendFrameReadyEvents = true; _videoPlayer.frameReady += (FrameReadyEventHandler)delegate(VideoPlayer vp, long frameIdx) { if (frameIdx == 0L || frameIdx % 300 == 0L) { ((BaseUnityPlugin)this).Logger.LogInfo((object)$"frameReady: {frameIdx}"); } }; _videoPlayer.Play(); ((BaseUnityPlugin)this).Logger.LogInfo((object)"HUD с видео успешно создан!"); } private void OnVideoPrepared(VideoPlayer vp) { //IL_0047: Unknown result type (might be due to invalid IL or missing references) ((BaseUnityPlugin)this).Logger.LogInfo((object)$"OnVideoPrepared: isPrepared={vp.isPrepared}"); if ((Object)(object)_rawImage != (Object)null) { float num = 640f; float num2 = 360f; ((Graphic)_rawImage).rectTransform.sizeDelta = new Vector2(num2, num); ((BaseUnityPlugin)this).Logger.LogInfo((object)$"Video size forced to {num2}x{num}"); _rawImage.texture = (Texture)(object)_rt; ((Graphic)_rawImage).SetAllDirty(); } if (!_videoPlayer.isPlaying) { _videoPlayer.Play(); ((BaseUnityPlugin)this).Logger.LogInfo((object)"VideoPlayer.Play() called (OnVideoPrepared)"); } if ((Object)(object)_audioSource != (Object)null && !_audioSource.isPlaying) { _audioSource.Play(); ((BaseUnityPlugin)this).Logger.LogInfo((object)"AudioSource.Play() called (OnVideoPrepared)"); } } private void OnSceneLoaded(Scene scene, LoadSceneMode mode) { ((BaseUnityPlugin)this).Logger.LogInfo((object)("SceneLoaded: " + ((Scene)(ref scene)).name)); if ((Object)(object)_canvasGO == (Object)null) { CreateVideoHud(); } if (((Scene)(ref scene)).name.StartsWith("stage")) { _canvasGO.SetActive(true); ((BaseUnityPlugin)this).Logger.LogInfo((object)"Canvas enabled (stage)"); if ((Object)(object)_videoPlayer != (Object)null) { if (!_videoPlayer.isPrepared) { _videoPlayer.Prepare(); ((BaseUnityPlugin)this).Logger.LogInfo((object)"VideoPlayer.Prepare() called (scene load)"); } else if (!_videoPlayer.isPlaying) { _videoPlayer.Play(); ((BaseUnityPlugin)this).Logger.LogInfo((object)"VideoPlayer.Play() called (scene load)"); } } } else { _canvasGO.SetActive(false); ((BaseUnityPlugin)this).Logger.LogInfo((object)"Canvas disabled (non-stage)"); } } private void Update() { if (Input.GetKeyDown((KeyCode)288) && (Object)(object)_canvasGO != (Object)null) { bool flag = !_canvasGO.activeSelf; _canvasGO.SetActive(flag); ((BaseUnityPlugin)this).Logger.LogInfo((object)("F7 toggled canvas: now " + (flag ? "enabled" : "disabled"))); if (flag && (Object)(object)_videoPlayer != (Object)null && !_videoPlayer.isPlaying) { _videoPlayer.Play(); ((BaseUnityPlugin)this).Logger.LogInfo((object)"VideoPlayer.Play() forced by F7"); } } if (Input.GetKeyDown((KeyCode)289)) { _onLeft = !_onLeft; UpdateVideoPosition(); ((BaseUnityPlugin)this).Logger.LogInfo((object)("Video side toggled: " + (_onLeft ? "Left" : "Right"))); } } private void UpdateVideoPosition() { //IL_0083: Unknown result type (might be due to invalid IL or missing references) //IL_0098: Unknown result type (might be due to invalid IL or missing references) //IL_00ad: 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_002e: 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_0058: 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) if (!((Object)(object)_rawImage == (Object)null)) { RectTransform rectTransform = ((Graphic)_rawImage).rectTransform; if (_onLeft) { rectTransform.anchorMin = new Vector2(0f, 0.5f); rectTransform.anchorMax = new Vector2(0f, 0.5f); rectTransform.pivot = new Vector2(0f, 0.5f); rectTransform.anchoredPosition = new Vector2(20f, 0f); } else { rectTransform.anchorMin = new Vector2(1f, 0.5f); rectTransform.anchorMax = new Vector2(1f, 0.5f); rectTransform.pivot = new Vector2(1f, 0.5f); rectTransform.anchoredPosition = new Vector2(-20f, 0f); } } } private void OnDestroy() { ((BaseUnityPlugin)this).Logger.LogInfo((object)"HudVideoPlugin OnDestroy"); SceneManager.sceneLoaded -= OnSceneLoaded; if ((Object)(object)_rt != (Object)null) { _rt.Release(); ((BaseUnityPlugin)this).Logger.LogInfo((object)"RenderTexture released"); } } }