/*********
        ** Public methods
        *********/

        /// <summary>The mod entry point, called after the mod is first loaded.</summary>
        /// <param name="helper">Provides simplified APIs for writing mods.</param>
        public override void Entry(IModHelper helper)
        {
            // Read config.
            this.config = new ConfigManager(this.Helper).GetConfig();

            // Create helper classes that make the mod work.
            ErrorQueue        errorQueue = new ErrorQueue(this.Monitor);
            ContentPackLoader packLoader = new ContentPackLoader(this.Helper, this.Monitor, errorQueue);

            this.serializer          = new DoorPositionSerializer(this.Helper.Data);
            this.timer               = new CallbackTimer();
            this.doorTileInfoManager = new GeneratedDoorTileInfoManager();
            this.generator           = new DoorSpriteGenerator(this.doorTileInfoManager, packLoader.LoadContentPacks(), this.Helper.Multiplayer.ModID, this.Monitor, Game1.graphics.GraphicsDevice);
            this.creator             = new DoorCreator(this.doorTileInfoManager, this.timer, errorQueue, this.Helper.ModRegistry.Get(this.Helper.ModRegistry.ModID).Manifest.Version);
            this.assetLoader         = new DoorAssetLoader(this.Helper.Content);
            this.mapTileSheetManager = new MapTileSheetManager();
            this.manager             = new DoorManager(this.config, this.OnDoorToggled);

            // Apply Harmony patches.
            BetterDoorsMod.Instance = this;
            HarmonyInstance harmony = HarmonyInstance.Create(this.Helper.ModRegistry.ModID);

            harmony.PatchAll(Assembly.GetExecutingAssembly());

            // Attach events.
            this.Enable();
            this.Helper.Events.Multiplayer.PeerContextReceived += this.Multiplayer_PeerContextReceived;
            this.Helper.Events.GameLoop.ReturnedToTitle        += this.GameLoop_ReturnedToTitle;
        }
 /// <summary>Raised after the player loads a save slot and the world is initialised.</summary>
 /// <param name="sender">The event sender.</param>
 /// <param name="e">The event arguments.</param>
 private void GameLoop_SaveLoaded(object sender, SaveLoadedEventArgs e)
 {
     if (Context.IsMainPlayer)
     {
         // Load initial door states and prepare every location for the host.
         IDictionary <string, IDictionary <Point, State> > saveData = this.serializer.Load();
         foreach (GameLocation location in BetterDoorsMod.GetAllLocations())
         {
             if (this.PrepareLocation(location))
             {
                 this.manager.SetDoorStates(Utils.GetLocationName(location), saveData.TryGetValue(Utils.GetLocationName(location), out IDictionary <Point, State> doorStates) ? doorStates : null);
             }
         }
     }
     else
     {
         // Only prepare the current location for farmhands. Also request initial door states.
         this.PrepareLocation(Game1.currentLocation);
         this.Helper.Multiplayer.SendMessage(new DoorStateRequest(Utils.GetLocationName(Game1.currentLocation)), nameof(DoorStateRequest), new[] { this.Helper.Multiplayer.ModID });
     }
 }