using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using EquinoxsModUtils;
using EquinoxsModUtils.Additions;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using TechtonicaFramework.API;
using TechtonicaFramework.Health;
using TechtonicaFramework.TechTree;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("SurvivalElements")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+592c5cbcbdf02bbcc492465fb89e5ddeeb698bc8")]
[assembly: AssemblyProduct("SurvivalElements")]
[assembly: AssemblyTitle("SurvivalElements")]
[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 SurvivalElements
{
[BepInPlugin("com.certifired.SurvivalElements", "SurvivalElements", "2.6.3")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class SurvivalElementsPlugin : BaseUnityPlugin
{
public const string MyGUID = "com.certifired.SurvivalElements";
public const string PluginName = "SurvivalElements";
public const string VersionString = "2.6.3";
private static readonly Harmony Harmony = new Harmony("com.certifired.SurvivalElements");
public static ManualLogSource Log;
public static SurvivalElementsPlugin Instance;
public static ConfigEntry<bool> EnableMachineHealth;
public static ConfigEntry<float> DefaultMachineHP;
public static ConfigEntry<bool> EnablePowerSurges;
public static ConfigEntry<float> PowerSurgeChance;
public static ConfigEntry<float> PowerSurgeDamage;
public static ConfigEntry<bool> EnableOverloadDamage;
public static ConfigEntry<float> OverloadDamageRate;
public static ConfigEntry<bool> DebugMode;
public const string RepairToolName = "Repair Tool";
public const string RepairToolUnlock = "Repair Tool Tech";
public const string FoodUnlock = "Sustenance Tech";
public const string RawMeatName = "Raw Meat";
public const string CookedMeatName = "Cooked Meat";
public const string PlantStewName = "Plant Stew";
public const string EnergyBarName = "Energy Bar";
public const string NutrientPasteName = "Nutrient Paste";
private static HashSet<uint> healthyMachines = new HashSet<uint>();
private static Dictionary<uint, GameObject> machineVisuals = new Dictionary<uint, GameObject>();
private static Dictionary<GameObject, uint> visualToMachineId = new Dictionary<GameObject, uint>();
private float powerSurgeTimer = 0f;
private float powerSurgeInterval = 60f;
private float hungerDecayTimer = 0f;
private float healthRegenTimer = 0f;
private static HungerHealthUI uiInstance;
private static DeathScreenUI deathScreenInstance;
private static MachineHealthDisplayUI machineHealthUI;
private static Vector3 elevatorRespawnPosition = Vector3.zero;
private static bool hasFoundElevator = false;
public static ConfigEntry<bool> EnableHunger;
public static ConfigEntry<float> HungerDecayRate;
public static ConfigEntry<float> StarvationDamage;
public static ConfigEntry<bool> EnablePlayerHealth;
public static ConfigEntry<float> PlayerHealthRegen;
public static ConfigEntry<bool> ShowHealthHungerUI;
public static ConfigEntry<float> RespawnDelay;
public static ConfigEntry<bool> RespawnAtElevator;
public static float CurrentHunger { get; private set; } = 100f;
public static float MaxHunger { get; private set; } = 100f;
public static float PlayerHealth { get; private set; } = 100f;
public static float PlayerMaxHealth { get; private set; } = 100f;
public static string LastDamageSource { get; private set; } = "unknown";
public static bool IsDead { get; private set; } = false;
private void Awake()
{
Instance = this;
Log = ((BaseUnityPlugin)this).Logger;
Log.LogInfo((object)"SurvivalElements v2.6.3 loading...");
InitializeConfig();
Harmony.PatchAll();
RegisterRepairTool();
RegisterFoodItems();
Events.GameDefinesLoaded += OnGameDefinesLoaded;
Events.GameLoaded += OnGameLoaded;
Events.TechTreeStateLoaded += OnTechTreeStateLoaded;
Log.LogInfo((object)"SurvivalElements v2.6.3 loaded!");
}
private void InitializeConfig()
{
//IL_004f: Unknown result type (might be due to invalid IL or missing references)
//IL_0059: Expected O, but got Unknown
//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
//IL_00b6: Expected O, but got Unknown
//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
//IL_00f3: Expected O, but got Unknown
//IL_0146: Unknown result type (might be due to invalid IL or missing references)
//IL_0150: Expected O, but got Unknown
//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
//IL_01ad: Expected O, but got Unknown
//IL_01e0: Unknown result type (might be due to invalid IL or missing references)
//IL_01ea: Expected O, but got Unknown
//IL_023d: Unknown result type (might be due to invalid IL or missing references)
//IL_0247: Expected O, but got Unknown
//IL_029a: Unknown result type (might be due to invalid IL or missing references)
//IL_02a4: Expected O, but got Unknown
EnableMachineHealth = ((BaseUnityPlugin)this).Config.Bind<bool>("Machine Health", "Enable Machine Health", true, "Enable health system for machines");
DefaultMachineHP = ((BaseUnityPlugin)this).Config.Bind<float>("Machine Health", "Default Machine HP", 100f, new ConfigDescription("Default health points for machines", (AcceptableValueBase)(object)new AcceptableValueRange<float>(10f, 1000f), Array.Empty<object>()));
EnablePowerSurges = ((BaseUnityPlugin)this).Config.Bind<bool>("Power Surges", "Enable Power Surges", true, "Random power surges can damage machines on the power grid");
PowerSurgeChance = ((BaseUnityPlugin)this).Config.Bind<float>("Power Surges", "Surge Chance Per Minute", 0.05f, new ConfigDescription("Chance of power surge per minute (0.05 = 5%)", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>()));
PowerSurgeDamage = ((BaseUnityPlugin)this).Config.Bind<float>("Power Surges", "Surge Damage", 25f, new ConfigDescription("Damage dealt by power surges", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 100f), Array.Empty<object>()));
EnableOverloadDamage = ((BaseUnityPlugin)this).Config.Bind<bool>("Overload", "Enable Overload Damage", true, "Machines take damage when power grid is overloaded");
OverloadDamageRate = ((BaseUnityPlugin)this).Config.Bind<float>("Overload", "Overload Damage Rate", 5f, new ConfigDescription("Damage per second during overload", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.1f, 50f), Array.Empty<object>()));
EnableHunger = ((BaseUnityPlugin)this).Config.Bind<bool>("Hunger", "Enable Hunger System", true, "Enable hunger that depletes over time");
HungerDecayRate = ((BaseUnityPlugin)this).Config.Bind<float>("Hunger", "Hunger Decay Per Minute", 2f, new ConfigDescription("Hunger points lost per minute", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.1f, 10f), Array.Empty<object>()));
StarvationDamage = ((BaseUnityPlugin)this).Config.Bind<float>("Hunger", "Starvation Damage Per Second", 1f, new ConfigDescription("Damage per second when starving", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.1f, 10f), Array.Empty<object>()));
EnablePlayerHealth = ((BaseUnityPlugin)this).Config.Bind<bool>("Player Health", "Enable Player Health", true, "Enable player health system with damage and regeneration");
PlayerHealthRegen = ((BaseUnityPlugin)this).Config.Bind<float>("Player Health", "Health Regen Per Second", 0.5f, new ConfigDescription("Health regeneration when well-fed", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 5f), Array.Empty<object>()));
ShowHealthHungerUI = ((BaseUnityPlugin)this).Config.Bind<bool>("UI", "Show Health/Hunger UI", true, "Display health and hunger bars on screen");
RespawnDelay = ((BaseUnityPlugin)this).Config.Bind<float>("Death", "Respawn Delay", 5f, new ConfigDescription("Seconds to wait before respawning", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 30f), Array.Empty<object>()));
RespawnAtElevator = ((BaseUnityPlugin)this).Config.Bind<bool>("Death", "Respawn At Elevator", true, "Respawn at the main elevator instead of death location");
DebugMode = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Debug Mode", false, "Enable debug logging");
}
private void RegisterRepairTool()
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
//IL_0013: Unknown result type (might be due to invalid IL or missing references)
//IL_0018: Unknown result type (might be due to invalid IL or missing references)
//IL_0020: 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_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_004a: Expected O, but got Unknown
//IL_004b: Unknown result type (might be due to invalid IL or missing references)
//IL_0050: Unknown result type (might be due to invalid IL or missing references)
//IL_005b: Unknown result type (might be due to invalid IL or missing references)
//IL_0066: 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_006d: Unknown result type (might be due to invalid IL or missing references)
//IL_0074: Unknown result type (might be due to invalid IL or missing references)
//IL_007f: Unknown result type (might be due to invalid IL or missing references)
//IL_0086: Unknown result type (might be due to invalid IL or missing references)
//IL_008e: Unknown result type (might be due to invalid IL or missing references)
//IL_0099: Unknown result type (might be due to invalid IL or missing references)
//IL_00aa: Expected O, but got Unknown
//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
//IL_00df: 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_00ff: Unknown result type (might be due to invalid IL or missing references)
//IL_0111: Unknown result type (might be due to invalid IL or missing references)
//IL_0121: Unknown result type (might be due to invalid IL or missing references)
//IL_012e: 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_014c: Expected O, but got Unknown
EMUAdditions.AddNewUnlock(new NewUnlockDetails
{
category = ModdedTabModule.ModdedCategory,
coreTypeNeeded = (CoreType)1,
coreCountNeeded = 50,
description = "A handheld tool that repairs damaged machines. Hold near a damaged machine to restore its health.",
displayName = "Repair Tool Tech",
requiredTier = (ResearchTier)1,
treePosition = 0
}, false);
EMUAdditions.AddNewResource(new NewResourceDetails
{
name = "Repair Tool",
description = "Handheld repair tool. Aim at damaged machines and hold to repair them.",
craftingMethod = (CraftingMethod)0,
craftTierRequired = 0,
headerTitle = "Modded",
maxStackCount = 1,
sortPriority = 100,
unlockName = "Repair Tool Tech",
parentName = "Scanner"
}, false);
EMUAdditions.AddNewRecipe(new NewRecipeDetails
{
GUID = "com.certifired.SurvivalElements",
craftingMethod = (CraftingMethod)0,
craftTierRequired = 0,
duration = 10f,
unlockName = "Repair Tool Tech",
ingredients = new List<RecipeResourceInfo>
{
new RecipeResourceInfo("Iron Frame", 5),
new RecipeResourceInfo("Copper Wire", 10),
new RecipeResourceInfo("Iron Components", 5)
},
outputs = new List<RecipeResourceInfo>
{
new RecipeResourceInfo("Repair Tool", 1)
},
sortPriority = 100
}, false);
LogDebug("Repair Tool registered");
}
private void RegisterFoodItems()
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
//IL_0013: Unknown result type (might be due to invalid IL or missing references)
//IL_0018: Unknown result type (might be due to invalid IL or missing references)
//IL_0020: 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_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_004a: Expected O, but got Unknown
//IL_004b: Unknown result type (might be due to invalid IL or missing references)
//IL_0050: Unknown result type (might be due to invalid IL or missing references)
//IL_005b: Unknown result type (might be due to invalid IL or missing references)
//IL_0066: 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_006d: Unknown result type (might be due to invalid IL or missing references)
//IL_0074: Unknown result type (might be due to invalid IL or missing references)
//IL_007f: Unknown result type (might be due to invalid IL or missing references)
//IL_0087: Unknown result type (might be due to invalid IL or missing references)
//IL_0092: Unknown result type (might be due to invalid IL or missing references)
//IL_009d: Unknown result type (might be due to invalid IL or missing references)
//IL_00ae: Expected O, but got Unknown
//IL_00af: Unknown result type (might be due to invalid IL or missing references)
//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
//IL_0101: Unknown result type (might be due to invalid IL or missing references)
//IL_0112: Expected O, but got Unknown
//IL_0113: Unknown result type (might be due to invalid IL or missing references)
//IL_0118: Unknown result type (might be due to invalid IL or missing references)
//IL_0123: Unknown result type (might be due to invalid IL or missing references)
//IL_0125: Unknown result type (might be due to invalid IL or missing references)
//IL_012a: Unknown result type (might be due to invalid IL or missing references)
//IL_0131: Unknown result type (might be due to invalid IL or missing references)
//IL_013c: Unknown result type (might be due to invalid IL or missing references)
//IL_0147: Unknown result type (might be due to invalid IL or missing references)
//IL_0154: Unknown result type (might be due to invalid IL or missing references)
//IL_0164: Unknown result type (might be due to invalid IL or missing references)
//IL_0171: Unknown result type (might be due to invalid IL or missing references)
//IL_0181: Unknown result type (might be due to invalid IL or missing references)
//IL_0192: Expected O, but got Unknown
//IL_0193: Unknown result type (might be due to invalid IL or missing references)
//IL_0198: Unknown result type (might be due to invalid IL or missing references)
//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
//IL_01ae: Unknown result type (might be due to invalid IL or missing references)
//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
//IL_01bc: Unknown result type (might be due to invalid IL or missing references)
//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
//IL_01cf: Unknown result type (might be due to invalid IL or missing references)
//IL_01da: Unknown result type (might be due to invalid IL or missing references)
//IL_01e5: Unknown result type (might be due to invalid IL or missing references)
//IL_01f6: Expected O, but got Unknown
//IL_01f7: Unknown result type (might be due to invalid IL or missing references)
//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
//IL_0207: Unknown result type (might be due to invalid IL or missing references)
//IL_0209: Unknown result type (might be due to invalid IL or missing references)
//IL_020e: Unknown result type (might be due to invalid IL or missing references)
//IL_0215: Unknown result type (might be due to invalid IL or missing references)
//IL_0220: Unknown result type (might be due to invalid IL or missing references)
//IL_022b: Unknown result type (might be due to invalid IL or missing references)
//IL_0239: Unknown result type (might be due to invalid IL or missing references)
//IL_024b: Unknown result type (might be due to invalid IL or missing references)
//IL_025b: Unknown result type (might be due to invalid IL or missing references)
//IL_0268: Unknown result type (might be due to invalid IL or missing references)
//IL_0278: Unknown result type (might be due to invalid IL or missing references)
//IL_0289: Expected O, but got Unknown
//IL_028a: Unknown result type (might be due to invalid IL or missing references)
//IL_028f: Unknown result type (might be due to invalid IL or missing references)
//IL_029a: Unknown result type (might be due to invalid IL or missing references)
//IL_02a5: Unknown result type (might be due to invalid IL or missing references)
//IL_02a7: Unknown result type (might be due to invalid IL or missing references)
//IL_02ac: Unknown result type (might be due to invalid IL or missing references)
//IL_02b3: Unknown result type (might be due to invalid IL or missing references)
//IL_02be: Unknown result type (might be due to invalid IL or missing references)
//IL_02c6: Unknown result type (might be due to invalid IL or missing references)
//IL_02d1: Unknown result type (might be due to invalid IL or missing references)
//IL_02dc: Unknown result type (might be due to invalid IL or missing references)
//IL_02ed: Expected O, but got Unknown
//IL_02ee: Unknown result type (might be due to invalid IL or missing references)
//IL_02f3: Unknown result type (might be due to invalid IL or missing references)
//IL_02fe: Unknown result type (might be due to invalid IL or missing references)
//IL_0300: Unknown result type (might be due to invalid IL or missing references)
//IL_0305: Unknown result type (might be due to invalid IL or missing references)
//IL_030c: Unknown result type (might be due to invalid IL or missing references)
//IL_0317: Unknown result type (might be due to invalid IL or missing references)
//IL_0322: Unknown result type (might be due to invalid IL or missing references)
//IL_032f: Unknown result type (might be due to invalid IL or missing references)
//IL_0341: Unknown result type (might be due to invalid IL or missing references)
//IL_0351: Unknown result type (might be due to invalid IL or missing references)
//IL_035e: Unknown result type (might be due to invalid IL or missing references)
//IL_036e: Unknown result type (might be due to invalid IL or missing references)
//IL_037f: Expected O, but got Unknown
//IL_0380: Unknown result type (might be due to invalid IL or missing references)
//IL_0385: Unknown result type (might be due to invalid IL or missing references)
//IL_0390: Unknown result type (might be due to invalid IL or missing references)
//IL_039b: Unknown result type (might be due to invalid IL or missing references)
//IL_039d: Unknown result type (might be due to invalid IL or missing references)
//IL_03a2: Unknown result type (might be due to invalid IL or missing references)
//IL_03a9: Unknown result type (might be due to invalid IL or missing references)
//IL_03b4: Unknown result type (might be due to invalid IL or missing references)
//IL_03bc: Unknown result type (might be due to invalid IL or missing references)
//IL_03c7: Unknown result type (might be due to invalid IL or missing references)
//IL_03d2: Unknown result type (might be due to invalid IL or missing references)
//IL_03e3: Expected O, but got Unknown
//IL_03e4: Unknown result type (might be due to invalid IL or missing references)
//IL_03e9: Unknown result type (might be due to invalid IL or missing references)
//IL_03f4: Unknown result type (might be due to invalid IL or missing references)
//IL_03f6: Unknown result type (might be due to invalid IL or missing references)
//IL_03fb: Unknown result type (might be due to invalid IL or missing references)
//IL_0402: Unknown result type (might be due to invalid IL or missing references)
//IL_040d: Unknown result type (might be due to invalid IL or missing references)
//IL_0418: Unknown result type (might be due to invalid IL or missing references)
//IL_0425: Unknown result type (might be due to invalid IL or missing references)
//IL_0438: Unknown result type (might be due to invalid IL or missing references)
//IL_044a: Unknown result type (might be due to invalid IL or missing references)
//IL_045a: Unknown result type (might be due to invalid IL or missing references)
//IL_0467: Unknown result type (might be due to invalid IL or missing references)
//IL_0477: Unknown result type (might be due to invalid IL or missing references)
//IL_0488: Expected O, but got Unknown
EMUAdditions.AddNewUnlock(new NewUnlockDetails
{
category = ModdedTabModule.ModdedCategory,
coreTypeNeeded = (CoreType)1,
coreCountNeeded = 30,
description = "Research food preparation techniques to stave off hunger.",
displayName = "Sustenance Tech",
requiredTier = (ResearchTier)1,
treePosition = 0
}, false);
EMUAdditions.AddNewResource(new NewResourceDetails
{
name = "Raw Meat",
description = "Raw meat from wildlife. Should be cooked before consumption.",
craftingMethod = (CraftingMethod)0,
craftTierRequired = 0,
headerTitle = "Modded",
maxStackCount = 50,
sortPriority = 300,
unlockName = "Sustenance Tech",
parentName = "Plantmatter"
}, false);
EMUAdditions.AddNewResource(new NewResourceDetails
{
name = "Cooked Meat",
description = "Well-cooked meat. Restores 40 hunger when consumed.",
craftingMethod = (CraftingMethod)2,
craftTierRequired = 0,
headerTitle = "Modded",
maxStackCount = 30,
sortPriority = 301,
unlockName = "Sustenance Tech",
parentName = "Plantmatter"
}, false);
EMUAdditions.AddNewRecipe(new NewRecipeDetails
{
GUID = "com.certifired.SurvivalElements_cookedmeat",
craftingMethod = (CraftingMethod)2,
craftTierRequired = 0,
duration = 5f,
unlockName = "Sustenance Tech",
ingredients = new List<RecipeResourceInfo>
{
new RecipeResourceInfo("Plantmatter", 5)
},
outputs = new List<RecipeResourceInfo>
{
new RecipeResourceInfo("Cooked Meat", 1)
},
sortPriority = 301
}, false);
EMUAdditions.AddNewResource(new NewResourceDetails
{
name = "Plant Stew",
description = "A hearty stew made from local plants. Restores 30 hunger.",
craftingMethod = (CraftingMethod)2,
craftTierRequired = 0,
headerTitle = "Modded",
maxStackCount = 20,
sortPriority = 302,
unlockName = "Sustenance Tech",
parentName = "Plantmatter"
}, false);
EMUAdditions.AddNewRecipe(new NewRecipeDetails
{
GUID = "com.certifired.SurvivalElements_plantstew",
craftingMethod = (CraftingMethod)2,
craftTierRequired = 0,
duration = 8f,
unlockName = "Sustenance Tech",
ingredients = new List<RecipeResourceInfo>
{
new RecipeResourceInfo("Plantmatter", 10),
new RecipeResourceInfo("Kindlevine", 2)
},
outputs = new List<RecipeResourceInfo>
{
new RecipeResourceInfo("Plant Stew", 2)
},
sortPriority = 302
}, false);
EMUAdditions.AddNewResource(new NewResourceDetails
{
name = "Energy Bar",
description = "Compact, long-lasting energy bar. Restores 25 hunger. Great for exploration.",
craftingMethod = (CraftingMethod)0,
craftTierRequired = 0,
headerTitle = "Modded",
maxStackCount = 50,
sortPriority = 303,
unlockName = "Sustenance Tech",
parentName = "Plantmatter"
}, false);
EMUAdditions.AddNewRecipe(new NewRecipeDetails
{
GUID = "com.certifired.SurvivalElements_energybar",
craftingMethod = (CraftingMethod)0,
craftTierRequired = 0,
duration = 10f,
unlockName = "Sustenance Tech",
ingredients = new List<RecipeResourceInfo>
{
new RecipeResourceInfo("Plantmatter Fiber", 5),
new RecipeResourceInfo("Kindlevine Extract", 2)
},
outputs = new List<RecipeResourceInfo>
{
new RecipeResourceInfo("Energy Bar", 3)
},
sortPriority = 303
}, false);
EMUAdditions.AddNewResource(new NewResourceDetails
{
name = "Nutrient Paste",
description = "Processed nutrient paste. Not tasty, but efficient. Restores 50 hunger.",
craftingMethod = (CraftingMethod)0,
craftTierRequired = 0,
headerTitle = "Modded",
maxStackCount = 30,
sortPriority = 304,
unlockName = "Sustenance Tech",
parentName = "Biobrick"
}, false);
EMUAdditions.AddNewRecipe(new NewRecipeDetails
{
GUID = "com.certifired.SurvivalElements_nutrientpaste",
craftingMethod = (CraftingMethod)0,
craftTierRequired = 0,
duration = 15f,
unlockName = "Sustenance Tech",
ingredients = new List<RecipeResourceInfo>
{
new RecipeResourceInfo("Biobrick", 5),
new RecipeResourceInfo("Plantmatter", 20),
new RecipeResourceInfo("Shiverthorn Extract", 1)
},
outputs = new List<RecipeResourceInfo>
{
new RecipeResourceInfo("Nutrient Paste", 5)
},
sortPriority = 304
}, false);
LogDebug("Food items registered");
}
private void OnGameLoaded()
{
CurrentHunger = MaxHunger;
PlayerHealth = PlayerMaxHealth;
IsDead = false;
if (ShowHealthHungerUI.Value)
{
CreateHealthHungerUI();
}
FindElevatorRespawnPoint();
Log.LogInfo((object)"SurvivalElements: Game loaded, hunger/health systems active");
}
private void FindElevatorRespawnPoint()
{
((MonoBehaviour)this).StartCoroutine(FindElevatorDelayed());
}
private IEnumerator FindElevatorDelayed()
{
yield return (object)new WaitForSeconds(2f);
try
{
Transform[] elevators = Object.FindObjectsOfType<Transform>();
Transform[] array = elevators;
foreach (Transform t in array)
{
if (((Object)t).name.ToLower().Contains("elevator") && ((Object)t).name.ToLower().Contains("main"))
{
elevatorRespawnPosition = t.position + Vector3.up * 2f;
hasFoundElevator = true;
Log.LogInfo((object)$"Found elevator respawn point: {elevatorRespawnPosition}");
yield break;
}
}
Player player = Player.instance;
if ((Object)(object)player != (Object)null)
{
elevatorRespawnPosition = ((Component)player).transform.position;
hasFoundElevator = true;
Log.LogInfo((object)$"Using player start position as respawn: {elevatorRespawnPosition}");
}
}
catch (Exception ex)
{
Log.LogWarning((object)("Error finding elevator: " + ex.Message));
}
}
private void CreateHealthHungerUI()
{
((MonoBehaviour)this).StartCoroutine(CreateUIDelayed());
}
private IEnumerator CreateUIDelayed()
{
yield return (object)new WaitForSeconds(1f);
GameObject uiObj = new GameObject("HungerHealthUI");
Object.DontDestroyOnLoad((Object)(object)uiObj);
uiInstance = uiObj.AddComponent<HungerHealthUI>();
GameObject deathObj = new GameObject("DeathScreenUI");
Object.DontDestroyOnLoad((Object)(object)deathObj);
deathScreenInstance = deathObj.AddComponent<DeathScreenUI>();
if (EnableMachineHealth.Value)
{
GameObject machineUIObj = new GameObject("MachineHealthDisplayUI");
Object.DontDestroyOnLoad((Object)(object)machineUIObj);
machineHealthUI = machineUIObj.AddComponent<MachineHealthDisplayUI>();
}
LogDebug("Health/Hunger UI, Death Screen, and Machine Health Display created");
}
private void OnGameDefinesLoaded()
{
ResourceInfo resourceInfoByName = Resources.GetResourceInfoByName("Repair Tool", false);
if ((Object)(object)resourceInfoByName != (Object)null)
{
resourceInfoByName.unlock = Unlocks.GetUnlockByName("Repair Tool Tech", false);
LogDebug("Repair Tool linked to unlock");
}
}
private void OnTechTreeStateLoaded()
{
ConfigureUnlock("Repair Tool Tech", "Iron Components", (ResearchTier)64, 90);
ConfigureUnlock("Sustenance Tech", "Plantmatter", (ResearchTier)4, 90);
Log.LogInfo((object)"Configured SurvivalElements unlock tiers");
}
private void ConfigureUnlock(string unlockName, string spriteSourceName, ResearchTier tier, int position)
{
//IL_0032: Unknown result type (might be due to invalid IL or missing references)
//IL_0033: Unknown result type (might be due to invalid IL or missing references)
//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
try
{
Unlock unlockByName = Unlocks.GetUnlockByName(unlockName, false);
if ((Object)(object)unlockByName == (Object)null)
{
LogDebug("Unlock '" + unlockName + "' not found");
return;
}
unlockByName.requiredTier = tier;
unlockByName.treePosition = position;
if ((Object)(object)unlockByName.sprite == (Object)null)
{
ResourceInfo resourceInfoByName = Resources.GetResourceInfoByName(spriteSourceName, false);
if ((Object)(object)resourceInfoByName != (Object)null && (Object)(object)resourceInfoByName.sprite != (Object)null)
{
unlockByName.sprite = resourceInfoByName.sprite;
}
else
{
Unlock unlockByName2 = Unlocks.GetUnlockByName(spriteSourceName, false);
if ((Object)(object)unlockByName2 != (Object)null && (Object)(object)unlockByName2.sprite != (Object)null)
{
unlockByName.sprite = unlockByName2.sprite;
}
}
}
LogDebug($"Configured unlock '{unlockName}': tier={tier}, position={position}");
}
catch (Exception ex)
{
Log.LogWarning((object)("Failed to configure unlock " + unlockName + ": " + ex.Message));
}
}
private void Update()
{
if (EnableMachineHealth.Value)
{
if (EnablePowerSurges.Value)
{
powerSurgeTimer += Time.deltaTime;
if (powerSurgeTimer >= powerSurgeInterval)
{
powerSurgeTimer = 0f;
CheckPowerSurge();
}
}
CheckRepairToolUsage();
}
if (EnableHunger.Value)
{
UpdateHunger();
}
if (EnablePlayerHealth.Value)
{
UpdatePlayerHealth();
}
}
private void UpdateHunger()
{
hungerDecayTimer += Time.deltaTime;
if (hungerDecayTimer >= 60f)
{
hungerDecayTimer = 0f;
CurrentHunger = Mathf.Max(0f, CurrentHunger - HungerDecayRate.Value);
if (CurrentHunger <= 0f)
{
Log.LogWarning((object)"STARVING! Take damage until you eat!");
}
else if (CurrentHunger <= 25f)
{
Log.LogWarning((object)$"Hunger critically low: {CurrentHunger:F0}%");
}
}
if (CurrentHunger <= 0f && EnablePlayerHealth.Value)
{
DamagePlayer(StarvationDamage.Value * Time.deltaTime, "starvation");
}
}
private void UpdatePlayerHealth()
{
if (CurrentHunger > 50f && PlayerHealth < PlayerMaxHealth)
{
healthRegenTimer += Time.deltaTime;
if (healthRegenTimer >= 1f)
{
healthRegenTimer = 0f;
PlayerHealth = Mathf.Min(PlayerMaxHealth, PlayerHealth + PlayerHealthRegen.Value);
}
}
else
{
healthRegenTimer = 0f;
}
if (PlayerHealth <= 0f)
{
OnPlayerDeath();
}
}
public static void DamagePlayer(float damage, string source = "unknown")
{
if (EnablePlayerHealth.Value && !IsDead)
{
LastDamageSource = source;
PlayerHealth = Mathf.Max(0f, PlayerHealth - damage);
if (damage >= 5f)
{
Log.LogInfo((object)$"Player took {damage:F0} damage from {source}, HP: {PlayerHealth:F0}/{PlayerMaxHealth}");
}
else
{
LogDebug($"Player took {damage:F1} damage from {source}, health: {PlayerHealth:F0}/{PlayerMaxHealth}");
}
if ((Object)(object)uiInstance != (Object)null)
{
uiInstance.FlashDamage();
}
if (PlayerHealth <= 0f)
{
Instance?.TriggerDeath();
}
}
}
public static void HealPlayer(float amount)
{
PlayerHealth = Mathf.Min(PlayerMaxHealth, PlayerHealth + amount);
LogDebug($"Player healed {amount:F1}, health: {PlayerHealth:F0}/{PlayerMaxHealth}");
}
public static void RestoreHunger(float amount)
{
CurrentHunger = Mathf.Min(MaxHunger, CurrentHunger + amount);
Log.LogInfo((object)$"Restored {amount:F0} hunger, now: {CurrentHunger:F0}/{MaxHunger}");
}
public static float GetFoodValue(string itemName)
{
if (1 == 0)
{
}
float result = itemName switch
{
"Cooked Meat" => 40f,
"Plant Stew" => 30f,
"Energy Bar" => 25f,
"Nutrient Paste" => 50f,
"Raw Meat" => 10f,
_ => 0f,
};
if (1 == 0)
{
}
return result;
}
public void TriggerDeath()
{
if (!IsDead)
{
IsDead = true;
Log.LogError((object)("PLAYER DIED! Cause: " + LastDamageSource));
if ((Object)(object)deathScreenInstance != (Object)null)
{
deathScreenInstance.ShowDeathScreen(LastDamageSource);
}
((MonoBehaviour)this).StartCoroutine(RespawnAfterDelay());
}
}
private IEnumerator RespawnAfterDelay()
{
float delay = RespawnDelay.Value;
Log.LogInfo((object)$"Respawning in {delay} seconds...");
yield return (object)new WaitForSeconds(delay);
PerformRespawn();
}
private void PerformRespawn()
{
//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
//IL_0084: Unknown result type (might be due to invalid IL or missing references)
//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
Log.LogInfo((object)"Respawning player...");
PlayerHealth = PlayerMaxHealth * 0.5f;
CurrentHunger = MaxHunger * 0.3f;
if (RespawnAtElevator.Value && hasFoundElevator)
{
Player instance = Player.instance;
if ((Object)(object)instance != (Object)null)
{
CharacterController component = ((Component)instance).GetComponent<CharacterController>();
if ((Object)(object)component != (Object)null)
{
((Collider)component).enabled = false;
((Component)instance).transform.position = elevatorRespawnPosition;
((Collider)component).enabled = true;
}
else
{
((Component)instance).transform.position = elevatorRespawnPosition;
}
Log.LogInfo((object)$"Teleported player to elevator: {elevatorRespawnPosition}");
}
}
if ((Object)(object)deathScreenInstance != (Object)null)
{
deathScreenInstance.HideDeathScreen();
}
IsDead = false;
LastDamageSource = "unknown";
Log.LogInfo((object)"Player respawned!");
}
private void OnPlayerDeath()
{
TriggerDeath();
}
private void CheckPowerSurge()
{
if (Random.value < PowerSurgeChance.Value)
{
TriggerPowerSurge();
}
}
private void TriggerPowerSurge()
{
Log.LogInfo((object)"POWER SURGE! Machines on the grid are taking damage!");
int num = 0;
foreach (uint healthyMachine in healthyMachines)
{
if (Random.value < 0.3f)
{
FrameworkAPI.DamageMachine(healthyMachine, PowerSurgeDamage.Value, (DamageType)2);
num++;
}
}
if (num > 0)
{
LogDebug($"Power surge damaged {num} machines");
}
}
private void CheckRepairToolUsage()
{
//IL_0057: Unknown result type (might be due to invalid IL or missing references)
//IL_005c: Unknown result type (might be due to invalid IL or missing references)
//IL_0061: 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)
Player instance = Player.instance;
if ((Object)(object)instance == (Object)null || !Input.GetButton("Fire1"))
{
return;
}
Camera main = Camera.main;
if ((Object)(object)main == (Object)null)
{
return;
}
Ray val = main.ScreenPointToRay(new Vector3((float)(Screen.width / 2), (float)(Screen.height / 2), 0f));
RaycastHit val2 = default(RaycastHit);
if (!Physics.Raycast(val, ref val2, 5f))
{
return;
}
GameObject gameObject = ((Component)((RaycastHit)(ref val2)).collider).gameObject;
uint machineIdFromObject = GetMachineIdFromObject(gameObject);
if (machineIdFromObject != 0 && healthyMachines.Contains(machineIdFromObject))
{
float machineHealthPercent = FrameworkAPI.GetMachineHealthPercent(machineIdFromObject);
if (machineHealthPercent < 1f)
{
FrameworkAPI.HealMachine(machineIdFromObject, 10f * Time.deltaTime);
LogDebug($"Repairing machine {machineIdFromObject}: {machineHealthPercent * 100f:F0}%");
}
}
}
private uint GetMachineIdFromObject(GameObject obj)
{
if ((Object)(object)obj == (Object)null)
{
return 0u;
}
MachineHealthTracker componentInParent = obj.GetComponentInParent<MachineHealthTracker>();
if ((Object)(object)componentInParent != (Object)null)
{
return componentInParent.MachineId;
}
if (visualToMachineId.TryGetValue(obj, out var value))
{
return value;
}
Transform val = obj.transform;
while ((Object)(object)val != (Object)null)
{
if (visualToMachineId.TryGetValue(((Component)val).gameObject, out value))
{
return value;
}
val = val.parent;
}
return 0u;
}
public static (bool found, float current, float max, float percent) GetMachineHealthInfo(uint machineId)
{
if (!healthyMachines.Contains(machineId))
{
return (false, 0f, 0f, 1f);
}
float machineHealthPercent = FrameworkAPI.GetMachineHealthPercent(machineId);
float value = DefaultMachineHP.Value;
float item = value * machineHealthPercent;
return (true, item, value, machineHealthPercent);
}
private void OnMachineDestroyed(uint machineId)
{
healthyMachines.Remove(machineId);
Log.LogWarning((object)$"Machine {machineId} was destroyed!");
}
private void OnMachineRepaired(uint machineId)
{
LogDebug($"Machine {machineId} fully repaired");
}
public static void RegisterMachineWithHealth(uint machineId, float maxHealth = 0f, GameObject visual = null)
{
if (!EnableMachineHealth.Value)
{
return;
}
if (maxHealth <= 0f)
{
maxHealth = DefaultMachineHP.Value;
}
FrameworkAPI.RegisterMachineHealth(machineId, maxHealth);
healthyMachines.Add(machineId);
if ((Object)(object)visual != (Object)null)
{
machineVisuals[machineId] = visual;
visualToMachineId[visual] = machineId;
MachineHealthTracker machineHealthTracker = visual.GetComponent<MachineHealthTracker>();
if ((Object)(object)machineHealthTracker == (Object)null)
{
machineHealthTracker = visual.AddComponent<MachineHealthTracker>();
}
machineHealthTracker.MachineId = machineId;
}
LogDebug(string.Format("Registered machine {0} with {1} HP (visual: {2})", machineId, maxHealth, ((visual != null) ? ((Object)visual).name : null) ?? "none"));
}
public static void UnregisterMachine(uint machineId)
{
healthyMachines.Remove(machineId);
if (machineVisuals.TryGetValue(machineId, out var value))
{
if ((Object)(object)value != (Object)null)
{
visualToMachineId.Remove(value);
}
machineVisuals.Remove(machineId);
}
}
public static void LogDebug(string message)
{
if (DebugMode != null && DebugMode.Value)
{
Log.LogInfo((object)("[DEBUG] " + message));
}
}
}
public class MachineHealthTracker : MonoBehaviour
{
public uint MachineId;
}
[HarmonyPatch]
public static class MachineHealthPatches
{
[HarmonyPatch(typeof(GridManager), "BuildObj", new Type[] { typeof(GenericMachineInstanceRef) })]
[HarmonyPostfix]
public static void OnMachineBuilt(GenericMachineInstanceRef machineRef)
{
//IL_0018: Unknown result type (might be due to invalid IL or missing references)
//IL_001d: Unknown result type (might be due to invalid IL or missing references)
//IL_001e: Unknown result type (might be due to invalid IL or missing references)
//IL_002f: Unknown result type (might be due to invalid IL or missing references)
try
{
if (!((GenericMachineInstanceRef)(ref machineRef)).IsValid())
{
return;
}
GameObject visual = null;
try
{
CommonMachineInfo commonInfo = ((GenericMachineInstanceRef)(ref machineRef)).GetCommonInfo();
if ((Object)(object)commonInfo.refGameObj != (Object)null)
{
visual = commonInfo.refGameObj;
}
}
catch (Exception ex)
{
SurvivalElementsPlugin.LogDebug($"Could not get visual for machine {((GenericMachineInstanceRef)(ref machineRef)).instanceId}: {ex.Message}");
}
SurvivalElementsPlugin.RegisterMachineWithHealth(((GenericMachineInstanceRef)(ref machineRef)).instanceId, 0f, visual);
}
catch (Exception ex2)
{
SurvivalElementsPlugin.Log.LogError((object)("Error registering machine health: " + ex2.Message));
}
}
[HarmonyPatch(typeof(GridManager), "RemoveObj", new Type[] { typeof(GenericMachineInstanceRef) })]
[HarmonyPrefix]
public static void OnMachineRemoved(GenericMachineInstanceRef machineRef)
{
try
{
if (((GenericMachineInstanceRef)(ref machineRef)).IsValid())
{
SurvivalElementsPlugin.UnregisterMachine(((GenericMachineInstanceRef)(ref machineRef)).instanceId);
}
}
catch
{
}
}
}
[HarmonyPatch]
public static class DamageVisualPatches
{
private static readonly Color HealthyColor = Color.white;
private static readonly Color DamagedColor = new Color(1f, 0.8f, 0.2f);
private static readonly Color CriticalColor = new Color(1f, 0.2f, 0.2f);
private static Dictionary<uint, float> lastHealthCheck = new Dictionary<uint, float>();
public static void UpdateMachineVisuals(uint machineId, GameObject visual)
{
//IL_0065: Unknown result type (might be due to invalid IL or missing references)
//IL_006a: Unknown result type (might be due to invalid IL or missing references)
//IL_009e: Unknown result type (might be due to invalid IL or missing references)
//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
//IL_00af: Unknown result type (might be due to invalid IL or missing references)
//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
//IL_007d: Unknown result type (might be due to invalid IL or missing references)
//IL_0082: Unknown result type (might be due to invalid IL or missing references)
//IL_0094: Unknown result type (might be due to invalid IL or missing references)
//IL_0099: Unknown result type (might be due to invalid IL or missing references)
//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
//IL_00d6: Expected O, but got Unknown
//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)visual == (Object)null)
{
return;
}
float machineHealthPercent = FrameworkAPI.GetMachineHealthPercent(machineId);
if (!lastHealthCheck.TryGetValue(machineId, out var value) || !(Mathf.Abs(machineHealthPercent - value) < 0.01f))
{
lastHealthCheck[machineId] = machineHealthPercent;
Color val = ((machineHealthPercent > 0.75f) ? HealthyColor : ((!(machineHealthPercent > 0.25f)) ? Color.Lerp(CriticalColor, DamagedColor, machineHealthPercent / 0.25f) : Color.Lerp(DamagedColor, HealthyColor, (machineHealthPercent - 0.25f) / 0.5f)));
MeshRenderer[] componentsInChildren = visual.GetComponentsInChildren<MeshRenderer>(true);
MeshRenderer[] array = componentsInChildren;
foreach (MeshRenderer val2 in array)
{
MaterialPropertyBlock val3 = new MaterialPropertyBlock();
((Renderer)val2).GetPropertyBlock(val3);
val3.SetColor("_Color", val);
val3.SetColor("_BaseColor", val);
((Renderer)val2).SetPropertyBlock(val3);
}
}
}
}
public class HungerHealthUI : MonoBehaviour
{
private GUIStyle healthBarStyle;
private GUIStyle hungerBarStyle;
private GUIStyle backgroundStyle;
private GUIStyle borderStyle;
private GUIStyle labelStyle;
private GUIStyle iconStyle;
private GUIStyle warningStyle;
private float damageFlashTimer = 0f;
private bool isFlashing = false;
private float damageVignetteAlpha = 0f;
private Texture2D healthTex;
private Texture2D hungerTex;
private Texture2D backgroundTex;
private Texture2D borderTex;
private Texture2D vignetteTex;
private void Awake()
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_000c: Expected O, but got Unknown
//IL_000d: Unknown result type (might be due to invalid IL or missing references)
//IL_0017: Expected O, but got Unknown
//IL_0018: Unknown result type (might be due to invalid IL or missing references)
//IL_0022: Expected O, but got Unknown
//IL_0023: Unknown result type (might be due to invalid IL or missing references)
//IL_002d: Expected O, but got Unknown
//IL_002e: Unknown result type (might be due to invalid IL or missing references)
//IL_0038: Expected O, but got Unknown
//IL_0039: Unknown result type (might be due to invalid IL or missing references)
//IL_0043: Expected O, but got Unknown
//IL_0044: Unknown result type (might be due to invalid IL or missing references)
//IL_004e: Expected O, but got Unknown
healthBarStyle = new GUIStyle();
hungerBarStyle = new GUIStyle();
backgroundStyle = new GUIStyle();
borderStyle = new GUIStyle();
labelStyle = new GUIStyle();
iconStyle = new GUIStyle();
warningStyle = new GUIStyle();
}
private void OnGUI()
{
//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
//IL_0107: 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_0163: Unknown result type (might be due to invalid IL or missing references)
//IL_018d: Unknown result type (might be due to invalid IL or missing references)
//IL_019e: Unknown result type (might be due to invalid IL or missing references)
//IL_01c6: Unknown result type (might be due to invalid IL or missing references)
//IL_01bf: Unknown result type (might be due to invalid IL or missing references)
//IL_01cb: Unknown result type (might be due to invalid IL or missing references)
//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
//IL_01f6: Unknown result type (might be due to invalid IL or missing references)
//IL_0273: Unknown result type (might be due to invalid IL or missing references)
//IL_0294: Unknown result type (might be due to invalid IL or missing references)
//IL_02cf: Unknown result type (might be due to invalid IL or missing references)
//IL_030b: Unknown result type (might be due to invalid IL or missing references)
//IL_0330: Unknown result type (might be due to invalid IL or missing references)
//IL_035a: Unknown result type (might be due to invalid IL or missing references)
//IL_036b: Unknown result type (might be due to invalid IL or missing references)
//IL_0384: Unknown result type (might be due to invalid IL or missing references)
//IL_0389: Unknown result type (might be due to invalid IL or missing references)
//IL_038b: Unknown result type (might be due to invalid IL or missing references)
//IL_03b4: Unknown result type (might be due to invalid IL or missing references)
//IL_03ca: Unknown result type (might be due to invalid IL or missing references)
//IL_03eb: Unknown result type (might be due to invalid IL or missing references)
//IL_0426: Unknown result type (might be due to invalid IL or missing references)
//IL_024b: Unknown result type (might be due to invalid IL or missing references)
//IL_025c: Unknown result type (might be due to invalid IL or missing references)
//IL_04f2: Unknown result type (might be due to invalid IL or missing references)
//IL_0511: Unknown result type (might be due to invalid IL or missing references)
//IL_0527: Unknown result type (might be due to invalid IL or missing references)
//IL_0485: Unknown result type (might be due to invalid IL or missing references)
//IL_04a4: Unknown result type (might be due to invalid IL or missing references)
//IL_04ba: Unknown result type (might be due to invalid IL or missing references)
//IL_058b: Unknown result type (might be due to invalid IL or missing references)
//IL_05aa: Unknown result type (might be due to invalid IL or missing references)
//IL_05c0: Unknown result type (might be due to invalid IL or missing references)
if (SurvivalElementsPlugin.ShowHealthHungerUI.Value && !SurvivalElementsPlugin.IsDead)
{
if ((Object)(object)healthTex == (Object)null)
{
SetupStyles();
}
if (damageVignetteAlpha > 0f)
{
DrawDamageVignette();
}
float num = 140f;
float num2 = 18f;
float num3 = 4f;
float num4 = 2f;
float num5 = 45f;
float num6 = (float)Screen.width / 2f + 280f;
float num7 = num6 + 15f;
float num8 = (float)Screen.height - 85f;
float num9 = num + num5 + 10f;
float num10 = num2 * 2f + num3 + 8f;
GUI.color = new Color(0f, 0f, 0f, 0.5f);
GUI.Box(new Rect(num7 - 4f, num8 - 4f, num9 + 8f, num10 + 4f), "", backgroundStyle);
float num11 = SurvivalElementsPlugin.PlayerHealth / SurvivalElementsPlugin.PlayerMaxHealth;
GUI.color = new Color(0.3f, 0.3f, 0.3f, 0.9f);
GUI.Box(new Rect(num7 - num4, num8 - num4, num + num4 * 2f, num2 + num4 * 2f), "", borderStyle);
GUI.color = new Color(0.1f, 0.1f, 0.1f, 0.95f);
GUI.Box(new Rect(num7, num8, num, num2), "", backgroundStyle);
Color color = (isFlashing ? Color.white : GetHealthColor(num11));
GUI.color = color;
GUI.Box(new Rect(num7 + 1f, num8 + 1f, (num - 2f) * num11, num2 - 2f), "", healthBarStyle);
if (num11 < 0.25f)
{
float num12 = Mathf.Sin(Time.time * 5f) * 0.3f + 0.3f;
GUI.color = new Color(1f, 0f, 0f, num12);
GUI.Box(new Rect(num7, num8, num, num2), "", backgroundStyle);
}
GUI.color = Color.white;
GUI.Label(new Rect(num7 + 3f, num8 - 1f, 20f, num2), "♥", iconStyle);
string text = $"{SurvivalElementsPlugin.PlayerHealth:F0}";
GUI.Label(new Rect(num7 + num + 6f, num8, num5, num2), text, labelStyle);
num8 += num2 + num3;
float num13 = SurvivalElementsPlugin.CurrentHunger / SurvivalElementsPlugin.MaxHunger;
GUI.color = new Color(0.3f, 0.3f, 0.3f, 0.9f);
GUI.Box(new Rect(num7 - num4, num8 - num4, num + num4 * 2f, num2 + num4 * 2f), "", borderStyle);
GUI.color = new Color(0.1f, 0.1f, 0.1f, 0.95f);
GUI.Box(new Rect(num7, num8, num, num2), "", backgroundStyle);
Color hungerColor = GetHungerColor(num13);
GUI.color = hungerColor;
GUI.Box(new Rect(num7 + 1f, num8 + 1f, (num - 2f) * num13, num2 - 2f), "", hungerBarStyle);
GUI.color = Color.white;
GUI.Label(new Rect(num7 + 3f, num8 - 1f, 20f, num2), "●", iconStyle);
string text2 = $"{SurvivalElementsPlugin.CurrentHunger:F0}%";
GUI.Label(new Rect(num7 + num + 6f, num8, num5, num2), text2, labelStyle);
if (SurvivalElementsPlugin.CurrentHunger <= 0f)
{
float num14 = ((Mathf.Sin(Time.time * 8f) > 0f) ? 1f : 0.5f);
GUI.color = new Color(1f, 0.2f, 0.2f, num14);
GUI.Label(new Rect(num7, num8 - 45f, 200f, 20f), "STARVING!", warningStyle);
GUI.color = Color.white;
}
else if (SurvivalElementsPlugin.CurrentHunger <= 25f)
{
GUI.color = new Color(1f, 0.8f, 0.2f, 1f);
GUI.Label(new Rect(num7, num8 - 45f, 200f, 20f), "Hungry", warningStyle);
GUI.color = Color.white;
}
if (SurvivalElementsPlugin.PlayerHealth <= 25f && SurvivalElementsPlugin.PlayerHealth > 0f)
{
float num15 = ((Mathf.Sin(Time.time * 6f) > 0f) ? 1f : 0.3f);
GUI.color = new Color(1f, 0f, 0f, num15);
GUI.Label(new Rect(num7, num8 - 25f, 200f, 20f), "LOW HEALTH!", warningStyle);
GUI.color = Color.white;
}
}
}
private void Update()
{
if (isFlashing)
{
damageFlashTimer -= Time.deltaTime;
if (damageFlashTimer <= 0f)
{
isFlashing = false;
}
}
if (damageVignetteAlpha > 0f)
{
damageVignetteAlpha -= Time.deltaTime * 2f;
}
}
public void FlashDamage()
{
isFlashing = true;
damageFlashTimer = 0.15f;
damageVignetteAlpha = 0.4f;
}
private void DrawDamageVignette()
{
//IL_0038: Unknown result type (might be due to invalid IL or missing references)
//IL_0059: Unknown result type (might be due to invalid IL or missing references)
//IL_006b: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)vignetteTex == (Object)null)
{
vignetteTex = MakeVignetteTexture(64, 64);
}
GUI.color = new Color(1f, 0f, 0f, damageVignetteAlpha);
GUI.DrawTexture(new Rect(0f, 0f, (float)Screen.width, (float)Screen.height), (Texture)(object)vignetteTex, (ScaleMode)0);
GUI.color = Color.white;
}
private void SetupStyles()
{
//IL_001a: Unknown result type (might be due to invalid IL or missing references)
//IL_0033: Unknown result type (might be due to invalid IL or missing references)
//IL_0072: Unknown result type (might be due to invalid IL or missing references)
//IL_008b: Unknown result type (might be due to invalid IL or missing references)
//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
//IL_0107: 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_0176: Unknown result type (might be due to invalid IL or missing references)
//IL_01b4: Unknown result type (might be due to invalid IL or missing references)
healthTex = MakeGradientTexture(32, 8, new Color(0.7f, 0.15f, 0.15f, 1f), new Color(0.9f, 0.3f, 0.3f, 1f));
healthBarStyle.normal.background = healthTex;
hungerTex = MakeGradientTexture(32, 8, new Color(0.7f, 0.45f, 0.1f, 1f), new Color(0.9f, 0.6f, 0.2f, 1f));
hungerBarStyle.normal.background = hungerTex;
backgroundTex = MakeTexture(2, 2, new Color(0.05f, 0.05f, 0.05f, 0.85f));
backgroundStyle.normal.background = backgroundTex;
borderTex = MakeTexture(2, 2, new Color(0.2f, 0.2f, 0.2f, 0.95f));
borderStyle.normal.background = borderTex;
labelStyle.normal.textColor = Color.white;
labelStyle.fontSize = 12;
labelStyle.fontStyle = (FontStyle)1;
labelStyle.alignment = (TextAnchor)3;
iconStyle.normal.textColor = Color.white;
iconStyle.fontSize = 14;
iconStyle.fontStyle = (FontStyle)1;
iconStyle.alignment = (TextAnchor)3;
warningStyle.normal.textColor = Color.white;
warningStyle.fontSize = 11;
warningStyle.fontStyle = (FontStyle)1;
warningStyle.alignment = (TextAnchor)3;
}
private Color GetHealthColor(float percent)
{
//IL_001c: Unknown result type (might be due to invalid IL or missing references)
//IL_0021: Unknown result type (might be due to invalid IL or missing references)
//IL_0056: Unknown result type (might be due to invalid IL or missing references)
//IL_005b: Unknown result type (might be due to invalid IL or missing references)
//IL_003f: Unknown result type (might be due to invalid IL or missing references)
//IL_0044: 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)
if (percent > 0.6f)
{
return new Color(0.2f, 0.85f, 0.3f);
}
if (percent > 0.3f)
{
return new Color(0.95f, 0.85f, 0.2f);
}
return new Color(0.9f, 0.2f, 0.2f);
}
private Color GetHungerColor(float percent)
{
//IL_001c: Unknown result type (might be due to invalid IL or missing references)
//IL_0021: Unknown result type (might be due to invalid IL or missing references)
//IL_0056: Unknown result type (might be due to invalid IL or missing references)
//IL_005b: Unknown result type (might be due to invalid IL or missing references)
//IL_003f: Unknown result type (might be due to invalid IL or missing references)
//IL_0044: 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)
if (percent > 0.5f)
{
return new Color(0.9f, 0.65f, 0.2f);
}
if (percent > 0.25f)
{
return new Color(0.85f, 0.45f, 0.15f);
}
return new Color(0.7f, 0.25f, 0.15f);
}
private Texture2D MakeTexture(int width, int height, Color col)
{
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
//IL_0011: 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: Expected O, but got Unknown
Color[] array = (Color[])(object)new Color[width * height];
for (int i = 0; i < array.Length; i++)
{
array[i] = col;
}
Texture2D val = new Texture2D(width, height);
val.SetPixels(array);
val.Apply();
return val;
}
private Texture2D MakeGradientTexture(int width, int height, Color bottom, Color top)
{
//IL_0003: Unknown result type (might be due to invalid IL or missing references)
//IL_0009: Expected O, but got Unknown
//IL_000e: Unknown result type (might be due to invalid IL or missing references)
//IL_000f: Unknown result type (might be due to invalid IL or missing references)
//IL_0016: 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)
//IL_0024: Unknown result type (might be due to invalid IL or missing references)
Texture2D val = new Texture2D(width, height);
for (int i = 0; i < height; i++)
{
Color val2 = Color.Lerp(bottom, top, (float)i / (float)height);
for (int j = 0; j < width; j++)
{
val.SetPixel(j, i, val2);
}
}
val.Apply();
return val;
}
private Texture2D MakeVignetteTexture(int width, int height)
{
//IL_0003: Unknown result type (might be due to invalid IL or missing references)
//IL_0009: Expected O, but got Unknown
//IL_0020: 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_002d: Unknown result type (might be due to invalid IL or missing references)
//IL_0033: Unknown result type (might be due to invalid IL or missing references)
//IL_0051: Unknown result type (might be due to invalid IL or missing references)
//IL_0056: Unknown result type (might be due to invalid IL or missing references)
//IL_0085: Unknown result type (might be due to invalid IL or missing references)
Texture2D val = new Texture2D(width, height);
Vector2 val2 = default(Vector2);
((Vector2)(ref val2))..ctor((float)width / 2f, (float)height / 2f);
float num = Mathf.Sqrt(val2.x * val2.x + val2.y * val2.y);
for (int i = 0; i < height; i++)
{
for (int j = 0; j < width; j++)
{
float num2 = Vector2.Distance(new Vector2((float)j, (float)i), val2);
float num3 = Mathf.Clamp01(num2 / num);
num3 *= num3;
val.SetPixel(j, i, new Color(1f, 0f, 0f, num3));
}
}
val.Apply();
return val;
}
}
public class DeathScreenUI : MonoBehaviour
{
private bool isVisible = false;
private string deathCause = "";
private float respawnTimer = 0f;
private GUIStyle titleStyle;
private GUIStyle subtitleStyle;
private GUIStyle countdownStyle;
private GUIStyle tipStyle;
private Texture2D overlayTex;
private float fadeAlpha = 0f;
private float glitchTimer = 0f;
private static readonly string[] DeathTips = new string[8] { "Tip: Keep your hunger above 50% to regenerate health.", "Tip: Craft food at a Smelter or Assembler to stay alive.", "Tip: Watch out for hostile drones and environmental hazards.", "Tip: The Repair Tool can fix damaged machines.", "Tip: Energy Bars are lightweight and great for exploration.", "Tip: Nutrient Paste restores the most hunger.", "Tip: Avoid starvation - it slowly drains your health!", "Tip: Stay away from radiation zones without protection." };
private string currentTip = "";
private void Awake()
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_000c: Expected O, but got Unknown
//IL_000d: Unknown result type (might be due to invalid IL or missing references)
//IL_0017: Expected O, but got Unknown
//IL_0018: Unknown result type (might be due to invalid IL or missing references)
//IL_0022: Expected O, but got Unknown
//IL_0023: Unknown result type (might be due to invalid IL or missing references)
//IL_002d: Expected O, but got Unknown
titleStyle = new GUIStyle();
subtitleStyle = new GUIStyle();
countdownStyle = new GUIStyle();
tipStyle = new GUIStyle();
}
private void Update()
{
if (isVisible)
{
if (respawnTimer > 0f)
{
respawnTimer -= Time.deltaTime;
}
fadeAlpha = Mathf.MoveTowards(fadeAlpha, 0.85f, Time.deltaTime * 2f);
glitchTimer += Time.deltaTime;
}
else
{
fadeAlpha = Mathf.MoveTowards(fadeAlpha, 0f, Time.deltaTime * 3f);
}
}
private void OnGUI()
{
//IL_004c: Unknown result type (might be due to invalid IL or missing references)
//IL_006d: Unknown result type (might be due to invalid IL or missing references)
//IL_007e: Unknown result type (might be due to invalid IL or missing references)
//IL_0117: 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_0170: Unknown result type (might be due to invalid IL or missing references)
//IL_019a: Unknown result type (might be due to invalid IL or missing references)
//IL_01c1: Unknown result type (might be due to invalid IL or missing references)
//IL_01d7: Unknown result type (might be due to invalid IL or missing references)
//IL_0204: Unknown result type (might be due to invalid IL or missing references)
//IL_0227: Unknown result type (might be due to invalid IL or missing references)
//IL_023a: Unknown result type (might be due to invalid IL or missing references)
//IL_02e2: Unknown result type (might be due to invalid IL or missing references)
//IL_0305: Unknown result type (might be due to invalid IL or missing references)
//IL_031b: Unknown result type (might be due to invalid IL or missing references)
//IL_0289: Unknown result type (might be due to invalid IL or missing references)
//IL_02ac: Unknown result type (might be due to invalid IL or missing references)
//IL_02bf: Unknown result type (might be due to invalid IL or missing references)
//IL_033b: Unknown result type (might be due to invalid IL or missing references)
//IL_035e: Unknown result type (might be due to invalid IL or missing references)
//IL_0375: Unknown result type (might be due to invalid IL or missing references)
//IL_0394: Unknown result type (might be due to invalid IL or missing references)
//IL_03b7: Unknown result type (might be due to invalid IL or missing references)
//IL_03cd: Unknown result type (might be due to invalid IL or missing references)
if (fadeAlpha <= 0f)
{
return;
}
if ((Object)(object)overlayTex == (Object)null)
{
SetupStyles();
}
GUI.color = new Color(0f, 0f, 0f, fadeAlpha);
GUI.DrawTexture(new Rect(0f, 0f, (float)Screen.width, (float)Screen.height), (Texture)(object)overlayTex);
GUI.color = Color.white;
if (isVisible)
{
float num = (float)Screen.width / 2f;
float num2 = (float)Screen.height / 2f;
float num3 = 0f;
float num4 = 0f;
if (Mathf.Sin(glitchTimer * 15f) > 0.9f)
{
num3 = Random.Range(-5f, 5f);
num4 = Random.Range(-2f, 2f);
}
GUI.color = new Color(0.6f, 0f, 0f, 0.5f);
GUI.Label(new Rect(num - 302f + num3, num2 - 148f + num4, 600f, 100f), "YOU DIED", titleStyle);
GUI.Label(new Rect(num - 298f + num3, num2 - 152f + num4, 600f, 100f), "YOU DIED", titleStyle);
GUI.color = new Color(0.85f, 0.1f, 0.1f, 1f);
GUI.Label(new Rect(num - 300f + num3, num2 - 150f + num4, 600f, 100f), "YOU DIED", titleStyle);
GUI.color = Color.white;
string text = FormatDeathCause(deathCause);
GUI.color = new Color(0.8f, 0.8f, 0.8f, 1f);
GUI.Label(new Rect(num - 300f, num2 - 50f, 600f, 50f), text, subtitleStyle);
GUI.color = Color.white;
if (respawnTimer > 0f)
{
string text2 = $"Respawning in {Mathf.CeilToInt(respawnTimer)}...";
GUI.color = new Color(1f, 1f, 1f, 0.9f);
GUI.Label(new Rect(num - 200f, num2 + 50f, 400f, 50f), text2, countdownStyle);
GUI.color = Color.white;
}
else
{
GUI.color = new Color(0.5f, 1f, 0.5f, 1f);
GUI.Label(new Rect(num - 200f, num2 + 50f, 400f, 50f), "Respawning...", countdownStyle);
GUI.color = Color.white;
}
GUI.color = new Color(0.7f, 0.7f, 0.7f, 0.8f);
GUI.Label(new Rect(num - 300f, num2 + 150f, 600f, 50f), currentTip, tipStyle);
GUI.color = Color.white;
GUI.color = new Color(0.6f, 0.6f, 0.6f, 0.7f);
GUI.Label(new Rect(num - 200f, num2 + 200f, 400f, 30f), "You will respawn with 50% health and 30% hunger.", tipStyle);
GUI.color = Color.white;
}
}
public void ShowDeathScreen(string cause)
{
isVisible = true;
deathCause = cause;
respawnTimer = SurvivalElementsPlugin.RespawnDelay.Value;
glitchTimer = 0f;
currentTip = DeathTips[Random.Range(0, DeathTips.Length)];
SurvivalElementsPlugin.Log.LogInfo((object)("Death screen shown - Cause: " + cause));
}
public void HideDeathScreen()
{
isVisible = false;
}
private string FormatDeathCause(string cause)
{
string text = cause.ToLower();
if (1 == 0)
{
}
string result = text switch
{
"starvation" => "You starved to death.",
"alien fighter" => "Killed by an Alien Fighter.",
"alien" => "Killed by hostile aliens.",
"drone" => "Destroyed by an enemy drone.",
"turret" => "Shot down by a turret.",
"radiation" => "Died from radiation exposure.",
"toxic" => "Poisoned by toxic fumes.",
"fall" => "Fell to your death.",
"explosion" => "Killed in an explosion.",
"power surge" => "Electrocuted by a power surge.",
"environmental" => "Killed by environmental hazard.",
_ => "Killed by: " + cause,
};
if (1 == 0)
{
}
return result;
}
private void SetupStyles()
{
//IL_0004: Unknown result type (might be due to invalid IL or missing references)
//IL_000e: Expected O, but got Unknown
//IL_0016: Unknown result type (might be due to invalid IL or missing references)
//IL_0060: Unknown result type (might be due to invalid IL or missing references)
//IL_009e: Unknown result type (might be due to invalid IL or missing references)
//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
//IL_011a: Unknown result type (might be due to invalid IL or missing references)
overlayTex = new Texture2D(1, 1);
overlayTex.SetPixel(0, 0, Color.black);
overlayTex.Apply();
titleStyle.fontSize = 72;
titleStyle.fontStyle = (FontStyle)1;
titleStyle.alignment = (TextAnchor)4;
titleStyle.normal.textColor = Color.white;
subtitleStyle.fontSize = 28;
subtitleStyle.fontStyle = (FontStyle)0;
subtitleStyle.alignment = (TextAnchor)4;
subtitleStyle.normal.textColor = Color.white;
countdownStyle.fontSize = 24;
countdownStyle.fontStyle = (FontStyle)1;
countdownStyle.alignment = (TextAnchor)4;
countdownStyle.normal.textColor = Color.white;
tipStyle.fontSize = 18;
tipStyle.fontStyle = (FontStyle)2;
tipStyle.alignment = (TextAnchor)4;
tipStyle.normal.textColor = Color.white;
}
}
public class MachineHealthDisplayUI : MonoBehaviour
{
private GUIStyle healthBarStyle;
private GUIStyle backgroundStyle;
private GUIStyle labelStyle;
private GUIStyle repairStyle;
private Texture2D healthTex;
private Texture2D backgroundTex;
private uint currentTargetMachine = 0u;
private string currentTargetName = "";
private float currentHealthPercent = 1f;
private bool showRepairPrompt = false;
private bool isRepairing = false;
private void Awake()
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_000c: Expected O, but got Unknown
//IL_000d: Unknown result type (might be due to invalid IL or missing references)
//IL_0017: Expected O, but got Unknown
//IL_0018: Unknown result type (might be due to invalid IL or missing references)
//IL_0022: Expected O, but got Unknown
//IL_0023: Unknown result type (might be due to invalid IL or missing references)
//IL_002d: Expected O, but got Unknown
healthBarStyle = new GUIStyle();
backgroundStyle = new GUIStyle();
labelStyle = new GUIStyle();
repairStyle = new GUIStyle();
}
private void Update()
{
UpdateTargetMachine();
HandleRepairInput();
}
private void UpdateTargetMachine()
{
//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_0058: Unknown result type (might be due to invalid IL or missing references)
//IL_0059: Unknown result type (might be due to invalid IL or missing references)
currentTargetMachine = 0u;
currentTargetName = "";
showRepairPrompt = false;
Camera main = Camera.main;
if ((Object)(object)main == (Object)null)
{
return;
}
Ray val = main.ScreenPointToRay(new Vector3((float)Screen.width / 2f, (float)Screen.height / 2f, 0f));
RaycastHit val2 = default(RaycastHit);
if (!Physics.Raycast(val, ref val2, 10f))
{
return;
}
MachineHealthTracker componentInParent = ((Component)((RaycastHit)(ref val2)).collider).GetComponentInParent<MachineHealthTracker>();
if ((Object)(object)componentInParent != (Object)null)
{
currentTargetMachine = componentInParent.MachineId;
currentTargetName = ((Object)((Component)componentInParent).gameObject).name;
(bool, float, float, float) machineHealthInfo = SurvivalElementsPlugin.GetMachineHealthInfo(componentInParent.MachineId);
if (machineHealthInfo.Item1)
{
currentHealthPercent = machineHealthInfo.Item4;
showRepairPrompt = currentHealthPercent < 1f;
}
}
}
private void HandleRepairInput()
{
if (currentTargetMachine == 0 || !showRepairPrompt)
{
return;
}
if (Input.GetButton("Fire1"))
{
if (!isRepairing)
{
isRepairing = true;
FrameworkAPI.StartMachineRepair(currentTargetMachine);
SurvivalElementsPlugin.LogDebug($"Started repairing machine {currentTargetMachine}");
}
}
else if (isRepairing)
{
isRepairing = false;
FrameworkAPI.StopMachineRepair(currentTargetMachine);
SurvivalElementsPlugin.LogDebug($"Stopped repairing machine {currentTargetMachine}");
}
}
private void OnGUI()
{
//IL_005c: Unknown result type (might be due to invalid IL or missing references)
//IL_007f: Unknown result type (might be due to invalid IL or missing references)
//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
//IL_0118: Unknown result type (might be due to invalid IL or missing references)
//IL_012e: Unknown result type (might be due to invalid IL or missing references)
//IL_016a: Unknown result type (might be due to invalid IL or missing references)
//IL_01d0: Unknown result type (might be due to invalid IL or missing references)
//IL_01ba: Unknown result type (might be due to invalid IL or missing references)
//IL_01d5: Unknown result type (might be due to invalid IL or missing references)
//IL_01d7: Unknown result type (might be due to invalid IL or missing references)
//IL_01f9: Unknown result type (might be due to invalid IL or missing references)
//IL_020c: Unknown result type (might be due to invalid IL or missing references)
if (currentTargetMachine != 0)
{
if ((Object)(object)healthTex == (Object)null)
{
SetupStyles();
}
float num = 200f;
float num2 = 16f;
float num3 = (float)Screen.width / 2f;
float num4 = (float)Screen.height / 2f - 60f;
GUI.color = Color.white;
GUI.Label(new Rect(num3 - 100f, num4 - 25f, 200f, 20f), currentTargetName, labelStyle);
GUI.color = new Color(0.1f, 0.1f, 0.1f, 0.8f);
GUI.Box(new Rect(num3 - num / 2f - 2f, num4 - 2f, num + 4f, num2 + 4f), "", backgroundStyle);
Color healthColor = GetHealthColor(currentHealthPercent);
GUI.color = healthColor;
GUI.Box(new Rect(num3 - num / 2f, num4, num * currentHealthPercent, num2), "", healthBarStyle);
GUI.color = Color.white;
string text = $"{currentHealthPercent * 100f:F0}%";
GUI.Label(new Rect(num3 - 20f, num4 - 1f, 40f, num2), text, labelStyle);
if (showRepairPrompt)
{
string text2 = (isRepairing ? "Repairing..." : "[LMB] Hold to Repair");
Color color = (isRepairing ? new Color(0.5f, 1f, 0.5f) : new Color(1f, 0.8f, 0.2f));
GUI.color = color;
GUI.Label(new Rect(num3 - 80f, num4 + num2 + 10f, 160f, 20f), text2, repairStyle);
GUI.color = Color.white;
}
}
}
private Color GetHealthColor(float percent)
{
//IL_001c: Unknown result type (might be due to invalid IL or missing references)
//IL_0021: Unknown result type (might be due to invalid IL or missing references)
//IL_0056: Unknown result type (might be due to invalid IL or missing references)
//IL_005b: Unknown result type (might be due to invalid IL or missing references)
//IL_003f: Unknown result type (might be due to invalid IL or missing references)
//IL_0044: 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)
if (percent > 0.6f)
{
return new Color(0.3f, 0.9f, 0.3f);
}
if (percent > 0.3f)
{
return new Color(1f, 0.9f, 0.2f);
}
return new Color(1f, 0.3f, 0.3f);
}
private void SetupStyles()
{
//IL_0019: Unknown result type (might be due to invalid IL or missing references)
//IL_0057: Unknown result type (might be due to invalid IL or missing references)
//IL_0088: Unknown result type (might be due to invalid IL or missing references)
//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
healthTex = MakeTexture(2, 2, new Color(0.3f, 0.8f, 0.3f, 1f));
healthBarStyle.normal.background = healthTex;
backgroundTex = MakeTexture(2, 2, new Color(0.1f, 0.1f, 0.1f, 0.85f));
backgroundStyle.normal.background = backgroundTex;
labelStyle.normal.textColor = Color.white;
labelStyle.fontSize = 14;
labelStyle.fontStyle = (FontStyle)1;
labelStyle.alignment = (TextAnchor)4;
repairStyle.normal.textColor = Color.white;
repairStyle.fontSize = 12;
repairStyle.fontStyle = (FontStyle)1;
repairStyle.alignment = (TextAnchor)4;
}
private Texture2D MakeTexture(int width, int height, Color col)
{
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
//IL_0011: 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: Expected O, but got Unknown
Color[] array = (Color[])(object)new Color[width * height];
for (int i = 0; i < array.Length; i++)
{
array[i] = col;
}
Texture2D val = new Texture2D(width, height);
val.SetPixels(array);
val.Apply();
return val;
}
}
}