Example #1
0
        private static void fixDisposedFarmerTexture(SFarmer f)
        {
            if (f.FarmerRenderer.baseTexture.IsDisposed)
            {
                Log.debug("Disposed texture for player " + f.name + ", fixing");
                int times = 0;
preFixDispose:
                try
                {
                    var field = MultiplayerMod.instance.Helper.Reflection.GetPrivateField <LocalizedContentManager>(f, "farmerTextureManager");
                    var ftm   = field.GetValue();
                    if (ftm != null)
                    {
                        ftm.Unload();
                        ftm.Dispose();
                    }
                    field.SetValue(Game1.content.CreateTemporary());
                    f.FarmerRenderer.baseTexture = f.getTexture();
                    f.changeEyeColor(f.newEyeColor);
                    f.changeAccessory(f.accessory);
                    f.changeShirt(f.shirt);
                    f.changePants(f.pantsColor);
                    f.changeSkinColor(f.skin);
                    f.changeHairColor(f.hairstyleColor);
                    f.changeHairStyle(f.hair);
                    if (f.boots != null)
                    {
                        f.changeShoeColor(f.boots.indexInColorSheet);
                    }
                }
                catch (ObjectDisposedException e)
                {
                    if (++times < 5)
                    {
                        Log.trace("Failed, trying again");
                        goto preFixDispose;
                    }
                    else
                    {
                        Log.trace("Waiting until next frame I guess");
                    }
                }
            }
        }
        // Token: 0x060006EE RID: 1774 RVA: 0x000A3F3C File Offset: 0x000A213C
        public static void loadDataToFarmer(Farmer tmp, Farmer target = null)
        {
            if (target == null)
            {
                target = Game1.player;
            }
            target         = tmp;
            target.items   = tmp.items;
            target.canMove = true;
            target.sprite  = new FarmerSprite(null);
            target.FarmerSprite.setOwner(target);
            target.reloadLivestockSprites();
            if (target.cookingRecipes == null || target.cookingRecipes.Count == 0)
            {
                target.cookingRecipes.Add("Fried Egg", 0);
            }
            if (target.craftingRecipes == null || target.craftingRecipes.Count == 0)
            {
                target.craftingRecipes.Add("Lumber", 0);
            }
            if (!target.songsHeard.Contains("title_day"))
            {
                target.songsHeard.Add("title_day");
            }
            if (!target.songsHeard.Contains("title_night"))
            {
                target.songsHeard.Add("title_night");
            }
            if (target.addedSpeed > 0)
            {
                target.addedSpeed = 0;
            }
            target.maxItems = tmp.maxItems;
            for (int i = 0; i < target.maxItems; i++)
            {
                if (target.items.Count <= i)
                {
                    target.items.Add(null);
                }
            }
            if (target.FarmerRenderer == null)
            {
                target.FarmerRenderer = new FarmerRenderer(target.getTexture());
            }
            target.changeGender(tmp.isMale);
            target.changeAccessory(tmp.accessory);
            target.changeShirt(tmp.shirt);
            target.changePants(tmp.pantsColor);
            target.changeSkinColor(tmp.skin);
            target.changeHairColor(tmp.hairstyleColor);
            target.changeHairStyle(tmp.hair);
            if (target.boots != null)
            {
                target.changeShoeColor(tmp.boots.indexInColorSheet);
            }
            target.Stamina       = tmp.Stamina;
            target.health        = tmp.health;
            target.MaxStamina    = tmp.MaxStamina;
            target.mostRecentBed = tmp.mostRecentBed;
            target.position      = target.mostRecentBed;
            Farmer expr_1E2_cp_0_cp_0 = target;

            expr_1E2_cp_0_cp_0.position.X = expr_1E2_cp_0_cp_0.position.X - (float)Game1.tileSize;
            Game1.player = target;
            Game1.player.checkForLevelTenStatus();
            if (!Game1.player.craftingRecipes.ContainsKey("Wood Path"))
            {
                Game1.player.craftingRecipes.Add("Wood Path", 1);
            }
            if (!Game1.player.craftingRecipes.ContainsKey("Gravel Path"))
            {
                Game1.player.craftingRecipes.Add("Gravel Path", 1);
            }
            if (!Game1.player.craftingRecipes.ContainsKey("Cobblestone Path"))
            {
                Game1.player.craftingRecipes.Add("Cobblestone Path", 1);
            }
        }
Example #3
0
        public static void loadDataToFarmer(Farmer target)
        {
            Farmer farmer = target;

            target.items   = farmer.items;
            target.canMove = true;
            target.sprite  = (AnimatedSprite) new FarmerSprite((Texture2D)null);
            target.FarmerSprite.setOwner(target);
            target.reloadLivestockSprites();
            if (target.cookingRecipes == null || target.cookingRecipes.Count == 0)
            {
                target.cookingRecipes.Add("Fried Egg", 0);
            }
            if (target.craftingRecipes == null || target.craftingRecipes.Count == 0)
            {
                target.craftingRecipes.Add("Lumber", 0);
            }
            if (!target.songsHeard.Contains("title_day"))
            {
                target.songsHeard.Add("title_day");
            }
            if (!target.songsHeard.Contains("title_night"))
            {
                target.songsHeard.Add("title_night");
            }
            if (target.addedSpeed > 0)
            {
                target.addedSpeed = 0;
            }
            target.maxItems = farmer.maxItems;
            for (int index = 0; index < target.maxItems; ++index)
            {
                if (target.items.Count <= index)
                {
                    target.items.Add((Item)null);
                }
            }
            if (target.FarmerRenderer == null)
            {
                target.FarmerRenderer = new FarmerRenderer(target.getTexture());
            }
            target.changeGender(farmer.isMale);
            target.changeAccessory(farmer.accessory);
            target.changeShirt(farmer.shirt);
            target.changePants(farmer.pantsColor);
            target.changeSkinColor(farmer.skin);
            target.changeHairColor(farmer.hairstyleColor);
            target.changeHairStyle(farmer.hair);
            if (target.boots != null)
            {
                target.changeShoeColor(farmer.boots.indexInColorSheet);
            }
            target.Stamina       = farmer.Stamina;
            target.health        = farmer.health;
            target.MaxStamina    = farmer.MaxStamina;
            target.mostRecentBed = farmer.mostRecentBed;
            target.position      = target.mostRecentBed;
            target.position.X   -= (float)Game1.tileSize;
            target.checkForLevelTenStatus();
            if (!target.craftingRecipes.ContainsKey("Wood Path"))
            {
                target.craftingRecipes.Add("Wood Path", 1);
            }
            if (!target.craftingRecipes.ContainsKey("Gravel Path"))
            {
                target.craftingRecipes.Add("Gravel Path", 1);
            }
            if (target.craftingRecipes.ContainsKey("Cobblestone Path"))
            {
                return;
            }
            target.craftingRecipes.Add("Cobblestone Path", 1);
        }