using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security.Cryptography;
using System.Text;
using BepInEx;
using Mirror;
using TMPro;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("BeybladeBattle")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("BeybladeBattle")]
[assembly: AssemblyCopyright("Copyright © 2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("7a9e931a-d0bf-425e-93f0-af903091fc02")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace BeybladeBattleMod
{
[BepInPlugin("com.Syd4r.BeybladeBattle", "Beyblade Battle", "1.0.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class BeybladeBattlePlugin : BaseUnityPlugin
{
private void Awake()
{
((BaseUnityPlugin)this).Logger.LogInfo((object)"Beyblade Battle Assembly loaded by BepInEx! Waiting for Base Loader...");
}
}
}
namespace MoreGamesBase
{
public class Stats
{
public string name;
public int stability;
public int longevity;
public int attack;
public int defense;
public int total;
public int spinDirection;
public float oddsMultiplier;
public Color color;
public int originalIndex;
}
public enum GameState
{
Betting,
Fighting,
Finished
}
public class BeybladeBattle : GameBase
{
public GameObject beybladeBasePrefab;
public GameObject arenaPrefab;
public Transform spawnLocation1;
public Transform spawnLocation2;
public Transform spawnLocation3;
public Transform spawnLocation4;
public Transform textSpawnLocation1;
public Transform textSpawnLocation2;
public Transform textSpawnLocation3;
public Transform textSpawnLocation4;
public GameObject buttonSelected1;
public GameObject buttonSelected2;
public GameObject buttonSelected3;
public GameObject buttonSelected4;
public GameObject winText;
public GameObject statsPrefab;
private Vector2 arenaCenter = Vector2.zero;
private int currentBetNum = 0;
private GameState currentState = GameState.Betting;
private float resetTimer = 0f;
private float fightTimer = 0f;
private readonly List<Stats> beybladeStats = new List<Stats>();
private readonly List<GameObject> activeBeyblades = new List<GameObject>();
private readonly List<GameObject> activeStatUIs = new List<GameObject>();
private List<Transform> spawnLocations = new List<Transform>();
private List<Transform> textSpawnLocations = new List<Transform>();
private readonly Dictionary<GameObject, float> deathTimers = new Dictionary<GameObject, float>();
private readonly Color[] slotColors = (Color[])(object)new Color[4]
{
Color.red,
Color.cyan,
Color.green,
Color.yellow
};
private void Start()
{
SetupBeybladeNetworking();
InitArena();
InitBettingPhase();
}
private void SetupBeybladeNetworking()
{
//IL_015a: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)beybladeBasePrefab == (Object)null)
{
return;
}
beybladeBasePrefab.SetActive(false);
NetworkIdentity component = beybladeBasePrefab.GetComponent<NetworkIdentity>();
if ((Object)(object)component == (Object)null)
{
component = beybladeBasePrefab.AddComponent<NetworkIdentity>();
uint num;
using (MD5 mD = MD5.Create())
{
byte[] value = mD.ComputeHash(Encoding.UTF8.GetBytes("BeybladeTemplate_" + ((Object)beybladeBasePrefab).name));
num = BitConverter.ToUInt32(value, 0);
}
PropertyInfo property = typeof(NetworkIdentity).GetProperty("assetId", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
if (property != null && property.CanWrite)
{
property.SetValue(component, num);
}
else
{
FieldInfo field = typeof(NetworkIdentity).GetField("<assetId>k__BackingField", BindingFlags.Instance | BindingFlags.NonPublic);
if (field != null)
{
field.SetValue(component, num);
}
}
NetworkClient.RegisterPrefab(beybladeBasePrefab, num);
}
NetworkTransformReliable component2 = beybladeBasePrefab.GetComponent<NetworkTransformReliable>();
if ((Object)(object)component2 == (Object)null)
{
component2 = beybladeBasePrefab.AddComponent<NetworkTransformReliable>();
((NetworkTransformBase)component2).target = beybladeBasePrefab.transform;
((NetworkBehaviour)component2).syncDirection = (SyncDirection)0;
}
}
private void InitArena()
{
//IL_000d: 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)
//IL_002c: Unknown result type (might be due to invalid IL or missing references)
//IL_0031: Unknown result type (might be due to invalid IL or missing references)
arenaCenter = new Vector2(arenaPrefab.transform.position.x, arenaPrefab.transform.position.z);
spawnLocations = new List<Transform> { spawnLocation1, spawnLocation2, spawnLocation3, spawnLocation4 };
textSpawnLocations = new List<Transform> { textSpawnLocation1, textSpawnLocation2, textSpawnLocation3, textSpawnLocation4 };
if ((Object)(object)winText != (Object)null)
{
winText.SetActive(false);
}
}
private void InitBettingPhase()
{
currentState = GameState.Betting;
if ((Object)(object)winText != (Object)null)
{
winText.SetActive(false);
}
GenerateBeyblades();
SpawnStatUI();
UpdateButtonVisuals();
}
private void GenerateBeyblades()
{
//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)
beybladeStats.Clear();
for (int i = 0; i < spawnLocations.Count; i++)
{
Stats stats = new Stats
{
originalIndex = i,
color = slotColors[i],
name = GenerateRandomName(),
stability = Random.Range(1, 11),
longevity = Random.Range(1, 11),
attack = Random.Range(1, 11),
defense = Random.Range(1, 11),
spinDirection = Random.Range(0, 2)
};
stats.total = stats.stability + stats.longevity + stats.attack + stats.defense;
beybladeStats.Add(stats);
}
int num = beybladeStats.Sum((Stats s) => s.total);
foreach (Stats beybladeStat in beybladeStats)
{
float num2 = (float)beybladeStat.total / (float)num;
float num3 = 0.7f;
float num4 = Random.Range(0.9f, 1.1f);
float num5 = 1f / num2 * num3 * num4;
beybladeStat.oddsMultiplier = (float)Math.Round(Mathf.Clamp(num5, 1.1f, 10f), 2);
}
}
private void SpawnStatUI()
{
//IL_005f: 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_0073: Unknown result type (might be due to invalid IL or missing references)
//IL_0084: Unknown result type (might be due to invalid IL or missing references)
//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
foreach (GameObject activeStatUI in activeStatUIs)
{
Object.Destroy((Object)(object)activeStatUI);
}
activeStatUIs.Clear();
for (int i = 0; i < spawnLocations.Count; i++)
{
GameObject val = Object.Instantiate<GameObject>(statsPrefab, textSpawnLocations[i].position + Vector3.up * 1.9f, textSpawnLocations[i].rotation, textSpawnLocations[i]);
Stats stats = beybladeStats[i];
val.AddComponent<LookAtCamera>();
SetTextSafely(val, "name", "<color=#" + ColorUtility.ToHtmlStringRGB(stats.color) + ">" + stats.name + "</color>");
SetTextSafely(val, "spin", "Spin: " + ((stats.spinDirection == 1) ? "Right" : "Left"));
SetTextSafely(val, "odds", stats.oddsMultiplier.ToString("0.00") + " : 1");
SetStatCubes(val, "stability", stats.stability);
SetStatCubes(val, "longevity", stats.longevity);
SetStatCubes(val, "attack", stats.attack);
SetStatCubes(val, "defense", stats.defense);
activeStatUIs.Add(val);
}
}
private void SetTextSafely(GameObject parentObject, string childName, string textValue)
{
Transform val = parentObject.transform.Find(childName);
if ((Object)(object)val == (Object)null)
{
Debug.LogError((object)("[Beyblade Mod] ERROR: Could not find child named exactly '" + childName + "' inside statsPrefab!"));
return;
}
TextMeshPro component = ((Component)val).GetComponent<TextMeshPro>();
if ((Object)(object)component != (Object)null)
{
((TMP_Text)component).text = textValue;
}
else
{
Debug.LogError((object)("[Beyblade Mod] ERROR: Found child '" + childName + "', but it has no TextMeshPro component attached!"));
}
}
private string GenerateRandomName()
{
string[] array = new string[45]
{
"Cosmic", "Shadow", "Blazing", "Crystal", "Iron", "Storm", "Fierce", "Void", "Silly", "Little",
"Huge", "Gross", "Slimy", "Slick", "Busty", "Lucky", "Killer", "Deadly", "Wet", "Tiny",
"Horny", "Mushy", "Steel", "Bulky", "Strong", "Pulsing", "Giant", "Wicked", "Manic", "Exotic",
"Evil", "Magic", "Tony", "John", "Erotic", "Freaky", "Hungry", "Passive", "Angry", "Touchy",
"Quick", "Mad", "Dumb", "Northern", "Burnt"
};
string[] array2 = new string[47]
{
"Dragon", "Pegasus", "Wolf", "Tiger", "Valkyrie", "Serpent", "Phoenix", "Titan", "Royal", "Coyote",
"Hound", "Minion", "Devil", "Spinner", "Sprinter", "Bouncer", "Death", "Smurf", "Ludwig", "Stool",
"Steve", "John", "Crusher", "Top", "Bottom", "Wizard", "Lizard", "Johnson", "Emu", "Hawk",
"Bob", "Hitman", "Sonic", "MILF", "Moon", "Earth", "Plant", "Planet", "Sun", "Bug",
"Virus", "Log", "Predator", "Lion", "Dog", "Chiblee", "Peanut"
};
return array[Random.Range(0, array.Length)] + " " + array2[Random.Range(0, array2.Length)];
}
private void SetStatCubes(GameObject parentObject, string statName, int statValue)
{
//IL_007a: 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_007f: 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)
Transform val = parentObject.transform.Find(statName + "/Bar");
if ((Object)(object)val == (Object)null)
{
Debug.LogError((object)("[Beyblade Mod] ERROR: Could not find '" + statName + "/Bar' in statsPrefab!"));
return;
}
int num = Mathf.Clamp(Mathf.CeilToInt((float)statValue / 2f), 1, 5);
for (int i = 0; i < 5; i++)
{
if (i < val.childCount)
{
Transform child = val.GetChild(i);
Color color = ((i < num) ? Color.green : Color.white);
MeshRenderer component = ((Component)child).GetComponent<MeshRenderer>();
if ((Object)(object)component != (Object)null)
{
((Renderer)component).material.color = color;
}
}
}
}
public void SetBet1()
{
BroadCaseSetBet("0");
}
public void SetBet2()
{
BroadCaseSetBet("1");
}
public void SetBet3()
{
BroadCaseSetBet("2");
}
public void SetBet4()
{
BroadCaseSetBet("3");
}
public void BroadCaseSetBet(string text)
{
if (NetworkServer.active)
{
string text2 = "System.Void MoreGamesBase.BeybladeBattle::UserRpcSetBet(System.String)";
int stableHashCode = Extensions.GetStableHashCode(text2);
NetworkWriterPooled val = NetworkWriterPool.Get();
NetworkWriterExtensions.WriteString((NetworkWriter)(object)val, text);
((NetworkBehaviour)this).SendRPCInternal(text2, stableHashCode, (NetworkWriter)(object)val, 0, true);
NetworkWriterPool.Return(val);
}
}
public void UserRpcSetBet(string beybladeIndex)
{
int num = int.Parse(beybladeIndex);
if (currentState == GameState.Betting)
{
currentBetNum = num;
UpdateButtonVisuals();
}
}
private void UpdateButtonVisuals()
{
//IL_0057: Unknown result type (might be due to invalid IL or missing references)
//IL_005c: 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_0072: Unknown result type (might be due to invalid IL or missing references)
//IL_0092: Unknown result type (might be due to invalid IL or missing references)
List<GameObject> list = new List<GameObject> { buttonSelected1, buttonSelected2, buttonSelected3, buttonSelected4 };
for (int i = 0; i < list.Count; i++)
{
GameObject val = list[i];
if (!((Object)(object)val == (Object)null))
{
Color color = Color.black;
if (i == currentBetNum)
{
color = Color.white;
}
MeshRenderer component = val.GetComponent<MeshRenderer>();
if ((Object)(object)component != (Object)null)
{
((Renderer)component).material.color = color;
}
}
}
}
protected override void StartGame()
{
if (!NetworkServer.active)
{
return;
}
foreach (GameObject activeStatUI in activeStatUIs)
{
Object.Destroy((Object)(object)activeStatUI);
}
activeStatUIs.Clear();
currentState = GameState.Fighting;
deathTimers.Clear();
fightTimer = 0f;
for (int i = 0; i < spawnLocations.Count; i++)
{
AddBeyblade(spawnLocations[i], beybladeStats[i]);
}
}
private void AddBeyblade(Transform spawnLocation, Stats stats)
{
//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_008b: Unknown result type (might be due to invalid IL or missing references)
//IL_003b: Unknown result type (might be due to invalid IL or missing references)
//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
//IL_012c: Unknown result type (might be due to invalid IL or missing references)
//IL_0133: Expected O, but got Unknown
//IL_0196: Unknown result type (might be due to invalid IL or missing references)
//IL_019d: Expected O, but got Unknown
GameObject val = Object.Instantiate<GameObject>(beybladeBasePrefab, spawnLocation.position, Quaternion.identity);
val.SetActive(true);
MeshRenderer componentInChildren = val.GetComponentInChildren<MeshRenderer>();
if ((Object)(object)componentInChildren != (Object)null)
{
((Renderer)componentInChildren).material.color = stats.color;
}
((Object)val).name = stats.originalIndex.ToString();
Rigidbody component = val.GetComponent<Rigidbody>();
component.centerOfMass = new Vector3(0.003f - 0.00015f * (float)stats.stability, -0.05f, 0.003f - 0.00015f * (float)stats.stability);
component.useGravity = true;
float num = 150f + 10f * (float)stats.attack;
float num2 = ((stats.spinDirection == 1) ? 1f : (-1f));
component.AddTorque(new Vector3(0f, num * num2, 0f), (ForceMode)1);
component.mass = 20f + 1f * (float)stats.defense;
component.maxAngularVelocity = 500f;
component.angularDamping = 0.15f - 0.001f * (float)stats.longevity;
SphereCollider componentInChildren2 = val.GetComponentInChildren<SphereCollider>();
PhysicsMaterial val2 = new PhysicsMaterial();
val2.dynamicFriction = 0.9f - 0.04f * (float)stats.longevity;
val2.staticFriction = 0.9f - 0.04f * (float)stats.longevity;
val2.bounciness = 0f + 0.01f * (float)stats.attack;
((Collider)componentInChildren2).material = val2;
MeshCollider componentInChildren3 = val.GetComponentInChildren<MeshCollider>();
PhysicsMaterial val3 = new PhysicsMaterial();
val3.bounciness = 0.7f - 0.04f * (float)stats.defense;
((Collider)componentInChildren3).material = val3;
val.AddComponent<BeybladeDeflector>();
activeBeyblades.Add(val);
NetworkServer.Spawn(val, (NetworkConnectionToClient)null);
}
private void RemoveBeyblade(GameObject beyblade)
{
activeBeyblades.Remove(beyblade);
deathTimers.Remove(beyblade);
if ((Object)(object)beyblade != (Object)null)
{
NetworkServer.Destroy(beyblade);
}
}
private void Update()
{
//IL_0194: Unknown result type (might be due to invalid IL or missing references)
//IL_01a5: 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_01ef: Unknown result type (might be due to invalid IL or missing references)
//IL_01f4: 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_01dd: Unknown result type (might be due to invalid IL or missing references)
if (!NetworkServer.active)
{
return;
}
if (currentState == GameState.Finished)
{
resetTimer -= Time.deltaTime;
if (!(resetTimer <= 0f))
{
return;
}
foreach (GameObject item in activeBeyblades.ToList())
{
RemoveBeyblade(item);
}
activeBeyblades.Clear();
((GameBase)this).ResetGame();
InitBettingPhase();
}
else
{
if (currentState != GameState.Fighting)
{
return;
}
fightTimer += Time.deltaTime;
if (activeBeyblades.Count == 0)
{
currentState = GameState.Finished;
resetTimer = 3f;
if ((Object)(object)winText != (Object)null)
{
winText.SetActive(true);
((TMP_Text)winText.GetComponent<TextMeshPro>()).text = "Draw!";
}
((GameBase)this).Payout(1.0, (ChangeType)1, (Dictionary<string, object>)null, -1L);
}
if (activeBeyblades.Count == 1)
{
HandleWin(activeBeyblades[0]);
return;
}
Vector2 val2 = default(Vector2);
for (int i = 0; i < activeBeyblades.Count; i++)
{
GameObject val = activeBeyblades[i];
((Vector2)(ref val2))..ctor(val.transform.position.x, val.transform.position.z);
if ((Mathf.Abs(val.GetComponent<Rigidbody>().angularVelocity.y) < 1f && Vector3.Angle(val.transform.up, Vector3.up) > 15f) || Vector2.Distance(arenaCenter, val2) > 3f)
{
if (!deathTimers.ContainsKey(val))
{
deathTimers[val] = 0f;
}
deathTimers[val] += Time.deltaTime;
if (deathTimers[val] >= 0.5f)
{
RemoveBeyblade(val);
i--;
}
}
else if (deathTimers.ContainsKey(val))
{
deathTimers.Remove(val);
}
}
}
}
private void HandleWin(GameObject winnerObj)
{
//IL_0066: Unknown result type (might be due to invalid IL or missing references)
currentState = GameState.Finished;
resetTimer = 3f;
int num = int.Parse(((Object)winnerObj).name);
Stats stats = beybladeStats[num];
if ((Object)(object)winText != (Object)null)
{
winText.SetActive(true);
((TMP_Text)winText.GetComponent<TextMeshPro>()).text = "Winner:\n<color=#" + ColorUtility.ToHtmlStringRGB(stats.color) + ">" + stats.name + "</color>";
}
if (currentBetNum == num)
{
((GameBase)this).Payout((double)stats.oddsMultiplier, (ChangeType)1, (Dictionary<string, object>)null, -1L);
}
}
}
public class BeybladeDeflector : MonoBehaviour
{
private void Start()
{
SphereCollider val = ((Component)this).gameObject.AddComponent<SphereCollider>();
((Collider)val).isTrigger = true;
val.radius = 0.5f;
}
private void OnTriggerEnter(Collider other)
{
//IL_0070: 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_0080: Unknown result type (might be due to invalid IL or missing references)
//IL_0085: Unknown result type (might be due to invalid IL or missing references)
//IL_0089: Unknown result type (might be due to invalid IL or missing references)
//IL_008e: Unknown result type (might be due to invalid IL or missing references)
//IL_009d: Unknown result type (might be due to invalid IL or missing references)
//IL_00ab: 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)
//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
if (!((Object)(object)((Component)other).GetComponentInParent<ConsumableItem>() != (Object)null))
{
return;
}
Collider[] componentsInChildren = ((Component)this).GetComponentsInChildren<Collider>();
Collider[] array = componentsInChildren;
foreach (Collider val in array)
{
if (!val.isTrigger)
{
Physics.IgnoreCollision(other, val, true);
}
}
Rigidbody attachedRigidbody = other.attachedRigidbody;
if ((Object)(object)attachedRigidbody != (Object)null)
{
Vector3 val2 = ((Component)other).transform.position - ((Component)this).transform.position;
Vector3 normalized = ((Vector3)(ref val2)).normalized;
normalized.y = 1.25f;
attachedRigidbody.linearVelocity = Vector3.zero;
attachedRigidbody.AddForce(((Vector3)(ref normalized)).normalized * 8f, (ForceMode)1);
attachedRigidbody.AddTorque(Random.insideUnitSphere * 10f, (ForceMode)1);
}
}
}
}