Guest User

Client Plugin Script Template

a guest
Jul 18th, 2021
480
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.76 KB | None | 0 0
  1. using Intersect.Client.General;
  2. using Intersect.Client.Plugins;
  3. using Intersect.Client.Plugins.Interfaces;
  4. using Intersect.Plugins;
  5.  
  6. /// <summary>
  7. /// **Make sure to change this namespace to match yours!**
  8. /// </summary>
  9. namespace Client.Plugins
  10. {
  11.  
  12. /// <summary>
  13. /// Client plugin entry class template.
  14. /// Change the class name to match yours or just copy the contents.
  15. /// </summary>
  16. public class ClientPluginEntryTemplate : ClientPluginEntry
  17. {
  18.  
  19. /// <summary>
  20. /// Called during application bootstrap, before OnStart is called.
  21. /// <para></para>Useful for registering custom packets and handlers using context.Network,
  22. /// and initializing command line options using context.CommandLine.
  23. /// </summary>
  24. /// <param name="context"></param>The current plugin context for the client.
  25. public override void OnBootstrap(IPluginBootstrapContext context)
  26. {
  27. RegisterPackets(context);
  28. RegisterPacketHandlers(context);
  29. }
  30.  
  31. /// <summary>
  32. /// Registers custom packets.
  33. /// </summary>
  34. /// <param name="context"></param>
  35. private void RegisterPackets(IPluginBootstrapContext context)
  36. {
  37. // Example packet registration
  38. //if (!context.Packet.TryRegisterPacketType<YourServerPacket>())
  39. //{
  40. // context.Logging.Plugin.Error($"Failed to register {nameof(YourServerPacket)} packet.");
  41. // Environment.Exit(-3);
  42. //}
  43. }
  44.  
  45. /// <summary>
  46. /// Registers packet handlers for custom packets.
  47. /// </summary>
  48. /// <param name="context"></param>
  49. private void RegisterPacketHandlers(IPluginBootstrapContext context)
  50. {
  51. // Example packet handler registration
  52. //if (!context.Packet.TryRegisterPacketHandler<YourServerPacketHandler, YourServerPacket>(out _))
  53. //{
  54. // context.Logging.Plugin.Error($"Failed to register {nameof(YourServerPacketHandler)} packet handler.");
  55. // Environment.Exit(-4);
  56. //}
  57. }
  58.  
  59. /// <summary>
  60. /// Invoked on application start after bootstrapping and other basic initialization.
  61. /// <para></para>Useful for subscribing to lifecycle events using context.Lifecycle,
  62. /// and loading assets using context.ContentManager.
  63. /// </summary>
  64. /// <param name="context"></param>
  65. public override void OnStart(IClientPluginContext context)
  66. {
  67. // Subscribe to lifecycle event callbacks
  68. context.Lifecycle.LifecycleChangeState += Lifecycle_LifecycleChangeState;
  69. context.Lifecycle.GameUpdate += Lifecycle_GameUpdate;
  70. }
  71.  
  72. /// <summary>
  73. /// Invoked once when the client lifecycle changes state.
  74. /// </summary>
  75. /// <param name="context"></param>The client plugin context.
  76. /// <param name="lifecycleChangeStateArgs"></param>The args invoked when GameState changes. Includes the new GameState.
  77. private void Lifecycle_LifecycleChangeState(IClientPluginContext context,
  78. LifecycleChangeStateArgs lifecycleChangeStateArgs)
  79. {
  80. switch (lifecycleChangeStateArgs.State)
  81. {
  82. // Called when the intro images begin playing.
  83. case GameStates.Intro:
  84.  
  85. break;
  86.  
  87. // Called when the main menu is loaded.
  88. case GameStates.Menu:
  89.  
  90. break;
  91.  
  92. // Called when logging in and the main menu transitions to the game.
  93. case GameStates.Loading:
  94.  
  95. break;
  96.  
  97. // Called when the game is done loading.
  98. case GameStates.InGame:
  99.  
  100. break;
  101.  
  102. // Internal use.
  103. case GameStates.Error:
  104. break;
  105. default:
  106. break;
  107. }
  108. }
  109.  
  110. /// <summary>
  111. /// Invoked once per frame during the given GameState.
  112. /// Useful for things that require immediate updates such as capturing inputs.
  113. /// </summary>
  114. /// <param name="context"></param>
  115. /// <param name="gameUpdateArgs"></param>
  116. private void Lifecycle_GameUpdate(IClientPluginContext context,
  117. GameUpdateArgs gameUpdateArgs)
  118. {
  119. switch (gameUpdateArgs.State)
  120. {
  121. // Called when the intro images are playing.
  122. case GameStates.Intro:
  123.  
  124. break;
  125.  
  126. // Called while in the main menu.
  127. case GameStates.Menu:
  128.  
  129. break;
  130.  
  131. // Called while logging in, while the main menu transitions to the game.
  132. case GameStates.Loading:
  133.  
  134. break;
  135.  
  136. // Called while in game.
  137. case GameStates.InGame:
  138.  
  139. break;
  140.  
  141. // Internal use.
  142. case GameStates.Error:
  143. break;
  144. default:
  145. break;
  146. }
  147. }
  148.  
  149. /// <summary>
  150. /// Invoked when the application is shutting down.
  151. /// <para></para>
  152. /// Useful for cleaning up and saving data.
  153. /// </summary>
  154. /// <param name="context"></param>
  155. public override void OnStop(IClientPluginContext context)
  156. {
  157. // Unsubscribe from event callbacks when app stops.
  158. context.Lifecycle.LifecycleChangeState -= Lifecycle_LifecycleChangeState;
  159. context.Lifecycle.GameUpdate -= Lifecycle_GameUpdate;
  160. }
  161.  
  162. }
  163.  
  164. }
  165.  
Advertisement
Add Comment
Please, Sign In to add comment