Example #1
0
        /// <summary>Get the locale codes (like <c>ja-JP</c>) used in asset keys.</summary>
        /// <param name="reflection">Simplifies access to private game code.</param>
        private IDictionary <string, LanguageCode> GetKeyLocales(Reflector reflection)
        {
            // get the private code field directly to avoid changed-code logic
            IPrivateField <LanguageCode> codeField = reflection.GetPrivateField <LanguageCode>(typeof(LocalizedContentManager), "_currentLangCode");

            // remember previous settings
            LanguageCode previousCode     = codeField.GetValue();
            string       previousOverride = this.LanguageCodeOverride;

            // create locale => code map
            IDictionary <string, LanguageCode> map = new Dictionary <string, LanguageCode>(StringComparer.InvariantCultureIgnoreCase);

            this.LanguageCodeOverride = null;
            foreach (LanguageCode code in Enum.GetValues(typeof(LanguageCode)))
            {
                codeField.SetValue(code);
                map[this.GetKeyLocale.Invoke <string>()] = code;
            }

            // restore previous settings
            codeField.SetValue(previousCode);
            this.LanguageCodeOverride = previousOverride;

            return(map);
        }
Example #2
0
        /// <summary>Temporarily dismount and set up the player to interact with a tile, then return it to the previous state afterwards.</summary>
        /// <param name="action">The action to perform.</param>
        private void TemporarilyFakeInteraction(Action action)
        {
            // get references
            SFarmer player = Game1.player;
            IPrivateField <Horse> mountField = this.Reflection.GetPrivateField <Horse>(Game1.player, "mount");

            // save current state
            Horse       mount            = mountField.GetValue();
            Vector2     mountPosition    = this.Current.position;
            WateringCan wateringCan      = player.CurrentTool as WateringCan;
            int         waterInCan       = wateringCan?.WaterLeft ?? 0;
            float       stamina          = player.stamina;
            Vector2     position         = player.position;
            int         facingDirection  = player.facingDirection;
            int         currentToolIndex = player.CurrentToolIndex;
            bool        canMove          = Game1.player.canMove; // fix player frozen due to animations when performing an action

            // move mount out of the way
            mountField.SetValue(null);
            this.Current.position = new Vector2(-5, -5);

            // perform action
            try
            {
                action();
            }
            finally
            {
                // move mount back
                this.Current.position = mountPosition;
                mountField.SetValue(mount);

                // restore previous state
                if (wateringCan != null)
                {
                    wateringCan.WaterLeft = waterInCan;
                }
                player.stamina          = stamina;
                player.position         = position;
                player.facingDirection  = facingDirection;
                player.CurrentToolIndex = currentToolIndex;
                Game1.player.canMove    = canMove;
            }
        }
        private void GameEvents_UpdateTick(object sender, EventArgs e)
        {
            if (Game1.activeClickableMenu is CarpenterMenu carpenter)
            {
                if (carpenter.CurrentBlueprint.name == "Aquaponics")
                {
                    IPrivateField <Building> cBuilding = Helper.Reflection.GetPrivateField <Building>(carpenter, "currentBuilding");

                    if (!(cBuilding.GetValue() is Aquaponics))
                    {
                        cBuilding.SetValue(new Aquaponics(Vector2.Zero, Game1.getFarm()));
                    }
                }
            }
        }
Example #4
0
        private void OnPreRenderGuiEvent(object sender, EventArgs e)
        {
            if (Game1.activeClickableMenu is Billboard)
            {
                Billboard menu          = (Billboard)Game1.activeClickableMenu;
                FieldInfo calendarField = menu.GetType().GetField("calendarDays", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
                if (calendarField == null)
                {
                    this.Monitor.Log("Could not find field 'calendarDays' in Billboard!", LogLevel.Error);
                    return;
                }
                List <ClickableTextureComponent> calendarDays = (List <ClickableTextureComponent>)calendarField.GetValue(menu);
                IPrivateField <string>           hoverField   = this.Helper.Reflection.GetPrivateField <string>(menu, "hoverText");
                string hoverText = hoverField.GetValue();
                if (calendarDays != null && !(hoverText.Contains("Shrooms") || hoverText.Contains("shrooms")))
                {
                    for (int day = 1; day <= 28; day++)
                    {
                        ClickableTextureComponent component = calendarDays[day - 1];
                        if (component.bounds.Contains(Game1.getMouseX(), Game1.getMouseY()))
                        {
                            List <int> shrooms = this.GetShroomLayers(day - Game1.dayOfMonth);

                            if (hoverText.Length > 0)
                            {
                                hoverText += "\n";
                            }

                            if (shrooms.Count > 0)
                            {
                                hoverText += "Shrooms: " + string.Join(", ", shrooms);
                            }
                            else
                            {
                                hoverText += "No shrooms";
                            }

                            break;
                        }
                    }

                    hoverField.SetValue(hoverText);
                }
            }
        }
Example #5
0
        private void CurrentLocationChanged(object sender, EventArgsCurrentLocationChanged e)
        {
            GameLocation loc = e.NewLocation;

            if (!Game1.killScreen && Game1.farmEvent == null && loc.currentEvent == null)
            {
                foreach (ModEvent ev in this.Events)
                {
                    int?id = ev.getID();
                    if (id == null)
                    {
                        continue;
                    }
                    if (id < 0)
                    {
                        continue;
                    }
                    if (ev.Location == loc.name)
                    {
                        this.Monitor.Log(id.ToString(), LogLevel.Trace);
                        if (ev.Repeatable)
                        {
                            Game1.player.eventsSeen.Remove((int)id);
                        }
                        int eventID = -1;

                        try {
                            eventID = this.Helper.Reflection.GetPrivateMethod(loc, "checkEventPrecondition").Invoke <int>(ev.Condition);
                        } catch {
                            this.Monitor.Log("Failed to check condition for event " + id + "(at '" + loc.name + "')", LogLevel.Error);
                        }

                        if (eventID != -1)
                        {
                            loc.currentEvent = new Event(ev.Data, eventID);

                            if (Game1.player.getMount() != null)
                            {
                                loc.currentEvent.playerWasMounted = true;
                                Game1.player.getMount().dismount();
                            }
                            foreach (NPC character in loc.characters)
                            {
                                character.clearTextAboveHead();
                            }
                            Game1.eventUp        = true;
                            Game1.displayHUD     = false;
                            Game1.player.CanMove = false;
                            Game1.player.showNotCarrying();

                            IPrivateField <List <Critter> > crittersF = this.Helper.Reflection.GetPrivateField <List <Critter> >(loc, "critters");
                            List <Critter> critters = crittersF.GetValue();
                            if (critters == null)
                            {
                                return;
                            }
                            critters.Clear();
                            crittersF.SetValue(critters);
                            break;
                        }
                    }
                }
            }
        }