Exemplo n.º 1
0
        public static void OnLoad()
        {
            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();
            }
            WinFunctions.CopyTlsValues(WinFunctions.GetProcessMainThreadId(), WinFunctions.GetCurrentThreadId(), GameOffsets.TlsAllocator0, GameOffsets.TlsAllocator1, GameOffsets.TlsAllocator2);

            bool  on       = false;
            Ped   p        = Game.LocalPlayer.Character;
            ulong shadowId = Render.GenerateShadowId();

            while (true)
            {
                GameFiber.Yield();
                if (Game.IsKeyDown(System.Windows.Forms.Keys.NumPad0))
                {
                    on = !on;
                }
                if (p && on)
                {
                    Game.DisplayHelp("Light: ~g~On");
                    Render.SpotLight(p.GetOffsetPositionFront(1), p.Direction,
                                     eLightFlags.CanRenderUnderground | eLightFlags.EnableVolume | eLightFlags.DisableSpecular,
                                     30, 45, 0.06f, 0.175f, 45, 5, 8.25f, System.Drawing.Color.Red, shadowId);
                }
            }
        }
Exemplo n.º 2
0
        static APISpotlightMgr()
        {
            bool gameFnInit  = GameFunctions.Init();
            bool gameMemInit = GameMemory.Init();

            if (!gameFnInit || !gameMemInit)
            {
                string str = "";
                if (!gameFnInit)
                {
                    str += nameof(GameFunctions);

                    if (!gameMemInit)
                    {
                        str += " and ";
                        str += nameof(GameMemory);
                    }
                }
                else if (!gameMemInit)
                {
                    str += nameof(GameMemory);
                }

                Game.LogTrivial($"[ERROR] Spotlight: Failed to initialize {str}");
            }

            spotlights = new List <APISpotlight>();
            fiber      = GameFiber.StartNew(UpdateSpotlights, "Spotlight API Manager");

            finalizer = new StaticFinalizer(Dispose);
        }
Exemplo n.º 3
0
        static APISpotlightMgr()
        {
            bool gameFnInit  = GameFunctions.Init();
            bool gameMemInit = GameMemory.Init();

            if (!gameFnInit || !gameMemInit)
            {
                string str = "";
                if (!gameFnInit)
                {
                    str += nameof(GameFunctions);

                    if (!gameMemInit)
                    {
                        str += " and ";
                        str += nameof(GameMemory);
                    }
                }
                else if (!gameMemInit)
                {
                    str += nameof(GameMemory);
                }

                Game.LogTrivial($"[ERROR] Spotlight: Failed to initialize {str}");
            }

            BaseSpotlight.CoronaPositionPtr  = (NativeVector3 *)Game.AllocateMemory(sizeof(NativeVector3) * 2);
            BaseSpotlight.CoronaDirectionPtr = BaseSpotlight.CoronaPositionPtr++;

            spotlights = new List <APISpotlight>();
            fiber      = GameFiber.StartNew(UpdateSpotlights, "Spotlight API Manager");

            finalizer = new StaticFinalizer(Dispose);
        }
Exemplo n.º 4
0
        static APISpotlightMgr()
        {
            if (!(GameFunctions.Init() && GameMemory.Init() && GameOffsets.Init()))
            {
                Game.LogTrivial($"[ERROR] Failed to initialize spotlight API");
                return;
            }

            spotlights = new List <APISpotlight>();
            fiber      = GameFiber.StartNew(UpdateSpotlights, "Spotlight API Manager");

            finalizer = new StaticFinalizer(Dispose);
        }
Exemplo n.º 5
0
        private static void Main()
        {
            while (Game.IsLoading)
            {
                GameFiber.Sleep(500);
            }

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

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

            LoadSpotlightControllers();

            bool gameFnInit  = GameFunctions.Init();
            bool gameMemInit = GameMemory.Init();

            if (gameFnInit)
            {
                Game.LogTrivialDebug($"Successful {nameof(GameFunctions)} init");
            }
            if (gameMemInit)
            {
                Game.LogTrivialDebug($"Successful {nameof(GameMemory)} init");
            }

            if (!gameFnInit || !gameMemInit)
            {
                string str = "";
                if (!gameFnInit)
                {
                    str += nameof(GameFunctions);

                    if (!gameMemInit)
                    {
                        str += " and ";
                        str += nameof(GameMemory);
                    }
                }
                else if (!gameMemInit)
                {
                    str += nameof(GameMemory);
                }

                Game.DisplayNotification($"~r~[ERROR] Spotlight: ~s~Failed to initialize {str}, unloading...");
                Game.LogTrivial($"[ERROR] Failed to initialize {str}, unloading...");
                Game.UnloadActivePlugin();
            }

            BaseSpotlight.CoronaPositionPtr  = (NativeVector3 *)Game.AllocateMemory(sizeof(NativeVector3) * 2);
            BaseSpotlight.CoronaDirectionPtr = BaseSpotlight.CoronaPositionPtr++;

            // 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(), GameMemory.TlsAllocatorOffset0, GameMemory.TlsAllocatorOffset1, GameMemory.TlsAllocatorOffset2);

            while (true)
            {
                GameFiber.Yield();

                Update();
            }
        }
Exemplo n.º 6
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();
            }
        }