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.Security;
using System.Security.Permissions;
using BepInEx;
using HarmonyLib;
using Mono.Cecil.Cil;
using MonoMod.Cil;
using StrongerHitFeedback;
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("StrongerHitFeedback")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("StrongerHitFeedback")]
[assembly: AssemblyCopyright("Copyright © 2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("17665fc7-b7f3-448d-b85b-22506f488236")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
public class AudioResourceLoader
{
public static void loadFromFolder(string modName)
{
ResourceLoaderSoundbanks resourceLoaderSoundbanks = new ResourceLoaderSoundbanks();
resourceLoaderSoundbanks.AutoloadFromPath(ETGMod.FolderPath((BaseUnityPlugin)(object)HitFeedbackModule.instance), modName);
}
}
public class ResourceLoaderSoundbanks
{
public void AutoloadFromPath(string path, string prefix)
{
if (string.IsNullOrEmpty(path))
{
throw new ArgumentNullException("path", "Path cannot be null.");
}
if (string.IsNullOrEmpty(prefix))
{
throw new ArgumentNullException("prefix", "Prefix name cannot be null.");
}
prefix = prefix.Trim();
if (string.IsNullOrEmpty(prefix))
{
throw new ArgumentException("Prefix name cannot be an empty (or whitespace only) string.", "prefix");
}
path = path.Replace('/', Path.DirectorySeparatorChar);
path = path.Replace('\\', Path.DirectorySeparatorChar);
if (!Directory.Exists(path))
{
Debug.LogError((object)$"{typeof(ResourceLoaderSoundbanks)}: No autoload directory in path, not autoloading anything. Path='{path}'.");
return;
}
List<string> list = new List<string>(Directory.GetFiles(path, "*.bnk", SearchOption.AllDirectories));
for (int i = 0; i < list.Count; i++)
{
string text = list[i];
string text2 = text;
text2 = text2.Replace('/', Path.DirectorySeparatorChar);
text2 = text2.Replace('\\', Path.DirectorySeparatorChar);
text2 = text2.Substring(text2.IndexOf(path) + path.Length);
text2 = text2.Substring(0, text2.Length - ".bnk".Length);
if (text2.IndexOf(Path.DirectorySeparatorChar) == 0)
{
text2 = text2.Substring(1);
}
text2 = prefix + ":" + text2;
Debug.Log((object)$"{typeof(ResourceLoaderSoundbanks)}: Soundbank found, attempting to autoload: name='{text2}' file='{text}'");
using FileStream stream = File.OpenRead(text);
LoadSoundbankFromStream(stream, text2);
}
}
private void LoadSoundbankFromStream(Stream stream, string name)
{
//IL_0027: 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_0032: Unknown result type (might be due to invalid IL or missing references)
byte[] array = StreamToByteArray(stream);
IntPtr intPtr = Marshal.AllocHGlobal(array.Length);
try
{
Marshal.Copy(array, 0, intPtr, array.Length);
uint num = default(uint);
AKRESULT val = AkSoundEngine.LoadAndDecodeBankFromMemory(intPtr, (uint)array.Length, false, name, false, ref num);
Debug.Log((object)$"Result of soundbank load: {val}.");
}
finally
{
Marshal.FreeHGlobal(intPtr);
}
}
public static byte[] StreamToByteArray(Stream input)
{
byte[] array = new byte[16384];
using MemoryStream memoryStream = new MemoryStream();
int count;
while ((count = input.Read(array, 0, array.Length)) > 0)
{
memoryStream.Write(array, 0, count);
}
return memoryStream.ToArray();
}
}
namespace StrongerHitFeedback;
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInPlugin("kleirof.etg.strongerhitfeedback", "Stronger Hit Feedback", "1.1.2")]
public class HitFeedbackModule : BaseUnityPlugin
{
public const string GUID = "kleirof.etg.strongerhitfeedback";
public const string NAME = "Stronger Hit Feedback";
public const string VERSION = "1.1.2";
public const string TEXT_COLOR = "#92A1E6";
public static HitFeedbackModule instance;
public void Start()
{
instance = this;
ETGModMainBehaviour.WaitForGameManagerStart((Action<GameManager>)GMStart);
}
public void GMStart(GameManager g)
{
//IL_0021: Unknown result type (might be due to invalid IL or missing references)
//IL_0027: Expected O, but got Unknown
Log("Stronger Hit Feedback v1.1.2 started successfully.", "#92A1E6");
AudioResourceLoader.loadFromFolder("Stronger Hit Feedback");
Harmony val = new Harmony("kleirof.etg.strongerhitfeedback");
val.PatchAll();
}
public static void Log(string text, string color = "FFFFFF")
{
ETGModConsole.Log((object)("<color=" + color + ">" + text + "</color>"), false);
}
}
public static class HitFeedbackPatches
{
[HarmonyPatch(typeof(Projectile), "HandleKnockback")]
public class HandleKnockbackPatchClass
{
[HarmonyILManipulator]
public static void HandleKnockbackPatch(ILContext ctx)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_0008: Expected O, but got Unknown
ILCursor val = new ILCursor(ctx);
if (val.TryGotoNext((MoveType)2, new Func<Instruction, bool>[1]
{
(Instruction x) => ILPatternMatchingExt.MatchMul(x)
}))
{
val.EmitCall<HandleKnockbackPatchClass>("HandleKnockbackPatchCall");
}
}
private static float HandleKnockbackPatchCall(float orig)
{
return orig * 2f;
}
}
[HarmonyPatch(/*Could not decode attribute arguments.*/)]
public class FlashOnHitPatchClass
{
[HarmonyILManipulator]
public static void FlashOnHitPatch(ILContext ctx)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_0008: Expected O, but got Unknown
//IL_0052: Unknown result type (might be due to invalid IL or missing references)
ILCursor val = new ILCursor(ctx);
if (val.TryGotoNext((MoveType)0, new Func<Instruction, bool>[1]
{
(Instruction x) => ILPatternMatchingExt.MatchLdstr(x, "Play_ENM_hurt")
}))
{
FieldInfo fieldInfo = AccessTools.Field(Type.GetType("HealthHaver+<FlashOnHit>c__Iterator0, Assembly-CSharp"), "$this");
val.Emit(OpCodes.Ldarg_0);
val.EmitCall<FlashOnHitPatchClass>("FlashOnHitPatchCall_1");
}
val.Index = 0;
for (int i = 0; i < 2; i++)
{
if (val.TryGotoNext((MoveType)2, new Func<Instruction, bool>[1]
{
(Instruction x) => ILPatternMatchingExt.MatchLdcR4(x, 0.04f)
}))
{
val.EmitCall<FlashOnHitPatchClass>("FlashOnHitPatchCall_2");
}
}
val.Index = 0;
if (val.TryGotoNext((MoveType)2, new Func<Instruction, bool>[1]
{
(Instruction x) => ILPatternMatchingExt.MatchLdcR4(x, 0.2f)
}))
{
val.EmitCall<FlashOnHitPatchClass>("FlashOnHitPatchCall_3");
}
}
private static void FlashOnHitPatchCall_1(object selfObject)
{
HealthHaver fieldInEnumerator = GetFieldInEnumerator<HealthHaver>(selfObject, "this");
Random random = new Random();
int num = random.Next(1, 7);
AkSoundEngine.PostEvent($"Play_hit_{num}", ((Component)fieldInEnumerator).gameObject);
}
private static float FlashOnHitPatchCall_2(float orig)
{
return orig * 9f;
}
private static float FlashOnHitPatchCall_3(float orig)
{
return 0f;
}
}
[HarmonyPatch(typeof(HealthHaver), "ApplyDamageDirectional")]
public class ApplyDamageDirectionalPatchClass
{
[HarmonyILManipulator]
public static void ApplyDamageDirectionalPatch(ILContext ctx)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_0008: Expected O, but got Unknown
//IL_003d: Unknown result type (might be due to invalid IL or missing references)
ILCursor val = new ILCursor(ctx);
if (val.TryGotoNext((MoveType)0, new Func<Instruction, bool>[1]
{
(Instruction x) => ILPatternMatchingExt.MatchLdstr(x, "Play_ENM_death")
}))
{
val.Emit(OpCodes.Ldarg_0);
val.EmitCall<ApplyDamageDirectionalPatchClass>("ApplyDamageDirectionalPatchCall");
}
}
private static void ApplyDamageDirectionalPatchCall(HealthHaver self)
{
Random random = new Random();
int num = random.Next(1, 5);
AkSoundEngine.PostEvent($"Play_killed_{num}", ((Component)self).gameObject);
}
}
public static void EmitCall<T>(this ILCursor iLCursor, string methodName, Type[] parameters = null, Type[] generics = null)
{
//IL_0015: Unknown result type (might be due to invalid IL or missing references)
MethodInfo methodInfo = AccessTools.Method(typeof(T), methodName, parameters, generics);
iLCursor.Emit(OpCodes.Call, (MethodBase)methodInfo);
}
public static T GetFieldInEnumerator<T>(object instance, string fieldNamePattern)
{
return (T)instance.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic).FirstOrDefault((FieldInfo f) => f.Name.Contains("$" + fieldNamePattern) || f.Name.Contains("<" + fieldNamePattern + ">"))
.GetValue(instance);
}
}