private bool RenderPrimitiveImpl(int a1, char *a2, int a3) { // Get vertex buffer. bool shift = false; if (_shiftOrthographicProjection.Count > 0) { shift = _shiftOrthographicProjection.Dequeue(); } if (shift || _shiftProjectionFlag) { var vertexBufferPtr = *(VertexBufferSubmission **)0xAA5048; var vertexBufferSubmissionThing = vertexBufferPtr->SubmissionThing != (void *)0 ? (*vertexBufferPtr).SubmissionThing : (VertexBufferSubmissionDetails *)Fun_GetVertexBufferSubmission.GetWrapper()(); // Convert.ToInt32 performs rounding! var extraLeftBorder = (short)(Convert.ToInt32(AspectConverter.GetBorderWidthX(ActualAspectRatio, CurrentHeight) / 2)); var extraTopBorder = (short)(Convert.ToInt32(AspectConverter.GetBorderHeightY(ActualAspectRatio, CurrentWidth) / 2)); vertexBufferSubmissionThing->X += extraLeftBorder; vertexBufferSubmissionThing->Y += extraTopBorder; // Execute var result = _renderPrimitiveHook.OriginalFunction(a1, a2, a3); vertexBufferSubmissionThing->X -= extraLeftBorder; vertexBufferSubmissionThing->Y -= extraTopBorder; return(result); } return(_renderPrimitiveHook.OriginalFunction(a1, a2, a3)); }
private int TObjCameraInit(IntPtr thisPointer, int camLimit) { // Backup old resolution. var windowHandle = Variables.WindowHandle; if (!windowHandle.IsNull) { User32_Gdi.GetWindowRect(windowHandle, out var windowRect); int resolutionXBackup = windowRect.Width; int resolutionYBackup = windowRect.Height; // Get new resolution int greaterResolution = resolutionXBackup > resolutionYBackup ? resolutionXBackup : resolutionYBackup; AspectConverter.WidthToResolution(greaterResolution, AspectConverter.OriginalGameAspect, out var resolution); // Temp resize window and execute. User32_Gdi.MoveWindow(windowHandle, windowRect.left, windowRect.top, resolution.Width, resolution.Height, false); int result = _cameraInitHook.OriginalFunction(thisPointer, camLimit); // Restore window. User32_Gdi.MoveWindow(windowHandle, windowRect.left, windowRect.top, resolutionXBackup, resolutionYBackup, false); return(result); } return(_cameraInitHook.OriginalFunction(thisPointer, camLimit)); }
private int QueryInformationFileImpl(IntPtr hfile, out Native.Native.IO_STATUS_BLOCK ioStatusBlock, void *fileInformation, uint length, Native.Native.FileInformationClass fileInformationClass) { lock (_getInfoLock) { if (_handleToInfoMap.ContainsKey(hfile) && fileInformationClass == Native.Native.FileInformationClass.FileStandardInformation) { var result = _getFileSizeHook.OriginalFunction(hfile, out ioStatusBlock, fileInformation, length, fileInformationClass); var information = (Native.Native.FILE_STANDARD_INFORMATION *)fileInformation; var newFileSize = OnGetFileSize(hfile); if (newFileSize != -1) { information->EndOfFile = newFileSize; information->AllocationSize = Utilities.RoundUp(newFileSize, 4096); } #if DEBUG Console.WriteLine($"[ONEHook] QueryInformationFile: Alloc Size: {information->AllocationSize}, EndOfFile: {information->EndOfFile}"); #endif return(result); } return(_getFileSizeHook.OriginalFunction(hfile, out ioStatusBlock, fileInformation, length, fileInformationClass)); } }
private unsafe IntPtr EndScene(IntPtr device) { if (!_initialized) { // Try our best to initialize if not hooked at boot. // This can fail though if window handle is only passed in presentation parameters. if (_windowHandle == IntPtr.Zero) { var dev = new Device(device); _windowHandle = dev.CreationParameters.HFocusWindow; dev.Dispose(); } Misc.Debug.WriteLine($"EndScene Window Handle {(long)_windowHandle:X}"); if (_windowHandle == IntPtr.Zero) { return(_endSceneHook.OriginalFunction(device)); } ImGui.ImGuiImplDX9Init((void *)device); _initialized = true; } ImGui.ImGuiImplDX9NewFrame(); ImguiHook.NewFrame(); ImGui.ImGuiImplDX9RenderDrawData(ImGui.GetDrawData()); return(_endSceneHook.OriginalFunction(device)); }
/// <summary> /// <see cref="SonicHeroes.Utils.StageInjector.Hooks.Hooks.InitPath"/> /// </summary> private bool InitSplineImpl(Spline **splinePointerArray) { if (TryGetCurrentStage(out StageBase stage)) { if (stage.Splines != null) { return(_initPathHook.OriginalFunction(stage.Splines)); } } return(_initPathHook.OriginalFunction(splinePointerArray)); }
private unsafe IntPtr PresentHook(IntPtr swapChainPtr, int syncInterval, PresentFlags flags) { var swapChain = new SwapChain(swapChainPtr); var device = swapChain.GetDevice <Device>(); if (!_initialized) { _windowHandle = swapChain.Description.OutputHandle; ImGui.ImGuiImplDX11Init((void *)device.NativePointer, (void *)device.ImmediateContext.NativePointer); var backBuffer = swapChain.GetBackBuffer <Texture2D>(0); _renderTargetView = new RenderTargetView(device, backBuffer); _initialized = true; backBuffer.Dispose(); } ImGui.ImGuiImplDX11NewFrame(); ImguiHook.NewFrame(); device.ImmediateContext.OutputMerger.SetRenderTargets(_renderTargetView); ImGui.ImGuiImplDX11RenderDrawData(ImGui.GetDrawData()); swapChain.Dispose(); device.Dispose(); return(_presentHook.OriginalFunction(swapChainPtr, syncInterval, flags)); }
public void TestHookAddWithBranch() { int Hookfunction01(int a, int b) { return(_addWithBranchHook01.OriginalFunction(a, b) + 1); } int Hookfunction02(int a, int b) { return(_addWithBranchHook02.OriginalFunction(a, b) + 1); } _addWithBranchHook01 = ReloadedHooks.Instance.CreateHook <NativeCalculator.AddFunction>(Hookfunction01, (long)_nativeCalculator.AddWithBranch).Activate(); _addWithBranchHook02 = ReloadedHooks.Instance.CreateHook <NativeCalculator.AddFunction>(Hookfunction02, (long)_nativeCalculator.AddWithBranch).Activate(); for (int x = 0; x < 100; x++) { for (int y = 1; y < 100;) { int expected = ((x + y) + 1) + 1; int result = _addWithBranchFunction(x, y); Assert.Equal(expected, result); y += 2; } } }
private unsafe int NtReadFileImpl(IntPtr handle, IntPtr hEvent, IntPtr *apcRoutine, IntPtr *apcContext, ref Native.Native.IO_STATUS_BLOCK ioStatus, byte *buffer, uint length, long *byteOffset, IntPtr key) { lock (_readLock) { if (_handleToInfoMap.ContainsKey(handle)) { long offset = _handleToInfoMap[handle].FilePointer; long requestedOffset = byteOffset != (void *)0 ? *byteOffset : -1; #if DEBUG Console.WriteLine($"[AFSHook] Read Request, Buffer: {(long)buffer:X}, Length: {length}, Offset (via SetInformationFile): {offset}, Requested Offset (Optional): {requestedOffset}"); #endif DisableRedirectionHooks(); bool result; int numReadBytes; result = requestedOffset != -1 ? OnAfsReadData(handle, buffer, length, requestedOffset, out numReadBytes) : OnAfsReadData(handle, buffer, length, offset, out numReadBytes); EnableRedirectionHooks(); if (result) { offset += length; SetInformationFileImpl(handle, out _, &offset, sizeof(long), Native.Native.FileInformationClass.FilePositionInformation); // Set number of read bytes. ioStatus.Status = 0; ioStatus.Information = new IntPtr(numReadBytes); return(0); } } return(_readFileHook.OriginalFunction(handle, hEvent, apcRoutine, apcContext, ref ioStatus, buffer, length, byteOffset, key)); } }
public void TestHookAdd() { int Hookfunction01(int a, int b) { return(_addHook01.OriginalFunction(a, b) + 1); } int Hookfunction02(int a, int b) { return(_addHook02.OriginalFunction(a, b) + 1); } _addHook01 = new Hook <Calculator.AddFunction>(Hookfunction01, (long)_calculator.Add).Activate(); _addHook02 = new Hook <Calculator.AddFunction>(Hookfunction02, (long)_calculator.Add).Activate(); for (int x = 0; x < 100; x++) { for (int y = 1; y < 100;) { int expected = ((x + y) + 1) + 1; int result = _addFunction(x, y); Assert.Equal(expected, result); y += 2; } } }
private int DrawSmallFrameImpl(int ebx, float x, float y, float width, float height, int a5) { x += GetBorderWidthX(_actualAspectRatio, _currentHeight) / 2; y += GetBorderHeightY(_actualAspectRatio, _currentWidth) / 2; return(_drawSmallVideoFrameHook.OriginalFunction(ebx, x, y, width, height, a5)); }
private int ReadConfigFromIni(char *configPath) { int result = ReadConfigFromIniHook.OriginalFunction(configPath); DefaultSettings.Apply(); return(result); }
private unsafe byte TitleSequenceImpl() { var task = (Task <TitleSequence, TitleSequenceTaskState> *)(*State.CurrentTask); _mode = task->TaskData->RaceMode; return(_titleHook.OriginalFunction()); }
public void TestHookDiv() { int Hookfunction01(int a, int b) { return(_divideHook01.OriginalFunction(a, b) * 2); } int Hookfunction02(int a, int b) { return(_divideHook02.OriginalFunction(a, b) * 2); } _divideHook01 = new Hook <FastcallCalculator.DivideFunction>(Hookfunction01, (long)_calculator.Divide).Activate(); _divideHook02 = new Hook <FastcallCalculator.DivideFunction>(Hookfunction02, (long)_calculator.Divide).Activate(); int x = 100; for (int y = 1; y < 100; y++) { int expected = ((x / y) * 2) * 2; int result = _divideFunction(x, y); Assert.Equal(expected, result); } }
/// <summary> /// Executes original function and checks for possible increment of player score. /// </summary> private void *CheckScoreIncrementHookFunction(ref TObjTeam thisPointer) { void *result = _tObjTeamExecHook.OriginalFunction(ref thisPointer); // Custom Code var tracker = State.VictoryTracker; if (tracker.PlayerOne > _lastVictoryCount.PlayerOne) { _totalVictories.PlayerOne++; } if (tracker.PlayerTwo > _lastVictoryCount.PlayerTwo) { _totalVictories.PlayerTwo++; } if (tracker.PlayerThree > _lastVictoryCount.PlayerThree) { _totalVictories.PlayerThree++; } if (tracker.PlayerFour > _lastVictoryCount.PlayerFour) { _totalVictories.PlayerFour++; } _lastVictoryCount = tracker; // End of Custom Code return(result); }
private void *UtilsMemoryReserveImpl(ulong size, void *use_addr) { var addr = mUtilsMemoryReserveHook.OriginalFunction(size, use_addr); if (addr != null && size == 0x100000000) { // Most likely a global memory allocation var byteAddr = (byte *)addr; if (vm_g_base_addr == null) { vm_g_base_addr = byteAddr; } else if (vm_g_sudo_addr == null) { vm_g_sudo_addr = byteAddr; } else if (vm_g_exec_addr == null) { vm_g_exec_addr = byteAddr; } else if (vm_g_stat_addr == null) { vm_g_stat_addr = byteAddr; } else if (vm_g_reservations == null) { vm_g_reservations = byteAddr; } } return(addr); }
private void PPUInitializeImpl() { mPPUInitializeHook.OriginalFunction(); mGameBindings.Initialize(); mGameBindings.Activate(); }
private void PPUInitializeModuleImpl(ppu_module *info) { mPPUInitializeModuleHook.OriginalFunction(info); var logger = Services.Get <ILogger>(); var hooks = Services.Get <IReloadedHooks>(); logger.WriteLine($"ppu_module: name: {info->name} path: {info->path} cache: {info->cache}"); foreach (var func in info->funcs) { //var jitAddr = *ppu_ref<uint>(func.addr); //logger.WriteLine( $"ppu_function: addr: {func.addr:X8} jit addr: {jitAddr:X8} name: {func.name}" ); //var jitFunc = hooks.CreateFunction<PPUFunctionDelegate>( jitAddr ); //mPPUFunctions[addr] = new PPUFunction( jitFunc, jitAddr ); var blocks = func.blocks.GetValues(); foreach (var block in blocks) { var addr = block.First; var jitAddr = *ppu_ref <uint>(addr); logger.WriteLine($"ppu_function: addr: {addr:X8} jit addr: {jitAddr:X8} name: {func.name}"); var jitFunc = hooks.CreateFunction <PPUFunctionDelegate>(jitAddr); mPPUFunctions[addr] = new PPUFunction(jitFunc, jitAddr); } } }
public void TestHookSub() { int Hookfunction01(int a, int b) { return(_subHook01.OriginalFunction(a, b) - 1); } int Hookfunction02(int a, int b) { return(_subHook02.OriginalFunction(a, b) - 1); } _subHook01 = ReloadedHooks.Instance.CreateHook <NativeCalculator.SubtractFunction>(Hookfunction01, (long)_nativeCalculator.Subtract).Activate(); _subHook02 = ReloadedHooks.Instance.CreateHook <NativeCalculator.SubtractFunction>(Hookfunction02, (long)_nativeCalculator.Subtract).Activate(); int x = 100; for (int y = 100; y >= 0; y--) { int expected = ((x - y) - 1) - 1; int result = _subtractFunction(x, y); Assert.Equal(expected, result); } }
public void TestHookDiv() { int Hookfunction01(int a, int b) { return(_divideHook01.OriginalFunction(a, b) * 2); } int Hookfunction02(int a, int b) { return(_divideHook02.OriginalFunction(a, b) * 2); } _divideHook01 = ReloadedHooks.Instance.CreateHook <NativeCalculator.DivideFunction>(Hookfunction01, (long)_nativeCalculator.Divide).Activate(); _divideHook02 = ReloadedHooks.Instance.CreateHook <NativeCalculator.DivideFunction>(Hookfunction02, (long)_nativeCalculator.Divide).Activate(); int x = 100; for (int y = 1; y < 100; y++) { int expected = ((x / y) * 2) * 2; int result = _divideFunction(x, y); Assert.Equal(expected, result); } }
private int DrawFullVideoFrameHookImpl(int ebx, float x, float y, float width, float height, int a5, float a6, float a7) { x = GetBorderWidthX(_actualAspectRatio, _currentHeight) / 2; y = GetBorderHeightY(_actualAspectRatio, _currentWidth) / 2; return(_drawFullVideoFrameHook.OriginalFunction(ebx, x, y, width, height, a5, a6, a7)); }
public void TestHookMul() { int Hookfunction01(int a, int b) { return(_multiplyHook01.OriginalFunction(a, b) * 2); } int Hookfunction02(int a, int b) { return(_multiplyHook02.OriginalFunction(a, b) * 2); } _multiplyHook01 = new Hook <Calculator.MultiplyFunction>(Hookfunction01, (long)_calculator.Multiply).Activate(); _multiplyHook02 = new Hook <Calculator.MultiplyFunction>(Hookfunction02, (long)_calculator.Multiply).Activate(); int x = 100; for (int y = 0; y < 100; y++) { int expected = ((x * y) * 2) * 2; int result = _multiplyFunction(x, y); Assert.Equal(expected, result); } }
public void TestHookSub() { int Hookfunction01(int a, int b) { return(_subHook01.OriginalFunction(a, b) - 1); } int Hookfunction02(int a, int b) { return(_subHook02.OriginalFunction(a, b) - 1); } _subHook01 = new Hook <FastcallCalculator.SubtractFunction>(Hookfunction01, (long)_calculator.Subtract).Activate(); _subHook02 = new Hook <FastcallCalculator.SubtractFunction>(Hookfunction02, (long)_calculator.Subtract).Activate(); int x = 100; for (int y = 100; y >= 0; y--) { int expected = ((x - y) - 1) - 1; int result = _subtractFunction(x, y); Assert.Equal(expected, result); } }
private unsafe void appUpdateExDetour(context_t *context) { //var deltaTime = context->fpr[1]; //timer -= deltaTime; //if ( timer <= 0d ) //{ // sndManGetBgm.GetWrapper()( context ); // context->r3 = ( ulong )( 0x2290 + ( updateCounter % 10 ) ); // sndManPlayBgm.GetWrapper()( context ); // //Bindings.VirtualMemory.Read( 0xCFF4C4, out int value ); // //value += 1; // //Bindings.VirtualMemory.Write( 0xCFF4C4, ref value ); // timer = 20f; //} ++updateCounter; if (mHandleInput && context->state == 0) { //var tempContext = *context; //tempContext.r3 = ( ulong )( 0x2BC ); //sndManPlayBgm.GetWrapper()( &tempContext ); //context->r3 = 0x2BC; //sndManGetBgm.GetWrapper()( context ); // TODO: maybe try setting the CIA & LR, invalidating the status (non zero) and then calling the function // in the hopes it gets scheduled...? //var tempContext = *context; //context->r3 = 1; //context->r4 = 0; //context->r5 = 0; //context->r6 = 8; //context->cia = 0x10DB4; //seqManTransition.GetWrapper()( context ); //*context = tempContext; var bgm = CallFunction(sndManGetBgm, context); mLogger.WriteLine($"bgm = {bgm:X8}"); CallFunction(sndManPlayBgm, context, (context) => { context.Value->r3 = 0x12C; //ontext.Value->r3 = bgm + 1; }); //CallFunction( seqManTransition, context, ( context ) => // { // context.Value->r3 = 1; // context.Value->r4 = 0; // context.Value->r5 = 0; // context.Value->r6 = 8; // } ); mHandleInput = false; } mAppUpdateExHook.OriginalFunction(context); }
private int DrawSpecialStageBarImpl(int preserveEax, float x, float y, float width, float height) { return(_drawSpecialStageBarHook.OriginalFunction(preserveEax, ProjectFromOldToNewCanvasX(x, _relativeAspectRatio, _actualAspectRatio), ProjectFromOldToNewCanvasY(y, _relativeAspectRatio, _actualAspectRatio), ScaleByRelativeAspectX(width, _relativeAspectRatio, _actualAspectRatio), ScaleByRelativeAspectY(height, _relativeAspectRatio, _actualAspectRatio))); }
private bool RestartAppIfNecessaryImpl(uint appid) { // Write the Steam AppID to a local file if not dropped by the other method. SteamAppId.WriteToDirectory(_applicationFolder, (int)appid); _restartAppIfNecessaryHook.OriginalFunction(appid); return(false); }
private void *DrawSpecialStageEmeraldImpl(void *preserveEax, void *preserveEsi, float x, float y, float width, float height) { x = AspectConverter.ProjectFromOldToNewCanvasX(x, RelativeAspectRatio, ActualAspectRatio); y = AspectConverter.ProjectFromOldToNewCanvasY(y, RelativeAspectRatio, ActualAspectRatio); width = AspectConverter.ScaleByRelativeAspectX(width, RelativeAspectRatio, ActualAspectRatio); height = AspectConverter.ScaleByRelativeAspectY(height, RelativeAspectRatio, ActualAspectRatio); return(_drawSpecialStageEmeraldHook.OriginalFunction(preserveEax, preserveEsi, x, y, width, height)); }
private void EmulatorRunImpl(Emulator *pThis) { mEmulatorRunHook.OriginalFunction(pThis); if (pThis->m_state != system_state.running) { return; } }
private bool RestartAppIfNecessaryImpl(uint appid) { // Write the Steam AppID to a local file if not dropped by the other method. _restartAppIfNecessaryHook.OriginalFunction(appid); SteamAppId.Write((int)appid); return(false); }
private IntPtr ResizeBuffers(IntPtr swapchainPtr, uint bufferCount, uint width, uint height, Format newFormat, uint swapchainFlags) { PreResizeBuffers(); var result = _resizeBuffersHook.OriginalFunction(swapchainPtr, bufferCount, width, height, newFormat, swapchainFlags); PostResizeBuffers(swapchainPtr); return(result); }
/// <summary> /// See <see cref="SonicHeroes.Utils.StageInjector.Hooks.Hooks.GetStartPosition"/> /// </summary> private PositionStart *GetStartPositionImpl(Team team) { if (TryGetCurrentStage(out StageBase stage)) { return(GetStartPositionForStage(stage, team)); } return(_getStartPositionHook.OriginalFunction(team)); }