Decompiled source of BetterRepo v1.0.0

ValuableTestSword.dll

Decompiled 2 months ago
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
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("SourceCodeLook")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("SourceCodeLook")]
[assembly: AssemblyCopyright("Copyright ©  2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("47f94d6c-8222-4f09-a968-d52fca6ba63d")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
public static class RepoExtensions
{
	private static FieldInfo _playerNameField;

	private static FieldInfo _grabbedPhysGrabObjectField;

	static RepoExtensions()
	{
		try
		{
			Type typeFromHandle = typeof(PlayerAvatar);
			_playerNameField = typeFromHandle.GetField("_playerName", BindingFlags.Instance | BindingFlags.NonPublic) ?? typeFromHandle.GetField("playerName", BindingFlags.Instance | BindingFlags.NonPublic) ?? typeFromHandle.GetField("m_playerName", BindingFlags.Instance | BindingFlags.NonPublic);
			if (_playerNameField == null)
			{
				Debug.LogError((object)"RepoExtensions: Couldn't find playerName field in PlayerAvatar class");
			}
			else
			{
				Debug.Log((object)("RepoExtensions: Found playerName field: " + _playerNameField.Name));
			}
		}
		catch (Exception ex)
		{
			Debug.LogError((object)("RepoExtensions: Error initializing playerName field: " + ex.Message));
		}
		try
		{
			Type typeFromHandle2 = typeof(PhysGrabber);
			_grabbedPhysGrabObjectField = typeFromHandle2.GetField("_grabbedPhysGrabObject", BindingFlags.Instance | BindingFlags.NonPublic) ?? typeFromHandle2.GetField("grabbedPhysGrabObject", BindingFlags.Instance | BindingFlags.NonPublic) ?? typeFromHandle2.GetField("m_grabbedPhysGrabObject", BindingFlags.Instance | BindingFlags.NonPublic);
			if (_grabbedPhysGrabObjectField == null)
			{
				Debug.LogError((object)"RepoExtensions: Couldn't find grabbedPhysGrabObject field in PhysGrabber class");
			}
			else
			{
				Debug.Log((object)("RepoExtensions: Found grabbedPhysGrabObject field: " + _grabbedPhysGrabObjectField.Name));
			}
		}
		catch (Exception ex2)
		{
			Debug.LogError((object)("RepoExtensions: Error initializing grabbedPhysGrabObject field: " + ex2.Message));
		}
	}

	public static string playerName(this PlayerAvatar playerAvatar)
	{
		//IL_000f: Unknown result type (might be due to invalid IL or missing references)
		//IL_001a: Expected O, but got Unknown
		if (_playerNameField != null && (Object)playerAvatar != (Object)null)
		{
			try
			{
				return (string)_playerNameField.GetValue(playerAvatar);
			}
			catch (Exception ex)
			{
				Debug.LogError((object)("RepoExtensions: Error accessing playerName: " + ex.Message));
			}
		}
		return "Unknown Player";
	}

	public static PhysGrabObject grabbedPhysGrabObject(this PhysGrabber physGrabber)
	{
		//IL_000f: Unknown result type (might be due to invalid IL or missing references)
		//IL_001a: Expected O, but got Unknown
		//IL_002e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0034: Expected O, but got Unknown
		if (_grabbedPhysGrabObjectField != null && (Object)physGrabber != (Object)null)
		{
			try
			{
				return (PhysGrabObject)_grabbedPhysGrabObjectField.GetValue(physGrabber);
			}
			catch (Exception ex)
			{
				Debug.LogError((object)("RepoExtensions: Error accessing grabbedPhysGrabObject: " + ex.Message));
			}
		}
		return null;
	}
}
public class ValuableHeal : MonoBehaviour
{
	public static ManualLogSource Log;

	private PhysGrabObject physGrabObject;

	public Sound testSound;

	private AudioSource audioSource;

	public bool playSound;

	private void Awake()
	{
		Log = Logger.CreateLogSource($"ValuableHeal_{((Object)this).GetInstanceID()}");
		Log.LogInfo((object)"ValuableTestSword Mod: Initialization complete");
	}

	private void Start()
	{
	}

	private void Update()
	{
		testSound.PlayLoop(true, 5f, 5f, 1f);
	}
}
namespace GrabSoundMod;

[BepInPlugin("yourname.grabsoundmod", "Grab Sound Mod", "1.0.0")]
public class Plugin : BaseUnityPlugin
{
	public static ManualLogSource _log;

	private static AudioClip _grabSong;

	private void Awake()
	{
		//IL_0028: Unknown result type (might be due to invalid IL or missing references)
		//IL_002e: Expected O, but got Unknown
		_log = ((BaseUnityPlugin)this).Logger;
		_log.LogInfo((object)"Grab Sound Mod is starting...");
		LoadAudioFromBundle();
		Harmony val = new Harmony("yourname.grabsoundmod");
		val.PatchAll(Assembly.GetExecutingAssembly());
		_log.LogInfo((object)"Grab Sound Mod patched successfully!");
	}

	private void LoadAudioFromBundle()
	{
		try
		{
			string text = FindBundlePath();
			if (string.IsNullOrEmpty(text))
			{
				_log.LogError((object)"Could not find testsword.repobundle file!");
				return;
			}
			_log.LogInfo((object)("Loading asset bundle from: " + text));
			AssetBundle val = AssetBundle.LoadFromFile(text);
			if ((Object)(object)val == (Object)null)
			{
				_log.LogError((object)"Failed to load asset bundle!");
				return;
			}
			string[] allAssetNames = val.GetAllAssetNames();
			_log.LogInfo((object)$"Bundle contains {allAssetNames.Length} assets:");
			string[] array = allAssetNames;
			foreach (string text2 in array)
			{
				_log.LogInfo((object)("Asset: " + text2));
			}
			AudioClip[] array2 = val.LoadAllAssets<AudioClip>();
			if (array2.Length != 0)
			{
				_grabSong = array2[0];
				_log.LogInfo((object)("Loaded clip: " + ((Object)_grabSong).name));
			}
			else
			{
				_log.LogError((object)"Failed to load any audio clips from bundle!");
			}
		}
		catch (Exception ex)
		{
			_log.LogError((object)("Error loading audio: " + ex.Message));
		}
	}

	private string FindBundlePath()
	{
		string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
		string[] array = new string[4]
		{
			Path.Combine(directoryName, "testsword.repobundle"),
			Path.Combine(Paths.PluginPath, "testsword.repobundle"),
			Path.Combine(Paths.GameRootPath, "testsword.repobundle"),
			Path.Combine(Paths.GameRootPath, "BepInEx", "plugins", "testsword.repobundle")
		};
		string[] array2 = array;
		foreach (string text in array2)
		{
			if (File.Exists(text))
			{
				return text;
			}
		}
		return null;
	}

	public static AudioClip GetGrabSong()
	{
		return _grabSong;
	}
}
public class GrabSoundComponent : MonoBehaviour
{
	private PhysGrabObject _physGrabObject;

	private Sound _sound;

	private AudioSource _audioSource;

	private bool _isPlaying = false;

	private void Awake()
	{
		//IL_005f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0069: Expected O, but got Unknown
		_physGrabObject = ((Component)this).GetComponent<PhysGrabObject>();
		_audioSource = ((Component)this).gameObject.AddComponent<AudioSource>();
		_audioSource.spatialBlend = 0f;
		_audioSource.loop = true;
		_audioSource.volume = 0.5f;
		_audioSource.clip = Plugin.GetGrabSong();
		_sound = new Sound();
		_sound.Source = _audioSource;
		_sound.Sounds = (AudioClip[])(object)new AudioClip[1] { Plugin.GetGrabSong() };
		_sound.Volume = 0.5f;
		_sound.SpatialBlend = 0f;
	}

	private void Update()
	{
		bool flag = (Object)(object)_physGrabObject != (Object)null && _physGrabObject.grabbed;
		if (flag != _isPlaying)
		{
			_isPlaying = flag;
		}
		_sound.PlayLoop(_isPlaying, 5f, 5f, 1f);
	}
}
[HarmonyPatch(typeof(PhysGrabObject), "Start")]
internal class PhysGrabObjectStartPatch
{
	[HarmonyPostfix]
	private static void Postfix(PhysGrabObject __instance)
	{
		try
		{
			if ((Object)(object)((Component)__instance).GetComponent<GrabSoundComponent>() == (Object)null)
			{
				((Component)__instance).gameObject.AddComponent<GrabSoundComponent>();
				Plugin._log.LogInfo((object)("Added GrabSoundComponent to PhysGrabObject: " + ((Object)((Component)__instance).gameObject).name));
			}
		}
		catch (Exception ex)
		{
			Plugin._log.LogError((object)("Error adding GrabSoundComponent: " + ex.Message));
		}
	}
}