public FocusModel Copy(int XChange = 0, int YChange = 0)
        {
            Script newScript = new Script();

            newScript.Analyse(InternalScript.Parse());
            return(new FocusModel
            {
                Image = Image,
                UniqueName = UniqueName,
                Text = Text,
                X = CoordinatesRelativeTo != null? X : X + XChange,
                Y = CoordinatesRelativeTo != null ? Y : Y + YChange,
                Cost = Cost,
                InternalScript = newScript,
                Note = Note
            });
        }
        internal static Duality.ContentRef <Script> GetScript <T>() where T : InternalScript, new()
        {
            if (_scriptsCache == null)
            {
                _scriptsCache = new Dictionary <string, Duality.ContentRef <Script> >();
            }

            Type scriptType = typeof(T);

            if (!_scriptsCache.ContainsKey(scriptType.FullName))
            {
                InternalScript newScript = scriptType.GetConstructor(Type.EmptyTypes).Invoke(null) as InternalScript;
                _scriptsCache.Add(scriptType.FullName, new Duality.ContentRef <Script>(newScript));
            }

            return(_scriptsCache[scriptType.FullName]);
        }
Exemplo n.º 3
0
        public static void Initialize()
        {
            try
            {
                if (Kernel32.GetModuleHandle("game.dll") == IntPtr.Zero)
                {
                    throw new Exception("Attempted to initialize " + typeof(GameHack).Name + " before 'game.dll' has been loaded.");
                }

                var sw = (Stopwatch)null;

                sw = new Stopwatch();
                Trace.WriteLine("Initializing addresses . . .");
                Trace.Indent();
                sw.Start();
                GameAddresses.Initialize();
                sw.Stop();
                Trace.Unindent();
                Trace.WriteLine(" - Done! (" + sw.ElapsedMilliseconds + " ms)");

                sw = new Stopwatch();
                Trace.WriteLine("Initializing functions . . .");
                Trace.Indent();
                sw.Start();
                GameFunctions.Initialize();
                sw.Stop();
                Trace.Unindent();
                Trace.WriteLine(" - Done! (" + sw.ElapsedMilliseconds + " ms)");

                sw = new Stopwatch();
                Trace.WriteLine("Initializing Game api . . .");
                Trace.Indent();
                sw.Start();
                InternalGame.Initialize();
                sw.Stop();
                Trace.Unindent();
                Trace.WriteLine(" - Done! (" + sw.ElapsedMilliseconds + " ms)");

                sw = new Stopwatch();
                Trace.WriteLine("Initializing JassMachine api . . .");
                Trace.Indent();
                sw.Start();
                InternalScript.Initialize();
                sw.Stop();
                Trace.Unindent();
                Trace.WriteLine(" - Done! (" + sw.ElapsedMilliseconds + " ms)");

                sw = new Stopwatch();
                Trace.WriteLine("Initializing Interface api . . .");
                Trace.Indent();
                sw.Start();
                InternalInterface.Initialize();
                sw.Stop();
                Trace.Unindent();
                Trace.WriteLine(" - Done! (" + sw.ElapsedMilliseconds + " ms)");

                sw = new Stopwatch();
                Trace.WriteLine("Initializing Input api . . .");
                Trace.Indent();
                sw.Start();
                InternalInput.Initialize();
                sw.Stop();
                Trace.Unindent();
                Trace.WriteLine(" - Done! (" + sw.ElapsedMilliseconds + " ms)");

                sw = new Stopwatch();
                Trace.WriteLine("Initializing Natives api . . .");
                Trace.Indent();
                sw.Start();
                InternalNatives.Initialize();
                sw.Stop();
                Trace.Unindent();
                Trace.WriteLine(" - Done! (" + sw.ElapsedMilliseconds + " ms)");

                GameHack.IsReady = true;
                GameHack.OnReady();
            }
            catch (Exception exception)
            {
                MessageBox.Show(
                    "Fatal exception!" + Environment.NewLine +
                    exception + Environment.NewLine +
                    "Aborting execution!",
                    typeof(GameHack) + ".Initialize()", MessageBoxButton.OK, MessageBoxImage.Error);
                Process.GetCurrentProcess().Kill();
            }
        }