143 lines
4.0 KiB
C#
143 lines
4.0 KiB
C#
using BoneSync.Networking;
|
|
using BoneSync.Networking.LobbyManager;
|
|
using BoneSync.Networking.Transport;
|
|
using MelonLoader;
|
|
using HarmonyLib;
|
|
using UnityEngine;
|
|
using BoneSync.Player;
|
|
using BoneSync.Sync;
|
|
using Facepunch.Steamworks;
|
|
using System.Reflection.Emit;
|
|
using BoneSync.Data;
|
|
using BoneSync.Networking.Messages;
|
|
|
|
namespace BoneSync
|
|
{
|
|
public static class BuildInfo
|
|
{
|
|
public const string Name = "BoneSync"; // Name of the Mod. (MUST BE SET)
|
|
public const string Author = "aarov"; // Author of the Mod. (Set as null if none)
|
|
public const string Company = null; // Company that made the Mod. (Set as null if none)
|
|
public const string Version = "0.0.1"; // Version of the Mod. (MUST BE SET)
|
|
public const string DownloadLink = null; // Download Link for the Mod. (Set as null if none)
|
|
}
|
|
|
|
public class BoneSync : MelonMod
|
|
{
|
|
public static bool IsConnected
|
|
{
|
|
get; private set;
|
|
}
|
|
|
|
|
|
public static LobbyManager lobby;
|
|
public static TransportBase transport;
|
|
public override void OnApplicationStart()
|
|
{
|
|
SteamClient.Init(823500, true);
|
|
|
|
SteamLobbyManager steamLobbyManager = new SteamLobbyManager();
|
|
|
|
lobby = steamLobbyManager;
|
|
transport = new SteamTransport();
|
|
|
|
SceneSync.Initialize();
|
|
NetworkMessage.RegisterPacketTypes();
|
|
|
|
SpawnableManager.Initialize();
|
|
|
|
PlayerRig.LoadBundle();
|
|
|
|
PatchAll();
|
|
}
|
|
|
|
public static void PatchAll()
|
|
{
|
|
//HarmonyLib.Harmony harmony = new HarmonyLib.Harmony("com.aarov.bonesync");
|
|
//harmony.i
|
|
}
|
|
|
|
public override void OnSceneWasLoaded(int buildIndex, string sceneName)
|
|
{
|
|
//SyncLogger.Msg("OnLevelWasLoaded: " + sceneName);
|
|
}
|
|
|
|
public override void OnSceneWasInitialized(int buildIndex, string sceneName)
|
|
{
|
|
//SyncLogger.Msg("OnLevelWasInitialized: " + sceneName);
|
|
SceneSync.OnSceneInit(buildIndex);
|
|
PlayerScripts.GetPlayerScripts();
|
|
}
|
|
|
|
public override void OnSceneWasUnloaded(int buildIndex, string sceneName)
|
|
{
|
|
//SyncLogger.Msg("OnLevelWasLoaded: " + sceneName);
|
|
}
|
|
|
|
public override void OnUpdate()
|
|
{
|
|
PlayerRig.LocalSyncTick();
|
|
transport.Tick();
|
|
|
|
//SyncDebugUI.UpdateUI();
|
|
|
|
//PlayerRig.Tick();
|
|
|
|
if (Input.GetKeyDown(KeyCode.P))
|
|
{
|
|
SyncLogger.Msg("P key pressed");
|
|
//PlayerRig playerRig = PlayerRig.InstantiatePlayerRigPrefab();
|
|
}
|
|
if (Input.GetKeyDown(KeyCode.I))
|
|
{
|
|
lobby.CreateLobby();
|
|
}
|
|
|
|
if (Input.GetKeyDown(KeyCode.N))
|
|
{
|
|
SyncLogger.Msg("Creating debug player rig");
|
|
PlayerRig debugRig = PlayerRig.GetPlayerRig(0);
|
|
PlayerSyncInfo? playerSyncInfo = PlayerRig.GetLocalSyncInfo();
|
|
if (!playerSyncInfo.HasValue)
|
|
{
|
|
SyncLogger.Msg("PlayerSyncInfo is null");
|
|
}
|
|
debugRig.UpdatePlayerSync(playerSyncInfo.Value);
|
|
}
|
|
}
|
|
|
|
public override void BONEWORKS_OnLoadingScreen()
|
|
{
|
|
base.BONEWORKS_OnLoadingScreen();
|
|
}
|
|
|
|
public override void OnFixedUpdate()
|
|
{
|
|
IsConnected = lobby.IsConnected();
|
|
transport.Tick();
|
|
Packet.TryCatchup();
|
|
PlayerRig.Tick();
|
|
}
|
|
|
|
public override void OnLateUpdate()
|
|
{
|
|
//SyncLogger.Msg("OnLateUpdate");
|
|
}
|
|
|
|
public override void OnGUI()
|
|
{
|
|
//SyncLogger.Msg("OnGUI");
|
|
}
|
|
|
|
public override void OnApplicationQuit()
|
|
{
|
|
//SyncLogger.Msg("OnApplicationQuit");
|
|
}
|
|
|
|
public override void OnPreferencesLoaded()
|
|
{
|
|
//SyncLogger.Msg("OnPreferencesLoaded");
|
|
}
|
|
}
|
|
}
|