using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using Il2CppFemur;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using KoStars;
using MelonLoader;
using UnityEngine;
using UnityEngine.Rendering;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: MelonInfo(typeof(KoStarsMod), "KoStars", "1.0.0", "Zooks", null)]
[assembly: MelonGame("Boneloaf", "Gang Beasts")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("KoStars")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("KoStars")]
[assembly: AssemblyTitle("KoStars")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace KoStars;
public class KoStarsMod : MelonMod
{
private readonly List<StarTracker> _trackers = new List<StarTracker>();
private static Mesh _cachedMesh;
public override void OnSceneWasInitialized(int buildIndex, string sceneName)
{
ClearAllTrackers();
ScanForActors();
}
public override void OnUpdate()
{
if (Time.frameCount % 15 == 0)
{
ScanForActors();
}
}
public override void OnLateUpdate()
{
for (int num = _trackers.Count - 1; num >= 0; num--)
{
StarTracker starTracker = _trackers[num];
if (starTracker == null || starTracker.IsActorDead())
{
starTracker?.Dispose();
_trackers.RemoveAt(num);
}
else
{
starTracker.UpdateEffect();
}
}
}
public override void OnSceneWasUnloaded(int buildIndex, string sceneName)
{
ClearAllTrackers();
}
private void ScanForActors()
{
Il2CppArrayBase<Actor> val = Object.FindObjectsOfType<Actor>();
if (val == null)
{
return;
}
for (int i = 0; i < val.Length; i++)
{
Actor val2 = val[i];
if ((Object)(object)val2 == (Object)null)
{
continue;
}
bool flag = false;
for (int j = 0; j < _trackers.Count; j++)
{
if ((Object)(object)_trackers[j].TargetActor == (Object)(object)val2)
{
flag = true;
break;
}
}
if (!flag)
{
if ((Object)(object)_cachedMesh == (Object)null)
{
_cachedMesh = GenerateCrispStarMesh();
}
_trackers.Add(new StarTracker(val2, _cachedMesh));
}
}
}
private void ClearAllTrackers()
{
for (int i = 0; i < _trackers.Count; i++)
{
_trackers[i]?.Dispose();
}
_trackers.Clear();
}
private static Mesh GenerateCrispStarMesh()
{
//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_0011: Expected O, but got Unknown
//IL_0065: 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_00d4: Unknown result type (might be due to invalid IL or missing references)
//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
//IL_012d: 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_013c: 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_014f: Unknown result type (might be due to invalid IL or missing references)
//IL_0154: Unknown result type (might be due to invalid IL or missing references)
//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
//IL_01c1: Unknown result type (might be due to invalid IL or missing references)
//IL_01c6: Unknown result type (might be due to invalid IL or missing references)
Mesh val = new Mesh
{
name = "Star_Crisp"
};
Vector3[] array = (Vector3[])(object)new Vector3[10];
for (int i = 0; i < 10; i++)
{
float num = (float)i * (float)Math.PI / 5f + (float)Math.PI / 2f;
float num2 = ((i % 2 == 0) ? 0.075f : 0.032f);
array[i] = new Vector3(Mathf.Cos(num) * num2, Mathf.Sin(num) * num2, 0f);
}
Vector3 val2 = default(Vector3);
((Vector3)(ref val2))..ctor(0f, 0f, 0.012f);
Vector3 val3 = default(Vector3);
((Vector3)(ref val3))..ctor(0f, 0f, -0.012f);
Vector3[] array2 = (Vector3[])(object)new Vector3[60];
int[] array3 = new int[60];
int num3 = 0;
int num4 = 0;
for (int j = 0; j < 10; j++)
{
int num5 = (j + 1) % 10;
array2[num3] = val2;
array2[num3 + 1] = array[j];
array2[num3 + 2] = array[num5];
array3[num4] = num3;
array3[num4 + 1] = num3 + 1;
array3[num4 + 2] = num3 + 2;
num3 += 3;
num4 += 3;
array2[num3] = val3;
array2[num3 + 1] = array[num5];
array2[num3 + 2] = array[j];
array3[num4] = num3;
array3[num4 + 1] = num3 + 1;
array3[num4 + 2] = num3 + 2;
num3 += 3;
num4 += 3;
}
val.vertices = Il2CppStructArray<Vector3>.op_Implicit(array2);
val.triangles = Il2CppStructArray<int>.op_Implicit(array3);
val.RecalculateNormals();
val.bounds = new Bounds(Vector3.zero, Vector3.one * 10f);
return val;
}
}
public class StarTracker
{
private Transform _headTransform;
private GameObject _pivot;
private readonly Transform[] _stars;
private Material _material;
private const int StarCount = 4;
private float _orbitAngle;
private float _scale;
private Vector3 _smoothHeadPos;
private Color _appliedColor;
public Actor TargetActor { get; }
public StarTracker(Actor actor, Mesh mesh)
{
//IL_0025: Unknown result type (might be due to invalid IL or missing references)
//IL_002f: Expected O, but got Unknown
//IL_0081: Unknown result type (might be due to invalid IL or missing references)
//IL_0087: Expected O, but got Unknown
TargetActor = actor;
_stars = (Transform[])(object)new Transform[4];
CreateMaterial();
_pivot = new GameObject("DizzyHalo");
_pivot.transform.SetParent((Transform)null);
_pivot.layer = ((Component)actor).gameObject.layer;
for (int i = 0; i < 4; i++)
{
GameObject val = new GameObject($"Star_{i}");
val.transform.SetParent(_pivot.transform);
val.layer = ((Component)actor).gameObject.layer;
MeshFilter val2 = val.AddComponent<MeshFilter>();
MeshRenderer obj = val.AddComponent<MeshRenderer>();
val2.sharedMesh = mesh;
((Renderer)obj).sharedMaterial = _material;
((Renderer)obj).shadowCastingMode = (ShadowCastingMode)0;
((Renderer)obj).receiveShadows = false;
_stars[i] = val.transform;
}
_pivot.SetActive(false);
ResolveHead();
}
private void CreateMaterial()
{
//IL_0091: Unknown result type (might be due to invalid IL or missing references)
//IL_009b: Expected O, but got Unknown
Shader val = null;
if ((Object)(object)TargetActor != (Object)null && (Object)(object)TargetActor.bodyHandeler != (Object)null && (Object)(object)TargetActor.bodyHandeler.headMaterial != (Object)null)
{
val = TargetActor.bodyHandeler.headMaterial.shader;
}
if ((Object)(object)val == (Object)null)
{
val = Shader.Find("Universal Render Pipeline/Lit") ?? Shader.Find("Universal Render Pipeline/Simple Lit") ?? Shader.Find("Universal Render Pipeline/Unlit") ?? Shader.Find("Standard");
}
_material = new Material(val);
if (_material.HasProperty("_Smoothness"))
{
_material.SetFloat("_Smoothness", 0.95f);
}
if (_material.HasProperty("_Metallic"))
{
_material.SetFloat("_Metallic", 0.1f);
}
if (_material.HasProperty("_EmissionColor"))
{
_material.EnableKeyword("_EMISSION");
}
SyncColor(force: true);
}
private void SyncColor(bool force = false)
{
//IL_0023: 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_0029: 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_003c: Unknown result type (might be due to invalid IL or missing references)
//IL_0041: 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_007e: 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_00a0: Unknown result type (might be due to invalid IL or missing references)
//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)TargetActor == (Object)null || (Object)(object)_material == (Object)null)
{
return;
}
Color val = TargetActor.primaryColor;
if (val.a < 0.1f)
{
val = TargetActor.CostumeColor;
}
if (val.a < 0.1f)
{
((Color)(ref val))..ctor(1f, 0.88f, 0.15f, 1f);
}
if (force || !(_appliedColor == val))
{
_appliedColor = val;
if (_material.HasProperty("_BaseColor"))
{
_material.SetColor("_BaseColor", val);
}
if (_material.HasProperty("_Color"))
{
_material.SetColor("_Color", val);
}
if (_material.HasProperty("_EmissionColor"))
{
_material.SetColor("_EmissionColor", val * 1.8f);
}
}
}
public bool IsActorDead()
{
if (!((Object)(object)TargetActor == (Object)null))
{
return (Object)(object)((Component)TargetActor).gameObject == (Object)null;
}
return true;
}
private void ResolveHead()
{
//IL_0064: 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_00ad: 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)
if ((Object)(object)TargetActor == (Object)null)
{
return;
}
if ((Object)(object)TargetActor.bodyHandeler != (Object)null && TargetActor.bodyHandeler.Head != null)
{
_headTransform = TargetActor.bodyHandeler.Head.PartTransform;
if ((Object)(object)_headTransform != (Object)null)
{
_smoothHeadPos = _headTransform.position;
return;
}
}
Il2CppArrayBase<Transform> componentsInChildren = ((Component)TargetActor).GetComponentsInChildren<Transform>();
for (int i = 0; i < componentsInChildren.Length; i++)
{
if (((Object)componentsInChildren[i]).name.IndexOf("head", StringComparison.OrdinalIgnoreCase) >= 0)
{
_headTransform = componentsInChildren[i];
_smoothHeadPos = _headTransform.position;
break;
}
}
}
public void UpdateEffect()
{
//IL_0030: Unknown result type (might be due to invalid IL or missing references)
//IL_0036: Invalid comparison between Unknown and I4
//IL_003e: 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_0046: Invalid comparison between Unknown and I4
//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
//IL_00da: Unknown result type (might be due to invalid IL or missing references)
//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
//IL_0100: 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_010f: 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_0129: Unknown result type (might be due to invalid IL or missing references)
//IL_0134: Unknown result type (might be due to invalid IL or missing references)
//IL_00c3: 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_01ae: Unknown result type (might be due to invalid IL or missing references)
//IL_01b3: Unknown result type (might be due to invalid IL or missing references)
//IL_0218: Unknown result type (might be due to invalid IL or missing references)
//IL_021f: Unknown result type (might be due to invalid IL or missing references)
//IL_0224: Unknown result type (might be due to invalid IL or missing references)
//IL_0281: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)_headTransform == (Object)null)
{
ResolveHead();
if ((Object)(object)_headTransform == (Object)null)
{
return;
}
}
SyncColor();
bool flag = (int)TargetActor.actorState == 2 || (TargetActor.actorState & 2) > 0;
float num = (flag ? 1f : 0f);
_scale = Mathf.MoveTowards(_scale, num, Time.deltaTime * 6.5f);
if (_scale <= 0.001f && !flag)
{
if (_pivot.activeSelf)
{
_pivot.SetActive(false);
}
return;
}
if (!_pivot.activeSelf)
{
_pivot.SetActive(true);
_smoothHeadPos = _headTransform.position;
}
_smoothHeadPos = Vector3.Lerp(_smoothHeadPos, _headTransform.position, Time.deltaTime * 24f);
_pivot.transform.position = _smoothHeadPos + Vector3.up * 0.4f;
_pivot.transform.localScale = Vector3.one * _scale;
_orbitAngle += 280f * Time.deltaTime;
if (_orbitAngle >= 360f)
{
_orbitAngle -= 360f;
}
float num2 = Mathf.Sin(Time.time * 2.5f) * 6f + 16f;
float num3 = Mathf.Cos(Time.time * 2.5f) * 6f;
Quaternion val = Quaternion.Euler(num2, 0f, num3);
for (int i = 0; i < _stars.Length; i++)
{
float num4 = (_orbitAngle + 90f * (float)i) * ((float)Math.PI / 180f);
float num5 = Mathf.Cos(num4) * 0.32f;
float num6 = Mathf.Sin(num4) * 0.32f;
float num7 = Mathf.Sin(Time.time * 7f + (float)i * 1.6f) * 0.035f;
_stars[i].localPosition = val * new Vector3(num5, num7, num6);
_stars[i].localRotation = Quaternion.Euler(Mathf.Sin(Time.time * 4f + (float)i) * 25f, _orbitAngle * 2f + (float)i * 90f, Mathf.Cos(Time.time * 4f + (float)i) * 25f);
}
}
public void Dispose()
{
if ((Object)(object)_pivot != (Object)null)
{
Object.Destroy((Object)(object)_pivot);
}
}
}