using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BoneLib;
using BoneLib.BoneMenu;
using BoneLib.Notifications;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppSLZ.Marrow;
using ImageBoardSaver;
using MelonLoader;
using MelonLoader.Utils;
using Microsoft.CodeAnalysis;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: MelonInfo(typeof(Core), "ImageBoardSaver", "1.0.0", "Rexmeck", null)]
[assembly: MelonGame("Stress Level Zero", "BONELAB")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("ImageBoardSaver")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("ImageBoardSaver")]
[assembly: AssemblyTitle("ImageBoardSaver")]
[assembly: NeutralResourcesLanguage("en-US")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
internal sealed class RefSafetyRulesAttribute : Attribute
{
public readonly int Version;
public RefSafetyRulesAttribute(int P_0)
{
Version = P_0;
}
}
}
namespace ImageBoardSaver
{
public class Core : MelonMod
{
public override void OnInitializeMelon()
{
Directory.CreateDirectory(Utils.SavePath());
InitializeBoneMenu();
((MelonBase)this).LoggerInstance.Msg("Initialized.");
}
public void InitializeBoneMenu()
{
//IL_000a: Unknown result type (might be due to invalid IL or missing references)
//IL_001b: Unknown result type (might be due to invalid IL or missing references)
Page.Root.CreatePage("ImageBoard Saver", Color.cyan, 0, true).CreateFunction("Save Image from grabbed boards", Color.yellow, (Action)SaveGrabbed);
}
public static void SaveGrabbed()
{
if (!((Object)(object)Player.PhysicsRig == (Object)null))
{
Hand leftHand = Player.PhysicsRig.leftHand;
Hand rightHand = Player.PhysicsRig.rightHand;
SaveGrabbed(leftHand);
SaveGrabbed(rightHand);
}
}
public static void SaveGrabbed(Hand hand)
{
if ((Object)(object)hand.AttachedReceiver == (Object)null)
{
return;
}
InteractableHost componentInParent = ((Component)((Il2CppObjectBase)hand.AttachedReceiver).Cast<Grip>()).gameObject.GetComponentInParent<InteractableHost>(true);
if (!((Object)(object)componentInParent != (Object)null))
{
return;
}
Transform transform = ((Component)componentInParent).transform;
if ((Object)(object)transform.Find("IS_IMAGEBOARD") != (Object)null)
{
Transform val = transform.Find("UltEvents/dataholders");
if ((Object)(object)val != (Object)null && (Object)(object)val.GetChild(0) != (Object)null)
{
Utils.SaveImageData(((Object)((Component)val.GetChild(0)).gameObject).name);
}
}
}
}
public static class Utils
{
private static Dictionary<string, byte[]> imageHeaders = new Dictionary<string, byte[]>
{
{
"jpg",
new byte[2] { 255, 216 }
},
{
"bmp",
new byte[2] { 66, 77 }
},
{
"png",
new byte[8] { 137, 80, 78, 71, 13, 10, 26, 10 }
},
{
"gif",
new byte[3] { 71, 73, 70 }
}
};
public static string SanitizeFileName(string name)
{
return name.Replace("/", "_").Replace(":", "_").Replace(" ", "_");
}
public static string DetermineExtensionFromData(byte[] data)
{
foreach (KeyValuePair<string, byte[]> imageHeader in imageHeaders)
{
bool flag = true;
string key = imageHeader.Key;
byte[] value = imageHeader.Value;
if (value.Length > data.Length)
{
continue;
}
for (int i = 0; i < value.Length; i++)
{
if (data[i] != value[i])
{
flag = false;
break;
}
}
if (flag)
{
return key;
}
}
return null;
}
public static string SavePath()
{
return Path.Combine(MelonEnvironment.UserDataDirectory, "ImageBoard");
}
public static void SaveImageData(string base64)
{
//IL_0021: Unknown result type (might be due to invalid IL or missing references)
//IL_0026: Unknown result type (might be due to invalid IL or missing references)
//IL_002c: Unknown result type (might be due to invalid IL or missing references)
//IL_0031: Unknown result type (might be due to invalid IL or missing references)
//IL_0036: Unknown result type (might be due to invalid IL or missing references)
//IL_0038: Unknown result type (might be due to invalid IL or missing references)
//IL_003d: Unknown result type (might be due to invalid IL or missing references)
//IL_0048: Unknown result type (might be due to invalid IL or missing references)
//IL_004e: Unknown result type (might be due to invalid IL or missing references)
//IL_0053: Unknown result type (might be due to invalid IL or missing references)
//IL_005d: Expected O, but got Unknown
//IL_010b: Unknown result type (might be due to invalid IL or missing references)
//IL_0110: Unknown result type (might be due to invalid IL or missing references)
//IL_0116: Unknown result type (might be due to invalid IL or missing references)
//IL_011b: Unknown result type (might be due to invalid IL or missing references)
//IL_0120: Unknown result type (might be due to invalid IL or missing references)
//IL_0122: Unknown result type (might be due to invalid IL or missing references)
//IL_0127: Unknown result type (might be due to invalid IL or missing references)
//IL_0132: Unknown result type (might be due to invalid IL or missing references)
//IL_013e: Unknown result type (might be due to invalid IL or missing references)
//IL_0143: Unknown result type (might be due to invalid IL or missing references)
//IL_014d: Expected O, but got Unknown
byte[] array = Convert.FromBase64String(base64);
if (array == null)
{
return;
}
string text = DetermineExtensionFromData(array);
if (text == null)
{
MelonLogger.Error("Could not determine extension from data!");
Notifier.Send(new Notification
{
Title = NotificationText.op_Implicit("ImageBoard Saver"),
Type = (NotificationType)2,
PopupLength = 1f,
Message = NotificationText.op_Implicit("Could not determine extension from data!")
});
return;
}
string text2 = SavePath();
Directory.CreateDirectory(text2);
string text3 = Path.Combine(text2, "image_" + SanitizeFileName(DateTime.Now.ToString()) + ".");
string text4 = "";
int num = 1;
while (File.Exists(text3 + text4 + text))
{
text4 = $" ({num})";
num++;
}
text3 += text4;
text3 += text;
File.WriteAllBytes(text3, array);
MelonLogger.Msg("Screenshot saved in " + text3);
Notifier.Send(new Notification
{
Title = NotificationText.op_Implicit("ImageBoard Saver"),
Type = (NotificationType)0,
PopupLength = 1f,
Message = NotificationText.op_Implicit("Screenshot saved in " + text3)
});
}
}
}