using System;
using System.Collections;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using FistVR;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyCompany("vithamonsta")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("simple wind plugin")]
[assembly: AssemblyFileVersion("0.0.2.0")]
[assembly: AssemblyInformationalVersion("0.0.2")]
[assembly: AssemblyProduct("wind")]
[assembly: AssemblyTitle("Simple Wind Plugin")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.2.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;
}
}
}
namespace BepInEx
{
[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
[Conditional("CodeGeneration")]
internal sealed class BepInAutoPluginAttribute : Attribute
{
public BepInAutoPluginAttribute(string id = null, string name = null, string version = null)
{
}
}
}
namespace BepInEx.Preloader.Core.Patching
{
[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
[Conditional("CodeGeneration")]
internal sealed class PatcherAutoPluginAttribute : Attribute
{
public PatcherAutoPluginAttribute(string id = null, string name = null, string version = null)
{
}
}
}
namespace visSpace
{
[BepInProcess("h3vr.exe")]
[BepInPlugin("wind", "Simple Wind Plugin", "0.0.2")]
public class WindPlugin : BaseUnityPlugin
{
internal static Vector3 WindVector;
internal static Vector3 ActiveGustVector = Vector3.zero;
internal static float WindStrength;
internal static float WindChangeTime;
internal static Vector3 GustVector;
internal static float GustSpeed;
internal static float GustRand;
internal static float GustFreq;
internal static float GustDuration;
internal static bool AffectsRb;
internal static ConfigEntry<float> WindStrConfig;
internal static ConfigEntry<float> WindTimeConfig;
internal static ConfigEntry<float> WindGustRandConfig;
internal static ConfigEntry<float> WindGustIntConfig;
internal static ConfigEntry<float> WindGustFreqConfig;
internal static ConfigEntry<float> WindGustDurConfig;
internal static ConfigEntry<bool> WindRBConfig;
public const string Id = "wind";
internal static ManualLogSource Logger { get; private set; }
public static string Name => "Simple Wind Plugin";
public static string Version => "0.0.2";
private void LoadConfig()
{
WindStrConfig = ((BaseUnityPlugin)this).Config.Bind<float>("Wind Settings", "Wind Strength", 16f, "Controls the strength of the wind effect.");
WindTimeConfig = ((BaseUnityPlugin)this).Config.Bind<float>("Wind Settings", "Wind Change Time", 90f, "Controls how often wind direction changes in minimum seconds.");
WindRBConfig = ((BaseUnityPlugin)this).Config.Bind<bool>("Wind Settings", "Wind Affects Rigidbodies", true, "Controls if wind affects all objects and not only bullets.");
WindGustRandConfig = ((BaseUnityPlugin)this).Config.Bind<float>("Wind Settings", "Gust Randomness", 0.25f, "How random gusts are");
WindGustIntConfig = ((BaseUnityPlugin)this).Config.Bind<float>("Wind Settings", "Gust Intensity", 4f, "How strong gusts are maximum");
WindGustFreqConfig = ((BaseUnityPlugin)this).Config.Bind<float>("Wind Settings", "Gust Frequency", 10f, "How often gusts occur minimum");
WindGustDurConfig = ((BaseUnityPlugin)this).Config.Bind<float>("Wind Settings", "Gust Duration", 5f, "How long gusts last minimum");
AffectsRb = WindRBConfig.Value;
WindStrength = WindStrConfig.Value;
WindChangeTime = WindTimeConfig.Value;
GustRand = WindGustRandConfig.Value;
GustSpeed = WindGustIntConfig.Value;
GustFreq = WindGustFreqConfig.Value;
GustDuration = WindGustDurConfig.Value;
WindStrConfig.SettingChanged += OnSettingChanged;
WindRBConfig.SettingChanged += OnSettingChanged;
WindTimeConfig.SettingChanged += OnSettingChanged;
WindGustIntConfig.SettingChanged += OnSettingChanged;
WindGustRandConfig.SettingChanged += OnSettingChanged;
WindGustFreqConfig.SettingChanged += OnSettingChanged;
WindGustDurConfig.SettingChanged += OnSettingChanged;
}
private void OnSettingChanged(object sender, EventArgs e)
{
WindStrength = WindStrConfig.Value;
AffectsRb = WindRBConfig.Value;
WindChangeTime = WindTimeConfig.Value;
GustRand = WindGustRandConfig.Value;
GustSpeed = WindGustIntConfig.Value;
GustFreq = WindGustFreqConfig.Value;
GustDuration = WindGustDurConfig.Value;
}
private void Awake()
{
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
Logger = ((BaseUnityPlugin)this).Logger;
new Harmony("com.vi.windplugin").PatchAll();
LoadConfig();
GenerateWind();
((MonoBehaviour)this).StartCoroutine(UpdateWind());
((MonoBehaviour)this).StartCoroutine(UpdateGustVector());
}
private void OnDestroy()
{
WindStrConfig.SettingChanged -= OnSettingChanged;
WindRBConfig.SettingChanged -= OnSettingChanged;
WindTimeConfig.SettingChanged -= OnSettingChanged;
WindGustRandConfig.SettingChanged -= OnSettingChanged;
WindGustIntConfig.SettingChanged -= OnSettingChanged;
WindGustFreqConfig.SettingChanged -= OnSettingChanged;
WindGustDurConfig.SettingChanged -= OnSettingChanged;
}
private IEnumerator UpdateGustVector()
{
while (true)
{
GustVector = WindVector;
Vector3 val = new Vector3(Random.Range(-1f, 1f), Random.Range(-0.1f, 0.1f), Random.Range(-1f, 1f));
Vector3 val2 = ((Vector3)(ref val)).normalized * (((Vector3)(ref GustVector)).magnitude * GustRand);
GustVector += val2;
float num = Random.Range(0.01f, GustSpeed);
GustVector *= num;
yield return ((MonoBehaviour)this).StartCoroutine(SmoothDoGust(Random.Range(GustDuration, GustDuration * 4f)));
yield return (object)new WaitForSeconds(Random.Range(GustFreq, GustFreq * 4f));
}
}
private IEnumerator SmoothDoGust(float duration)
{
Vector3 startValue = ActiveGustVector;
float elapsedTime2 = 0f;
float num = Random.Range(duration / 10f, duration - duration / 10f);
float num2 = Random.Range(duration / 10f, duration - duration / 10f);
float attackTime = Mathf.Min(num, num2);
float sustainTime = Mathf.Max(num, num2) - attackTime;
float decayTime = duration - (attackTime + sustainTime);
while (elapsedTime2 < attackTime)
{
ActiveGustVector = Vector3.Slerp(startValue, GustVector, elapsedTime2 / attackTime);
elapsedTime2 += Time.deltaTime;
yield return null;
}
yield return (object)new WaitForSeconds(sustainTime);
elapsedTime2 = 0f;
while (elapsedTime2 < decayTime)
{
ActiveGustVector = Vector3.Slerp(ActiveGustVector, startValue, elapsedTime2 / decayTime);
elapsedTime2 += Time.deltaTime;
yield return null;
}
ActiveGustVector *= 0f;
}
private IEnumerator SmoothChangeWind(Vector3 targetValue, float duration)
{
//IL_0007: 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)
Vector3 startValue = WindVector;
float elapsedTime = 0f;
while (elapsedTime < duration)
{
WindVector = Vector3.Lerp(startValue, targetValue, elapsedTime / duration);
elapsedTime += Time.deltaTime;
yield return null;
}
WindVector = targetValue;
}
private void FixedUpdate()
{
if (AffectsRb)
{
Rigidbody[] array = Object.FindObjectsOfType<Rigidbody>();
foreach (Rigidbody rb in array)
{
ApplyWindForce(rb);
}
}
}
private void ApplyWindForce(Rigidbody rb)
{
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
//IL_000d: 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_001a: 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_0029: 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_0052: 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_0060: 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)
//IL_0068: Unknown result type (might be due to invalid IL or missing references)
float colliderSurfaceArea = GetColliderSurfaceArea(rb);
Vector3 val = WindVector + ActiveGustVector;
Vector3 normalized = ((Vector3)(ref val)).normalized;
float sqrMagnitude = ((Vector3)(ref val)).sqrMagnitude;
float num = Vector3.Dot(rb.velocity, normalized);
float num2 = Mathf.Max(0f, sqrMagnitude - num * num);
if (num2 > 0f)
{
Vector3 val2 = normalized * Mathf.Sqrt(num2) * colliderSurfaceArea;
rb.AddForce(val2, (ForceMode)0);
}
}
private float GetColliderSurfaceArea(Rigidbody rb)
{
//IL_0014: 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_0021: 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_003a: Unknown result type (might be due to invalid IL or missing references)
//IL_0046: 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_0060: Unknown result type (might be due to invalid IL or missing references)
float num = 0f;
Collider[] components = ((Component)rb).GetComponents<Collider>();
for (int i = 0; i < components.Length; i++)
{
Bounds bounds = components[i].bounds;
float num2 = 2f * (((Bounds)(ref bounds)).size.x * ((Bounds)(ref bounds)).size.y + ((Bounds)(ref bounds)).size.x * ((Bounds)(ref bounds)).size.z + ((Bounds)(ref bounds)).size.y * ((Bounds)(ref bounds)).size.z);
num += num2;
}
return num;
}
private IEnumerator UpdateWind()
{
while (true)
{
float num = Random.Range(-1f, 1f);
float num2 = Random.Range(-0.1f, 0.1f);
float num3 = Random.Range(-1f, 1f);
Vector3 newWind = new Vector3(num, num2, num3) * Random.Range(0.01f, WindStrength);
float randTime = WindChangeTime * (float)Random.Range(1, 4);
yield return ((MonoBehaviour)this).StartCoroutine(SmoothChangeWind(newWind, randTime));
if (Logger != null)
{
Logger.LogInfo((object)$"Generated Wind Vector: {newWind}");
}
yield return (object)new WaitForSeconds(randTime / (float)Random.Range(1, 16));
}
}
public static void GenerateWind()
{
//IL_0031: 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_004a: Unknown result type (might be due to invalid IL or missing references)
//IL_0060: Unknown result type (might be due to invalid IL or missing references)
float num = Random.Range(-1f, 1f);
float num2 = Random.Range(-0.1f, 0.1f);
float num3 = Random.Range(-1f, 1f);
WindVector = new Vector3(num, num2, num3) * Random.Range(0.01f, WindStrength);
if (Logger != null)
{
Logger.LogInfo((object)$"Generated Wind Vector: {WindVector}");
}
}
}
}
namespace visSpace.Patches
{
[HarmonyPatch(typeof(BallisticProjectile), "ApplyDrag")]
public class BulletDragPatch
{
[HarmonyPrefix]
public static void Prefix(ref Vector3 velocity, ref float time)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//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_0011: Unknown result type (might be due to invalid IL or missing references)
//IL_0018: Unknown result type (might be due to invalid IL or missing references)
//IL_001d: 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)
velocity += (WindPlugin.ActiveGustVector + WindPlugin.WindVector) * time;
}
}
}