using System;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using HubVideo;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using MelonLoader;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.Bindings;
using UnityEngine.Video;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: MelonInfo(typeof(Core), "HubVideo", "0.1.0", "coope", null)]
[assembly: MelonGame("Kubunautilus", "BrutalistickVR")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("HubVideo")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("HubVideo")]
[assembly: AssemblyTitle("HubVideo")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[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;
}
}
}
namespace HubVideo
{
public class Core : MelonMod
{
private const string HubScene = "MainHub";
private const string LogPath = "D:\\BrutalistickVrWork\\Probe\\hubvideo.log";
private bool _inHub;
private Camera _cam;
private int _camTries;
private GameObject _screen;
private VideoPlayer _player;
private RenderTexture _texture;
private AudioSource _audio;
private static readonly Vector3 ScreenScale = new Vector3(0.52f, 0.88f, 1f);
private static readonly float[] WallAngles = new float[7] { -50f, -80f, 0f, 50f, -120f, 120f, 180f };
public override void OnSceneWasLoaded(int buildIndex, string sceneName)
{
_inHub = string.Equals(sceneName, "MainHub", StringComparison.OrdinalIgnoreCase);
_cam = null;
_camTries = 0;
if (!_inHub)
{
DestroyScreen();
}
}
public override void OnApplicationQuit()
{
DestroyScreen();
}
public override void OnUpdate()
{
//IL_0062: Unknown result type (might be due to invalid IL or missing references)
//IL_0068: Invalid comparison between Unknown and I4
if (!_inHub || (Object)(object)_screen != (Object)null)
{
return;
}
if ((Object)(object)_cam == (Object)null)
{
if (_camTries >= 120)
{
return;
}
_camTries++;
Il2CppReferenceArray<Camera> allCameras = Camera.allCameras;
if (allCameras == null)
{
return;
}
for (int i = 0; i < ((Il2CppArrayBase<Camera>)(object)allCameras).Length; i++)
{
if ((Object)(object)((Il2CppArrayBase<Camera>)(object)allCameras)[i] != (Object)null && (int)((Il2CppArrayBase<Camera>)(object)allCameras)[i].stereoTargetEye == 3)
{
_cam = ((Il2CppArrayBase<Camera>)(object)allCameras)[i];
break;
}
}
if ((Object)(object)_cam == (Object)null)
{
return;
}
}
CreateScreen();
}
private static bool TryReadPosition(string path, out Vector3 position, out Quaternion rotation)
{
//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_012e: Unknown result type (might be due to invalid IL or missing references)
//IL_0133: Unknown result type (might be due to invalid IL or missing references)
//IL_0141: 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)
position = Vector3.zero;
rotation = Quaternion.identity;
if (!File.Exists(path))
{
return false;
}
try
{
string[] array = File.ReadAllLines(path);
if (array.Length < 2)
{
return false;
}
string[] array2 = array[0].Split(' ');
string[] array3 = array[1].Split(' ');
if (array2.Length != 3 || array3.Length != 4)
{
return false;
}
if (!float.TryParse(array2[0], NumberStyles.Float, CultureInfo.InvariantCulture, out var result))
{
return false;
}
if (!float.TryParse(array2[1], NumberStyles.Float, CultureInfo.InvariantCulture, out var result2))
{
return false;
}
if (!float.TryParse(array2[2], NumberStyles.Float, CultureInfo.InvariantCulture, out var result3))
{
return false;
}
if (!float.TryParse(array3[0], NumberStyles.Float, CultureInfo.InvariantCulture, out var result4))
{
return false;
}
if (!float.TryParse(array3[1], NumberStyles.Float, CultureInfo.InvariantCulture, out var result5))
{
return false;
}
if (!float.TryParse(array3[2], NumberStyles.Float, CultureInfo.InvariantCulture, out var result6))
{
return false;
}
if (!float.TryParse(array3[3], NumberStyles.Float, CultureInfo.InvariantCulture, out var result7))
{
return false;
}
position = new Vector3(result, result2, result3);
rotation = new Quaternion(result4, result5, result6, result7);
return true;
}
catch
{
return false;
}
}
private static void SavePosition(string path, Vector3 position, Quaternion rotation)
{
try
{
CultureInfo invariantCulture = CultureInfo.InvariantCulture;
File.WriteAllText(path, position.x.ToString("F3", invariantCulture) + " " + position.y.ToString("F3", invariantCulture) + " " + position.z.ToString("F3", invariantCulture) + "\n" + rotation.x.ToString("F4", invariantCulture) + " " + rotation.y.ToString("F4", invariantCulture) + " " + rotation.z.ToString("F4", invariantCulture) + " " + rotation.w.ToString("F4", invariantCulture) + "\n");
}
catch
{
}
}
private bool FindWall(out Vector3 position, out Quaternion rotation)
{
//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_0021: 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_0029: 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_006e: Unknown result type (might be due to invalid IL or missing references)
//IL_0073: Unknown result type (might be due to invalid IL or missing references)
//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
//IL_00a9: 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_00b1: Unknown result type (might be due to invalid IL or missing references)
//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
//IL_00d2: 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_00dc: Unknown result type (might be due to invalid IL or missing references)
//IL_0162: Unknown result type (might be due to invalid IL or missing references)
//IL_017d: Unknown result type (might be due to invalid IL or missing references)
//IL_01b6: Unknown result type (might be due to invalid IL or missing references)
//IL_01bb: Unknown result type (might be due to invalid IL or missing references)
//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
//IL_01e2: Unknown result type (might be due to invalid IL or missing references)
//IL_01e7: Unknown result type (might be due to invalid IL or missing references)
//IL_01ec: Unknown result type (might be due to invalid IL or missing references)
//IL_01f2: 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_020a: Unknown result type (might be due to invalid IL or missing references)
//IL_020f: Unknown result type (might be due to invalid IL or missing references)
//IL_0214: Unknown result type (might be due to invalid IL or missing references)
position = Vector3.zero;
rotation = Quaternion.identity;
Vector3 position2 = ((Component)_cam).transform.position;
position2.y = Mathf.Clamp(position2.y, 1.4f, 1.8f);
Vector3 forward = ((Component)_cam).transform.forward;
forward.y = 0f;
if (((Vector3)(ref forward)).sqrMagnitude < 0.01f)
{
forward = Vector3.forward;
}
((Vector3)(ref forward)).Normalize();
Transform root = ((Component)_cam).transform.root;
RaycastHit val2 = default(RaycastHit);
RaycastHit val3 = default(RaycastHit);
for (int i = 0; i < WallAngles.Length; i++)
{
Vector3 val = Quaternion.Euler(0f, WallAngles[i], 0f) * forward;
if (Physics.Raycast(position2, val, ref val2, 12f, -1, (QueryTriggerInteraction)1) && Physics.Raycast(position2 + Vector3.up * 0.7f, val, ref val3, 12f, -1, (QueryTriggerInteraction)1) && !((Object)(object)((RaycastHit)(ref val2)).collider == (Object)null) && !((Object)(object)((RaycastHit)(ref val3)).collider == (Object)null) && !((Object)(object)((RaycastHit)(ref val2)).transform == (Object)null) && !((Object)(object)((RaycastHit)(ref val2)).transform.root == (Object)(object)root) && !(((RaycastHit)(ref val2)).distance < 1.8f) && !(((RaycastHit)(ref val2)).distance > 10f) && !(Mathf.Abs(((RaycastHit)(ref val2)).normal.y) > 0.25f) && !(Mathf.Abs(((RaycastHit)(ref val3)).normal.y) > 0.25f) && !(Mathf.Abs(((RaycastHit)(ref val2)).distance - ((RaycastHit)(ref val3)).distance) > 0.6f) && !(Vector3.Dot(((RaycastHit)(ref val2)).normal, -val) < 0.5f))
{
position = ((RaycastHit)(ref val2)).point + ((RaycastHit)(ref val2)).normal * 0.06f;
position.y = position2.y;
rotation = Quaternion.LookRotation(-((RaycastHit)(ref val2)).normal, Vector3.up);
Write("wall " + ((Object)((RaycastHit)(ref val2)).collider).name + " at " + ((Vector3)(ref position)).ToString("F2"));
return true;
}
}
return false;
}
private void CreateScreen()
{
//IL_00c7: 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_00eb: Unknown result type (might be due to invalid IL or missing references)
//IL_0102: Unknown result type (might be due to invalid IL or missing references)
//IL_010c: Expected O, but got Unknown
//IL_0119: Unknown result type (might be due to invalid IL or missing references)
//IL_0120: Expected O, but got Unknown
//IL_0228: Unknown result type (might be due to invalid IL or missing references)
//IL_022a: Unknown result type (might be due to invalid IL or missing references)
string path = Path.Combine(Application.dataPath, "..", "Mods", "HubVideo");
string text = Path.Combine(path, "hubvideo.mp4");
if (!File.Exists(text))
{
Write("missing " + text);
return;
}
try
{
Shader val = Shader.Find("Sprites/Default");
if ((Object)(object)val == (Object)null)
{
return;
}
string path2 = Path.Combine(path, "position.txt");
Vector3 position;
Quaternion rotation;
bool flag = TryReadPosition(path2, out position, out rotation);
if (!flag && !FindWall(out position, out rotation))
{
Write("no wall found");
return;
}
_screen = GameObject.CreatePrimitive((PrimitiveType)5);
Object.Destroy((Object)(object)_screen.GetComponent<Collider>());
((Object)_screen).name = "HubVideoScreen";
_screen.transform.position = position;
_screen.transform.rotation = rotation;
_screen.transform.localScale = ScreenScale;
_texture = new RenderTexture(716, 1208, 0, (RenderTextureFormat)0);
_texture.Create();
Material val2 = new Material(val);
val2.mainTexture = (Texture)(object)_texture;
_screen.GetComponent<Renderer>().material = val2;
_audio = _screen.AddComponent<AudioSource>();
_audio.playOnAwake = false;
_audio.loop = false;
_audio.volume = 0.7f;
_audio.spatialBlend = 1f;
_audio.minDistance = 1f;
_audio.maxDistance = 12f;
_player = _screen.AddComponent<VideoPlayer>();
_player.playOnAwake = false;
_player.isLooping = true;
_player.renderMode = (VideoRenderMode)2;
_player.targetTexture = _texture;
_player.audioOutputMode = (VideoAudioOutputMode)1;
_player.SetTargetAudioSource((ushort)0, _audio);
SetUrl(_player, text);
_player.Play();
if (!flag)
{
SavePosition(path2, position, rotation);
}
Write("playing " + text);
}
catch (Exception ex)
{
Write("failed " + ex);
DestroyScreen();
}
}
private unsafe static void SetUrl(VideoPlayer player, string url)
{
IntPtr intPtr = MarshalledUnityObject.MarshalNotNull<VideoPlayer>(player);
fixed (char* ptr = url)
{
ManagedSpanWrapper val = default(ManagedSpanWrapper);
((ManagedSpanWrapper)(ref val))..ctor((void*)ptr, url.Length);
VideoPlayer[intPtr] = ref val;
}
}
private void DestroyScreen()
{
if ((Object)(object)_player != (Object)null)
{
try
{
_player.Stop();
}
catch
{
}
}
if ((Object)(object)_screen != (Object)null)
{
try
{
Object.Destroy((Object)(object)_screen);
}
catch
{
}
}
_screen = null;
_player = null;
_audio = null;
if ((Object)(object)_texture != (Object)null)
{
try
{
_texture.Release();
Object.Destroy((Object)(object)_texture);
}
catch
{
}
}
_texture = null;
}
private static void Write(string s)
{
try
{
File.AppendAllText("D:\\BrutalistickVrWork\\Probe\\hubvideo.log", "[" + DateTime.Now.ToString("HH:mm:ss") + "] " + s + "\n");
}
catch
{
}
}
}
}