public void AddPlayer(string name, ModPlayer player) { player.Name = name; players[name] = player; player.mod = this; PlayerHooks.Add(player); }
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 { } } } } } }
internal static void SetupPlayer(Player player) { foreach (ModPlayer modPlayer in players) { ModPlayer newPlayer = modPlayer.Clone(); newPlayer.player = player; player.modPlayers.Add(newPlayer); } }
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); }
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); }
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); }
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); } }
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); } }
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); }
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); }
/// <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) { }
/// <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) { }
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"); } }
public bool TypeEquals(ModPlayer other) { return mod == other.mod && Name == other.Name; }
public virtual void clientClone(ModPlayer clientClone) { }
public virtual void SendClientChanges(ModPlayer clientPlayer) { }
public bool TypeEquals(ModPlayer other) { return(mod == other.mod && Name == other.Name); }
internal static void Add(ModPlayer player) { indexes[player.mod.Name + ':' + player.Name] = players.Count; players.Add(player); }
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; }
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); }