Skip to content

Commit f3d800e

Browse files
committed
fix graphics plus
1 parent b1342ce commit f3d800e

3 files changed

Lines changed: 58 additions & 19 deletions

File tree

AmongUs.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project>
22
<ItemGroup>
3-
<PackageReference Include="AmongUs.GameLibs.Android" Version="2026.2.17" />
3+
<PackageReference Include="AmongUs.GameLibs.Android" Version="2026.3.17" />
44
<PackageReference Include="BepInEx.Unity.IL2CPP" Version="6.0.0-be.735" Private="false" ExcludeAssets="runtime;native" />
55

66
<PackageReference Include="BepInEx.AutoPlugin" Version="1.1.0" PrivateAssets="all" />

GraphicsPlus/GraphicsPlugin.cs

Lines changed: 54 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
using System.Reflection;
2+
using System.Runtime.InteropServices;
23
using BepInEx;
34
using BepInEx.Configuration;
45
using BepInEx.Unity.IL2CPP;
56
using HarmonyLib;
7+
using Il2CppInterop.Runtime.Injection;
68
using UnityEngine;
79

810
namespace GraphicsPlus;
@@ -11,48 +13,84 @@ namespace GraphicsPlus;
1113
public partial class GraphicsPlugin : BasePlugin
1214
{
1315
private static GraphicsPlugin Instance { get; set; }
14-
16+
1517
private ConfigEntry<int> TargetFrameRate { get; set; }
1618

1719
private ConfigEntry<bool> FullResolution { get; set; }
20+
21+
private static ResolutionManager _resolutionManager;
1822

23+
[LibraryImport("libstarlight.so")]
24+
private static unsafe partial int get_width();
25+
26+
[LibraryImport("libstarlight.so")]
27+
private static unsafe partial int get_height();
28+
1929
public GraphicsPlugin()
2030
{
2131
Instance = this;
2232
TargetFrameRate = Config.Bind("General", "Target Frame Rate", 60, "The target frame rate of the game");
23-
FullResolution = Config.Bind("General", "Increase Resolution", false, "Set the game to use the display resolution.");
33+
FullResolution = Config.Bind("General", "Increase Resolution", false,
34+
"Set the game to use the display resolution.");
2435
}
2536

2637
public override void Load()
2738
{
2839
Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), Id);
40+
ClassInjector.RegisterTypeInIl2Cpp<ResolutionManager>();
2941
Log.LogInfo("GraphicsPlus loaded!");
3042
}
3143

3244
[HarmonyPatch(typeof(AmongUsClient), nameof(AmongUsClient.Awake))]
3345
public static class FrameRatePatch
3446
{
3547
public static void Postfix()
36-
{
48+
{
3749
Instance.Log.LogInfo($"Setting target frame rate to {Instance.TargetFrameRate.Value}");
3850
Application.targetFrameRate = Instance.TargetFrameRate.Value;
3951

40-
if (!Instance.FullResolution.Value) return;
52+
if (Instance.FullResolution.Value)
53+
{
54+
_resolutionManager = Instance.AddComponent<ResolutionManager>();
55+
}
56+
}
57+
}
4158

42-
Instance.Log.LogInfo($"Setting fullscreen resolution to {Display.main.systemWidth}x{Display.main.systemHeight}");
43-
44-
Screen.autorotateToPortrait = false;
45-
Screen.autorotateToPortraitUpsideDown = false;
46-
Screen.autorotateToLandscapeLeft = false;
47-
Screen.autorotateToLandscapeRight = false;
59+
public class ResolutionManager : MonoBehaviour
60+
{
61+
public ResolutionManager(nint ptr) : base(ptr) { }
62+
63+
public ResolutionManager() : base(ClassInjector.DerivedConstructorPointer<ResolutionManager>())
64+
{
65+
ClassInjector.DerivedConstructorBody(this);
66+
}
67+
68+
private ScreenOrientation _lastOrientation = ScreenOrientation.Landscape;
4869

49-
Screen.orientation = ScreenOrientation.Portrait;
70+
public void Start()
71+
{
72+
SetNativeResolution();
73+
}
74+
75+
public void Update()
76+
{
77+
if (_lastOrientation != Screen.orientation)
78+
{
79+
SetNativeResolution();
80+
}
81+
}
5082

51-
Screen.SetResolution(
52-
Display.main.systemWidth,
53-
Display.main.systemHeight,
54-
true
55-
);
83+
public void SetNativeResolution()
84+
{
85+
ScalableBufferManager.ResizeBuffers(1f, 1f);
86+
var width = get_width();
87+
var height = get_height();
88+
if (Screen.orientation is ScreenOrientation.Landscape or ScreenOrientation.LandscapeRight)
89+
{
90+
Screen.SetResolution(width, height, FullScreenMode.FullScreenWindow);
91+
Instance.Log.LogInfo($"Set resolution to {width}x{height}");
92+
}
93+
_lastOrientation = Screen.orientation;
5694
}
5795
}
5896
}

GraphicsPlus/GraphicsPlus.csproj

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<TargetFramework>net6.0</TargetFramework>
3+
<TargetFramework>net10.0</TargetFramework>
44
<LangVersion>latest</LangVersion>
55
<DebugType>embedded</DebugType>
6+
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
67

7-
<VersionPrefix>1.0.0</VersionPrefix>
8+
<VersionPrefix>1.0.1</VersionPrefix>
89
<VersionSuffix>dev</VersionSuffix>
910
<Description>Graphics improvements for mobile devices</Description>
1011
</PropertyGroup>

0 commit comments

Comments
 (0)