Exemplo n.º 1
0
 public void AddPlayer(string name, ModPlayer player)
 {
     player.Name   = name;
     players[name] = player;
     player.mod    = this;
     PlayerHooks.Add(player);
 }
Exemplo n.º 2
0
        public static void ReceiveCustomBiomes(Player player, BinaryReader reader)
        {
            int count = reader.ReadUInt16();

            for (int k = 0; k < count; k++)
            {
                string    modName   = reader.ReadString();
                string    name      = reader.ReadString();
                byte[]    data      = reader.ReadBytes(reader.ReadByte());
                Mod       mod       = ModLoader.GetMod(modName);
                ModPlayer modPlayer = mod == null ? null : player.GetModPlayer(mod, name);
                if (modPlayer != null)
                {
                    using (MemoryStream stream = new MemoryStream(data))
                    {
                        using (BinaryReader customReader = new BinaryReader(stream))
                        {
                            try
                            {
                                modPlayer.ReceiveCustomBiomes(customReader);
                            }
                            catch
                            {
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 3
0
 internal static void SetupPlayer(Player player)
 {
     foreach (ModPlayer modPlayer in players)
     {
         ModPlayer newPlayer = modPlayer.Clone();
         newPlayer.player = player;
         player.modPlayers.Add(newPlayer);
     }
 }
Exemplo n.º 4
0
		internal static void Add(ModPlayer player)
		{
			string mod = player.mod.Name;
			if (!indexes.ContainsKey(mod))
			{
				indexes[mod] = new Dictionary<string, int>();
			}
			indexes[mod][player.Name] = players.Count;
			players.Add(player);
		}
Exemplo n.º 5
0
        internal ModPlayer CreateFor(Player newPlayer)
        {
            ModPlayer modPlayer = (ModPlayer)(CloneNewInstances ? MemberwiseClone() : Activator.CreateInstance(GetType()));

            modPlayer.Mod    = Mod;
            modPlayer.player = newPlayer;
            modPlayer.index  = index;
            modPlayer.Initialize();
            return(modPlayer);
        }
Exemplo n.º 6
0
        internal static void Add(ModPlayer player)
        {
            string mod = player.mod.Name;

            if (!indexes.ContainsKey(mod))
            {
                indexes[mod] = new Dictionary <string, int>();
            }
            indexes[mod][player.Name] = players.Count;
            players.Add(player);
        }
Exemplo n.º 7
0
 internal static void SetupPlayer(Player player)
 {
     player.modPlayers.Clear();
     foreach (ModPlayer modPlayer in players)
     {
         ModPlayer newPlayer = modPlayer.Clone();
         newPlayer.player = player;
         newPlayer.Initialize();
         player.modPlayers.Add(newPlayer);
     }
 }
Exemplo n.º 8
0
        private void AutoloadPlayer(Type type)
        {
            ModPlayer player = (ModPlayer)Activator.CreateInstance(type);

            player.mod = this;
            string name = type.Name;

            if (player.Autoload(ref name))
            {
                AddPlayer(name, player);
            }
        }
Exemplo n.º 9
0
 internal static void Add(ModPlayer player)
 {
     player.index = players.Count;
     indexes[player.mod.Name + ':' + player.Name] = players.Count;
     if (indexesByType.ContainsKey(player.GetType()))
     {
         indexesByType[player.GetType()] = -1;
     }
     else
     {
         indexesByType[player.GetType()] = players.Count;
     }
     players.Add(player);
 }
Exemplo n.º 10
0
 private static bool SendCustomBiomes(ModPlayer modPlayer, BinaryWriter writer)
 {
     byte[] data;
     using (MemoryStream stream = new MemoryStream())
     {
         using (BinaryWriter customWriter = new BinaryWriter(stream))
         {
             modPlayer.SendCustomBiomes(customWriter);
             customWriter.Flush();
             data = stream.ToArray();
         }
     }
     if (data.Length > 0)
     {
         writer.Write(modPlayer.mod.Name);
         writer.Write(modPlayer.Name);
         writer.Write((byte)data.Length);
         writer.Write(data);
         return(true);
     }
     return(false);
 }
Exemplo n.º 11
0
 /// <summary>
 /// Allows you to sync any information that has changed between the server and client. Here, you should check the information you have copied in the clientClone parameter; if they differ between this player and the clientPlayer parameter, then you should send that information using NetMessage.SendData or ModPacket.Send.
 /// </summary>
 /// <param name="clientPlayer"></param>
 public virtual void SendClientChanges(ModPlayer clientPlayer)
 {
 }
Exemplo n.º 12
0
 /// <summary>
 /// Allows you to copy information about this player to the clientClone parameter. You should copy information that you intend to sync between server and client. This hook is called in the Player.clientClone method. See SendClientChanges for more info.
 /// </summary>
 /// <param name="clientClone"></param>
 public virtual void clientClone(ModPlayer clientClone)
 {
 }
Exemplo n.º 13
0
        internal static void VerifyGlobalItem(ModPlayer player)
        {
            var type = player.GetType();

            int netCustomBiomeMethods = 0;

            if (HasMethod(type, "CustomBiomesMatch", typeof(Player)))
            {
                netCustomBiomeMethods++;
            }
            if (HasMethod(type, "CopyCustomBiomesTo", typeof(Player)))
            {
                netCustomBiomeMethods++;
            }
            if (HasMethod(type, "SendCustomBiomes", typeof(BinaryWriter)))
            {
                netCustomBiomeMethods++;
            }
            if (HasMethod(type, "ReceiveCustomBiomes", typeof(BinaryReader)))
            {
                netCustomBiomeMethods++;
            }
            if (netCustomBiomeMethods > 0 && netCustomBiomeMethods < 4)
            {
                throw new Exception(type + " must override all of (CustomBiomesMatch/CopyCustomBiomesTo/SendCustomBiomes/ReceiveCustomBiomes) or none");
            }

            int netClientMethods = 0;

            if (HasMethod(type, "clientClone", typeof(ModPlayer)))
            {
                netClientMethods++;
            }
            if (HasMethod(type, "SyncPlayer", typeof(int), typeof(int), typeof(bool)))
            {
                netClientMethods++;
            }
            if (HasMethod(type, "SendClientChanges", typeof(ModPlayer)))
            {
                netClientMethods++;
            }
            if (netClientMethods > 0 && netClientMethods < 3)
            {
                throw new Exception(type + " must override all of (clientClone/SyncPlayer/SendClientChanges) or none");
            }

            int saveMethods = 0;

            if (HasMethod(type, "Save"))
            {
                saveMethods++;
            }
            if (HasMethod(type, "Load", typeof(TagCompound)))
            {
                saveMethods++;
            }
            if (saveMethods == 1)
            {
                throw new Exception(type + " must override all of (Save/Load) or none");
            }

            int netMethods = 0;

            if (HasMethod(type, "NetSend", typeof(BinaryWriter)))
            {
                netMethods++;
            }
            if (HasMethod(type, "NetReceive", typeof(BinaryReader)))
            {
                netMethods++;
            }
            if (netMethods == 1)
            {
                throw new Exception(type + " must override both of (NetSend/NetReceive) or none");
            }
        }
Exemplo n.º 14
0
 public bool TypeEquals(ModPlayer other)
 {
     return mod == other.mod && Name == other.Name;
 }
Exemplo n.º 15
0
 public virtual void clientClone(ModPlayer clientClone)
 {
 }
Exemplo n.º 16
0
 public virtual void SendClientChanges(ModPlayer clientPlayer)
 {
 }
Exemplo n.º 17
0
 public bool TypeEquals(ModPlayer other)
 {
     return(mod == other.mod && Name == other.Name);
 }
Exemplo n.º 18
0
 public void AddPlayer(string name, ModPlayer player)
 {
     player.Name = name;
     players[name] = player;
     player.mod = this;
     PlayerHooks.Add(player);
 }
Exemplo n.º 19
0
 internal static void Add(ModPlayer player)
 {
     indexes[player.mod.Name + ':' + player.Name] = players.Count;
     players.Add(player);
 }
Exemplo n.º 20
0
 internal static void Add(ModPlayer player)
 {
     indexes[player.mod.Name + ':' + player.Name] = players.Count;
     players.Add(player);
 }
Exemplo n.º 21
0
 private static bool SendCustomBiomes(ModPlayer modPlayer, BinaryWriter writer)
 {
     byte[] data;
     using (MemoryStream stream = new MemoryStream())
     {
         using (BinaryWriter customWriter = new BinaryWriter(stream))
         {
             modPlayer.SendCustomBiomes(customWriter);
             customWriter.Flush();
             data = stream.ToArray();
         }
     }
     if (data.Length > 0)
     {
         writer.Write(modPlayer.mod.Name);
         writer.Write(modPlayer.Name);
         writer.Write((byte)data.Length);
         writer.Write(data);
         return true;
     }
     return false;
 }
Exemplo n.º 22
0
		public void AddPlayer(string name, ModPlayer player)
		{
			Type itemClass = typeof(Item);
			Type intClass = typeof(int);
			if (player.GetType().GetMethod("CatchFish", new Type[] {
				itemClass, itemClass, intClass, intClass, intClass, intClass,
				intClass.MakeByRefType(), typeof(bool).MakeByRefType() }) != null)
			{
				throw new OldHookException("ModPlayer.CatchFish");
			}
			player.Name = name;
			players[name] = player;
			player.mod = this;
			PlayerHooks.Add(player);
		}