public void Add( Module mod ) { if( ContainsKey( mod.GetType() ) ) return; Add( mod.GetType(), mod ); }
public void Append(Module mod, bool negatively) { if (ContainsKey(mod.GetType())) { ((Module)this[mod.GetType()]).Append(mod, negatively); } }
public void Change(Module mod) { if (ContainsKey(mod.GetType())) { this[mod.GetType()] = mod; } }
public void Add(Module mod) { if (ContainsKey(mod.GetType())) { return; } Add(mod.GetType(), mod); }
public void Remove( Module mod ) { Remove( mod.GetType() ); if( Count == 0 ) CentralMemory.Remove( m_Owner ); }
public void Remove(Module mod) { Remove(mod.GetType()); if (Count == 0) { CentralMemory.Remove(m_Owner); } }
public static void AppendModule(Serial ser, Module mod, bool negatively) { if (!m_DictionaryOfModuleLists.ContainsKey(ser)) { Add(ser); } else if (!ContainsModule(ser, mod.GetType())) { AddModule(mod); return; } else { m_DictionaryOfModuleLists[ser].Append(mod, negatively); } }
public static void AppendModule(Serial ser, Module mod, bool negatively) { if (!m_Modules.ContainsKey(ser)) { Add(ser); } else if (!ContainsModule(ser, mod.GetType())) { AddModule(mod); return; } else { ((ModuleList)m_Modules[ser]).Append(mod, negatively); } }
public override void Load(BinaryReader idx, BinaryReader tdb, BinaryFileReader reader) { object[] ctorArgs = new object[1]; Type[] ctorTypes = new Type[1] { typeof(Serial) }; List <ModuleEntry> modules = new List <ModuleEntry>(); m_DictionaryOfModuleLists = new Dictionary <Serial, ModuleList>(); int version = reader.ReadInt(); int count = tdb.ReadInt32(); ArrayList types = new ArrayList(count); for (int i = 0; i < count; ++i) { string typeName = tdb.ReadString(); Type t = ScriptCompiler.FindTypeByFullName(typeName); if (t == null) { Console.WriteLine("Type not found: {0}, remove?", typeName); if (Console.ReadKey(true).Key == ConsoleKey.Y) { types.Add(null); continue; } throw new Exception(String.Format("Bad type '{0}'", typeName)); } ConstructorInfo ctor = t.GetConstructor(ctorTypes); if (ctor != null) { types.Add(new object[] { ctor, null }); } else { throw new Exception(String.Format("Type '{0}' does not have a serialization constructor", t)); } } int moduleCount = idx.ReadInt32(); for (int i = 0; i < moduleCount; ++i) { int typeID = idx.ReadInt32(); int serial = idx.ReadInt32(); long pos = idx.ReadInt64(); int length = idx.ReadInt32(); object[] objs = (object[])types[typeID]; if (objs == null) { continue; } Module m = null; ConstructorInfo ctor = (ConstructorInfo)objs[0]; string typeName = (string)objs[1]; try { ctorArgs[0] = (Serial)serial; m = (Module)(ctor.Invoke(ctorArgs)); } catch { } if (m != null) { modules.Add(new ModuleEntry(m, typeID, typeName, pos, length)); AddModule(m); } } bool failedModules = false; Type failedType = null; Exception failed = null; int failedTypeID = 0; for (int i = 0; i < modules.Count; ++i) { ModuleEntry entry = modules[i]; Module m = entry.Module; if (m != null) { reader.Seek(entry.Position, SeekOrigin.Begin); try { m.Deserialize(reader); if (reader.Position != (entry.Position + entry.Length)) { throw new Exception(String.Format("Bad serialize on {0}", m.GetType())); } } catch (Exception e) { modules.RemoveAt(i); failed = e; failedModules = true; failedType = m.GetType(); failedTypeID = entry.TypeID; break; } } } if (failedModules) { Console.WriteLine("An error was encountered while loading a Module of Type: {0}", failedType); Console.WriteLine("Remove this type of Module? (y/n)"); if (Console.ReadLine() == "y") { for (int i = 0; i < modules.Count;) { if (((ModuleEntry)modules[i]).TypeID == failedTypeID) { modules.RemoveAt(i); } else { ++i; } } SaveIndex <ModuleEntry>(modules); } Console.WriteLine("After pressing return an exception will be thrown and the server will terminate"); Console.ReadLine(); throw new Exception(String.Format("Load failed (type={0})", failedType), failed); } }
public void Append( Module mod, bool negatively ) { if( ContainsKey( mod.GetType() ) ) ((Module)this[ mod.GetType() ]).Append( mod, negatively ); }
public void Change( Module mod ) { if( ContainsKey( mod.GetType() ) ) this[ mod.GetType() ] = mod; }