コード例 #1
0
ファイル: Mod.cs プロジェクト: Unowndeveloper/tModLoader
 public void AddPlayer(string name, ModPlayer player)
 {
     player.Name   = name;
     players[name] = player;
     player.mod    = this;
     PlayerHooks.Add(player);
 }
コード例 #2
0
ファイル: PlayerHooks.cs プロジェクト: akemimadoka/tModLoader
        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
                            {
                            }
                        }
                    }
                }
            }
        }
コード例 #3
0
 internal static void SetupPlayer(Player player)
 {
     foreach (ModPlayer modPlayer in players)
     {
         ModPlayer newPlayer = modPlayer.Clone();
         newPlayer.player = player;
         player.modPlayers.Add(newPlayer);
     }
 }
コード例 #4
0
ファイル: PlayerHooks.cs プロジェクト: DrakoGlyph/tModLoader
		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);
		}
コード例 #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);
        }
コード例 #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);
        }
コード例 #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);
     }
 }
コード例 #8
0
ファイル: ModInternals.cs プロジェクト: re4prr/tModLoader
        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);
            }
        }
コード例 #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);
 }
コード例 #10
0
ファイル: PlayerHooks.cs プロジェクト: akemimadoka/tModLoader
 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);
 }
コード例 #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)
 {
 }
コード例 #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)
 {
 }
コード例 #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");
            }
        }
コード例 #14
0
ファイル: ModPlayer.cs プロジェクト: PJB3005/tModLoader
 public bool TypeEquals(ModPlayer other)
 {
     return mod == other.mod && Name == other.Name;
 }
コード例 #15
0
ファイル: ModPlayer.cs プロジェクト: bluemagic123/tModLoader
 public virtual void clientClone(ModPlayer clientClone)
 {
 }
コード例 #16
0
ファイル: ModPlayer.cs プロジェクト: bluemagic123/tModLoader
 public virtual void SendClientChanges(ModPlayer clientPlayer)
 {
 }
コード例 #17
0
ファイル: ModPlayer.cs プロジェクト: saeym/tModLoader
 public bool TypeEquals(ModPlayer other)
 {
     return(mod == other.mod && Name == other.Name);
 }
コード例 #18
0
ファイル: Mod.cs プロジェクト: trekko727/tModLoader
 public void AddPlayer(string name, ModPlayer player)
 {
     player.Name = name;
     players[name] = player;
     player.mod = this;
     PlayerHooks.Add(player);
 }
コード例 #19
0
ファイル: PlayerHooks.cs プロジェクト: akemimadoka/tModLoader
 internal static void Add(ModPlayer player)
 {
     indexes[player.mod.Name + ':' + player.Name] = players.Count;
     players.Add(player);
 }
コード例 #20
0
 internal static void Add(ModPlayer player)
 {
     indexes[player.mod.Name + ':' + player.Name] = players.Count;
     players.Add(player);
 }
コード例 #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;
 }
コード例 #22
0
ファイル: Mod.cs プロジェクト: JavidPack/TerraCustom
		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);
		}