/// <summary> /// Checks whether the buffer size for a file about to be loaded is sufficient and /// conditonally returns an address to a new buffer with adequate size. /// </summary> /// <returns>The address of a new buffer for the game to decompress a file to</returns> private static void *CheckBufferSize(int fileIndex, void *addressToDecompressTo, ONEFILE *thisPointer) { if (fileIndex >= 2) { // Get pointer and length. IntPtr onePointer = (IntPtr)thisPointer[0].InternalDataPointer - 0xC; // The start of file pointer is sometimes unused, so we use the InternalDataPointer instead and offset. int fileLength = thisPointer[0].FileLength; // Now the ONE File MemoryONEArchive memoryOneFile = MemoryONEArchive.ParseONEFromMemory(onePointer, fileLength); // Now we estimate the size of it. int actualFileIndex = fileIndex - 2; MemoryONEFile oneFile = memoryOneFile.Files[actualFileIndex]; byte[] oneFileCopy = GameProcess.ReadMemory((IntPtr)oneFile.CompressedDataPointer, oneFile.DataLength); int oneFileLength = Prs.Estimate(ref oneFileCopy); // Check if the size of allocation is sufficient. MemoryAddressDetails addressDetails = Allocator.GetAddressDetails((int)addressToDecompressTo); if (addressDetails.MemorySize < oneFileLength) { // Allocate some new data for me please addressToDecompressTo = (void *)Allocator.Allocate((int)addressToDecompressTo, oneFileLength); } } return(addressToDecompressTo); }
/* Entry Point */ public static unsafe void Init() { #if DEBUG Debugger.Launch(); #endif // Setup controllers. var controllerManager = new ControllerManager(); playerOneController = new ReloadedController(Player.PlayerOne, controllerManager); playerTwoController = new ReloadedController(Player.PlayerTwo, controllerManager); playerThreeController = new ReloadedController(Player.PlayerThree, controllerManager); playerFourController = new ReloadedController(Player.PlayerFour, controllerManager); // Hook get controls function. psPADServerHook = FunctionHook <psPADServerPC> .Create(0x444F30, PSPADServerImpl).Activate(); // Copy the old function to a new place and create a function from it. byte[] periMakeRepeatBytes = GameProcess.ReadMemory((IntPtr)0x00434FF0, 0xDD); IntPtr functionPtr = MemoryBufferManager.Add(periMakeRepeatBytes); periMakeRepeatFunction = FunctionWrapper.CreateWrapperFunction <sGamePeri__MakeRepeatCount>((long)functionPtr); periMakeRepeatCountHook = FunctionHook <sGamePeri__MakeRepeatCount> .Create(0x00434FF0, MakeRepeatCountImpl).Activate(); }