示例#1
0
        private void InitGameIfNecessary()
        {
            ModEntry.Log("InitGameIfNecessary(" + isDeepWoodsGameRunning + ")", StardewModdingAPI.LogLevel.Trace);

            // Make sure our interceptor is set.
            // E.g. MTN overrides Game1.multiplayer instead of wrapping.
            Game1MultiplayerAccessProvider.InterceptMultiplayerIfNecessary();

            if (isDeepWoodsGameRunning)
            {
                return;
            }

            if (Game1.IsMasterGame)
            {
                DeepWoodsSettings.DoLoad();
                DeepWoodsManager.Add();
                EasterEggFunctions.RestoreAllEasterEggsInGame();
                WoodsObelisk.RestoreAllInGame();
                isDeepWoodsGameRunning = true;
            }
            else
            {
                DeepWoodsManager.Remove();
                hasRequestedInitMessageFromServer = true;
                Game1.MasterPlayer.queueMessage(Settings.Network.DeepWoodsMessageId, Game1.player, new object[] { NETWORK_MESSAGE_DEEPWOODS_INIT });
            }
        }
示例#2
0
        private void SaveEvents_BeforeSave(object sender, EventArgs args)
        {
            ModEntry.Log("SaveEvents_BeforeSave", StardewModdingAPI.LogLevel.Trace);

            isBeforeSaveCount++;
            if (isBeforeSaveCount > 1)
            {
                ModEntry.Log("BeforeSave event was called twice in a row. Ignoring second call.", StardewModdingAPI.LogLevel.Warn);
                return;
            }

            DeepWoodsManager.Remove();
            EasterEggFunctions.RemoveAllEasterEggsFromGame();
            WoodsObelisk.RemoveAllFromGame();
            DeepWoodsSettings.DoSave();

            foreach (var who in Game1.getAllFarmers())
            {
                if (who.currentLocation is DeepWoods)
                {
                    who.currentLocation = Game1.getLocationFromName("Woods");
                    who.Position        = new Vector2(WOODS_WARP_LOCATION.X * 64, WOODS_WARP_LOCATION.Y * 64);
                }
            }
        }
示例#3
0
 public override void Entry(IModHelper helper)
 {
     ModEntry.mod         = this;
     ModEntry.multiplayer = helper.Reflection.GetField <Multiplayer>(typeof(Game1), "multiplayer").GetValue();
     DeepWoodsSettings.Init(helper.Translation);
     Textures.LoadAll();
     RegisterEvents(helper.Events);
 }
        public static void DoLoad()
        {
            if (!Game1.IsMasterGame)
            {
                return;
            }

            ModEntry.Log("DeepWoodsSettings.DoLoad()", StardewModdingAPI.LogLevel.Trace);

            // load data
            DeepWoodsState = ModEntry.GetHelper().Data.ReadSaveData <DeepWoodsStateData>("data");
            if (DeepWoodsState == null)
            {
                // legacy file
                FileInfo legacyFile = new FileInfo($"{Constants.CurrentSavePath}/{SAVE_FILE_NAME}.json");
                ModEntry.Log("DeepWoodsSettings.DoLoad: Couldn't find savedata, trying legacy save: " + legacyFile.FullName, StardewModdingAPI.LogLevel.Trace);
                if (legacyFile.Exists)
                {
                    ModEntry.Log("DeepWoodsSettings.DoLoad: Loading legacy save.", StardewModdingAPI.LogLevel.Trace);
                    DeepWoodsState = JsonConvert.DeserializeObject <DeepWoodsStateData>(File.ReadAllText(legacyFile.FullName));
                }
            }
            if (DeepWoodsState == null)
            {
                ModEntry.Log("DeepWoodsSettings.DoLoad: No savedata, falling back to default.", StardewModdingAPI.LogLevel.Trace);
                DeepWoodsState = new DeepWoodsStateData();
            }

            // init settings
            ModEntry.Log("DeepWoodsSettings.DoLoad: Loading settings.", StardewModdingAPI.LogLevel.Trace);
            DeepWoodsSettings settings = ModEntry.GetHelper().ReadConfig <DeepWoodsSettings>();

            if (settings == null)
            {
                ModEntry.Log("Settings are null, using defaults.", StardewModdingAPI.LogLevel.Trace);
                Settings = new DeepWoodsSettings();
            }
            else
            {
                ModEntry.Log("Settings loaded successfully.", StardewModdingAPI.LogLevel.Trace);
                Settings = settings;

                if (Settings.WoodsPassage.AddBuildingTiles.Length == 0 &&
                    Settings.WoodsPassage.DeleteBuildingTiles.Length == 0 &&
                    Settings.WoodsPassage.WarpLocations.Length == 0)
                {
                    Settings.WoodsPassage = new WoodsPassageSettings();
                }
            }

            ModEntry.Log("DeepWoodsSettings.DoLoad: Done.", StardewModdingAPI.LogLevel.Trace);
        }
示例#5
0
 private void OnGameLaunched(object sender, GameLaunchedEventArgs args)
 {
     ModEntry.multiplayer = Helper.Reflection.GetField <Multiplayer>(typeof(Game1), "multiplayer").GetValue();
     DeepWoodsSettings.Init(Helper.Translation);
     DeepWoodsTextures.Textures.LoadAll();
     if (Helper.ModRegistry.IsLoaded("Omegasis.SaveAnywhere"))
     {
         ISaveAnywhereAPI api = Helper.ModRegistry.GetApi <ISaveAnywhereAPI>("Omegasis.SaveAnywhere");
         if (api != null)
         {
             api.BeforeSave += (s, e) => this.CleanupBeforeSave();
             api.AfterSave  += (s, e) => this.RestoreAfterSave();
             api.AfterLoad  += (s, e) => this.InitAfterLoad();
         }
     }
 }
示例#6
0
        private void InitGameIfNecessary()
        {
            ModEntry.Log("InitGameIfNecessary(" + isDeepWoodsGameRunning + ")", StardewModdingAPI.LogLevel.Trace);

            if (isDeepWoodsGameRunning)
            {
                return;
            }

            if (Game1.IsMasterGame)
            {
                DeepWoodsSettings.DoLoad();
                DeepWoodsManager.Add();
                EasterEggFunctions.RestoreAllEasterEggsInGame();
                WoodsObelisk.RestoreAllInGame();
                isDeepWoodsGameRunning = true;
            }
            else
            {
                DeepWoodsManager.Remove();
                ModEntry.SendMessage(MessageId.RequestMetadata, Game1.MasterPlayer.UniqueMultiplayerID);
            }
        }