|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147 |
- using System;
- using System.Reflection;
- using GameServer;
- using HarmonyLib;
- using Svelto.Context;
-
- namespace CLre_server.API.MainServer
- {
- public class Server
- {
- // static
-
- private static Server _instance = null;
-
- public static Server Instance
- {
- get
- {
- if (_instance == null) _instance = new Server();
- return _instance;
- }
- }
-
- // instance events
- public event EventHandler<StartingEventArgs> InitStart
- {
- add => MainGameServer_Constructor_Patch.preConstructor += value;
- remove => MainGameServer_Constructor_Patch.preConstructor -= value;
- }
-
- public event EventHandler<StartedEventArgs> InitComplete
- {
- add => ServerReadyEngine.serverEngineReady += value;
- remove => ServerReadyEngine.serverEngineReady -= value;
- }
-
- public event EventHandler<StartedEventArgs> FrameworkReady
- {
- add => ServerReadyEngine.serverFrameworkReady += value;
- remove => ServerReadyEngine.serverFrameworkReady -= value;
- }
-
- public event EventHandler<StopEventArgs> FrameworkExit
- {
- add => ServerReadyEngine.serverFrameworkDestroyed += value;
- remove => ServerReadyEngine.serverFrameworkDestroyed -= value;
- }
-
- // properties
-
- public GameServerSettings GameServerSettings
- {
- get => MainGameServer_SetupMods_Patch._gameServerSettings;
-
- set
- {
- MainGameServer_SetupMods_Patch._gameServerSettings = value;
- Traverse.Create(MainGameServer_Constructor_Patch.mgs).Field<GameServerSettings>("_gameServerSettings").Value = value;
- }
- }
-
- private Server()
- {
- new ServerReadyEngine();
- }
- }
-
- [HarmonyPatch]
- class MainGameServer_SetupMods_Patch
- {
- internal static GameServerSettings _gameServerSettings;
-
- [HarmonyPostfix]
- public static void AfterMethodCall(GameServerSettings ____gameServerSettings)
- {
- _gameServerSettings = ____gameServerSettings;
- }
-
- [HarmonyTargetMethod]
- public static MethodBase Target()
- {
- return AccessTools.Method("GameServer.GameFramework.MainGameServer:SetupMods");
- }
- }
-
- [HarmonyPatch]
- class MainGameServer_Constructor_Patch
- {
-
- internal static ICompositionRoot mgs = null;
-
- internal static event EventHandler<StartingEventArgs> preConstructor;
-
- internal static event EventHandler<StartingEventArgs> postConstructor;
-
- [HarmonyPrefix]
- public static void BeforeMethodCall()
- {
- if (preConstructor != null) preConstructor(null, default(StartingEventArgs));
- }
-
- [HarmonyPostfix]
- public static void AfterMethodCall(ICompositionRoot __instance)
- {
- mgs = __instance;
- if (postConstructor != null) postConstructor(__instance, default(StartingEventArgs));
- }
-
- [HarmonyTargetMethod]
- public static MethodBase Target()
- {
- return AccessTools.Constructor(AccessTools.TypeByName("GameServer.GameFramework.MainGameServer"));
- }
- }
-
- [HarmonyPatch(typeof(PhotonNetwork), "ConnectUsingSettings")]
- class PhotonNetwork_ConnectUsingSettings_Patch
- {
- internal static event EventHandler<StartedEventArgs> preConnect;
-
- internal static event EventHandler<StartedEventArgs> postConnect;
-
- [HarmonyPostfix]
- public static void AfterMethodCall(string gameVersion)
- {
- if (postConnect != null) postConnect(null, new StartedEventArgs
- {
- photonVersion = gameVersion,
- photonRegion = PhotonNetwork.CloudRegion,
- worldName = MainGameServer_SetupMods_Patch._gameServerSettings.GetWorldName(),
- gameGuid = MainGameServer_SetupMods_Patch._gameServerSettings.GetGameGuid(),
- });
- }
-
- [HarmonyPrefix]
- public static void BeforeMethodCall(string gameVersion)
- {
- if (preConnect != null) preConnect(null, new StartedEventArgs
- {
- photonVersion = gameVersion,
- photonRegion = PhotonNetwork.CloudRegion,
- worldName = MainGameServer_SetupMods_Patch._gameServerSettings.GetWorldName(),
- gameGuid = MainGameServer_SetupMods_Patch._gameServerSettings.GetGameGuid(),
- });
- }
- }
- }
|