Exemplo n.º 1
0
        private static void Main()
        {
            PluginState.Init();
            PluginState.IsLoaded = true;

            while (Game.IsLoading)
            {
                GameFiber.Sleep(500);
            }

            if (!Directory.Exists(@"Plugins\Spotlight Resources\"))
            {
                Directory.CreateDirectory(@"Plugins\Spotlight Resources\");
            }

            // let's keep using the Offsets.ini file for now
            //string vehSettingsFile = @"Plugins\Spotlight Resources\VehiclesSettings.xml";
            //if (!File.Exists(vehSettingsFile) && File.Exists(@"Plugins\Spotlight Resources\Offsets.ini"))
            //{
            //    // legacy
            //    vehSettingsFile = @"Plugins\Spotlight Resources\Offsets.ini";
            //}

            Settings = new Settings(@"Plugins\Spotlight Resources\General.ini",
                                    @"Plugins\Spotlight Resources\Offsets.ini",
                                    @"Plugins\Spotlight Resources\VisualSettings.xml",
                                    true);

            LoadSpotlightControllers();

            if (!(GameFunctions.Init() && GameMemory.Init() && GameOffsets.Init()))
            {
                Game.DisplayNotification($"~r~[ERROR] Spotlight: ~s~Failed to initialize, unloading...");
                Game.LogTrivial($"[ERROR] Failed to initialize, unloading...");
                Game.UnloadActivePlugin();
            }

            if (Settings.EnableLightEmissives)
            {
                VehiclesUpdateHook.Hook();
            }

            // when the queue array that the GetFreeLightDrawDataSlotFromQueue function accesses is full,
            // it uses the TLS to get an allocator to allocate memory for a bigger array,
            // therefore we copy the allocator pointers from the main thread TLS to our current thread TLS.
            WinFunctions.CopyTlsValues(WinFunctions.GetProcessMainThreadId(), WinFunctions.GetCurrentThreadId(), GameOffsets.TlsAllocator);

            if (Settings.EnableLightEmissives)
            {
                // TODO: find something better than this vehicles update hook to override the extralight emissives values
                // This function may execute multiple times per tick, which is not optimal
                VehiclesUpdateHook.VehiclesUpdate += OnVehiclesUpdate;
            }

            Game.LogTrivial("Initialized");

#if DEBUG
            bool f = false;
#endif
            while (true)
            {
                GameFiber.Yield();

#if DEBUG
                if (Game.LocalPlayer.Character.CurrentVehicle)
                {
                    if (Game.IsKeyDown(System.Windows.Forms.Keys.Y))
                    {
                        Game.LocalPlayer.Character.CurrentVehicle.IsPositionFrozen = f = !f;
                    }
                    else if (Game.IsKeyDown(System.Windows.Forms.Keys.D7))
                    {
                        Game.LocalPlayer.Character.CurrentVehicle.Rotation = new Rotator(45.0f, 0.0f, 0.0f);
                    }
                    else if (Game.IsKeyDown(System.Windows.Forms.Keys.D8))
                    {
                        Game.LocalPlayer.Character.CurrentVehicle.Rotation = new Rotator(0.0f, 45.0f, 0.0f);
                    }
                    else if (Game.IsKeyDown(System.Windows.Forms.Keys.D9))
                    {
                        Game.LocalPlayer.Character.CurrentVehicle.Rotation = new Rotator(0.0f, 0.0f, 45.0f);
                    }
                    else if (Game.IsKeyDown(System.Windows.Forms.Keys.D0))
                    {
                        Game.LocalPlayer.Character.CurrentVehicle.Rotation = Rotator.Zero;
                    }
                }
#endif

                Update();
            }
        }