public void import(Farm f) { characters.Set(f.characters); Traverse.Create(this).Field("objects").SetValue(f.objects); temporarySprites = f.temporarySprites; Traverse.Create(this).Field("farmers").SetValue(f.farmers); projectiles.Set(f.projectiles); //terrainFeatures.Set(f.terrainFeatures); Traverse.Create(this).Field("terrainFeatures").SetValue(f.terrainFeatures); debris.Set(f.debris); buildings.Set(f.buildings); //animals.Set(f.animals); Traverse.Create(this).Field("animals").SetValue(f.animals); resourceClumps.Set(f.resourceClumps); piecesOfHay = f.piecesOfHay; grandpaScore = f.grandpaScore; hasSeenGrandpaNote = f.hasSeenGrandpaNote; foreach (var c in characters) { c.currentLocation = this; } foreach (var p in farmers) { p.currentLocation = this; } foreach (var c in f.characters) { c.currentLocation = f; } foreach (var p in f.farmers) { p.currentLocation = f; } }
protected override void ReadDelta(BinaryReader reader, NetVersion version) { sourceRect = new NetRectangle(); if (sourceRect == null) { throw new Exception("WTF??? Why is netfield null"); } if (reader == null) { throw new Exception("reader null"); } if (value == null) { this.Set(new Animation()); } sourceRect.Read(reader, version); Value.sourceRectangle = sourceRect.Value; frameDuration = new NetInt(); frameDuration.Read(reader, version); Value.frameDuration = frameDuration.Value; frameDurationUntilNextAnimation = new NetInt(); frameDurationUntilNextAnimation.Read(reader, version); Value.frameCountUntilNextAnimation = frameDurationUntilNextAnimation.Value; }
public void netShoot(int damage) { NetInt shootUpdate = new NetInt(); shootUpdate.value = damage; nm.nc.Send(903, shootUpdate); }
public override ITrackedStack GetOutput() { FarmAnimal animal = this.UnprocessedAnimals.FirstOrDefault(); if (animal == null) { return(null); } this.UnprocessedAnimals.RemoveAt(0); Tool tool = new Shears(); if (animal.toolUsedForHarvest == "Milk Pail") { tool = new MilkPail(); } var produce = new SObject(animal.currentProduce, 1, false, -1, animal.produceQuality); FieldInfo info = typeof(FarmAnimal).GetField("currentProduce", BindingFlags.Instance | BindingFlags.Public); NetInt netint = new NetInt(-1); info.SetValue(animal, netint); this.produceCount += 1; return(new TrackedItem(produce)); }
/// <summary> /// Performs the tree fall. /// </summary> /// <returns><c>true</c>, if tree fall was performed, <c>false</c> otherwise.</returns> /// <param name="t">Tool used</param> /// <param name="explosion">Explosion. (Not used)</param> /// <param name="tileLocation">Tile location.</param> /// <param name="location">Location.</param> public static bool performTreeFall(Tool t, int explosion, Vector2 tileLocation, GameLocation location) { ModMonitor.Log($"performTreeFall called with: t: {t} explosion: {explosion} tileLocation: {tileLocation} location: {location}", LogLevel.Trace); NetFloat health = tree.health; NetBool stump = tree.stump; NetInt treeType = tree.treeType; NetBool shakeLeft = tree.shakeLeft; NetLong lastPlayerToHit = ModHelper.Reflection.GetField <NetLong>(tree, "lastPlayerToHit").GetValue(); NetBool falling = ModHelper.Reflection.GetField <NetBool>(tree, "falling").GetValue(); string key = GetKeyForObject(treeType); //Code for calculation of tree fall position: (int)tileLocation.X + (((bool)shakeLeft) ? (-4) : 4) if ((bool)stump) { if (Config.TreeDrops[key].StumpDrops != null) { for (int i = 0; i < Config.TreeDrops[key].StumpDrops.Length / 2; i++) { if (Game1.IsMultiplayer) { Game1.createMultipleObjectDebris(Config.TreeDrops[key].StumpDrops[i, 0], (int)tileLocation.X, (int)tileLocation.Y, Config.TreeDrops[key].StumpDrops[i, 1], lastPlayerToHit, location); } else { Game1.createMultipleObjectDebris(Config.TreeDrops[key].StumpDrops[i, 0], (int)tileLocation.X, (int)tileLocation.Y, Config.TreeDrops[key].StumpDrops[i, 1], location); } } } } return(false); }
private static bool CheckCanBeGiant(NetInt cropRow_) { int cropRow = cropRow_.Value; var cropData = Mod.instance.Crops.FirstOrDefault(c => c.GetCropSpriteIndex() == cropRow); return(cropData?.GiantTexture != null); }
protected override void WriteDelta(BinaryWriter writer) { texture = new NetTexture2DExtended(Value.getExtendedTexture()); texture.Write(writer); which = new NetInt(Value.ParentSheetIndex); which.Write(writer); tilePos = new NetVector2(Value.TileLocation); tilePos.Write(writer); InventoryMaxSize = new NetInt(Value.inventoryMaxSize); InventoryMaxSize.Write(writer); sourceRect = new NetRectangle(Value.sourceRect); sourceRect.Write(writer); boundingBox = new NetRectangle(Value.boundingBox.Value); sourceRect.Write(writer); drawPosition = new NetVector2(Value.drawPosition); drawPosition.Write(writer); locationName = new NetString(Value.locationsName); locationName.Write(writer); /* * if (Value.animationManager == null) * { * throw new Exception("WTF, why is the animation manager null???????????"); * } * animationManager = new NetAnimationManager(Value.animationManager); * animationManager.Write(writer); */ }
void OnPlayerJump(NetworkMessage netMsg) { NetInt id = new NetInt(); id.value = netMsg.conn.connectionId; sendToAllExcept(netMsg.conn.connectionId, 918, id); }
private static bool DrawAtNonTileSpotPrefix(Furniture __instance, NetInt ___sourceIndexOffset, SpriteBatch spriteBatch, Vector2 location, float layerDepth, float alpha = 1f) { if (__instance.modData.ContainsKey("AlternativeTextureName")) { var textureModel = AlternativeTextures.textureManager.GetSpecificTextureModel(__instance.modData["AlternativeTextureName"]); if (textureModel is null) { return(true); } var textureVariation = Int32.Parse(__instance.modData["AlternativeTextureVariation"]); if (textureVariation == -1 || AlternativeTextures.modConfig.IsTextureVariationDisabled(textureModel.GetId(), textureVariation)) { return(true); } var textureOffset = textureModel.GetTextureOffset(textureVariation); // Replicate the base draw Rectangle sourceRect = __instance.sourceRect.Value; sourceRect.X -= __instance.defaultSourceRect.X; sourceRect.Y = textureOffset; spriteBatch.Draw(textureModel.GetTexture(textureVariation), location, sourceRect, Color.White * alpha, 0f, Vector2.Zero, 4f, __instance.flipped ? SpriteEffects.FlipHorizontally : SpriteEffects.None, layerDepth); return(false); } return(true); }
public static bool Prefix(WorldChangeEvent __instance, ref bool __result) { NetInt evt = (NetInt)Traverse.Create(__instance).Field("whichEvent").GetValue(); if (Memory.isCustomFarmLoaded && evt.Value == 1) { Game1.currentLightSources.Clear(); Traverse.Create(__instance).Field("location").SetValue(null); int targetXTile = 64; int targetYTile = 116; //__instance.cutsceneLengthTimer = 8000; Traverse.Create(__instance).Field("cutsceneLengthTimer").SetValue(8000); //__instance.wasRaining = Game1.isRaining; Traverse.Create(__instance).Field("wasRaining").SetValue(Game1.isRaining); Game1.isRaining = false; GameLocation loc = (GameLocation)Traverse.Create(__instance).Field("location").GetValue(); loc = Game1.getLocationFromName("Farm"); loc.resetForPlayerEntry(); Utility.addSprinklesToLocation(loc, targetXTile, 12, 7, 7, 15000, 150, Color.LightCyan, null, false); Utility.addStarsAndSpirals(loc, targetXTile, 12, 7, 7, 15000, 150, Color.White, null, false); Game1.player.activeDialogueEvents.Add("cc_Greenhouse", 3); //__instance.sound = "junimoMeep1"; Traverse.Create(__instance).Field("sound").SetValue("junimoMeep1"); Game1.currentLightSources.Add(new LightSource(4, new Vector2((float)targetXTile, (float)targetYTile) * 64f, 4f, Color.DarkGoldenrod)); loc.temporarySprites.Add(new TemporaryAnimatedSprite("LooseSprites\\Cursors", new Rectangle(294, 1432, 16, 16), 300f, 4, 999, new Vector2(1792f, 704f), false, false) { scale = 4f, layerDepth = 1f, xPeriodic = true, xPeriodicLoopTime = 2000f, xPeriodicRange = 16f, light = true, lightcolor = Color.DarkGoldenrod, lightRadius = 1f }); //this.soundInterval = 800; Traverse.Create(__instance).Field("soundInterval").SetValue(800); //this.soundTimer = this.soundInterval; Traverse.Create(__instance).Field("soundTimer").SetValue(800); Traverse.Create(__instance).Field("location").SetValue(loc); Game1.currentLocation = loc; Game1.fadeClear(); Game1.nonWarpFade = true; Game1.timeOfDay = 2400; Game1.displayHUD = false; Game1.viewportFreeze = true; Game1.player.position.X = -999999f; Game1.viewport.X = Math.Max(0, Math.Min(loc.map.DisplayWidth - Game1.viewport.Width, targetXTile * 64 - Game1.viewport.Width / 2)); Game1.viewport.Y = Math.Max(0, Math.Min(loc.map.DisplayHeight - Game1.viewport.Height, targetYTile * 64 - Game1.viewport.Height / 2)); Game1.changeMusicTrack("nightTime"); __result = false; return(false); } //bypass = false; return(true); }
public void Header(int chunkSize, int strongLength) { NetInt.Write(stream, Const.RS_SIG_MAGIC); NetInt.Write(stream, chunkSize); NetInt.Write(stream, strongLength); this.strongLength = strongLength; }
protected override void AnimateDoorStateChange() { // Need to use reflection to animate the door changing state because it is private var prop = StardewCoop.GetType().GetField("animalDoorMotion", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance); NetInt animalDoorMotion = prop.GetValue(StardewCoop) as NetInt; animalDoorMotion.Value = StardewCoop.animalDoorOpen.Value ? (-2) : 2; }
protected override void WriteDelta(BinaryWriter writer) { sourceRect = new NetRectangle(Value.sourceRectangle); sourceRect.Write(writer); frameDuration = new NetInt(Value.frameDuration); frameDuration.Write(writer); frameDurationUntilNextAnimation = new NetInt(Value.frameCountUntilNextAnimation); frameDurationUntilNextAnimation.Write(writer); }
public static bool CheckCanBeGiant(NetInt cropRow_) { int cropRow = cropRow_.Value; var cropData = Mod.instance.crops.FirstOrDefault(c => c.GetCropSpriteIndex() == cropRow); if (cropData == null) { return(false); } return(cropData.giantTex != null); }
protected override void WriteDelta(BinaryWriter writer) { if (String.IsNullOrEmpty(Value.currentAnimationName)) { NetBool isNull = new NetBool(true); writer.Write(isNull); NetTexture2DExtended defaultTexture = new NetTexture2DExtended(Value.getExtendedTexture()); defaultTexture.Write(writer); //do read/write null values here!!! if (Value == null) { throw new Exception("DONT WRITE A NULL VALUE!!!!"); } NetAnimation drawFrame = new NetAnimation(Value.defaultDrawFrame); drawFrame.Write(writer); return; //throw new Exception("Null string value for currentAnimationName!"); } else { NetBool isNull = new NetBool(false); writer.Write(isNull); } NetString curentAnimationName = new NetString(!String.IsNullOrEmpty(Value.currentAnimationName) ? Value.currentAnimationName : ""); currentAnimationName.Write(writer); NetInt currentAnimationListIndex = new NetInt(Value.currentAnimationListIndex); currentAnimationListIndex.Write(writer); NetTexture2DExtended texture = new NetTexture2DExtended(Value.getExtendedTexture()); texture.Write(writer); //do read/write null values here!!! NetAnimation defaultDrawFrame = new NetAnimation(Value.defaultDrawFrame); defaultDrawFrame.Write(writer); NetBool enabled = new NetBool(Value.enabled); enabled.Write(writer); NetString animationData = new NetString(Value.animationDataString); animationData.Write(writer); }
void OnPlayerShoot(NetworkMessage netMsg) { NetInt shootUpdate = netMsg.ReadMessage <NetInt>(); PlayerShoot playerShoot = new PlayerShoot(); playerShoot.id = netMsg.conn.connectionId; playerShoot.damage = shootUpdate.value; sendToAllExcept(netMsg.conn.connectionId, 913, playerShoot); /*foreach(User u in ConnectedUsers.FindAll(x => x.id != netMsg.conn.connectionId)){ * NetworkServer.SendToClient(u.id,913,playerShoot); * }*/ }
internal static void saveCurrentAppearance() { shirt = Game1.player.GetShirtIndex(); shirtItem = Game1.player.shirtItem.Get(); pants = Game1.player.GetPantsIndex(); pantsItem = Game1.player.pantsItem.Get(); pantsColour = Game1.player.GetPantsColor(); hair = Game1.player.getHair(); accessory = Game1.player.accessory.Get(); hairColour = Game1.player.hairstyleColor.Get(); eyeColour = helper.Reflection.GetField <NetColor>(Game1.player.FarmerRenderer, "eyes").GetValue().Get(); skinColour = Game1.player.skin; isMale = Game1.player.IsMale; }
void OnDisconnect(NetworkMessage netMsg) { ConnectedUsers.RemoveAll(x => x.id == netMsg.conn.connectionId); NetInt userDisconnect = new NetInt(); userDisconnect.value = netMsg.conn.connectionId; sendToAllExcept(netMsg.conn.connectionId, 810, userDisconnect); /*if(ConnectedUsers.Count==0){ * timeLeft=config.timeLimit; * }*/ /*foreach(User u in ConnectedUsers.FindAll(x => x.id != netMsg.conn.connectionId)){ * NetworkServer.SendToClient(u.id,810,userDisconnect); * }*/ }
public void Dead(int id) { NetInt dead = new NetInt(); dead.value = id; nm.nc.Send(904, dead); UI.transform.localScale = new Vector3(0, 0, 0); respawnTimer.Start(nm.getConfiguration().respawnTime, "Sei stato eliminato da " + players[id].gameObject.transform.Find("username").GetComponent <TextMesh>().text); enemy e = players[id].GetComponent <enemy>(); e.addKill(); if (e.getKills() > maxPoints) { setRecordHolder(id, e.getKills()); } }
private void OnDayEnding(object sender, SaveLoadedEventArgs e /*DayEndingEventArgs e*/) { /* * var loc = Game1.getFarm().buildings; * if (loc == null) * return;*/ foreach (Building b2 in Game1.getFarm().buildings.Where(b => b.buildingType.Value.Contains("Coop"))) { if (b2 is Coop coop) { Monitor.Log($"Found a {coop.nameOfIndoors}"); coop.animalDoorOpen.Value = true; NetInt h = Helper.Reflection.GetField <NetInt>(coop, "yPositionOfAnimalDoor").GetValue(); Monitor.Log($"yPositionOfAnimalDoor: {h.ToString()}"); NetInt h1 = Helper.Reflection.GetField <NetInt>(coop, "yPositionOfAnimalDoor").GetValue(); h1.Value = -52; Monitor.Log($"yPositionOfAnimalDoor: {h1.Value.ToString()}"); } else { Monitor.Log("Couldn't find a coop."); } } /* * IEnumerator<Building> enumerator = Game1.getFarm().buildings.GetEnumerator(); * try * { * while (enumerator.MoveNext()) * { * Building b = enumerator.Current; * AnimalHouse bb = b?.indoors.Value as AnimalHouse; * if (b is Coop coop) * { * coop.animalDoorOpen.Value = true; * int h = Helper.Reflection.GetField<int>(coop, "yPositionOfAnimalDoor").GetValue(); * Monitor.Log($"yPositionOfAnimalDoor: {h.ToString()}"); * } * } * } * finally * { * enumerator.Dispose(); * }*/ }
private static string GetQualityName(NetInt quality) { switch (quality.Value) { case 0: return("Normal"); case 1: return("Silver"); case 2: return("Gold"); case 3: throw new InvalidEnumArgumentException(); case 4: return("Iridium"); default: throw new InvalidEnumArgumentException(); } }
/*Get MAC Address*/ public static PhysicalAddress GetMacAddress() { try { foreach (NetworkInterface NetInt in NetworkInterface.GetAllNetworkInterfaces()) { if (NetInt.NetworkInterfaceType == NetworkInterfaceType.Ethernet && NetInt.OperationalStatus == OperationalStatus.Up) { return(NetInt.GetPhysicalAddress()); } } return(null); } catch (Exception ex) { GlobalSysFunctions.ShowCallerInfo("GlobalSysInfo => GetMacAddress : ", ex); throw new BLException("GlobalSysInfo => GetMacAddress : " + ex.Message); } }
protected override void ReadDelta(BinaryReader reader, NetVersion version) { texture = new NetTexture2DExtended(); texture.Read(reader, version); Value.setExtendedTexture(texture.Value); which = new NetInt(); which.Read(reader, version); Value.ParentSheetIndex = which.Value; tilePos = new NetVector2(); tilePos.Read(reader, version); Value.TileLocation = tilePos.Value; InventoryMaxSize = new NetInt(); InventoryMaxSize.Read(reader, version); Value.inventoryMaxSize = InventoryMaxSize.Value; sourceRect = new NetRectangle(); sourceRect.Read(reader, version); Value.sourceRect = sourceRect.Value; boundingBox = new NetRectangle(); boundingBox.Read(reader, version); Value.boundingBox.Value = boundingBox.Value; drawPosition = new NetVector2(); drawPosition.Read(reader, version); Value.drawPosition = drawPosition.Value; locationName = new NetString(); locationName.Read(reader, version); Value.locationsName = locationName.Value; Value.thisLocation = Game1.getLocationFromName(locationName.Value); /* * animationManager = new NetAnimationManager(); * animationManager.Read(reader, version); * Value.animationManager = animationManager.Value; */ }
private static int GetSetOffset(NetInt parentSheetIndex) { if (new int[] { 48, 50, 52, 54, 76, 290, 850 }.Contains(parentSheetIndex)) { return(1); // blue } if (new int[] { 56, 58 }.Contains(parentSheetIndex)) { return(2); // red } if (new int[] { 10, 44, 46, 765, 843, 844, 849 }.Contains(parentSheetIndex)) { return(3); // purple } if (new int[] { 2, 34, 36, 75, 668, 670, 760, 762, 764 }.Contains(parentSheetIndex)) { return(4); // grey } return(0); }
public override void updateWhenCurrentLocation(GameTime time, GameLocation environment) { int gatePosition = this.gatePosition.Get(); gatePosition += gateMotion; if (gatePosition == 88) { int drawSum = getDrawSum(environment); if (drawSum != 110 && drawSum != 1500 && drawSum != 1000 && drawSum != 500 && drawSum != 100 && drawSum != 10) { toggleGate(Game1.player, open: false); } } this.gatePosition.Set(gatePosition); if (gatePosition >= 88 || gatePosition <= 0) { gateMotion = 0; } heldObject.Get()?.updateWhenCurrentLocation(time, environment); }
public void load(int which) { Dictionary <int, string> dictionary = Game1.content.Load <Dictionary <int, string> >("Data\\hats"); if (!dictionary.ContainsKey(which)) { which = 0; } string[] split = dictionary[which].Split('/'); Name = split[0]; if (split[2] == "hide") { hairDrawType.Set(2); } else if (Convert.ToBoolean(split[2])) { hairDrawType.Set(0); } else { hairDrawType.Set(1); } if (skipHairDraw) { skipHairDraw = false; hairDrawType.Set(0); } if (split.Length > 4) { string[] specialTags = split[4].Split(' '); foreach (string a in specialTags) { if (a == "Prismatic") { isPrismatic.Value = true; } } } ignoreHairstyleOffset.Value = Convert.ToBoolean(split[3]); base.Category = -95; }
private static bool DrawInMenuPrefix(Furniture __instance, NetInt ___sourceIndexOffset, SpriteBatch spriteBatch, Vector2 location, float scaleSize, float transparency, float layerDepth, StackDrawType drawStackNumber, Color color, bool drawShadow) { if (Game1.activeClickableMenu is PaintBucketMenu && !PatchTemplate.IsDGAObject(__instance)) { var texture = Furniture.furnitureTexture; var sourceRect = __instance.rotations > 1 ? __instance.sourceRect.Value : __instance.defaultSourceRect.Value; if (__instance.modData.ContainsKey("AlternativeTextureName") && AlternativeTextures.textureManager.GetSpecificTextureModel(__instance.modData["AlternativeTextureName"]) is AlternativeTextureModel textureModel && Int32.TryParse(__instance.modData["AlternativeTextureVariation"], out int textureVariation) && textureVariation != -1) { texture = textureModel.GetTexture(textureVariation); sourceRect.X = Math.Max(0, __instance.sourceRect.X - __instance.defaultSourceRect.X); sourceRect.Y = textureModel.GetTextureOffset(textureVariation); } sourceRect.X += sourceRect.Width * ___sourceIndexOffset.Value; spriteBatch.Draw(texture, location + new Vector2(32f, 32f), sourceRect, color * transparency, 0f, new Vector2(sourceRect.Width / 2, sourceRect.Height / 2), 1f * GetScaleSize(sourceRect) * scaleSize, __instance.flipped ? SpriteEffects.FlipHorizontally : SpriteEffects.None, layerDepth); return(false); } return(true); }
public bool IsGiantCrop(NetInt id) { if (!IsLoaded || CropPatcher == null) { return(false); } var method = Self.Helper.Reflection.GetMethod(CropPatcher, "CheckCanBeGiant", false); if (method == null) { return(false); } try { return(method.Invoke <bool>(id)); } catch (Exception ex) { Log($"Error calling CheckCanBeGiant.", LogLevel.Trace, ex); } return(false); }
public override bool hitWithTool(Tool t) { if (t is Pickaxe && t.getLastFarmerToUse() != null && shellHealth.Value > 0) { currentLocation.playSound("hammer", NetAudio.SoundContext.Default); NetInt netInt = shellHealth; int value = netInt.Value; netInt.Value = value - 1; shake(500); setTrajectory(Utility.getAwayFromPlayerTrajectory(GetBoundingBox(), t.getLastFarmerToUse())); if (shellHealth.Value <= 0) { shellGone.Value = true; moveTowardPlayer(-1); currentLocation.playSound("stoneCrack", NetAudio.SoundContext.Default); Game1.createRadialDebris(currentLocation, 14, getTileX(), getTileY(), Game1.random.Next(2, 7), false, -1, false, -1); Game1.createRadialDebris(currentLocation, 14, getTileX(), getTileY(), Game1.random.Next(2, 7), false, -1, false, -1); } return(true); } return(base.hitWithTool(t)); }
/// <summary> /// A method called via Harmony before the getter for <see cref="Farmer.CurrentItem" /> /// that replaces it. /// This method checks if currentToolIndex is equal to -1 before accessing items. /// </summary> /// <returns> /// Returns <see langword="false"/>, terminating prefixes and skipping the execution of the original method, /// effectively replacing the original method. /// </returns> internal static bool BeforeGetCurrentItem( Farmer __instance, NetInt ___currentToolIndex, bool ____itemStowed, ref Item __result) { if (__instance.TemporaryItem is not null) { __result = __instance.TemporaryItem; } else if (____itemStowed || ___currentToolIndex.Value == -1 || ___currentToolIndex.Value >= __instance.items.Count) { __result = null; } else { __result = __instance.items[___currentToolIndex.Value]; } return(false); }