public static bool Prefix(FarmerRenderer __instance, SpriteBatch b, FarmerSprite.AnimationFrame animationFrame, int currentFrame, Rectangle sourceRect, Vector2 position, Vector2 origin, float layerDepth, int facingDirection, Color overrideColor, float rotation, float scale, Farmer who) { if (AllowOneMethodCall) { AllowOneMethodCall = false; return(true); } try { if (who != null && hitShakeTimers.ContainsKey(who.UniqueMultiplayerID)) { if (hitShakeTimers[who.UniqueMultiplayerID] % 100 < 50) { return(false); } } }catch (Exception) { return(true); } AllowOneMethodCall = true; try { __instance.draw(b, animationFrame, currentFrame, sourceRect, position, origin, layerDepth, facingDirection, overrideColor, rotation, scale, who); } catch (Exception) { } AllowOneMethodCall = false; return(false); }
/// <summary> /// Lock the player into a sitting-down animation facing a given direction until they press any key. /// </summary> /// <param name="position">Target position in world coordinates to sit at.</param> /// <param name="direction">Value for direction to face, follows standard SDV rules of clockwise-from-zero.</param> private static void SitDownStart(Vector2 position, int direction) { Game1.playSound("breathin"); Game1.player.mount = null; _playerLastStandingLocation = Game1.player.getTileLocation(); IsPlayerSittingDown = true; // TODO: METHOD: Add check for front layer objects to opt-out of the 64f+16f player offset Game1.player.yOffset = 0f; if (direction != 0) { const int yOffsetTiles = 1; position.Y += yOffsetTiles; Game1.player.yOffset = yOffsetTiles * 64f + 16f; } Game1.player.faceDirection(direction); Game1.player.completelyStopAnimatingOrDoingAction(); Game1.player.setTileLocation(position); var animFrames = new FarmerSprite.AnimationFrame[1]; animFrames[0] = new FarmerSprite.AnimationFrame( PlayerSittingFrames[direction], 999999, false, direction == 3); Game1.player.FarmerSprite.animateOnce(animFrames); Game1.player.CanMove = false; }
/********* ** Public methods *********/ /// <summary>Construct an instance.</summary> /// <param name="sourceRectangle">The area of the spritesheet to show for this frame.</param> /// <param name="startFrame">The first frame in the animation.</param> public AnimationFrame(Rectangle sourceRectangle, FarmerSprite.AnimationFrame startFrame) { this.AnimationStartFrame = startFrame.frame; this.AnimationStartTime = startFrame.milliseconds; this.AnimationStartBehaviour = startFrame.frameBehavior?.Method.ToString(); this.SourceRectangle = sourceRectangle; }
public static bool draw_Prefix(ref FarmerRenderer __instance, SpriteBatch b, FarmerSprite.AnimationFrame animationFrame, int currentFrame, Rectangle sourceRect, Vector2 position, Vector2 origin, float layerDepth, int facingDirection, Color overrideColor, float rotation, float scale, Farmer who, ref PanHat __state) { // Store the hat if it's a pan. if (who.hat.Value != null && who.hat.Value is PanHat panHat) { __state = panHat; } return(true); }
internal static void DrawPostFix(SpriteBatch b, FarmerSprite.AnimationFrame animationFrame, int currentFrame, Rectangle sourceRect, Vector2 position, Vector2 origin, float layerDepth, int facingDirection, Color overrideColor, float rotation, float scale, Farmer who, FarmerRenderer __instance) { if (ModEntry.EquippedOuterwear == null) { return; } OuterwearData outerwearData = ModEntry.OuterwearData .Where(data => data.DisplayName == ModEntry.EquippedOuterwear.DisplayName) .FirstOrDefault(); // get private member values Vector2 positionOffset = (Vector2)typeof(FarmerRenderer).GetField("positionOffset", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(__instance); positionOffset.Y -= 4; Rectangle? sourceRectangle = null; SpriteEffects spriteEffects = SpriteEffects.None; switch (facingDirection) { case 0: positionOffset.Y += 4; sourceRectangle = new Rectangle(0, 64, 16, 32); break; case 1: sourceRectangle = new Rectangle(0, 32, 16, 32); break; case 2: sourceRectangle = new Rectangle(0, 0, 16, 32); break; case 3: sourceRectangle = new Rectangle(0, 32, 16, 32); spriteEffects = SpriteEffects.FlipHorizontally; break; } b.Draw( texture: outerwearData.EquippedTexture, position: position + origin + positionOffset + new Vector2(FarmerRenderer.featureXOffsetPerFrame[currentFrame] * 4, FarmerRenderer.featureYOffsetPerFrame[currentFrame] * 4), sourceRectangle: sourceRectangle, color: Color.White, rotation: rotation, origin: origin, scale: 4f * scale, effects: spriteEffects, layerDepth: layerDepth + 4.9E-04f ); }
public void draw(SpriteBatch b, FarmerSprite.AnimationFrame animationFrame, int currentFrame, Rectangle sourceRect, Vector2 position, Vector2 origin, float layerDepth, int facingDirection, Color overrideColor, float rotation, float scale, Farmer who) { position = new Vector2((float)Math.Floor((double)position.X), (float)Math.Floor((double)position.Y)); this.rotationAdjustment = Vector2.Zero; this.positionOffset.Y = (float)(animationFrame.positionOffset * Game1.pixelZoom); this.positionOffset.X = (float)(animationFrame.xOffset * Game1.pixelZoom); if (who.swimming) { sourceRect.Height /= 2; sourceRect.Height -= (int)who.yOffset / Game1.pixelZoom; position.Y += (float)Game1.tileSize; } b.Draw(this.baseTexture, position + origin + this.positionOffset, new Rectangle?(sourceRect), overrideColor, rotation, origin, (float)Game1.pixelZoom * scale, animationFrame.flip ? SpriteEffects.FlipHorizontally : SpriteEffects.None, layerDepth); if (who.swimming) { if (who.currentEyes != 0 && who.facingDirection != 0 && Game1.timeOfDay < 2600 && (!who.FarmerSprite.pauseForSingleAnimation || who.usingTool && who.CurrentTool is FishingRod)) { b.Draw(this.baseTexture, position + origin + this.positionOffset + new Vector2((float)(FarmerRenderer.featureXOffsetPerFrame[currentFrame] * Game1.pixelZoom + 5 * Game1.pixelZoom + (who.FacingDirection == 1 ? 3 * Game1.pixelZoom : (who.FacingDirection == 3 ? Game1.pixelZoom : 0))), (float)(FarmerRenderer.featureYOffsetPerFrame[currentFrame] * Game1.pixelZoom + (who.IsMale ? 9 * Game1.pixelZoom : 10 * Game1.pixelZoom))), new Rectangle?(new Rectangle(5, 16, who.FacingDirection == 2 ? 6 : 2, 2)), overrideColor, 0.0f, origin, (float)Game1.pixelZoom * scale, SpriteEffects.None, layerDepth + 5E-08f); b.Draw(this.baseTexture, position + origin + this.positionOffset + new Vector2((float)(FarmerRenderer.featureXOffsetPerFrame[currentFrame] * Game1.pixelZoom + 5 * Game1.pixelZoom + (who.FacingDirection == 1 ? 3 * Game1.pixelZoom : (who.FacingDirection == 3 ? Game1.pixelZoom : 0))), (float)(FarmerRenderer.featureYOffsetPerFrame[currentFrame] * Game1.pixelZoom + (who.IsMale ? 9 * Game1.pixelZoom : 10 * Game1.pixelZoom))), new Rectangle?(new Rectangle(264 + (who.FacingDirection == 3 ? 4 : 0), 2 + (who.currentEyes - 1) * 2, who.FacingDirection == 2 ? 6 : 2, 2)), overrideColor, 0.0f, origin, (float)Game1.pixelZoom * scale, SpriteEffects.None, layerDepth + 1.2E-07f); } this.drawHairAndAccesories(b, facingDirection, who, position, origin, scale, currentFrame, rotation, overrideColor, layerDepth); b.Draw(Game1.staminaRect, new Rectangle((int)position.X + (int)who.yOffset + Game1.pixelZoom * 2, (int)position.Y - 32 * Game1.pixelZoom + sourceRect.Height * Game1.pixelZoom + (int)origin.Y - (int)who.yOffset, sourceRect.Width * Game1.pixelZoom - (int)who.yOffset * 2 - Game1.pixelZoom * Game1.pixelZoom, Game1.pixelZoom), new Rectangle?(Game1.staminaRect.Bounds), Color.White * 0.75f, 0.0f, Vector2.Zero, SpriteEffects.None, layerDepth + 1f / 1000f); } else { sourceRect.Offset(288, 0); b.Draw(this.baseTexture, position + origin + this.positionOffset, new Rectangle?(sourceRect), overrideColor.Equals(Color.White) ? who.pantsColor : overrideColor, rotation, origin, (float)Game1.pixelZoom * scale, animationFrame.flip ? SpriteEffects.FlipHorizontally : SpriteEffects.None, layerDepth + (who.FarmerSprite.CurrentAnimationFrame.frame == 5 ? 0.00092f : 9.2E-08f)); if (who.currentEyes != 0 && facingDirection != 0 && (!who.isRidingHorse() && Game1.timeOfDay < 2600) && (!who.FarmerSprite.pauseForSingleAnimation || who.usingTool && who.CurrentTool is FishingRod)) { b.Draw(this.baseTexture, position + origin + this.positionOffset + new Vector2((float)(FarmerRenderer.featureXOffsetPerFrame[currentFrame] * Game1.pixelZoom + 5 * Game1.pixelZoom + (facingDirection == 1 ? 3 * Game1.pixelZoom : (facingDirection == 3 ? Game1.pixelZoom : 0))), (float)(FarmerRenderer.featureYOffsetPerFrame[currentFrame] * Game1.pixelZoom + (!who.IsMale || who.facingDirection == 2 ? 10 * Game1.pixelZoom : 9 * Game1.pixelZoom))), new Rectangle?(new Rectangle(5, 16, facingDirection == 2 ? 6 : 2, 2)), overrideColor, 0.0f, origin, (float)Game1.pixelZoom * scale, SpriteEffects.None, layerDepth + 5E-08f); b.Draw(this.baseTexture, position + origin + this.positionOffset + new Vector2((float)(FarmerRenderer.featureXOffsetPerFrame[currentFrame] * Game1.pixelZoom + 5 * Game1.pixelZoom + (facingDirection == 1 ? 3 * Game1.pixelZoom : (facingDirection == 3 ? Game1.pixelZoom : 0))), (float)(FarmerRenderer.featureYOffsetPerFrame[currentFrame] * Game1.pixelZoom + (who.facingDirection == 1 || who.facingDirection == 3 ? 10 * Game1.pixelZoom : 11 * Game1.pixelZoom))), new Rectangle?(new Rectangle(264 + (facingDirection == 3 ? 4 : 0), 2 + (who.currentEyes - 1) * 2, facingDirection == 2 ? 6 : 2, 2)), overrideColor, 0.0f, origin, (float)Game1.pixelZoom * scale, SpriteEffects.None, layerDepth + 1.2E-07f); } this.drawHairAndAccesories(b, facingDirection, who, position, origin, scale, currentFrame, rotation, overrideColor, layerDepth); sourceRect.Offset((animationFrame.secondaryArm ? 192 : 96) - 288, 0); b.Draw(this.baseTexture, position + origin + this.positionOffset + who.armOffset, new Rectangle?(sourceRect), overrideColor, rotation, origin, (float)Game1.pixelZoom * scale, animationFrame.flip ? SpriteEffects.FlipHorizontally : SpriteEffects.None, layerDepth + (facingDirection != 0 ? 4.9E-05f : 0.0f)); if (!who.usingSlingshot) { return; } int num1 = Game1.getOldMouseX() + Game1.viewport.X; int num2 = Game1.getOldMouseY() + Game1.viewport.Y; if ((who.CurrentTool as Slingshot).didStartWithGamePad()) { Vector2 standingPosition = Game1.player.getStandingPosition(); GamePadThumbSticks thumbSticks = Game1.oldPadState.ThumbSticks; double x = (double)thumbSticks.Left.X; thumbSticks = Game1.oldPadState.ThumbSticks; double num3 = -(double)thumbSticks.Left.Y; Vector2 vector2 = new Vector2((float)x, (float)num3) * (float)Game1.tileSize * 4f; Point point = Utility.Vector2ToPoint(standingPosition + vector2); num1 = point.X; num2 = point.Y; } int num4 = Math.Min(20, (int)Vector2.Distance(who.getStandingPosition(), new Vector2((float)num1, (float)num2)) / 20); float rotation1 = (float)Math.Atan2((double)num2 - (double)who.getStandingPosition().Y - (double)Game1.tileSize, (double)num1 - (double)who.getStandingPosition().X) + 3.141593f; switch (facingDirection) { case 0: b.Draw(this.baseTexture, position + new Vector2((float)(4.0 + (double)rotation1 * 8.0), (float)(-Game1.tileSize * 3 / 4 + 4)), new Rectangle?(new Rectangle(173, 238, 9, 14)), Color.White, 0.0f, new Vector2(4f, 11f), (float)Game1.pixelZoom * scale, SpriteEffects.None, layerDepth + (facingDirection != 0 ? 5.9E-05f : -0.0005f)); break; case 1: b.Draw(this.baseTexture, position + new Vector2((float)(52 - num4), (float)(-Game1.tileSize / 2)), new Rectangle?(new Rectangle(147, 237, 10, 4)), Color.White, 0.0f, new Vector2(8f, 3f), (float)Game1.pixelZoom * scale, SpriteEffects.None, layerDepth + (facingDirection != 0 ? 5.9E-05f : 0.0f)); b.Draw(this.baseTexture, position + new Vector2(36f, (float)(-Game1.tileSize / 2 - 12)), new Rectangle?(new Rectangle(156, 244, 9, 10)), Color.White, rotation1, new Vector2(0.0f, 3f), (float)Game1.pixelZoom * scale, SpriteEffects.None, layerDepth + (facingDirection != 0 ? 1E-08f : 0.0f)); int num5 = (int)(Math.Cos((double)rotation1 + 1.57079637050629) * (double)(20 - num4 - 8) - Math.Sin((double)rotation1 + 1.57079637050629) * -68.0); int num6 = (int)(Math.Sin((double)rotation1 + 1.57079637050629) * (double)(20 - num4 - 8) + Math.Cos((double)rotation1 + 1.57079637050629) * -68.0); Utility.drawLineWithScreenCoordinates((int)((double)position.X + 52.0 - (double)num4), (int)((double)position.Y - (double)(Game1.tileSize / 2) - 4.0), (int)((double)position.X + 32.0 + (double)(num5 / 2)), (int)((double)position.Y - (double)(Game1.tileSize / 2) - 12.0 + (double)(num6 / 2)), b, Color.White, 1f); break; case 2: b.Draw(this.baseTexture, position + new Vector2(4f, (float)(-Game1.tileSize / 2 - num4 / 2)), new Rectangle?(new Rectangle(148, 244, 4, 4)), Color.White, 0.0f, Vector2.Zero, (float)Game1.pixelZoom * scale, SpriteEffects.None, layerDepth + (facingDirection != 0 ? 5.9E-05f : 0.0f)); Utility.drawLineWithScreenCoordinates((int)((double)position.X + 16.0), (int)((double)position.Y - 28.0 - (double)(num4 / 2)), (int)((double)position.X + 44.0 - (double)rotation1 * 10.0), (int)((double)position.Y - (double)(Game1.tileSize / 4) - 8.0), b, Color.White, 1f); Utility.drawLineWithScreenCoordinates((int)((double)position.X + 16.0), (int)((double)position.Y - 28.0 - (double)(num4 / 2)), (int)((double)position.X + 56.0 - (double)rotation1 * 10.0), (int)((double)position.Y - (double)(Game1.tileSize / 4) - 8.0), b, Color.White, 1f); b.Draw(this.baseTexture, position + new Vector2((float)(44.0 - (double)rotation1 * 10.0), (float)(-Game1.tileSize / 4)), new Rectangle?(new Rectangle(167, 235, 7, 9)), Color.White, 0.0f, new Vector2(3f, 5f), (float)Game1.pixelZoom * scale, SpriteEffects.None, layerDepth + (facingDirection != 0 ? 5.9E-05f : 0.0f)); break; case 3: b.Draw(this.baseTexture, position + new Vector2((float)(40 + num4), (float)(-Game1.tileSize / 2)), new Rectangle?(new Rectangle(147, 237, 10, 4)), Color.White, 0.0f, new Vector2(9f, 4f), (float)Game1.pixelZoom * scale, SpriteEffects.FlipHorizontally, layerDepth + (facingDirection != 0 ? 5.9E-05f : 0.0f)); b.Draw(this.baseTexture, position + new Vector2(24f, (float)(-Game1.tileSize / 2 - 8)), new Rectangle?(new Rectangle(156, 244, 9, 10)), Color.White, rotation1 + 3.141593f, new Vector2(8f, 3f), (float)Game1.pixelZoom * scale, SpriteEffects.FlipHorizontally, layerDepth + (facingDirection != 0 ? 1E-08f : 0.0f)); int num7 = (int)(Math.Cos((double)rotation1 + 1.25663709640503) * (double)(20 + num4 - 8) - Math.Sin((double)rotation1 + 1.25663709640503) * -68.0); int num8 = (int)(Math.Sin((double)rotation1 + 1.25663709640503) * (double)(20 + num4 - 8) + Math.Cos((double)rotation1 + 1.25663709640503) * -68.0); Utility.drawLineWithScreenCoordinates((int)((double)position.X + 4.0 + (double)num4), (int)((double)position.Y - (double)(Game1.tileSize / 2) - 8.0), (int)((double)position.X + 26.0 + (double)num7 * 4.0 / 10.0), (int)((double)position.Y - (double)(Game1.tileSize / 2) - 8.0 + (double)num8 * 4.0 / 10.0), b, Color.White, 1f); break; } } }
public void draw(SpriteBatch b, FarmerSprite.AnimationFrame animationFrame, int currentFrame, Rectangle sourceRect, Vector2 position, Vector2 origin, float layerDepth, Color overrideColor, float rotation, float scale, Farmer who) { this.draw(b, animationFrame, currentFrame, sourceRect, position, origin, layerDepth, who.facingDirection, overrideColor, rotation, scale, who); }
public void draw(SpriteBatch b, FarmerSprite.AnimationFrame animationFrame, int currentFrame, Rectangle sourceRect, Vector2 position, Vector2 origin, float layerDepth, int facingDirection, Color overrideColor, float rotation, float scale, Farmer who) { bool sick_frame = currentFrame == 104 || currentFrame == 105; if (_sickFrame != sick_frame) { _sickFrame = sick_frame; _shirtDirty = true; _spriteDirty = true; } executeRecolorActions(who); position = new Vector2((float)Math.Floor(position.X), (float)Math.Floor(position.Y)); rotationAdjustment = Vector2.Zero; positionOffset.Y = animationFrame.positionOffset * 4; positionOffset.X = animationFrame.xOffset * 4; if (!isDrawingForUI && (bool)who.swimming) { sourceRect.Height /= 2; sourceRect.Height -= (int)who.yOffset / 4; position.Y += 64f; } if (facingDirection == 3 || facingDirection == 1) { facingDirection = ((!animationFrame.flip) ? 1 : 3); } b.Draw(baseTexture, position + origin + positionOffset, sourceRect, overrideColor, rotation, origin, 4f * scale, animationFrame.flip ? SpriteEffects.FlipHorizontally : SpriteEffects.None, layerDepth); if (!isDrawingForUI && (bool)who.swimming) { if (who.currentEyes != 0 && who.FacingDirection != 0 && (Game1.timeOfDay < 2600 || (who.isInBed.Value && who.timeWentToBed.Value != 0)) && (!who.FarmerSprite.PauseForSingleAnimation || (who.UsingTool && who.CurrentTool is FishingRod))) { b.Draw(baseTexture, position + origin + positionOffset + new Vector2(featureXOffsetPerFrame[currentFrame] * 4 + 20 + ((who.FacingDirection == 1) ? 12 : ((who.FacingDirection == 3) ? 4 : 0)), featureYOffsetPerFrame[currentFrame] * 4 + 40), new Rectangle(5, 16, (who.FacingDirection == 2) ? 6 : 2, 2), overrideColor, 0f, origin, 4f * scale, SpriteEffects.None, layerDepth + 5E-08f); b.Draw(baseTexture, position + origin + positionOffset + new Vector2(featureXOffsetPerFrame[currentFrame] * 4 + 20 + ((who.FacingDirection == 1) ? 12 : ((who.FacingDirection == 3) ? 4 : 0)), featureYOffsetPerFrame[currentFrame] * 4 + 40), new Rectangle(264 + ((who.FacingDirection == 3) ? 4 : 0), 2 + (who.currentEyes - 1) * 2, (who.FacingDirection == 2) ? 6 : 2, 2), overrideColor, 0f, origin, 4f * scale, SpriteEffects.None, layerDepth + 1.2E-07f); } drawHairAndAccesories(b, facingDirection, who, position, origin, scale, currentFrame, rotation, overrideColor, layerDepth); b.Draw(Game1.staminaRect, new Rectangle((int)position.X + (int)who.yOffset + 8, (int)position.Y - 128 + sourceRect.Height * 4 + (int)origin.Y - (int)who.yOffset, sourceRect.Width * 4 - (int)who.yOffset * 2 - 16, 4), Game1.staminaRect.Bounds, Color.White * 0.75f, 0f, Vector2.Zero, SpriteEffects.None, layerDepth + 0.001f); return; } Rectangle pants_rect = new Rectangle(sourceRect.X, sourceRect.Y, sourceRect.Width, sourceRect.Height); pants_rect.X += ClampPants(who.GetPantsIndex()) % 10 * 192; pants_rect.Y += ClampPants(who.GetPantsIndex()) / 10 * 688; if (!who.IsMale) { pants_rect.X += 96; } b.Draw(pantsTexture, position + origin + positionOffset, pants_rect, overrideColor.Equals(Color.White) ? Utility.MakeCompletelyOpaque(who.GetPantsColor()) : overrideColor, rotation, origin, 4f * scale, animationFrame.flip ? SpriteEffects.FlipHorizontally : SpriteEffects.None, layerDepth + ((who.FarmerSprite.CurrentAnimationFrame.frame == 5) ? 0.00092f : 9.2E-08f)); sourceRect.Offset(288, 0); FishingRod fishing_rod; if (who.currentEyes != 0 && facingDirection != 0 && (Game1.timeOfDay < 2600 || (who.isInBed.Value && who.timeWentToBed.Value != 0)) && (!who.FarmerSprite.PauseForSingleAnimation || (who.UsingTool && who.CurrentTool is FishingRod)) && (!who.UsingTool || (fishing_rod = who.CurrentTool as FishingRod) == null || fishing_rod.isFishing)) { int x_adjustment = 5; x_adjustment = (animationFrame.flip ? (x_adjustment - featureXOffsetPerFrame[currentFrame]) : (x_adjustment + featureXOffsetPerFrame[currentFrame])); switch (facingDirection) { case 1: x_adjustment += 3; break; case 3: x_adjustment++; break; } x_adjustment *= 4; b.Draw(baseTexture, position + origin + positionOffset + new Vector2(x_adjustment, featureYOffsetPerFrame[currentFrame] * 4 + ((who.IsMale && who.FacingDirection != 2) ? 36 : 40)), new Rectangle(5, 16, (facingDirection == 2) ? 6 : 2, 2), overrideColor, 0f, origin, 4f * scale, SpriteEffects.None, layerDepth + 5E-08f); b.Draw(baseTexture, position + origin + positionOffset + new Vector2(x_adjustment, featureYOffsetPerFrame[currentFrame] * 4 + ((who.FacingDirection == 1 || who.FacingDirection == 3) ? 40 : 44)), new Rectangle(264 + ((facingDirection == 3) ? 4 : 0), 2 + (who.currentEyes - 1) * 2, (facingDirection == 2) ? 6 : 2, 2), overrideColor, 0f, origin, 4f * scale, SpriteEffects.None, layerDepth + 1.2E-07f); } drawHairAndAccesories(b, facingDirection, who, position, origin, scale, currentFrame, rotation, overrideColor, layerDepth); float arm_layer_offset = 4.9E-05f; if (facingDirection == 0) { arm_layer_offset = -1E-07f; } sourceRect.Offset(-288 + (animationFrame.secondaryArm ? 192 : 96), 0); b.Draw(baseTexture, position + origin + positionOffset + who.armOffset, sourceRect, overrideColor, rotation, origin, 4f * scale, animationFrame.flip ? SpriteEffects.FlipHorizontally : SpriteEffects.None, layerDepth + arm_layer_offset); if (!who.usingSlingshot || !(who.CurrentTool is Slingshot)) { return; } Slingshot slingshot = who.CurrentTool as Slingshot; Point point = Utility.Vector2ToPoint(slingshot.AdjustForHeight(Utility.PointToVector2(slingshot.aimPos.Value))); int mouseX = point.X; int y = point.Y; int backArmDistance = slingshot.GetBackArmDistance(who); Vector2 shoot_origin = slingshot.GetShootOrigin(who); float frontArmRotation = (float)Math.Atan2((float)y - shoot_origin.Y, (float)mouseX - shoot_origin.X) + (float)Math.PI; if (!Game1.options.useLegacySlingshotFiring) { frontArmRotation -= (float)Math.PI; if (frontArmRotation < 0f) { frontArmRotation += (float)Math.PI * 2f; } } switch (facingDirection) { case 0: b.Draw(baseTexture, position + new Vector2(4f + frontArmRotation * 8f, -44f), new Rectangle(173, 238, 9, 14), Color.White, 0f, new Vector2(4f, 11f), 4f * scale, SpriteEffects.None, layerDepth + ((facingDirection != 0) ? 5.9E-05f : (-0.0005f))); break; case 1: { b.Draw(baseTexture, position + new Vector2(52 - backArmDistance, -32f), new Rectangle(147, 237, 10, 4), Color.White, 0f, new Vector2(8f, 3f), 4f * scale, SpriteEffects.None, layerDepth + ((facingDirection != 0) ? 5.9E-05f : 0f)); b.Draw(baseTexture, position + new Vector2(36f, -44f), new Rectangle(156, 244, 9, 10), Color.White, frontArmRotation, new Vector2(0f, 3f), 4f * scale, SpriteEffects.None, layerDepth + ((facingDirection != 0) ? 1E-08f : 0f)); int slingshotAttachX = (int)(Math.Cos(frontArmRotation + (float)Math.PI / 2f) * (double)(20 - backArmDistance - 8) - Math.Sin(frontArmRotation + (float)Math.PI / 2f) * -68.0); int slingshotAttachY = (int)(Math.Sin(frontArmRotation + (float)Math.PI / 2f) * (double)(20 - backArmDistance - 8) + Math.Cos(frontArmRotation + (float)Math.PI / 2f) * -68.0); Utility.drawLineWithScreenCoordinates((int)(position.X + 52f - (float)backArmDistance), (int)(position.Y - 32f - 4f), (int)(position.X + 32f + (float)(slingshotAttachX / 2)), (int)(position.Y - 32f - 12f + (float)(slingshotAttachY / 2)), b, Color.White); break; } case 3: { b.Draw(baseTexture, position + new Vector2(40 + backArmDistance, -32f), new Rectangle(147, 237, 10, 4), Color.White, 0f, new Vector2(9f, 4f), 4f * scale, SpriteEffects.FlipHorizontally, layerDepth + ((facingDirection != 0) ? 5.9E-05f : 0f)); b.Draw(baseTexture, position + new Vector2(24f, -40f), new Rectangle(156, 244, 9, 10), Color.White, frontArmRotation + (float)Math.PI, new Vector2(8f, 3f), 4f * scale, SpriteEffects.FlipHorizontally, layerDepth + ((facingDirection != 0) ? 1E-08f : 0f)); int slingshotAttachX = (int)(Math.Cos(frontArmRotation + (float)Math.PI * 2f / 5f) * (double)(20 + backArmDistance - 8) - Math.Sin(frontArmRotation + (float)Math.PI * 2f / 5f) * -68.0); int slingshotAttachY = (int)(Math.Sin(frontArmRotation + (float)Math.PI * 2f / 5f) * (double)(20 + backArmDistance - 8) + Math.Cos(frontArmRotation + (float)Math.PI * 2f / 5f) * -68.0); Utility.drawLineWithScreenCoordinates((int)(position.X + 4f + (float)backArmDistance), (int)(position.Y - 32f - 8f), (int)(position.X + 26f + (float)slingshotAttachX * 4f / 10f), (int)(position.Y - 32f - 8f + (float)slingshotAttachY * 4f / 10f), b, Color.White); break; } case 2: b.Draw(baseTexture, position + new Vector2(4f, -32 - backArmDistance / 2), new Rectangle(148, 244, 4, 4), Color.White, 0f, Vector2.Zero, 4f * scale, SpriteEffects.None, layerDepth + ((facingDirection != 0) ? 5.9E-05f : 0f)); Utility.drawLineWithScreenCoordinates((int)(position.X + 16f), (int)(position.Y - 28f - (float)(backArmDistance / 2)), (int)(position.X + 44f - frontArmRotation * 10f), (int)(position.Y - 16f - 8f), b, Color.White); Utility.drawLineWithScreenCoordinates((int)(position.X + 16f), (int)(position.Y - 28f - (float)(backArmDistance / 2)), (int)(position.X + 56f - frontArmRotation * 10f), (int)(position.Y - 16f - 8f), b, Color.White); b.Draw(baseTexture, position + new Vector2(44f - frontArmRotation * 10f, -16f), new Rectangle(167, 235, 7, 9), Color.White, 0f, new Vector2(3f, 5f), 4f * scale, SpriteEffects.None, layerDepth + ((facingDirection != 0) ? 5.9E-05f : 0f)); break; } }
// Token: 0x060000F4 RID: 244 RVA: 0x0000B40C File Offset: 0x0000960C public void draw(SpriteBatch b, FarmerSprite.AnimationFrame animationFrame, int currentFrame, Rectangle sourceRect, Vector2 position, Vector2 origin, float layerDepth, int facingDirection, Color overrideColor, float rotation, float scale, Farmer who) { position = new Vector2((float)Math.Floor((double)position.X), (float)Math.Floor((double)position.Y)); this.rotationAdjustment = Vector2.Zero; this.positionOffset.Y = (float)(animationFrame.positionOffset * Game1.pixelZoom); this.positionOffset.X = (float)(animationFrame.xOffset * Game1.pixelZoom); if (who.swimming) { sourceRect.Height /= 2; sourceRect.Height -= (int)who.yOffset / Game1.pixelZoom; position.Y += (float)Game1.tileSize; } b.Draw(this.baseTexture, position + origin + this.positionOffset, new Rectangle?(sourceRect), overrideColor, rotation, origin, (float)Game1.pixelZoom * scale, animationFrame.flip ? SpriteEffects.FlipHorizontally : SpriteEffects.None, layerDepth); if (who.swimming) { if (who.currentEyes != 0 && who.facingDirection != 0 && Game1.timeOfDay < 2600 && (!who.FarmerSprite.pauseForSingleAnimation || (who.usingTool && who.CurrentTool is FishingRod))) { b.Draw(this.baseTexture, position + origin + this.positionOffset + new Vector2((float)(FarmerRenderer.featureXOffsetPerFrame[currentFrame] * Game1.pixelZoom + 5 * Game1.pixelZoom + ((who.FacingDirection == 1) ? (3 * Game1.pixelZoom) : ((who.FacingDirection == 3) ? Game1.pixelZoom : 0))), (float)(FarmerRenderer.featureYOffsetPerFrame[currentFrame] * Game1.pixelZoom + (who.IsMale ? (9 * Game1.pixelZoom) : (10 * Game1.pixelZoom)))), new Rectangle?(new Rectangle(5, 16, (who.FacingDirection == 2) ? 6 : 2, 2)), overrideColor, 0f, origin, (float)Game1.pixelZoom * scale, SpriteEffects.None, layerDepth + 5E-08f); b.Draw(this.baseTexture, position + origin + this.positionOffset + new Vector2((float)(FarmerRenderer.featureXOffsetPerFrame[currentFrame] * Game1.pixelZoom + 5 * Game1.pixelZoom + ((who.FacingDirection == 1) ? (3 * Game1.pixelZoom) : ((who.FacingDirection == 3) ? Game1.pixelZoom : 0))), (float)(FarmerRenderer.featureYOffsetPerFrame[currentFrame] * Game1.pixelZoom + (who.IsMale ? (9 * Game1.pixelZoom) : (10 * Game1.pixelZoom)))), new Rectangle?(new Rectangle(264 + ((who.FacingDirection == 3) ? 4 : 0), 2 + (who.currentEyes - 1) * 2, (who.FacingDirection == 2) ? 6 : 2, 2)), overrideColor, 0f, origin, (float)Game1.pixelZoom * scale, SpriteEffects.None, layerDepth + 1.2E-07f); } this.drawHairAndAccesories(b, facingDirection, who, position, origin, scale, currentFrame, rotation, overrideColor, layerDepth); b.Draw(Game1.staminaRect, new Rectangle((int)position.X + (int)who.yOffset + Game1.pixelZoom * 2, (int)position.Y - 32 * Game1.pixelZoom + sourceRect.Height * Game1.pixelZoom + (int)origin.Y - (int)who.yOffset, sourceRect.Width * Game1.pixelZoom - (int)who.yOffset * 2 - Game1.pixelZoom * Game1.pixelZoom, Game1.pixelZoom), new Rectangle?(Game1.staminaRect.Bounds), Color.White * 0.75f, 0f, Vector2.Zero, SpriteEffects.None, layerDepth + 0.001f); return; } sourceRect.Offset(288, 0); b.Draw(this.baseTexture, position + origin + this.positionOffset, new Rectangle?(sourceRect), overrideColor.Equals(Color.White) ? who.pantsColor : overrideColor, rotation, origin, (float)Game1.pixelZoom * scale, animationFrame.flip ? SpriteEffects.FlipHorizontally : SpriteEffects.None, layerDepth + ((who.FarmerSprite.CurrentAnimationFrame.frame == 5) ? 0.00092f : 9.2E-08f)); if (who.currentEyes != 0 && facingDirection != 0 && !who.isRidingHorse() && Game1.timeOfDay < 2600 && (!who.FarmerSprite.pauseForSingleAnimation || (who.usingTool && who.CurrentTool is FishingRod))) { b.Draw(this.baseTexture, position + origin + this.positionOffset + new Vector2((float)(FarmerRenderer.featureXOffsetPerFrame[currentFrame] * Game1.pixelZoom + 5 * Game1.pixelZoom + ((facingDirection == 1) ? (3 * Game1.pixelZoom) : ((facingDirection == 3) ? Game1.pixelZoom : 0))), (float)(FarmerRenderer.featureYOffsetPerFrame[currentFrame] * Game1.pixelZoom + ((who.IsMale && who.facingDirection != 2) ? (9 * Game1.pixelZoom) : (10 * Game1.pixelZoom)))), new Rectangle?(new Rectangle(5, 16, (facingDirection == 2) ? 6 : 2, 2)), overrideColor, 0f, origin, (float)Game1.pixelZoom * scale, SpriteEffects.None, layerDepth + 5E-08f); b.Draw(this.baseTexture, position + origin + this.positionOffset + new Vector2((float)(FarmerRenderer.featureXOffsetPerFrame[currentFrame] * Game1.pixelZoom + 5 * Game1.pixelZoom + ((facingDirection == 1) ? (3 * Game1.pixelZoom) : ((facingDirection == 3) ? Game1.pixelZoom : 0))), (float)(FarmerRenderer.featureYOffsetPerFrame[currentFrame] * Game1.pixelZoom + ((who.facingDirection == 1 || who.facingDirection == 3) ? (10 * Game1.pixelZoom) : (11 * Game1.pixelZoom)))), new Rectangle?(new Rectangle(264 + ((facingDirection == 3) ? 4 : 0), 2 + (who.currentEyes - 1) * 2, (facingDirection == 2) ? 6 : 2, 2)), overrideColor, 0f, origin, (float)Game1.pixelZoom * scale, SpriteEffects.None, layerDepth + 1.2E-07f); } this.drawHairAndAccesories(b, facingDirection, who, position, origin, scale, currentFrame, rotation, overrideColor, layerDepth); sourceRect.Offset(-288 + (animationFrame.secondaryArm ? 192 : 96), 0); b.Draw(this.baseTexture, position + origin + this.positionOffset + who.armOffset, new Rectangle?(sourceRect), overrideColor, rotation, origin, (float)Game1.pixelZoom * scale, animationFrame.flip ? SpriteEffects.FlipHorizontally : SpriteEffects.None, layerDepth + ((facingDirection != 0) ? 4.9E-05f : 0f)); if (who.usingSlingshot) { int mouseX = Game1.getOldMouseX() + Game1.viewport.X; int mouseY = Game1.getOldMouseY() + Game1.viewport.Y; if ((who.CurrentTool as Slingshot).didStartWithGamePad()) { Point expr_770 = Utility.Vector2ToPoint(Game1.player.getStandingPosition() + new Vector2(Game1.oldPadState.ThumbSticks.Left.X, -Game1.oldPadState.ThumbSticks.Left.Y) * (float)Game1.tileSize * 4f); mouseX = expr_770.X; mouseY = expr_770.Y; } int backArmDistance = Math.Min(20, (int)Vector2.Distance(who.getStandingPosition(), new Vector2((float)mouseX, (float)mouseY)) / 20); float frontArmRotation = (float)Math.Atan2((double)((float)mouseY - who.getStandingPosition().Y - (float)Game1.tileSize), (double)((float)mouseX - who.getStandingPosition().X)) + 3.14159274f; switch (facingDirection) { case 0: b.Draw(this.baseTexture, position + new Vector2(4f + frontArmRotation * 8f, (float)(-(float)Game1.tileSize * 3 / 4 + 4)), new Rectangle?(new Rectangle(173, 238, 9, 14)), Color.White, 0f, new Vector2(4f, 11f), (float)Game1.pixelZoom * scale, SpriteEffects.None, layerDepth + ((facingDirection != 0) ? 5.9E-05f : -0.0005f)); return; case 1: { b.Draw(this.baseTexture, position + new Vector2((float)(52 - backArmDistance), (float)(-(float)Game1.tileSize / 2)), new Rectangle?(new Rectangle(147, 237, 10, 4)), Color.White, 0f, new Vector2(8f, 3f), (float)Game1.pixelZoom * scale, SpriteEffects.None, layerDepth + ((facingDirection != 0) ? 5.9E-05f : 0f)); b.Draw(this.baseTexture, position + new Vector2(36f, (float)(-(float)Game1.tileSize / 2 - 12)), new Rectangle?(new Rectangle(156, 244, 9, 10)), Color.White, frontArmRotation, new Vector2(0f, 3f), (float)Game1.pixelZoom * scale, SpriteEffects.None, layerDepth + ((facingDirection != 0) ? 1E-08f : 0f)); int slingshotAttachX = (int)(Math.Cos((double)(frontArmRotation + 1.57079637f)) * (double)(20 - backArmDistance - 8) - Math.Sin((double)(frontArmRotation + 1.57079637f)) * -68.0); int slingshotAttachY = (int)(Math.Sin((double)(frontArmRotation + 1.57079637f)) * (double)(20 - backArmDistance - 8) + Math.Cos((double)(frontArmRotation + 1.57079637f)) * -68.0); Utility.drawLineWithScreenCoordinates((int)(position.X + 52f - (float)backArmDistance), (int)(position.Y - (float)(Game1.tileSize / 2) - 4f), (int)(position.X + 32f + (float)(slingshotAttachX / 2)), (int)(position.Y - (float)(Game1.tileSize / 2) - 12f + (float)(slingshotAttachY / 2)), b, Color.White, 1f); return; } case 2: b.Draw(this.baseTexture, position + new Vector2(4f, (float)(-(float)Game1.tileSize / 2 - backArmDistance / 2)), new Rectangle?(new Rectangle(148, 244, 4, 4)), Color.White, 0f, Vector2.Zero, (float)Game1.pixelZoom * scale, SpriteEffects.None, layerDepth + ((facingDirection != 0) ? 5.9E-05f : 0f)); Utility.drawLineWithScreenCoordinates((int)(position.X + 16f), (int)(position.Y - 28f - (float)(backArmDistance / 2)), (int)(position.X + 44f - frontArmRotation * 10f), (int)(position.Y - (float)(Game1.tileSize / 4) - 8f), b, Color.White, 1f); Utility.drawLineWithScreenCoordinates((int)(position.X + 16f), (int)(position.Y - 28f - (float)(backArmDistance / 2)), (int)(position.X + 56f - frontArmRotation * 10f), (int)(position.Y - (float)(Game1.tileSize / 4) - 8f), b, Color.White, 1f); b.Draw(this.baseTexture, position + new Vector2(44f - frontArmRotation * 10f, (float)(-(float)Game1.tileSize / 4)), new Rectangle?(new Rectangle(167, 235, 7, 9)), Color.White, 0f, new Vector2(3f, 5f), (float)Game1.pixelZoom * scale, SpriteEffects.None, layerDepth + ((facingDirection != 0) ? 5.9E-05f : 0f)); break; case 3: { b.Draw(this.baseTexture, position + new Vector2((float)(40 + backArmDistance), (float)(-(float)Game1.tileSize / 2)), new Rectangle?(new Rectangle(147, 237, 10, 4)), Color.White, 0f, new Vector2(9f, 4f), (float)Game1.pixelZoom * scale, SpriteEffects.FlipHorizontally, layerDepth + ((facingDirection != 0) ? 5.9E-05f : 0f)); b.Draw(this.baseTexture, position + new Vector2(24f, (float)(-(float)Game1.tileSize / 2 - 8)), new Rectangle?(new Rectangle(156, 244, 9, 10)), Color.White, frontArmRotation + 3.14159274f, new Vector2(8f, 3f), (float)Game1.pixelZoom * scale, SpriteEffects.FlipHorizontally, layerDepth + ((facingDirection != 0) ? 1E-08f : 0f)); int slingshotAttachX = (int)(Math.Cos((double)(frontArmRotation + 1.2566371f)) * (double)(20 + backArmDistance - 8) - Math.Sin((double)(frontArmRotation + 1.2566371f)) * -68.0); int slingshotAttachY = (int)(Math.Sin((double)(frontArmRotation + 1.2566371f)) * (double)(20 + backArmDistance - 8) + Math.Cos((double)(frontArmRotation + 1.2566371f)) * -68.0); Utility.drawLineWithScreenCoordinates((int)(position.X + 4f + (float)backArmDistance), (int)(position.Y - (float)(Game1.tileSize / 2) - 8f), (int)(position.X + 26f + (float)slingshotAttachX * 4f / 10f), (int)(position.Y - (float)(Game1.tileSize / 2) - 8f + (float)slingshotAttachY * 4f / 10f), b, Color.White, 1f); return; } default: return; } } }
/********* ** Internal Methods *********/ /// <summary>The post fix for the <see cref="FarmerRenderer.draw(SpriteBatch, FarmerSprite.AnimationFrame, int, Rectangle, Vector2, Vector2, float, int, Color, float, float, Farmer)"/> method.</summary> /// <param name="b">The sprite batch to draw the outerwear to.</param> /// <param name="animationFrame">The animation frame of the farmer.</param> /// <param name="currentFrame">The current frame of the farmer.</param> /// <param name="sourceRect">The source rectangle of the farmer.</param> /// <param name="position">The position of the farmer.</param> /// <param name="origin">The origin of the farmer.</param> /// <param name="layerDepth">The layer depth of the farmer.</param> /// <param name="facingDirection">The facing direction of the farmer.</param> /// <param name="overrideColor">The override colour of the farmer.</param> /// <param name="rotation">The rotation of the farmer.</param> /// <param name="scale">The scale of the farmer.</param> /// <param name="who">The farmer being drawn.</param> /// <param name="__instance">The current <see cref="FarmerRenderer"/> instance being patched.</param> /// <remarks>This is used to draw the outerwear on the farmer.</remarks> internal static void DrawPostFix(SpriteBatch b, FarmerSprite.AnimationFrame animationFrame, int currentFrame, Rectangle sourceRect, Vector2 position, Vector2 origin, float layerDepth, int facingDirection, Color overrideColor, float rotation, float scale, Farmer who, FarmerRenderer __instance) { // ensure farmer being drawn is wearing some outerwear var objectId = ModEntry.Instance.Api.GetEquippedOuterwearId(who); if (objectId == -1) { return; } // get the outerwear with the specified objectId var outerwearData = ModEntry.Instance.Api.GetOuterwearData(objectId); if (outerwearData == null) { return; } // retrieve private members var positionOffset = (Vector2)typeof(FarmerRenderer).GetField("positionOffset", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(__instance); var rotationAdjustment = (Vector2)typeof(FarmerRenderer).GetField("rotationAdjustment", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(__instance); // get outerwear type dependant values var drawPosition = Vector2.Zero; var drawSourceRectangle = sourceRect; var drawEffects = SpriteEffects.None; var drawLayerDepth = layerDepth; switch (outerwearData.Type) { case OuterwearType.Shirt: drawPosition = position + origin + positionOffset + new Vector2(16 * scale + FarmerRenderer.featureXOffsetPerFrame[currentFrame] * 4, 56 + FarmerRenderer.featureYOffsetPerFrame[currentFrame] * 4 + __instance.heightOffset * scale); drawSourceRectangle = SourceRectangles[OuterwearType.Shirt][facingDirection]; drawLayerDepth = layerDepth + 2.81E-07f; break; case OuterwearType.Accessory: drawPosition = position + origin + positionOffset + rotationAdjustment + new Vector2(FarmerRenderer.featureXOffsetPerFrame[currentFrame] * 4, 4 + FarmerRenderer.featureYOffsetPerFrame[currentFrame] * 4 + __instance.heightOffset); drawSourceRectangle = SourceRectangles[OuterwearType.Accessory][facingDirection]; drawEffects = IsFlipped[OuterwearType.Accessory][facingDirection] ? SpriteEffects.FlipHorizontally : SpriteEffects.None; drawLayerDepth = layerDepth + 2.9E-05f; break; case OuterwearType.Hair: drawPosition = position + origin + positionOffset + new Vector2(FarmerRenderer.featureXOffsetPerFrame[currentFrame] * 4, FarmerRenderer.featureYOffsetPerFrame[currentFrame] * 4 + (facingDirection != 0 ? 4 : 0) + (who.IsMale ? -4 : 0)); drawSourceRectangle = SourceRectangles[OuterwearType.Hair][facingDirection]; drawEffects = IsFlipped[OuterwearType.Hair][facingDirection] ? SpriteEffects.FlipHorizontally : SpriteEffects.None; drawLayerDepth = layerDepth + 2.21E-05f; break; case OuterwearType.Hat: drawPosition = position + origin + positionOffset + new Vector2(-8 + (who.FarmerSprite.CurrentAnimationFrame.flip ? -1 : 1) * FarmerRenderer.featureXOffsetPerFrame[currentFrame] * 4, -16 + FarmerRenderer.featureYOffsetPerFrame[currentFrame] * 4 + 4 + __instance.heightOffset); drawSourceRectangle = SourceRectangles[OuterwearType.Hat][facingDirection]; drawLayerDepth = layerDepth + 3.91E-05f; break; case OuterwearType.Pants: drawPosition = position + origin + positionOffset; drawSourceRectangle = sourceRect; drawEffects = animationFrame.flip ? SpriteEffects.FlipHorizontally : SpriteEffects.None; drawLayerDepth = layerDepth + (who.FarmerSprite.CurrentAnimationFrame.frame == 5 ? 9.9E-04f : 9.9E-08f); break; } // draw outerwear b.Draw( texture: outerwearData.EquippedTexture, position: drawPosition, sourceRectangle: drawSourceRectangle, color: Color.White, rotation: rotation, origin: origin, scale: scale * 4, effects: drawEffects, layerDepth: drawLayerDepth ); }
public static void draw_Postfix(ref FarmerRenderer __instance, SpriteBatch b, FarmerSprite.AnimationFrame animationFrame, int currentFrame, Rectangle sourceRect, Vector2 position, Vector2 origin, float layerDepth, int facingDirection, Color overrideColor, float rotation, float scale, Farmer who, Texture2D ___baseTexture, Vector2 ___positionOffset, ref PanHat __state) { // Draw our updated graphics over the original based on the upgrade level. if (who.UsingTool && who.CurrentTool is Pan pan) { switch (pan.UpgradeLevel) { case 2: sourceRect.Offset(48, 0); break; case 3: sourceRect.Offset(96, 0); break; case 4: sourceRect.Offset(-48, 0); break; default: return; } b.Draw(___baseTexture, position + origin + ___positionOffset + who.armOffset, sourceRect, overrideColor, rotation, origin, 4f * scale, animationFrame.flip ? SpriteEffects.FlipHorizontally : SpriteEffects.None, layerDepth + 5.0E-05f); } // Draw updated hat graphics over the original. if (__state != null) { bool flip = who.FarmerSprite.CurrentAnimationFrame.flip; float layer_offset2 = 4.0E-05f; Rectangle hatSourceRect = new Rectangle(20 * (__state.UpgradeLevel - 2), 20 * (__state.UpgradeLevel - 2) / PanHat.panHatTexture.Width * 20 * 4, 20, 20); b.Draw(PanHat.panHatTexture, position + origin + ___positionOffset + new Vector2(-8 + ((!flip) ? 1 : (-1)) * FarmerRenderer.featureXOffsetPerFrame[currentFrame] * 4, -16 + FarmerRenderer.featureYOffsetPerFrame[currentFrame] * 4 + ((!__state.ignoreHairstyleOffset) ? FarmerRenderer.hairstyleHatOffset[(int)who.hair % 16] : 0) + 4 + __instance.heightOffset.Value), hatSourceRect, __state.isPrismatic ? Utility.GetPrismaticColor() : Color.White, rotation, origin, 4f * scale, SpriteEffects.None, layerDepth + layer_offset2); //who.hat.Set(__state); } }
public static void draw_Postfix(ref FarmerRenderer __instance, SpriteBatch b, FarmerSprite.AnimationFrame animationFrame, int currentFrame, Rectangle sourceRect, Vector2 position, Vector2 origin, float layerDepth, int facingDirection, Color overrideColor, float rotation, float scale, Farmer who, Texture2D ___baseTexture, Vector2 ___positionOffset) { try { if (ModEntry.drawUmbrella) { if (ModEntry.isMaleFarmer) { if (Game1.player.FarmerSprite.currentFrame == 12) { //standing back b.Draw(ModEntry.umbrellaOverlayTextureBack, position + origin + ___positionOffset + who.armOffset + new Vector2(0, -4 * scale), new Rectangle(0, 0, 16, 16), overrideColor, rotation, origin, 4f * scale, animationFrame.flip ? SpriteEffects.FlipHorizontally : SpriteEffects.None, layerDepth + 5.0E-05f); } else if (Game1.player.FarmerSprite.currentFrame == 13 || Game1.player.FarmerSprite.currentFrame == 14 || Game1.player.FarmerSprite.currentFrame == 22 || Game1.player.FarmerSprite.currentFrame == 23) { //moving back b.Draw(ModEntry.umbrellaOverlayTextureBack, position + origin + ___positionOffset + who.armOffset, new Rectangle(0, 0, 16, 16), overrideColor, rotation, origin, 4f * scale, animationFrame.flip ? SpriteEffects.FlipHorizontally : SpriteEffects.None, layerDepth + 5.0E-05f); } else if (Game1.player.FarmerSprite.currentFrame == 113) { //sitting back b.Draw(ModEntry.umbrellaOverlayTextureBack, position + origin + ___positionOffset + who.armOffset + new Vector2(0, -20 * scale), new Rectangle(0, 0, 16, 16), overrideColor, rotation, origin, 4f * scale, animationFrame.flip ? SpriteEffects.FlipHorizontally : SpriteEffects.None, layerDepth + 5.0E-05f); } else if (Game1.player.FarmerSprite.currentFrame == 117) { //sitting side b.Draw(ModEntry.umbrellaOverlayTextureSide, position + origin + ___positionOffset + who.armOffset + new Vector2(0, -20 * scale), new Rectangle(0, 0, 16, 16), overrideColor, rotation, origin, 4f * scale, animationFrame.flip ? SpriteEffects.FlipHorizontally : SpriteEffects.None, layerDepth + 5.0E-05f); } else if (Game1.player.FarmerSprite.currentFrame == 107) { //sitting front b.Draw(ModEntry.umbrellaOverlayTextureBack, position + origin + ___positionOffset + who.armOffset + new Vector2(0, -24 * scale), new Rectangle(0, 0, 16, 16), overrideColor, rotation, origin, 4f * scale, animationFrame.flip ? SpriteEffects.FlipHorizontally : SpriteEffects.None, layerDepth + 5.0E-05f); } } else { if (Game1.player.FarmerSprite.currentFrame == 12) { //standing back b.Draw(ModEntry.umbrellaOverlayTextureBack, position + origin + ___positionOffset + who.armOffset, new Rectangle(0, 0, 16, 16), overrideColor, rotation, origin, 4f * scale, animationFrame.flip ? SpriteEffects.FlipHorizontally : SpriteEffects.None, layerDepth + 5.0E-05f); } else if (Game1.player.FarmerSprite.currentFrame == 13 || Game1.player.FarmerSprite.currentFrame == 14 || Game1.player.FarmerSprite.currentFrame == 22 || Game1.player.FarmerSprite.currentFrame == 23) { //moving back b.Draw(ModEntry.umbrellaOverlayTextureBack, position + origin + ___positionOffset + who.armOffset + new Vector2(0, 4 * scale), new Rectangle(0, 0, 16, 16), overrideColor, rotation, origin, 4f * scale, animationFrame.flip ? SpriteEffects.FlipHorizontally : SpriteEffects.None, layerDepth + 5.0E-05f); } else if (Game1.player.FarmerSprite.currentFrame == 113) { //sitting back b.Draw(ModEntry.umbrellaOverlayTextureBack, position + origin + ___positionOffset + who.armOffset + new Vector2(0, -16 * scale), new Rectangle(0, 0, 16, 16), overrideColor, rotation, origin, 4f * scale, animationFrame.flip ? SpriteEffects.FlipHorizontally : SpriteEffects.None, layerDepth + 5.0E-05f); } else if (Game1.player.FarmerSprite.currentFrame == 117) { //sitting side b.Draw(ModEntry.umbrellaOverlayTextureSide, position + origin + ___positionOffset + who.armOffset + new Vector2(0, -16 * scale), new Rectangle(0, 0, 16, 16), overrideColor, rotation, origin, 4f * scale, animationFrame.flip ? SpriteEffects.FlipHorizontally : SpriteEffects.None, layerDepth + 5.0E-05f); } else if (Game1.player.FarmerSprite.currentFrame == 107) { //sitting front b.Draw(ModEntry.umbrellaOverlayTextureBack, position + origin + ___positionOffset + who.armOffset + new Vector2(0, -20 * scale), new Rectangle(0, 0, 16, 16), overrideColor, rotation, origin, 4f * scale, animationFrame.flip ? SpriteEffects.FlipHorizontally : SpriteEffects.None, layerDepth + 5.0E-05f); } } } } catch (Exception ex) { Monitor.Log($"Failed in {nameof(draw_Postfix)}:\n{ex}", LogLevel.Error); } }
private static void drawFarmer(SpriteBatch b, int currentFrame, Rectangle sourceRect, Vector2 position, Color overrideColor) { var animationFrame = new FarmerSprite.AnimationFrame(Game1.player.bathingClothes.Value ? 108 : currentFrame, 0, false, false, null, false); var who = Game1.player; float layerDepth = 0.8f; float scale = 4f; AccessTools.Method(typeof(FarmerRenderer), "executeRecolorActions").Invoke(Game1.player.FarmerRenderer, new object[] { who }); position = new Vector2((float)Math.Floor(position.X), (float)Math.Floor(position.Y)); var positionOffset = new Vector2(animationFrame.positionOffset * 4, animationFrame.positionOffset * 4); var baseTexture = AccessTools.FieldRefAccess <FarmerRenderer, Texture2D>(Game1.player.FarmerRenderer, "baseTexture"); // body b.Draw(baseTexture, position + positionOffset, new Rectangle?(sourceRect), overrideColor, 0, Vector2.Zero, 16, SpriteEffects.None, 0.8f); // eyes sourceRect.Offset(288, 0); if (who.currentEyes != 0 && (Game1.timeOfDay < 2600 || (who.isInBed.Value && who.timeWentToBed.Value != 0)) && ((!who.FarmerSprite.PauseForSingleAnimation && !who.UsingTool) || (who.UsingTool && who.CurrentTool is FishingRod))) { if (!who.UsingTool || who.CurrentTool is not FishingRod || (who.CurrentTool as FishingRod).isFishing) { int x_adjustment = 5 - FarmerRenderer.featureXOffsetPerFrame[currentFrame]; if (!Config.FacingFront) { x_adjustment += 3; } x_adjustment *= 4; b.Draw(baseTexture, position + positionOffset + new Vector2(x_adjustment, FarmerRenderer.featureYOffsetPerFrame[currentFrame] * 4 + ((who.IsMale && !Config.FacingFront) ? 36 : 40)) * scale, new Rectangle?(new Rectangle(5, 16, Config.FacingFront ? 6 : 2, 2)), overrideColor, 0f, Vector2.Zero, 16, SpriteEffects.None, 0.8f + 5E-08f); b.Draw(baseTexture, position + positionOffset + new Vector2(x_adjustment, FarmerRenderer.featureYOffsetPerFrame[currentFrame] * 4 + (!Config.FacingFront ? 40 : 44)) * scale, new Rectangle?(new Rectangle(264 + 0, 2 + (who.currentEyes - 1) * 2, Config.FacingFront ? 6 : 2, 2)), overrideColor, 0f, Vector2.Zero, 16, SpriteEffects.None, 0.8f + 1.2E-07f); } } // hair and accessories int hair_style = who.getHair(false); HairStyleMetadata hair_metadata = Farmer.GetHairStyleMetadata(who.hair.Value); if (who != null && who.hat.Value != null && who.hat.Value.hairDrawType.Value == 1 && hair_metadata != null && hair_metadata.coveredIndex != -1) { hair_style = hair_metadata.coveredIndex; hair_metadata = Farmer.GetHairStyleMetadata(hair_style); } AccessTools.Method(typeof(FarmerRenderer), "executeRecolorActions").Invoke(Game1.player.FarmerRenderer, new object[] { who }); int hatCutoff = 4; int shirtCutoff = 4; var shirtSourceRect = new Rectangle(Game1.player.FarmerRenderer.ClampShirt(who.GetShirtIndex()) * 8 % 128, Game1.player.FarmerRenderer.ClampShirt(who.GetShirtIndex()) * 8 / 128 * 32, 8, 8 - shirtCutoff); Texture2D hair_texture = FarmerRenderer.hairStylesTexture; var hairstyleSourceRect = new Rectangle(hair_style * 16 % FarmerRenderer.hairStylesTexture.Width, hair_style * 16 / FarmerRenderer.hairStylesTexture.Width * 96, 16, 32); Rectangle hatSourceRect = who.hat.Value != null ? new Rectangle(20 * who.hat.Value.which.Value % FarmerRenderer.hatsTexture.Width, 20 * who.hat.Value.which.Value / FarmerRenderer.hatsTexture.Width * 20 * 4 + hatCutoff, 20, 20 - hatCutoff) : new Rectangle(); var accessorySourceRect = who.accessory.Value >= 0 ? new Rectangle(who.accessory.Value * 16 % FarmerRenderer.accessoriesTexture.Width, who.accessory.Value * 16 / FarmerRenderer.accessoriesTexture.Width * 32, 16, 16) : new Rectangle(); if (hair_metadata != null) { hair_texture = hair_metadata.texture; hairstyleSourceRect = new Rectangle(hair_metadata.tileX * 16, hair_metadata.tileY * 16, 16, 32); } Rectangle dyed_shirt_source_rect = shirtSourceRect; float dye_layer_offset = 1E-07f; float hair_draw_layer = 2.2E-05f; var heightOffset = 0; if (Config.FacingFront) { dyed_shirt_source_rect = shirtSourceRect; dyed_shirt_source_rect.Offset(128, 0); // shirt if (!who.bathingClothes.Value) { b.Draw(FarmerRenderer.shirtsTexture, position + positionOffset + new Vector2(16 + FarmerRenderer.featureXOffsetPerFrame[currentFrame] * 4, 56 + FarmerRenderer.featureYOffsetPerFrame[currentFrame] * 4 + (float)heightOffset * 4 - (who.IsMale ? 0 : 0)) * scale, new Rectangle?(shirtSourceRect), overrideColor.Equals(Color.White) ? Color.White : overrideColor, 0, Vector2.Zero, 16, SpriteEffects.None, 0.8f + 1.5E-07f); b.Draw(FarmerRenderer.shirtsTexture, position + positionOffset + new Vector2(16 + FarmerRenderer.featureXOffsetPerFrame[currentFrame] * 4, 56 + FarmerRenderer.featureYOffsetPerFrame[currentFrame] * 4 + (float)heightOffset * 4 - (who.IsMale ? 0 : 0)), new Rectangle?(dyed_shirt_source_rect), overrideColor.Equals(Color.White) ? Utility.MakeCompletelyOpaque(who.GetShirtColor()) : overrideColor, 0, Vector2.Zero, 16, SpriteEffects.None, 0.8f + 1.5E-07f + dye_layer_offset); } // accessory if (who.accessory.Value >= 0) { b.Draw(FarmerRenderer.accessoriesTexture, position + positionOffset + new Vector2(FarmerRenderer.featureXOffsetPerFrame[currentFrame] * 4, 8 + FarmerRenderer.featureYOffsetPerFrame[currentFrame] * 4 + heightOffset - 4), new Rectangle?(accessorySourceRect), (overrideColor.Equals(Color.White) && who.accessory.Value < 6) ? who.hairstyleColor.Value : overrideColor, 0, Vector2.Zero, 16, SpriteEffects.None, 0.8f + ((who.accessory.Value < 8) ? 1.9E-05f : 2.9E-05f)); } // hair b.Draw(hair_texture, position + positionOffset + new Vector2(FarmerRenderer.featureXOffsetPerFrame[currentFrame] * 4, FarmerRenderer.featureYOffsetPerFrame[currentFrame] * 4 + ((who.IsMale && who.hair.Value >= 16) ? -4 : ((!who.IsMale && who.hair.Value < 16) ? 4 : 0))) * scale, new Rectangle?(hairstyleSourceRect), overrideColor.Equals(Color.White) ? who.hairstyleColor.Value : overrideColor, 0, Vector2.Zero, 16, SpriteEffects.None, 0.8f + hair_draw_layer); } else { shirtSourceRect.Offset(0, 8); hairstyleSourceRect.Offset(0, 32); dyed_shirt_source_rect = shirtSourceRect; dyed_shirt_source_rect.Offset(128, 0); if (who.accessory.Value >= 0) { accessorySourceRect.Offset(0, 16); } if (who.hat.Value != null) { hatSourceRect.Offset(0, 20); } // shirt if (!who.bathingClothes.Value) { b.Draw(FarmerRenderer.shirtsTexture, position + positionOffset + new Vector2(16f + FarmerRenderer.featureXOffsetPerFrame[currentFrame] * 4, 56f + FarmerRenderer.featureYOffsetPerFrame[currentFrame] * 4 + heightOffset) * scale, new Rectangle?(shirtSourceRect), overrideColor.Equals(Color.White) ? Color.White : overrideColor, 0, Vector2.Zero, 4f * scale, SpriteEffects.None, layerDepth + 1.8E-07f); b.Draw(FarmerRenderer.shirtsTexture, position + positionOffset + new Vector2(16f + FarmerRenderer.featureXOffsetPerFrame[currentFrame] * 4, 56f + FarmerRenderer.featureYOffsetPerFrame[currentFrame] * 4 + heightOffset) * scale, new Rectangle?(dyed_shirt_source_rect), overrideColor.Equals(Color.White) ? Utility.MakeCompletelyOpaque(who.GetShirtColor()) : overrideColor, 0, Vector2.Zero, 4f * scale, SpriteEffects.None, layerDepth + 1.8E-07f + dye_layer_offset); } // accessory if (who.accessory.Value >= 0) { b.Draw(FarmerRenderer.accessoriesTexture, position + positionOffset + new Vector2(FarmerRenderer.featureXOffsetPerFrame[currentFrame] * 4, 4 + FarmerRenderer.featureYOffsetPerFrame[currentFrame] * 4 + heightOffset) * scale, new Rectangle?(accessorySourceRect), (overrideColor.Equals(Color.White) && who.accessory.Value < 6) ? who.hairstyleColor.Value : overrideColor, 0, Vector2.Zero, 4f * scale, SpriteEffects.None, layerDepth + ((who.accessory.Value < 8) ? 1.9E-05f : 2.9E-05f)); } // hair b.Draw(hair_texture, position + positionOffset + new Vector2(FarmerRenderer.featureXOffsetPerFrame[currentFrame] * 4, FarmerRenderer.featureYOffsetPerFrame[currentFrame] * 4 + ((who.IsMale && who.hair.Value >= 16) ? -4 : ((!who.IsMale && who.hair.Value < 16) ? 4 : 0))) * scale, new Rectangle?(hairstyleSourceRect), overrideColor.Equals(Color.White) ? who.hairstyleColor.Value : overrideColor, 0, Vector2.Zero, 16, SpriteEffects.None, layerDepth + hair_draw_layer); } // hat if (who.hat.Value != null && !who.bathingClothes.Value) { float layer_offset = 3.9E-05f; b.Draw(FarmerRenderer.hatsTexture, position + positionOffset * scale + new Vector2(-9 * FarmerRenderer.featureXOffsetPerFrame[currentFrame] * 4 - 8, -16 + FarmerRenderer.featureYOffsetPerFrame[currentFrame] * 4 + (who.hat.Value.ignoreHairstyleOffset.Value ? 0 : FarmerRenderer.hairstyleHatOffset[who.hair.Value % 16]) + 8 + heightOffset + 4 * hatCutoff) * scale, new Rectangle?(hatSourceRect), who.hat.Value.isPrismatic.Value ? Utility.GetPrismaticColor(0, 1f) : Color.White, 0, Vector2.Zero, 16, SpriteEffects.None, 0.8f + layer_offset); } float arm_layer_offset = 4.9E-05f; sourceRect.Offset(-288 + (animationFrame.secondaryArm ? 192 : 96), 0); b.Draw(baseTexture, position + positionOffset + who.armOffset, new Rectangle?(sourceRect), overrideColor, 0, Vector2.Zero, 4f * scale, SpriteEffects.None, layerDepth + arm_layer_offset); }
public AnimationFrameWrapper(FarmerSprite.AnimationFrame animationFrame) => GetBasType = animationFrame;