using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;
using crecheng.DSPModSave;
[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.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyCompany("CraftingSpeed")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+c49796b2a6e50a369df8f487da88e3339a0da976")]
[assembly: AssemblyProduct("CraftingSpeed")]
[assembly: AssemblyTitle("CraftingSpeed")]
[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 CraftingSpeed
{
[HarmonyPatch(typeof(AssemblerComponent), "InternalUpdate")]
internal class AssemblerComponentPatcher
{
public static void Prefix(ref AssemblerComponent __instance, out PatchState __state)
{
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
//IL_000b: Invalid comparison between Unknown and I4
__state = null;
if ((int)__instance.recipeType == 4 && __instance.recipeId != 0)
{
__state = new PatchState
{
Speed = __instance.speedOverride
};
if (__instance.speedMultiplier < 1 || __instance.speedMultiplier > 100)
{
__instance.speedMultiplier = 100;
}
if (__instance.speedMultiplier != 100)
{
__instance.speedOverride = (int)((double)(__instance.speedOverride * __instance.speedMultiplier) / 100.0);
}
}
}
public static void Postfix(ref AssemblerComponent __instance, PatchState __state)
{
if (__state != null)
{
__instance.speedOverride = __state.Speed;
}
}
}
[BepInPlugin("com.github.jiesiluo.assemblerspeed", "Assembler Speed", "1.0.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class AssemblerSpeedMod : BaseUnityPlugin, IModCanSave
{
public const string pluginGuid = "com.github.jiesiluo.assemblerspeed";
public const string pluginName = "Assembler Speed";
public const string pluginVersion = "1.0.0";
public const int saveVersion = 1;
private Harmony harmony;
public void Awake()
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_0011: Expected O, but got Unknown
harmony = new Harmony("com.github.jiesiluo.assemblerspeed");
harmony.PatchAll();
}
public void Import(BinaryReader r)
{
//IL_00be: Unknown result type (might be due to invalid IL or missing references)
//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
int num = r.ReadInt32();
if (num != 1)
{
return;
}
while (true)
{
int num2 = r.ReadInt32();
int num3 = r.ReadInt32();
int num4 = r.ReadInt32();
if (num2 == -1 && num3 == -1 && num4 == -1)
{
break;
}
GameData data = GameMain.data;
if (num2 < 0 || num2 >= data.factoryCount)
{
break;
}
PlanetFactory val = data.factories[num2];
if (val == null || num3 < 0 || num3 >= val.factorySystem.assemblerCursor)
{
break;
}
AssemblerComponent val2 = val.factorySystem.assemblerPool[num3];
if (val2.id != num3 || num4 < 1 || num4 > 100)
{
break;
}
if (num4 != 100)
{
data.factories[num2].factorySystem.assemblerPool[num3].speedMultiplier = num4;
}
}
}
public void Export(BinaryWriter w)
{
//IL_0041: Unknown result type (might be due to invalid IL or missing references)
//IL_0046: Unknown result type (might be due to invalid IL or missing references)
//IL_0048: Unknown result type (might be due to invalid IL or missing references)
//IL_005e: Unknown result type (might be due to invalid IL or missing references)
//IL_0069: Unknown result type (might be due to invalid IL or missing references)
//IL_0090: Unknown result type (might be due to invalid IL or missing references)
w.Write(1);
GameData data = GameMain.data;
for (int i = 0; i < data.factoryCount; i++)
{
PlanetFactory val = data.factories[i];
if (val == null)
{
continue;
}
for (int j = 1; j < val.factorySystem.assemblerCursor; j++)
{
AssemblerComponent val2 = val.factorySystem.assemblerPool[j];
if (val2.id == j && val2.speedMultiplier < 100 && val2.speedMultiplier >= 1)
{
w.Write(i);
w.Write(j);
w.Write(val2.speedMultiplier);
}
}
}
w.Write(-1);
w.Write(-1);
w.Write(-1);
}
public void IntoOtherSave()
{
}
}
public class MySlider : MonoBehaviour
{
public Slider slider;
public RectTransform rectTrans;
public Text labelText;
public string labelFormat;
private float _value;
public float Value
{
get
{
return _value;
}
set
{
_value = value;
OnValueSet();
}
}
public event Action OnValueChanged;
public static MySlider CreateSlider(RectTransform parent)
{
//IL_004b: Unknown result type (might be due to invalid IL or missing references)
//IL_0052: Expected O, but got Unknown
//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_0084: Unknown result type (might be due to invalid IL or missing references)
//IL_017b: Unknown result type (might be due to invalid IL or missing references)
//IL_01db: Unknown result type (might be due to invalid IL or missing references)
//IL_021e: Unknown result type (might be due to invalid IL or missing references)
UIOptionWindow optionWindow = UIRoot.instance.optionWindow;
Slider audioVolumeComp = optionWindow.audioVolumeComp;
GameObject val = Object.Instantiate<GameObject>(((Component)audioVolumeComp).gameObject);
((Object)val).name = "assemblerSpeedMultiplierSlider";
val.SetActive(true);
MySlider mySlider = val.AddComponent<MySlider>();
mySlider._value = 100f;
RectTransform val2 = (RectTransform)((Component)mySlider).transform;
((Transform)val2).SetParent((Transform)(object)parent, false);
val2.anchoredPosition = Vector2.op_Implicit(new Vector3(310f, 220f));
val2.sizeDelta = new Vector2(150f, 20f);
mySlider.slider = val.GetComponent<Slider>();
mySlider.slider.minValue = 1f;
mySlider.slider.maxValue = 100f;
mySlider.slider.value = 100f;
mySlider.slider.wholeNumbers = true;
((UnityEventBase)mySlider.slider.onValueChanged).RemoveAllListeners();
((UnityEvent<float>)(object)mySlider.slider.onValueChanged).AddListener((UnityAction<float>)mySlider.SliderChanged);
Transform obj = ((Transform)mySlider.slider.handleRect).Find("Text");
mySlider.labelText = ((obj != null) ? ((Component)obj).GetComponent<Text>() : null);
if ((Object)(object)mySlider.labelText != (Object)null)
{
mySlider.labelText.fontSize = 14;
Transform transform = ((Component)mySlider.labelText).transform;
RectTransform val3 = (RectTransform)(object)((transform is RectTransform) ? transform : null);
if (val3 != null)
{
val3.sizeDelta = new Vector2(22f, 22f);
}
}
mySlider.labelFormat = "G";
Transform obj2 = ((Component)mySlider.slider).transform.Find("Background");
Image val4 = ((obj2 != null) ? ((Component)obj2).GetComponent<Image>() : null);
if ((Object)(object)val4 != (Object)null)
{
((Graphic)val4).color = new Color(0.5f, 0.5f, 0.5f, 0.5f);
}
Image component = ((Component)mySlider.slider.fillRect).GetComponent<Image>();
if ((Object)(object)component != (Object)null)
{
((Graphic)component).color = new Color(1f, 1f, 1f, 0.28f);
}
mySlider.OnValueSet();
mySlider.UpdateLabel();
return mySlider;
}
public void OnValueSet()
{
lock (this)
{
float num = _value;
if (!num.Equals(slider.value))
{
if (num > slider.maxValue)
{
num = (_value = slider.maxValue);
}
else if (num < slider.minValue)
{
num = (_value = slider.minValue);
}
slider.value = num;
UpdateLabel();
}
}
}
public void UpdateLabel()
{
if ((Object)(object)labelText != (Object)null)
{
labelText.text = _value.ToString(labelFormat);
}
}
public void SetLabelText(string text)
{
if ((Object)(object)labelText != (Object)null)
{
labelText.text = text;
}
}
public void SliderChanged(float val)
{
lock (this)
{
float num = Mathf.Round(slider.value);
if (!_value.Equals(num))
{
_value = num;
UpdateLabel();
this.OnValueChanged?.Invoke();
}
}
}
}
public class PatchState
{
public int Speed;
}
[HarmonyPatch(typeof(UIAssemblerWindow))]
internal class Patch_UIAssemblerWindow
{
public static MySlider slider;
private static ManualLogSource logger;
[HarmonyPostfix]
[HarmonyPatch("_OnInit")]
public static void Patch_OnInit(UIAssemblerWindow __instance)
{
//IL_0032: Unknown result type (might be due to invalid IL or missing references)
//IL_0038: Expected O, but got Unknown
logger = Logger.CreateLogSource("Crafting Speed Mod");
UIAssemblerWindow assemblerWindow = UIRoot.instance.uiGame.assemblerWindow;
GameObject val = new GameObject("slider");
slider = MySlider.CreateSlider(assemblerWindow.windowTrans);
HideSlider(__instance);
slider.OnValueChanged += delegate
{
UpdateSpeedMultiplierPerSlider(__instance);
};
}
private static bool ShouldShowSlider(UIAssemblerWindow __instance)
{
//IL_0042: Unknown result type (might be due to invalid IL or missing references)
//IL_0047: Unknown result type (might be due to invalid IL or missing references)
//IL_0048: Unknown result type (might be due to invalid IL or missing references)
//IL_0066: Unknown result type (might be due to invalid IL or missing references)
//IL_0067: Unknown result type (might be due to invalid IL or missing references)
//IL_006d: Invalid comparison between Unknown and I4
//IL_006f: 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_0091: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)__instance == (Object)null || !((ManualBehaviour)__instance).active || __instance.assemblerId == 0 || __instance.factory == null)
{
return false;
}
AssemblerComponent val = __instance.factorySystem.assemblerPool[__instance.assemblerId];
if (val.id != __instance.assemblerId)
{
return false;
}
if ((int)val.recipeType != 4 || val.recipeId == 0)
{
return false;
}
if (val.speedMultiplier < 1 || val.speedMultiplier > 100)
{
__instance.factorySystem.assemblerPool[__instance.assemblerId].speedMultiplier = 100;
}
int num = (int)slider.Value;
if (num < 1 || num > 100)
{
slider.Value = 100f;
}
((Component)slider).gameObject.SetActive(true);
return true;
}
private static void UpdateSpeedMultiplierPerSlider(UIAssemblerWindow __instance)
{
int speedMultiplier = (int)slider.Value;
__instance.factorySystem.assemblerPool[__instance.assemblerId].speedMultiplier = speedMultiplier;
}
private static void UpdateSliderPerSpeedMultiplier(UIAssemblerWindow __instance)
{
int speedMultiplier = __instance.factorySystem.assemblerPool[__instance.assemblerId].speedMultiplier;
slider.Value = __instance.factorySystem.assemblerPool[__instance.assemblerId].speedMultiplier;
}
private static void HideSlider(UIAssemblerWindow __instance)
{
((Component)slider).gameObject.SetActive(false);
}
private static void ShowSlider(UIAssemblerWindow __instance)
{
((Component)slider).gameObject.SetActive(true);
}
[HarmonyPostfix]
[HarmonyPatch("_OnClose")]
public static void Patch_OnClose(UIAssemblerWindow __instance)
{
slider.Value = 100f;
HideSlider(__instance);
}
[HarmonyPostfix]
[HarmonyPatch("OnServingBoxChange")]
public static void Patch_OnServingBoxChange(UIAssemblerWindow __instance)
{
if (!((Object)(object)__instance == (Object)null))
{
HideSlider(__instance);
if (ShouldShowSlider(__instance))
{
ShowSlider(__instance);
UpdateSliderPerSpeedMultiplier(__instance);
}
}
}
}
}