using System;
using System.Collections;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using FireballMod;
using Il2Cpp;
using Il2CppHurricaneVR.Framework.Core.Grabbers;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppSystem;
using Il2CppSystem.Reflection;
using MelonLoader;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: MelonInfo(typeof(Core), "FireballMod", "1.1.0", "YourName", null)]
[assembly: MelonGame("Kubunautilus", "BrutalistickVR")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("FireballMod")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("FireballMod")]
[assembly: AssemblyTitle("FireballMod")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace FireballMod;
public class Core : MelonMod
{
private enum State
{
Idle,
Charging,
Ready,
Cooldown
}
public static HVRHexaBodyInputs playerInputs;
public static HVRHandGrabber leftHand;
public static HVRHandGrabber rightHand;
private State leftState = State.Idle;
private State rightState = State.Idle;
private GameObject leftFireball;
private GameObject rightFireball;
private float leftCharge;
private float rightCharge;
private bool wasLeftStick;
private bool wasRightStick;
private const float CHARGE_SPEED = 1.2f;
private const float MAX_CHARGE = 1f;
private const float MIN_SIZE = 0.06f;
private const float MAX_SIZE = 0.35f;
private const float SHOOT_SPEED = 30f;
private const float COOLDOWN = 0.4f;
private const float MIN_CHARGE_TO_SHOOT = 0.15f;
public override void OnSceneWasLoaded(int buildIndex, string sceneName)
{
if (sceneName == "MainMenuScene")
{
return;
}
GameObject val = GameObject.Find("Hexa4Rig26.10.23");
if ((Object)(object)val == (Object)null)
{
((MelonBase)this).LoggerInstance.Warning("Hexa4Rig26.10.23 не найден!");
return;
}
playerInputs = val.GetComponentInChildren<HVRHexaBodyInputs>();
Transform obj = val.transform.Find("Physics LeftHand");
leftHand = ((obj != null) ? ((Component)obj).GetComponent<HVRHandGrabber>() : null);
Transform obj2 = val.transform.Find("Physics RightHand");
rightHand = ((obj2 != null) ? ((Component)obj2).GetComponent<HVRHandGrabber>() : null);
if ((Object)(object)leftHand == (Object)null || (Object)(object)rightHand == (Object)null)
{
((MelonBase)this).LoggerInstance.Warning("Руки не найдены!");
}
else
{
((MelonBase)this).LoggerInstance.Msg("FireballMod загружен! Взрыв через корутину.");
}
}
public override void OnUpdate()
{
//IL_001f: 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)
if (!((Object)(object)playerInputs == (Object)null))
{
bool active = playerInputs.LeftController.JoystickButtonState.Active;
bool active2 = playerInputs.RightController.JoystickButtonState.Active;
ProcessHand(isLeft: true, active, wasLeftStick, ref leftState, ref leftFireball, ref leftCharge, leftHand);
ProcessHand(isLeft: false, active2, wasRightStick, ref rightState, ref rightFireball, ref rightCharge, rightHand);
wasLeftStick = active;
wasRightStick = active2;
}
}
private void ProcessHand(bool isLeft, bool stick, bool wasStick, ref State state, ref GameObject ball, ref float charge, HVRHandGrabber hand)
{
if ((Object)(object)hand == (Object)null)
{
return;
}
if (state == State.Idle)
{
if (stick && !wasStick)
{
state = State.Charging;
ball = CreateBall(((Component)hand).transform);
charge = 0f;
}
}
else if (state == State.Charging)
{
if (!stick && wasStick)
{
if (charge < 0.15f)
{
CancelBall(ref ball);
state = State.Cooldown;
MelonCoroutines.Start(ResetAfterCooldown(isLeft));
}
else
{
state = State.Ready;
}
}
else
{
charge += Time.deltaTime * 1.2f;
if (charge > 1f)
{
charge = 1f;
}
UpdateBall(ball, charge);
}
}
else if (state == State.Ready && stick && !wasStick)
{
Shoot(ball, ((Component)hand).transform, charge);
ball = null;
state = State.Cooldown;
MelonCoroutines.Start(ResetAfterCooldown(isLeft));
}
}
private GameObject CreateBall(Transform hand)
{
//IL_0042: 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_0064: 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_008a: Unknown result type (might be due to invalid IL or missing references)
//IL_0090: Expected O, but got Unknown
//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
//IL_00bb: 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_0108: Unknown result type (might be due to invalid IL or missing references)
GameObject val = GameObject.CreatePrimitive((PrimitiveType)0);
Object.Destroy((Object)(object)val.GetComponent<Collider>());
((Object)val).name = "Fireball";
val.transform.SetParent(hand);
val.transform.localPosition = new Vector3(0f, 0.05f, 0.12f);
val.transform.localRotation = Quaternion.identity;
val.transform.localScale = Vector3.one * 0.06f;
Renderer component = val.GetComponent<Renderer>();
Material val2 = new Material(Shader.Find("Standard"));
val2.EnableKeyword("_EMISSION");
val2.SetColor("_EmissionColor", new Color(1f, 0.1f, 0f) * 3f);
val2.color = new Color(1f, 0.35f, 0f);
component.material = val2;
Light val3 = val.AddComponent<Light>();
val3.type = (LightType)2;
val3.color = new Color(1f, 0.5f, 0f);
val3.intensity = 1.5f;
val3.range = 0.6f;
return val;
}
private void UpdateBall(GameObject b, float charge)
{
//IL_0032: Unknown result type (might be due to invalid IL or missing references)
//IL_0038: 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_007b: Unknown result type (might be due to invalid IL or missing references)
//IL_0081: Unknown result type (might be due to invalid IL or missing references)
//IL_0086: 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_00a5: Unknown result type (might be due to invalid IL or missing references)
//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
if (!((Object)(object)b == (Object)null))
{
float num = charge / 1f;
float num2 = Mathf.Lerp(0.06f, 0.35f, num);
b.transform.localScale = Vector3.one * num2;
Renderer component = b.GetComponent<Renderer>();
if ((Object)(object)component != (Object)null)
{
Color val = Color.Lerp(new Color(1f, 0.4f, 0f), new Color(1f, 0.05f, 0f), num);
component.material.SetColor("_EmissionColor", val * Mathf.Lerp(2f, 6f, num));
component.material.color = val;
}
Light component2 = b.GetComponent<Light>();
if ((Object)(object)component2 != (Object)null)
{
component2.intensity = Mathf.Lerp(1.5f, 5f, num);
component2.range = Mathf.Lerp(0.6f, 2.5f, num);
}
}
}
private void Shoot(GameObject b, Transform hand, float charge)
{
//IL_0066: 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)
if (!((Object)(object)b == (Object)null))
{
b.transform.SetParent((Transform)null);
SphereCollider val = b.AddComponent<SphereCollider>();
val.radius = 0.5f;
((Collider)val).isTrigger = false;
Rigidbody val2 = b.AddComponent<Rigidbody>();
val2.useGravity = false;
val2.collisionDetectionMode = (CollisionDetectionMode)2;
float num = Mathf.Lerp(18f, 30f, charge / 1f);
val2.velocity = hand.forward * num;
MelonCoroutines.Start(TrackFireball(b, charge));
}
}
private void CancelBall(ref GameObject ball)
{
if ((Object)(object)ball != (Object)null)
{
Object.Destroy((Object)(object)ball);
ball = null;
}
}
private IEnumerator ResetAfterCooldown(bool isLeft)
{
yield return (object)new WaitForSeconds(0.4f);
if (isLeft)
{
leftState = State.Idle;
}
else
{
rightState = State.Idle;
}
}
private IEnumerator TrackFireball(GameObject ball, float charge)
{
yield return (object)new WaitForSeconds(0.05f);
float startTime = Time.time;
float checkRadius = 0.4f;
while ((Object)(object)ball != (Object)null && Time.time - startTime < 5f)
{
Vector3 pos = ball.transform.position;
Collider[] hits = Il2CppArrayBase<Collider>.op_Implicit((Il2CppArrayBase<Collider>)(object)Physics.OverlapSphere(pos, checkRadius));
Collider[] array = hits;
foreach (Collider hit in array)
{
if (!((Object)(object)((Component)hit).gameObject == (Object)(object)ball) && !hit.isTrigger)
{
Explode(pos, charge);
Object.Destroy((Object)(object)ball);
yield break;
}
}
yield return null;
}
if ((Object)(object)ball != (Object)null)
{
Object.Destroy((Object)(object)ball);
}
}
private void Explode(Vector3 position, float charge)
{
//IL_0041: 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_0093: Unknown result type (might be due to invalid IL or missing references)
//IL_007c: Unknown result type (might be due to invalid IL or missing references)
float num = Mathf.Clamp01(charge / 1f);
float num2 = Mathf.Lerp(1.5f, 3.5f, num);
float num3 = Mathf.Lerp(400f, 1200f, num);
float damage = Mathf.Lerp(30f, 100f, num);
Collider[] array = Il2CppArrayBase<Collider>.op_Implicit((Il2CppArrayBase<Collider>)(object)Physics.OverlapSphere(position, num2));
Collider[] array2 = array;
foreach (Collider val in array2)
{
Rigidbody component = ((Component)val).GetComponent<Rigidbody>();
if ((Object)(object)component != (Object)null)
{
component.AddExplosionForce(num3, position, num2, 1f, (ForceMode)1);
}
ApplyDamage(((Component)val).gameObject, position, damage, num2);
}
SpawnExplosionEffect(position, num2);
}
private void ApplyDamage(GameObject target, Vector3 hitPosition, float damage, float radius)
{
//IL_0066: 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_00b5: Unknown result type (might be due to invalid IL or missing references)
Component val = FindIl2CppComponent(target, "StickHealth");
if ((Object)(object)val == (Object)null && (Object)(object)target.transform.parent != (Object)null)
{
val = FindIl2CppComponent(((Component)target.transform.parent).gameObject, "StickHealth");
}
if ((Object)(object)val == (Object)null)
{
return;
}
Type type = ((object)val).GetType();
float num = Vector3.Distance(hitPosition, target.transform.position);
float num2 = 1f - num / radius;
float num3 = damage * Mathf.Clamp01(num2);
MethodInfo method = type.GetMethod("HitByBullet");
if (method != null)
{
try
{
method.Invoke(val, new object[3] { hitPosition, num3, false });
return;
}
catch
{
}
}
MethodInfo method2 = type.GetMethod("ReceivedGeneralDamage");
if (method2 != null)
{
try
{
Type nestedType = type.GetNestedType("DamageType");
object obj2 = 1;
if (nestedType != null && nestedType.IsEnum)
{
try
{
obj2 = Enum.Parse(nestedType, "Explosion");
}
catch
{
obj2 = Convert.ChangeType(1, nestedType);
}
}
method2.Invoke(val, new object[4] { num3, obj2, "torso", null });
return;
}
catch
{
}
}
MethodInfo method3 = type.GetMethod("KillZoneEntered");
if (!(method3 != null))
{
return;
}
try
{
method3.Invoke(val, null);
}
catch
{
}
}
private Component FindIl2CppComponent(GameObject go, string typeName)
{
if ((Object)(object)go == (Object)null)
{
return null;
}
Il2CppArrayBase<Component> components = go.GetComponents<Component>();
if (components == null)
{
return null;
}
foreach (Component item in components)
{
if ((Object)(object)item == (Object)null || !(((MemberInfo)((Object)item).GetIl2CppType()).Name == typeName))
{
continue;
}
return item;
}
return null;
}
private void SpawnExplosionEffect(Vector3 position, float radius)
{
//IL_0026: 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)
//IL_003d: 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)
//IL_005f: Expected O, but got Unknown
//IL_0080: Unknown result type (might be due to invalid IL or missing references)
//IL_008a: Unknown result type (might be due to invalid IL or missing references)
//IL_00a5: 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)
GameObject val = GameObject.CreatePrimitive((PrimitiveType)0);
Object.Destroy((Object)(object)val.GetComponent<Collider>());
((Object)val).name = "FireballExplosion";
val.transform.position = position;
val.transform.localScale = Vector3.one * 0.1f;
Renderer component = val.GetComponent<Renderer>();
Material val2 = new Material(Shader.Find("Standard"));
val2.EnableKeyword("_EMISSION");
val2.SetColor("_EmissionColor", new Color(1f, 0.6f, 0.1f) * 8f);
val2.color = new Color(1f, 0.4f, 0f);
component.material = val2;
Light val3 = val.AddComponent<Light>();
val3.type = (LightType)2;
val3.color = new Color(1f, 0.7f, 0.2f);
val3.intensity = 20f;
val3.range = radius * 3f;
MelonCoroutines.Start(ExplosionAnimation(val, val3));
}
private IEnumerator ExplosionAnimation(GameObject explosion, Light flash)
{
float duration = 0.3f;
float elapsed = 0f;
Vector3 maxScale = Vector3.one * 2.5f;
while (elapsed < duration)
{
elapsed += Time.deltaTime;
float t = elapsed / duration;
explosion.transform.localScale = Vector3.Lerp(Vector3.one * 0.1f, maxScale, t);
flash.intensity = Mathf.Lerp(20f, 0f, t * t);
Renderer r = explosion.GetComponent<Renderer>();
if ((Object)(object)r != (Object)null)
{
Color c = Color.Lerp(new Color(1f, 0.5f, 0f), new Color(0.2f, 0.05f, 0f), t);
r.material.SetColor("_EmissionColor", c * Mathf.Lerp(8f, 0f, t));
}
yield return null;
}
Object.Destroy((Object)(object)explosion);
}
}