//Executes a GameDLL command, Idea taken from jultima http://code.google.com/p/jultima/ public List <object> _executeCommand(bool ReturnResults, string CommandName, object[] args) { // Maybe return bool and results as an Out? List <object> Results = new List <object>(); UODLL.SetTop(UOHandle, 0); UODLL.PushStrVal(UOHandle, "Call"); UODLL.PushStrVal(UOHandle, CommandName); foreach (var o in args) { if (o is Int32) // (o.GetType() == typeof(int)) { UODLL.PushInteger(UOHandle, (int)o); } else if (o is string) { UODLL.PushStrVal(UOHandle, (string)o); } else if (o is bool) { UODLL.PushBoolean(UOHandle, (bool)o); } } if (UODLL.Execute(UOHandle) != 0) { return(null); } if (!ReturnResults) { return(null); } int objectcnt = UODLL.GetTop(UOHandle); for (int i = 1; i <= objectcnt; i++) { int gettype = UODLL.GetType(UOHandle, 1); switch (gettype) { case 1: Results.Add(UODLL.GetBoolean(UOHandle, i).ToString()); break; case 3: Results.Add(UODLL.GetInteger(UOHandle, i).ToString()); break; case 4: Results.Add(Marshal.PtrToStringAnsi(UODLL.GetString(UOHandle, i))); break; default: throw new NotImplementedException(); break; } } return(Results); }
//Get and Set Handlers #region GetterSetterHelpers private bool GetBoolean(string command) { UODLL.SetTop(UOHandle, 0); UODLL.PushStrVal(UOHandle, "Get"); UODLL.PushStrVal(UOHandle, command); var result = UODLL.Execute(UOHandle); if (result == 0) { return(UODLL.GetBoolean(UOHandle, 1)); } else { return(false); } }