├── .gitignore ├── CMakeLists.txt ├── LICENSE ├── README.md ├── README_en.md ├── README_jp.md ├── TargetList.json ├── TargetList_jp.json └── UnityFPSUnlocker ├── CMakeLists.txt ├── file_watch ├── dispatcher │ ├── epoller.cc │ ├── epoller.hh │ ├── ibusiness_event.hh │ └── ipoller.hh ├── listener.cc └── listener.hh ├── fpslimiter.cc ├── fpslimiter.hh ├── main.cc ├── main.hh ├── third ├── rapidjson │ └── rapidjson │ │ ├── allocators.h │ │ ├── cursorstreamwrapper.h │ │ ├── document.h │ │ ├── encodedstream.h │ │ ├── encodings.h │ │ ├── error │ │ ├── en.h │ │ └── error.h │ │ ├── filereadstream.h │ │ ├── filewritestream.h │ │ ├── fwd.h │ │ ├── internal │ │ ├── biginteger.h │ │ ├── clzll.h │ │ ├── diyfp.h │ │ ├── dtoa.h │ │ ├── ieee754.h │ │ ├── itoa.h │ │ ├── meta.h │ │ ├── pow10.h │ │ ├── regex.h │ │ ├── stack.h │ │ ├── strfunc.h │ │ ├── strtod.h │ │ └── swap.h │ │ ├── istreamwrapper.h │ │ ├── memorybuffer.h │ │ ├── memorystream.h │ │ ├── msinttypes │ │ ├── inttypes.h │ │ └── stdint.h │ │ ├── ostreamwrapper.h │ │ ├── pointer.h │ │ ├── prettywriter.h │ │ ├── rapidjson.h │ │ ├── reader.h │ │ ├── schema.h │ │ ├── stream.h │ │ ├── stringbuffer.h │ │ └── writer.h ├── riru_hide │ ├── hide.cc │ ├── hide.hh │ ├── pmparser.c │ ├── pmparser.h │ └── riru_hide_logger.hh ├── xdl │ ├── CMakeLists.txt │ ├── xdl.c │ ├── xdl.h │ ├── xdl.map.txt │ ├── xdl_iterate.c │ ├── xdl_iterate.h │ ├── xdl_linker.c │ ├── xdl_linker.h │ ├── xdl_lzma.c │ ├── xdl_lzma.h │ ├── xdl_util.c │ └── xdl_util.h └── zygisk.hh ├── unity ├── unity_engine.cc └── unity_engine.hh └── utility ├── config.cc ├── config.hh ├── houdini.cc ├── houdini.hh ├── logger.hh ├── native_bridge.h ├── singleton.hh ├── socket.cc └── socket.hh /.gitignore: -------------------------------------------------------------------------------- 1 | .vs* 2 | build 3 | libs 4 | riru_module 5 | zygisk_module 6 | *.cmd 7 | *.zip 8 | *.json -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # CMakeList.txt: 顶层 CMake 项目文件,在此处执行全局配置 2 | # 并包含子项目。 3 | # 4 | cmake_minimum_required (VERSION 3.8) 5 | 6 | project ("UnityFPSUnlocker") 7 | 8 | # 包含子项目。 9 | add_subdirectory ("UnityFPSUnlocker") -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 hexstr 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # UnityFPSUnlocker 2 | [README_EN](https://github.com/hexstr/UnityFPSUnlocker/blob/zygisk_module/README_en.md) 3 | [README_JP](https://github.com/hexstr/UnityFPSUnlocker/blob/zygisk_module/README_jp.md) 4 | 5 | ## 安装需求 6 | - 设备已安装 [Magisk](https://github.com/topjohnwu/Magisk/releases) / [KernelSU](https://github.com/tiann/KernelSU/releases) / [APatch](https://github.com/bmax121/APatch/releases) 7 | - 启用`Zygisk` (对于KernelSU / APatch用户 需要安装`Zygisk Next`) 8 | 9 | ## 附加需求 10 | - 对目标游戏启用`Shamiko` (Shamiko可以避免一些游戏对于Zygisk注入或SafetyNet的检测) 11 | 12 | ## 使用 13 | 若你的手机没有开启Zygisk,请先开启Zygisk后重启。当上述需求准备完毕后即可刷入`UnityFPSUnlocker`模块。在重启之前,先下载`TargetList.json`放入`/data/local/tmp/TargetList.json`,并修改你的配置。 14 | 模块会通过判断游戏数据目录是否存在`/sdcard/Android/data/{包名}/files/il2cpp`来自动加载。 15 | 16 | ``` 17 | { 18 | "global": { 19 | "delay": 10, 20 | "mod_opcode": true, 21 | "fps": 90, 22 | "scale": 1.0 23 | }, 24 | "custom": { 25 | "com.random.package.name.a": { 26 | "fps": 60 27 | }, 28 | "com.random.package.name.b": { 29 | "mod_opcode": false 30 | }, 31 | "com.random.package.name.c": { 32 | "delay": 5 33 | } 34 | } 35 | } 36 | ``` 37 | 38 | 其中,`global`节点中的配置为: 39 | 40 | - `fps` 需要设置的`fps`,设置为`0`以禁用 41 | - `delay` 游戏载入后等待`delay`秒执行 42 | - `mod_opcode` 是否修改`opcode`,如果你发现游戏会重新锁定fps,可以把这项改为`true`,但由于修改内存,可能会被反作弊检测到 43 | - `scale` 设置分辨率的倍数,一般保持`1.0`即可,必须为小数。`当前屏幕宽度 * scale x 当前屏幕高度 * scale` 44 | 45 | 然后,`custom`节点中的配置会覆盖`global`中的配置单独生效: 46 | 47 | - `key` 包名,比如`com.random.package.name.a` 48 | - `fps` 同上 49 | - `mod_opcode` 同上 50 | - `delay` 同上 51 | - `scale` 同上 52 | 53 | `TargetList.json`修改后可以搜索`json 格式校验`校验是否完整。修改后立即生效(`模块版本>=1.8`)。 54 | 可以在终端模拟器输入`logcat -s UnityFPSUnlocker`查看输入日志。 55 | 56 | ## 分辨率 57 | 最近发现`BlueArchive`最高分辨率只有`1080P`,在模拟器上有肉眼可见的锯齿,而且在`16:10`的比例下甚至像素点比`16:9`更少 58 | 59 | `2560x1600->1822x1138` 60 | 61 | 对比 62 | 63 | `2560x1440->1920x1080` 64 | 65 | 所以加上调整分辨率的功能,对比图如下 66 | 67 | https://imgsli.com/MjI3NDQ2/0/1 68 | 69 | https://imgsli.com/MjI3NDQ2/2/3 70 | 71 | 但是设置的时机需要尽可能早,也就是`delay`尽可能短,否则需要更改`绘图`选项中的任意一项后生效(比如开关一次`抗锯齿`) 72 | 73 | 如果你不需要超分辨率,可以修改`/sdcard/Android/data/com.nexon.bluearchive/files/DeviceOption`,把`Resolution`修改为大于`3`即可,这样会走`default`分支(在函数`GraphicsManager.CoSetScreenResolution()`中) 74 | 75 | - `0`: 1080P 76 | - `1`: 720P 77 | - `2`: 540P 78 | - `3`: 480P 79 | - `default` default 80 | -------------------------------------------------------------------------------- /README_en.md: -------------------------------------------------------------------------------- 1 | # UnityFPSUnlocker 2 | ## Installation requirements 3 | - The device has already installed [Magisk](https://github.com/topjohnwu/Magisk/releases) / [KernelSU](https://github.com/tiann/KernelSU/releases) / [APatch](https://github.com/bmax121/APatch/releases) 4 | - Enable `Zygisk` (For KernelSU / APatch user, Need install `Zygisk Next`) 5 | 6 | ## Additional requirements 7 | - Enable `Shamiko` for the target game (Shamiko can avoid detected Zygisk injection or SafetyNet in some games) 8 | 9 | ## Use now 10 | If your device does not have Zygisk enabled, please enable Zygisk first and then reboot your device. After the above requirements are prepared, the 'UnityFPSUnlocker' module can be install in. Before rebooting, download `TargetList.json` and place it to `/data/local/tmp/TargetList.json`, and modify configuration by yourself. 11 | The module will automatically load by checking if the game data directory contains `/sdcard/Android/data/{package_name}/files/il2cpp`. 12 | 13 | ``` 14 | { 15 | "global": { 16 | "delay": 10, 17 | "mod_opcode": true, 18 | "fps": 90, 19 | "scale": 1.0 20 | }, 21 | "custom": { 22 | "com.random.package.name.a": { 23 | "fps": 60 24 | }, 25 | "com.random.package.name.b": { 26 | "mod_opcode": false 27 | }, 28 | "com.random.package.name.c": { 29 | "delay": 5 30 | } 31 | } 32 | } 33 | ``` 34 | 35 | Among them, the configuration in the `global` node is: 36 | 37 | - `fps` Required settings for `fps`,Set to `0` to disable module injection 38 | - `delay` Wait for `delay` seconds to execute after the game is loaded 39 | - `mod_opcode` Do you want to modify `opcode`, If you find that the game will lock fps again, you can change this to `true`, But due to modifying memory, it maybe detected by anti-cheat 40 | - `scale` Set the multiplier of resolution, Generally, it keep `1.0`, and which must be a decimal number. `Current screen width * scale x Current screen height * scale` 41 | 42 | Then, the configuration in the `custom` node will override the configuration in the `global` and take effect separately: 43 | 44 | - `key` package name, like `com.random.package.name.a` 45 | - `fps` Same as above 46 | - `mod_opcode` Same as above 47 | - `delay` Same as above 48 | - `scale` Same as above 49 | 50 | `TargetList.json` effective immediately after modification (`Module version>=1.8`)。 51 | And you can input `logcat - s UnityFPSUnlocker` in the shell to view the input logs. 52 | -------------------------------------------------------------------------------- /README_jp.md: -------------------------------------------------------------------------------- 1 | # UnityFPSUnlocker 2 | ## インストール条件 3 | - [Magisk](https://github.com/topjohnwu/Magisk/releases) / [KernelSU](https://github.com/tiann/KernelSU/releases) / [APatch](https://github.com/bmax121/APatch/releases) 4 | - `Zygisk`の有効化 (KernelSU / APatch ユーザーには `Zygisk Next`) 5 | - `Shamiko`の有効化 6 |
ShamikoはSafetyNetによる対策が入ったゲームに適用する場合に必要になる事があります。(ウマ娘など) 7 | 8 | ## 使用方法 9 | UnityFPSUnlockerとZygiskの有効化を行ない、`TargetList.json`を`/data/local/tmp/`に配置をしてください。
10 | プラグインは`/sdcard/Android/data/{パッケージ名}/files/il2cpp`にファイルが入っていると自動的にロードされます。 11 | 12 | ``` 13 | { 14 | "global": { 15 | "delay": 10, 16 | "mod_opcode": true, 17 | "fps": 90 18 | }, 19 | "custom": { 20 | "com.random.package.name.a": { 21 | "fps": 60 22 | }, 23 | "com.random.package.name.b": { 24 | "mod_opcode": false 25 | }, 26 | "com.random.package.name.c": { 27 | "delay": 5 28 | } 29 | } 30 | } 31 | ``` 32 | 33 | 以下は`global`ノードの設定方法です: 34 | - `fps`はアンロックを行なう`FPS値`を入力します。 35 | - `delay`はアンロックを行なうまでの`ディレイ値`の設定です。 36 | - `mod_opcode`は`オペコード`の変更モードです。
37 | FPSを再ロックしてしまうゲームでこのオプションを`ture`にする事で、完全なアンロックが可能になりますがメモリの変更を行なうため「アンチチート機能」が反応してしまう事があります。 38 | 39 | `custom`ノードの設定は`global`ノードの設定を上書きし、別々で有効化されます: 40 | - `キー`となるパッケージ名、例:`com.random.package.name.a` 41 | - `fps` `global`ノード設定方法と同上 42 | - `mod_opcode` `global`ノード設定方法と同上 43 | - `delay` `global`ノード設定方法と同上 44 | 45 | `TargetList.json`に`JSONのフォーマットのチェック`を行なうようにしました。(>=1.8) 46 | 動作のログはターミナルエミュレーターで`logcat -s UnityFPSUnlocker`を入力する事でログを確認できます。 47 | -------------------------------------------------------------------------------- /TargetList.json: -------------------------------------------------------------------------------- 1 | { 2 | "global": { 3 | "delay": 10, 4 | "mod_opcode": true, 5 | "fps": 120 6 | }, 7 | "custom": { 8 | "com.nexon.bluearchive": { 9 | "fps": 90 10 | }, 11 | "com.random.package.name.b": { 12 | "mod_opcode": false 13 | }, 14 | "com.random.package.name.c": { 15 | "delay": 5 16 | }, 17 | "com.random.package.name.d": { 18 | "description": "keep blank to use global parameters (delete this line)." 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /TargetList_jp.json: -------------------------------------------------------------------------------- 1 | { 2 | "global": { 3 | "delay": 10, 4 | "mod_opcode": true, 5 | "fps": 120 6 | }, 7 | "custom": { 8 | "com.nexon.bluearchive": { 9 | "fps": 120 10 | }, 11 | "com.YoStarJP.AzurLane": { 12 | "mod_opcode": false 13 | }, 14 | "com.YostarJP.BlueArchive": { 15 | "mod_opcode": false 16 | }, 17 | "com.sunborn.girlsfrontline.jp": { 18 | "mod_opcode": false 19 | }, 20 | "com.miHoYo.GenshinImpact": { 21 | "mod_opcode": false 22 | }, 23 | "co.grimoire.bxb": { 24 | "mod_opcode": false 25 | }, 26 | "jp.co.craftegg.band": { 27 | "mod_opcode": false 28 | }, 29 | "com.proximabeta.nikke": { 30 | "mod_opcode": false 31 | }, 32 | "com.random.package.name.b": { 33 | "mod_opcode": false 34 | }, 35 | "com.random.package.name.c": { 36 | "fps": 120 37 | }, 38 | "com.random.package.name.d": { 39 | "記述": "グローバルパラメータを使用する場合は空白にします(この行は削除してください)" 40 | } 41 | } 42 | } -------------------------------------------------------------------------------- /UnityFPSUnlocker/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # CMakeList.txt: UnityFPSUnlocker 的 CMake 项目,在此处包括源代码并定义 2 | # 项目特定的逻辑。 3 | # 4 | cmake_minimum_required (VERSION 3.8) 5 | 6 | set(CMAKE_CXX_STANDARD 17) 7 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti -fno-exceptions -D_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS") 8 | 9 | set(LibraryName UnityFPSUnlocker) 10 | 11 | # 隐藏导出函数 12 | set(CMAKE_C_VISIBILITY_PRESET hidden) 13 | set(CMAKE_CXX_VISIBILITY_PRESET hidden) 14 | 15 | # 添加Debug和Release版本信息 16 | string(TOUPPER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE_UP) 17 | if(CMAKE_BUILD_TYPE_UP STREQUAL DEBUG) 18 | message(STATUS "Debug Version") 19 | set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -g") 20 | set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -g") 21 | else() 22 | message(STATUS "Release Version") 23 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Oz -flto -fdata-sections -ffunction-sections") 24 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Oz -flto -fdata-sections -ffunction-sections") 25 | set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -s -Wl,--exclude-libs,ALL -flto") 26 | set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -s -Wl,--exclude-libs,ALL -Wl,--gc-sections -flto") 27 | endif() 28 | 29 | set(CMAKE_PREFIX_PATH "${CMAKE_SYSROOT}/${CMAKE_LIBRARY_ARCHITECTURE}") 30 | message(STATUS CMAKE_PREFIX_PATH: ${CMAKE_PREFIX_PATH}) 31 | 32 | # 添加头文件 33 | include_directories( 34 | . 35 | "third/rapidjson" 36 | "third/xdl" 37 | ) 38 | 39 | # 文件写出位置 40 | set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/libs/${CMAKE_BUILD_TYPE}/) 41 | 42 | # 将源代码添加到此项目的可执行文件。 43 | aux_source_directory(${PROJECT_SOURCE_DIR}/${LibraryName} program-src) 44 | aux_source_directory(unity unity-src) 45 | aux_source_directory(utility utility-src) 46 | aux_source_directory(third/xdl xdl-src) 47 | aux_source_directory(third/riru_hide riru_hide-src) 48 | aux_source_directory(file_watch listener-src) 49 | aux_source_directory(file_watch/dispatcher dispatcher-src) 50 | 51 | add_library ( 52 | ${LibraryName} 53 | SHARED 54 | ${program-src} 55 | ${unity-src} 56 | ${utility-src} 57 | ${listener-src} 58 | ${dispatcher-src} 59 | ${xdl-src} 60 | ${riru_hide-src} 61 | ) 62 | 63 | find_library(log-lib log) 64 | target_link_libraries(${LibraryName} ${log-lib}) 65 | 66 | find_package(absl REQUIRED) 67 | target_link_libraries(${LibraryName} absl::status) 68 | target_link_libraries(${LibraryName} absl::statusor) 69 | target_link_libraries(${LibraryName} absl::flat_hash_set) 70 | 71 | set_target_properties(${LibraryName} PROPERTIES PREFIX "") 72 | set_target_properties(${LibraryName} PROPERTIES OUTPUT_NAME ${ANDROID_ABI}) -------------------------------------------------------------------------------- /UnityFPSUnlocker/file_watch/dispatcher/epoller.cc: -------------------------------------------------------------------------------- 1 | #ifdef __linux__ 2 | 3 | #include 4 | 5 | #include 6 | 7 | #include "epoller.hh" 8 | #include "utility/logger.hh" 9 | 10 | std::vector EPoller::reserved_list_; 11 | 12 | EPoller::EPoller(IBusinessEvent* business) { 13 | epoller_inst_ = epoll_create1(0); 14 | op_ = business; 15 | op_->poller_ = reinterpret_cast(this); 16 | } 17 | 18 | int EPoller::SetNonBlocking(int fd) { 19 | int old_opt = fcntl(fd, F_GETFL); 20 | int new_opt = old_opt | O_NONBLOCK; 21 | return fcntl(fd, F_SETFL, new_opt); 22 | } 23 | 24 | absl::Status EPoller::AddSocket(intptr_t s, long eventflags) { 25 | epoll_event _event; 26 | _event.data.u64 = s; 27 | _event.events = eventflags; 28 | if (epoll_ctl(epoller_inst_, EPOLL_CTL_ADD, s, &_event) == -1) { 29 | return absl::InternalError(strerror(errno)); 30 | } 31 | return absl::OkStatus(); 32 | } 33 | 34 | absl::Status EPoller::ModSocket(intptr_t s, long eventflags) { 35 | epoll_event _event; 36 | _event.data.fd = s; 37 | _event.events = eventflags; 38 | if (epoll_ctl(epoller_inst_, EPOLL_CTL_MOD, s, &_event) == -1) { 39 | return absl::InternalError(strerror(errno)); 40 | } 41 | return absl::OkStatus(); 42 | } 43 | 44 | absl::Status EPoller::RemoveSocket(intptr_t s) { 45 | if (epoll_ctl(epoller_inst_, EPOLL_CTL_DEL, s, nullptr) == -1) { 46 | return absl::InternalError(strerror(errno)); 47 | } 48 | else { 49 | return absl::OkStatus(); 50 | } 51 | } 52 | 53 | void EPoller::Poll() { 54 | int CompEventNum = epoll_wait(epoller_inst_, &event_array_[0], MAX_EVENT_NUMBER, 3000); 55 | for (int i = 0; i < CompEventNum; ++i) { 56 | HandleEvents(reinterpret_cast(event_array_[i].data.ptr), event_array_[i].events); 57 | } 58 | } 59 | 60 | void EPoller::HandleEvents(intptr_t s, uint32_t event) { 61 | if (event & EPOLLRDHUP) { 62 | op_->OnClose(s); 63 | } 64 | 65 | else if (event & EPOLLIN) { 66 | op_->OnReadable(s); 67 | } 68 | 69 | else if (event & EPOLLOUT) { 70 | op_->OnWritable(s); 71 | } 72 | 73 | else if (event & EPOLLERR) { 74 | op_->OnError(s); 75 | } 76 | } 77 | 78 | #endif // #ifdef __linux__ -------------------------------------------------------------------------------- /UnityFPSUnlocker/file_watch/dispatcher/epoller.hh: -------------------------------------------------------------------------------- 1 | #ifndef EPOLLER_HEADER 2 | #define EPOLLER_HEADER 3 | 4 | #include 5 | #ifdef __linux__ 6 | 7 | #include 8 | 9 | #include 10 | #include 11 | 12 | #include "ipoller.hh" 13 | 14 | constexpr int MAX_EVENT_NUMBER = 64; 15 | 16 | class EPoller : public IPoller { 17 | public: 18 | EPoller(IBusinessEvent* business); 19 | ~EPoller(){}; 20 | 21 | absl::Status AddSocket(intptr_t s, long eventflags) override; 22 | absl::Status ModSocket(intptr_t s, long eventflags) override; 23 | absl::Status RemoveSocket(intptr_t s) override; 24 | 25 | void Poll() override; 26 | void HandleEvents(intptr_t s, uint32_t event); 27 | 28 | std::array event_array_{}; 29 | 30 | static int SetNonBlocking(int); 31 | static std::vector reserved_list_; // SubReactor list 32 | 33 | protected: 34 | int epoller_inst_ = 0; 35 | }; 36 | 37 | #endif // #ifdef __linux__ 38 | 39 | #endif // epoller.hh -------------------------------------------------------------------------------- /UnityFPSUnlocker/file_watch/dispatcher/ibusiness_event.hh: -------------------------------------------------------------------------------- 1 | #ifndef IBUSINESS_EVENT_HEADER 2 | #define IBUSINESS_EVENT_HEADER 3 | 4 | #include 5 | 6 | class IPoller; 7 | 8 | class IBusinessEvent { 9 | public: 10 | virtual ~IBusinessEvent() {} 11 | virtual void OnAcceptable(uintptr_t){}; 12 | virtual void OnClose(uintptr_t){}; 13 | virtual void OnReadable(uintptr_t){}; 14 | virtual void OnWritable(uintptr_t){}; 15 | virtual void OnError(uintptr_t){}; 16 | IPoller* poller_ = nullptr; 17 | }; 18 | 19 | #endif // ibusiness_event.hh -------------------------------------------------------------------------------- /UnityFPSUnlocker/file_watch/dispatcher/ipoller.hh: -------------------------------------------------------------------------------- 1 | #ifndef IPOLLER_HEADER 2 | #define IPOLLER_HEADER 3 | 4 | #include 5 | 6 | #include "ibusiness_event.hh" 7 | 8 | class IPoller { 9 | public: 10 | IPoller(){}; 11 | virtual ~IPoller(){}; 12 | virtual absl::Status AddSocket(intptr_t s, long eventflags) = 0; 13 | virtual absl::Status ModSocket(intptr_t s, long eventflags) = 0; 14 | virtual absl::Status RemoveSocket(intptr_t s) = 0; 15 | // while (IsRunning) { 16 | virtual void Poll() = 0; 17 | // } 18 | void SetBusiness(IBusinessEvent* op) { op_ = op; } 19 | 20 | protected: 21 | IBusinessEvent* op_ = nullptr; 22 | }; 23 | 24 | #endif // ipoller.hh -------------------------------------------------------------------------------- /UnityFPSUnlocker/file_watch/listener.cc: -------------------------------------------------------------------------------- 1 | #include "listener.hh" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #include "dispatcher/epoller.hh" 11 | #include "utility/logger.hh" 12 | 13 | namespace FileWatch { 14 | Listener::Listener() { 15 | inotify_fd_ = inotify_init1(IN_NONBLOCK | IN_CLOEXEC); 16 | if (inotify_fd_ == -1) { 17 | ERROR("[Listener::Register] [%d] %s", __LINE__, strerror(errno)); 18 | } 19 | } 20 | 21 | int Listener::Register(const char* file_path, OnModified mod_callback, OnDeleted del_callback) { 22 | int wd = inotify_add_watch(inotify_fd_, file_path, IN_CLOSE_WRITE | IN_MODIFY | IN_DELETE_SELF); 23 | if (wd == -1) { 24 | ERROR("[Listener::Register] [%d] %s", __LINE__, strerror(errno)); 25 | return -1; 26 | } 27 | 28 | auto res = EPoller::reserved_list_[0]->AddSocket(inotify_fd_, EPOLLIN); 29 | if (!res.ok()) { 30 | ERROR("[Listener::Register] %s", res.message().data()); 31 | return -1; 32 | } 33 | 34 | registered_[wd] = std::make_tuple(mod_callback, del_callback); 35 | LOG("[Listener::Register] Registered: wd: %d %s", wd, file_path); 36 | return wd; 37 | } 38 | 39 | void Listener::Remove(int wd) { 40 | inotify_rm_watch(inotify_fd_, wd); 41 | } 42 | 43 | void Listener::OnReadable(uintptr_t s) { 44 | inotify_event event; 45 | int read_size = read(s, &event, sizeof(event)); 46 | if (read_size == -1) { 47 | ERROR("[Listener::OnReadable] [%d] %s", __LINE__, strerror(errno)); 48 | return; 49 | } 50 | /* 51 | if (event.mask & IN_CREATE) { 52 | LOGI("The file was created."); 53 | } 54 | else*/ 55 | if (event.mask & IN_DELETE_SELF) { 56 | if (auto itor = registered_.find(event.wd); itor != registered_.end()) { 57 | auto del_callback = std::get<1>(itor->second); 58 | if (del_callback != nullptr) { 59 | del_callback(); 60 | } 61 | } 62 | } 63 | /* 64 | else if (event.mask & IN_MODIFY) { 65 | LOGI("The file was modified."); 66 | } 67 | */ 68 | else if (event.mask & IN_CLOSE_WRITE) { 69 | if (auto itor = registered_.find(event.wd); itor != registered_.end()) { 70 | auto mod_callback = std::get<0>(itor->second); 71 | if (mod_callback != nullptr) { 72 | mod_callback(event.wd); 73 | } 74 | } 75 | } 76 | } 77 | } // namespace FileWatch -------------------------------------------------------------------------------- /UnityFPSUnlocker/file_watch/listener.hh: -------------------------------------------------------------------------------- 1 | #ifndef LISTENER_HEADER 2 | #define LISTENER_HEADER 3 | 4 | #include 5 | 6 | #include "dispatcher/ibusiness_event.hh" 7 | 8 | #include 9 | 10 | namespace FileWatch { 11 | class Listener : public IBusinessEvent { 12 | public: 13 | Listener(); 14 | virtual void OnReadable(uintptr_t) override final; 15 | virtual void OnWritable(uintptr_t) override final{}; 16 | virtual void OnError(uintptr_t) override final{}; 17 | virtual void OnClose(uintptr_t) override final{}; 18 | 19 | using OnModified = void (*)(int wd); 20 | using OnDeleted = void (*)(); 21 | int Register(const char* file_path, OnModified mod_callback, OnDeleted del_callback); 22 | void Remove(int wd); 23 | 24 | private: 25 | int inotify_fd_; 26 | absl::flat_hash_map> registered_; 27 | }; 28 | } // namespace FileWatch 29 | 30 | #endif // listener.hh -------------------------------------------------------------------------------- /UnityFPSUnlocker/fpslimiter.cc: -------------------------------------------------------------------------------- 1 | #include "fpslimiter.hh" 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include "unity/unity_engine.hh" 8 | #include "utility/logger.hh" 9 | 10 | #include 11 | 12 | namespace FPSLimiter { 13 | void Start(const ConfigValue& cfg) { 14 | #ifdef __aarch64__ 15 | LOG("[UnityFPSUnlocker][arm64] Starting..."); 16 | #elif defined(__ARM_ARCH_7A__) 17 | LOG("[UnityFPSUnlocker][armv7] Starting..."); 18 | #elif defined(__i386__) 19 | LOG("[UnityFPSUnlocker][x86] Starting..."); 20 | #elif defined(__x86_64__) 21 | LOG("[UnityFPSUnlocker][x86_64] Starting..."); 22 | #endif 23 | cfg.DebugPrint(); 24 | std::chrono::seconds sleep_duration(cfg.delay_); 25 | std::this_thread::sleep_for(sleep_duration); 26 | 27 | LOG("***** begin *****"); 28 | void* handle = nullptr; 29 | for (int i = 0; i < 10; ++i) { 30 | if ((handle = xdl_open("libil2cpp.so", 0))) { 31 | break; 32 | } 33 | std::this_thread::sleep_for(std::chrono::seconds(1)); 34 | } 35 | if (handle) { 36 | Unity::GetInstance().Init(handle); 37 | Unity::GetInstance().SetFrameRate(cfg.fps_, cfg.mod_opcode_); 38 | Unity::GetInstance().SetResolution(cfg.scale_); 39 | 40 | LOG("***** finished *****"); 41 | return; 42 | } 43 | else { 44 | ERROR("Failed to open libil2cpp.so"); 45 | } 46 | } 47 | } // namespace FPSLimiter 48 | -------------------------------------------------------------------------------- /UnityFPSUnlocker/fpslimiter.hh: -------------------------------------------------------------------------------- 1 | #ifndef FPSLIMITER_HEADER 2 | #define FPSLIMITER_HEADER 3 | 4 | #include "utility/config.hh" 5 | 6 | namespace FPSLimiter { 7 | void Start(const ConfigValue&); 8 | } // namespace FPSLimiter 9 | 10 | #endif // fpslimiter.hh -------------------------------------------------------------------------------- /UnityFPSUnlocker/main.cc: -------------------------------------------------------------------------------- 1 | #include "main.hh" 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include 8 | #include 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | #include "file_watch/dispatcher/epoller.hh" 17 | #include "file_watch/listener.hh" 18 | #include "fpslimiter.hh" 19 | #include "third/riru_hide/hide.hh" 20 | #include "utility/houdini.hh" 21 | #include "utility/socket.hh" 22 | 23 | using namespace rapidjson; 24 | 25 | static bool is_loaded = false; 26 | static int watch_descriptor = -1; 27 | static absl::flat_hash_map custom_list; 28 | static ConfigValue global_cfg; 29 | static FileWatch::Listener* file_watch_listener = nullptr; 30 | 31 | constexpr const char* ConfigFile = "/data/local/tmp/TargetList.json"; 32 | 33 | absl::Status LoadConfig() { 34 | custom_list.clear(); 35 | 36 | auto read_path = Utility::LoadJsonFromFile(ConfigFile); 37 | if (!read_path.ok()) { 38 | return read_path.status(); 39 | } 40 | 41 | Document& doc = *read_path; 42 | if (auto itor = doc.FindMember("global"); itor != doc.MemberEnd() && itor->value.IsObject()) { 43 | const auto& itor_json_object = itor->value.GetObject(); 44 | if (auto itor2 = itor_json_object.FindMember("delay"); itor2 != itor_json_object.MemberEnd() && itor2->value.IsInt()) { 45 | global_cfg.delay_ = itor2->value.GetInt(); 46 | } 47 | if (auto itor2 = itor_json_object.FindMember("fps"); itor2 != itor_json_object.MemberEnd() && itor2->value.IsInt()) { 48 | global_cfg.fps_ = itor2->value.GetInt(); 49 | } 50 | if (auto itor2 = itor_json_object.FindMember("mod_opcode"); itor2 != itor_json_object.MemberEnd() && itor2->value.IsBool()) { 51 | global_cfg.mod_opcode_ = itor2->value.GetBool(); 52 | } 53 | if (auto itor2 = itor_json_object.FindMember("scale"); itor2 != itor_json_object.MemberEnd() && itor2->value.IsFloat()) { 54 | global_cfg.scale_ = itor2->value.GetFloat(); 55 | } 56 | } 57 | 58 | if (auto itor = doc.FindMember("custom"); itor != doc.MemberEnd() && itor->value.IsObject()) { 59 | for (const auto& item : itor->value.GetObject()) { 60 | if (item.value.IsObject()) { 61 | auto cfg(global_cfg); 62 | if (item.value.MemberCount()) { 63 | if (auto itor2 = item.value.FindMember("delay"); itor2 != item.value.MemberEnd() && itor2->value.IsInt()) { 64 | cfg.delay_ = itor2->value.GetInt(); 65 | } 66 | if (auto itor2 = item.value.FindMember("fps"); itor2 != item.value.MemberEnd() && itor2->value.IsInt()) { 67 | cfg.fps_ = itor2->value.GetInt(); 68 | } 69 | if (auto itor2 = item.value.FindMember("mod_opcode"); itor2 != item.value.MemberEnd() && itor2->value.IsBool()) { 70 | cfg.mod_opcode_ = itor2->value.GetBool(); 71 | } 72 | if (auto itor2 = item.value.FindMember("scale"); itor2 != item.value.MemberEnd() && itor2->value.IsFloat()) { 73 | cfg.scale_ = itor2->value.GetFloat(); 74 | } 75 | } 76 | custom_list[item.name.GetString()] = cfg; 77 | } 78 | } 79 | } 80 | 81 | LOG("[LoadConfig] custom_list: %zu", custom_list.size()); 82 | LOG("[LoadConfig] global_cfg: "); 83 | global_cfg.DebugPrint(); 84 | 85 | return absl::OkStatus(); 86 | } 87 | 88 | void OnModified(int wd) { 89 | if (wd == watch_descriptor) { 90 | LoadConfig().IgnoreError(); 91 | } 92 | } 93 | 94 | void OnDeleted() { 95 | watch_descriptor = -1; 96 | } 97 | 98 | // In zygiskd memory. 99 | void CompanionEntry(int s) { 100 | std::string package_name = read_string(s); 101 | if (is_loaded == false) { 102 | if (auto res = LoadConfig(); res.ok()) { 103 | is_loaded = true; 104 | file_watch_listener = new FileWatch::Listener(); 105 | EPoller* file_watch_poller = new EPoller(file_watch_listener); 106 | EPoller::reserved_list_.push_back(file_watch_poller); 107 | std::thread([=] { 108 | while (true) { 109 | file_watch_poller->Poll(); 110 | } 111 | }).detach(); 112 | watch_descriptor = file_watch_listener->Register(ConfigFile, OnModified, OnDeleted); 113 | } 114 | else { 115 | ERROR("LoadConfig error: %s", res.message().data()); 116 | } 117 | } 118 | 119 | if (is_loaded && watch_descriptor == -1) { 120 | watch_descriptor = file_watch_listener->Register(ConfigFile, OnModified, OnDeleted); 121 | } 122 | 123 | if (auto itor = custom_list.find(package_name); itor != custom_list.end()) { 124 | write_int(s, 1); 125 | write_int(s, itor->second.delay_); 126 | write_int(s, itor->second.fps_); 127 | write_int(s, itor->second.mod_opcode_); 128 | write_float(s, itor->second.scale_); 129 | } 130 | else { 131 | write_int(s, 0); 132 | write_int(s, global_cfg.delay_); 133 | write_int(s, global_cfg.fps_); 134 | write_int(s, global_cfg.mod_opcode_); 135 | write_float(s, global_cfg.scale_); 136 | } 137 | } 138 | 139 | REGISTER_ZYGISK_MODULE(MyModule) 140 | REGISTER_ZYGISK_COMPANION(CompanionEntry) 141 | 142 | void MyModule::onLoad(Api* api, JNIEnv* env) { 143 | this->api = api; 144 | this->env = env; 145 | } 146 | 147 | void MyModule::preAppSpecialize(AppSpecializeArgs* args) { 148 | int client_socket = api->connectCompanion(); 149 | 150 | package_name_ = env->GetStringUTFChars(args->nice_name, nullptr); 151 | write_string(client_socket, package_name_); 152 | 153 | has_custom_cfg_ = read_int(client_socket); 154 | current_cfg_.delay_ = read_int(client_socket); 155 | current_cfg_.fps_ = read_int(client_socket); 156 | current_cfg_.mod_opcode_ = read_int(client_socket); 157 | current_cfg_.scale_ = read_float(client_socket); 158 | 159 | close(client_socket); 160 | } 161 | 162 | void MyModule::ForHoudini() { 163 | #if defined(__i386__) || defined(__x86_64__) 164 | std::thread([=]() { 165 | std::chrono::seconds sleep_duration(current_cfg_.delay_); 166 | std::this_thread::sleep_for(sleep_duration); 167 | #ifdef __x86_64__ 168 | #define libdir "/lib64/x86_64" 169 | #define library_name "arm64-v8a.so" 170 | #endif 171 | 172 | #ifdef __i386__ 173 | #define libdir "/lib64/x86" 174 | #define library_name "armeabi-v7a.so" 175 | #endif 176 | 177 | auto vms = Utility::GetVM(); 178 | if (!vms.ok()) { 179 | ERROR("%s", vms.status().message().data()); 180 | return; 181 | } 182 | 183 | JNIEnv* env = nullptr; 184 | if (vms.value()->AttachCurrentThread(&env, nullptr) < 0) { 185 | ERROR("Cannot connect to JNI environment"); 186 | return; 187 | } 188 | 189 | auto app_info = Utility::GetApplicationInfo(env); 190 | auto path = Utility::GetLibraryPath(env, app_info.value()); 191 | 192 | if (!path.ok()) { 193 | ERROR("%s", vms.status().message().data()); 194 | return; 195 | } 196 | 197 | if (path.value().find(libdir) == std::string::npos) { 198 | auto& houdini = Houdini::GetInstance(); 199 | auto plugin = houdini.LoadLibrary("/data/local/tmp/gh@hexstr/UnityFPSUnlocker/" library_name, RTLD_NOW); 200 | if (plugin.ok()) { 201 | if (plugin.value() == nullptr) { 202 | ERROR("Failed to load library : %s", Houdini::GetInstance().GetError()); 203 | return; 204 | } 205 | ConfigValue config(0, current_cfg_.fps_, current_cfg_.mod_opcode_, current_cfg_.scale_); 206 | if (auto result = houdini.CallJNI(plugin.value(), vms.value(), &config); 207 | !result.ok()) { 208 | ERROR("%s", plugin.status().message().data()); 209 | } 210 | riru_hide("/data/local/tmp/gh@hexstr/UnityFPSUnlocker/" library_name); 211 | } 212 | else { 213 | ERROR("%s", plugin.status().message().data()); 214 | } 215 | } 216 | else { 217 | FPSLimiter::Start(current_cfg_); 218 | } 219 | }).detach(); 220 | #endif 221 | } 222 | 223 | void MyModule::postAppSpecialize(const AppSpecializeArgs* args) { 224 | auto path = absl::Substitute("/sdcard/Android/data/$0/files/il2cpp", package_name_); 225 | if ((has_custom_cfg_ || access(path.c_str(), F_OK) == 0) && current_cfg_.fps_ > 0) { 226 | #if defined(__ARM_ARCH_7A__) || defined(__aarch64__) 227 | std::thread([=]() { 228 | FPSLimiter::Start(current_cfg_); 229 | }).detach(); 230 | #endif 231 | ForHoudini(); 232 | } 233 | else { 234 | api->setOption(zygisk::Option::DLCLOSE_MODULE_LIBRARY); 235 | } 236 | env->ReleaseStringUTFChars(args->nice_name, package_name_); 237 | } 238 | 239 | #if defined(__ARM_ARCH_7A__) || defined(__aarch64__) 240 | 241 | extern "C" { 242 | JNIEXPORT void JNICALL Java_io_github_hexstr_UnityFPSUnlocker_MyModule_HelloWorld(JNIEnv* env, jobject obj, jint delay, jint fps, jint mod_opcode, jfloat scale) { 243 | LOG("[UnityFPSUnlocker][xposed] delay: %d | fps: %d | mod_opcode: %d | scale: %f", delay, fps, mod_opcode, scale); 244 | ConfigValue current_cfg(delay, fps, mod_opcode, scale); 245 | std::thread([=]() { 246 | FPSLimiter::Start(current_cfg); 247 | }).detach(); 248 | } 249 | } 250 | 251 | JNIEXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) { 252 | if (reserved) { 253 | ConfigValue* config = reinterpret_cast(reserved); 254 | 255 | std::thread([=]() { 256 | FPSLimiter::Start(*config); 257 | }).detach(); 258 | } 259 | return JNI_VERSION_1_6; 260 | } 261 | 262 | #endif -------------------------------------------------------------------------------- /UnityFPSUnlocker/main.hh: -------------------------------------------------------------------------------- 1 | #ifndef MAIN_HEADER 2 | #define MAIN_HEADER 3 | 4 | #include "third/zygisk.hh" 5 | 6 | #include "utility/config.hh" 7 | #include "utility/logger.hh" 8 | 9 | using zygisk::Api; 10 | using zygisk::AppSpecializeArgs; 11 | 12 | class MyModule : public zygisk::ModuleBase { 13 | public: 14 | virtual void onLoad(Api* api, JNIEnv* env) override final; 15 | virtual void preAppSpecialize(AppSpecializeArgs* args) override final; 16 | virtual void postAppSpecialize(const AppSpecializeArgs* args) override final; 17 | 18 | private: 19 | Api* api; 20 | JNIEnv* env; 21 | int module_dir_fd_ = -1; 22 | int has_custom_cfg_ = false; 23 | const char* package_name_ = nullptr; 24 | ConfigValue current_cfg_; 25 | 26 | void ForHoudini(); 27 | }; 28 | 29 | #endif // main.hh -------------------------------------------------------------------------------- /UnityFPSUnlocker/third/rapidjson/rapidjson/cursorstreamwrapper.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making RapidJSON available. 2 | // 3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef RAPIDJSON_CURSORSTREAMWRAPPER_H_ 16 | #define RAPIDJSON_CURSORSTREAMWRAPPER_H_ 17 | 18 | #include "stream.h" 19 | 20 | #if defined(__GNUC__) 21 | RAPIDJSON_DIAG_PUSH 22 | RAPIDJSON_DIAG_OFF(effc++) 23 | #endif 24 | 25 | #if defined(_MSC_VER) && _MSC_VER <= 1800 26 | RAPIDJSON_DIAG_PUSH 27 | RAPIDJSON_DIAG_OFF(4702) // unreachable code 28 | RAPIDJSON_DIAG_OFF(4512) // assignment operator could not be generated 29 | #endif 30 | 31 | RAPIDJSON_NAMESPACE_BEGIN 32 | 33 | 34 | //! Cursor stream wrapper for counting line and column number if error exists. 35 | /*! 36 | \tparam InputStream Any stream that implements Stream Concept 37 | */ 38 | template > 39 | class CursorStreamWrapper : public GenericStreamWrapper { 40 | public: 41 | typedef typename Encoding::Ch Ch; 42 | 43 | CursorStreamWrapper(InputStream& is): 44 | GenericStreamWrapper(is), line_(1), col_(0) {} 45 | 46 | // counting line and column number 47 | Ch Take() { 48 | Ch ch = this->is_.Take(); 49 | if(ch == '\n') { 50 | line_ ++; 51 | col_ = 0; 52 | } else { 53 | col_ ++; 54 | } 55 | return ch; 56 | } 57 | 58 | //! Get the error line number, if error exists. 59 | size_t GetLine() const { return line_; } 60 | //! Get the error column number, if error exists. 61 | size_t GetColumn() const { return col_; } 62 | 63 | private: 64 | size_t line_; //!< Current Line 65 | size_t col_; //!< Current Column 66 | }; 67 | 68 | #if defined(_MSC_VER) && _MSC_VER <= 1800 69 | RAPIDJSON_DIAG_POP 70 | #endif 71 | 72 | #if defined(__GNUC__) 73 | RAPIDJSON_DIAG_POP 74 | #endif 75 | 76 | RAPIDJSON_NAMESPACE_END 77 | 78 | #endif // RAPIDJSON_CURSORSTREAMWRAPPER_H_ 79 | -------------------------------------------------------------------------------- /UnityFPSUnlocker/third/rapidjson/rapidjson/error/en.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making RapidJSON available. 2 | // 3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef RAPIDJSON_ERROR_EN_H_ 16 | #define RAPIDJSON_ERROR_EN_H_ 17 | 18 | #include "error.h" 19 | 20 | #ifdef __clang__ 21 | RAPIDJSON_DIAG_PUSH 22 | RAPIDJSON_DIAG_OFF(switch-enum) 23 | RAPIDJSON_DIAG_OFF(covered-switch-default) 24 | #endif 25 | 26 | RAPIDJSON_NAMESPACE_BEGIN 27 | 28 | //! Maps error code of parsing into error message. 29 | /*! 30 | \ingroup RAPIDJSON_ERRORS 31 | \param parseErrorCode Error code obtained in parsing. 32 | \return the error message. 33 | \note User can make a copy of this function for localization. 34 | Using switch-case is safer for future modification of error codes. 35 | */ 36 | inline const RAPIDJSON_ERROR_CHARTYPE* GetParseError_En(ParseErrorCode parseErrorCode) { 37 | switch (parseErrorCode) { 38 | case kParseErrorNone: return RAPIDJSON_ERROR_STRING("No error."); 39 | 40 | case kParseErrorDocumentEmpty: return RAPIDJSON_ERROR_STRING("The document is empty."); 41 | case kParseErrorDocumentRootNotSingular: return RAPIDJSON_ERROR_STRING("The document root must not be followed by other values."); 42 | 43 | case kParseErrorValueInvalid: return RAPIDJSON_ERROR_STRING("Invalid value."); 44 | 45 | case kParseErrorObjectMissName: return RAPIDJSON_ERROR_STRING("Missing a name for object member."); 46 | case kParseErrorObjectMissColon: return RAPIDJSON_ERROR_STRING("Missing a colon after a name of object member."); 47 | case kParseErrorObjectMissCommaOrCurlyBracket: return RAPIDJSON_ERROR_STRING("Missing a comma or '}' after an object member."); 48 | 49 | case kParseErrorArrayMissCommaOrSquareBracket: return RAPIDJSON_ERROR_STRING("Missing a comma or ']' after an array element."); 50 | 51 | case kParseErrorStringUnicodeEscapeInvalidHex: return RAPIDJSON_ERROR_STRING("Incorrect hex digit after \\u escape in string."); 52 | case kParseErrorStringUnicodeSurrogateInvalid: return RAPIDJSON_ERROR_STRING("The surrogate pair in string is invalid."); 53 | case kParseErrorStringEscapeInvalid: return RAPIDJSON_ERROR_STRING("Invalid escape character in string."); 54 | case kParseErrorStringMissQuotationMark: return RAPIDJSON_ERROR_STRING("Missing a closing quotation mark in string."); 55 | case kParseErrorStringInvalidEncoding: return RAPIDJSON_ERROR_STRING("Invalid encoding in string."); 56 | 57 | case kParseErrorNumberTooBig: return RAPIDJSON_ERROR_STRING("Number too big to be stored in double."); 58 | case kParseErrorNumberMissFraction: return RAPIDJSON_ERROR_STRING("Miss fraction part in number."); 59 | case kParseErrorNumberMissExponent: return RAPIDJSON_ERROR_STRING("Miss exponent in number."); 60 | 61 | case kParseErrorTermination: return RAPIDJSON_ERROR_STRING("Terminate parsing due to Handler error."); 62 | case kParseErrorUnspecificSyntaxError: return RAPIDJSON_ERROR_STRING("Unspecific syntax error."); 63 | 64 | default: return RAPIDJSON_ERROR_STRING("Unknown error."); 65 | } 66 | } 67 | 68 | RAPIDJSON_NAMESPACE_END 69 | 70 | #ifdef __clang__ 71 | RAPIDJSON_DIAG_POP 72 | #endif 73 | 74 | #endif // RAPIDJSON_ERROR_EN_H_ 75 | -------------------------------------------------------------------------------- /UnityFPSUnlocker/third/rapidjson/rapidjson/error/error.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making RapidJSON available. 2 | // 3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef RAPIDJSON_ERROR_ERROR_H_ 16 | #define RAPIDJSON_ERROR_ERROR_H_ 17 | 18 | #include "../rapidjson.h" 19 | 20 | #ifdef __clang__ 21 | RAPIDJSON_DIAG_PUSH 22 | RAPIDJSON_DIAG_OFF(padded) 23 | #endif 24 | 25 | /*! \file error.h */ 26 | 27 | /*! \defgroup RAPIDJSON_ERRORS RapidJSON error handling */ 28 | 29 | /////////////////////////////////////////////////////////////////////////////// 30 | // RAPIDJSON_ERROR_CHARTYPE 31 | 32 | //! Character type of error messages. 33 | /*! \ingroup RAPIDJSON_ERRORS 34 | The default character type is \c char. 35 | On Windows, user can define this macro as \c TCHAR for supporting both 36 | unicode/non-unicode settings. 37 | */ 38 | #ifndef RAPIDJSON_ERROR_CHARTYPE 39 | #define RAPIDJSON_ERROR_CHARTYPE char 40 | #endif 41 | 42 | /////////////////////////////////////////////////////////////////////////////// 43 | // RAPIDJSON_ERROR_STRING 44 | 45 | //! Macro for converting string literial to \ref RAPIDJSON_ERROR_CHARTYPE[]. 46 | /*! \ingroup RAPIDJSON_ERRORS 47 | By default this conversion macro does nothing. 48 | On Windows, user can define this macro as \c _T(x) for supporting both 49 | unicode/non-unicode settings. 50 | */ 51 | #ifndef RAPIDJSON_ERROR_STRING 52 | #define RAPIDJSON_ERROR_STRING(x) x 53 | #endif 54 | 55 | RAPIDJSON_NAMESPACE_BEGIN 56 | 57 | /////////////////////////////////////////////////////////////////////////////// 58 | // ParseErrorCode 59 | 60 | //! Error code of parsing. 61 | /*! \ingroup RAPIDJSON_ERRORS 62 | \see GenericReader::Parse, GenericReader::GetParseErrorCode 63 | */ 64 | enum ParseErrorCode { 65 | kParseErrorNone = 0, //!< No error. 66 | 67 | kParseErrorDocumentEmpty, //!< The document is empty. 68 | kParseErrorDocumentRootNotSingular, //!< The document root must not follow by other values. 69 | 70 | kParseErrorValueInvalid, //!< Invalid value. 71 | 72 | kParseErrorObjectMissName, //!< Missing a name for object member. 73 | kParseErrorObjectMissColon, //!< Missing a colon after a name of object member. 74 | kParseErrorObjectMissCommaOrCurlyBracket, //!< Missing a comma or '}' after an object member. 75 | 76 | kParseErrorArrayMissCommaOrSquareBracket, //!< Missing a comma or ']' after an array element. 77 | 78 | kParseErrorStringUnicodeEscapeInvalidHex, //!< Incorrect hex digit after \\u escape in string. 79 | kParseErrorStringUnicodeSurrogateInvalid, //!< The surrogate pair in string is invalid. 80 | kParseErrorStringEscapeInvalid, //!< Invalid escape character in string. 81 | kParseErrorStringMissQuotationMark, //!< Missing a closing quotation mark in string. 82 | kParseErrorStringInvalidEncoding, //!< Invalid encoding in string. 83 | 84 | kParseErrorNumberTooBig, //!< Number too big to be stored in double. 85 | kParseErrorNumberMissFraction, //!< Miss fraction part in number. 86 | kParseErrorNumberMissExponent, //!< Miss exponent in number. 87 | 88 | kParseErrorTermination, //!< Parsing was terminated. 89 | kParseErrorUnspecificSyntaxError //!< Unspecific syntax error. 90 | }; 91 | 92 | //! Result of parsing (wraps ParseErrorCode) 93 | /*! 94 | \ingroup RAPIDJSON_ERRORS 95 | \code 96 | Document doc; 97 | ParseResult ok = doc.Parse("[42]"); 98 | if (!ok) { 99 | fprintf(stderr, "JSON parse error: %s (%u)", 100 | GetParseError_En(ok.Code()), ok.Offset()); 101 | exit(EXIT_FAILURE); 102 | } 103 | \endcode 104 | \see GenericReader::Parse, GenericDocument::Parse 105 | */ 106 | struct ParseResult { 107 | //!! Unspecified boolean type 108 | typedef bool (ParseResult::*BooleanType)() const; 109 | public: 110 | //! Default constructor, no error. 111 | ParseResult() : code_(kParseErrorNone), offset_(0) {} 112 | //! Constructor to set an error. 113 | ParseResult(ParseErrorCode code, size_t offset) : code_(code), offset_(offset) {} 114 | 115 | //! Get the error code. 116 | ParseErrorCode Code() const { return code_; } 117 | //! Get the error offset, if \ref IsError(), 0 otherwise. 118 | size_t Offset() const { return offset_; } 119 | 120 | //! Explicit conversion to \c bool, returns \c true, iff !\ref IsError(). 121 | operator BooleanType() const { return !IsError() ? &ParseResult::IsError : NULL; } 122 | //! Whether the result is an error. 123 | bool IsError() const { return code_ != kParseErrorNone; } 124 | 125 | bool operator==(const ParseResult& that) const { return code_ == that.code_; } 126 | bool operator==(ParseErrorCode code) const { return code_ == code; } 127 | friend bool operator==(ParseErrorCode code, const ParseResult & err) { return code == err.code_; } 128 | 129 | bool operator!=(const ParseResult& that) const { return !(*this == that); } 130 | bool operator!=(ParseErrorCode code) const { return !(*this == code); } 131 | friend bool operator!=(ParseErrorCode code, const ParseResult & err) { return err != code; } 132 | 133 | //! Reset error code. 134 | void Clear() { Set(kParseErrorNone); } 135 | //! Update error code and offset. 136 | void Set(ParseErrorCode code, size_t offset = 0) { code_ = code; offset_ = offset; } 137 | 138 | private: 139 | ParseErrorCode code_; 140 | size_t offset_; 141 | }; 142 | 143 | //! Function pointer type of GetParseError(). 144 | /*! \ingroup RAPIDJSON_ERRORS 145 | 146 | This is the prototype for \c GetParseError_X(), where \c X is a locale. 147 | User can dynamically change locale in runtime, e.g.: 148 | \code 149 | GetParseErrorFunc GetParseError = GetParseError_En; // or whatever 150 | const RAPIDJSON_ERROR_CHARTYPE* s = GetParseError(document.GetParseErrorCode()); 151 | \endcode 152 | */ 153 | typedef const RAPIDJSON_ERROR_CHARTYPE* (*GetParseErrorFunc)(ParseErrorCode); 154 | 155 | RAPIDJSON_NAMESPACE_END 156 | 157 | #ifdef __clang__ 158 | RAPIDJSON_DIAG_POP 159 | #endif 160 | 161 | #endif // RAPIDJSON_ERROR_ERROR_H_ 162 | -------------------------------------------------------------------------------- /UnityFPSUnlocker/third/rapidjson/rapidjson/filereadstream.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making RapidJSON available. 2 | // 3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef RAPIDJSON_FILEREADSTREAM_H_ 16 | #define RAPIDJSON_FILEREADSTREAM_H_ 17 | 18 | #include "stream.h" 19 | #include 20 | 21 | #ifdef __clang__ 22 | RAPIDJSON_DIAG_PUSH 23 | RAPIDJSON_DIAG_OFF(padded) 24 | RAPIDJSON_DIAG_OFF(unreachable-code) 25 | RAPIDJSON_DIAG_OFF(missing-noreturn) 26 | #endif 27 | 28 | RAPIDJSON_NAMESPACE_BEGIN 29 | 30 | //! File byte stream for input using fread(). 31 | /*! 32 | \note implements Stream concept 33 | */ 34 | class FileReadStream { 35 | public: 36 | typedef char Ch; //!< Character type (byte). 37 | 38 | //! Constructor. 39 | /*! 40 | \param fp File pointer opened for read. 41 | \param buffer user-supplied buffer. 42 | \param bufferSize size of buffer in bytes. Must >=4 bytes. 43 | */ 44 | FileReadStream(std::FILE* fp, char* buffer, size_t bufferSize) : fp_(fp), buffer_(buffer), bufferSize_(bufferSize), bufferLast_(0), current_(buffer_), readCount_(0), count_(0), eof_(false) { 45 | RAPIDJSON_ASSERT(fp_ != 0); 46 | RAPIDJSON_ASSERT(bufferSize >= 4); 47 | Read(); 48 | } 49 | 50 | Ch Peek() const { return *current_; } 51 | Ch Take() { Ch c = *current_; Read(); return c; } 52 | size_t Tell() const { return count_ + static_cast(current_ - buffer_); } 53 | 54 | // Not implemented 55 | void Put(Ch) { RAPIDJSON_ASSERT(false); } 56 | void Flush() { RAPIDJSON_ASSERT(false); } 57 | Ch* PutBegin() { RAPIDJSON_ASSERT(false); return 0; } 58 | size_t PutEnd(Ch*) { RAPIDJSON_ASSERT(false); return 0; } 59 | 60 | // For encoding detection only. 61 | const Ch* Peek4() const { 62 | return (current_ + 4 - !eof_ <= bufferLast_) ? current_ : 0; 63 | } 64 | 65 | private: 66 | void Read() { 67 | if (current_ < bufferLast_) 68 | ++current_; 69 | else if (!eof_) { 70 | count_ += readCount_; 71 | readCount_ = std::fread(buffer_, 1, bufferSize_, fp_); 72 | bufferLast_ = buffer_ + readCount_ - 1; 73 | current_ = buffer_; 74 | 75 | if (readCount_ < bufferSize_) { 76 | buffer_[readCount_] = '\0'; 77 | ++bufferLast_; 78 | eof_ = true; 79 | } 80 | } 81 | } 82 | 83 | std::FILE* fp_; 84 | Ch *buffer_; 85 | size_t bufferSize_; 86 | Ch *bufferLast_; 87 | Ch *current_; 88 | size_t readCount_; 89 | size_t count_; //!< Number of characters read 90 | bool eof_; 91 | }; 92 | 93 | RAPIDJSON_NAMESPACE_END 94 | 95 | #ifdef __clang__ 96 | RAPIDJSON_DIAG_POP 97 | #endif 98 | 99 | #endif // RAPIDJSON_FILESTREAM_H_ 100 | -------------------------------------------------------------------------------- /UnityFPSUnlocker/third/rapidjson/rapidjson/filewritestream.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making RapidJSON available. 2 | // 3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef RAPIDJSON_FILEWRITESTREAM_H_ 16 | #define RAPIDJSON_FILEWRITESTREAM_H_ 17 | 18 | #include "stream.h" 19 | #include 20 | 21 | #ifdef __clang__ 22 | RAPIDJSON_DIAG_PUSH 23 | RAPIDJSON_DIAG_OFF(unreachable-code) 24 | #endif 25 | 26 | RAPIDJSON_NAMESPACE_BEGIN 27 | 28 | //! Wrapper of C file stream for output using fwrite(). 29 | /*! 30 | \note implements Stream concept 31 | */ 32 | class FileWriteStream { 33 | public: 34 | typedef char Ch; //!< Character type. Only support char. 35 | 36 | FileWriteStream(std::FILE* fp, char* buffer, size_t bufferSize) : fp_(fp), buffer_(buffer), bufferEnd_(buffer + bufferSize), current_(buffer_) { 37 | RAPIDJSON_ASSERT(fp_ != 0); 38 | } 39 | 40 | void Put(char c) { 41 | if (current_ >= bufferEnd_) 42 | Flush(); 43 | 44 | *current_++ = c; 45 | } 46 | 47 | void PutN(char c, size_t n) { 48 | size_t avail = static_cast(bufferEnd_ - current_); 49 | while (n > avail) { 50 | std::memset(current_, c, avail); 51 | current_ += avail; 52 | Flush(); 53 | n -= avail; 54 | avail = static_cast(bufferEnd_ - current_); 55 | } 56 | 57 | if (n > 0) { 58 | std::memset(current_, c, n); 59 | current_ += n; 60 | } 61 | } 62 | 63 | void Flush() { 64 | if (current_ != buffer_) { 65 | size_t result = std::fwrite(buffer_, 1, static_cast(current_ - buffer_), fp_); 66 | if (result < static_cast(current_ - buffer_)) { 67 | // failure deliberately ignored at this time 68 | // added to avoid warn_unused_result build errors 69 | } 70 | current_ = buffer_; 71 | } 72 | } 73 | 74 | // Not implemented 75 | char Peek() const { RAPIDJSON_ASSERT(false); return 0; } 76 | char Take() { RAPIDJSON_ASSERT(false); return 0; } 77 | size_t Tell() const { RAPIDJSON_ASSERT(false); return 0; } 78 | char* PutBegin() { RAPIDJSON_ASSERT(false); return 0; } 79 | size_t PutEnd(char*) { RAPIDJSON_ASSERT(false); return 0; } 80 | 81 | private: 82 | // Prohibit copy constructor & assignment operator. 83 | FileWriteStream(const FileWriteStream&); 84 | FileWriteStream& operator=(const FileWriteStream&); 85 | 86 | std::FILE* fp_; 87 | char *buffer_; 88 | char *bufferEnd_; 89 | char *current_; 90 | }; 91 | 92 | //! Implement specialized version of PutN() with memset() for better performance. 93 | template<> 94 | inline void PutN(FileWriteStream& stream, char c, size_t n) { 95 | stream.PutN(c, n); 96 | } 97 | 98 | RAPIDJSON_NAMESPACE_END 99 | 100 | #ifdef __clang__ 101 | RAPIDJSON_DIAG_POP 102 | #endif 103 | 104 | #endif // RAPIDJSON_FILESTREAM_H_ 105 | -------------------------------------------------------------------------------- /UnityFPSUnlocker/third/rapidjson/rapidjson/fwd.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making RapidJSON available. 2 | // 3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef RAPIDJSON_FWD_H_ 16 | #define RAPIDJSON_FWD_H_ 17 | 18 | #include "rapidjson.h" 19 | 20 | RAPIDJSON_NAMESPACE_BEGIN 21 | 22 | // encodings.h 23 | 24 | template struct UTF8; 25 | template struct UTF16; 26 | template struct UTF16BE; 27 | template struct UTF16LE; 28 | template struct UTF32; 29 | template struct UTF32BE; 30 | template struct UTF32LE; 31 | template struct ASCII; 32 | template struct AutoUTF; 33 | 34 | template 35 | struct Transcoder; 36 | 37 | // allocators.h 38 | 39 | class CrtAllocator; 40 | 41 | template 42 | class MemoryPoolAllocator; 43 | 44 | // stream.h 45 | 46 | template 47 | struct GenericStringStream; 48 | 49 | typedef GenericStringStream > StringStream; 50 | 51 | template 52 | struct GenericInsituStringStream; 53 | 54 | typedef GenericInsituStringStream > InsituStringStream; 55 | 56 | // stringbuffer.h 57 | 58 | template 59 | class GenericStringBuffer; 60 | 61 | typedef GenericStringBuffer, CrtAllocator> StringBuffer; 62 | 63 | // filereadstream.h 64 | 65 | class FileReadStream; 66 | 67 | // filewritestream.h 68 | 69 | class FileWriteStream; 70 | 71 | // memorybuffer.h 72 | 73 | template 74 | struct GenericMemoryBuffer; 75 | 76 | typedef GenericMemoryBuffer MemoryBuffer; 77 | 78 | // memorystream.h 79 | 80 | struct MemoryStream; 81 | 82 | // reader.h 83 | 84 | template 85 | struct BaseReaderHandler; 86 | 87 | template 88 | class GenericReader; 89 | 90 | typedef GenericReader, UTF8, CrtAllocator> Reader; 91 | 92 | // writer.h 93 | 94 | template 95 | class Writer; 96 | 97 | // prettywriter.h 98 | 99 | template 100 | class PrettyWriter; 101 | 102 | // document.h 103 | 104 | template 105 | class GenericMember; 106 | 107 | template 108 | class GenericMemberIterator; 109 | 110 | template 111 | struct GenericStringRef; 112 | 113 | template 114 | class GenericValue; 115 | 116 | typedef GenericValue, MemoryPoolAllocator > Value; 117 | 118 | template 119 | class GenericDocument; 120 | 121 | typedef GenericDocument, MemoryPoolAllocator, CrtAllocator> Document; 122 | 123 | // pointer.h 124 | 125 | template 126 | class GenericPointer; 127 | 128 | typedef GenericPointer Pointer; 129 | 130 | // schema.h 131 | 132 | template 133 | class IGenericRemoteSchemaDocumentProvider; 134 | 135 | template 136 | class GenericSchemaDocument; 137 | 138 | typedef GenericSchemaDocument SchemaDocument; 139 | typedef IGenericRemoteSchemaDocumentProvider IRemoteSchemaDocumentProvider; 140 | 141 | template < 142 | typename SchemaDocumentType, 143 | typename OutputHandler, 144 | typename StateAllocator> 145 | class GenericSchemaValidator; 146 | 147 | typedef GenericSchemaValidator, void>, CrtAllocator> SchemaValidator; 148 | 149 | RAPIDJSON_NAMESPACE_END 150 | 151 | #endif // RAPIDJSON_RAPIDJSONFWD_H_ 152 | -------------------------------------------------------------------------------- /UnityFPSUnlocker/third/rapidjson/rapidjson/internal/biginteger.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making RapidJSON available. 2 | // 3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef RAPIDJSON_BIGINTEGER_H_ 16 | #define RAPIDJSON_BIGINTEGER_H_ 17 | 18 | #include "../rapidjson.h" 19 | 20 | #if defined(_MSC_VER) && !defined(__INTEL_COMPILER) && defined(_M_AMD64) 21 | #include // for _umul128 22 | #pragma intrinsic(_umul128) 23 | #endif 24 | 25 | RAPIDJSON_NAMESPACE_BEGIN 26 | namespace internal { 27 | 28 | class BigInteger { 29 | public: 30 | typedef uint64_t Type; 31 | 32 | BigInteger(const BigInteger& rhs) : count_(rhs.count_) { 33 | std::memcpy(digits_, rhs.digits_, count_ * sizeof(Type)); 34 | } 35 | 36 | explicit BigInteger(uint64_t u) : count_(1) { 37 | digits_[0] = u; 38 | } 39 | 40 | BigInteger(const char* decimals, size_t length) : count_(1) { 41 | RAPIDJSON_ASSERT(length > 0); 42 | digits_[0] = 0; 43 | size_t i = 0; 44 | const size_t kMaxDigitPerIteration = 19; // 2^64 = 18446744073709551616 > 10^19 45 | while (length >= kMaxDigitPerIteration) { 46 | AppendDecimal64(decimals + i, decimals + i + kMaxDigitPerIteration); 47 | length -= kMaxDigitPerIteration; 48 | i += kMaxDigitPerIteration; 49 | } 50 | 51 | if (length > 0) 52 | AppendDecimal64(decimals + i, decimals + i + length); 53 | } 54 | 55 | BigInteger& operator=(const BigInteger &rhs) 56 | { 57 | if (this != &rhs) { 58 | count_ = rhs.count_; 59 | std::memcpy(digits_, rhs.digits_, count_ * sizeof(Type)); 60 | } 61 | return *this; 62 | } 63 | 64 | BigInteger& operator=(uint64_t u) { 65 | digits_[0] = u; 66 | count_ = 1; 67 | return *this; 68 | } 69 | 70 | BigInteger& operator+=(uint64_t u) { 71 | Type backup = digits_[0]; 72 | digits_[0] += u; 73 | for (size_t i = 0; i < count_ - 1; i++) { 74 | if (digits_[i] >= backup) 75 | return *this; // no carry 76 | backup = digits_[i + 1]; 77 | digits_[i + 1] += 1; 78 | } 79 | 80 | // Last carry 81 | if (digits_[count_ - 1] < backup) 82 | PushBack(1); 83 | 84 | return *this; 85 | } 86 | 87 | BigInteger& operator*=(uint64_t u) { 88 | if (u == 0) return *this = 0; 89 | if (u == 1) return *this; 90 | if (*this == 1) return *this = u; 91 | 92 | uint64_t k = 0; 93 | for (size_t i = 0; i < count_; i++) { 94 | uint64_t hi; 95 | digits_[i] = MulAdd64(digits_[i], u, k, &hi); 96 | k = hi; 97 | } 98 | 99 | if (k > 0) 100 | PushBack(k); 101 | 102 | return *this; 103 | } 104 | 105 | BigInteger& operator*=(uint32_t u) { 106 | if (u == 0) return *this = 0; 107 | if (u == 1) return *this; 108 | if (*this == 1) return *this = u; 109 | 110 | uint64_t k = 0; 111 | for (size_t i = 0; i < count_; i++) { 112 | const uint64_t c = digits_[i] >> 32; 113 | const uint64_t d = digits_[i] & 0xFFFFFFFF; 114 | const uint64_t uc = u * c; 115 | const uint64_t ud = u * d; 116 | const uint64_t p0 = ud + k; 117 | const uint64_t p1 = uc + (p0 >> 32); 118 | digits_[i] = (p0 & 0xFFFFFFFF) | (p1 << 32); 119 | k = p1 >> 32; 120 | } 121 | 122 | if (k > 0) 123 | PushBack(k); 124 | 125 | return *this; 126 | } 127 | 128 | BigInteger& operator<<=(size_t shift) { 129 | if (IsZero() || shift == 0) return *this; 130 | 131 | size_t offset = shift / kTypeBit; 132 | size_t interShift = shift % kTypeBit; 133 | RAPIDJSON_ASSERT(count_ + offset <= kCapacity); 134 | 135 | if (interShift == 0) { 136 | std::memmove(digits_ + offset, digits_, count_ * sizeof(Type)); 137 | count_ += offset; 138 | } 139 | else { 140 | digits_[count_] = 0; 141 | for (size_t i = count_; i > 0; i--) 142 | digits_[i + offset] = (digits_[i] << interShift) | (digits_[i - 1] >> (kTypeBit - interShift)); 143 | digits_[offset] = digits_[0] << interShift; 144 | count_ += offset; 145 | if (digits_[count_]) 146 | count_++; 147 | } 148 | 149 | std::memset(digits_, 0, offset * sizeof(Type)); 150 | 151 | return *this; 152 | } 153 | 154 | bool operator==(const BigInteger& rhs) const { 155 | return count_ == rhs.count_ && std::memcmp(digits_, rhs.digits_, count_ * sizeof(Type)) == 0; 156 | } 157 | 158 | bool operator==(const Type rhs) const { 159 | return count_ == 1 && digits_[0] == rhs; 160 | } 161 | 162 | BigInteger& MultiplyPow5(unsigned exp) { 163 | static const uint32_t kPow5[12] = { 164 | 5, 165 | 5 * 5, 166 | 5 * 5 * 5, 167 | 5 * 5 * 5 * 5, 168 | 5 * 5 * 5 * 5 * 5, 169 | 5 * 5 * 5 * 5 * 5 * 5, 170 | 5 * 5 * 5 * 5 * 5 * 5 * 5, 171 | 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5, 172 | 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5, 173 | 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5, 174 | 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5, 175 | 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 176 | }; 177 | if (exp == 0) return *this; 178 | for (; exp >= 27; exp -= 27) *this *= RAPIDJSON_UINT64_C2(0X6765C793, 0XFA10079D); // 5^27 179 | for (; exp >= 13; exp -= 13) *this *= static_cast(1220703125u); // 5^13 180 | if (exp > 0) *this *= kPow5[exp - 1]; 181 | return *this; 182 | } 183 | 184 | // Compute absolute difference of this and rhs. 185 | // Assume this != rhs 186 | bool Difference(const BigInteger& rhs, BigInteger* out) const { 187 | int cmp = Compare(rhs); 188 | RAPIDJSON_ASSERT(cmp != 0); 189 | const BigInteger *a, *b; // Makes a > b 190 | bool ret; 191 | if (cmp < 0) { a = &rhs; b = this; ret = true; } 192 | else { a = this; b = &rhs; ret = false; } 193 | 194 | Type borrow = 0; 195 | for (size_t i = 0; i < a->count_; i++) { 196 | Type d = a->digits_[i] - borrow; 197 | if (i < b->count_) 198 | d -= b->digits_[i]; 199 | borrow = (d > a->digits_[i]) ? 1 : 0; 200 | out->digits_[i] = d; 201 | if (d != 0) 202 | out->count_ = i + 1; 203 | } 204 | 205 | return ret; 206 | } 207 | 208 | int Compare(const BigInteger& rhs) const { 209 | if (count_ != rhs.count_) 210 | return count_ < rhs.count_ ? -1 : 1; 211 | 212 | for (size_t i = count_; i-- > 0;) 213 | if (digits_[i] != rhs.digits_[i]) 214 | return digits_[i] < rhs.digits_[i] ? -1 : 1; 215 | 216 | return 0; 217 | } 218 | 219 | size_t GetCount() const { return count_; } 220 | Type GetDigit(size_t index) const { RAPIDJSON_ASSERT(index < count_); return digits_[index]; } 221 | bool IsZero() const { return count_ == 1 && digits_[0] == 0; } 222 | 223 | private: 224 | void AppendDecimal64(const char* begin, const char* end) { 225 | uint64_t u = ParseUint64(begin, end); 226 | if (IsZero()) 227 | *this = u; 228 | else { 229 | unsigned exp = static_cast(end - begin); 230 | (MultiplyPow5(exp) <<= exp) += u; // *this = *this * 10^exp + u 231 | } 232 | } 233 | 234 | void PushBack(Type digit) { 235 | RAPIDJSON_ASSERT(count_ < kCapacity); 236 | digits_[count_++] = digit; 237 | } 238 | 239 | static uint64_t ParseUint64(const char* begin, const char* end) { 240 | uint64_t r = 0; 241 | for (const char* p = begin; p != end; ++p) { 242 | RAPIDJSON_ASSERT(*p >= '0' && *p <= '9'); 243 | r = r * 10u + static_cast(*p - '0'); 244 | } 245 | return r; 246 | } 247 | 248 | // Assume a * b + k < 2^128 249 | static uint64_t MulAdd64(uint64_t a, uint64_t b, uint64_t k, uint64_t* outHigh) { 250 | #if defined(_MSC_VER) && defined(_M_AMD64) 251 | uint64_t low = _umul128(a, b, outHigh) + k; 252 | if (low < k) 253 | (*outHigh)++; 254 | return low; 255 | #elif (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) && defined(__x86_64__) 256 | __extension__ typedef unsigned __int128 uint128; 257 | uint128 p = static_cast(a) * static_cast(b); 258 | p += k; 259 | *outHigh = static_cast(p >> 64); 260 | return static_cast(p); 261 | #else 262 | const uint64_t a0 = a & 0xFFFFFFFF, a1 = a >> 32, b0 = b & 0xFFFFFFFF, b1 = b >> 32; 263 | uint64_t x0 = a0 * b0, x1 = a0 * b1, x2 = a1 * b0, x3 = a1 * b1; 264 | x1 += (x0 >> 32); // can't give carry 265 | x1 += x2; 266 | if (x1 < x2) 267 | x3 += (static_cast(1) << 32); 268 | uint64_t lo = (x1 << 32) + (x0 & 0xFFFFFFFF); 269 | uint64_t hi = x3 + (x1 >> 32); 270 | 271 | lo += k; 272 | if (lo < k) 273 | hi++; 274 | *outHigh = hi; 275 | return lo; 276 | #endif 277 | } 278 | 279 | static const size_t kBitCount = 3328; // 64bit * 54 > 10^1000 280 | static const size_t kCapacity = kBitCount / sizeof(Type); 281 | static const size_t kTypeBit = sizeof(Type) * 8; 282 | 283 | Type digits_[kCapacity]; 284 | size_t count_; 285 | }; 286 | 287 | } // namespace internal 288 | RAPIDJSON_NAMESPACE_END 289 | 290 | #endif // RAPIDJSON_BIGINTEGER_H_ 291 | -------------------------------------------------------------------------------- /UnityFPSUnlocker/third/rapidjson/rapidjson/internal/clzll.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making RapidJSON available. 2 | // 3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef RAPIDJSON_CLZLL_H_ 16 | #define RAPIDJSON_CLZLL_H_ 17 | 18 | #include "../rapidjson.h" 19 | 20 | #if defined(_MSC_VER) 21 | #include 22 | #if defined(_WIN64) 23 | #pragma intrinsic(_BitScanReverse64) 24 | #else 25 | #pragma intrinsic(_BitScanReverse) 26 | #endif 27 | #endif 28 | 29 | RAPIDJSON_NAMESPACE_BEGIN 30 | namespace internal { 31 | 32 | inline uint32_t clzll(uint64_t x) { 33 | // Passing 0 to __builtin_clzll is UB in GCC and results in an 34 | // infinite loop in the software implementation. 35 | RAPIDJSON_ASSERT(x != 0); 36 | 37 | #if defined(_MSC_VER) 38 | unsigned long r = 0; 39 | #if defined(_WIN64) 40 | _BitScanReverse64(&r, x); 41 | #else 42 | // Scan the high 32 bits. 43 | if (_BitScanReverse(&r, static_cast(x >> 32))) 44 | return 63 - (r + 32); 45 | 46 | // Scan the low 32 bits. 47 | _BitScanReverse(&r, static_cast(x & 0xFFFFFFFF)); 48 | #endif // _WIN64 49 | 50 | return 63 - r; 51 | #elif (defined(__GNUC__) && __GNUC__ >= 4) || RAPIDJSON_HAS_BUILTIN(__builtin_clzll) 52 | // __builtin_clzll wrapper 53 | return static_cast(__builtin_clzll(x)); 54 | #else 55 | // naive version 56 | uint32_t r; 57 | while (!(x & (static_cast(1) << 63))) { 58 | x <<= 1; 59 | ++r; 60 | } 61 | 62 | return r; 63 | #endif // _MSC_VER 64 | } 65 | 66 | #define RAPIDJSON_CLZLL RAPIDJSON_NAMESPACE::internal::clzll 67 | 68 | } // namespace internal 69 | RAPIDJSON_NAMESPACE_END 70 | 71 | #endif // RAPIDJSON_CLZLL_H_ 72 | -------------------------------------------------------------------------------- /UnityFPSUnlocker/third/rapidjson/rapidjson/internal/dtoa.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making RapidJSON available. 2 | // 3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | // This is a C++ header-only implementation of Grisu2 algorithm from the publication: 16 | // Loitsch, Florian. "Printing floating-point numbers quickly and accurately with 17 | // integers." ACM Sigplan Notices 45.6 (2010): 233-243. 18 | 19 | #ifndef RAPIDJSON_DTOA_ 20 | #define RAPIDJSON_DTOA_ 21 | 22 | #include "itoa.h" // GetDigitsLut() 23 | #include "diyfp.h" 24 | #include "ieee754.h" 25 | 26 | RAPIDJSON_NAMESPACE_BEGIN 27 | namespace internal { 28 | 29 | #ifdef __GNUC__ 30 | RAPIDJSON_DIAG_PUSH 31 | RAPIDJSON_DIAG_OFF(effc++) 32 | RAPIDJSON_DIAG_OFF(array-bounds) // some gcc versions generate wrong warnings https://gcc.gnu.org/bugzilla/show_bug.cgi?id=59124 33 | #endif 34 | 35 | inline void GrisuRound(char* buffer, int len, uint64_t delta, uint64_t rest, uint64_t ten_kappa, uint64_t wp_w) { 36 | while (rest < wp_w && delta - rest >= ten_kappa && 37 | (rest + ten_kappa < wp_w || /// closer 38 | wp_w - rest > rest + ten_kappa - wp_w)) { 39 | buffer[len - 1]--; 40 | rest += ten_kappa; 41 | } 42 | } 43 | 44 | inline int CountDecimalDigit32(uint32_t n) { 45 | // Simple pure C++ implementation was faster than __builtin_clz version in this situation. 46 | if (n < 10) return 1; 47 | if (n < 100) return 2; 48 | if (n < 1000) return 3; 49 | if (n < 10000) return 4; 50 | if (n < 100000) return 5; 51 | if (n < 1000000) return 6; 52 | if (n < 10000000) return 7; 53 | if (n < 100000000) return 8; 54 | // Will not reach 10 digits in DigitGen() 55 | //if (n < 1000000000) return 9; 56 | //return 10; 57 | return 9; 58 | } 59 | 60 | inline void DigitGen(const DiyFp& W, const DiyFp& Mp, uint64_t delta, char* buffer, int* len, int* K) { 61 | static const uint32_t kPow10[] = { 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000 }; 62 | const DiyFp one(uint64_t(1) << -Mp.e, Mp.e); 63 | const DiyFp wp_w = Mp - W; 64 | uint32_t p1 = static_cast(Mp.f >> -one.e); 65 | uint64_t p2 = Mp.f & (one.f - 1); 66 | int kappa = CountDecimalDigit32(p1); // kappa in [0, 9] 67 | *len = 0; 68 | 69 | while (kappa > 0) { 70 | uint32_t d = 0; 71 | switch (kappa) { 72 | case 9: d = p1 / 100000000; p1 %= 100000000; break; 73 | case 8: d = p1 / 10000000; p1 %= 10000000; break; 74 | case 7: d = p1 / 1000000; p1 %= 1000000; break; 75 | case 6: d = p1 / 100000; p1 %= 100000; break; 76 | case 5: d = p1 / 10000; p1 %= 10000; break; 77 | case 4: d = p1 / 1000; p1 %= 1000; break; 78 | case 3: d = p1 / 100; p1 %= 100; break; 79 | case 2: d = p1 / 10; p1 %= 10; break; 80 | case 1: d = p1; p1 = 0; break; 81 | default:; 82 | } 83 | if (d || *len) 84 | buffer[(*len)++] = static_cast('0' + static_cast(d)); 85 | kappa--; 86 | uint64_t tmp = (static_cast(p1) << -one.e) + p2; 87 | if (tmp <= delta) { 88 | *K += kappa; 89 | GrisuRound(buffer, *len, delta, tmp, static_cast(kPow10[kappa]) << -one.e, wp_w.f); 90 | return; 91 | } 92 | } 93 | 94 | // kappa = 0 95 | for (;;) { 96 | p2 *= 10; 97 | delta *= 10; 98 | char d = static_cast(p2 >> -one.e); 99 | if (d || *len) 100 | buffer[(*len)++] = static_cast('0' + d); 101 | p2 &= one.f - 1; 102 | kappa--; 103 | if (p2 < delta) { 104 | *K += kappa; 105 | int index = -kappa; 106 | GrisuRound(buffer, *len, delta, p2, one.f, wp_w.f * (index < 9 ? kPow10[index] : 0)); 107 | return; 108 | } 109 | } 110 | } 111 | 112 | inline void Grisu2(double value, char* buffer, int* length, int* K) { 113 | const DiyFp v(value); 114 | DiyFp w_m, w_p; 115 | v.NormalizedBoundaries(&w_m, &w_p); 116 | 117 | const DiyFp c_mk = GetCachedPower(w_p.e, K); 118 | const DiyFp W = v.Normalize() * c_mk; 119 | DiyFp Wp = w_p * c_mk; 120 | DiyFp Wm = w_m * c_mk; 121 | Wm.f++; 122 | Wp.f--; 123 | DigitGen(W, Wp, Wp.f - Wm.f, buffer, length, K); 124 | } 125 | 126 | inline char* WriteExponent(int K, char* buffer) { 127 | if (K < 0) { 128 | *buffer++ = '-'; 129 | K = -K; 130 | } 131 | 132 | if (K >= 100) { 133 | *buffer++ = static_cast('0' + static_cast(K / 100)); 134 | K %= 100; 135 | const char* d = GetDigitsLut() + K * 2; 136 | *buffer++ = d[0]; 137 | *buffer++ = d[1]; 138 | } 139 | else if (K >= 10) { 140 | const char* d = GetDigitsLut() + K * 2; 141 | *buffer++ = d[0]; 142 | *buffer++ = d[1]; 143 | } 144 | else 145 | *buffer++ = static_cast('0' + static_cast(K)); 146 | 147 | return buffer; 148 | } 149 | 150 | inline char* Prettify(char* buffer, int length, int k, int maxDecimalPlaces) { 151 | const int kk = length + k; // 10^(kk-1) <= v < 10^kk 152 | 153 | if (0 <= k && kk <= 21) { 154 | // 1234e7 -> 12340000000 155 | for (int i = length; i < kk; i++) 156 | buffer[i] = '0'; 157 | buffer[kk] = '.'; 158 | buffer[kk + 1] = '0'; 159 | return &buffer[kk + 2]; 160 | } 161 | else if (0 < kk && kk <= 21) { 162 | // 1234e-2 -> 12.34 163 | std::memmove(&buffer[kk + 1], &buffer[kk], static_cast(length - kk)); 164 | buffer[kk] = '.'; 165 | if (0 > k + maxDecimalPlaces) { 166 | // When maxDecimalPlaces = 2, 1.2345 -> 1.23, 1.102 -> 1.1 167 | // Remove extra trailing zeros (at least one) after truncation. 168 | for (int i = kk + maxDecimalPlaces; i > kk + 1; i--) 169 | if (buffer[i] != '0') 170 | return &buffer[i + 1]; 171 | return &buffer[kk + 2]; // Reserve one zero 172 | } 173 | else 174 | return &buffer[length + 1]; 175 | } 176 | else if (-6 < kk && kk <= 0) { 177 | // 1234e-6 -> 0.001234 178 | const int offset = 2 - kk; 179 | std::memmove(&buffer[offset], &buffer[0], static_cast(length)); 180 | buffer[0] = '0'; 181 | buffer[1] = '.'; 182 | for (int i = 2; i < offset; i++) 183 | buffer[i] = '0'; 184 | if (length - kk > maxDecimalPlaces) { 185 | // When maxDecimalPlaces = 2, 0.123 -> 0.12, 0.102 -> 0.1 186 | // Remove extra trailing zeros (at least one) after truncation. 187 | for (int i = maxDecimalPlaces + 1; i > 2; i--) 188 | if (buffer[i] != '0') 189 | return &buffer[i + 1]; 190 | return &buffer[3]; // Reserve one zero 191 | } 192 | else 193 | return &buffer[length + offset]; 194 | } 195 | else if (kk < -maxDecimalPlaces) { 196 | // Truncate to zero 197 | buffer[0] = '0'; 198 | buffer[1] = '.'; 199 | buffer[2] = '0'; 200 | return &buffer[3]; 201 | } 202 | else if (length == 1) { 203 | // 1e30 204 | buffer[1] = 'e'; 205 | return WriteExponent(kk - 1, &buffer[2]); 206 | } 207 | else { 208 | // 1234e30 -> 1.234e33 209 | std::memmove(&buffer[2], &buffer[1], static_cast(length - 1)); 210 | buffer[1] = '.'; 211 | buffer[length + 1] = 'e'; 212 | return WriteExponent(kk - 1, &buffer[0 + length + 2]); 213 | } 214 | } 215 | 216 | inline char* dtoa(double value, char* buffer, int maxDecimalPlaces = 324) { 217 | RAPIDJSON_ASSERT(maxDecimalPlaces >= 1); 218 | Double d(value); 219 | if (d.IsZero()) { 220 | if (d.Sign()) 221 | *buffer++ = '-'; // -0.0, Issue #289 222 | buffer[0] = '0'; 223 | buffer[1] = '.'; 224 | buffer[2] = '0'; 225 | return &buffer[3]; 226 | } 227 | else { 228 | if (value < 0) { 229 | *buffer++ = '-'; 230 | value = -value; 231 | } 232 | int length, K; 233 | Grisu2(value, buffer, &length, &K); 234 | return Prettify(buffer, length, K, maxDecimalPlaces); 235 | } 236 | } 237 | 238 | #ifdef __GNUC__ 239 | RAPIDJSON_DIAG_POP 240 | #endif 241 | 242 | } // namespace internal 243 | RAPIDJSON_NAMESPACE_END 244 | 245 | #endif // RAPIDJSON_DTOA_ 246 | -------------------------------------------------------------------------------- /UnityFPSUnlocker/third/rapidjson/rapidjson/internal/ieee754.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making RapidJSON available. 2 | // 3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef RAPIDJSON_IEEE754_ 16 | #define RAPIDJSON_IEEE754_ 17 | 18 | #include "../rapidjson.h" 19 | 20 | RAPIDJSON_NAMESPACE_BEGIN 21 | namespace internal { 22 | 23 | class Double { 24 | public: 25 | Double() {} 26 | Double(double d) : d_(d) {} 27 | Double(uint64_t u) : u_(u) {} 28 | 29 | double Value() const { return d_; } 30 | uint64_t Uint64Value() const { return u_; } 31 | 32 | double NextPositiveDouble() const { 33 | RAPIDJSON_ASSERT(!Sign()); 34 | return Double(u_ + 1).Value(); 35 | } 36 | 37 | bool Sign() const { return (u_ & kSignMask) != 0; } 38 | uint64_t Significand() const { return u_ & kSignificandMask; } 39 | int Exponent() const { return static_cast(((u_ & kExponentMask) >> kSignificandSize) - kExponentBias); } 40 | 41 | bool IsNan() const { return (u_ & kExponentMask) == kExponentMask && Significand() != 0; } 42 | bool IsInf() const { return (u_ & kExponentMask) == kExponentMask && Significand() == 0; } 43 | bool IsNanOrInf() const { return (u_ & kExponentMask) == kExponentMask; } 44 | bool IsNormal() const { return (u_ & kExponentMask) != 0 || Significand() == 0; } 45 | bool IsZero() const { return (u_ & (kExponentMask | kSignificandMask)) == 0; } 46 | 47 | uint64_t IntegerSignificand() const { return IsNormal() ? Significand() | kHiddenBit : Significand(); } 48 | int IntegerExponent() const { return (IsNormal() ? Exponent() : kDenormalExponent) - kSignificandSize; } 49 | uint64_t ToBias() const { return (u_ & kSignMask) ? ~u_ + 1 : u_ | kSignMask; } 50 | 51 | static int EffectiveSignificandSize(int order) { 52 | if (order >= -1021) 53 | return 53; 54 | else if (order <= -1074) 55 | return 0; 56 | else 57 | return order + 1074; 58 | } 59 | 60 | private: 61 | static const int kSignificandSize = 52; 62 | static const int kExponentBias = 0x3FF; 63 | static const int kDenormalExponent = 1 - kExponentBias; 64 | static const uint64_t kSignMask = RAPIDJSON_UINT64_C2(0x80000000, 0x00000000); 65 | static const uint64_t kExponentMask = RAPIDJSON_UINT64_C2(0x7FF00000, 0x00000000); 66 | static const uint64_t kSignificandMask = RAPIDJSON_UINT64_C2(0x000FFFFF, 0xFFFFFFFF); 67 | static const uint64_t kHiddenBit = RAPIDJSON_UINT64_C2(0x00100000, 0x00000000); 68 | 69 | union { 70 | double d_; 71 | uint64_t u_; 72 | }; 73 | }; 74 | 75 | } // namespace internal 76 | RAPIDJSON_NAMESPACE_END 77 | 78 | #endif // RAPIDJSON_IEEE754_ 79 | -------------------------------------------------------------------------------- /UnityFPSUnlocker/third/rapidjson/rapidjson/internal/meta.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making RapidJSON available. 2 | // 3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef RAPIDJSON_INTERNAL_META_H_ 16 | #define RAPIDJSON_INTERNAL_META_H_ 17 | 18 | #include "../rapidjson.h" 19 | 20 | #ifdef __GNUC__ 21 | RAPIDJSON_DIAG_PUSH 22 | RAPIDJSON_DIAG_OFF(effc++) 23 | #endif 24 | 25 | #if defined(_MSC_VER) && !defined(__clang__) 26 | RAPIDJSON_DIAG_PUSH 27 | RAPIDJSON_DIAG_OFF(6334) 28 | #endif 29 | 30 | #if RAPIDJSON_HAS_CXX11_TYPETRAITS 31 | #include 32 | #endif 33 | 34 | //@cond RAPIDJSON_INTERNAL 35 | RAPIDJSON_NAMESPACE_BEGIN 36 | namespace internal { 37 | 38 | // Helper to wrap/convert arbitrary types to void, useful for arbitrary type matching 39 | template struct Void { typedef void Type; }; 40 | 41 | /////////////////////////////////////////////////////////////////////////////// 42 | // BoolType, TrueType, FalseType 43 | // 44 | template struct BoolType { 45 | static const bool Value = Cond; 46 | typedef BoolType Type; 47 | }; 48 | typedef BoolType TrueType; 49 | typedef BoolType FalseType; 50 | 51 | 52 | /////////////////////////////////////////////////////////////////////////////// 53 | // SelectIf, BoolExpr, NotExpr, AndExpr, OrExpr 54 | // 55 | 56 | template struct SelectIfImpl { template struct Apply { typedef T1 Type; }; }; 57 | template <> struct SelectIfImpl { template struct Apply { typedef T2 Type; }; }; 58 | template struct SelectIfCond : SelectIfImpl::template Apply {}; 59 | template struct SelectIf : SelectIfCond {}; 60 | 61 | template struct AndExprCond : FalseType {}; 62 | template <> struct AndExprCond : TrueType {}; 63 | template struct OrExprCond : TrueType {}; 64 | template <> struct OrExprCond : FalseType {}; 65 | 66 | template struct BoolExpr : SelectIf::Type {}; 67 | template struct NotExpr : SelectIf::Type {}; 68 | template struct AndExpr : AndExprCond::Type {}; 69 | template struct OrExpr : OrExprCond::Type {}; 70 | 71 | 72 | /////////////////////////////////////////////////////////////////////////////// 73 | // AddConst, MaybeAddConst, RemoveConst 74 | template struct AddConst { typedef const T Type; }; 75 | template struct MaybeAddConst : SelectIfCond {}; 76 | template struct RemoveConst { typedef T Type; }; 77 | template struct RemoveConst { typedef T Type; }; 78 | 79 | 80 | /////////////////////////////////////////////////////////////////////////////// 81 | // IsSame, IsConst, IsMoreConst, IsPointer 82 | // 83 | template struct IsSame : FalseType {}; 84 | template struct IsSame : TrueType {}; 85 | 86 | template struct IsConst : FalseType {}; 87 | template struct IsConst : TrueType {}; 88 | 89 | template 90 | struct IsMoreConst 91 | : AndExpr::Type, typename RemoveConst::Type>, 92 | BoolType::Value >= IsConst::Value> >::Type {}; 93 | 94 | template struct IsPointer : FalseType {}; 95 | template struct IsPointer : TrueType {}; 96 | 97 | /////////////////////////////////////////////////////////////////////////////// 98 | // IsBaseOf 99 | // 100 | #if RAPIDJSON_HAS_CXX11_TYPETRAITS 101 | 102 | template struct IsBaseOf 103 | : BoolType< ::std::is_base_of::value> {}; 104 | 105 | #else // simplified version adopted from Boost 106 | 107 | template struct IsBaseOfImpl { 108 | RAPIDJSON_STATIC_ASSERT(sizeof(B) != 0); 109 | RAPIDJSON_STATIC_ASSERT(sizeof(D) != 0); 110 | 111 | typedef char (&Yes)[1]; 112 | typedef char (&No) [2]; 113 | 114 | template 115 | static Yes Check(const D*, T); 116 | static No Check(const B*, int); 117 | 118 | struct Host { 119 | operator const B*() const; 120 | operator const D*(); 121 | }; 122 | 123 | enum { Value = (sizeof(Check(Host(), 0)) == sizeof(Yes)) }; 124 | }; 125 | 126 | template struct IsBaseOf 127 | : OrExpr, BoolExpr > >::Type {}; 128 | 129 | #endif // RAPIDJSON_HAS_CXX11_TYPETRAITS 130 | 131 | 132 | ////////////////////////////////////////////////////////////////////////// 133 | // EnableIf / DisableIf 134 | // 135 | template struct EnableIfCond { typedef T Type; }; 136 | template struct EnableIfCond { /* empty */ }; 137 | 138 | template struct DisableIfCond { typedef T Type; }; 139 | template struct DisableIfCond { /* empty */ }; 140 | 141 | template 142 | struct EnableIf : EnableIfCond {}; 143 | 144 | template 145 | struct DisableIf : DisableIfCond {}; 146 | 147 | // SFINAE helpers 148 | struct SfinaeTag {}; 149 | template struct RemoveSfinaeTag; 150 | template struct RemoveSfinaeTag { typedef T Type; }; 151 | 152 | #define RAPIDJSON_REMOVEFPTR_(type) \ 153 | typename ::RAPIDJSON_NAMESPACE::internal::RemoveSfinaeTag \ 154 | < ::RAPIDJSON_NAMESPACE::internal::SfinaeTag&(*) type>::Type 155 | 156 | #define RAPIDJSON_ENABLEIF(cond) \ 157 | typename ::RAPIDJSON_NAMESPACE::internal::EnableIf \ 158 | ::Type * = NULL 159 | 160 | #define RAPIDJSON_DISABLEIF(cond) \ 161 | typename ::RAPIDJSON_NAMESPACE::internal::DisableIf \ 162 | ::Type * = NULL 163 | 164 | #define RAPIDJSON_ENABLEIF_RETURN(cond,returntype) \ 165 | typename ::RAPIDJSON_NAMESPACE::internal::EnableIf \ 166 | ::Type 168 | 169 | #define RAPIDJSON_DISABLEIF_RETURN(cond,returntype) \ 170 | typename ::RAPIDJSON_NAMESPACE::internal::DisableIf \ 171 | ::Type 173 | 174 | } // namespace internal 175 | RAPIDJSON_NAMESPACE_END 176 | //@endcond 177 | 178 | #if defined(_MSC_VER) && !defined(__clang__) 179 | RAPIDJSON_DIAG_POP 180 | #endif 181 | 182 | #ifdef __GNUC__ 183 | RAPIDJSON_DIAG_POP 184 | #endif 185 | 186 | #endif // RAPIDJSON_INTERNAL_META_H_ 187 | -------------------------------------------------------------------------------- /UnityFPSUnlocker/third/rapidjson/rapidjson/internal/pow10.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making RapidJSON available. 2 | // 3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef RAPIDJSON_POW10_ 16 | #define RAPIDJSON_POW10_ 17 | 18 | #include "../rapidjson.h" 19 | 20 | RAPIDJSON_NAMESPACE_BEGIN 21 | namespace internal { 22 | 23 | //! Computes integer powers of 10 in double (10.0^n). 24 | /*! This function uses lookup table for fast and accurate results. 25 | \param n non-negative exponent. Must <= 308. 26 | \return 10.0^n 27 | */ 28 | inline double Pow10(int n) { 29 | static const double e[] = { // 1e-0...1e308: 309 * 8 bytes = 2472 bytes 30 | 1e+0, 31 | 1e+1, 1e+2, 1e+3, 1e+4, 1e+5, 1e+6, 1e+7, 1e+8, 1e+9, 1e+10, 1e+11, 1e+12, 1e+13, 1e+14, 1e+15, 1e+16, 1e+17, 1e+18, 1e+19, 1e+20, 32 | 1e+21, 1e+22, 1e+23, 1e+24, 1e+25, 1e+26, 1e+27, 1e+28, 1e+29, 1e+30, 1e+31, 1e+32, 1e+33, 1e+34, 1e+35, 1e+36, 1e+37, 1e+38, 1e+39, 1e+40, 33 | 1e+41, 1e+42, 1e+43, 1e+44, 1e+45, 1e+46, 1e+47, 1e+48, 1e+49, 1e+50, 1e+51, 1e+52, 1e+53, 1e+54, 1e+55, 1e+56, 1e+57, 1e+58, 1e+59, 1e+60, 34 | 1e+61, 1e+62, 1e+63, 1e+64, 1e+65, 1e+66, 1e+67, 1e+68, 1e+69, 1e+70, 1e+71, 1e+72, 1e+73, 1e+74, 1e+75, 1e+76, 1e+77, 1e+78, 1e+79, 1e+80, 35 | 1e+81, 1e+82, 1e+83, 1e+84, 1e+85, 1e+86, 1e+87, 1e+88, 1e+89, 1e+90, 1e+91, 1e+92, 1e+93, 1e+94, 1e+95, 1e+96, 1e+97, 1e+98, 1e+99, 1e+100, 36 | 1e+101,1e+102,1e+103,1e+104,1e+105,1e+106,1e+107,1e+108,1e+109,1e+110,1e+111,1e+112,1e+113,1e+114,1e+115,1e+116,1e+117,1e+118,1e+119,1e+120, 37 | 1e+121,1e+122,1e+123,1e+124,1e+125,1e+126,1e+127,1e+128,1e+129,1e+130,1e+131,1e+132,1e+133,1e+134,1e+135,1e+136,1e+137,1e+138,1e+139,1e+140, 38 | 1e+141,1e+142,1e+143,1e+144,1e+145,1e+146,1e+147,1e+148,1e+149,1e+150,1e+151,1e+152,1e+153,1e+154,1e+155,1e+156,1e+157,1e+158,1e+159,1e+160, 39 | 1e+161,1e+162,1e+163,1e+164,1e+165,1e+166,1e+167,1e+168,1e+169,1e+170,1e+171,1e+172,1e+173,1e+174,1e+175,1e+176,1e+177,1e+178,1e+179,1e+180, 40 | 1e+181,1e+182,1e+183,1e+184,1e+185,1e+186,1e+187,1e+188,1e+189,1e+190,1e+191,1e+192,1e+193,1e+194,1e+195,1e+196,1e+197,1e+198,1e+199,1e+200, 41 | 1e+201,1e+202,1e+203,1e+204,1e+205,1e+206,1e+207,1e+208,1e+209,1e+210,1e+211,1e+212,1e+213,1e+214,1e+215,1e+216,1e+217,1e+218,1e+219,1e+220, 42 | 1e+221,1e+222,1e+223,1e+224,1e+225,1e+226,1e+227,1e+228,1e+229,1e+230,1e+231,1e+232,1e+233,1e+234,1e+235,1e+236,1e+237,1e+238,1e+239,1e+240, 43 | 1e+241,1e+242,1e+243,1e+244,1e+245,1e+246,1e+247,1e+248,1e+249,1e+250,1e+251,1e+252,1e+253,1e+254,1e+255,1e+256,1e+257,1e+258,1e+259,1e+260, 44 | 1e+261,1e+262,1e+263,1e+264,1e+265,1e+266,1e+267,1e+268,1e+269,1e+270,1e+271,1e+272,1e+273,1e+274,1e+275,1e+276,1e+277,1e+278,1e+279,1e+280, 45 | 1e+281,1e+282,1e+283,1e+284,1e+285,1e+286,1e+287,1e+288,1e+289,1e+290,1e+291,1e+292,1e+293,1e+294,1e+295,1e+296,1e+297,1e+298,1e+299,1e+300, 46 | 1e+301,1e+302,1e+303,1e+304,1e+305,1e+306,1e+307,1e+308 47 | }; 48 | RAPIDJSON_ASSERT(n >= 0 && n <= 308); 49 | return e[n]; 50 | } 51 | 52 | } // namespace internal 53 | RAPIDJSON_NAMESPACE_END 54 | 55 | #endif // RAPIDJSON_POW10_ 56 | -------------------------------------------------------------------------------- /UnityFPSUnlocker/third/rapidjson/rapidjson/internal/stack.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making RapidJSON available. 2 | // 3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef RAPIDJSON_INTERNAL_STACK_H_ 16 | #define RAPIDJSON_INTERNAL_STACK_H_ 17 | 18 | #include "../allocators.h" 19 | #include "swap.h" 20 | #include 21 | 22 | #if defined(__clang__) 23 | RAPIDJSON_DIAG_PUSH 24 | RAPIDJSON_DIAG_OFF(c++98-compat) 25 | #endif 26 | 27 | RAPIDJSON_NAMESPACE_BEGIN 28 | namespace internal { 29 | 30 | /////////////////////////////////////////////////////////////////////////////// 31 | // Stack 32 | 33 | //! A type-unsafe stack for storing different types of data. 34 | /*! \tparam Allocator Allocator for allocating stack memory. 35 | */ 36 | template 37 | class Stack { 38 | public: 39 | // Optimization note: Do not allocate memory for stack_ in constructor. 40 | // Do it lazily when first Push() -> Expand() -> Resize(). 41 | Stack(Allocator* allocator, size_t stackCapacity) : allocator_(allocator), ownAllocator_(0), stack_(0), stackTop_(0), stackEnd_(0), initialCapacity_(stackCapacity) { 42 | } 43 | 44 | #if RAPIDJSON_HAS_CXX11_RVALUE_REFS 45 | Stack(Stack&& rhs) 46 | : allocator_(rhs.allocator_), 47 | ownAllocator_(rhs.ownAllocator_), 48 | stack_(rhs.stack_), 49 | stackTop_(rhs.stackTop_), 50 | stackEnd_(rhs.stackEnd_), 51 | initialCapacity_(rhs.initialCapacity_) 52 | { 53 | rhs.allocator_ = 0; 54 | rhs.ownAllocator_ = 0; 55 | rhs.stack_ = 0; 56 | rhs.stackTop_ = 0; 57 | rhs.stackEnd_ = 0; 58 | rhs.initialCapacity_ = 0; 59 | } 60 | #endif 61 | 62 | ~Stack() { 63 | Destroy(); 64 | } 65 | 66 | #if RAPIDJSON_HAS_CXX11_RVALUE_REFS 67 | Stack& operator=(Stack&& rhs) { 68 | if (&rhs != this) 69 | { 70 | Destroy(); 71 | 72 | allocator_ = rhs.allocator_; 73 | ownAllocator_ = rhs.ownAllocator_; 74 | stack_ = rhs.stack_; 75 | stackTop_ = rhs.stackTop_; 76 | stackEnd_ = rhs.stackEnd_; 77 | initialCapacity_ = rhs.initialCapacity_; 78 | 79 | rhs.allocator_ = 0; 80 | rhs.ownAllocator_ = 0; 81 | rhs.stack_ = 0; 82 | rhs.stackTop_ = 0; 83 | rhs.stackEnd_ = 0; 84 | rhs.initialCapacity_ = 0; 85 | } 86 | return *this; 87 | } 88 | #endif 89 | 90 | void Swap(Stack& rhs) RAPIDJSON_NOEXCEPT { 91 | internal::Swap(allocator_, rhs.allocator_); 92 | internal::Swap(ownAllocator_, rhs.ownAllocator_); 93 | internal::Swap(stack_, rhs.stack_); 94 | internal::Swap(stackTop_, rhs.stackTop_); 95 | internal::Swap(stackEnd_, rhs.stackEnd_); 96 | internal::Swap(initialCapacity_, rhs.initialCapacity_); 97 | } 98 | 99 | void Clear() { stackTop_ = stack_; } 100 | 101 | void ShrinkToFit() { 102 | if (Empty()) { 103 | // If the stack is empty, completely deallocate the memory. 104 | Allocator::Free(stack_); // NOLINT (+clang-analyzer-unix.Malloc) 105 | stack_ = 0; 106 | stackTop_ = 0; 107 | stackEnd_ = 0; 108 | } 109 | else 110 | Resize(GetSize()); 111 | } 112 | 113 | // Optimization note: try to minimize the size of this function for force inline. 114 | // Expansion is run very infrequently, so it is moved to another (probably non-inline) function. 115 | template 116 | RAPIDJSON_FORCEINLINE void Reserve(size_t count = 1) { 117 | // Expand the stack if needed 118 | if (RAPIDJSON_UNLIKELY(static_cast(sizeof(T) * count) > (stackEnd_ - stackTop_))) 119 | Expand(count); 120 | } 121 | 122 | template 123 | RAPIDJSON_FORCEINLINE T* Push(size_t count = 1) { 124 | Reserve(count); 125 | return PushUnsafe(count); 126 | } 127 | 128 | template 129 | RAPIDJSON_FORCEINLINE T* PushUnsafe(size_t count = 1) { 130 | RAPIDJSON_ASSERT(stackTop_); 131 | RAPIDJSON_ASSERT(static_cast(sizeof(T) * count) <= (stackEnd_ - stackTop_)); 132 | T* ret = reinterpret_cast(stackTop_); 133 | stackTop_ += sizeof(T) * count; 134 | return ret; 135 | } 136 | 137 | template 138 | T* Pop(size_t count) { 139 | RAPIDJSON_ASSERT(GetSize() >= count * sizeof(T)); 140 | stackTop_ -= count * sizeof(T); 141 | return reinterpret_cast(stackTop_); 142 | } 143 | 144 | template 145 | T* Top() { 146 | RAPIDJSON_ASSERT(GetSize() >= sizeof(T)); 147 | return reinterpret_cast(stackTop_ - sizeof(T)); 148 | } 149 | 150 | template 151 | const T* Top() const { 152 | RAPIDJSON_ASSERT(GetSize() >= sizeof(T)); 153 | return reinterpret_cast(stackTop_ - sizeof(T)); 154 | } 155 | 156 | template 157 | T* End() { return reinterpret_cast(stackTop_); } 158 | 159 | template 160 | const T* End() const { return reinterpret_cast(stackTop_); } 161 | 162 | template 163 | T* Bottom() { return reinterpret_cast(stack_); } 164 | 165 | template 166 | const T* Bottom() const { return reinterpret_cast(stack_); } 167 | 168 | bool HasAllocator() const { 169 | return allocator_ != 0; 170 | } 171 | 172 | Allocator& GetAllocator() { 173 | RAPIDJSON_ASSERT(allocator_); 174 | return *allocator_; 175 | } 176 | 177 | bool Empty() const { return stackTop_ == stack_; } 178 | size_t GetSize() const { return static_cast(stackTop_ - stack_); } 179 | size_t GetCapacity() const { return static_cast(stackEnd_ - stack_); } 180 | 181 | private: 182 | template 183 | void Expand(size_t count) { 184 | // Only expand the capacity if the current stack exists. Otherwise just create a stack with initial capacity. 185 | size_t newCapacity; 186 | if (stack_ == 0) { 187 | if (!allocator_) 188 | ownAllocator_ = allocator_ = RAPIDJSON_NEW(Allocator)(); 189 | newCapacity = initialCapacity_; 190 | } else { 191 | newCapacity = GetCapacity(); 192 | newCapacity += (newCapacity + 1) / 2; 193 | } 194 | size_t newSize = GetSize() + sizeof(T) * count; 195 | if (newCapacity < newSize) 196 | newCapacity = newSize; 197 | 198 | Resize(newCapacity); 199 | } 200 | 201 | void Resize(size_t newCapacity) { 202 | const size_t size = GetSize(); // Backup the current size 203 | stack_ = static_cast(allocator_->Realloc(stack_, GetCapacity(), newCapacity)); 204 | stackTop_ = stack_ + size; 205 | stackEnd_ = stack_ + newCapacity; 206 | } 207 | 208 | void Destroy() { 209 | Allocator::Free(stack_); 210 | RAPIDJSON_DELETE(ownAllocator_); // Only delete if it is owned by the stack 211 | } 212 | 213 | // Prohibit copy constructor & assignment operator. 214 | Stack(const Stack&); 215 | Stack& operator=(const Stack&); 216 | 217 | Allocator* allocator_; 218 | Allocator* ownAllocator_; 219 | char *stack_; 220 | char *stackTop_; 221 | char *stackEnd_; 222 | size_t initialCapacity_; 223 | }; 224 | 225 | } // namespace internal 226 | RAPIDJSON_NAMESPACE_END 227 | 228 | #if defined(__clang__) 229 | RAPIDJSON_DIAG_POP 230 | #endif 231 | 232 | #endif // RAPIDJSON_STACK_H_ 233 | -------------------------------------------------------------------------------- /UnityFPSUnlocker/third/rapidjson/rapidjson/internal/strfunc.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making RapidJSON available. 2 | // 3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef RAPIDJSON_INTERNAL_STRFUNC_H_ 16 | #define RAPIDJSON_INTERNAL_STRFUNC_H_ 17 | 18 | #include "../stream.h" 19 | #include 20 | 21 | RAPIDJSON_NAMESPACE_BEGIN 22 | namespace internal { 23 | 24 | //! Custom strlen() which works on different character types. 25 | /*! \tparam Ch Character type (e.g. char, wchar_t, short) 26 | \param s Null-terminated input string. 27 | \return Number of characters in the string. 28 | \note This has the same semantics as strlen(), the return value is not number of Unicode codepoints. 29 | */ 30 | template 31 | inline SizeType StrLen(const Ch* s) { 32 | RAPIDJSON_ASSERT(s != 0); 33 | const Ch* p = s; 34 | while (*p) ++p; 35 | return SizeType(p - s); 36 | } 37 | 38 | template <> 39 | inline SizeType StrLen(const char* s) { 40 | return SizeType(std::strlen(s)); 41 | } 42 | 43 | template <> 44 | inline SizeType StrLen(const wchar_t* s) { 45 | return SizeType(std::wcslen(s)); 46 | } 47 | 48 | //! Returns number of code points in a encoded string. 49 | template 50 | bool CountStringCodePoint(const typename Encoding::Ch* s, SizeType length, SizeType* outCount) { 51 | RAPIDJSON_ASSERT(s != 0); 52 | RAPIDJSON_ASSERT(outCount != 0); 53 | GenericStringStream is(s); 54 | const typename Encoding::Ch* end = s + length; 55 | SizeType count = 0; 56 | while (is.src_ < end) { 57 | unsigned codepoint; 58 | if (!Encoding::Decode(is, &codepoint)) 59 | return false; 60 | count++; 61 | } 62 | *outCount = count; 63 | return true; 64 | } 65 | 66 | } // namespace internal 67 | RAPIDJSON_NAMESPACE_END 68 | 69 | #endif // RAPIDJSON_INTERNAL_STRFUNC_H_ 70 | -------------------------------------------------------------------------------- /UnityFPSUnlocker/third/rapidjson/rapidjson/internal/strtod.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making RapidJSON available. 2 | // 3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef RAPIDJSON_STRTOD_ 16 | #define RAPIDJSON_STRTOD_ 17 | 18 | #include "ieee754.h" 19 | #include "biginteger.h" 20 | #include "diyfp.h" 21 | #include "pow10.h" 22 | #include 23 | #include 24 | 25 | RAPIDJSON_NAMESPACE_BEGIN 26 | namespace internal { 27 | 28 | inline double FastPath(double significand, int exp) { 29 | if (exp < -308) 30 | return 0.0; 31 | else if (exp >= 0) 32 | return significand * internal::Pow10(exp); 33 | else 34 | return significand / internal::Pow10(-exp); 35 | } 36 | 37 | inline double StrtodNormalPrecision(double d, int p) { 38 | if (p < -308) { 39 | // Prevent expSum < -308, making Pow10(p) = 0 40 | d = FastPath(d, -308); 41 | d = FastPath(d, p + 308); 42 | } 43 | else 44 | d = FastPath(d, p); 45 | return d; 46 | } 47 | 48 | template 49 | inline T Min3(T a, T b, T c) { 50 | T m = a; 51 | if (m > b) m = b; 52 | if (m > c) m = c; 53 | return m; 54 | } 55 | 56 | inline int CheckWithinHalfULP(double b, const BigInteger& d, int dExp) { 57 | const Double db(b); 58 | const uint64_t bInt = db.IntegerSignificand(); 59 | const int bExp = db.IntegerExponent(); 60 | const int hExp = bExp - 1; 61 | 62 | int dS_Exp2 = 0, dS_Exp5 = 0, bS_Exp2 = 0, bS_Exp5 = 0, hS_Exp2 = 0, hS_Exp5 = 0; 63 | 64 | // Adjust for decimal exponent 65 | if (dExp >= 0) { 66 | dS_Exp2 += dExp; 67 | dS_Exp5 += dExp; 68 | } 69 | else { 70 | bS_Exp2 -= dExp; 71 | bS_Exp5 -= dExp; 72 | hS_Exp2 -= dExp; 73 | hS_Exp5 -= dExp; 74 | } 75 | 76 | // Adjust for binary exponent 77 | if (bExp >= 0) 78 | bS_Exp2 += bExp; 79 | else { 80 | dS_Exp2 -= bExp; 81 | hS_Exp2 -= bExp; 82 | } 83 | 84 | // Adjust for half ulp exponent 85 | if (hExp >= 0) 86 | hS_Exp2 += hExp; 87 | else { 88 | dS_Exp2 -= hExp; 89 | bS_Exp2 -= hExp; 90 | } 91 | 92 | // Remove common power of two factor from all three scaled values 93 | int common_Exp2 = Min3(dS_Exp2, bS_Exp2, hS_Exp2); 94 | dS_Exp2 -= common_Exp2; 95 | bS_Exp2 -= common_Exp2; 96 | hS_Exp2 -= common_Exp2; 97 | 98 | BigInteger dS = d; 99 | dS.MultiplyPow5(static_cast(dS_Exp5)) <<= static_cast(dS_Exp2); 100 | 101 | BigInteger bS(bInt); 102 | bS.MultiplyPow5(static_cast(bS_Exp5)) <<= static_cast(bS_Exp2); 103 | 104 | BigInteger hS(1); 105 | hS.MultiplyPow5(static_cast(hS_Exp5)) <<= static_cast(hS_Exp2); 106 | 107 | BigInteger delta(0); 108 | dS.Difference(bS, &delta); 109 | 110 | return delta.Compare(hS); 111 | } 112 | 113 | inline bool StrtodFast(double d, int p, double* result) { 114 | // Use fast path for string-to-double conversion if possible 115 | // see http://www.exploringbinary.com/fast-path-decimal-to-floating-point-conversion/ 116 | if (p > 22 && p < 22 + 16) { 117 | // Fast Path Cases In Disguise 118 | d *= internal::Pow10(p - 22); 119 | p = 22; 120 | } 121 | 122 | if (p >= -22 && p <= 22 && d <= 9007199254740991.0) { // 2^53 - 1 123 | *result = FastPath(d, p); 124 | return true; 125 | } 126 | else 127 | return false; 128 | } 129 | 130 | // Compute an approximation and see if it is within 1/2 ULP 131 | inline bool StrtodDiyFp(const char* decimals, int dLen, int dExp, double* result) { 132 | uint64_t significand = 0; 133 | int i = 0; // 2^64 - 1 = 18446744073709551615, 1844674407370955161 = 0x1999999999999999 134 | for (; i < dLen; i++) { 135 | if (significand > RAPIDJSON_UINT64_C2(0x19999999, 0x99999999) || 136 | (significand == RAPIDJSON_UINT64_C2(0x19999999, 0x99999999) && decimals[i] > '5')) 137 | break; 138 | significand = significand * 10u + static_cast(decimals[i] - '0'); 139 | } 140 | 141 | if (i < dLen && decimals[i] >= '5') // Rounding 142 | significand++; 143 | 144 | int remaining = dLen - i; 145 | const int kUlpShift = 3; 146 | const int kUlp = 1 << kUlpShift; 147 | int64_t error = (remaining == 0) ? 0 : kUlp / 2; 148 | 149 | DiyFp v(significand, 0); 150 | v = v.Normalize(); 151 | error <<= -v.e; 152 | 153 | dExp += remaining; 154 | 155 | int actualExp; 156 | DiyFp cachedPower = GetCachedPower10(dExp, &actualExp); 157 | if (actualExp != dExp) { 158 | static const DiyFp kPow10[] = { 159 | DiyFp(RAPIDJSON_UINT64_C2(0xa0000000, 0x00000000), -60), // 10^1 160 | DiyFp(RAPIDJSON_UINT64_C2(0xc8000000, 0x00000000), -57), // 10^2 161 | DiyFp(RAPIDJSON_UINT64_C2(0xfa000000, 0x00000000), -54), // 10^3 162 | DiyFp(RAPIDJSON_UINT64_C2(0x9c400000, 0x00000000), -50), // 10^4 163 | DiyFp(RAPIDJSON_UINT64_C2(0xc3500000, 0x00000000), -47), // 10^5 164 | DiyFp(RAPIDJSON_UINT64_C2(0xf4240000, 0x00000000), -44), // 10^6 165 | DiyFp(RAPIDJSON_UINT64_C2(0x98968000, 0x00000000), -40) // 10^7 166 | }; 167 | int adjustment = dExp - actualExp; 168 | RAPIDJSON_ASSERT(adjustment >= 1 && adjustment < 8); 169 | v = v * kPow10[adjustment - 1]; 170 | if (dLen + adjustment > 19) // has more digits than decimal digits in 64-bit 171 | error += kUlp / 2; 172 | } 173 | 174 | v = v * cachedPower; 175 | 176 | error += kUlp + (error == 0 ? 0 : 1); 177 | 178 | const int oldExp = v.e; 179 | v = v.Normalize(); 180 | error <<= oldExp - v.e; 181 | 182 | const int effectiveSignificandSize = Double::EffectiveSignificandSize(64 + v.e); 183 | int precisionSize = 64 - effectiveSignificandSize; 184 | if (precisionSize + kUlpShift >= 64) { 185 | int scaleExp = (precisionSize + kUlpShift) - 63; 186 | v.f >>= scaleExp; 187 | v.e += scaleExp; 188 | error = (error >> scaleExp) + 1 + kUlp; 189 | precisionSize -= scaleExp; 190 | } 191 | 192 | DiyFp rounded(v.f >> precisionSize, v.e + precisionSize); 193 | const uint64_t precisionBits = (v.f & ((uint64_t(1) << precisionSize) - 1)) * kUlp; 194 | const uint64_t halfWay = (uint64_t(1) << (precisionSize - 1)) * kUlp; 195 | if (precisionBits >= halfWay + static_cast(error)) { 196 | rounded.f++; 197 | if (rounded.f & (DiyFp::kDpHiddenBit << 1)) { // rounding overflows mantissa (issue #340) 198 | rounded.f >>= 1; 199 | rounded.e++; 200 | } 201 | } 202 | 203 | *result = rounded.ToDouble(); 204 | 205 | return halfWay - static_cast(error) >= precisionBits || precisionBits >= halfWay + static_cast(error); 206 | } 207 | 208 | inline double StrtodBigInteger(double approx, const char* decimals, int dLen, int dExp) { 209 | RAPIDJSON_ASSERT(dLen >= 0); 210 | const BigInteger dInt(decimals, static_cast(dLen)); 211 | Double a(approx); 212 | int cmp = CheckWithinHalfULP(a.Value(), dInt, dExp); 213 | if (cmp < 0) 214 | return a.Value(); // within half ULP 215 | else if (cmp == 0) { 216 | // Round towards even 217 | if (a.Significand() & 1) 218 | return a.NextPositiveDouble(); 219 | else 220 | return a.Value(); 221 | } 222 | else // adjustment 223 | return a.NextPositiveDouble(); 224 | } 225 | 226 | inline double StrtodFullPrecision(double d, int p, const char* decimals, size_t length, size_t decimalPosition, int exp) { 227 | RAPIDJSON_ASSERT(d >= 0.0); 228 | RAPIDJSON_ASSERT(length >= 1); 229 | 230 | double result = 0.0; 231 | if (StrtodFast(d, p, &result)) 232 | return result; 233 | 234 | RAPIDJSON_ASSERT(length <= INT_MAX); 235 | int dLen = static_cast(length); 236 | 237 | RAPIDJSON_ASSERT(length >= decimalPosition); 238 | RAPIDJSON_ASSERT(length - decimalPosition <= INT_MAX); 239 | int dExpAdjust = static_cast(length - decimalPosition); 240 | 241 | RAPIDJSON_ASSERT(exp >= INT_MIN + dExpAdjust); 242 | int dExp = exp - dExpAdjust; 243 | 244 | // Make sure length+dExp does not overflow 245 | RAPIDJSON_ASSERT(dExp <= INT_MAX - dLen); 246 | 247 | // Trim leading zeros 248 | while (dLen > 0 && *decimals == '0') { 249 | dLen--; 250 | decimals++; 251 | } 252 | 253 | // Trim trailing zeros 254 | while (dLen > 0 && decimals[dLen - 1] == '0') { 255 | dLen--; 256 | dExp++; 257 | } 258 | 259 | if (dLen == 0) { // Buffer only contains zeros. 260 | return 0.0; 261 | } 262 | 263 | // Trim right-most digits 264 | const int kMaxDecimalDigit = 767 + 1; 265 | if (dLen > kMaxDecimalDigit) { 266 | dExp += dLen - kMaxDecimalDigit; 267 | dLen = kMaxDecimalDigit; 268 | } 269 | 270 | // If too small, underflow to zero. 271 | // Any x <= 10^-324 is interpreted as zero. 272 | if (dLen + dExp <= -324) 273 | return 0.0; 274 | 275 | // If too large, overflow to infinity. 276 | // Any x >= 10^309 is interpreted as +infinity. 277 | if (dLen + dExp > 309) 278 | return std::numeric_limits::infinity(); 279 | 280 | if (StrtodDiyFp(decimals, dLen, dExp, &result)) 281 | return result; 282 | 283 | // Use approximation from StrtodDiyFp and make adjustment with BigInteger comparison 284 | return StrtodBigInteger(result, decimals, dLen, dExp); 285 | } 286 | 287 | } // namespace internal 288 | RAPIDJSON_NAMESPACE_END 289 | 290 | #endif // RAPIDJSON_STRTOD_ 291 | -------------------------------------------------------------------------------- /UnityFPSUnlocker/third/rapidjson/rapidjson/internal/swap.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making RapidJSON available. 2 | // 3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef RAPIDJSON_INTERNAL_SWAP_H_ 16 | #define RAPIDJSON_INTERNAL_SWAP_H_ 17 | 18 | #include "../rapidjson.h" 19 | 20 | #if defined(__clang__) 21 | RAPIDJSON_DIAG_PUSH 22 | RAPIDJSON_DIAG_OFF(c++98-compat) 23 | #endif 24 | 25 | RAPIDJSON_NAMESPACE_BEGIN 26 | namespace internal { 27 | 28 | //! Custom swap() to avoid dependency on C++ header 29 | /*! \tparam T Type of the arguments to swap, should be instantiated with primitive C++ types only. 30 | \note This has the same semantics as std::swap(). 31 | */ 32 | template 33 | inline void Swap(T& a, T& b) RAPIDJSON_NOEXCEPT { 34 | T tmp = a; 35 | a = b; 36 | b = tmp; 37 | } 38 | 39 | } // namespace internal 40 | RAPIDJSON_NAMESPACE_END 41 | 42 | #if defined(__clang__) 43 | RAPIDJSON_DIAG_POP 44 | #endif 45 | 46 | #endif // RAPIDJSON_INTERNAL_SWAP_H_ 47 | -------------------------------------------------------------------------------- /UnityFPSUnlocker/third/rapidjson/rapidjson/istreamwrapper.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making RapidJSON available. 2 | // 3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef RAPIDJSON_ISTREAMWRAPPER_H_ 16 | #define RAPIDJSON_ISTREAMWRAPPER_H_ 17 | 18 | #include "stream.h" 19 | #include 20 | #include 21 | 22 | #ifdef __clang__ 23 | RAPIDJSON_DIAG_PUSH 24 | RAPIDJSON_DIAG_OFF(padded) 25 | #elif defined(_MSC_VER) 26 | RAPIDJSON_DIAG_PUSH 27 | RAPIDJSON_DIAG_OFF(4351) // new behavior: elements of array 'array' will be default initialized 28 | #endif 29 | 30 | RAPIDJSON_NAMESPACE_BEGIN 31 | 32 | //! Wrapper of \c std::basic_istream into RapidJSON's Stream concept. 33 | /*! 34 | The classes can be wrapped including but not limited to: 35 | 36 | - \c std::istringstream 37 | - \c std::stringstream 38 | - \c std::wistringstream 39 | - \c std::wstringstream 40 | - \c std::ifstream 41 | - \c std::fstream 42 | - \c std::wifstream 43 | - \c std::wfstream 44 | 45 | \tparam StreamType Class derived from \c std::basic_istream. 46 | */ 47 | 48 | template 49 | class BasicIStreamWrapper { 50 | public: 51 | typedef typename StreamType::char_type Ch; 52 | 53 | //! Constructor. 54 | /*! 55 | \param stream stream opened for read. 56 | */ 57 | BasicIStreamWrapper(StreamType &stream) : stream_(stream), buffer_(peekBuffer_), bufferSize_(4), bufferLast_(0), current_(buffer_), readCount_(0), count_(0), eof_(false) { 58 | Read(); 59 | } 60 | 61 | //! Constructor. 62 | /*! 63 | \param stream stream opened for read. 64 | \param buffer user-supplied buffer. 65 | \param bufferSize size of buffer in bytes. Must >=4 bytes. 66 | */ 67 | BasicIStreamWrapper(StreamType &stream, char* buffer, size_t bufferSize) : stream_(stream), buffer_(buffer), bufferSize_(bufferSize), bufferLast_(0), current_(buffer_), readCount_(0), count_(0), eof_(false) { 68 | RAPIDJSON_ASSERT(bufferSize >= 4); 69 | Read(); 70 | } 71 | 72 | Ch Peek() const { return *current_; } 73 | Ch Take() { Ch c = *current_; Read(); return c; } 74 | size_t Tell() const { return count_ + static_cast(current_ - buffer_); } 75 | 76 | // Not implemented 77 | void Put(Ch) { RAPIDJSON_ASSERT(false); } 78 | void Flush() { RAPIDJSON_ASSERT(false); } 79 | Ch* PutBegin() { RAPIDJSON_ASSERT(false); return 0; } 80 | size_t PutEnd(Ch*) { RAPIDJSON_ASSERT(false); return 0; } 81 | 82 | // For encoding detection only. 83 | const Ch* Peek4() const { 84 | return (current_ + 4 - !eof_ <= bufferLast_) ? current_ : 0; 85 | } 86 | 87 | private: 88 | BasicIStreamWrapper(); 89 | BasicIStreamWrapper(const BasicIStreamWrapper&); 90 | BasicIStreamWrapper& operator=(const BasicIStreamWrapper&); 91 | 92 | void Read() { 93 | if (current_ < bufferLast_) 94 | ++current_; 95 | else if (!eof_) { 96 | count_ += readCount_; 97 | readCount_ = bufferSize_; 98 | bufferLast_ = buffer_ + readCount_ - 1; 99 | current_ = buffer_; 100 | 101 | if (!stream_.read(buffer_, static_cast(bufferSize_))) { 102 | readCount_ = static_cast(stream_.gcount()); 103 | *(bufferLast_ = buffer_ + readCount_) = '\0'; 104 | eof_ = true; 105 | } 106 | } 107 | } 108 | 109 | StreamType &stream_; 110 | Ch peekBuffer_[4], *buffer_; 111 | size_t bufferSize_; 112 | Ch *bufferLast_; 113 | Ch *current_; 114 | size_t readCount_; 115 | size_t count_; //!< Number of characters read 116 | bool eof_; 117 | }; 118 | 119 | typedef BasicIStreamWrapper IStreamWrapper; 120 | typedef BasicIStreamWrapper WIStreamWrapper; 121 | 122 | #if defined(__clang__) || defined(_MSC_VER) 123 | RAPIDJSON_DIAG_POP 124 | #endif 125 | 126 | RAPIDJSON_NAMESPACE_END 127 | 128 | #endif // RAPIDJSON_ISTREAMWRAPPER_H_ 129 | -------------------------------------------------------------------------------- /UnityFPSUnlocker/third/rapidjson/rapidjson/memorybuffer.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making RapidJSON available. 2 | // 3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef RAPIDJSON_MEMORYBUFFER_H_ 16 | #define RAPIDJSON_MEMORYBUFFER_H_ 17 | 18 | #include "stream.h" 19 | #include "internal/stack.h" 20 | 21 | RAPIDJSON_NAMESPACE_BEGIN 22 | 23 | //! Represents an in-memory output byte stream. 24 | /*! 25 | This class is mainly for being wrapped by EncodedOutputStream or AutoUTFOutputStream. 26 | 27 | It is similar to FileWriteBuffer but the destination is an in-memory buffer instead of a file. 28 | 29 | Differences between MemoryBuffer and StringBuffer: 30 | 1. StringBuffer has Encoding but MemoryBuffer is only a byte buffer. 31 | 2. StringBuffer::GetString() returns a null-terminated string. MemoryBuffer::GetBuffer() returns a buffer without terminator. 32 | 33 | \tparam Allocator type for allocating memory buffer. 34 | \note implements Stream concept 35 | */ 36 | template 37 | struct GenericMemoryBuffer { 38 | typedef char Ch; // byte 39 | 40 | GenericMemoryBuffer(Allocator* allocator = 0, size_t capacity = kDefaultCapacity) : stack_(allocator, capacity) {} 41 | 42 | void Put(Ch c) { *stack_.template Push() = c; } 43 | void Flush() {} 44 | 45 | void Clear() { stack_.Clear(); } 46 | void ShrinkToFit() { stack_.ShrinkToFit(); } 47 | Ch* Push(size_t count) { return stack_.template Push(count); } 48 | void Pop(size_t count) { stack_.template Pop(count); } 49 | 50 | const Ch* GetBuffer() const { 51 | return stack_.template Bottom(); 52 | } 53 | 54 | size_t GetSize() const { return stack_.GetSize(); } 55 | 56 | static const size_t kDefaultCapacity = 256; 57 | mutable internal::Stack stack_; 58 | }; 59 | 60 | typedef GenericMemoryBuffer<> MemoryBuffer; 61 | 62 | //! Implement specialized version of PutN() with memset() for better performance. 63 | template<> 64 | inline void PutN(MemoryBuffer& memoryBuffer, char c, size_t n) { 65 | std::memset(memoryBuffer.stack_.Push(n), c, n * sizeof(c)); 66 | } 67 | 68 | RAPIDJSON_NAMESPACE_END 69 | 70 | #endif // RAPIDJSON_MEMORYBUFFER_H_ 71 | -------------------------------------------------------------------------------- /UnityFPSUnlocker/third/rapidjson/rapidjson/memorystream.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making RapidJSON available. 2 | // 3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef RAPIDJSON_MEMORYSTREAM_H_ 16 | #define RAPIDJSON_MEMORYSTREAM_H_ 17 | 18 | #include "stream.h" 19 | 20 | #ifdef __clang__ 21 | RAPIDJSON_DIAG_PUSH 22 | RAPIDJSON_DIAG_OFF(unreachable-code) 23 | RAPIDJSON_DIAG_OFF(missing-noreturn) 24 | #endif 25 | 26 | RAPIDJSON_NAMESPACE_BEGIN 27 | 28 | //! Represents an in-memory input byte stream. 29 | /*! 30 | This class is mainly for being wrapped by EncodedInputStream or AutoUTFInputStream. 31 | 32 | It is similar to FileReadBuffer but the source is an in-memory buffer instead of a file. 33 | 34 | Differences between MemoryStream and StringStream: 35 | 1. StringStream has encoding but MemoryStream is a byte stream. 36 | 2. MemoryStream needs size of the source buffer and the buffer don't need to be null terminated. StringStream assume null-terminated string as source. 37 | 3. MemoryStream supports Peek4() for encoding detection. StringStream is specified with an encoding so it should not have Peek4(). 38 | \note implements Stream concept 39 | */ 40 | struct MemoryStream { 41 | typedef char Ch; // byte 42 | 43 | MemoryStream(const Ch *src, size_t size) : src_(src), begin_(src), end_(src + size), size_(size) {} 44 | 45 | Ch Peek() const { return RAPIDJSON_UNLIKELY(src_ == end_) ? '\0' : *src_; } 46 | Ch Take() { return RAPIDJSON_UNLIKELY(src_ == end_) ? '\0' : *src_++; } 47 | size_t Tell() const { return static_cast(src_ - begin_); } 48 | 49 | Ch* PutBegin() { RAPIDJSON_ASSERT(false); return 0; } 50 | void Put(Ch) { RAPIDJSON_ASSERT(false); } 51 | void Flush() { RAPIDJSON_ASSERT(false); } 52 | size_t PutEnd(Ch*) { RAPIDJSON_ASSERT(false); return 0; } 53 | 54 | // For encoding detection only. 55 | const Ch* Peek4() const { 56 | return Tell() + 4 <= size_ ? src_ : 0; 57 | } 58 | 59 | const Ch* src_; //!< Current read position. 60 | const Ch* begin_; //!< Original head of the string. 61 | const Ch* end_; //!< End of stream. 62 | size_t size_; //!< Size of the stream. 63 | }; 64 | 65 | RAPIDJSON_NAMESPACE_END 66 | 67 | #ifdef __clang__ 68 | RAPIDJSON_DIAG_POP 69 | #endif 70 | 71 | #endif // RAPIDJSON_MEMORYBUFFER_H_ 72 | -------------------------------------------------------------------------------- /UnityFPSUnlocker/third/rapidjson/rapidjson/msinttypes/inttypes.h: -------------------------------------------------------------------------------- 1 | // ISO C9x compliant inttypes.h for Microsoft Visual Studio 2 | // Based on ISO/IEC 9899:TC2 Committee draft (May 6, 2005) WG14/N1124 3 | // 4 | // Copyright (c) 2006-2013 Alexander Chemeris 5 | // 6 | // Redistribution and use in source and binary forms, with or without 7 | // modification, are permitted provided that the following conditions are met: 8 | // 9 | // 1. Redistributions of source code must retain the above copyright notice, 10 | // this list of conditions and the following disclaimer. 11 | // 12 | // 2. Redistributions in binary form must reproduce the above copyright 13 | // notice, this list of conditions and the following disclaimer in the 14 | // documentation and/or other materials provided with the distribution. 15 | // 16 | // 3. Neither the name of the product nor the names of its contributors may 17 | // be used to endorse or promote products derived from this software 18 | // without specific prior written permission. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 21 | // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 22 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 23 | // EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 26 | // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 27 | // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 28 | // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 29 | // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | // 31 | /////////////////////////////////////////////////////////////////////////////// 32 | 33 | // The above software in this distribution may have been modified by 34 | // THL A29 Limited ("Tencent Modifications"). 35 | // All Tencent Modifications are Copyright (C) 2015 THL A29 Limited. 36 | 37 | #ifndef _MSC_VER // [ 38 | #error "Use this header only with Microsoft Visual C++ compilers!" 39 | #endif // _MSC_VER ] 40 | 41 | #ifndef _MSC_INTTYPES_H_ // [ 42 | #define _MSC_INTTYPES_H_ 43 | 44 | #if _MSC_VER > 1000 45 | #pragma once 46 | #endif 47 | 48 | #include "stdint.h" 49 | 50 | // miloyip: VC supports inttypes.h since VC2013 51 | #if _MSC_VER >= 1800 52 | #include 53 | #else 54 | 55 | // 7.8 Format conversion of integer types 56 | 57 | typedef struct { 58 | intmax_t quot; 59 | intmax_t rem; 60 | } imaxdiv_t; 61 | 62 | // 7.8.1 Macros for format specifiers 63 | 64 | #if !defined(__cplusplus) || defined(__STDC_FORMAT_MACROS) // [ See footnote 185 at page 198 65 | 66 | // The fprintf macros for signed integers are: 67 | #define PRId8 "d" 68 | #define PRIi8 "i" 69 | #define PRIdLEAST8 "d" 70 | #define PRIiLEAST8 "i" 71 | #define PRIdFAST8 "d" 72 | #define PRIiFAST8 "i" 73 | 74 | #define PRId16 "hd" 75 | #define PRIi16 "hi" 76 | #define PRIdLEAST16 "hd" 77 | #define PRIiLEAST16 "hi" 78 | #define PRIdFAST16 "hd" 79 | #define PRIiFAST16 "hi" 80 | 81 | #define PRId32 "I32d" 82 | #define PRIi32 "I32i" 83 | #define PRIdLEAST32 "I32d" 84 | #define PRIiLEAST32 "I32i" 85 | #define PRIdFAST32 "I32d" 86 | #define PRIiFAST32 "I32i" 87 | 88 | #define PRId64 "I64d" 89 | #define PRIi64 "I64i" 90 | #define PRIdLEAST64 "I64d" 91 | #define PRIiLEAST64 "I64i" 92 | #define PRIdFAST64 "I64d" 93 | #define PRIiFAST64 "I64i" 94 | 95 | #define PRIdMAX "I64d" 96 | #define PRIiMAX "I64i" 97 | 98 | #define PRIdPTR "Id" 99 | #define PRIiPTR "Ii" 100 | 101 | // The fprintf macros for unsigned integers are: 102 | #define PRIo8 "o" 103 | #define PRIu8 "u" 104 | #define PRIx8 "x" 105 | #define PRIX8 "X" 106 | #define PRIoLEAST8 "o" 107 | #define PRIuLEAST8 "u" 108 | #define PRIxLEAST8 "x" 109 | #define PRIXLEAST8 "X" 110 | #define PRIoFAST8 "o" 111 | #define PRIuFAST8 "u" 112 | #define PRIxFAST8 "x" 113 | #define PRIXFAST8 "X" 114 | 115 | #define PRIo16 "ho" 116 | #define PRIu16 "hu" 117 | #define PRIx16 "hx" 118 | #define PRIX16 "hX" 119 | #define PRIoLEAST16 "ho" 120 | #define PRIuLEAST16 "hu" 121 | #define PRIxLEAST16 "hx" 122 | #define PRIXLEAST16 "hX" 123 | #define PRIoFAST16 "ho" 124 | #define PRIuFAST16 "hu" 125 | #define PRIxFAST16 "hx" 126 | #define PRIXFAST16 "hX" 127 | 128 | #define PRIo32 "I32o" 129 | #define PRIu32 "I32u" 130 | #define PRIx32 "I32x" 131 | #define PRIX32 "I32X" 132 | #define PRIoLEAST32 "I32o" 133 | #define PRIuLEAST32 "I32u" 134 | #define PRIxLEAST32 "I32x" 135 | #define PRIXLEAST32 "I32X" 136 | #define PRIoFAST32 "I32o" 137 | #define PRIuFAST32 "I32u" 138 | #define PRIxFAST32 "I32x" 139 | #define PRIXFAST32 "I32X" 140 | 141 | #define PRIo64 "I64o" 142 | #define PRIu64 "I64u" 143 | #define PRIx64 "I64x" 144 | #define PRIX64 "I64X" 145 | #define PRIoLEAST64 "I64o" 146 | #define PRIuLEAST64 "I64u" 147 | #define PRIxLEAST64 "I64x" 148 | #define PRIXLEAST64 "I64X" 149 | #define PRIoFAST64 "I64o" 150 | #define PRIuFAST64 "I64u" 151 | #define PRIxFAST64 "I64x" 152 | #define PRIXFAST64 "I64X" 153 | 154 | #define PRIoMAX "I64o" 155 | #define PRIuMAX "I64u" 156 | #define PRIxMAX "I64x" 157 | #define PRIXMAX "I64X" 158 | 159 | #define PRIoPTR "Io" 160 | #define PRIuPTR "Iu" 161 | #define PRIxPTR "Ix" 162 | #define PRIXPTR "IX" 163 | 164 | // The fscanf macros for signed integers are: 165 | #define SCNd8 "d" 166 | #define SCNi8 "i" 167 | #define SCNdLEAST8 "d" 168 | #define SCNiLEAST8 "i" 169 | #define SCNdFAST8 "d" 170 | #define SCNiFAST8 "i" 171 | 172 | #define SCNd16 "hd" 173 | #define SCNi16 "hi" 174 | #define SCNdLEAST16 "hd" 175 | #define SCNiLEAST16 "hi" 176 | #define SCNdFAST16 "hd" 177 | #define SCNiFAST16 "hi" 178 | 179 | #define SCNd32 "ld" 180 | #define SCNi32 "li" 181 | #define SCNdLEAST32 "ld" 182 | #define SCNiLEAST32 "li" 183 | #define SCNdFAST32 "ld" 184 | #define SCNiFAST32 "li" 185 | 186 | #define SCNd64 "I64d" 187 | #define SCNi64 "I64i" 188 | #define SCNdLEAST64 "I64d" 189 | #define SCNiLEAST64 "I64i" 190 | #define SCNdFAST64 "I64d" 191 | #define SCNiFAST64 "I64i" 192 | 193 | #define SCNdMAX "I64d" 194 | #define SCNiMAX "I64i" 195 | 196 | #ifdef _WIN64 // [ 197 | # define SCNdPTR "I64d" 198 | # define SCNiPTR "I64i" 199 | #else // _WIN64 ][ 200 | # define SCNdPTR "ld" 201 | # define SCNiPTR "li" 202 | #endif // _WIN64 ] 203 | 204 | // The fscanf macros for unsigned integers are: 205 | #define SCNo8 "o" 206 | #define SCNu8 "u" 207 | #define SCNx8 "x" 208 | #define SCNX8 "X" 209 | #define SCNoLEAST8 "o" 210 | #define SCNuLEAST8 "u" 211 | #define SCNxLEAST8 "x" 212 | #define SCNXLEAST8 "X" 213 | #define SCNoFAST8 "o" 214 | #define SCNuFAST8 "u" 215 | #define SCNxFAST8 "x" 216 | #define SCNXFAST8 "X" 217 | 218 | #define SCNo16 "ho" 219 | #define SCNu16 "hu" 220 | #define SCNx16 "hx" 221 | #define SCNX16 "hX" 222 | #define SCNoLEAST16 "ho" 223 | #define SCNuLEAST16 "hu" 224 | #define SCNxLEAST16 "hx" 225 | #define SCNXLEAST16 "hX" 226 | #define SCNoFAST16 "ho" 227 | #define SCNuFAST16 "hu" 228 | #define SCNxFAST16 "hx" 229 | #define SCNXFAST16 "hX" 230 | 231 | #define SCNo32 "lo" 232 | #define SCNu32 "lu" 233 | #define SCNx32 "lx" 234 | #define SCNX32 "lX" 235 | #define SCNoLEAST32 "lo" 236 | #define SCNuLEAST32 "lu" 237 | #define SCNxLEAST32 "lx" 238 | #define SCNXLEAST32 "lX" 239 | #define SCNoFAST32 "lo" 240 | #define SCNuFAST32 "lu" 241 | #define SCNxFAST32 "lx" 242 | #define SCNXFAST32 "lX" 243 | 244 | #define SCNo64 "I64o" 245 | #define SCNu64 "I64u" 246 | #define SCNx64 "I64x" 247 | #define SCNX64 "I64X" 248 | #define SCNoLEAST64 "I64o" 249 | #define SCNuLEAST64 "I64u" 250 | #define SCNxLEAST64 "I64x" 251 | #define SCNXLEAST64 "I64X" 252 | #define SCNoFAST64 "I64o" 253 | #define SCNuFAST64 "I64u" 254 | #define SCNxFAST64 "I64x" 255 | #define SCNXFAST64 "I64X" 256 | 257 | #define SCNoMAX "I64o" 258 | #define SCNuMAX "I64u" 259 | #define SCNxMAX "I64x" 260 | #define SCNXMAX "I64X" 261 | 262 | #ifdef _WIN64 // [ 263 | # define SCNoPTR "I64o" 264 | # define SCNuPTR "I64u" 265 | # define SCNxPTR "I64x" 266 | # define SCNXPTR "I64X" 267 | #else // _WIN64 ][ 268 | # define SCNoPTR "lo" 269 | # define SCNuPTR "lu" 270 | # define SCNxPTR "lx" 271 | # define SCNXPTR "lX" 272 | #endif // _WIN64 ] 273 | 274 | #endif // __STDC_FORMAT_MACROS ] 275 | 276 | // 7.8.2 Functions for greatest-width integer types 277 | 278 | // 7.8.2.1 The imaxabs function 279 | #define imaxabs _abs64 280 | 281 | // 7.8.2.2 The imaxdiv function 282 | 283 | // This is modified version of div() function from Microsoft's div.c found 284 | // in %MSVC.NET%\crt\src\div.c 285 | #ifdef STATIC_IMAXDIV // [ 286 | static 287 | #else // STATIC_IMAXDIV ][ 288 | _inline 289 | #endif // STATIC_IMAXDIV ] 290 | imaxdiv_t __cdecl imaxdiv(intmax_t numer, intmax_t denom) 291 | { 292 | imaxdiv_t result; 293 | 294 | result.quot = numer / denom; 295 | result.rem = numer % denom; 296 | 297 | if (numer < 0 && result.rem > 0) { 298 | // did division wrong; must fix up 299 | ++result.quot; 300 | result.rem -= denom; 301 | } 302 | 303 | return result; 304 | } 305 | 306 | // 7.8.2.3 The strtoimax and strtoumax functions 307 | #define strtoimax _strtoi64 308 | #define strtoumax _strtoui64 309 | 310 | // 7.8.2.4 The wcstoimax and wcstoumax functions 311 | #define wcstoimax _wcstoi64 312 | #define wcstoumax _wcstoui64 313 | 314 | #endif // _MSC_VER >= 1800 315 | 316 | #endif // _MSC_INTTYPES_H_ ] 317 | -------------------------------------------------------------------------------- /UnityFPSUnlocker/third/rapidjson/rapidjson/ostreamwrapper.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making RapidJSON available. 2 | // 3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef RAPIDJSON_OSTREAMWRAPPER_H_ 16 | #define RAPIDJSON_OSTREAMWRAPPER_H_ 17 | 18 | #include "stream.h" 19 | #include 20 | 21 | #ifdef __clang__ 22 | RAPIDJSON_DIAG_PUSH 23 | RAPIDJSON_DIAG_OFF(padded) 24 | #endif 25 | 26 | RAPIDJSON_NAMESPACE_BEGIN 27 | 28 | //! Wrapper of \c std::basic_ostream into RapidJSON's Stream concept. 29 | /*! 30 | The classes can be wrapped including but not limited to: 31 | 32 | - \c std::ostringstream 33 | - \c std::stringstream 34 | - \c std::wpstringstream 35 | - \c std::wstringstream 36 | - \c std::ifstream 37 | - \c std::fstream 38 | - \c std::wofstream 39 | - \c std::wfstream 40 | 41 | \tparam StreamType Class derived from \c std::basic_ostream. 42 | */ 43 | 44 | template 45 | class BasicOStreamWrapper { 46 | public: 47 | typedef typename StreamType::char_type Ch; 48 | BasicOStreamWrapper(StreamType& stream) : stream_(stream) {} 49 | 50 | void Put(Ch c) { 51 | stream_.put(c); 52 | } 53 | 54 | void Flush() { 55 | stream_.flush(); 56 | } 57 | 58 | // Not implemented 59 | char Peek() const { RAPIDJSON_ASSERT(false); return 0; } 60 | char Take() { RAPIDJSON_ASSERT(false); return 0; } 61 | size_t Tell() const { RAPIDJSON_ASSERT(false); return 0; } 62 | char* PutBegin() { RAPIDJSON_ASSERT(false); return 0; } 63 | size_t PutEnd(char*) { RAPIDJSON_ASSERT(false); return 0; } 64 | 65 | private: 66 | BasicOStreamWrapper(const BasicOStreamWrapper&); 67 | BasicOStreamWrapper& operator=(const BasicOStreamWrapper&); 68 | 69 | StreamType& stream_; 70 | }; 71 | 72 | typedef BasicOStreamWrapper OStreamWrapper; 73 | typedef BasicOStreamWrapper WOStreamWrapper; 74 | 75 | #ifdef __clang__ 76 | RAPIDJSON_DIAG_POP 77 | #endif 78 | 79 | RAPIDJSON_NAMESPACE_END 80 | 81 | #endif // RAPIDJSON_OSTREAMWRAPPER_H_ 82 | -------------------------------------------------------------------------------- /UnityFPSUnlocker/third/rapidjson/rapidjson/stream.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making RapidJSON available. 2 | // 3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #include "rapidjson.h" 16 | 17 | #ifndef RAPIDJSON_STREAM_H_ 18 | #define RAPIDJSON_STREAM_H_ 19 | 20 | #include "encodings.h" 21 | 22 | RAPIDJSON_NAMESPACE_BEGIN 23 | 24 | /////////////////////////////////////////////////////////////////////////////// 25 | // Stream 26 | 27 | /*! \class rapidjson::Stream 28 | \brief Concept for reading and writing characters. 29 | 30 | For read-only stream, no need to implement PutBegin(), Put(), Flush() and PutEnd(). 31 | 32 | For write-only stream, only need to implement Put() and Flush(). 33 | 34 | \code 35 | concept Stream { 36 | typename Ch; //!< Character type of the stream. 37 | 38 | //! Read the current character from stream without moving the read cursor. 39 | Ch Peek() const; 40 | 41 | //! Read the current character from stream and moving the read cursor to next character. 42 | Ch Take(); 43 | 44 | //! Get the current read cursor. 45 | //! \return Number of characters read from start. 46 | size_t Tell(); 47 | 48 | //! Begin writing operation at the current read pointer. 49 | //! \return The begin writer pointer. 50 | Ch* PutBegin(); 51 | 52 | //! Write a character. 53 | void Put(Ch c); 54 | 55 | //! Flush the buffer. 56 | void Flush(); 57 | 58 | //! End the writing operation. 59 | //! \param begin The begin write pointer returned by PutBegin(). 60 | //! \return Number of characters written. 61 | size_t PutEnd(Ch* begin); 62 | } 63 | \endcode 64 | */ 65 | 66 | //! Provides additional information for stream. 67 | /*! 68 | By using traits pattern, this type provides a default configuration for stream. 69 | For custom stream, this type can be specialized for other configuration. 70 | See TEST(Reader, CustomStringStream) in readertest.cpp for example. 71 | */ 72 | template 73 | struct StreamTraits { 74 | //! Whether to make local copy of stream for optimization during parsing. 75 | /*! 76 | By default, for safety, streams do not use local copy optimization. 77 | Stream that can be copied fast should specialize this, like StreamTraits. 78 | */ 79 | enum { copyOptimization = 0 }; 80 | }; 81 | 82 | //! Reserve n characters for writing to a stream. 83 | template 84 | inline void PutReserve(Stream& stream, size_t count) { 85 | (void)stream; 86 | (void)count; 87 | } 88 | 89 | //! Write character to a stream, presuming buffer is reserved. 90 | template 91 | inline void PutUnsafe(Stream& stream, typename Stream::Ch c) { 92 | stream.Put(c); 93 | } 94 | 95 | //! Put N copies of a character to a stream. 96 | template 97 | inline void PutN(Stream& stream, Ch c, size_t n) { 98 | PutReserve(stream, n); 99 | for (size_t i = 0; i < n; i++) 100 | PutUnsafe(stream, c); 101 | } 102 | 103 | /////////////////////////////////////////////////////////////////////////////// 104 | // GenericStreamWrapper 105 | 106 | //! A Stream Wrapper 107 | /*! \tThis string stream is a wrapper for any stream by just forwarding any 108 | \treceived message to the origin stream. 109 | \note implements Stream concept 110 | */ 111 | 112 | #if defined(_MSC_VER) && _MSC_VER <= 1800 113 | RAPIDJSON_DIAG_PUSH 114 | RAPIDJSON_DIAG_OFF(4702) // unreachable code 115 | RAPIDJSON_DIAG_OFF(4512) // assignment operator could not be generated 116 | #endif 117 | 118 | template > 119 | class GenericStreamWrapper { 120 | public: 121 | typedef typename Encoding::Ch Ch; 122 | GenericStreamWrapper(InputStream& is): is_(is) {} 123 | 124 | Ch Peek() const { return is_.Peek(); } 125 | Ch Take() { return is_.Take(); } 126 | size_t Tell() { return is_.Tell(); } 127 | Ch* PutBegin() { return is_.PutBegin(); } 128 | void Put(Ch ch) { is_.Put(ch); } 129 | void Flush() { is_.Flush(); } 130 | size_t PutEnd(Ch* ch) { return is_.PutEnd(ch); } 131 | 132 | // wrapper for MemoryStream 133 | const Ch* Peek4() const { return is_.Peek4(); } 134 | 135 | // wrapper for AutoUTFInputStream 136 | UTFType GetType() const { return is_.GetType(); } 137 | bool HasBOM() const { return is_.HasBOM(); } 138 | 139 | protected: 140 | InputStream& is_; 141 | }; 142 | 143 | #if defined(_MSC_VER) && _MSC_VER <= 1800 144 | RAPIDJSON_DIAG_POP 145 | #endif 146 | 147 | /////////////////////////////////////////////////////////////////////////////// 148 | // StringStream 149 | 150 | //! Read-only string stream. 151 | /*! \note implements Stream concept 152 | */ 153 | template 154 | struct GenericStringStream { 155 | typedef typename Encoding::Ch Ch; 156 | 157 | GenericStringStream(const Ch *src) : src_(src), head_(src) {} 158 | 159 | Ch Peek() const { return *src_; } 160 | Ch Take() { return *src_++; } 161 | size_t Tell() const { return static_cast(src_ - head_); } 162 | 163 | Ch* PutBegin() { RAPIDJSON_ASSERT(false); return 0; } 164 | void Put(Ch) { RAPIDJSON_ASSERT(false); } 165 | void Flush() { RAPIDJSON_ASSERT(false); } 166 | size_t PutEnd(Ch*) { RAPIDJSON_ASSERT(false); return 0; } 167 | 168 | const Ch* src_; //!< Current read position. 169 | const Ch* head_; //!< Original head of the string. 170 | }; 171 | 172 | template 173 | struct StreamTraits > { 174 | enum { copyOptimization = 1 }; 175 | }; 176 | 177 | //! String stream with UTF8 encoding. 178 | typedef GenericStringStream > StringStream; 179 | 180 | /////////////////////////////////////////////////////////////////////////////// 181 | // InsituStringStream 182 | 183 | //! A read-write string stream. 184 | /*! This string stream is particularly designed for in-situ parsing. 185 | \note implements Stream concept 186 | */ 187 | template 188 | struct GenericInsituStringStream { 189 | typedef typename Encoding::Ch Ch; 190 | 191 | GenericInsituStringStream(Ch *src) : src_(src), dst_(0), head_(src) {} 192 | 193 | // Read 194 | Ch Peek() { return *src_; } 195 | Ch Take() { return *src_++; } 196 | size_t Tell() { return static_cast(src_ - head_); } 197 | 198 | // Write 199 | void Put(Ch c) { RAPIDJSON_ASSERT(dst_ != 0); *dst_++ = c; } 200 | 201 | Ch* PutBegin() { return dst_ = src_; } 202 | size_t PutEnd(Ch* begin) { return static_cast(dst_ - begin); } 203 | void Flush() {} 204 | 205 | Ch* Push(size_t count) { Ch* begin = dst_; dst_ += count; return begin; } 206 | void Pop(size_t count) { dst_ -= count; } 207 | 208 | Ch* src_; 209 | Ch* dst_; 210 | Ch* head_; 211 | }; 212 | 213 | template 214 | struct StreamTraits > { 215 | enum { copyOptimization = 1 }; 216 | }; 217 | 218 | //! Insitu string stream with UTF8 encoding. 219 | typedef GenericInsituStringStream > InsituStringStream; 220 | 221 | RAPIDJSON_NAMESPACE_END 222 | 223 | #endif // RAPIDJSON_STREAM_H_ 224 | -------------------------------------------------------------------------------- /UnityFPSUnlocker/third/rapidjson/rapidjson/stringbuffer.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making RapidJSON available. 2 | // 3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef RAPIDJSON_STRINGBUFFER_H_ 16 | #define RAPIDJSON_STRINGBUFFER_H_ 17 | 18 | #include "stream.h" 19 | #include "internal/stack.h" 20 | 21 | #if RAPIDJSON_HAS_CXX11_RVALUE_REFS 22 | #include // std::move 23 | #endif 24 | 25 | #include "internal/stack.h" 26 | 27 | #if defined(__clang__) 28 | RAPIDJSON_DIAG_PUSH 29 | RAPIDJSON_DIAG_OFF(c++98-compat) 30 | #endif 31 | 32 | RAPIDJSON_NAMESPACE_BEGIN 33 | 34 | //! Represents an in-memory output stream. 35 | /*! 36 | \tparam Encoding Encoding of the stream. 37 | \tparam Allocator type for allocating memory buffer. 38 | \note implements Stream concept 39 | */ 40 | template 41 | class GenericStringBuffer { 42 | public: 43 | typedef typename Encoding::Ch Ch; 44 | 45 | GenericStringBuffer(Allocator* allocator = 0, size_t capacity = kDefaultCapacity) : stack_(allocator, capacity) {} 46 | 47 | #if RAPIDJSON_HAS_CXX11_RVALUE_REFS 48 | GenericStringBuffer(GenericStringBuffer&& rhs) : stack_(std::move(rhs.stack_)) {} 49 | GenericStringBuffer& operator=(GenericStringBuffer&& rhs) { 50 | if (&rhs != this) 51 | stack_ = std::move(rhs.stack_); 52 | return *this; 53 | } 54 | #endif 55 | 56 | void Put(Ch c) { *stack_.template Push() = c; } 57 | void PutUnsafe(Ch c) { *stack_.template PushUnsafe() = c; } 58 | void Flush() {} 59 | 60 | void Clear() { stack_.Clear(); } 61 | void ShrinkToFit() { 62 | // Push and pop a null terminator. This is safe. 63 | *stack_.template Push() = '\0'; 64 | stack_.ShrinkToFit(); 65 | stack_.template Pop(1); 66 | } 67 | 68 | void Reserve(size_t count) { stack_.template Reserve(count); } 69 | Ch* Push(size_t count) { return stack_.template Push(count); } 70 | Ch* PushUnsafe(size_t count) { return stack_.template PushUnsafe(count); } 71 | void Pop(size_t count) { stack_.template Pop(count); } 72 | 73 | const Ch* GetString() const { 74 | // Push and pop a null terminator. This is safe. 75 | *stack_.template Push() = '\0'; 76 | stack_.template Pop(1); 77 | 78 | return stack_.template Bottom(); 79 | } 80 | 81 | //! Get the size of string in bytes in the string buffer. 82 | size_t GetSize() const { return stack_.GetSize(); } 83 | 84 | //! Get the length of string in Ch in the string buffer. 85 | size_t GetLength() const { return stack_.GetSize() / sizeof(Ch); } 86 | 87 | static const size_t kDefaultCapacity = 256; 88 | mutable internal::Stack stack_; 89 | 90 | private: 91 | // Prohibit copy constructor & assignment operator. 92 | GenericStringBuffer(const GenericStringBuffer&); 93 | GenericStringBuffer& operator=(const GenericStringBuffer&); 94 | }; 95 | 96 | //! String buffer with UTF8 encoding 97 | typedef GenericStringBuffer > StringBuffer; 98 | 99 | template 100 | inline void PutReserve(GenericStringBuffer& stream, size_t count) { 101 | stream.Reserve(count); 102 | } 103 | 104 | template 105 | inline void PutUnsafe(GenericStringBuffer& stream, typename Encoding::Ch c) { 106 | stream.PutUnsafe(c); 107 | } 108 | 109 | //! Implement specialized version of PutN() with memset() for better performance. 110 | template<> 111 | inline void PutN(GenericStringBuffer >& stream, char c, size_t n) { 112 | std::memset(stream.stack_.Push(n), c, n * sizeof(c)); 113 | } 114 | 115 | RAPIDJSON_NAMESPACE_END 116 | 117 | #if defined(__clang__) 118 | RAPIDJSON_DIAG_POP 119 | #endif 120 | 121 | #endif // RAPIDJSON_STRINGBUFFER_H_ 122 | -------------------------------------------------------------------------------- /UnityFPSUnlocker/third/riru_hide/hide.cc: -------------------------------------------------------------------------------- 1 | #include "hide.hh" 2 | 3 | #include 4 | 5 | #include "pmparser.h" 6 | #include "riru_hide_logger.hh" 7 | 8 | /** 9 | * Magic to hide from /proc/###/maps, the idea is from Haruue Icymoon (https://github.com/haruue) 10 | */ 11 | 12 | struct hide_struct { 13 | procmaps_struct* original; 14 | uintptr_t backup_address; 15 | }; 16 | 17 | static int get_prot(const procmaps_struct* procstruct) { 18 | int prot = 0; 19 | if (procstruct->is_r) { 20 | prot |= PROT_READ; 21 | } 22 | if (procstruct->is_w) { 23 | prot |= PROT_WRITE; 24 | } 25 | if (procstruct->is_x) { 26 | prot |= PROT_EXEC; 27 | } 28 | return prot; 29 | } 30 | 31 | #define FAILURE_RETURN(exp, failure_value) ({ \ 32 | __typeof__(exp) _rc; \ 33 | _rc = (exp); \ 34 | if (_rc == failure_value) { \ 35 | PLOGE(#exp); \ 36 | return 1; \ 37 | } \ 38 | _rc; }) 39 | 40 | static int do_hide(hide_struct* data) { 41 | auto procstruct = data->original; 42 | auto start = (uintptr_t)procstruct->addr_start; 43 | auto end = (uintptr_t)procstruct->addr_end; 44 | auto length = end - start; 45 | int prot = get_prot(procstruct); 46 | 47 | // backup 48 | data->backup_address = (uintptr_t)FAILURE_RETURN( 49 | mmap(nullptr, length, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0), 50 | MAP_FAILED); 51 | RIRU_LOGD("%" PRIxPTR "-%" PRIxPTR " %s %ld %s is backup to %" PRIxPTR, start, end, procstruct->perm, 52 | procstruct->offset, 53 | procstruct->pathname, data->backup_address); 54 | 55 | if (!procstruct->is_r) { 56 | RIRU_LOGD("mprotect +r"); 57 | FAILURE_RETURN(mprotect((void*)start, length, prot | PROT_READ), -1); 58 | } 59 | RIRU_LOGD("memcpy -> backup"); 60 | memcpy((void*)data->backup_address, (void*)start, length); 61 | 62 | // munmap original 63 | RIRU_LOGD("munmap original"); 64 | FAILURE_RETURN(munmap((void*)start, length), -1); 65 | 66 | // restore 67 | RIRU_LOGD("mmap original"); 68 | FAILURE_RETURN(mmap((void*)start, length, prot, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0), 69 | MAP_FAILED); 70 | RIRU_LOGD("mprotect +w"); 71 | FAILURE_RETURN(mprotect((void*)start, length, prot | PROT_WRITE), -1); 72 | RIRU_LOGD("memcpy -> original"); 73 | memcpy((void*)start, (void*)data->backup_address, length); 74 | if (!procstruct->is_w) { 75 | RIRU_LOGD("mprotect -w"); 76 | FAILURE_RETURN(mprotect((void*)start, length, prot), -1); 77 | } 78 | return 0; 79 | } 80 | 81 | int riru_hide(const char* name) { 82 | procmaps_iterator* maps = pmparser_parse(-1); 83 | if (maps == nullptr) { 84 | RIRU_LOGE("cannot parse the memory map"); 85 | return false; 86 | } 87 | 88 | char buf[PATH_MAX]; 89 | hide_struct* data = nullptr; 90 | size_t data_count = 0; 91 | procmaps_struct* maps_tmp; 92 | while ((maps_tmp = pmparser_next(maps)) != nullptr) { 93 | if (strstr(maps_tmp->pathname, name) == 0) { 94 | continue; 95 | } 96 | 97 | auto start = (uintptr_t)maps_tmp->addr_start; 98 | auto end = (uintptr_t)maps_tmp->addr_end; 99 | if (maps_tmp->is_r) { 100 | if (data) { 101 | data = (hide_struct*)realloc(data, sizeof(hide_struct) * (data_count + 1)); 102 | } 103 | else { 104 | data = (hide_struct*)malloc(sizeof(hide_struct)); 105 | } 106 | data[data_count].original = maps_tmp; 107 | data_count += 1; 108 | } 109 | RIRU_LOGD("%" PRIxPTR "-%" PRIxPTR " %s %ld %s", start, end, maps_tmp->perm, maps_tmp->offset, 110 | maps_tmp->pathname); 111 | } 112 | 113 | for (int i = 0; i < data_count; ++i) { 114 | do_hide(&data[i]); 115 | } 116 | 117 | if (data) { 118 | free(data); 119 | } 120 | pmparser_free(maps); 121 | return 0; 122 | } -------------------------------------------------------------------------------- /UnityFPSUnlocker/third/riru_hide/hide.hh: -------------------------------------------------------------------------------- 1 | #ifndef HIDE_HEADER 2 | #define HIDE_HEADER 3 | 4 | int riru_hide(const char* name); 5 | 6 | #endif // hide.hh -------------------------------------------------------------------------------- /UnityFPSUnlocker/third/riru_hide/pmparser.c: -------------------------------------------------------------------------------- 1 | /* 2 | @Author : ouadimjamal@gmail.com 3 | @date : December 2015 4 | 5 | Permission to use, copy, modify, distribute, and sell this software and its 6 | documentation for any purpose is hereby granted without fee, provided that 7 | the above copyright notice appear in all copies and that both that 8 | copyright notice and this permission notice appear in supporting 9 | documentation. No representations are made about the suitability of this 10 | software for any purpose. It is provided "as is" without express or 11 | implied warranty. 12 | */ 13 | 14 | #include "pmparser.h" 15 | #include "riru_hide_logger.hh" 16 | 17 | /** 18 | * gobal variables 19 | */ 20 | // procmaps_struct* g_last_head=NULL; 21 | // procmaps_struct* g_current=NULL; 22 | 23 | procmaps_iterator* pmparser_parse(int pid) { 24 | procmaps_iterator* maps_it = malloc(sizeof(procmaps_iterator)); 25 | char maps_path[500]; 26 | if (pid >= 0) { 27 | sprintf(maps_path, "/proc/%d/maps", pid); 28 | } 29 | else { 30 | sprintf(maps_path, "/proc/self/maps"); 31 | } 32 | FILE* file = fopen(maps_path, "r"); 33 | if (!file) { 34 | fprintf(stderr, "pmparser : cannot open the memory maps, %s\n", strerror(errno)); 35 | return NULL; 36 | } 37 | int ind = 0; 38 | char buf[PROCMAPS_LINE_MAX_LENGTH]; 39 | int c; 40 | procmaps_struct* list_maps = NULL; 41 | procmaps_struct* tmp; 42 | procmaps_struct* current_node = list_maps; 43 | char addr1[20], addr2[20], offset[20], inode[30]; 44 | while (!feof(file)) { 45 | fgets(buf, PROCMAPS_LINE_MAX_LENGTH, file); 46 | // allocate a node 47 | tmp = (procmaps_struct*)malloc(sizeof(procmaps_struct)); 48 | // fill the node 49 | _pmparser_split_line(buf, addr1, addr2, tmp->perm, offset, tmp->dev, inode, tmp->pathname); 50 | // RIRU_LOGD("#%s",buf); 51 | // RIRU_LOGD("%s-%s %s %s %s %s\t%s\n",addr1,addr2,perm,offset,dev,inode,pathname); 52 | // addr_start & addr_end 53 | unsigned long l_addr_start; 54 | sscanf(addr1, "%lx", (long unsigned*)&tmp->addr_start); 55 | sscanf(addr2, "%lx", (long unsigned*)&tmp->addr_end); 56 | // size 57 | tmp->length = (unsigned long)(tmp->addr_end - tmp->addr_start); 58 | // perm 59 | tmp->is_r = (tmp->perm[0] == 'r'); 60 | tmp->is_w = (tmp->perm[1] == 'w'); 61 | tmp->is_x = (tmp->perm[2] == 'x'); 62 | tmp->is_p = (tmp->perm[3] == 'p'); 63 | 64 | // offset 65 | sscanf(offset, "%lx", &tmp->offset); 66 | // inode 67 | tmp->inode = atoi(inode); 68 | tmp->next = NULL; 69 | // attach the node 70 | if (ind == 0) { 71 | list_maps = tmp; 72 | list_maps->next = NULL; 73 | current_node = list_maps; 74 | } 75 | current_node->next = tmp; 76 | current_node = tmp; 77 | ind++; 78 | // RIRU_LOGD("%s",buf); 79 | } 80 | 81 | // close file 82 | fclose(file); 83 | 84 | // g_last_head=list_maps; 85 | maps_it->head = list_maps; 86 | maps_it->current = list_maps; 87 | return maps_it; 88 | } 89 | 90 | procmaps_struct* pmparser_next(procmaps_iterator* p_procmaps_it) { 91 | if (p_procmaps_it->current == NULL) 92 | return NULL; 93 | procmaps_struct* p_current = p_procmaps_it->current; 94 | p_procmaps_it->current = p_procmaps_it->current->next; 95 | return p_current; 96 | /* 97 | if(g_current==NULL){ 98 | g_current=g_last_head; 99 | }else 100 | g_current=g_current->next; 101 | 102 | return g_current; 103 | */ 104 | } 105 | 106 | void pmparser_free(procmaps_iterator* p_procmaps_it) { 107 | procmaps_struct* maps_list = p_procmaps_it->head; 108 | if (maps_list == NULL) 109 | return; 110 | procmaps_struct* act = maps_list; 111 | procmaps_struct* nxt = act->next; 112 | while (act != NULL) { 113 | free(act); 114 | act = nxt; 115 | if (nxt != NULL) 116 | nxt = nxt->next; 117 | } 118 | } 119 | 120 | void _pmparser_split_line( 121 | char* buf, char* addr1, char* addr2, 122 | char* perm, char* offset, char* device, char* inode, 123 | char* pathname) { 124 | // 125 | int orig = 0; 126 | int i = 0; 127 | // addr1 128 | while (buf[i] != '-') { 129 | addr1[i - orig] = buf[i]; 130 | i++; 131 | } 132 | addr1[i] = '\0'; 133 | i++; 134 | // addr2 135 | orig = i; 136 | while (buf[i] != '\t' && buf[i] != ' ') { 137 | addr2[i - orig] = buf[i]; 138 | i++; 139 | } 140 | addr2[i - orig] = '\0'; 141 | 142 | // perm 143 | while (buf[i] == '\t' || buf[i] == ' ') 144 | i++; 145 | orig = i; 146 | while (buf[i] != '\t' && buf[i] != ' ') { 147 | perm[i - orig] = buf[i]; 148 | i++; 149 | } 150 | perm[i - orig] = '\0'; 151 | // offset 152 | while (buf[i] == '\t' || buf[i] == ' ') 153 | i++; 154 | orig = i; 155 | while (buf[i] != '\t' && buf[i] != ' ') { 156 | offset[i - orig] = buf[i]; 157 | i++; 158 | } 159 | offset[i - orig] = '\0'; 160 | // dev 161 | while (buf[i] == '\t' || buf[i] == ' ') 162 | i++; 163 | orig = i; 164 | while (buf[i] != '\t' && buf[i] != ' ') { 165 | device[i - orig] = buf[i]; 166 | i++; 167 | } 168 | device[i - orig] = '\0'; 169 | // inode 170 | while (buf[i] == '\t' || buf[i] == ' ') 171 | i++; 172 | orig = i; 173 | while (buf[i] != '\t' && buf[i] != ' ') { 174 | inode[i - orig] = buf[i]; 175 | i++; 176 | } 177 | inode[i - orig] = '\0'; 178 | // pathname 179 | pathname[0] = '\0'; 180 | while (buf[i] == '\t' || buf[i] == ' ') 181 | i++; 182 | orig = i; 183 | while (buf[i] != '\t' && buf[i] != ' ' && buf[i] != '\n') { 184 | pathname[i - orig] = buf[i]; 185 | i++; 186 | } 187 | pathname[i - orig] = '\0'; 188 | } 189 | 190 | void pmparser_print(procmaps_struct* map, int order) { 191 | 192 | procmaps_struct* tmp = map; 193 | int id = 0; 194 | if (order < 0) 195 | order = -1; 196 | while (tmp != NULL) { 197 | //(unsigned long) tmp->addr_start; 198 | if (order == id || order == -1) { 199 | RIRU_LOGD("Backed by:\t%s\n", strlen(tmp->pathname) == 0 ? "[anonym*]" : tmp->pathname); 200 | RIRU_LOGD("Range:\t\t%p-%p\n", tmp->addr_start, tmp->addr_end); 201 | RIRU_LOGD("Length:\t\t%ld\n", tmp->length); 202 | RIRU_LOGD("Offset:\t\t%ld\n", tmp->offset); 203 | RIRU_LOGD("Permissions:\t%s\n", tmp->perm); 204 | RIRU_LOGD("Inode:\t\t%d\n", tmp->inode); 205 | RIRU_LOGD("Device:\t\t%s\n", tmp->dev); 206 | } 207 | if (order != -1 && id > order) 208 | tmp = NULL; 209 | else if (order == -1) { 210 | RIRU_LOGD("#################################\n"); 211 | tmp = tmp->next; 212 | } 213 | else 214 | tmp = tmp->next; 215 | 216 | id++; 217 | } 218 | } -------------------------------------------------------------------------------- /UnityFPSUnlocker/third/riru_hide/pmparser.h: -------------------------------------------------------------------------------- 1 | /* 2 | @Author : ouadimjamal@gmail.com 3 | @date : December 2015 4 | 5 | Permission to use, copy, modify, distribute, and sell this software and its 6 | documentation for any purpose is hereby granted without fee, provided that 7 | the above copyright notice appear in all copies and that both that 8 | copyright notice and this permission notice appear in supporting 9 | documentation. No representations are made about the suitability of this 10 | software for any purpose. It is provided "as is" without express or 11 | implied warranty. 12 | 13 | */ 14 | 15 | #ifndef H_PMPARSER 16 | #define H_PMPARSER 17 | 18 | #ifdef __cplusplus 19 | extern "C" { 20 | #endif 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | // maximum line length in a procmaps file 33 | #define PROCMAPS_LINE_MAX_LENGTH (PATH_MAX + 100) 34 | /** 35 | * procmaps_struct 36 | * @desc hold all the information about an area in the process's VM 37 | */ 38 | typedef struct procmaps_struct { 39 | void* addr_start; //< start address of the area 40 | void* addr_end; //< end address 41 | unsigned long length; //< size of the range 42 | 43 | char perm[5]; //< permissions rwxp 44 | short is_r; //< rewrote of perm with short flags 45 | short is_w; 46 | short is_x; 47 | short is_p; 48 | 49 | long offset; //< offset 50 | char dev[12]; //< dev major:minor 51 | int inode; //< inode of the file that backs the area 52 | 53 | char pathname[PATH_MAX]; //< the path of the file that backs the area 54 | // chained list 55 | struct procmaps_struct* next; // 6 | 7 | #ifdef DEBUG 8 | #define RIRU_LOGD(...) __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__) 9 | #else 10 | #define RIRU_LOGD(...) 11 | #endif 12 | #define RIRU_LOGI(...) __android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__) 13 | #define RIRU_LOGE(...) __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__) 14 | #define PLOGE(fmt, args...) RIRU_LOGE(fmt " failed with %d: %s", ##args, errno, strerror(errno)) 15 | 16 | #endif // LOGGER_HEADER -------------------------------------------------------------------------------- /UnityFPSUnlocker/third/xdl/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.22.1) 2 | project(xdl) 3 | 4 | file(GLOB XDL_SRC *.c) 5 | add_library(xdl SHARED ${XDL_SRC}) 6 | target_compile_features(xdl PUBLIC c_std_17) 7 | target_compile_options(xdl PUBLIC -std=c17 -Weverything -Werror) 8 | target_include_directories(xdl PUBLIC include .) 9 | #target_link_libraries(xdl log) 10 | 11 | if(USEASAN) 12 | target_compile_options(xdl PUBLIC -fsanitize=address -fno-omit-frame-pointer) 13 | target_link_options(xdl PUBLIC -fsanitize=address) 14 | else() 15 | target_compile_options(xdl PUBLIC -Oz -flto -faddrsig -ffunction-sections -fdata-sections) 16 | target_link_options(xdl PUBLIC -Oz -flto -Wl,--icf=all -Wl,-mllvm,--enable-machine-outliner=always -Wl,--exclude-libs,ALL -Wl,--gc-sections -Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/xdl.map.txt) 17 | endif() 18 | -------------------------------------------------------------------------------- /UnityFPSUnlocker/third/xdl/xdl.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020-2021 HexHacking Team 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all 11 | // copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | // SOFTWARE. 20 | // 21 | 22 | // Created by caikelun on 2020-10-04. 23 | 24 | // 25 | // xDL version: 1.2.1 26 | // 27 | // xDL is an enhanced implementation of the Android DL series functions. 28 | // For more information, documentation, and the latest version please check: 29 | // https://github.com/hexhacking/xDL 30 | // 31 | 32 | #ifndef IO_HEXHACKING_XDL 33 | #define IO_HEXHACKING_XDL 34 | 35 | #include 36 | #include 37 | #include 38 | 39 | #ifdef __cplusplus 40 | extern "C" { 41 | #endif 42 | 43 | typedef struct { 44 | // same as Dl_info: 45 | const char *dli_fname; // Pathname of shared object that contains address. 46 | void *dli_fbase; // Address at which shared object is loaded. 47 | const char *dli_sname; // Name of nearest symbol with address lower than addr. 48 | void *dli_saddr; // Exact address of symbol named in dli_sname. 49 | // added by xDL: 50 | size_t dli_ssize; // Symbol size of nearest symbol with address lower than addr. 51 | const ElfW(Phdr) *dlpi_phdr; // Pointer to array of ELF program headers for this object. 52 | size_t dlpi_phnum; // Number of items in dlpi_phdr. 53 | } xdl_info_t; 54 | 55 | // 56 | // Default value for flags in both xdl_open() and xdl_iterate_phdr(). 57 | // 58 | #define XDL_DEFAULT 0x00 59 | 60 | // 61 | // Enhanced dlopen() / dlclose() / dlsym(). 62 | // 63 | #define XDL_TRY_FORCE_LOAD 0x01 64 | #define XDL_ALWAYS_FORCE_LOAD 0x02 65 | void *xdl_open(const char *filename, int flags); 66 | void *xdl_close(void *handle); 67 | void *xdl_sym(void *handle, const char *symbol, size_t *symbol_size); 68 | void *xdl_dsym(void *handle, const char *symbol, size_t *symbol_size); 69 | 70 | // 71 | // Enhanced dladdr(). 72 | // 73 | int xdl_addr(void *addr, xdl_info_t *info, void **cache); 74 | void xdl_addr_clean(void **cache); 75 | 76 | // 77 | // Enhanced dl_iterate_phdr(). 78 | // 79 | #define XDL_FULL_PATHNAME 0x01 80 | int xdl_iterate_phdr(int (*callback)(struct dl_phdr_info *, size_t, void *), void *data, int flags); 81 | 82 | // 83 | // Custom dlinfo(). 84 | // 85 | #define XDL_DI_DLINFO 1 // type of info: xdl_info_t 86 | int xdl_info(void *handle, int request, void *info); 87 | 88 | #ifdef __cplusplus 89 | } 90 | #endif 91 | 92 | #endif 93 | -------------------------------------------------------------------------------- /UnityFPSUnlocker/third/xdl/xdl.map.txt: -------------------------------------------------------------------------------- 1 | { 2 | global: 3 | xdl_open; 4 | xdl_close; 5 | xdl_sym; 6 | xdl_dsym; 7 | xdl_addr; 8 | xdl_addr_clean; 9 | xdl_iterate_phdr; 10 | xdl_info; 11 | 12 | local: 13 | *; 14 | }; 15 | -------------------------------------------------------------------------------- /UnityFPSUnlocker/third/xdl/xdl_iterate.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020-2021 HexHacking Team 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all 11 | // copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | // SOFTWARE. 20 | // 21 | 22 | // Created by caikelun on 2020-10-04. 23 | 24 | #ifndef IO_HEXHACKING_XDL_ITERATE 25 | #define IO_HEXHACKING_XDL_ITERATE 26 | 27 | #include 28 | #include 29 | 30 | #ifdef __cplusplus 31 | extern "C" { 32 | #endif 33 | 34 | typedef int (*xdl_iterate_phdr_cb_t)(struct dl_phdr_info *info, size_t size, void *arg); 35 | int xdl_iterate_phdr_impl(xdl_iterate_phdr_cb_t cb, void *cb_arg, int flags); 36 | 37 | int xdl_iterate_get_full_pathname(uintptr_t base, char *buf, size_t buf_len); 38 | 39 | #ifdef __cplusplus 40 | } 41 | #endif 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /UnityFPSUnlocker/third/xdl/xdl_linker.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020-2021 HexHacking Team 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all 11 | // copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | // SOFTWARE. 20 | // 21 | 22 | // Created by caikelun on 2021-02-21. 23 | 24 | #include "xdl_linker.h" 25 | 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | #include "xdl.h" 32 | #include "xdl_iterate.h" 33 | #include "xdl_util.h" 34 | 35 | #define XDL_LINKER_SYM_MUTEX "__dl__ZL10g_dl_mutex" 36 | #define XDL_LINKER_SYM_DLOPEN_EXT_N "__dl__ZL10dlopen_extPKciPK17android_dlextinfoPv" 37 | #define XDL_LINKER_SYM_DO_DLOPEN_N "__dl__Z9do_dlopenPKciPK17android_dlextinfoPv" 38 | #define XDL_LINKER_SYM_DLOPEN_O "__dl__Z8__dlopenPKciPKv" 39 | #define XDL_LINKER_SYM_LOADER_DLOPEN_P "__loader_dlopen" 40 | 41 | typedef void *(*xdl_linker_dlopen_n_t)(const char *, int, const void *, void *); 42 | typedef void *(*xdl_linker_dlopen_o_t)(const char *, int, const void *); 43 | 44 | static pthread_mutex_t *xdl_linker_mutex = NULL; 45 | static void *xdl_linker_dlopen = NULL; 46 | 47 | static void *xdl_linker_caller_addr[] = { 48 | NULL, // default 49 | NULL, // art 50 | NULL // vendor 51 | }; 52 | 53 | #ifndef __LP64__ 54 | #define XDL_LINKER_LIB "lib" 55 | #else 56 | #define XDL_LINKER_LIB "lib64" 57 | #endif 58 | static const char *xdl_linker_vendor_path[] = { 59 | // order is important 60 | "/vendor/" XDL_LINKER_LIB "/egl/", "/vendor/" XDL_LINKER_LIB "/hw/", 61 | "/vendor/" XDL_LINKER_LIB "/", "/odm/" XDL_LINKER_LIB "/", 62 | "/vendor/" XDL_LINKER_LIB "/vndk-sp/", "/odm/" XDL_LINKER_LIB "/vndk-sp/"}; 63 | 64 | static void xdl_linker_init(void) { 65 | static bool inited = false; 66 | if (inited) return; 67 | inited = true; 68 | 69 | void *handle = xdl_open(XDL_UTIL_LINKER_BASENAME, XDL_DEFAULT); 70 | if (NULL == handle) return; 71 | 72 | int api_level = xdl_util_get_api_level(); 73 | if (__ANDROID_API_L__ == api_level || __ANDROID_API_L_MR1__ == api_level) { 74 | // == Android 5.x 75 | xdl_linker_mutex = (pthread_mutex_t *)xdl_dsym(handle, XDL_LINKER_SYM_MUTEX, NULL); 76 | } else if (__ANDROID_API_N__ == api_level || __ANDROID_API_N_MR1__ == api_level) { 77 | // == Android 7.x 78 | xdl_linker_dlopen = xdl_dsym(handle, XDL_LINKER_SYM_DLOPEN_EXT_N, NULL); 79 | if (NULL == xdl_linker_dlopen) { 80 | xdl_linker_dlopen = xdl_dsym(handle, XDL_LINKER_SYM_DO_DLOPEN_N, NULL); 81 | xdl_linker_mutex = (pthread_mutex_t *)xdl_dsym(handle, XDL_LINKER_SYM_MUTEX, NULL); 82 | } 83 | } else if (__ANDROID_API_O__ == api_level || __ANDROID_API_O_MR1__ == api_level) { 84 | // == Android 8.x 85 | xdl_linker_dlopen = xdl_dsym(handle, XDL_LINKER_SYM_DLOPEN_O, NULL); 86 | } else if (api_level >= __ANDROID_API_P__) { 87 | // >= Android 9.0 88 | xdl_linker_dlopen = xdl_sym(handle, XDL_LINKER_SYM_LOADER_DLOPEN_P, NULL); 89 | } 90 | 91 | xdl_close(handle); 92 | } 93 | 94 | void xdl_linker_lock(void) { 95 | xdl_linker_init(); 96 | 97 | if (NULL != xdl_linker_mutex) pthread_mutex_lock(xdl_linker_mutex); 98 | } 99 | 100 | void xdl_linker_unlock(void) { 101 | if (NULL != xdl_linker_mutex) pthread_mutex_unlock(xdl_linker_mutex); 102 | } 103 | 104 | static void *xdl_linker_get_caller_addr(struct dl_phdr_info *info) { 105 | for (size_t i = 0; i < info->dlpi_phnum; i++) { 106 | const ElfW(Phdr) *phdr = &(info->dlpi_phdr[i]); 107 | if (PT_LOAD == phdr->p_type) { 108 | return (void *)(info->dlpi_addr + phdr->p_vaddr); 109 | } 110 | } 111 | return NULL; 112 | } 113 | 114 | static int xdl_linker_get_caller_addr_cb(struct dl_phdr_info *info, size_t size, void *arg) { 115 | (void)size; 116 | 117 | size_t *vendor_match = (size_t *)arg; 118 | 119 | if (0 == info->dlpi_addr || NULL == info->dlpi_name) return 0; // continue 120 | 121 | if (NULL == xdl_linker_caller_addr[0] && xdl_util_ends_with(info->dlpi_name, "/libc.so")) 122 | xdl_linker_caller_addr[0] = xdl_linker_get_caller_addr(info); 123 | 124 | if (NULL == xdl_linker_caller_addr[1] && xdl_util_ends_with(info->dlpi_name, "/libart.so")) 125 | xdl_linker_caller_addr[1] = xdl_linker_get_caller_addr(info); 126 | 127 | if (0 != *vendor_match) { 128 | for (size_t i = 0; i < *vendor_match; i++) { 129 | if (xdl_util_starts_with(info->dlpi_name, xdl_linker_vendor_path[i])) { 130 | void *caller_addr = xdl_linker_get_caller_addr(info); 131 | if (NULL != caller_addr) { 132 | xdl_linker_caller_addr[2] = caller_addr; 133 | *vendor_match = i; 134 | } 135 | } 136 | } 137 | } 138 | 139 | if (NULL != xdl_linker_caller_addr[0] && NULL != xdl_linker_caller_addr[1] && 0 == *vendor_match) { 140 | return 1; // finish 141 | } else { 142 | return 0; // continue 143 | } 144 | } 145 | 146 | static void xdl_linker_load_caller_addr(void) { 147 | if (NULL == xdl_linker_caller_addr[0]) { 148 | size_t vendor_match = sizeof(xdl_linker_vendor_path) / sizeof(xdl_linker_vendor_path[0]); 149 | xdl_iterate_phdr_impl(xdl_linker_get_caller_addr_cb, &vendor_match, XDL_DEFAULT); 150 | } 151 | } 152 | 153 | void *xdl_linker_load(const char *filename) { 154 | int api_level = xdl_util_get_api_level(); 155 | 156 | if (api_level <= __ANDROID_API_M__) { 157 | // <= Android 6.0 158 | return dlopen(filename, RTLD_NOW); 159 | } else { 160 | xdl_linker_init(); 161 | if (NULL == xdl_linker_dlopen) return NULL; 162 | xdl_linker_load_caller_addr(); 163 | 164 | void *handle = NULL; 165 | if (__ANDROID_API_N__ == api_level || __ANDROID_API_N_MR1__ == api_level) { 166 | // == Android 7.x 167 | xdl_linker_lock(); 168 | for (size_t i = 0; i < sizeof(xdl_linker_caller_addr) / sizeof(xdl_linker_caller_addr[0]); i++) { 169 | if (NULL != xdl_linker_caller_addr[i]) { 170 | handle = 171 | ((xdl_linker_dlopen_n_t)xdl_linker_dlopen)(filename, RTLD_NOW, NULL, xdl_linker_caller_addr[i]); 172 | if (NULL != handle) break; 173 | } 174 | } 175 | xdl_linker_unlock(); 176 | } else { 177 | // >= Android 8.0 178 | for (size_t i = 0; i < sizeof(xdl_linker_caller_addr) / sizeof(xdl_linker_caller_addr[0]); i++) { 179 | if (NULL != xdl_linker_caller_addr[i]) { 180 | handle = ((xdl_linker_dlopen_o_t)xdl_linker_dlopen)(filename, RTLD_NOW, xdl_linker_caller_addr[i]); 181 | if (NULL != handle) break; 182 | } 183 | } 184 | } 185 | return handle; 186 | } 187 | } 188 | -------------------------------------------------------------------------------- /UnityFPSUnlocker/third/xdl/xdl_linker.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020-2021 HexHacking Team 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all 11 | // copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | // SOFTWARE. 20 | // 21 | 22 | // Created by caikelun on 2021-02-21. 23 | 24 | #ifndef IO_HEXHACKING_XDL_LINKER 25 | #define IO_HEXHACKING_XDL_LINKER 26 | 27 | #ifdef __cplusplus 28 | extern "C" { 29 | #endif 30 | 31 | void xdl_linker_lock(void); 32 | void xdl_linker_unlock(void); 33 | 34 | void *xdl_linker_load(const char *filename); 35 | 36 | #ifdef __cplusplus 37 | } 38 | #endif 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /UnityFPSUnlocker/third/xdl/xdl_lzma.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020-2021 HexHacking Team 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all 11 | // copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | // SOFTWARE. 20 | // 21 | 22 | // Created by caikelun on 2020-11-08. 23 | 24 | #include "xdl_lzma.h" 25 | 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | 35 | #include "xdl.h" 36 | #include "xdl_util.h" 37 | 38 | // LZMA library pathname & symbol names 39 | #ifndef __LP64__ 40 | #define XDL_LZMA_PATHNAME "/system/lib/liblzma.so" 41 | #else 42 | #define XDL_LZMA_PATHNAME "/system/lib64/liblzma.so" 43 | #endif 44 | #define XDL_LZMA_SYM_CRCGEN "CrcGenerateTable" 45 | #define XDL_LZMA_SYM_CRC64GEN "Crc64GenerateTable" 46 | #define XDL_LZMA_SYM_CONSTRUCT "XzUnpacker_Construct" 47 | #define XDL_LZMA_SYM_ISFINISHED "XzUnpacker_IsStreamWasFinished" 48 | #define XDL_LZMA_SYM_FREE "XzUnpacker_Free" 49 | #define XDL_LZMA_SYM_CODE "XzUnpacker_Code" 50 | 51 | // LZMA data type definition 52 | #define SZ_OK 0 53 | typedef struct ISzAlloc ISzAlloc; 54 | typedef const ISzAlloc *ISzAllocPtr; 55 | struct ISzAlloc { 56 | void *(*Alloc)(ISzAllocPtr p, size_t size); 57 | void (*Free)(ISzAllocPtr p, void *address); /* address can be 0 */ 58 | }; 59 | typedef enum { 60 | CODER_STATUS_NOT_SPECIFIED, /* use main error code instead */ 61 | CODER_STATUS_FINISHED_WITH_MARK, /* stream was finished with end mark. */ 62 | CODER_STATUS_NOT_FINISHED, /* stream was not finished */ 63 | CODER_STATUS_NEEDS_MORE_INPUT /* you must provide more input bytes */ 64 | } ECoderStatus; 65 | typedef enum { 66 | CODER_FINISH_ANY, /* finish at any point */ 67 | CODER_FINISH_END /* block must be finished at the end */ 68 | } ECoderFinishMode; 69 | 70 | // LZMA function type definition 71 | typedef void (*xdl_lzma_crcgen_t)(void); 72 | typedef void (*xdl_lzma_crc64gen_t)(void); 73 | typedef void (*xdl_lzma_construct_t)(void *, ISzAllocPtr); 74 | typedef int (*xdl_lzma_isfinished_t)(const void *); 75 | typedef void (*xdl_lzma_free_t)(void *); 76 | typedef int (*xdl_lzma_code_t)(void *, uint8_t *, size_t *, const uint8_t *, size_t *, ECoderFinishMode, 77 | ECoderStatus *); 78 | typedef int (*xdl_lzma_code_q_t)(void *, uint8_t *, size_t *, const uint8_t *, size_t *, int, 79 | ECoderFinishMode, ECoderStatus *); 80 | 81 | // LZMA function pointor 82 | static xdl_lzma_construct_t xdl_lzma_construct = NULL; 83 | static xdl_lzma_isfinished_t xdl_lzma_isfinished = NULL; 84 | static xdl_lzma_free_t xdl_lzma_free = NULL; 85 | static void *xdl_lzma_code = NULL; 86 | 87 | // LZMA init 88 | static void xdl_lzma_init() { 89 | void *lzma = xdl_open(XDL_LZMA_PATHNAME, XDL_TRY_FORCE_LOAD); 90 | if (NULL == lzma) return; 91 | 92 | xdl_lzma_crcgen_t crcgen = NULL; 93 | xdl_lzma_crc64gen_t crc64gen = NULL; 94 | if (NULL == (crcgen = (xdl_lzma_crcgen_t)xdl_sym(lzma, XDL_LZMA_SYM_CRCGEN, NULL))) goto end; 95 | if (NULL == (crc64gen = (xdl_lzma_crc64gen_t)xdl_sym(lzma, XDL_LZMA_SYM_CRC64GEN, NULL))) goto end; 96 | if (NULL == (xdl_lzma_construct = (xdl_lzma_construct_t)xdl_sym(lzma, XDL_LZMA_SYM_CONSTRUCT, NULL))) 97 | goto end; 98 | if (NULL == (xdl_lzma_isfinished = (xdl_lzma_isfinished_t)xdl_sym(lzma, XDL_LZMA_SYM_ISFINISHED, NULL))) 99 | goto end; 100 | if (NULL == (xdl_lzma_free = (xdl_lzma_free_t)xdl_sym(lzma, XDL_LZMA_SYM_FREE, NULL))) goto end; 101 | if (NULL == (xdl_lzma_code = xdl_sym(lzma, XDL_LZMA_SYM_CODE, NULL))) goto end; 102 | crcgen(); 103 | crc64gen(); 104 | 105 | end: 106 | xdl_close(lzma); 107 | } 108 | 109 | // LZMA internal alloc / free 110 | static void *xdl_lzma_internal_alloc(ISzAllocPtr p, size_t size) { 111 | (void)p; 112 | return malloc(size); 113 | } 114 | static void xdl_lzma_internal_free(ISzAllocPtr p, void *address) { 115 | (void)p; 116 | free(address); 117 | } 118 | 119 | int xdl_lzma_decompress(uint8_t *src, size_t src_size, uint8_t **dst, size_t *dst_size) { 120 | size_t src_offset = 0; 121 | size_t dst_offset = 0; 122 | size_t src_remaining; 123 | size_t dst_remaining; 124 | ISzAlloc alloc = {.Alloc = xdl_lzma_internal_alloc, .Free = xdl_lzma_internal_free}; 125 | long long state[4096 / sizeof(long long)]; // must be enough, 8-bit aligned 126 | ECoderStatus status; 127 | int api_level = xdl_util_get_api_level(); 128 | 129 | // init and check 130 | static bool inited = false; 131 | if (!inited) { 132 | xdl_lzma_init(); 133 | inited = true; 134 | } 135 | if (NULL == xdl_lzma_code) return -1; 136 | 137 | xdl_lzma_construct(&state, &alloc); 138 | 139 | *dst_size = 2 * src_size; 140 | *dst = NULL; 141 | do { 142 | *dst_size *= 2; 143 | if (NULL == (*dst = realloc(*dst, *dst_size))) { 144 | xdl_lzma_free(&state); 145 | return -1; 146 | } 147 | 148 | src_remaining = src_size - src_offset; 149 | dst_remaining = *dst_size - dst_offset; 150 | 151 | int result; 152 | if (api_level >= __ANDROID_API_Q__) { 153 | xdl_lzma_code_q_t lzma_code_q = (xdl_lzma_code_q_t)xdl_lzma_code; 154 | result = lzma_code_q(&state, *dst + dst_offset, &dst_remaining, src + src_offset, &src_remaining, 1, 155 | CODER_FINISH_ANY, &status); 156 | } else { 157 | xdl_lzma_code_t lzma_code = (xdl_lzma_code_t)xdl_lzma_code; 158 | result = lzma_code(&state, *dst + dst_offset, &dst_remaining, src + src_offset, &src_remaining, 159 | CODER_FINISH_ANY, &status); 160 | } 161 | if (SZ_OK != result) { 162 | free(*dst); 163 | xdl_lzma_free(&state); 164 | return -1; 165 | } 166 | 167 | src_offset += src_remaining; 168 | dst_offset += dst_remaining; 169 | } while (status == CODER_STATUS_NOT_FINISHED); 170 | 171 | xdl_lzma_free(&state); 172 | 173 | if (!xdl_lzma_isfinished(&state)) { 174 | free(*dst); 175 | return -1; 176 | } 177 | 178 | *dst_size = dst_offset; 179 | *dst = realloc(*dst, *dst_size); 180 | return 0; 181 | } 182 | -------------------------------------------------------------------------------- /UnityFPSUnlocker/third/xdl/xdl_lzma.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020-2021 HexHacking Team 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all 11 | // copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | // SOFTWARE. 20 | // 21 | 22 | // Created by caikelun on 2020-11-08. 23 | 24 | #ifndef IO_HEXHACKING_XDL_LZMA 25 | #define IO_HEXHACKING_XDL_LZMA 26 | 27 | #include 28 | #include 29 | 30 | #ifdef __cplusplus 31 | extern "C" { 32 | #endif 33 | 34 | int xdl_lzma_decompress(uint8_t *src, size_t src_size, uint8_t **dst, size_t *dst_size); 35 | 36 | #ifdef __cplusplus 37 | } 38 | #endif 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /UnityFPSUnlocker/third/xdl/xdl_util.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020-2021 HexHacking Team 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all 11 | // copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | // SOFTWARE. 20 | // 21 | 22 | // Created by caikelun on 2020-10-04. 23 | 24 | #include "xdl_util.h" 25 | 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | 36 | bool xdl_util_starts_with(const char *str, const char *start) { 37 | while (*str && *str == *start) { 38 | str++; 39 | start++; 40 | } 41 | 42 | return '\0' == *start; 43 | } 44 | 45 | bool xdl_util_ends_with(const char *str, const char *ending) { 46 | size_t str_len = strlen(str); 47 | size_t ending_len = strlen(ending); 48 | 49 | if (ending_len > str_len) return false; 50 | 51 | return 0 == strcmp(str + (str_len - ending_len), ending); 52 | } 53 | 54 | size_t xdl_util_trim_ending(char *start) { 55 | char *end = start + strlen(start); 56 | while (start < end && isspace((int)(*(end - 1)))) { 57 | end--; 58 | *end = '\0'; 59 | } 60 | return (size_t)(end - start); 61 | } 62 | 63 | static int xdl_util_get_api_level_from_build_prop(void) { 64 | char buf[128]; 65 | int api_level = -1; 66 | 67 | FILE *fp = fopen("/system/build.prop", "r"); 68 | if (NULL == fp) goto end; 69 | 70 | while (fgets(buf, sizeof(buf), fp)) { 71 | if (xdl_util_starts_with(buf, "ro.build.version.sdk=")) { 72 | api_level = atoi(buf + 21); 73 | break; 74 | } 75 | } 76 | fclose(fp); 77 | 78 | end: 79 | return (api_level > 0) ? api_level : -1; 80 | } 81 | 82 | int xdl_util_get_api_level(void) { 83 | static int xdl_util_api_level = -1; 84 | 85 | if (xdl_util_api_level < 0) { 86 | int api_level = android_get_device_api_level(); 87 | if (api_level < 0) 88 | api_level = xdl_util_get_api_level_from_build_prop(); // compatible with unusual models 89 | if (api_level < __ANDROID_API_J__) api_level = __ANDROID_API_J__; 90 | 91 | __atomic_store_n(&xdl_util_api_level, api_level, __ATOMIC_SEQ_CST); 92 | } 93 | 94 | return xdl_util_api_level; 95 | } 96 | -------------------------------------------------------------------------------- /UnityFPSUnlocker/third/xdl/xdl_util.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020-2021 HexHacking Team 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all 11 | // copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | // SOFTWARE. 20 | // 21 | 22 | // Created by caikelun on 2020-10-04. 23 | 24 | #ifndef IO_HEXHACKING_XDL_UTIL 25 | #define IO_HEXHACKING_XDL_UTIL 26 | 27 | #include 28 | #include 29 | #include 30 | 31 | #ifndef __LP64__ 32 | #define XDL_UTIL_LINKER_BASENAME "linker" 33 | #define XDL_UTIL_LINKER_PATHNAME "/system/bin/linker" 34 | #define XDL_UTIL_APP_PROCESS_BASENAME "app_process32" 35 | #define XDL_UTIL_APP_PROCESS_PATHNAME "/system/bin/app_process32" 36 | #define XDL_UTIL_APP_PROCESS_BASENAME_K "app_process" 37 | #define XDL_UTIL_APP_PROCESS_PATHNAME_K "/system/bin/app_process" 38 | #else 39 | #define XDL_UTIL_LINKER_BASENAME "linker64" 40 | #define XDL_UTIL_LINKER_PATHNAME "/system/bin/linker64" 41 | #define XDL_UTIL_APP_PROCESS_BASENAME "app_process64" 42 | #define XDL_UTIL_APP_PROCESS_PATHNAME "/system/bin/app_process64" 43 | #endif 44 | #define XDL_UTIL_VDSO_BASENAME "[vdso]" 45 | 46 | #define XDL_UTIL_TEMP_FAILURE_RETRY(exp) \ 47 | ({ \ 48 | __typeof__(exp) _rc; \ 49 | do { \ 50 | errno = 0; \ 51 | _rc = (exp); \ 52 | } while (_rc == -1 && errno == EINTR); \ 53 | _rc; \ 54 | }) 55 | 56 | #ifdef __cplusplus 57 | extern "C" { 58 | #endif 59 | 60 | bool xdl_util_starts_with(const char *str, const char *start); 61 | bool xdl_util_ends_with(const char *str, const char *ending); 62 | 63 | size_t xdl_util_trim_ending(char *start); 64 | 65 | int xdl_util_get_api_level(void); 66 | 67 | #ifdef __cplusplus 68 | } 69 | #endif 70 | 71 | #endif 72 | -------------------------------------------------------------------------------- /UnityFPSUnlocker/unity/unity_engine.cc: -------------------------------------------------------------------------------- 1 | #include "unity_engine.hh" 2 | 3 | #include 4 | 5 | #include "utility/config.hh" 6 | #include "utility/logger.hh" 7 | 8 | void Unity::Init(void* handle) { 9 | if ((il2cpp_resolve_icall = (il2cpp_resolve_icall_f)xdl_sym(handle, "il2cpp_resolve_icall", nullptr)) == nullptr) { 10 | ERROR("il2cpp_resolve_icall not found"); 11 | return; 12 | } 13 | 14 | if ((set_targetFrameRate = (set_targetFrameRate_f)il2cpp_resolve_icall("UnityEngine.Application::set_targetFrameRate")) == nullptr) { 15 | ERROR("set_targetFrameRate not found"); 16 | } 17 | 18 | if ((get_currentResolution = (get_currentResolution_t)il2cpp_resolve_icall("UnityEngine.Screen::get_currentResolution_Injected")) == nullptr) { 19 | ERROR("get_currentResolution not found"); 20 | } 21 | 22 | if ((SetResolution_Internal = (SetResolution_t)il2cpp_resolve_icall("UnityEngine.Screen::SetResolution")) == nullptr) { 23 | if ((SetResolution_Internal = (SetResolution_t)il2cpp_resolve_icall("UnityEngine.Screen::SetResolution_Injected")) == nullptr) { 24 | ERROR("SetResolution not found"); 25 | 26 | if (auto get_height_ptr = il2cpp_resolve_icall("UnityEngine.Screen::get_height")) { 27 | auto ptr = reinterpret_cast(get_height_ptr); 28 | auto opcode = ptr[1]; 29 | if ((opcode & 0xFC000000) == 0x94000000) { 30 | auto offset = (int32_t)(opcode << 8) >> 6; 31 | auto addr = reinterpret_cast(get_height_ptr) + 4 + offset; 32 | auto GetScreenManager = reinterpret_cast(addr); 33 | screen_manager_ = reinterpret_cast(GetScreenManager()); 34 | } 35 | } 36 | 37 | if (screen_manager_ == nullptr) { 38 | ERROR("ScreenManager not found"); 39 | } 40 | } 41 | } 42 | 43 | if ((GetSystemExtImpl_Internal = (GetSystemExtImpl_t)il2cpp_resolve_icall("UnityEngine.Display::GetSystemExtImpl")) == nullptr) { 44 | ERROR("GetSystemExtImpl not found"); 45 | } 46 | } 47 | 48 | Resolution Unity::GetSystemExtImpl() { 49 | Resolution resolution; 50 | if (GetSystemExtImpl_Internal) { 51 | GetSystemExtImpl_Internal(nullptr, &resolution.m_Width, &resolution.m_Height); 52 | } 53 | return resolution; 54 | } 55 | 56 | Resolution Unity::GetResolution() { 57 | Resolution resolution; 58 | if (get_currentResolution) { 59 | get_currentResolution(&resolution); 60 | } 61 | return resolution; 62 | } 63 | 64 | void Unity::SetResolution(float scale) { 65 | Resolution resolution = GetSystemExtImpl(); 66 | if (scale > 0 && resolution.m_Width > 0) { 67 | auto target_width = static_cast(resolution.m_Width * scale); 68 | auto target_height = static_cast(resolution.m_Height * scale); 69 | int preferred_refresh_rate = 0; 70 | 71 | if (SetResolution_Internal) { 72 | LOG("Set resolution: %d x %d", target_width, target_height); 73 | SetResolution_Internal(target_width, target_height, 1, &preferred_refresh_rate); 74 | Utility::NopFunc(reinterpret_cast(SetResolution_Internal)); 75 | } 76 | else if (screen_manager_) { 77 | LOG("Set resolution: %d x %d", target_width, target_height); 78 | screen_manager_->RequestResolution(target_width, target_height, 1, &preferred_refresh_rate); 79 | } 80 | } 81 | } 82 | 83 | void Unity::SetFrameRate(int framerate, bool mod_opcode) { 84 | Resolution resolution = GetResolution(); 85 | if (set_targetFrameRate) { 86 | set_targetFrameRate(framerate); 87 | LOG("Current resolution: %dx%d @%d", resolution.m_Width, resolution.m_Height, resolution.m_RefreshRate); 88 | if (framerate > resolution.m_RefreshRate) { 89 | ERROR("The screen refresh rate is lower than target framerate! %d < %d", resolution.m_RefreshRate, framerate); 90 | } 91 | 92 | if (mod_opcode) { 93 | auto ptr = reinterpret_cast(set_targetFrameRate); 94 | auto opcode = ptr[0]; 95 | if ((opcode & 0xFC000000) == 0x14000000) { 96 | auto offset = (int32_t)(opcode << 8) >> 6; 97 | ptr = reinterpret_cast(reinterpret_cast(set_targetFrameRate) + offset); 98 | } 99 | Utility::NopFunc(reinterpret_cast(ptr)); 100 | } 101 | } 102 | } -------------------------------------------------------------------------------- /UnityFPSUnlocker/unity/unity_engine.hh: -------------------------------------------------------------------------------- 1 | #ifndef UNITY_ENGINE_HEADER 2 | #define UNITY_ENGINE_HEADER 3 | 4 | #include 5 | 6 | #include "utility/singleton.hh" 7 | 8 | struct Resolution { 9 | int32_t m_Width = 0; 10 | int32_t m_Height = 0; 11 | int32_t m_RefreshRate = 0; 12 | }; 13 | 14 | class ScreenManager { 15 | public: 16 | virtual ~ScreenManager() {} 17 | virtual void RequestResolution(int, int, int, void*); 18 | }; 19 | 20 | class Unity : public Singleton { 21 | public: 22 | void Init(void*); 23 | 24 | Resolution GetSystemExtImpl(); 25 | Resolution GetResolution(); 26 | void SetResolution(float); 27 | void SetFrameRate(int, bool); 28 | 29 | private: 30 | using il2cpp_resolve_icall_f = void* (*)(const char*); 31 | using set_targetFrameRate_f = void (*)(int); 32 | using SetResolution_t = void (*)(int, int, int, void*); 33 | using get_currentResolution_t = void (*)(Resolution*); 34 | using GetSystemExtImpl_t = void (*)(void*, int*, int*); 35 | 36 | il2cpp_resolve_icall_f il2cpp_resolve_icall = nullptr; 37 | set_targetFrameRate_f set_targetFrameRate = nullptr; 38 | SetResolution_t SetResolution_Internal = nullptr; 39 | get_currentResolution_t get_currentResolution = nullptr; 40 | GetSystemExtImpl_t GetSystemExtImpl_Internal = nullptr; 41 | 42 | ScreenManager* screen_manager_ = nullptr; 43 | }; 44 | 45 | #endif // unity_engine.hh -------------------------------------------------------------------------------- /UnityFPSUnlocker/utility/config.cc: -------------------------------------------------------------------------------- 1 | #include "config.hh" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include 9 | #include 10 | 11 | #include 12 | #include 13 | 14 | #include "logger.hh" 15 | 16 | using namespace rapidjson; 17 | 18 | namespace Utility { 19 | absl::StatusOr LoadJsonFromFile(const char* file_path) { 20 | Document doc; 21 | std::ifstream file(file_path); 22 | if (file.is_open()) { 23 | std::string content((std::istreambuf_iterator(file)), 24 | (std::istreambuf_iterator())); 25 | if (doc.Parse(content.c_str()).HasParseError()) { 26 | if (content.size() > 2) { 27 | content[doc.GetErrorOffset() - 2] = '-'; 28 | content[doc.GetErrorOffset() - 1] = '>'; 29 | } 30 | ERROR("[%s] %s #%d\nFile: %s %s %zu %s", __FUNCTION__, __FILE__, __LINE__, 31 | file_path, GetParseError_En(doc.GetParseError()), doc.GetErrorOffset(), content.c_str()); 32 | return absl::InternalError("Parse error"); 33 | } 34 | } 35 | else { 36 | ERROR("[%s] %s #%d\nCould not read file: %s. %s", __FUNCTION__, __FILE__, __LINE__, file_path, strerror(errno)); 37 | return absl::InternalError("Could not read file."); 38 | } 39 | return doc; 40 | } 41 | 42 | jobject GetApplication(JNIEnv* env) { 43 | jclass activity_thread_clz = env->FindClass("android/app/ActivityThread"); 44 | if (activity_thread_clz != nullptr) { 45 | jmethodID currentApplicationId = env->GetStaticMethodID( 46 | activity_thread_clz, 47 | "currentApplication", 48 | "()Landroid/app/Application;"); 49 | if (currentApplicationId != nullptr) { 50 | return env->CallStaticObjectMethod(activity_thread_clz, currentApplicationId); 51 | } 52 | else { 53 | ERROR("Cannot find method: currentApplication() in ActivityThread."); 54 | } 55 | } 56 | else { 57 | ERROR("Cannot find class: android.app.ActivityThread"); 58 | } 59 | return nullptr; 60 | } 61 | 62 | absl::StatusOr GetApplicationInfo(JNIEnv* env) { 63 | jobject application = GetApplication(env); 64 | if (application == nullptr) { 65 | return absl::NotFoundError("No method id currentApplication"); 66 | } 67 | jclass application_clazz = env->GetObjectClass(application); 68 | if (application_clazz == nullptr) { 69 | return absl::NotFoundError("No class application"); 70 | } 71 | jmethodID get_application_info = env->GetMethodID( 72 | application_clazz, 73 | "getApplicationInfo", 74 | "()Landroid/content/pm/ApplicationInfo;"); 75 | if (get_application_info) { 76 | return env->CallObjectMethod(application, get_application_info); 77 | } 78 | else { 79 | return absl::NotFoundError("No method id getApplicationInfo"); 80 | } 81 | } 82 | 83 | absl::StatusOr GetLibraryPath(JNIEnv* env, jobject application_info) { 84 | if (!application_info) { 85 | return absl::NotFoundError("No method id"); 86 | } 87 | jfieldID native_library_dir_id = env->GetFieldID( 88 | env->GetObjectClass(application_info), 89 | "nativeLibraryDir", 90 | "Ljava/lang/String;"); 91 | 92 | if (native_library_dir_id) { 93 | jstring native_library_dir_jstring = (jstring)env->GetObjectField(application_info, native_library_dir_id); 94 | const char* path = env->GetStringUTFChars(native_library_dir_jstring, 0); 95 | std::string package_name(path); 96 | env->ReleaseStringUTFChars(native_library_dir_jstring, path); 97 | return package_name; 98 | } 99 | else { 100 | return absl::NotFoundError("No nativeLibraryDir"); 101 | } 102 | } 103 | 104 | absl::StatusOr GetVM() { 105 | // copy from https://github.com/frida/frida-core/blob/main/lib/agent/agent.vala 106 | 107 | void* art = xdl_open("libart.so", 0); 108 | if (!art) { 109 | return absl::InternalError("Cannot open libart.so."); 110 | } 111 | 112 | using JNIGetCreatedJavaVMs_t = int (*)(JavaVM** vmBuf, jsize bufLen, jsize* nVMs); 113 | static JNIGetCreatedJavaVMs_t JNIGetCreatedJavaVMsFunc = (JNIGetCreatedJavaVMs_t)xdl_sym(art, "JNI_GetCreatedJavaVMs", nullptr); 114 | 115 | if (!JNIGetCreatedJavaVMsFunc) { 116 | return absl::NotFoundError("Cannot get symbol JNIGetCreatedJavaVMsFunc"); 117 | } 118 | 119 | jsize numVMs; 120 | JavaVM* vms = nullptr; 121 | if (JNIGetCreatedJavaVMsFunc(&vms, 1, &numVMs) != 0) { 122 | return absl::NotFoundError("Cannot get vms"); 123 | } 124 | return vms; 125 | } 126 | 127 | // Generated by ChatGPT. 128 | int ChangeMemPermission(void* p, size_t n, int permission) { 129 | 130 | void* page_aligned_p = reinterpret_cast(reinterpret_cast(p) & ~(getpagesize() - 1)); 131 | 132 | size_t protect_size = reinterpret_cast(p) + n - reinterpret_cast(page_aligned_p); 133 | if (protect_size % getpagesize() != 0) { 134 | protect_size += getpagesize(); 135 | } 136 | 137 | return ::mprotect(page_aligned_p, protect_size, permission); 138 | } 139 | 140 | void NopFunc(unsigned char* ptr) { 141 | ChangeMemPermission(ptr, 4); 142 | #ifdef __aarch64__ 143 | ptr[0] = 0xC0; 144 | ptr[1] = 0x03; 145 | ptr[2] = 0x5F; 146 | ptr[3] = 0xD6; 147 | #elif __ARM_ARCH_7A__ 148 | if (0x00000001 == (reinterpret_cast(ptr) & 0x00000001)) { 149 | ptr--; 150 | ChangeMemPermission(ptr, 4); 151 | ptr[0] = 0x70; 152 | ptr[1] = 0x47; 153 | ptr[2] = 0x00; 154 | ptr[3] = 0xBF; 155 | } 156 | else { 157 | ptr[0] = 0x1E; 158 | ptr[1] = 0xFF; 159 | ptr[2] = 0x2F; 160 | ptr[3] = 0xE1; 161 | } 162 | #elif defined(__i386__) || defined(__x86_64__) 163 | ptr[0] = 0xC3; 164 | #endif 165 | } 166 | } // namespace Utility -------------------------------------------------------------------------------- /UnityFPSUnlocker/utility/config.hh: -------------------------------------------------------------------------------- 1 | #ifndef CONFIG_HEADER 2 | #define CONFIG_HEADER 3 | 4 | #include 5 | #include 6 | 7 | #include 8 | #include 9 | 10 | #include 11 | #include 12 | 13 | #include "logger.hh" 14 | 15 | class ConfigValue { 16 | public: 17 | int delay_ = 5; 18 | int fps_ = 90; 19 | bool mod_opcode_ = true; 20 | float scale_ = -1; 21 | 22 | ConfigValue(){}; 23 | ConfigValue(int delay, int fps, bool mod_opcode, float scale) 24 | : delay_(delay), 25 | fps_(fps), 26 | mod_opcode_(mod_opcode), 27 | scale_(scale){}; 28 | ConfigValue(const ConfigValue& lhs) { 29 | delay_ = lhs.delay_; 30 | fps_ = lhs.fps_; 31 | mod_opcode_ = lhs.mod_opcode_; 32 | scale_ = lhs.scale_; 33 | } 34 | 35 | void DebugPrint() const { 36 | LOG("\tdelay: %d | fps: %d | mod_opcode: %d | scale: %f", delay_, fps_, mod_opcode_, scale_); 37 | } 38 | }; 39 | 40 | namespace Utility { 41 | absl::StatusOr LoadJsonFromFile(const char*); 42 | jobject GetApplication(JNIEnv* env); 43 | absl::StatusOr GetApplicationInfo(JNIEnv* env); 44 | absl::StatusOr GetLibraryPath(JNIEnv* env, jobject application_info); 45 | absl::StatusOr GetVM(); 46 | int ChangeMemPermission(void* p, size_t n, int permission = PROT_READ | PROT_WRITE | PROT_EXEC); 47 | void NopFunc(unsigned char* ptr); 48 | }; // namespace Utility 49 | 50 | #endif // config.hh -------------------------------------------------------------------------------- /UnityFPSUnlocker/utility/houdini.cc: -------------------------------------------------------------------------------- 1 | #include "houdini.hh" 2 | 3 | #if defined(__i386__) || defined(__x86_64__) 4 | 5 | #include 6 | 7 | #ifdef __x86_64__ 8 | #define syslib "/system/lib64/" 9 | #elif defined(__i386__) 10 | #define syslib "/system/lib/" 11 | #endif 12 | 13 | namespace { 14 | using NativeBridgeGetVersion_t = uint32_t (*)(); 15 | using NativeBridgeLoadLibrary_t = void* (*)(const char*, int); 16 | using NativeBridgeLoadLibraryExt_t = void* (*)(const char*, int, void*); 17 | using NativeBridgeGetTrampoline_t = void* (*)(void* handle, const char* name, const char* shorty, uint32_t len); 18 | using NativeBridgeGetError_t = const char* (*)(); 19 | 20 | static NativeBridgeGetVersion_t NativeBridgeGetVersion = nullptr; 21 | } // namespace 22 | 23 | Houdini::Houdini() { 24 | void* libhoudini = dlopen("libhoudini.so", RTLD_NOW); 25 | if (libhoudini) { 26 | houdini_itf_ = reinterpret_cast(dlsym(libhoudini, "NativeBridgeItf")); 27 | if (houdini_itf_) { 28 | houdini_ver_ = houdini_itf_->version; 29 | } 30 | } 31 | else { 32 | void* libnativebridge = dlopen(syslib "libnativebridge.so", RTLD_NOW); 33 | if (libnativebridge) { 34 | NativeBridgeGetVersion = (NativeBridgeGetVersion_t)dlsym(libnativebridge, "_ZN7android22NativeBridgeGetVersionEv"); 35 | 36 | houdini_itf_ = new android::NativeBridgeCallbacks(); 37 | houdini_itf_->loadLibrary = reinterpret_cast(dlsym(libnativebridge, "_ZN7android23NativeBridgeLoadLibraryEPKci")); 38 | houdini_itf_->loadLibraryExt = reinterpret_cast(dlsym(libnativebridge, "_ZN7android26NativeBridgeLoadLibraryExtEPKciPNS_25native_bridge_namespace_tE")); 39 | houdini_itf_->getTrampoline = reinterpret_cast(dlsym(libnativebridge, "_ZN7android25NativeBridgeGetTrampolineEPvPKcS2_j")); 40 | 41 | houdini_ver_ = NativeBridgeGetVersion(); 42 | 43 | if (houdini_ver_ > 2) { 44 | houdini_itf_->getError = reinterpret_cast(dlsym(libnativebridge, "_ZN7android20NativeBridgeGetErrorEv")); 45 | } 46 | } 47 | } 48 | } 49 | 50 | absl::StatusOr Houdini::LoadLibrary(const char* name, int flag) { 51 | if (houdini_ver_ > 0 && houdini_itf_) { 52 | if (houdini_ver_ == 2) { 53 | return houdini_itf_->loadLibrary(name, flag); 54 | } 55 | else if (houdini_ver_ == 3) { 56 | return houdini_itf_->loadLibraryExt(name, flag, (void*)3); 57 | } 58 | else { 59 | return houdini_itf_->loadLibraryExt(name, flag, (void*)5); 60 | } 61 | } 62 | return absl::InternalError("Houdini init error"); 63 | } 64 | 65 | absl::Status Houdini::CallJNI(void* handle, void* vm, void* reserved) { 66 | using JNI_OnLoad_t = int (*)(void*, void*); 67 | JNI_OnLoad_t jni_onload_ptr = nullptr; 68 | if (houdini_ver_ > 0 && houdini_itf_) { 69 | jni_onload_ptr = reinterpret_cast(houdini_itf_->getTrampoline(handle, "JNI_OnLoad", nullptr, 0)); 70 | 71 | if (jni_onload_ptr) { 72 | jni_onload_ptr(vm, reserved); 73 | return absl::OkStatus(); 74 | } 75 | else { 76 | return absl::NotFoundError("JNI_OnLoad not found"); 77 | } 78 | } 79 | return absl::InternalError("Houdini init error"); 80 | } 81 | 82 | const char* Houdini::GetError() { 83 | if (houdini_ver_ > 2) { 84 | if (houdini_itf_) { 85 | auto ptr = reinterpret_cast(houdini_itf_); 86 | return ptr->getError(); 87 | } 88 | } 89 | return "(null)"; 90 | } 91 | 92 | #endif // architecture defined -------------------------------------------------------------------------------- /UnityFPSUnlocker/utility/houdini.hh: -------------------------------------------------------------------------------- 1 | #ifndef HOUDINI_HEADER 2 | #define HOUDINI_HEADER 3 | 4 | #if defined(__i386__) || defined(__x86_64__) 5 | 6 | #include 7 | #include 8 | 9 | #include "native_bridge.h" 10 | #include "singleton.hh" 11 | 12 | class Houdini : public Singleton { 13 | friend class Singleton; 14 | 15 | public: 16 | absl::StatusOr LoadLibrary(const char* name, int flag); 17 | absl::Status CallJNI(void* handle, void* vm, void* reserved); 18 | const char* GetError(); 19 | 20 | private: 21 | Houdini(); 22 | int houdini_ver_ = 0; 23 | android::NativeBridgeCallbacks* houdini_itf_ = nullptr; 24 | }; 25 | 26 | #endif // architecture defined 27 | 28 | #endif // houdini.hh -------------------------------------------------------------------------------- /UnityFPSUnlocker/utility/logger.hh: -------------------------------------------------------------------------------- 1 | #ifndef LOGGER_HEADER 2 | #define LOGGER_HEADER 3 | 4 | #define LOG_TAG "UnityFPSUnlocker" 5 | #include 6 | 7 | #define LOG(...) __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__) 8 | #define ERROR(...) __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__) 9 | 10 | #endif // LOGGER_HEADER -------------------------------------------------------------------------------- /UnityFPSUnlocker/utility/singleton.hh: -------------------------------------------------------------------------------- 1 | #ifndef SINGLETON_HEADER 2 | #define SINGLETON_HEADER 3 | 4 | template 5 | class Singleton { 6 | public: 7 | Singleton(const Singleton&) = delete; 8 | void operator=(const Singleton&) = delete; 9 | 10 | static T& GetInstance() { 11 | static T instance; 12 | return instance; 13 | } 14 | 15 | protected: 16 | Singleton() {} 17 | virtual ~Singleton() {} 18 | }; 19 | 20 | #endif // singleton.hh -------------------------------------------------------------------------------- /UnityFPSUnlocker/utility/socket.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include 6 | 7 | #include "utility/logger.hh" 8 | #include "utility/socket.hh" 9 | 10 | using namespace std; 11 | 12 | ssize_t xsendmsg(int sockfd, const struct msghdr* msg, int flags) { 13 | int sent = sendmsg(sockfd, msg, flags); 14 | if (sent < 0) { 15 | LOG("xsendmsg error: %s", strerror(errno)); 16 | } 17 | return sent; 18 | } 19 | 20 | ssize_t xrecvmsg(int sockfd, struct msghdr* msg, int flags) { 21 | int rec = recvmsg(sockfd, msg, flags); 22 | if (rec < 0) { 23 | LOG("xrecvmsg error: %s", strerror(errno)); 24 | } 25 | return rec; 26 | } 27 | 28 | ssize_t xxread(int fd, void* buf, size_t count) { 29 | size_t read_sz = 0; 30 | ssize_t ret; 31 | do { 32 | ret = read(fd, (std::byte*)buf + read_sz, count - read_sz); 33 | if (ret < 0) { 34 | if (errno == EINTR) 35 | continue; 36 | LOG("xxread error: %s", strerror(errno)); 37 | return ret; 38 | } 39 | read_sz += ret; 40 | } while (read_sz != count && ret != 0); 41 | if (read_sz != count) { 42 | LOG("xxread (%zu != %zu)", count, read_sz); 43 | } 44 | return read_sz; 45 | } 46 | 47 | ssize_t xwrite(int fd, const void* buf, size_t count) { 48 | size_t write_sz = 0; 49 | ssize_t ret; 50 | do { 51 | ret = write(fd, (std::byte*)buf + write_sz, count - write_sz); 52 | if (ret < 0) { 53 | if (errno == EINTR) 54 | continue; 55 | LOG("xwrite error: %s", strerror(errno)); 56 | return ret; 57 | } 58 | write_sz += ret; 59 | } while (write_sz != count && ret != 0); 60 | if (write_sz != count) { 61 | LOG("xwrite (%zu != %zu)", count, write_sz); 62 | } 63 | return write_sz; 64 | } 65 | 66 | static size_t socket_len(sockaddr_un* sun) { 67 | if (sun->sun_path[0]) 68 | return sizeof(sa_family_t) + strlen(sun->sun_path) + 1; 69 | else 70 | return sizeof(sa_family_t) + strlen(sun->sun_path + 1) + 1; 71 | } 72 | 73 | socklen_t setup_sockaddr(sockaddr_un* sun, const char* name) { 74 | memset(sun, 0, sizeof(*sun)); 75 | sun->sun_family = AF_UNIX; 76 | strcpy(sun->sun_path + 1, name); 77 | return socket_len(sun); 78 | } 79 | 80 | bool get_client_cred(int fd, sock_cred* cred) { 81 | socklen_t len = sizeof(ucred); 82 | if (getsockopt(fd, SOL_SOCKET, SO_PEERCRED, cred, &len) != 0) 83 | return false; 84 | char buf[4096]; 85 | len = sizeof(buf); 86 | if (getsockopt(fd, SOL_SOCKET, SO_PEERSEC, buf, &len) != 0) 87 | return false; 88 | buf[len] = '\0'; 89 | cred->context = buf; 90 | return true; 91 | } 92 | 93 | static int send_fds(int sockfd, void* cmsgbuf, size_t bufsz, const int* fds, int cnt) { 94 | iovec iov = { 95 | .iov_base = &cnt, 96 | .iov_len = sizeof(cnt), 97 | }; 98 | msghdr msg = { 99 | .msg_iov = &iov, 100 | .msg_iovlen = 1, 101 | }; 102 | 103 | if (cnt) { 104 | msg.msg_control = cmsgbuf; 105 | msg.msg_controllen = bufsz; 106 | cmsghdr* cmsg = CMSG_FIRSTHDR(&msg); 107 | cmsg->cmsg_len = CMSG_LEN(sizeof(int) * cnt); 108 | cmsg->cmsg_level = SOL_SOCKET; 109 | cmsg->cmsg_type = SCM_RIGHTS; 110 | 111 | memcpy(CMSG_DATA(cmsg), fds, sizeof(int) * cnt); 112 | } 113 | 114 | return xsendmsg(sockfd, &msg, 0); 115 | } 116 | 117 | int send_fds(int sockfd, const int* fds, int cnt) { 118 | if (cnt == 0) { 119 | return send_fds(sockfd, nullptr, 0, nullptr, 0); 120 | } 121 | vector cmsgbuf; 122 | cmsgbuf.resize(CMSG_SPACE(sizeof(int) * cnt)); 123 | return send_fds(sockfd, cmsgbuf.data(), cmsgbuf.size(), fds, cnt); 124 | } 125 | 126 | int send_fd(int sockfd, int fd) { 127 | if (fd < 0) { 128 | return send_fds(sockfd, nullptr, 0, nullptr, 0); 129 | } 130 | char cmsgbuf[CMSG_SPACE(sizeof(int))]; 131 | return send_fds(sockfd, cmsgbuf, sizeof(cmsgbuf), &fd, 1); 132 | } 133 | 134 | static void* recv_fds(int sockfd, char* cmsgbuf, size_t bufsz, int cnt) { 135 | iovec iov = { 136 | .iov_base = &cnt, 137 | .iov_len = sizeof(cnt), 138 | }; 139 | msghdr msg = { 140 | .msg_iov = &iov, 141 | .msg_iovlen = 1, 142 | .msg_control = cmsgbuf, 143 | .msg_controllen = bufsz 144 | }; 145 | 146 | xrecvmsg(sockfd, &msg, MSG_WAITALL); 147 | cmsghdr* cmsg = CMSG_FIRSTHDR(&msg); 148 | 149 | if (msg.msg_controllen != bufsz || 150 | cmsg == nullptr || 151 | cmsg->cmsg_len != CMSG_LEN(sizeof(int) * cnt) || 152 | cmsg->cmsg_level != SOL_SOCKET || 153 | cmsg->cmsg_type != SCM_RIGHTS) { 154 | return nullptr; 155 | } 156 | 157 | return CMSG_DATA(cmsg); 158 | } 159 | 160 | vector recv_fds(int sockfd) { 161 | vector results; 162 | 163 | // Peek fd count to allocate proper buffer 164 | int cnt; 165 | recv(sockfd, &cnt, sizeof(cnt), MSG_PEEK); 166 | if (cnt == 0) 167 | return results; 168 | 169 | vector cmsgbuf; 170 | cmsgbuf.resize(CMSG_SPACE(sizeof(int) * cnt)); 171 | 172 | void* data = recv_fds(sockfd, cmsgbuf.data(), cmsgbuf.size(), cnt); 173 | if (data == nullptr) 174 | return results; 175 | 176 | results.resize(cnt); 177 | memcpy(results.data(), data, sizeof(int) * cnt); 178 | 179 | return results; 180 | } 181 | 182 | int recv_fd(int sockfd) { 183 | char cmsgbuf[CMSG_SPACE(sizeof(int))]; 184 | 185 | void* data = recv_fds(sockfd, cmsgbuf, sizeof(cmsgbuf), 1); 186 | if (data == nullptr) 187 | return -1; 188 | 189 | int result; 190 | memcpy(&result, data, sizeof(int)); 191 | return result; 192 | } 193 | 194 | int read_int(int fd) { 195 | int val; 196 | if (xxread(fd, &val, sizeof(val)) != sizeof(val)) 197 | return -1; 198 | return val; 199 | } 200 | 201 | int read_int_be(int fd) { 202 | uint32_t val; 203 | if (xxread(fd, &val, sizeof(val)) != sizeof(val)) 204 | return -1; 205 | return ntohl(val); 206 | } 207 | 208 | void write_int(int fd, int val) { 209 | if (fd < 0) 210 | return; 211 | xwrite(fd, &val, sizeof(val)); 212 | } 213 | 214 | void write_int_be(int fd, int val) { 215 | uint32_t nl = htonl(val); 216 | xwrite(fd, &nl, sizeof(nl)); 217 | } 218 | 219 | void read_string(int fd, std::string& str) { 220 | int len = read_int(fd); 221 | str.clear(); 222 | str.resize(len); 223 | xxread(fd, str.data(), len); 224 | } 225 | 226 | string read_string(int fd) { 227 | string str; 228 | read_string(fd, str); 229 | return str; 230 | } 231 | 232 | void write_string(int fd, string_view str) { 233 | if (fd < 0) 234 | return; 235 | write_int(fd, str.size()); 236 | xwrite(fd, str.data(), str.size()); 237 | } 238 | 239 | float read_float(int fd) { 240 | float val; 241 | if (xxread(fd, &val, sizeof(val)) != sizeof(val)) 242 | return -1; 243 | return val; 244 | } 245 | 246 | void write_float(int fd, float val) { 247 | if (fd < 0) 248 | return; 249 | xwrite(fd, &val, sizeof(val)); 250 | } -------------------------------------------------------------------------------- /UnityFPSUnlocker/utility/socket.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | #include 8 | 9 | struct sock_cred : public ucred { 10 | std::string context; 11 | }; 12 | 13 | socklen_t setup_sockaddr(sockaddr_un* sun, const char* name); 14 | bool get_client_cred(int fd, sock_cred* cred); 15 | std::vector recv_fds(int sockfd); 16 | int recv_fd(int sockfd); 17 | int send_fds(int sockfd, const int* fds, int cnt); 18 | int send_fd(int sockfd, int fd); 19 | int read_int(int fd); 20 | int read_int_be(int fd); 21 | void write_int(int fd, int val); 22 | void write_int_be(int fd, int val); 23 | std::string read_string(int fd); 24 | void read_string(int fd, std::string& str); 25 | void write_string(int fd, std::string_view str); 26 | float read_float(int fd); 27 | void write_float(int fd, float val); 28 | --------------------------------------------------------------------------------