Difference between revisions of "Engine:Unity/Unlock FPS"
m (Add a space) |
|||
Line 7: | Line 7: | ||
{{++}} Most Unity games run perfect after FPS unlocked. Only a few Unity games contain logics tied to framerate. | {{++}} Most Unity games run perfect after FPS unlocked. Only a few Unity games contain logics tied to framerate. | ||
{{--}} There is currently no method to restore IL2CPP to compileable original code, which makes it difficult to modify code of Unity games using IL2CPP. | {{--}} There is currently no method to restore IL2CPP to compileable original code, which makes it difficult to modify code of Unity games using IL2CPP. | ||
+ | |||
+ | |||
+ | ==Determine whether game uses Mono or IL2CPP== | ||
+ | It is easy to determine by files in {{P|game}}. | ||
+ | |||
+ | ====Mono only files==== | ||
+ | * {{folder|GameName_Data/Mono}} or {{folder|MonoBleedingEdge}} | ||
+ | * {{file|GameName_Data/Managed/Assembly-CSharp.dll}} | ||
+ | |||
+ | ====IL2CPP only files==== | ||
+ | * {{file|GameName_Data/il2cpp_data/Metadata/global-metadata.dat}} | ||
+ | * {{file|GameAssembly.dll}} | ||
+ | * {{file|baselib.dll}} | ||
+ | |||
+ | ==Modify game code== | ||
+ | |||
+ | ===Decompile game code=== | ||
+ | If the game is using Mono, we can decompile with [https://github.com/dnSpyEx/dnSpy dnSpy]{{note|dnSpyEx is the most active fork after original dnSpy archived.}}. | ||
+ | # Open {{file|GameName_Data/Managed/Assembly-CSharp.dll}} in dnSpy. | ||
+ | # File -> Export to Project, ensure Language is set to C#, then select a folder to export | ||
+ | # Open the export folder, then open {{file|Assembly-CSharp.sln}} with Visual Studio, you should see game code | ||
+ | {{ii}} Sometimes the code we need to modify is in other dll files as some libraries used in game may modify FPS limit. Just decompile those dll files in {{folder|GameName_Data/Managed}} in the same way. | ||
+ | |||
+ | ===Find FPS lock code=== | ||
+ | # After {{file|Assembly-CSharp.sln}} opened in Visual Studio, use the key {{key|Ctrl|Shift|F}} to open global search tool. | ||
+ | {{ii}} {{key|Ctrl|Shift|F}} is also the key to change between Simplfied Chinese and Traditional Chinese of Microsoft Pinyin, which is the default input method for Chinese language pack since Windows 10. If you are using Chinese input on Windows 10 or above, don't forget to change to English input. | ||
+ | # Type <code>vSyncCount</code> or <code>targetFrameRate</code> then click 'Find All'. | ||
+ | # You can see code that limit FPS now. | ||
+ | {{ii}} If you cannot find any code limit FPS, the game may use {{file|globalgamemanagers}} configs to limit FPS. You can refer to [[Engine:Unity#Graphical_presets|graphics preset]]. | ||
+ | |||
+ | ===Modify code to unlock FPS=== | ||
+ | You should first record the highest locked FPS before modification. This can be used to find the code needs to modify. Do not simply modify all code in search result, which may break game on specific scenes.{{note|Some games limit FPS to video framerate when playing videos in game. Modify such code may break video playback.}} | ||
+ | |||
+ | # Navigate to the class with FPS lock code in dnSpy and find the code. | ||
+ | # Right click the code and select 'Edit Method (C#)...' or use {{key|Ctrl|Shift|E}}. | ||
+ | # Modify the code according to description below. | ||
+ | # Click 'Compile' button. | ||
+ | # File -> Save Module... -> OK | ||
+ | |||
+ | ====<code>QualitySettings.vSyncCount</code>==== | ||
+ | This function controls [[Glossary:Vertical_sync_(Vsync)|vertical sync]]. The value can be 0, 1, 2, 3, 4. | ||
+ | |||
+ | When set to 0, VSync is off and framerate is unlimited unless <code>Application.targetFrameRate</code> is set. | ||
+ | |||
+ | When set to 1-4, VSync is on and framerate limited to <code>Refresh Rate / Value</code>, and <code>Application.targetFrameRate</code> is ignored. For example, value 3 on a 240Hz display means FPS is locked to 240 / 3 = 80 FPS. | ||
+ | |||
+ | ====<code>Application.targetFrameRate</code>==== | ||
+ | This function simply limit FPS if <code>QualitySettings.vSyncCount</code> is set to 0. | ||
+ | |||
+ | When set to -1, FPS is unlimited. | ||
+ | |||
+ | When a positive integer is set, FPS is locked to this integer. | ||
+ | |||
+ | ==References== | ||
+ | <references group="Note"/> |
Revision as of 07:48, 4 May 2024
General information
Unity games usually lock FPS with QualitySettings.vSyncCount
and Application.targetFrameRate
. If we can change the parameters of these two methods, FPS can be easily unlocked.
- Most Unity games run perfect after FPS unlocked. Only a few Unity games contain logics tied to framerate.
- There is currently no method to restore IL2CPP to compileable original code, which makes it difficult to modify code of Unity games using IL2CPP.
Determine whether game uses Mono or IL2CPP
It is easy to determine by files in <path-to-game>.
Mono only files
GameName_Data/Mono
orMonoBleedingEdge
GameName_Data/Managed/Assembly-CSharp.dll
IL2CPP only files
GameName_Data/il2cpp_data/Metadata/global-metadata.dat
GameAssembly.dll
baselib.dll
Modify game code
Decompile game code
If the game is using Mono, we can decompile with dnSpy[Note 1].
- Open
GameName_Data/Managed/Assembly-CSharp.dll
in dnSpy. - File -> Export to Project, ensure Language is set to C#, then select a folder to export
- Open the export folder, then open
Assembly-CSharp.sln
with Visual Studio, you should see game code
- Sometimes the code we need to modify is in other dll files as some libraries used in game may modify FPS limit. Just decompile those dll files in
GameName_Data/Managed
in the same way.
Find FPS lock code
- After
Assembly-CSharp.sln
opened in Visual Studio, use the key Ctrl+⇧ Shift+F to open global search tool.
- Ctrl+⇧ Shift+F is also the key to change between Simplfied Chinese and Traditional Chinese of Microsoft Pinyin, which is the default input method for Chinese language pack since Windows 10. If you are using Chinese input on Windows 10 or above, don't forget to change to English input.
- Type
vSyncCount
ortargetFrameRate
then click 'Find All'. - You can see code that limit FPS now.
- If you cannot find any code limit FPS, the game may use
globalgamemanagers
configs to limit FPS. You can refer to graphics preset.
Modify code to unlock FPS
You should first record the highest locked FPS before modification. This can be used to find the code needs to modify. Do not simply modify all code in search result, which may break game on specific scenes.[Note 2]
- Navigate to the class with FPS lock code in dnSpy and find the code.
- Right click the code and select 'Edit Method (C#)...' or use Ctrl+⇧ Shift+E.
- Modify the code according to description below.
- Click 'Compile' button.
- File -> Save Module... -> OK
QualitySettings.vSyncCount
This function controls vertical sync. The value can be 0, 1, 2, 3, 4.
When set to 0, VSync is off and framerate is unlimited unless Application.targetFrameRate
is set.
When set to 1-4, VSync is on and framerate limited to Refresh Rate / Value
, and Application.targetFrameRate
is ignored. For example, value 3 on a 240Hz display means FPS is locked to 240 / 3 = 80 FPS.
Application.targetFrameRate
This function simply limit FPS if QualitySettings.vSyncCount
is set to 0.
When set to -1, FPS is unlimited.
When a positive integer is set, FPS is locked to this integer.