/// <summary> /// Prevent the core from exiting during a crash state while async writers are pending. /// </summary> private static void WaitForWriteCompletion() { if (!VitaNexCore.Crashed && !Core.Closing) { return; } var pending = PendingWriters; if (pending <= 0) { return; } VitaNexCore.ToConsole("Waiting for {0:#,0} pending write tasks...", pending); while (pending > 0) { _Sync.WaitOne(10); pending = PendingWriters; } VitaNexCore.ToConsole("All write tasks completed.", pending); }
static GumpsExtUtility() { try { var a = Assembly.LoadFrom("Ultima.dll"); if (a == null) { return; } var t = a.GetType("Ultima.Gumps"); if (t != null) { _UltimaArtGetGump = t.GetMethods(BindingFlags.Static | BindingFlags.Public) .FirstOrDefault(m => m.Name == "GetGump" && m.ReturnType.IsEqual <Bitmap>() && m.GetParameters().Length == 2); } } catch (Exception e) { VitaNexCore.ToConsole("Could not load Ultima.dll or a member of Ultima.Gumps:"); VitaNexCore.ToConsole(e); } }
static SerializeExtUtility() { VitaNexCore.OnSaved += WaitForWriteCompletion; VitaNexCore.OnDispose += WaitForWriteCompletion; VitaNexCore.OnDisposed += WaitForWriteCompletion; var asm = ScriptCompiler.Assemblies.With(Core.Assembly).Distinct(); int tid; foreach (var t in asm.SelectMany(o => o.GetTypeCache())) { tid = GetTypeID(t.FullName); if (_Types.ContainsKey(tid)) { VitaNexCore.ToConsole("Warning: Conflicting Type ID: {0}\n{1} <> {2}", tid, _Types[tid], t); } _Types[tid] = t; foreach (var a in t.GetCustomAttributes <TypeAliasAttribute>(false).SelectMany(o => o.Aliases)) { tid = GetTypeID(a); if (_Types.ContainsKey(tid)) { VitaNexCore.ToConsole("Warning: Conflicting Alias ID: {0}\n{1} <> {2}", tid, _Types[tid], t); } _Types[tid] = t; } } }
public static void SerializeAsync(this FileInfo file, Action <GenericWriter> handler, bool truncate) { if (file == null || handler == null) { return; } // Do not use async writing during a crash state or when closing. if (VitaNexCore.Crashed || Core.Closing) { _Serialize.Invoke(file, handler, truncate); return; } var t = _Serialize.BeginInvoke(file, handler, truncate, OnSerializeAsync, file); lock (_TaskRoot) { _Tasks.Add(t); } _Sync.Reset(); var dir = file.Directory != null ? file.Directory.Name : String.Empty; VitaNexCore.ToConsole("Async write started for '{0}/{1}'", dir, file.Name); }
public static void SerializeAsync(this FileInfo file, Action <GenericWriter> handler, bool truncate) { if (file == null || handler == null) { return; } var save = new Action <FileInfo, Action <GenericWriter>, bool>(Serialize); save.BeginInvoke( file, handler, truncate, r => { save.EndInvoke(r); var f = (FileInfo)r.AsyncState; VitaNexCore.ToConsole( "Async write ended for '{0}/{1}'", f.Directory != null ? f.Directory.Name : String.Empty, f.Name); /*if (_PendingWriters > 0) * { * VitaNexCore.ToConsole("There are {0:#,0} write operations pending", _PendingWriters); * }*/ }, file); }
private static void Resize(Type owner, string field, int resize) { var f = owner.GetField(field, BindingFlags.Static | BindingFlags.NonPublic); if (f != null) { var b = f.GetValue(null) as BufferPool; if (b != null) { string name; int freeCount, initialCapacity, currentCapacity, bufferSize, misses; b.GetInfo(out name, out freeCount, out initialCapacity, out currentCapacity, out bufferSize, out misses); if (bufferSize < resize && b.SetFieldValue("m_BufferSize", resize)) { Queue <byte[]> buffers; if (b.GetFieldValue("m_FreeBuffers", out buffers)) { buffers.Clear(); for (var i = 0; i < initialCapacity; i++) { buffers.Enqueue(new byte[resize]); } } VitaNexCore.ToConsole(owner.Name + "." + field + " Buffers: {0:#,0} -> {1:#,0}", bufferSize, resize); } } } }
public override SuperGump Send() { if (IsDisposed) { return(this); } return(VitaNexCore.TryCatchGet( () => { if (IsOpen) { InternalClose(this); } Compile(); Clear(); CompileLayout(Layout); Layout.ApplyTo(this); InvalidateOffsets(); InvalidateSize(); Compiled = true; if (Modal && ModalSafety && Buttons.Count == 0 && TileButtons.Count == 0) { CanDispose = true; CanClose = true; } OnBeforeSend(); Initialized = true; IsOpen = Avatar != null ? Avatar.SendGump(this, false) : User.SendGump(this, false); Hidden = false; if (IsOpen) { OnSend(); } else { OnSendFail(); } return this; }, e => { Console.WriteLine("SuperGump '{0}' could not be sent, an exception was caught:", GetType().FullName); VitaNexCore.ToConsole(e); IsOpen = false; Hidden = false; OnSendFail(); }) ?? this); }
public static double CountGold(bool includeStaff, out double accounts, out double checks, out double gold) { accounts = checks = gold = 0; NetState.Pause(); try { int g; double t; accounts = Accounts.GetAccounts().Aggregate( accounts, (c, a) => { if (!includeStaff && a.AccessLevel >= AccessLevel.Counselor) { return(c); } a.GetGoldBalance(out g, out t); return(c + t); }); foreach (var i in World.Items.Values.Where(i => !i.Deleted && (i is Gold || i is BankCheck))) { if (!includeStaff) { var p = i.RootParent as Mobile; if (p != null && p.AccessLevel >= AccessLevel.Counselor) { continue; } } if (i is Gold) { gold += i.Amount; } else if (i is BankCheck) { checks += ((BankCheck)i).Worth; } } } catch (Exception e) { VitaNexCore.ToConsole(e); accounts = checks = gold = 0; } NetState.Resume(); return(accounts + gold + checks); }
static UOFont() { Ascii = new UOFonts(UOEncoding.Ascii); Unicode = new UOFonts(UOEncoding.Unicode); for (var i = 0; i <= 1; i++) { VitaNexCore.ToConsole("[UOFont]: Preloaded {0}", Unicode[i]); } }
public static void WaitForWriteCompletion(bool forceWait) { if (_PendingWriters <= 0 || (!forceWait && !VitaNexCore.Disposed && !Core.Closing)) { return; } VitaNexCore.ToConsole("Waiting for {0:#,0} pending writers to finish...", _PendingWriters); while (_PendingWriters > 0) { Thread.Sleep(0); } }
private static void OnSerializeAsync(IAsyncResult r) { _Serialize.EndInvoke(r); lock (_TaskRoot) { _Tasks.Remove(r); } _Sync.Set(); var file = (FileInfo)r.AsyncState; var dir = file.Directory != null ? file.Directory.Name : String.Empty; VitaNexCore.ToConsole("Async write ended for '{0}/{1}'", dir, file.Name); }
protected void EndGamble(Mobile from) { if (from == null || from.Deleted) { return; } from.EndAction(GetType()); double a = Utility.RandomDouble(); double b = Math.Min(LuckCap, from.Luck) / (double)LuckCap; double c = a + b; Normalize(ref c); //Console.WriteLine("LDT: A = {0} B = {1} C = {2}", a, b, c); LuckyDipPrize prizeEntry = GetPrize(c); if (prizeEntry == null || prizeEntry.Disabled || prizeEntry.Equals(LuckyDipPrize.Empty)) { from.SendMessage(34, "Sorry {0}, you didn't win anything, better luck next time!", from.RawName); Delete(); return; } Item prize = prizeEntry.CreateInstance <Item>(); if (prize == null) { Prizes.Remove(prizeEntry); VitaNexCore.ToConsole( "WARNING: An instance of {0} could not be constructed in {1} at {2}", prizeEntry.Type.FullName, GetType().FullName, prizeEntry.GetType().FullName); from.SendMessage(34, "We couldn't process your ticket, please try again."); return; } from.SendMessage(85, "Congratulations, you won a prize! ({0})", prize.ResolveName(from)); ReplaceWith(prize); }
static ArtExtUtility() { try { var a = Assembly.LoadFrom("Ultima.dll"); var t = a.GetType("Ultima.Art"); if (t != null) { _UltimaArtGetStatic = t.GetMethods(BindingFlags.Static | BindingFlags.Public) .FirstOrDefault( m => m.Name == "GetStatic" && m.ReturnType.IsEqual <Bitmap>() && m.GetParameters().Length == 3); _UltimaArtMeasure = t.GetMethod("Measure", BindingFlags.Static | BindingFlags.Public); } } catch (Exception e) { VitaNexCore.ToConsole("UltimaArt could not load Ultima.dll or a member of Ultima.Art:"); VitaNexCore.ToConsole(e); } }
protected virtual void InitAssets() { var assets = PreloadAssets; if (assets == null || assets.Length == 0) { return; } var results = LoadAssets(assets); if (results == null || results.Length == 0) { return; } for (var i = 0; i < assets.Length && i < results.Length; i++) { if (!results[i]) { VitaNexCore.ToConsole("Warning: {0} failed to pre-load asset '{1}'", GetType(), assets[i]); } } }
public virtual SuperGump Send() { if (IsDisposed || _Sending) { return(this); } if (User == null || !User.IsOnline()) { return(this); } _Sending = true; return(VitaNexCore.TryCatchGet( () => { if (IsOpen) { InternalClose(this); } Compile(); Clear(); AddPage(); CompileLayout(Layout); Layout.ApplyTo(this); InvalidateAnimations(); InvalidateOffsets(); InvalidateSize(); Compiled = true; if (Modal && ModalSafety && Buttons.Count == 0 && TileButtons.Count == 0) { CanDispose = true; CanClose = true; } if (!OnBeforeSend()) { Close(true); _Sending = false; return this; } InternalCloseDupes(this); Initialized = true; IsOpen = User.SendGump(this, false); Hidden = false; if (IsOpen) { OnSend(); InternalSend(this); } else { OnSendFail(); } _Sending = false; return this; }, e => { Console.WriteLine("SuperGump '{0}' could not be sent, an exception was caught:", GetType().FullName); VitaNexCore.ToConsole(e); IsOpen = false; Hidden = false; OnSendFail(); _Sending = false; }) ?? this); }