Skip to content

Commit

Permalink
Merge pull request #159 from SubmergedAmongUs/unity-project
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexejhero authored Apr 19, 2024
2 parents e0c2df7 + 5ca7329 commit 975b3d9
Show file tree
Hide file tree
Showing 2,973 changed files with 452,042 additions and 50 deletions.
96 changes: 73 additions & 23 deletions Submerged/Loading/AssetLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,44 @@
using Reactor.Utilities.Extensions;
using Submerged.Resources;
using Submerged.Localization.Strings;
using Submerged.UI;
using UnityEngine;

namespace Submerged.Loading;

[RegisterInIl2Cpp]
public sealed class AssetLoader(nint ptr) : MonoBehaviour(ptr)
{
private class Result<T>
{
private T _value;
private Exception _error;

public void SetValue(T value)
{
_value = value;
_error = null;
}

public void SetError(Exception error)
{
_value = default;
_error = error;
}

public static implicit operator T(Result<T> result)
{
if (result._error != null) throw result._error;
return result._value;
}
}

private static AssetLoader _instance;

private bool _errored;
private GameObject _submerged;

public static GameObject Submerged => _instance._submerged;
public static GameObject Submerged { get; private set; }
public static GameObject Credits { get; private set; }

public static bool Errored => _instance._errored;

Expand All @@ -33,7 +58,7 @@ private void Awake()
}

[HideFromIl2Cpp]
private void Error(Exception e)
private void ShowDialogFromException(Exception e)
{
_errored = true;
Fatal(e);
Expand All @@ -43,59 +68,84 @@ private void Error(Exception e)
[HideFromIl2Cpp]
private IEnumerator Load()
{
while (!AmongUsClient.Instance)
{
yield return null;
}
while (!AmongUsClient.Instance) yield return null;

AssetBundleCreateRequest req;

try
{
req = AssetBundle.LoadFromMemoryAsync(ResourceManager.GetEmbeddedBytes("submerged"));

if (req == null) throw new NullReferenceException();
}
catch (Exception e)
{
Error(e);

ShowDialogFromException(e);
yield break;
}

while (!req.WasCollected && !req.isDone) yield return null;

AssetBundleRequest bundleReq;
AssetBundle bundle = req.assetBundle;

Result<GameObject> submerged = new();
yield return LoadAsset(bundle, "Submerged", submerged);

try
{
AssetBundle bundle = req.assetBundle;
bundleReq = bundle.LoadAssetAsync<GameObject>("Submerged.prefab");
Submerged = submerged;

if (bundleReq == null) throw new NullReferenceException();
List<InnerNetObject> nonAddrList = AmongUsClient.Instance.NonAddressableSpawnableObjects.ToList();
nonAddrList.Add(Submerged.GetComponent<ShipStatus>());
AmongUsClient.Instance.NonAddressableSpawnableObjects = nonAddrList.ToArray();
}
catch (Exception e)
{
Error(e);
ShowDialogFromException(e);
yield break;
}

Result<GameObject> credits = new();
yield return LoadAsset(bundle, "CreditsScreen", credits);

try
{
Credits = credits;
Credits.SetActive(false);
Credits.AddComponent<CreditsScreenManager>();
}
catch (Exception e)
{
ShowDialogFromException(e);
yield break;
}

while (!bundleReq.WasCollected && !bundleReq.isDone) yield return null;
LoadingManager.DoneLoading(nameof(AssetLoader));
}

[HideFromIl2Cpp]
private static IEnumerator LoadAsset<T>(AssetBundle bundle, string objectName, Result<T> result) where T : UnityObject
{
AssetBundleRequest bundleReq;

try
{
_submerged = bundleReq.asset.TryCast<GameObject>()!.DontDestroy().DontUnload();
bundleReq = bundle.LoadAssetAsync<T>(objectName);
if (bundleReq == null) throw new NullReferenceException();
}
catch (Exception e)
{
result.SetError(e);
yield break;
}

List<InnerNetObject> nonAddrList = AmongUsClient.Instance.NonAddressableSpawnableObjects.ToList();
nonAddrList.Add(Submerged.GetComponent<ShipStatus>());
AmongUsClient.Instance.NonAddressableSpawnableObjects = nonAddrList.ToArray();
while (!bundleReq.WasCollected && !bundleReq.isDone) yield return null;

LoadingManager.DoneLoading(nameof(AssetLoader));
try
{
result.SetValue(bundleReq.asset.TryCast<T>()!.DontDestroy().DontUnload());
}
catch (Exception e)
{
Error(e);
result.SetError(e);
}
}

Expand Down
Binary file removed Submerged/Resources/AssetBundles/credits
Binary file not shown.
Binary file modified Submerged/Resources/AssetBundles/submerged
Binary file not shown.
11 changes: 0 additions & 11 deletions Submerged/Resources/ResourceManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,6 @@ public static unsafe Il2CppStructArray<byte> GetEmbeddedBytes(string name)
return array;
}

public static AssetBundle GetAssetBundle(string name)
{
Il2CppStructArray<byte> buffer = GetEmbeddedBytes(name);

if (buffer == null) return null;

AssetBundle assetBundle = AssetBundle.LoadFromMemory(buffer);

return assetBundle;
}

public static Texture2D GetTexture(string name)
{
Il2CppStructArray<byte> buffer = GetEmbeddedBytes(name);
Expand Down
4 changes: 0 additions & 4 deletions Submerged/UI/CreditsScreenManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,5 @@ public void OnEnable()
textParent.Find("Technical Support").GetComponent<TextMeshPro>().text = General.Credits_TechnicalSupport;
textParent.Find("Additional Art").GetComponent<TextMeshPro>().text = General.Credits_AdditionalArt;
transform.Find("Translators/Text").GetComponent<TextMeshPro>().text = $"<u><b>{General.Credits_Translators}:</b></u> {TRANSLATORS}";

TextMeshPro devText = textParent.Find("Developers/Subtext").GetComponent<TextMeshPro>();
// TODO: Rebuild this asset
devText.text = devText.text.Replace("AlexejheroYTB", "Alexejhero").Replace("associatedlogos", "probablyadnf");
}
}
22 changes: 10 additions & 12 deletions Submerged/UI/Patches/CreditsScreenPatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Reactor.Utilities.Extensions;
using Submerged.Extensions;
using Submerged.Loading;
using Submerged.Resources;
using UnityEngine;

Expand All @@ -13,28 +14,25 @@ public static class CreditsScreenPatches
private const string MAIN_MENU_SPRITES_TEX_NAME = "MainMenuSprites";

private static Texture2D _texture;
private static CreditsScreenManager _creditsScreenManagerPrefab;
private static GameObject _creditsScreen;

private static CreditsScreenManager GetCreditsScreen()
private static GameObject GetCreditsScreen()
{
if (_creditsScreenManagerPrefab) return _creditsScreenManagerPrefab;
GameObject creditsMenuPrefab = ResourceManager.GetAssetBundle("credits").LoadAsset<GameObject>("CreditsScreen")!;
creditsMenuPrefab.DontDestroy();
creditsMenuPrefab.SetActive(false);
if (_creditsScreen) return _creditsScreen;

return _creditsScreenManagerPrefab = creditsMenuPrefab.AddComponent<CreditsScreenManager>();
_creditsScreen = UnityObject.Instantiate(AssetLoader.Credits).gameObject;
_creditsScreen.name = "SubmergedCreditsMenu";
_creditsScreen.AddComponent<CreditsScreenManager>();

return _creditsScreen;
}

// TODO: Move part of this into update
[HarmonyPatch(typeof(MainMenuManager), nameof(MainMenuManager.Awake))]
[HarmonyPatch(typeof(MainMenuManager), nameof(MainMenuManager.ActivateMainMenuUI))]
// [HarmonyPatch(typeof(MainMenuManager), nameof(MainMenuManager.ActivateMainMenuUI))]
[HarmonyPostfix]
public static void CreateCreditsButtonPatch(MainMenuManager __instance)
{
if (!_creditsScreen) _creditsScreen = UnityObject.Instantiate(GetCreditsScreen()).gameObject;
_creditsScreen.name = "SubmergedCreditsMenu";

DoNotPressButton doNotPressButton = __instance.GetComponentInChildren<DoNotPressButton>(true);

_texture ??= ResourceManager.GetTexture(MAIN_MENU_SPRITES_TEX_NAME).DontUnload();
Expand Down Expand Up @@ -80,7 +78,7 @@ public static void CreateCreditsButtonPatch(MainMenuManager __instance)
unpressedSprite.enabled = true;
});

creditsButton.OnClick.AddListener(() => { _creditsScreen.SetActive(true); });
creditsButton.OnClick.AddListener(() => { GetCreditsScreen().gameObject.SetActive(true); });

creditsButton.transform.localScale = 0.9f * Vector3.one;
}
Expand Down
76 changes: 76 additions & 0 deletions SubmergedUnity/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# This .gitignore file should be placed at the root of your Unity project directory
#
# Get latest from https://github.com/github/gitignore/blob/main/Unity.gitignore
#
/[Ll]ibrary/
/[Tt]emp/
/[Oo]bj/
/[Bb]uild/
/[Bb]uilds/
/[Ll]ogs/
/[Uu]ser[Ss]ettings/

# MemoryCaptures can get excessive in size.
# They also could contain extremely sensitive data
/[Mm]emoryCaptures/

# Recordings can get excessive in size
/[Rr]ecordings/

# Uncomment this line if you wish to ignore the asset store tools plugin
# /[Aa]ssets/AssetStoreTools*

# Autogenerated Jetbrains Rider plugin
/[Aa]ssets/Plugins/Editor/JetBrains*

# Visual Studio cache directory
.vs/

# Gradle cache directory
.gradle/

# Autogenerated VS/MD/Consulo solution and project files
ExportedObj/
.consulo/
*.csproj
*.unityproj
*.sln
*.suo
*.tmp
*.user
*.userprefs
*.pidb
*.booproj
*.svd
*.pdb
*.mdb
*.opendb
*.VC.db

# Unity3D generated meta files
*.pidb.meta
*.pdb.meta
*.mdb.meta

# Unity3D generated file on crash reports
sysinfo.txt

# Builds
*.apk
*.aab
*.unitypackage
*.app

# Crashlytics generated file
crashlytics-build.properties

# Packed Addressables
/[Aa]ssets/[Aa]ddressable[Aa]ssets[Dd]ata/*/*.bin*

# Temporary auto-generated Android Assets
/[Aa]ssets/[Ss]treamingAssets/aa.meta
/[Aa]ssets/[Ss]treamingAssets/aa/*

# User-ignored files
.idea
.vsconfig
6 changes: 6 additions & 0 deletions SubmergedUnity/Assembly-CSharp.csproj.DotSettings
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=assets_005Cbasegame/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=assets_005Cbasegame_005Cenums/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=assets_005Cbasegame_005Cscripts/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=assets_005Cbasegame_005Cscripts_005C_005Fused/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=assets_005Cbasegame_005Cscripts_005C_005Fused_005C_005Fref/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
8 changes: 8 additions & 0 deletions SubmergedUnity/Assets/Among Us.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions SubmergedUnity/Assets/Among Us/Enums.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 44 additions & 0 deletions SubmergedUnity/Assets/Among Us/Enums/ImageNames.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
public enum ImageNames
{
SubmergedAdminButton = 0x80,

// ReSharper disable InconsistentNaming
LocalButton = 0,
OnlineButton,
HowToPlayButton,
FreeplayButton,
HostHeader,
PublicHeader,
PrivateHeader,
KillButton,
ReportButton,
UseButton,
SabotageButton,
CamsButton,
AdminMapButton,
MIRAAdminButton,
PolusAdminButton,
DoorLogsButton,
VentButton,
VitalsButton,
StartButton,
PublicButton,
PrivateButton,
PlayAgainButton,
ExitRoomButton,
OptionsButton,
DiscussHeader,
ShhhHeader,
IVotedBadge,
SkipVoteButton,
MiraTaskBeginButton,
SkippedVoteTallyHeader,
ShopSkinsBanner,
ShopHatsBanner,
ShopPetsBanner,
EmergencyMeetingText,
AnnouncementsText,
DeadBodyReportedText,
ProceedButton,
AirshipAdminButton = 39,
}
11 changes: 11 additions & 0 deletions SubmergedUnity/Assets/Among Us/Enums/ImageNames.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 975b3d9

Please sign in to comment.