2023-05-29 22:23:11 +02:00
|
|
|
|
#if SRML
|
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
using SRML;
|
|
|
|
|
using SRML.SR;
|
|
|
|
|
using SRMultiplayer.Networking;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Reflection;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
namespace SRMultiplayer
|
|
|
|
|
{
|
2023-07-01 21:57:32 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Handles mod being loaded from SRML
|
|
|
|
|
/// Takes the place of the Main Standalone file, but caters to the SRML
|
|
|
|
|
/// </summary>
|
2023-05-29 22:23:11 +02:00
|
|
|
|
public class MainSRML : ModEntryPoint
|
|
|
|
|
{
|
|
|
|
|
private static GameObject m_GameObject;
|
|
|
|
|
|
|
|
|
|
// Called before GameContext.Awake
|
|
|
|
|
// this is where you want to register stuff (like custom enum values or identifiable id's)
|
|
|
|
|
// and patch anything you want to patch with harmony
|
|
|
|
|
public override void PreLoad()
|
|
|
|
|
{
|
|
|
|
|
base.PreLoad();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Called right before PostLoad
|
|
|
|
|
// Used to register stuff that needs lookupdirector access
|
|
|
|
|
public override void Load()
|
|
|
|
|
{
|
|
|
|
|
if (m_GameObject != null) return;
|
|
|
|
|
|
|
|
|
|
SRMP.Log("Loading SRMP SRML Version");
|
|
|
|
|
|
2023-07-01 21:57:32 +02:00
|
|
|
|
//create the mod directory in the install folder if needed
|
2023-05-29 22:23:11 +02:00
|
|
|
|
if (!Directory.Exists(SRMP.ModDataPath))
|
|
|
|
|
{
|
|
|
|
|
Directory.CreateDirectory(SRMP.ModDataPath);
|
|
|
|
|
}
|
2023-07-01 21:57:32 +02:00
|
|
|
|
//create the user data file if not created yet
|
2023-05-29 22:23:11 +02:00
|
|
|
|
if (!File.Exists(Path.Combine(SRMP.ModDataPath, "userdata.json")))
|
|
|
|
|
{
|
|
|
|
|
Globals.UserData = new UserData()
|
|
|
|
|
{
|
|
|
|
|
UUID = System.Guid.NewGuid(),
|
|
|
|
|
CheckDLC = true,
|
|
|
|
|
IgnoredMods = new System.Collections.Generic.List<string>()
|
|
|
|
|
};
|
|
|
|
|
File.WriteAllText(Path.Combine(SRMP.ModDataPath, "userdata.json"), JsonConvert.SerializeObject(Globals.UserData));
|
|
|
|
|
SRMP.Log("Created userdata with UUID " + Globals.UserData.UUID);
|
|
|
|
|
}
|
2023-07-01 21:57:32 +02:00
|
|
|
|
else //if alreayd created load in the data
|
2023-05-29 22:23:11 +02:00
|
|
|
|
{
|
|
|
|
|
Globals.UserData = JsonConvert.DeserializeObject<UserData>(File.ReadAllText(Path.Combine(SRMP.ModDataPath, "userdata.json")));
|
|
|
|
|
if(Globals.UserData.IgnoredMods == null)
|
|
|
|
|
{
|
|
|
|
|
Globals.UserData.IgnoredMods = new System.Collections.Generic.List<string>();
|
|
|
|
|
}
|
|
|
|
|
SRMP.Log("Loaded userdata with UUID " + Globals.UserData.UUID);
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-01 21:57:32 +02:00
|
|
|
|
//create the mods main game objects and start connecting everything
|
2023-05-29 22:23:11 +02:00
|
|
|
|
string[] args = System.Environment.GetCommandLineArgs();
|
|
|
|
|
|
|
|
|
|
m_GameObject = new GameObject("SRMP");
|
|
|
|
|
m_GameObject.AddComponent<SRMP>();
|
|
|
|
|
m_GameObject.AddComponent<NetworkMasterServer>();
|
|
|
|
|
m_GameObject.AddComponent<NetworkClient>();
|
|
|
|
|
m_GameObject.AddComponent<NetworkServer>();
|
|
|
|
|
m_GameObject.AddComponent<MultiplayerUI>();
|
|
|
|
|
m_GameObject.AddComponent<ChatUI>();
|
|
|
|
|
m_GameObject.AddComponent<SRMPConsole>();
|
|
|
|
|
|
2023-07-01 21:57:32 +02:00
|
|
|
|
//mark all mod objects and do not destroy
|
2023-05-29 22:23:11 +02:00
|
|
|
|
GameObject.DontDestroyOnLoad(m_GameObject);
|
|
|
|
|
|
2023-07-01 21:57:32 +02:00
|
|
|
|
//get current mod version
|
2023-05-29 22:23:11 +02:00
|
|
|
|
Globals.Version = Assembly.GetExecutingAssembly().GetName().Version.Revision;
|
|
|
|
|
|
2023-07-01 21:57:32 +02:00
|
|
|
|
//mark the mod as a background task
|
2023-05-29 22:23:11 +02:00
|
|
|
|
Application.runInBackground = true;
|
|
|
|
|
|
2023-07-01 21:57:32 +02:00
|
|
|
|
//initialize connect to the harmony patcher
|
2023-05-29 22:23:11 +02:00
|
|
|
|
HarmonyPatcher.GetInstance().PatchAll(Assembly.GetExecutingAssembly());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Called after GameContext.Start
|
|
|
|
|
// stuff like gamecontext.lookupdirector are available in this step, generally for when you want to access
|
|
|
|
|
// ingame prefabs and the such
|
|
|
|
|
public override void PostLoad()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif
|