using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Reptile;
using Reptile.Phone;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("CustomAppAPI")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("CustomAppAPI")]
[assembly: AssemblyCopyright("Copyright © tari.dance 2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("5d9dcfc8-fa5e-4966-95a9-d381ec43884b")]
[assembly: AssemblyFileVersion("1.0.1")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.1.0")]
namespace CustomAppAPI
{
public abstract class CustomApp : App
{
public string Name => CustomAppMod.GetAppKey(((object)this).GetType());
public abstract string DisplayName { get; }
public abstract Texture2D Icon { get; }
public override void Awake()
{
base.m_Unlockables = Array.Empty<AUnlockable>();
((App)this).Awake();
}
public static Texture2D LoadTexture(string filePath)
{
//IL_008d: Unknown result type (might be due to invalid IL or missing references)
//IL_0093: Expected O, but got Unknown
if (!File.Exists(filePath))
{
CustomAppMod.Log.LogError((object)("Texture doesn't exist at path: " + filePath));
return null;
}
string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(filePath);
string extension = Path.GetExtension(filePath);
if (extension != ".jpg" && extension != ".jpeg" && extension != ".png")
{
CustomAppMod.Log.LogWarning((object)("Cannot load texture: " + fileNameWithoutExtension + extension + ". Only .png and .jpg files are accepted."));
return null;
}
Texture2D val = new Texture2D(2, 2);
if (ImageConversion.LoadImage(val, File.ReadAllBytes(filePath)))
{
val.Apply();
return val;
}
CustomAppMod.Log.LogWarning((object)("Could not load image data of " + fileNameWithoutExtension + extension + "."));
return null;
}
public void SetNotification(Notification notification)
{
base.m_Notification = notification;
base.m_Notification.InitNotification((App)(object)this);
}
}
internal static class CustomAppCache
{
private static List<Type> _customAppTypes = new List<Type>();
private static List<CustomApp> _customApps = new List<CustomApp>();
public static List<Type> CustomAppTypes => _customAppTypes;
public static List<CustomApp> CustomApps => _customApps;
public static void AddType(Type type)
{
if (!_customAppTypes.Contains(type))
{
_customAppTypes.Add(type);
}
}
public static void AddApp(CustomApp customApp)
{
if (!_customApps.Contains(customApp))
{
_customApps.Add(customApp);
}
}
public static void ResetApps()
{
_customApps.Clear();
}
}
[BepInPlugin("dance.tari.bombrushcyberfunk.customappapi", "CustomAppAPI", "1.0.1")]
[BepInProcess("Bomb Rush Cyberfunk.exe")]
internal class CustomAppMod : BaseUnityPlugin
{
private static Harmony _harmonyInstance;
private static CustomAppMod _modInstance;
private static Assembly _modAssembly;
public static CustomAppMod Instance => _modInstance;
public static Assembly ModAssembly => _modAssembly;
public static ManualLogSource Log => ((BaseUnityPlugin)_modInstance).Logger;
private void Awake()
{
//IL_0016: Unknown result type (might be due to invalid IL or missing references)
//IL_0020: Expected O, but got Unknown
_modInstance = this;
_modAssembly = Assembly.GetExecutingAssembly();
_harmonyInstance = new Harmony("dance.tari.bombrushcyberfunk.customappapi.patch");
_harmonyInstance.PatchAll();
((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin CustomAppAPI patched successfully.");
}
private void Start()
{
Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
Assembly[] array = assemblies;
foreach (Assembly assembly in array)
{
Initialize(assembly);
}
}
public static void Initialize(Assembly assembly)
{
Type[] array = FindDerivedTypes(assembly, typeof(CustomApp)).ToArray();
if (array.Length != 0)
{
Type[] array2 = array;
foreach (Type type in array2)
{
CustomAppCache.AddType(type);
Log.LogInfo((object)("Loaded new custom app: " + GetAppKey(type)));
}
}
}
public static void InitializeApps(Phone phone)
{
//IL_0038: Unknown result type (might be due to invalid IL or missing references)
//IL_003e: Expected O, but got Unknown
//IL_0069: Unknown result type (might be due to invalid IL or missing references)
//IL_0081: Unknown result type (might be due to invalid IL or missing references)
//IL_0088: Expected O, but got Unknown
//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
CustomAppCache.ResetApps();
Transform val = ((Component)phone).transform.Find("OpenCanvas/PhoneContainerOpen/MainScreen/Apps");
foreach (Type customAppType in CustomAppCache.CustomAppTypes)
{
GameObject val2 = new GameObject(GetAppKey(customAppType));
val2.layer = 24;
CustomApp customApp = (CustomApp)(object)val2.AddComponent(customAppType);
val2.transform.SetParent(val, false);
val2.transform.localScale = Vector3.one;
val2.SetActive(true);
GameObject val3 = new GameObject("Content");
val3.layer = 24;
RectTransform val4 = val3.AddComponent<RectTransform>();
val4.sizeDelta = new Vector2(1070f, 1775f);
val3.transform.SetParent(val2.transform, false);
val3.transform.localScale = Vector3.one;
val3.SetActive(true);
Notification emailNotification = GetEmailNotification(phone);
GameObject val5 = Object.Instantiate<GameObject>(((Component)emailNotification).gameObject, val2.transform);
Notification component = val5.GetComponent<Notification>();
customApp.SetNotification(component);
CustomAppCache.AddApp(customApp);
}
}
private static Notification GetEmailNotification(Phone phone)
{
AppEmail appInstance = phone.GetAppInstance<AppEmail>();
if ((Object)(object)appInstance == (Object)null)
{
return null;
}
Notification component = ((Component)appInstance).GetComponent<Notification>();
if ((Object)(object)component == (Object)null)
{
return null;
}
return component;
}
private static IEnumerable<Type> FindDerivedTypes(Assembly assembly, Type baseType)
{
return from t in assembly.GetTypes()
where baseType.IsAssignableFrom(t) && t != baseType
select t;
}
public static string GetAppKey(Type type)
{
return type.Name ?? "";
}
}
internal static class PluginMetadata
{
public const string GUID = "dance.tari.bombrushcyberfunk.customappapi";
public const string Name = "CustomAppAPI";
public const string Version = "1.0.1";
}
}
namespace CustomAppAPI.Patches
{
[HarmonyPatch(typeof(AppHomeScreen))]
internal class AppHomeScreenPatch
{
[HarmonyPrefix]
[HarmonyPatch("OnAppInit")]
public static void OnAppInit(AppHomeScreen __instance)
{
//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
//IL_00ef: Expected I4, but got Unknown
//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
//IL_0138: Unknown result type (might be due to invalid IL or missing references)
//IL_0144: Unknown result type (might be due to invalid IL or missing references)
//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
Traverse val = Traverse.Create((object)__instance);
Traverse<HomeScreenApp[]> val2 = val.Field<HomeScreenApp[]>("m_Apps");
Traverse<HomeScreenApp[]> val3 = val.Field<HomeScreenApp[]>("availableHomeScreenApps");
Phone value = val.Property<Phone>("MyPhone", (object[])null).Value;
CustomAppMod.InitializeApps(value);
Traverse val4 = Traverse.Create((object)value);
AudioManager value2 = val4.Field<AudioManager>("audioManager").Value;
List<CustomApp> customApps = CustomAppCache.CustomApps;
foreach (CustomApp item in customApps)
{
value.AppInstances.Add(item.Name, (App)(object)item);
((App)item).Init(value, value2);
((Component)item).gameObject.SetActive(false);
}
List<HomeScreenApp> list = val2.Value.ToList();
List<HomeScreenApp> list2 = val3.Value.ToList();
int num = (int)Enum.GetValues(typeof(HomeScreenAppType)).Cast<HomeScreenAppType>().Max();
Rect val5 = default(Rect);
for (int i = 0; i < customApps.Count; i++)
{
HomeScreenAppType value3 = (HomeScreenAppType)(num + (i + 1));
CustomApp customApp = customApps[i];
Texture2D icon = customApp.Icon;
((Rect)(ref val5))..ctor(0f, 0f, (float)((Texture)icon).width, (float)((Texture)icon).height);
Sprite value4 = Sprite.Create(icon, val5, new Vector2(0.5f, 0.5f), 100f);
HomeScreenApp val6 = ScriptableObject.CreateInstance<HomeScreenApp>();
Traverse val7 = Traverse.Create((object)val6);
val7.Field<string>("m_AppName").Value = customApp.Name;
val7.Field<string>("m_DisplayName").Value = customApp.DisplayName;
val7.Field<Sprite>("m_AppIcon").Value = value4;
val7.Field<HomeScreenAppType>("appType").Value = value3;
list.Add(val6);
list2.Add(val6);
}
val2.Value = list.ToArray();
val3.Value = list2.ToArray();
}
}
[HarmonyPatch(typeof(Type))]
internal class AppTypePatch
{
[HarmonyPostfix]
[HarmonyPatch("GetType", new Type[] { typeof(string) })]
public static void GetType(string typeName, ref Type __result)
{
foreach (Type customAppType in CustomAppCache.CustomAppTypes)
{
if (typeName == "Reptile.Phone." + CustomAppMod.GetAppKey(customAppType))
{
__result = customAppType;
break;
}
}
}
}
}