using System;
using System.Collections;
using System.Collections.Generic;
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.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using UnityEngine;
using UnityEngine.SceneManagement;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("FirstValheimMod")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("FirstValheimMod")]
[assembly: AssemblyCopyright("Copyright © 2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("489b05db-7afd-43d9-9c7f-b6663f92dbcb")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace FirstValheimMod;
public class AssetLoader
{
private AssetBundle bundle;
public void InitAssetBundle(string assetBundleName)
{
string text = Path.Combine(Path.Combine(Paths.PluginPath, "LrsGroup-ValheimDRG"), assetBundleName);
bundle = AssetBundle.LoadFromFile(text);
if ((Object)(object)bundle == (Object)null)
{
MyLogger.Error("Failed to load AssetBundle!");
}
}
public GameObject LoadAsset(string assetName)
{
GameObject obj = bundle.LoadAsset<GameObject>(assetName);
if ((Object)(object)obj == (Object)null)
{
MyLogger.Error("Could not load prefab from AssetBundle!");
}
return obj;
}
}
public class Flashlight : MonoBehaviour
{
private AssetLoader loader;
private GameObject FlareAsset;
private List<PooledFlare> pool = new List<PooledFlare>();
private int poolSize = 20;
private int currentIndex;
public void Awake()
{
loader = new AssetLoader();
loader.InitAssetBundle("valheimdrg");
FlareAsset = loader.LoadAsset("Flare");
}
public void SpawnFlare(Vector3 spawnPosition, Vector3 direction, float force = 15f)
{
//IL_0095: Unknown result type (might be due to invalid IL or missing references)
//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
//IL_0070: Unknown result type (might be due to invalid IL or missing references)
//IL_0080: Unknown result type (might be due to invalid IL or missing references)
if (pool.Count == 0)
{
MyLogger.Error("Pool is null!");
return;
}
PooledFlare pooledFlare = pool[currentIndex];
if ((Object)(object)pooledFlare.GO == (Object)null)
{
MyLogger.Error("Pooled flare or its GameObject is null!");
return;
}
if (pooledFlare.GO.activeSelf)
{
pooledFlare.GO.SetActive(false);
if ((Object)(object)pooledFlare.Rigidbody != (Object)null)
{
pooledFlare.Rigidbody.velocity = Vector3.zero;
pooledFlare.Rigidbody.angularVelocity = Vector3.zero;
}
}
pooledFlare.GO.transform.position = spawnPosition;
pooledFlare.GO.transform.rotation = Quaternion.LookRotation(((Vector3)(ref direction)).normalized);
pooledFlare.GO.SetActive(true);
((MonoBehaviour)this).StartCoroutine(pooledFlare.Disable());
if ((Object)(object)pooledFlare.Rigidbody != (Object)null)
{
pooledFlare.Rigidbody.AddForce(((Vector3)(ref direction)).normalized * force, (ForceMode)1);
}
currentIndex = (currentIndex + 1) % pool.Count;
}
public void InstantiateFlares(float flareStenght, string flareColor, float flareRange, float flareTimeToDisable)
{
//IL_010d: Unknown result type (might be due to invalid IL or missing references)
//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
MyLogger.Warn($"Flare Info \n Flare Strenght{flareStenght} Flare Color{flareColor} Flare Range{flareRange} Flare Time To Disable{flareTimeToDisable}");
Color color = default(Color);
for (int i = 0; i < poolSize; i++)
{
GameObject val = Object.Instantiate<GameObject>(FlareAsset, ((Component)this).transform);
if ((Object)(object)val == (Object)null)
{
MyLogger.Error("Failed to instantiate flare GameObject!");
continue;
}
PooledFlare pooledFlare = new PooledFlare(val, flareTimeToDisable);
if ((Object)(object)pooledFlare.GO == (Object)null)
{
MyLogger.Warn("Instantiated Flare does not have a GmaObject");
}
if (!ColorUtility.TryParseHtmlString(flareColor, ref color))
{
MyLogger.Warn("Invalid flare color: " + flareColor);
break;
}
Renderer component = pooledFlare.GO.GetComponent<Renderer>();
if ((Object)(object)component != (Object)null && component.materials.Length > 1)
{
Material[] materials = component.materials;
materials[1].color = color;
component.materials = materials;
}
if ((Object)(object)pooledFlare.Light != (Object)null)
{
pooledFlare.Light.intensity = flareStenght;
pooledFlare.Light.range = flareRange;
pooledFlare.Light.color = color;
}
MyLogger.Warn("Added a polledFlare to pool");
pool.Add(pooledFlare);
}
}
}
public class PooledFlare
{
[CompilerGenerated]
private sealed class <Disable>d__5 : IEnumerator<object>, IDisposable, IEnumerator
{
private int <>1__state;
private object <>2__current;
public PooledFlare <>4__this;
object IEnumerator<object>.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
object IEnumerator.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
[DebuggerHidden]
public <Disable>d__5(int <>1__state)
{
this.<>1__state = <>1__state;
}
[DebuggerHidden]
void IDisposable.Dispose()
{
<>1__state = -2;
}
private bool MoveNext()
{
//IL_0025: Unknown result type (might be due to invalid IL or missing references)
//IL_002f: Expected O, but got Unknown
int num = <>1__state;
PooledFlare pooledFlare = <>4__this;
switch (num)
{
default:
return false;
case 0:
<>1__state = -1;
<>2__current = (object)new WaitForSeconds(pooledFlare.time);
<>1__state = 1;
return true;
case 1:
<>1__state = -1;
pooledFlare.GO.SetActive(false);
return false;
}
}
bool IEnumerator.MoveNext()
{
//ILSpy generated this explicit interface implementation from .override directive in MoveNext
return this.MoveNext();
}
[DebuggerHidden]
void IEnumerator.Reset()
{
throw new NotSupportedException();
}
}
public GameObject GO;
public Rigidbody Rigidbody;
public Light Light;
public float time;
public PooledFlare(GameObject go, float timeToDisable)
{
GO = go;
Rigidbody = go.GetComponent<Rigidbody>();
Light = go.GetComponentInChildren<Light>();
time = timeToDisable;
GO.SetActive(false);
}
[IteratorStateMachine(typeof(<Disable>d__5))]
public IEnumerator Disable()
{
//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
return new <Disable>d__5(0)
{
<>4__this = this
};
}
}
public static class MyLogger
{
public static ManualLogSource Logger { get; private set; }
public static void Init(string name)
{
Logger = Logger.CreateLogSource(name);
}
public static void Info(string msg)
{
ManualLogSource logger = Logger;
if (logger != null)
{
logger.LogInfo((object)msg);
}
}
public static void Warn(string msg)
{
ManualLogSource logger = Logger;
if (logger != null)
{
logger.LogWarning((object)msg);
}
}
public static void Error(string msg)
{
ManualLogSource logger = Logger;
if (logger != null)
{
logger.LogError((object)msg);
}
}
}
[BepInPlugin("com.lorendos", "DRGFlashlight", "0.0.1")]
public class Main : BaseUnityPlugin
{
private const string pluginGUID = "com.lorendos";
private const string pluginName = "DRGFlashlight";
private const string pluginVersion = "0.0.1";
public static ConfigEntry<KeyboardShortcut> FlareLightTrow;
public static ConfigEntry<string> FlareLightColor;
public static ConfigEntry<float> FlareLightStrenght;
public static ConfigEntry<float> FlareLightRange;
public static ConfigEntry<float> FlareLightTimeToDisable;
private readonly Harmony HarmonyInstance = new Harmony("com.lorendos");
private GameObject flashlightGO;
private Flashlight flashlight;
public void Awake()
{
InitConfigs();
MyLogger.Init("DRGFlashlight");
MyLogger.Info("DRGFlashlight plugin loaded");
SceneManager.sceneLoaded += OnSceneLoaded;
HarmonyInstance.PatchAll(Assembly.GetExecutingAssembly());
}
private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
{
//IL_0023: Unknown result type (might be due to invalid IL or missing references)
//IL_002d: Expected O, but got Unknown
//IL_0033: Unknown result type (might be due to invalid IL or missing references)
if (((Scene)(ref scene)).name == "main")
{
MyLogger.Warn("World scene loaded, creating FlashlightHandler...");
flashlightGO = new GameObject("Flashlight Handler");
SceneManager.MoveGameObjectToScene(flashlightGO, scene);
flashlight = flashlightGO.AddComponent<Flashlight>();
flashlight.InstantiateFlares(FlareLightStrenght.Value, FlareLightColor.Value, FlareLightRange.Value, FlareLightTimeToDisable.Value);
}
}
public void Update()
{
//IL_0026: Unknown result type (might be due to invalid IL or missing references)
//IL_002b: Unknown result type (might be due to invalid IL or missing references)
//IL_002e: Unknown result type (might be due to invalid IL or missing references)
//IL_0054: Unknown result type (might be due to invalid IL or missing references)
//IL_005e: Unknown result type (might be due to invalid IL or missing references)
//IL_0063: Unknown result type (might be due to invalid IL or missing references)
//IL_0068: Unknown result type (might be due to invalid IL or missing references)
//IL_0077: Unknown result type (might be due to invalid IL or missing references)
if (!((Object)(object)Player.m_localPlayer == (Object)null) && !((Object)(object)flashlight == (Object)null))
{
IInputSystem current = UnityInput.Current;
KeyboardShortcut value = FlareLightTrow.Value;
if (current.GetKeyDown(((KeyboardShortcut)(ref value)).MainKey))
{
MyLogger.Info("Flashlight was thrown");
flashlight.SpawnFlare(((Component)Player.m_localPlayer).transform.position + 2f * Vector3.up, ((Component)GameCamera.instance).transform.forward);
}
}
}
private void InitConfigs()
{
//IL_0015: Unknown result type (might be due to invalid IL or missing references)
FlareLightTrow = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Flare", "TrowLight", KeyboardShortcut.Deserialize("F"), "Hotkey to throw flashlight");
FlareLightColor = ((BaseUnityPlugin)this).Config.Bind<string>("Flare", "FlareColor", "#FFAA00", "Color of the light");
FlareLightStrenght = ((BaseUnityPlugin)this).Config.Bind<float>("Flare", "FlareLightStrenght", 1.5f, "Strenght of the flare color");
FlareLightRange = ((BaseUnityPlugin)this).Config.Bind<float>("Flare", "FlareLightRange", 10f, "Range of the flare");
FlareLightTimeToDisable = ((BaseUnityPlugin)this).Config.Bind<float>("Flare", "FlareLightTimeToDisable", 20f, "Time before the flare disables itself");
}
}