示例#1
0
 public static void OnMainLoop(ulong frame)
 {
     try
     {
         NWNEventHandler.OnMainLoop(frame);
     }
     catch (Exception e)
     {
         Console.WriteLine(e.ToString());
     }
 }
示例#2
0
        public static int Bootstrap(IntPtr arg, int argLength)
        {
            if (arg == (IntPtr)0)
            {
                Console.WriteLine("Received NULL bootstrap structure");
                return(1);
            }

            var expectedLength = Marshal.SizeOf(typeof(BootstrapArgs));

            if (argLength < expectedLength)
            {
                Console.WriteLine(
                    $"Received bootstrap structure too small - actual={argLength}, expected={expectedLength}");
                return(1);
            }

            if (argLength > expectedLength)
            {
                Console.WriteLine(
                    $"WARNING: Received bootstrap structure bigger than expected - actual={argLength}, expected={expectedLength}");
                Console.WriteLine("         This usually means that native code version is ahead of the managed code");
            }

            NativeFunctions = Marshal.PtrToStructure <BootstrapArgs>(arg);

            AllHandlers handlers;

            handlers.MainLoop  = OnMainLoop;
            handlers.RunScript = OnRunScript;
            handlers.Closure   = OnClosure;
            RegisterHandlers(handlers);

            try
            {
                NWNEventHandler.OnStart();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }

            return(0);
        }
示例#3
0
        private static int OnRunScript(string script, uint oidSelf)
        {
            var ret = 0;

            OBJECT_SELF = oidSelf;
            ScriptContexts.Push(new ScriptContext {
                OwnerObject = oidSelf, ScriptName = script
            });
            try
            {
                ret = NWNEventHandler.OnRunScript(script, oidSelf);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }

            ScriptContexts.Pop();
            OBJECT_SELF = ScriptContexts.Count == 0 ? OBJECT_INVALID : ScriptContexts.Peek().OwnerObject;
            return(ret);
        }