public CachedMessageEmojis(IModHelper helper, int numberVanillaEmojis) { Reflection = helper.Reflection; messagesField = Reflection.GetField <List <ChatMessage> >(Game1.chatBox, "messages"); cheatHistoryPositionField = Reflection.GetField <int>(Game1.chatBox, "cheatHistoryPosition"); choosingEmojiField = Reflection.GetField <bool>(Game1.chatBox, "choosingEmoji"); emojiMenuIconField = Reflection.GetField <ClickableTextureComponent>(Game1.chatBox, "emojiMenuIcon"); formatMessageMethod = Reflection.GetMethod(Game1.chatBox, "formatMessage"); messageColorMethod = Reflection.GetMethod(Game1.chatBox, "messageColor"); PlayerMessageList = new List <PlayerMessage>(); NumberVanillaEmoji = numberVanillaEmojis; chatCommandsIsLoaded = helper.ModRegistry.IsLoaded("cat.chatcommands"); if (chatCommandsIsLoaded) { displayLineIndexField = Reflection.GetField <int>(Game1.chatBox, "displayLineIndex"); getEndDisplayIndexMethod = Reflection.GetMethod(Game1.chatBox, "GetEndDisplayIndex"); } SubscribeEvents(); }
public CommandEmojiMenu(IReflectionHelper reflection, ChatBox chatBox, Texture2D emojiTexture, Texture2D chatBoxTexture) : base(chatBox, emojiTexture, chatBoxTexture) { this.bUpArrow = reflection.GetField <ClickableComponent>(this, "upArrow").GetValue(); this.bDownArrow = reflection.GetField <ClickableComponent>(this, "downArrow").GetValue(); this.bSendArrow = reflection.GetField <ClickableComponent>(this, "sendArrow").GetValue(); this.bEmojiSelectionButtons = reflection.GetField <List <ClickableComponent> >(this, "emojiSelectionButtons").GetValue(); this.bPageStartIndex = reflection.GetField <int>(this, "pageStartIndex"); this.bUpArrowPressed = reflection.GetMethod(this, "upArrowPressed"); this.bDownArrowPressed = reflection.GetMethod(this, "downArrowPressed"); }
public void Shake(IReflectionHelper helper, Vector2 tile) { helper.GetMethod(grass, "shake").Invoke(3f * (float)Math.PI / 32f, (float)Math.PI / 80f, this.left); // works, but too loud // Game1.currentLocation.localSoundAt("grassyStep", tile); }
public void Shake(IReflectionHelper helper, Vector2 tile) { if (dirt.crop == null) { return; } helper.GetMethod(this.dirt, "shake").Invoke((float)(0.392699092626572 / 2), (float)(Math.PI / 80f), this.left); }
} = false; // Automate doesn't support storage containers /********* ** Public methods *********/ /// <summary>Construct an instance.</summary> /// <param name="furniture">The in-game storage furniture.</param> /// <param name="reflection">Simplifies access to private code.</param> public StorageFurnitureContainer(StorageFurniture furniture, IReflectionHelper reflection) { string defaultName = reflection.GetMethod(furniture, "getData").Invoke <string[]>()?[0]; this.Furniture = furniture; this.Data = ContainerData.FromModData(furniture.modData, defaultName); this.DefaultName = defaultName; StorageFurnitureContainer.DresserCategories ??= new HashSet <int>(new ShopMenu(new List <ISalable>(), context: "Dresser").categoriesToSellHere); }
public override void Activate() { Console.WriteLine($"Clicked bookmark: {ServerName} at {IP}"); CoopMenu menu = TitleMenu.subMenu as CoopMenu; //IP in format of 127.0.0.1:1234 var multiplayer = reflection.GetField <Multiplayer>(typeof(Game1), "multiplayer"); var setMenuMethod = reflection.GetMethod(menu, "setMenu", true); setMenuMethod.Invoke(new FarmhandMenu(multiplayer.GetValue().InitClient(new LidgrenClient(IP)))); }
public static void AutoSwing() { Farmer player = Game1.player; MeleeWeapon currentTool = player.CurrentTool as MeleeWeapon; if (currentTool == null) { ModLogger.Trace("Current tool is not a melee weapon."); return; } if (Config.CheckIfToolIsScythe && currentTool.isScythe()) { ModLogger.Trace("Current tool is a Scythe."); return; } Vector2 toolLocation = player.GetToolLocation(true); //int toolLocationX = (int)Math.Round(toolLocation.X); //int toolLocationY = (int)Math.Round(toolLocation.Y); ModLogger.Trace($"Swinging '{currentTool.BaseName}'."); // --- Swing mechanic // Works and respects the game Reflection.GetMethod(player, "performFireTool").Invoke(); // Works, but turns weapon invisible //currentTool.doSwipe(currentTool.type, toolLocation, player.facingDirection, currentTool.speed, player); // Works, but turns tool invisible and stops animation //currentTool.beginUsing(player.currentLocation, toolLocationX, toolLocationY, player); //currentTool.endUsing(player.currentLocation, player); // Doesn't do anything //Farmer.useTool(player); // Doesn't do anything //currentTool.DoFunction(player.currentLocation, toolLocationX, toolLocationY, 1, player); // Doesn't do anything //currentTool.leftClick(player); // Doesn't do anything //currentTool.tickUpdate(new GameTime(), player); }
public static IReflectedMethod GetMethodEx(this IReflectionHelper reflectionHelper, object obj, string name, bool require = true, IMonitor monitor = null) { try { return(reflectionHelper.GetMethod(obj, name, require)); } catch (Exception ex) { if (monitor != null) { monitor.Log($"Error while executing {nameof(GetMethodEx)} for {nameof(IReflectionHelper)}{Environment.NewLine}" + $"Method Name: {name}{Environment.NewLine}" + $"{ex.Message}", LogLevel.Error); } return(null); } }
private void LoadContent() { Game1.concessionsSpriteSheet = ((ContentManager)Game1.content).Load <Texture2D>("LooseSprites\\Concessions"); Game1.birdsSpriteSheet = ((ContentManager)Game1.content).Load <Texture2D>("LooseSprites\\birds"); Game1.daybg = ((ContentManager)Game1.content).Load <Texture2D>("LooseSprites\\daybg"); Game1.nightbg = ((ContentManager)Game1.content).Load <Texture2D>("LooseSprites\\nightbg"); Game1.menuTexture = ((ContentManager)Game1.content).Load <Texture2D>("Maps\\MenuTiles"); Game1.uncoloredMenuTexture = ((ContentManager)Game1.content).Load <Texture2D>("Maps\\MenuTilesUncolored"); Game1.lantern = ((ContentManager)Game1.content).Load <Texture2D>("LooseSprites\\Lighting\\lantern"); Game1.windowLight = ((ContentManager)Game1.content).Load <Texture2D>("LooseSprites\\Lighting\\windowLight"); Game1.sconceLight = ((ContentManager)Game1.content).Load <Texture2D>("LooseSprites\\Lighting\\sconceLight"); Game1.cauldronLight = ((ContentManager)Game1.content).Load <Texture2D>("LooseSprites\\Lighting\\greenLight"); Game1.indoorWindowLight = ((ContentManager)Game1.content).Load <Texture2D>("LooseSprites\\Lighting\\indoorWindowLight"); Game1.shadowTexture = ((ContentManager)Game1.content).Load <Texture2D>("LooseSprites\\shadow"); Game1.mouseCursors = ((ContentManager)Game1.content).Load <Texture2D>("LooseSprites\\Cursors"); Game1.mouseCursors2 = ((ContentManager)Game1.content).Load <Texture2D>("LooseSprites\\Cursors2"); Game1.giftboxTexture = ((ContentManager)Game1.content).Load <Texture2D>("LooseSprites\\Giftbox"); Game1.controllerMaps = ((ContentManager)Game1.content).Load <Texture2D>("LooseSprites\\ControllerMaps"); Game1.animations = ((ContentManager)Game1.content).Load <Texture2D>("TileSheets\\animations"); Reflection.GetField <Texture2D>(typeof(Game1), "mobileSpriteSheet", false)?.SetValue(((ContentManager)Game1.content).Load <Texture2D>("LooseSprites\\MobileAtlas_manually_made")); Game1.achievements = (Dictionary <int, string>)((ContentManager)Game1.content).Load <Dictionary <int, string> >("Data\\Achievements"); Game1.NPCGiftTastes = (IDictionary <string, string>)((ContentManager)Game1.content).Load <Dictionary <string, string> >("Data\\NPCGiftTastes"); Game1.onScreenMenus.Clear(); Reflection.GetMethod(Game1.game1, "TranslateFields").Invoke(); Game1.dayTimeMoneyBox = new DayTimeMoneyBox(); Reflection.GetField <Game1>(Game1.dayTimeMoneyBox, "game1", false)?.SetValue(Game1.game1); Game1.onScreenMenus.Add((IClickableMenu)Game1.dayTimeMoneyBox); IReflectedField <Toolbar> fieldToolBar = Helper.Reflection.GetField <Toolbar>(typeof(Game1), "toolbar", false); fieldToolBar?.SetValue(new Toolbar()); Type typeVirtualJoypad = AccessTools.TypeByName("StardewValley.Mobile.VirtualJoypad"); if (typeVirtualJoypad != null) { object virtualJoypad = AccessTools.CreateInstance(typeVirtualJoypad); Reflection.GetField <object>(typeof(Game1), "virtualJoypad", false)?.SetValue(virtualJoypad); } if (fieldToolBar != null) { Game1.onScreenMenus.Add(fieldToolBar.GetValue()); } Game1.buffsDisplay = new BuffsDisplay(); Game1.onScreenMenus.Add((IClickableMenu)Game1.buffsDisplay); Game1.dialogueFont = (SpriteFont)((ContentManager)Game1.content).Load <SpriteFont>("Fonts\\SpriteFont1"); Game1.smallFont = (SpriteFont)((ContentManager)Game1.content).Load <SpriteFont>("Fonts\\SmallFont"); Game1.tinyFont = (SpriteFont)((ContentManager)Game1.content).Load <SpriteFont>("Fonts\\tinyFont"); Game1.tinyFontBorder = (SpriteFont)((ContentManager)Game1.content).Load <SpriteFont>("Fonts\\tinyFontBorder"); Game1.objectSpriteSheet = ((ContentManager)Game1.content).Load <Texture2D>("Maps\\springobjects"); Game1.cropSpriteSheet = ((ContentManager)Game1.content).Load <Texture2D>("TileSheets\\crops"); Game1.emoteSpriteSheet = ((ContentManager)Game1.content).Load <Texture2D>("TileSheets\\emotes"); Game1.debrisSpriteSheet = ((ContentManager)Game1.content).Load <Texture2D>("TileSheets\\debris"); Game1.bigCraftableSpriteSheet = ((ContentManager)Game1.content).Load <Texture2D>("TileSheets\\Craftables"); Game1.rainTexture = ((ContentManager)Game1.content).Load <Texture2D>("TileSheets\\rain"); Game1.buffsIcons = ((ContentManager)Game1.content).Load <Texture2D>("TileSheets\\BuffsIcons"); Game1.objectInformation = (IDictionary <int, string>)((ContentManager)Game1.content).Load <Dictionary <int, string> >("Data\\ObjectInformation"); Game1.clothingInformation = (IDictionary <int, string>)((ContentManager)Game1.content).Load <Dictionary <int, string> >("Data\\ClothingInformation"); Game1.objectContextTags = (IDictionary <string, string>)((ContentManager)Game1.content).Load <Dictionary <string, string> >("Data\\ObjectContextTags"); Game1.bigCraftablesInformation = (IDictionary <int, string>)((ContentManager)Game1.content).Load <Dictionary <int, string> >("Data\\BigCraftablesInformation"); FarmerRenderer.hairStylesTexture = ((ContentManager)Game1.content).Load <Texture2D>("Characters\\Farmer\\hairstyles"); FarmerRenderer.shirtsTexture = ((ContentManager)Game1.content).Load <Texture2D>("Characters\\Farmer\\shirts"); FarmerRenderer.pantsTexture = ((ContentManager)Game1.content).Load <Texture2D>("Characters\\Farmer\\pants"); FarmerRenderer.hatsTexture = ((ContentManager)Game1.content).Load <Texture2D>("Characters\\Farmer\\hats"); FarmerRenderer.accessoriesTexture = ((ContentManager)Game1.content).Load <Texture2D>("Characters\\Farmer\\accessories"); Furniture.furnitureTexture = ((ContentManager)Game1.content).Load <Texture2D>("TileSheets\\furniture"); SpriteText.spriteTexture = ((ContentManager)Game1.content).Load <Texture2D>("LooseSprites\\font_bold"); SpriteText.coloredTexture = ((ContentManager)Game1.content).Load <Texture2D>("LooseSprites\\font_colored"); Tool.weaponsTexture = ((ContentManager)Game1.content).Load <Texture2D>("TileSheets\\weapons"); Projectile.projectileSheet = ((ContentManager)Game1.content).Load <Texture2D>("TileSheets\\Projectiles"); }
public RGBIntegration(ModEntry mod) : base(mod, "blueberry.RaisedGardenBeds", "1.0.2") { Helper = mod.Helper.Reflection; if (!IsLoaded) { return; } try { OutdoorPot = Type.GetType("RaisedGardenBeds.OutdoorPot, RaisedGardenBeds"); if (OutdoorPot == null) { throw new ArgumentNullException("cannot get OutdoorPot"); } Entry = Type.GetType("RaisedGardenBeds.ModEntry, RaisedGardenBeds"); if (Entry == null) { throw new ArgumentNullException("cannot get ModEntry"); } ItemDefinition = Type.GetType("RaisedGardenBeds.ItemDefinition, RaisedGardenBeds"); if (ItemDefinition == null) { throw new ArgumentNullException("cannot get ItemDefinition"); } // Sanity check _ItemDefinitions = Helper.GetField <IDictionary>(Entry, "ItemDefinitions", required: true); _Sprites = Helper.GetField <Dictionary <string, Texture2D> >(Entry, "Sprites", required: true); // Get Generic Name GenericName = Helper.GetField <string>(OutdoorPot, "GenericName", required: true).GetValue(); // Methods _Constructor = OutdoorPot.GetConstructor(new[] { typeof(string), typeof(Vector2) }); if (_Constructor == null) { throw new ArgumentNullException("cannot get constructor"); } _GetVariantKeyFromName = Helper.GetMethod(OutdoorPot, "GetVariantKeyFromName", required: true); _GetDisplayNameFromVariantKey = Helper.GetMethod(OutdoorPot, "GetDisplayNameFromVariantKey", required: true); _GetRawDescription = Helper.GetMethod(OutdoorPot, "GetRawDescription", required: true); //_GetSpriteSourceRectangle = Helper.GetMethod(OutdoorPot, "GetSpriteSourceRectangle", required: true); _GetSpriteSourceRectangle = OutdoorPot.GetMethod("GetSpriteSourceRectangle", BindingFlags.Public | BindingFlags.Static | BindingFlags.DeclaredOnly); if (_GetSpriteSourceRectangle == null) { throw new ArgumentNullException("cannot get GetSpriteSourceRectangle"); } } catch (Exception ex) { Log($"Unable to find GardenPot class. Disabling integration.", LogLevel.Info, ex, LogLevel.Debug); IsLoaded = false; } if (IsLoaded) { mod.Recipes.AddProvider(this); } }
/// <summary>When a menu is open (<see cref="Game1.activeClickableMenu"/> isn't null), raised after that menu is drawn to the sprite batch but before it's rendered to the screen.</summary> /// <param name="sender">The event sender.</param> /// <param name="e">The event arguments.</param> private void OnRenderedActiveMenu(object sender, RenderedActiveMenuEventArgs e) { // draw shop harvest prices if (Game1.activeClickableMenu is ShopMenu menu) { if (typeof(ShopMenu).GetField("hoveredItem", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(menu) is Item hoverItem) { String text = string.Empty; bool itemHasPriceInfo = GetTruePrice(hoverItem) > 0; if (hoverItem is StardewValley.Object && (hoverItem as StardewValley.Object).Type == "Seeds" && itemHasPriceInfo && hoverItem.Name != "Mixed Seeds" && hoverItem.Name != "Winter Seeds") { StardewValley.Object temp = new StardewValley.Object( new Debris( new Crop( hoverItem.ParentSheetIndex, 0, 0) .indexOfHarvest.Value, Game1.player.position, Game1.player.position).chunkType.Value, 1); text = " " + temp.Price; } Item heldItem = typeof(ShopMenu).GetField("heldItem", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(menu) as Item; if (heldItem == null) { int value = 0; switch (hoverItem.ParentSheetIndex) { case 628: value = 50; break; case 629: value = 80; break; case 630: case 633: value = 100; break; case 631: case 632: value = 140; break; } if (value > 0) { text = " " + value; } if (text != "" && (hoverItem as StardewValley.Object).Type == "Seeds") { String textToRender = ModEntry.Translation.Get( LanguageKeys.HarvestPrice); int xPosition = menu.xPositionOnScreen - 30; int yPosition = menu.yPositionOnScreen + 580; IClickableMenu.drawTextureBox( Game1.spriteBatch, xPosition + 20, yPosition - 52, 264, 108, Color.White); Game1.spriteBatch.DrawString( Game1.dialogueFont, textToRender, new Vector2(xPosition + 30, yPosition - 38), Color.Black * 0.2f); Game1.spriteBatch.DrawString( Game1.dialogueFont, textToRender, new Vector2(xPosition + 32, yPosition - 40), Color.Black * 0.8f); xPosition += 80; Game1.spriteBatch.Draw( Game1.mouseCursors, new Vector2(xPosition, yPosition), new Rectangle(60, 428, 10, 10), Color.White, 0, Vector2.Zero, Game1.pixelZoom, SpriteEffects.None, 0.85f); Game1.spriteBatch.Draw( Game1.debrisSpriteSheet, new Vector2(xPosition + 32, yPosition + 10), Game1.getSourceRectForStandardTileSheet(Game1.debrisSpriteSheet, 8, 16, 16), Color.White, 0, new Vector2(8, 8), 4, SpriteEffects.None, 0.95f); Game1.spriteBatch.DrawString( Game1.dialogueFont, text, new Vector2(xPosition - 2, yPosition + 6), Color.Black * 0.2f); Game1.spriteBatch.DrawString( Game1.dialogueFont, text, new Vector2(xPosition, yPosition + 4), Color.Black * 0.8f); IReflectionHelper Reflection = ModEntry.Reflection; String hoverText = Reflection.GetField <String>(menu, "hoverText").GetValue(); String hoverTitle = Reflection.GetField <String>(menu, "boldTitleText").GetValue(); Item hoverItem2 = Reflection.GetField <Item>(menu, "hoveredItem").GetValue(); int currency = Reflection.GetField <int>(menu, "currency").GetValue(); int hoverPrice = Reflection.GetField <int>(menu, "hoverPrice").GetValue(); IReflectedMethod getHoveredItemExtraItemIndex = Reflection.GetMethod(menu, "getHoveredItemExtraItemIndex"); IReflectedMethod getHoveredItemExtraItemAmount = Reflection.GetMethod(menu, "getHoveredItemExtraItemAmount"); IClickableMenu.drawToolTip( Game1.spriteBatch, hoverText, hoverTitle, hoverItem2, heldItem != null, -1, currency, getHoveredItemExtraItemIndex.Invoke <int>(new object[0]), getHoveredItemExtraItemAmount.Invoke <int>(new object[0]), null, hoverPrice); } } } } }