示例#1
0
        private static int CameraBuildPerspClipPlanesImpl(RWCamera *rwCamera)
        {
            try
            {
                // The current aspect ratio.
                float currentAspectRatio   = GetCurrentAspectRatio();
                float aspectRatioScale     = currentAspectRatio / OriginalAspectRatio;
                float aspectLimitMultipler = OriginalAspectRatio / _graphicsSettings.AspectRatioLimit;

                // Stretch X or Y depending on aspect ratio.
                if (currentAspectRatio >= _graphicsSettings.AspectRatioLimit)
                {
                    (*rwCamera).viewWindow.x = (*rwCamera).viewWindow.x * aspectRatioScale;
                }
                else
                {
                    if (_graphicsSettings.AlternateAspectScaling)
                    {
                        (*rwCamera).viewWindow.x = (*rwCamera).viewWindow.x / (aspectLimitMultipler);
                        (*rwCamera).viewWindow.y = (*rwCamera).viewWindow.y * ((1F / aspectLimitMultipler) / aspectRatioScale);
                    }
                    else
                    {
                        (*rwCamera).viewWindow.y = (*rwCamera).viewWindow.y * (1F / aspectRatioScale);
                    }
                }

                // Call original
                int result = _cameraBuildPerspClipPlanesHook.OriginalFunction(rwCamera);

                // Unstretch X or Y depending on aspect ratio.
                if (currentAspectRatio >= _graphicsSettings.AspectRatioLimit)
                {
                    (*rwCamera).viewWindow.x = (*rwCamera).viewWindow.x / aspectRatioScale;
                }
                else
                {
                    if (_graphicsSettings.AlternateAspectScaling)
                    {
                        (*rwCamera).viewWindow.x = (*rwCamera).viewWindow.x * (aspectLimitMultipler);
                        (*rwCamera).viewWindow.y = (*rwCamera).viewWindow.y / ((1F / aspectLimitMultipler) / aspectRatioScale);
                    }
                    else
                    {
                        (*rwCamera).viewWindow.y = (*rwCamera).viewWindow.y / (1F / aspectRatioScale);
                    }
                }


                return(result);
            }
            catch
            {
                return(_cameraBuildPerspClipPlanesHook.OriginalFunction(rwCamera));
            }
        }
示例#2
0
        private int OnPresent(IntPtr swapChainPointer, int syncInterval, int flags)
        {
            if (Initialized)
            {
                return(_presentHook.OriginalFunction(swapChainPointer, syncInterval, flags));
            }

            var device = new SwapChain(swapChainPointer).GetDevice <Device>();

            OnInitialized?.Invoke(device, device.ImmediateContext);

            Initialized = true;

            return(_presentHook.OriginalFunction(swapChainPointer, syncInterval, flags));
        }
示例#3
0
        /// <summary>
        /// Executes original function and checks for possible increment of player score.
        /// </summary>
        private char CheckScoreIncrementHookFunction(void *thispointer)
        {
            char result = _tObjTeamExecHook.OriginalFunction(thispointer);

            // Custom Code
            VictoryStruct currentVictories = *_currentVictoryCount;

            if (currentVictories.PlayerOne > _lastVictoryCount.PlayerOne)
            {
                _playerOneTotalVictories++;
            }

            if (currentVictories.PlayerTwo > _lastVictoryCount.PlayerTwo)
            {
                _playerTwoTotalVictories++;
            }

            if (currentVictories.PlayerThree > _lastVictoryCount.PlayerThree)
            {
                _playerThreeTotalVictories++;
            }

            if (currentVictories.PlayerFour > _lastVictoryCount.PlayerFour)
            {
                _playerFourTotalVictories++;
            }

            _lastVictoryCount = currentVictories;

            // End of Custom Code

            return(result);
        }
示例#4
0
        /// <summary>
        /// Implements the hook for Sonic Heroes' malloc function, adding the address allocated to the set and
        /// calling any other necessary delegates.
        /// </summary>
        /// <param name="bytes">The amount of bytes to be allocated.</param>
        /// <returns>The memory address of allocation</returns>
        private void *MallocHookImpl(int bytes)
        {
            // Call our own delegate and get potential new return value.
            if (BeforeMallocDelegate != null)
            {
                void *potentialResult = BeforeMallocDelegate(bytes);
                if ((int)potentialResult > 0)
                {
                    return(potentialResult);
                }
            }


            // Call original allocator.
            void *newMemoryLocation = _mallocHook.OriginalFunction(bytes);

            // Some extra prep.
            int newMemoryLocationCopy = (int)newMemoryLocation;
            var memoryAddressDetails  = new MemoryAddressDetails(bytes);

            // Add to dictionary.
            AllocationList[newMemoryLocationCopy] = memoryAddressDetails;

            // Call subscribed delegates.
            MemoryTracer thisTracer = this;

            AfterMallocDelegate?.Invoke(ref thisTracer, ref newMemoryLocationCopy, ref memoryAddressDetails);

            // Return
            return(newMemoryLocation);
        }
示例#5
0
        /// <summary>
        /// Contains the implementation of the NtCreateFile hook.
        /// Conditionally redirects oncoming files through changing ObjectName inside the objectAttributes instance.
        /// </summary>
        private static int NtCreateFileImpl(out IntPtr filehandle, FileAccess access, ref OBJECT_ATTRIBUTES objectAttributes, ref IO_STATUS_BLOCK ioStatus, ref long allocSize, uint fileattributes, FileShare share, uint createDisposition, uint createOptions, IntPtr eaBuffer, uint eaLength)
        {
            // Retrieves the file name that we are attempting to access.
            string oldFileName = objectAttributes.ObjectName.ToString();

            // Sometimes life can be a bit ugly :/
            if (oldFileName.StartsWith("\\??\\", StringComparison.InvariantCultureIgnoreCase))
            {
                oldFileName = oldFileName.Replace("\\??\\", "");
            }

            // Here we simply check whether the file path is in the dictionary,
            // if it is, we replace it.
            if (_remapperDictionary.TryGetValue(Path.GetFullPath(oldFileName), out string newFileName))
            {
                #if DEBUG
                Bindings.PrintInfo($"[NTCF] File Redirection: {oldFileName} => {newFileName}");
                #endif

                objectAttributes.ObjectName = new UNICODE_STRING("\\??\\" + newFileName);

                // Since are providing an absolute path, we need to clear the root directory since our path is not relative.
                objectAttributes.RootDirectory = IntPtr.Zero;
            }

            return(IntPtr.Size == 4 ?
                   _ntCreateFileHook.OriginalFunction(out filehandle, access, ref objectAttributes, ref ioStatus, ref allocSize, fileattributes, share, createDisposition, createOptions, eaBuffer, eaLength) :
                   _ntCreateFileHook64.OriginalFunction(out filehandle, access, ref objectAttributes, ref ioStatus, ref allocSize, fileattributes, share, createDisposition, createOptions, eaBuffer, eaLength));
        }
示例#6
0
        /// <summary>
        /// Contains the implementation of our NtCreateFile hook.
        /// Simply prints the file name to the console and calls + returns the original function.
        /// </summary>
        /// <returns></returns>
        private static int NtCreateFileImpl(out IntPtr filehandle, FileAccess access, ref OBJECT_ATTRIBUTES objectAttributes, ref IO_STATUS_BLOCK ioStatus, ref long allocSize, uint fileattributes, FileShare share, uint createDisposition, uint createOptions, IntPtr eaBuffer, uint eaLength)
        {
            Bindings.PrintInfo($"[NTCF] Loading File {objectAttributes.ObjectName.ToString()}");

            return(IntPtr.Size == 4 ?
                   _ntCreateFileHook.OriginalFunction(out filehandle, access, ref objectAttributes, ref ioStatus, ref allocSize, fileattributes, share, createDisposition, createOptions, eaBuffer, eaLength) :
                   _ntCreateFileHook64.OriginalFunction(out filehandle, access, ref objectAttributes, ref ioStatus, ref allocSize, fileattributes, share, createDisposition, createOptions, eaBuffer, eaLength));
        }
示例#7
0
        /* Hook DirectX Device Reset */
        private int ResetDeviceImpl(IntPtr device, ref PresentParameters pPresentationParameters)
        {
            pPresentationParameters = SetPresentParameters(ref pPresentationParameters);
            int result = _resetDeviceHook.OriginalFunction(device, ref pPresentationParameters);

            SetDeviceParameters(device);
            return(result);
        }
示例#8
0
        /// <summary>
        /// Contains the implementation of the CreateFileW hook.
        /// Simply prints the file name to the console and calls + returns the original function.
        /// </summary>
        private static IntPtr CreateFileWImpl(string filename, FileAccess access, FileShare share, IntPtr securityAttributes, FileMode creationDisposition, FileAttributes flagsAndAttributes, IntPtr templateFile)
        {
            // Here we simply check whether the file path is in the dictionary,
            // if it is, we replace it.
            if (!filename.StartsWith(@"\\?\"))
            {
                if (_remapperDictionary.TryGetValue(Path.GetFullPath(filename), out string newFileName))
                {
                    return(IntPtr.Size == 4 ?
                           _createFileWHook.OriginalFunction(newFileName, access, share, securityAttributes, creationDisposition, flagsAndAttributes, templateFile) :
                           _createFileWHook64.OriginalFunction(newFileName, access, share, securityAttributes, creationDisposition, flagsAndAttributes, templateFile));
                }
            }

            return(IntPtr.Size == 4 ?
                   _createFileWHook.OriginalFunction(filename, access, share, securityAttributes, creationDisposition, flagsAndAttributes, templateFile) :
                   _createFileWHook64.OriginalFunction(filename, access, share, securityAttributes, creationDisposition, flagsAndAttributes, templateFile));
        }
        private void OnDrawIndexed(IntPtr deviceContextPointer, int indexCount, int startIndex, int baseVertexLocation)
        {
            if (indexCount < 7)
            {
                _drawIndexedHook.OriginalFunction(deviceContextPointer, indexCount, startIndex, baseVertexLocation);
                return;
            }

            if (!OnlyRenderSavedModels)
            {
                _drawIndexedHook.OriginalFunction(deviceContextPointer, indexCount, startIndex, baseVertexLocation);
            }

            var currentItem = GetCurrentItem(indexCount);

            if (IsLoggerEnabled)
            {
                if (_selectedByteWidth == _deviceContext.GetIndexByteWidth() / IndexByteWidthDivider)
                {
                    if (!_modelsInScene.Contains(currentItem))
                    {
                        _modelsInScene.Add(currentItem);
                    }

                    if (IsCurrentModel(currentItem, _currentIndex))
                    {
                        DrawCustom(indexCount, startIndex, baseVertexLocation, Color.Red);
                        return;
                    }

                    DrawCustom(indexCount, startIndex, baseVertexLocation, Color.White);
                    return;
                }
            }

            lock (SavedModels)
            {
                if (IsSavedModel(currentItem, out var index))
                {
                    DrawCustom(indexCount, startIndex, baseVertexLocation, SavedModels[index].Color);
                }
            }
        }
示例#10
0
        private static void RwCameraSetViewWindowImpl(RWCamera *cameraPointer, RWAspect.RWView *view)
        {
            if (!_resizeHookSetup)
            {
                SetupResizeHook();
            }

            try
            {
                _rwCameraSetViewWindowHook.OriginalFunction(cameraPointer, view);

                // Get aspect.
                float currentAspectRatio   = GetCurrentAspectRatio();
                float aspectRatioScale     = currentAspectRatio / OriginalAspectRatio;
                float aspectLimitMultipler = OriginalAspectRatio / _graphicsSettings.AspectRatioLimit; // Forced aspect ratio.

                // Unstretch X or Y depending on aspect ratio.
                if (currentAspectRatio >= _graphicsSettings.AspectRatioLimit)
                {
                    (*cameraPointer).recipViewWindow.x = (*cameraPointer).recipViewWindow.x / aspectRatioScale;
                }
                else
                {
                    if (_graphicsSettings.AlternateAspectScaling)
                    {
                        // Squish X as if the window was of the aspect ratio of aspectLimitMultipler regardless of whether it is or not.
                        // Then Squish Y accordingly.
                        (*cameraPointer).recipViewWindow.x = (*cameraPointer).recipViewWindow.x * (aspectLimitMultipler);
                        (*cameraPointer).recipViewWindow.y = (*cameraPointer).recipViewWindow.y / ((1F / aspectLimitMultipler) / aspectRatioScale);
                    }
                    else
                    {
                        // Squish more contents in from the top.
                        (*cameraPointer).recipViewWindow.y = (*cameraPointer).recipViewWindow.y / (1F / aspectRatioScale);
                    }
                }
            }
            catch
            {
                _rwCameraSetViewWindowHook.OriginalFunction(cameraPointer, view);
            }
        }
示例#11
0
        /// <summary>
        /// Contains the implementation of the CreateFileW hook.
        /// Simply prints the file name to the console and calls + returns the original function.
        /// </summary>
        private static IntPtr CreateFileWImpl(string filename, FileAccess access, FileShare share, IntPtr securityAttributes, FileMode creationDisposition, FileAttributes flagsAndAttributes, IntPtr templateFile)
        {
            // This function delegate is automatically assigned by the Reloaded DLL Template Initializer
            // It simply prints to the console of the Mod Loader's Loader (which is a local server).
            // The if statement filters out non-files such as HID devices.
            if (!filename.StartsWith(@"\\?\"))
            {
                Bindings.PrintInfo($"[CFW] Loading File {filename}");
            }

            return(IntPtr.Size == 4 ?
                   _createFileWHook.OriginalFunction(filename, access, share, securityAttributes, creationDisposition, flagsAndAttributes, templateFile) :
                   _createFileWHook64.OriginalFunction(filename, access, share, securityAttributes, creationDisposition, flagsAndAttributes, templateFile));
        }
示例#12
0
        /* Hook DirectX Device Creation */
        private IntPtr CreateDeviceImpl(IntPtr direct3DPointer, uint adapter, DeviceType deviceType, IntPtr hFocusWindow, CreateFlags behaviorFlags, ref PresentParameters pPresentationParameters, int **ppReturnedDeviceInterface)
        {
            // Get D3D Interface (IDirect3D9)
            Direct3D d3d = new Direct3D(direct3DPointer);

            // Enable Hardware Vertex Processing..
            if (_dx9Settings.HardwareVertexProcessing)
            {
                behaviorFlags = behaviorFlags & ~CreateFlags.SoftwareVertexProcessing;
                behaviorFlags = behaviorFlags | CreateFlags.HardwareVertexProcessing;
            }

            // Get and Set max MSAA Quality
            if (_dx9Settings.EnableMSAA)
            {
                bool msaaAvailable = d3d.CheckDeviceMultisampleType(0, DeviceType.Hardware, pPresentationParameters.BackBufferFormat,
                                                                    pPresentationParameters.Windowed, (MultisampleType)_dx9Settings.MSAALevel, out maxMSAAQuality);

                if (!msaaAvailable)
                {
                    Bindings.PrintError($"The user set MSAA Setting ({_dx9Settings.MSAALevel} Samples) is not supported on this hardware configuration.");
                    Bindings.PrintError($"MSAA will be disabled.");
                    _dx9Settings.EnableMSAA = false;
                }

                if (maxMSAAQuality > 0)
                {
                    maxMSAAQuality -= 1;
                }
            }

            // Check for AF Compatibility
            if (_dx9Settings.EnableAF)
            {
                var capabilities = d3d.GetDeviceCaps(0, DeviceType.Hardware);
                if (_dx9Settings.AFLevel > capabilities.MaxAnisotropy)
                {
                    Bindings.PrintError($"The user set Anisotropic Filtering Setting ({_dx9Settings.AFLevel} Samples) is not supported on this hardware configuration.");
                    Bindings.PrintError($"AF will be disabled.");
                    _dx9Settings.EnableAF = false;
                }
            }

            // Set present parameters.
            pPresentationParameters = SetPresentParameters(ref pPresentationParameters);

            return(_createDeviceHook.OriginalFunction(direct3DPointer, adapter, deviceType, hFocusWindow, behaviorFlags, ref pPresentationParameters, ppReturnedDeviceInterface));
        }
示例#13
0
        /// <summary>
        /// No, we don't need to restart app.
        /// </summary>
        private static bool FunctionDelegate(uint appid)
        {
            // Write the Steam AppID to a local file.
            File.WriteAllText(SteamAppId, $"{appid}");

            if (IntPtr.Size == 4)
            {
                restartIfNecessaryHook32.OriginalFunction(appid);
            }
            else
            {
                restartIfNecessaryHook64.OriginalFunction(appid);
            }

            return(false);
        }
示例#14
0
        /// <summary>
        /// Implements the hook for Sonic Heroes' free function, removing the address allocated from the set and
        /// calling any other necessary delegates.
        /// </summary>
        /// <param name="memoryAddress">The memory address to be freed from memory.</param>
        private void FreeHookImpl(void *memoryAddress)
        {
            // Call original deallocator.
            _freeHook.OriginalFunction(memoryAddress);

            // They can sometimes pass 0 in.
            if (AllocationList.ContainsKey((int)memoryAddress))
            {
                // Call subscribed delegates.
                MemoryTracer         thisTracer        = this;
                int                  memoryAddressCopy = (int)memoryAddress;
                MemoryAddressDetails addressDetails    = AllocationList[memoryAddressCopy];

                // Remove from dictionary and call delegate.
                AllocationList.Remove((int)memoryAddress);
                AfterFreeDelegate?.Invoke(ref thisTracer, ref memoryAddressCopy, ref addressDetails);
            }
        }
示例#15
0
        /// <summary>
        /// Override our fullscreen on/off preference after the game calls the original config reader.
        /// </summary>
        /// <returns></returns>
        private static int ReadConfigFromIniImpl(char *somePath)
        {
            int result = _readConfigFromIniHook.OriginalFunction(somePath);

            // Override our fullscreen preference.
            *_configFileFullscreen = Convert.ToInt32(_graphicsSettings.Fullscreen);

            // Set default settings.
            *_G_3DSound      = _graphicsSettings.DefaultSettings.ThreeDimensionalSound;
            *_G_BgmOn        = _graphicsSettings.DefaultSettings.BGMOn;
            *_G_BgmVolume    = (byte)_graphicsSettings.DefaultSettings.BGMVolume;
            *_G_CharmyShutup = _graphicsSettings.DefaultSettings.CharmyShutup;
            *_G_CheapShadow  = !_graphicsSettings.DefaultSettings.SoftShadows;
            *_G_Language     = (byte)_graphicsSettings.DefaultSettings.Language;
            *_G_MouseControl = _graphicsSettings.DefaultSettings.MouseControl;
            *_G_SfxOn        = _graphicsSettings.DefaultSettings.SFXOn;
            *_G_SfxVolume    = (byte)_graphicsSettings.DefaultSettings.SFXVolume;

            return(result);
        }
示例#16
0
        /// <summary>
        /// A crashfix for running Heroes at extreme resolutions, patches the resolution the rasters are created at.
        /// </summary>
        /// <returns></returns>
        private static int TObjCameraInitHook(int *thisPointer, int cameraLimit)
        {
            int resolutionXBackup = *_resolutionX;
            int resolutionYBackup = *_resolutionY;
            int greaterResolution = resolutionXBackup > resolutionYBackup ? resolutionXBackup : resolutionYBackup;

            // Get the window size.
            Structures.WinapiRectangle windowLocation = WindowProperties.GetWindowRectangle(GameProcess.Process.MainWindowHandle);

            // Set the window size.
            WindowFunctions.MoveWindow(GameProcess.Process.MainWindowHandle, windowLocation.LeftBorder,
                                       windowLocation.TopBorder, greaterResolution, (int)(greaterResolution / OriginalAspectRatio), false);

            int result = _someTitlecardCreateHook.OriginalFunction(thisPointer, cameraLimit);

            // Re-set the window size.
            WindowFunctions.MoveWindow(GameProcess.Process.MainWindowHandle, windowLocation.LeftBorder,
                                       windowLocation.TopBorder, resolutionXBackup, resolutionYBackup, false);

            return(result);
        }
示例#17
0
 private int MoviePlayImpl(int *thispointer)
 {
     IsPlayingFMV = true;
     return(_moviePlayHook.OriginalFunction(thispointer));
 }
示例#18
0
 private static ONEFILE *OneFileLoadCameraTmbImpl(int fileIndex, void *addressToDecompressTo, ONEFILE *thisPointer)
 {
     addressToDecompressTo = CheckBufferSize(fileIndex, addressToDecompressTo, thisPointer);
     return(OneFileLoadCameraTmbHook.OriginalFunction(fileIndex, addressToDecompressTo, thisPointer));
 }
示例#19
0
 private static int OneFileLoadMaestroImpl(void *addressToDecompressTo, ONEFILE *thisPointer, int fileIndex)
 {
     addressToDecompressTo = CheckBufferSize(fileIndex, addressToDecompressTo, thisPointer);
     return(OneFileLoadMaestroHook.OriginalFunction(addressToDecompressTo, thisPointer, fileIndex));
 }
示例#20
0
 private static int OneFileLoadDeltaMorphImpl(int fileIndex, void *addressToDecompressTo, ONEFILE *thisPointer)
 {
     addressToDecompressTo = CheckBufferSize(fileIndex, addressToDecompressTo, thisPointer);
     return(OneFileLoadDeltaMorphHook.OriginalFunction(fileIndex, addressToDecompressTo, thisPointer));
 }
示例#21
0
 private int MovieEndImpl()
 {
     IsPlayingFMV = false;
     return(_movieEndHook.OriginalFunction());
 }