using System;
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.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using HarmonyLib;
using Il2CppSystem.Collections.Generic;
using Microsoft.CodeAnalysis;
using Sons.Items.Core;
using UnityEngine;
using UnityEngine.Localization;
using UnityEngine.Localization.Settings;
using UnityEngine.Localization.Tables;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[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 PrintableAmmo
{
[BepInPlugin("local.printableammo", "PrintableAmmo", "0.1.0")]
public class Plugin : BasePlugin
{
public const string PluginGuid = "local.printableammo";
public const string PluginName = "PrintableAmmo";
public const string PluginVersion = "0.1.0";
internal static ManualLogSource Log;
internal static AmmoSettings Pistol;
internal static AmmoSettings Slug;
internal static AmmoSettings Buckshot;
internal static ConfigEntry<float> Spacing;
public override void Load()
{
//IL_009b: Unknown result type (might be due to invalid IL or missing references)
//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
//IL_00be: Expected O, but got Unknown
Log = ((BasePlugin)this).Log;
Pistol = new AmmoSettings(((BasePlugin)this).Config, "PistolAmmo", "Pistol / revolver ammo", 10, 50, 45f);
Slug = new AmmoSettings(((BasePlugin)this).Config, "SlugAmmo", "Shotgun slug ammo", 6, 50, 45f);
Buckshot = new AmmoSettings(((BasePlugin)this).Config, "BuckshotAmmo", "Shotgun buckshot ammo", 6, 50, 45f);
Spacing = ((BasePlugin)this).Config.Bind<float>("General", "BedSpacing", 0.05f, "Odleglosc miedzy wydrukowanymi sztukami na platformie drukarki (zmien, jesli sie nakladaja).");
new Harmony("local.printableammo").PatchAll(typeof(PrinterPatch));
ManualLogSource log = Log;
bool flag = default(bool);
BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(8, 2, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("PrintableAmmo");
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("0.1.0");
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" loaded");
}
log.LogInfo(val);
}
}
internal class AmmoSettings
{
public readonly ConfigEntry<bool> Enabled;
public readonly ConfigEntry<int> Amount;
public readonly ConfigEntry<int> ResinCost;
public readonly ConfigEntry<float> PrintTime;
public readonly string Section;
public readonly string DisplayName;
public AmmoSettings(ConfigFile cfg, string section, string displayName, int amount, int resin, float time)
{
Section = section;
DisplayName = displayName;
Enabled = cfg.Bind<bool>(section, "Enabled", true, "Dodaj '" + displayName + "' do drukarki 3D");
Amount = cfg.Bind<int>(section, "Amount", amount, "Ile sztuk powstaje z jednego wydruku");
ResinCost = cfg.Bind<int>(section, "ResinCost", resin, "Koszt zywicy jednego wydruku");
PrintTime = cfg.Bind<float>(section, "PrintTime", time, "Czas wydruku (sekundy)");
}
}
internal static class PrinterPatch
{
private const int IdPistol = 9101;
private const int IdSlug = 9102;
private const int IdBuckshot = 9103;
[HarmonyPatch(typeof(Resin3dPrinterLaptop), "Start")]
[HarmonyPostfix]
private static void AddBlueprints(Resin3dPrinterLaptop __instance)
{
//IL_008c: Unknown result type (might be due to invalid IL or missing references)
//IL_0092: Expected O, but got Unknown
try
{
List<PrintedItemBlueprint> availableBlueprints = __instance._availableBlueprints;
if (availableBlueprints == null || availableBlueprints.Count == 0)
{
Plugin.Log.LogWarning((object)"Laptop drukarki nie ma zadnej receptury - nie mam z czego sklonowac szablonu.");
return;
}
PrintedItemBlueprint template = availableBlueprints[0];
TryAdd(availableBlueprints, template, 9101, "3D_PISTOL_AMMO", Plugin.Pistol, ItemDatabase.PistolAmmoId);
TryAdd(availableBlueprints, template, 9102, "3D_SLUG_AMMO", Plugin.Slug, ItemDatabase.SlugAmmoId);
TryAdd(availableBlueprints, template, 9103, "3D_BUCKSHOT_AMMO", Plugin.Buckshot, ItemDatabase.BuckshotAmmoId);
}
catch (Exception ex)
{
ManualLogSource log = Plugin.Log;
bool flag = default(bool);
BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(15, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("AddBlueprints: ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<Exception>(ex);
}
log.LogError(val);
}
}
private static void TryAdd(List<PrintedItemBlueprint> list, PrintedItemBlueprint template, int id, string key, AmmoSettings s, int itemId)
{
//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
//IL_01c0: Expected O, but got Unknown
//IL_0060: Unknown result type (might be due to invalid IL or missing references)
//IL_0067: Expected O, but got Unknown
//IL_0295: Unknown result type (might be due to invalid IL or missing references)
//IL_02d0: Unknown result type (might be due to invalid IL or missing references)
//IL_02d7: Expected O, but got Unknown
//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
//IL_00fe: Expected O, but got Unknown
//IL_0173: Unknown result type (might be due to invalid IL or missing references)
//IL_017a: Expected O, but got Unknown
if (!s.Enabled.Value)
{
return;
}
for (int i = 0; i < list.Count; i++)
{
if ((Object)(object)list[i] != (Object)null && list[i]._id == id)
{
return;
}
}
ItemData val = ItemDatabaseManager.ItemById(itemId);
bool flag = default(bool);
if ((Object)(object)val == (Object)null)
{
ManualLogSource log = Plugin.Log;
BepInExWarningLogInterpolatedStringHandler val2 = new BepInExWarningLogInterpolatedStringHandler(35, 2, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Nie znaleziono przedmiotu id=");
((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<int>(itemId);
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" dla ");
((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(s.DisplayName);
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(".");
}
log.LogWarning(val2);
return;
}
PrintedItemBlueprint val3 = Object.Instantiate<PrintedItemBlueprint>(template);
((Object)val3).name = key;
((Object)val3).hideFlags = (HideFlags)61;
val3._id = id;
val3._name = s.DisplayName;
val3._translationKey = key;
if ((Object)(object)val.PickupPrefab == (Object)null)
{
ManualLogSource log2 = Plugin.Log;
BepInExWarningLogInterpolatedStringHandler val2 = new BepInExWarningLogInterpolatedStringHandler(18, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Brak prefabu dla ");
((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(s.DisplayName);
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(".");
}
log2.LogWarning(val2);
return;
}
val3._printedItem = ((Component)val.PickupPrefab).gameObject;
try
{
ItemUiData uiData = val.UiData;
Texture val4 = ((uiData != null) ? uiData._icon : null);
if ((Object)(object)val4 != (Object)null)
{
val3._iconTexture = val4;
}
else
{
ManualLogSource log3 = Plugin.Log;
BepInExWarningLogInterpolatedStringHandler val2 = new BepInExWarningLogInterpolatedStringHandler(16, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Brak ikony dla ");
((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(s.DisplayName);
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(".");
}
log3.LogWarning(val2);
}
}
catch (Exception ex)
{
ManualLogSource log4 = Plugin.Log;
BepInExWarningLogInterpolatedStringHandler val2 = new BepInExWarningLogInterpolatedStringHandler(24, 2, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Ikona '");
((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(s.DisplayName);
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("' nie ustawiona: ");
((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(ex.Message);
}
log4.LogWarning(val2);
}
val3._requiredResinVolume = s.ResinCost.Value;
val3._totalPrintTime = s.PrintTime.Value;
List<Vector3> val5 = new List<Vector3>();
int num = Math.Max(1, s.Amount.Value);
int num2 = 3;
int num3 = (num + num2 - 1) / num2;
float value = Plugin.Spacing.Value;
for (int j = 0; j < num; j++)
{
float num4 = ((float)(j % num2) - (float)(num2 - 1) / 2f) * value;
float num5 = ((float)(j / num2) - (float)(num3 - 1) / 2f) * value;
val5.Add(new Vector3(num4, 0f, num5));
}
val3._positions = val5;
AddTranslation(val3, key, s.DisplayName);
list.Add(val3);
ManualLogSource log5 = Plugin.Log;
BepInExInfoLogInterpolatedStringHandler val6 = new BepInExInfoLogInterpolatedStringHandler(20, 2, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val6).AppendLiteral("Dodano recepture: ");
((BepInExLogInterpolatedStringHandler)val6).AppendFormatted<string>(s.DisplayName);
((BepInExLogInterpolatedStringHandler)val6).AppendLiteral(" x");
((BepInExLogInterpolatedStringHandler)val6).AppendFormatted<int>(num);
}
log5.LogInfo(val6);
}
private static void AddTranslation(PrintedItemBlueprint bp, string key, string text)
{
//IL_0040: Unknown result type (might be due to invalid IL or missing references)
//IL_0046: Expected O, but got Unknown
try
{
StringTable table = ((LocalizedDatabase<StringTable, StringTableEntry>)(object)LocalizationSettings.StringDatabase).GetTable(TableReference.op_Implicit(PrintedItemBlueprint.ItemsTableReference), (Locale)null);
if (!((Object)(object)table == (Object)null) && ((DetailedLocalizationTable<StringTableEntry>)(object)table).GetEntry(key) == null)
{
((DetailedLocalizationTable<StringTableEntry>)(object)table).AddEntry(key, text);
}
}
catch (Exception ex)
{
ManualLogSource log = Plugin.Log;
bool flag = default(bool);
BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(27, 2, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Tlumaczenie '");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(key);
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("' nie dodane: ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex.Message);
}
log.LogWarning(val);
}
}
}
}