Esempio n. 1
0
        public static void Postfix(long peer)
        {
            var multiplayer = ModEntry.ModHelper.Reflection.GetField <Multiplayer>(typeof(Game1), "multiplayer").GetValue();

            NetRoot <FarmerTeam> fakeTeamRoot = new NetRoot <FarmerTeam>(new FarmerTeam());

            fakeTeamRoot.Value.money.Minimum = null;

            int moneyTheyHave = ModEntry.Config.StartingMoney;

            if (ModEntry.MoneyData.PlayerMoney.ContainsKey(peer))
            {
                moneyTheyHave = ModEntry.MoneyData.PlayerMoney[peer];
            }
            else
            {
                ModEntry.MoneyData.PlayerMoney.Add(peer, moneyTheyHave);
            }

            Console.WriteLine($"Setting {peer}'s money to {moneyTheyHave}");
            fakeTeamRoot.Value.money.Set(-1 * Game1.player.teamRoot.Value.money.Value + moneyTheyHave);

            byte[] fakeData = multiplayer.writeObjectDeltaBytes(fakeTeamRoot);

            BroadcastFarmerDeltasPatch.AllowOnce = true;
            Game1.server.sendMessage(peer, 13, Game1.player, fakeData);
            BroadcastFarmerDeltasPatch.AllowOnce = false;
        }
Esempio n. 2
0
        protected override void readActiveLocation(IncomingMessage msg, bool forceCurrentLocation = false)
        {
            NetRoot <GameLocation> root = readObjectFull <GameLocation>(msg.Reader);

            if (isAlwaysActiveLocation(root.Value))
            {
                Memory.instance.Monitor.Log("Recieving Map: " + root.Value.Name + " as Always Active.");
                for (int i = 0; i < Game1.locations.Count; i++)
                {
                    if (Game1.locations[i].Equals(root.Value))
                    {
                        Game1.locations[i] = root.Value;
                        if (Game1.locations[i] is BuildableGameLocation)
                        {
                            foreach (Building b in (Game1.locations[i] as BuildableGameLocation).buildings)
                            {
                                b.load();
                            }
                        }
                        break;
                    }
                }
            }
            if (Game1.locationRequest != null || forceCurrentLocation)
            {
                Memory.instance.Monitor.Log("Reciving Map: " + root.Value.Name + " as Current Location (disposible).");
                if (Game1.locationRequest != null)
                {
                    Game1.currentLocation = Game1.findStructure(root.Value, Game1.locationRequest.Name);
                    if (Game1.currentLocation == null)
                    {
                        Game1.currentLocation = root.Value;
                    }
                }
                else if (forceCurrentLocation)
                {
                    Game1.currentLocation = root.Value;
                }
                if (Game1.locationRequest != null)
                {
                    Game1.locationRequest.Loaded(root.Value);
                }
                Game1.currentLocation.resetForPlayerEntry();
                Game1.player.currentLocation = Game1.currentLocation;
                if (Game1.locationRequest != null)
                {
                    Game1.locationRequest.Warped(root.Value);
                }
                Game1.currentLocation.updateSeasonalTileSheets();
                if (Game1.isDebrisWeather)
                {
                    Game1.populateDebrisWeatherArray();
                }
                Game1.locationRequest = null;
            }
        }
Esempio n. 3
0
        public override NetRoot <Farmer> Clone()
        {
            NetRoot <Farmer> result = base.Clone();

            if (Game1.serverHost != null && result.Value != null)
            {
                result.Value.teamRoot = Game1.serverHost.Value.teamRoot;
            }
            return(result);
        }
Esempio n. 4
0
        public void sendVar <TField, T>(string varName, T value) where TField : NetFieldBase <T, TField>, new()
        {
            using MemoryStream stream = new MemoryStream();
            using BinaryWriter writer = new BinaryWriter(stream);
            NetRoot <TField> root = new NetRoot <TField>(new TField());

            root.Value.Value = value;
            root.WriteFull(writer);
            variables[varName] = root.Value;
            stream.Seek(0L, SeekOrigin.Begin);
            sendMessage((byte)0, varName, stream.ToArray());
        }
Esempio n. 5
0
        public static bool Prefix(Multiplayer __instance)
        {
            if (!Game1.IsServer)
            {
                return(true);
            }

            var reflection = ModEntry.ModHelper.Reflection;
            var broadcastFarmerDeltaMethod = reflection.GetMethod(__instance, "broadcastFarmerDelta");

            foreach (NetFarmerRoot item in __instance.farmerRoots())
            {
                if (item.Dirty && Game1.player.UniqueMultiplayerID == item.Value.UniqueMultiplayerID)
                {
                    //NetIntDelta actualValue = item.Value.teamRoot.Value.money;
                    //Console.WriteLine($"Trying to sync {item.Value.Name} with everyone.  value = {actualValue}");
                    //ModEntry.ModHelper.Reflection.GetField<NetIntDelta>(item.Value.teamRoot.Value, "money").SetValue(new NetIntDelta(0));

                    broadcastFarmerDeltaMethod.Invoke(item.Value, __instance.writeObjectDeltaBytes(item));

                    //ModEntry.ModHelper.Reflection.GetField<NetIntDelta>(item.Value.teamRoot.Value, "money").SetValue(actualValue);
                }
            }

            if (Game1.player.teamRoot.Dirty)
            {
                var    method     = reflection.GetMethod(__instance, "broadcastTeamDelta");
                byte[] deltaBytes = __instance.writeObjectDeltaBytes(Game1.player.teamRoot);

                NetRoot <FarmerTeam> team = new NetRoot <FarmerTeam>(new FarmerTeam());
                team.Value.money.Minimum = null;

                using (var mem = new MemoryStream(deltaBytes))
                    using (var bin = new BinaryReader(mem))
                    {
                        __instance.readObjectDelta(bin, team);

                        if (AllowOnce || team.Value.money.Value == 500)
                        {
                            //Not trying to change the money, so pass
                            AllowOnce = false;
                            method.Invoke(deltaBytes);
                        }
                    }
            }
            return(false);
        }
Esempio n. 6
0
        public void receiveMessage(IncomingMessage msg)
        {
            switch (msg.Reader.ReadByte())
            {
            case 0:
            {
                string varName = msg.Reader.ReadString();
                NetRoot <INetObject <INetSerializable> > root = new NetRoot <INetObject <INetSerializable> >();
                root.ReadFull(msg.Reader, default(NetVersion));
                variables[varName] = root.Value;
                break;
            }

            case 1:
            {
                string barrierName = msg.Reader.ReadString();
                barrierPlayers(barrierName).Add(msg.FarmerID);
                break;
            }
            }
        }
Esempio n. 7
0
        public static bool Prefix(IncomingMessage message, GameServer __instance)
        {
            Multiplayer multiplayer = ModEntry.ModHelper.Reflection.GetField <Multiplayer>(typeof(Game1), "multiplayer").GetValue();

            //Console.WriteLine($"Received packet {message.MessageType} by {message.FarmerID}/{message.SourceFarmer.Name}");

            if (message.MessageType == 13 && Game1.IsServer)
            {
                NetRoot <FarmerTeam> team = new NetRoot <FarmerTeam>(new FarmerTeam());
                team.Value.money.Minimum = null;
                multiplayer.readObjectDelta(message.Reader, team);

                int deltaMoney = team.Value.money.Value - 500;                //new FarmerTeam() has 500 as default.
                Console.WriteLine($"Delta money for {message.FarmerID}/{message.SourceFarmer.Name} = {deltaMoney}");

                if (deltaMoney != 0)
                {
                    if (ModEntry.MoneyData.PlayerMoney.ContainsKey(message.FarmerID))
                    {
                        ModEntry.MoneyData.PlayerMoney[message.FarmerID] += deltaMoney;
                    }
                    else
                    {
                        ModEntry.MoneyData.PlayerMoney.Add(message.FarmerID, Math.Max(0, ModEntry.Config.StartingMoney + deltaMoney));
                    }

                    Console.WriteLine($"{message.FarmerID} new total money = {ModEntry.MoneyData.PlayerMoney[message.FarmerID]}");

                    return(false);
                }

                #region Reset streams
                var stream = new MemoryStream(message.Data);
                var bin    = new BinaryReader(stream);

                //(msg.stream = new MemoryStream(data);)
                var streamField = ModEntry.ModHelper.Reflection.GetField <MemoryStream>(message, "stream");
                streamField.SetValue(stream);

                //(msg.reader = new BinaryReader(stream);)
                var readerField = ModEntry.ModHelper.Reflection.GetField <BinaryReader>(message, "reader");
                readerField.SetValue(bin);
                #endregion

                multiplayer.processIncomingMessage(message);

                if (multiplayer.isClientBroadcastType(message.MessageType))
                {
                    ModEntry.ModHelper.Reflection.GetMethod(__instance, "rebroadcastClientMessage").Invoke(message);
                }

                return(false);
            }
            else if (message.MessageType == 6 && Game1.IsServer)
            {
                var          readLocationMethod = ModEntry.ModHelper.Reflection.GetMethod(multiplayer, "readLocation");
                GameLocation location3          = readLocationMethod.Invoke <GameLocation>(message.Reader);
                if (location3 != null)
                {
                    Item[] ro = null;
                    if (location3 is Farm f)
                    {
                        ro = f.shippingBin.ToArray();
                    }

                    multiplayer.readObjectDelta(message.Reader, location3.Root);

                    if (location3 is Farm farm)
                    {
                        BinListener.StartListen(message.FarmerID, farm);
                    }
                }

                ModEntry.ModHelper.Reflection.GetMethod(__instance, "rebroadcastClientMessage").Invoke(message);

                return(false);
            }

            return(true);
        }
 public override byte[] writeObjectFullBytes <T>(NetRoot <T> root, long?peer)
 {
     return(intercepted.writeObjectFullBytes <T>(root, peer));
 }
 public override void writeObjectFull <T>(BinaryWriter writer, NetRoot <T> root, long?peer)
 {
     intercepted.writeObjectFull <T>(writer, root, peer);
 }
 public override byte[] writeObjectDeltaBytes <T>(NetRoot <T> root)
 {
     return(intercepted.writeObjectDeltaBytes <T>(root));
 }
 public override void writeObjectDelta <T>(BinaryWriter writer, NetRoot <T> root)
 {
     intercepted.writeObjectDelta <T>(writer, root);
 }
 public override void readObjectDelta <T>(BinaryReader reader, NetRoot <T> root)
 {
     intercepted.readObjectDelta(reader, root);
 }
Esempio n. 13
0
        public static bool Prefix(IList <Item> items, List <int> ___categoryTotals, List <List <Item> > ___categoryItems,
                                  ShippingMenu __instance, List <MoneyDial> ___categoryDials)
        {
            if (Game1.IsMasterGame)
            {
                var MoneyPerPlayer = new Dictionary <long, int>();

                foreach (var pair in ModEntry.OldItems)
                {
                    if (pair.Key is StardewValley.Object o)
                    {
                        int individualPrice = o.sellToStorePrice();
                        int stack           = o.Stack;

                        int value = individualPrice * stack;
                        if (MoneyPerPlayer.ContainsKey(pair.Value))
                        {
                            MoneyPerPlayer[pair.Value] += value;
                        }
                        else
                        {
                            MoneyPerPlayer.Add(pair.Value, value);
                        }
                    }
                }


                var multiplayer = ModEntry.ModHelper.Reflection.GetField <Multiplayer>(typeof(Game1), "multiplayer").GetValue();


                foreach (var pair in MoneyPerPlayer)
                {
                    if (pair.Key == Game1.player.UniqueMultiplayerID)
                    {
                        Game1.player.Money += pair.Value;
                        Console.WriteLine($"Host money += {pair.Value}");
                    }
                    else
                    {
                        NetRoot <FarmerTeam> fakeTeamRoot = new NetRoot <FarmerTeam>(new FarmerTeam());
                        fakeTeamRoot.Value.money.Minimum = null;

                        int moneyTheyGain = pair.Value;
                        if (ModEntry.MoneyData.PlayerMoney.ContainsKey(pair.Key))
                        {
                            ModEntry.MoneyData.PlayerMoney[pair.Key] += moneyTheyGain;
                        }
                        else
                        {
                            ModEntry.MoneyData.PlayerMoney.Add(pair.Key, Math.Max(0, ModEntry.Config.StartingMoney + moneyTheyGain));
                        }

                        fakeTeamRoot.Value.money.Set(moneyTheyGain);

                        var fakeData = multiplayer.writeObjectDeltaBytes(fakeTeamRoot);
                        BroadcastFarmerDeltasPatch.AllowOnce = true;
                        if (fakeData != null)
                        {
                            if (Game1.getOnlineFarmers().Any((f) => f.UniqueMultiplayerID == pair.Key))
                            {
                                Game1.server.sendMessage(pair.Key, 13, Game1.player, fakeData);
                            }
                            else
                            {
                                Console.WriteLine($"Player disconnected, do not need to send data to {pair.Key}");
                            }
                        }
                        else
                        {
                            Console.WriteLine($"Data is null, can't send data money for {pair.Key}");
                        }
                        BroadcastFarmerDeltasPatch.AllowOnce = false;

                        Console.WriteLine($"{pair.Key} money += {moneyTheyGain}");
                    }
                }

                ModEntry.OldItems.Clear();
            }

            ////

            Utility.consolidateStacks(items);

            for (int k = 0; k < 6; k++)
            {
                ___categoryItems.Add(new List <Item>());
                ___categoryTotals.Add(0);
                ___categoryDials.Add(new MoneyDial(7, k == 5));
            }
            foreach (Item item in items)
            {
                if (item is StardewValley.Object)
                {
                    StardewValley.Object o = item as StardewValley.Object;
                    int category           = __instance.getCategoryIndexForObject(o);
                    ___categoryItems[category].Add(o);
                    int index = category;
                    ___categoryTotals[index] += o.sellToStorePrice() * o.Stack;
                    Game1.stats.itemsShipped += (uint)o.Stack;
                    if (o.Category == -75 || o.Category == -79)
                    {
                        Game1.stats.CropsShipped += (uint)o.Stack;
                    }
                    if (o.countsForShippedCollection())
                    {
                        // Game1.player.shippedBasic(o.parentSheetIndex, o.stack);
                        Game1.player.shippedBasic(o.ParentSheetIndex, o.Stack);
                    }
                }
            }
            for (int i = 0; i < 5; i++)
            {
                ___categoryTotals[5] += ___categoryTotals[i];
                ___categoryItems[5].AddRange(___categoryItems[i]);
                ___categoryDials[i].currentValue        = ___categoryTotals[i];
                ___categoryDials[i].previousTargetValue = ___categoryDials[i].currentValue;
            }
            ___categoryDials[5].currentValue = ___categoryTotals[5];


            //if (Game1.IsMasterGame)
            //{
            //    Game1.player.Money += ___categoryTotals[5];
            //}


            Game1.setRichPresence("earnings", ___categoryTotals[5]);

            ////



            return(false);
        }
Esempio n. 14
0
 // Start is called before the first frame update
 private void Awake()
 {
     Ins = this;
 }