using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Threading.Tasks;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using ExitGames.Client.Photon;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using Photon.Realtime;
using UnityEngine;
using UnityEngine.SceneManagement;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("CustomPaintings")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+f1989f898e2eafb0a46ef0fdffeea9e6ae271875")]
[assembly: AssemblyProduct("CustomPaintings")]
[assembly: AssemblyTitle("CustomPaintings")]
[assembly: AssemblyVersion("1.0.0.0")]
[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 CustomPaintings
{
[BepInPlugin("UnderratedJunk.CustomPaintings", "CustomPaintings", "1.1.4")]
public class CustomPaintings : BaseUnityPlugin
{
[HarmonyPatch(typeof(LoadingUI), "LevelAnimationComplete")]
public class PaintingSwapPatch
{
private static void Postfix()
{
Task.Run(async delegate
{
int waited = 0;
int interval = 50;
while (!receivedSeed.HasValue && waited < maxWaitTimeMs)
{
await Task.Delay(interval);
waited += interval;
}
if (receivedSeed.HasValue)
{
logger.LogInfo($"[Postfix] Client using received seed: {receivedSeed.Value}");
CustomPaintingsSwap.ReceivedSeed = receivedSeed.Value;
receivedSeed = null;
}
swapper.ReplacePaintings();
});
}
private static void Prefix()
{
if (swapper.GetModState() == CustomPaintingsSwap.ModState.Client)
{
PhotonNetwork.AddCallbackTarget((object)sync);
}
if (swapper.GetModState() == CustomPaintingsSwap.ModState.Host)
{
CustomPaintingsSwap.HostSeed = Random.Range(0, int.MaxValue);
logger.LogInfo($"Generated Hostseed: {CustomPaintingsSwap.HostSeed}");
PhotonNetwork.AddCallbackTarget((object)sync);
sync.SendSeed(CustomPaintingsSwap.HostSeed);
if (CustomPaintingsConfig.SeperateImages.Value)
{
sync.SendSeperateState("on");
}
else if (!CustomPaintingsConfig.SeperateImages.Value)
{
sync.SendSeperateState("off");
}
}
loader.UpdateGrungeMaterialParameters();
}
}
[HarmonyPatch(typeof(NetworkConnect), "TryJoiningRoom")]
public class JoinLobbyPatch
{
private static void Prefix()
{
if (swapper.GetModState() != 0)
{
swapper.SetState(CustomPaintingsSwap.ModState.Client);
}
}
}
[HarmonyPatch(typeof(SteamManager), "HostLobby")]
public class HostLobbyPatch
{
private static bool Prefix()
{
swapper.SetState(CustomPaintingsSwap.ModState.Host);
return true;
}
}
[HarmonyPatch(typeof(SteamManager), "LeaveLobby")]
public class LeaveLobbyPatch
{
private static void Postfix()
{
PhotonNetwork.RemoveCallbackTarget((object)sync);
swapper.SetState(CustomPaintingsSwap.ModState.SinglePlayer);
CustomPaintingsSwap.SeperateState = "Singleplayer";
}
}
private static Logger logger;
private static CustomPaintingsLoader loader;
private static CustomPaintingsSwap swapper;
private static CustomPaintingsSync sync;
private static CustomPaintingsGroupList grouper;
private static CustomPaintingsConfig configfile;
public static int? receivedSeed = null;
public static readonly int maxWaitTimeMs = 1000;
private readonly Harmony harmony = new Harmony("UnderratedJunk.CustomPaintings");
private void Awake()
{
logger = new Logger("CustomPaintings");
logger.LogInfo("CustomPaintings mod initialized.");
CustomPaintingsConfig.Init(((BaseUnityPlugin)this).Config);
loader = new CustomPaintingsLoader(logger);
loader.LoadImagesFromAllPlugins();
configfile = new CustomPaintingsConfig();
grouper = new CustomPaintingsGroupList(logger);
swapper = new CustomPaintingsSwap(logger, loader, grouper);
sync = new CustomPaintingsSync(logger);
harmony.PatchAll();
}
}
public class CustomPaintingsConfig
{
internal static class Grunge
{
internal static ConfigEntry<bool> State;
internal static ConfigEntry<float> Intensity;
internal static ConfigEntry<Color> _BaseColor;
internal static ConfigEntry<Color> _MainColor;
internal static ConfigEntry<Color> _CracksColor;
internal static ConfigEntry<Color> _OutlineColor;
}
internal static class Graphics
{
internal static ConfigEntry<bool> PointFiltering;
}
public static ConfigEntry<bool> HostControl;
public static ConfigEntry<bool> SeperateImages;
public static ConfigEntry<bool> ChaosMode;
internal static void Init(ConfigFile config)
{
//IL_0017: Unknown result type (might be due to invalid IL or missing references)
//IL_0021: Expected O, but got Unknown
//IL_003d: Unknown result type (might be due to invalid IL or missing references)
//IL_0047: Expected O, but got Unknown
//IL_0063: Unknown result type (might be due to invalid IL or missing references)
//IL_006d: Expected O, but got Unknown
//IL_0089: Unknown result type (might be due to invalid IL or missing references)
//IL_0093: Expected O, but got Unknown
//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
//IL_00cb: Expected O, but got Unknown
//IL_00ef: 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_0109: Expected O, but got Unknown
//IL_012d: Unknown result type (might be due to invalid IL or missing references)
//IL_013d: Unknown result type (might be due to invalid IL or missing references)
//IL_0147: Expected O, but got Unknown
//IL_016b: 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_0185: Expected O, but got Unknown
//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
//IL_01c3: Expected O, but got Unknown
//IL_01df: Unknown result type (might be due to invalid IL or missing references)
//IL_01e9: Expected O, but got Unknown
HostControl = config.Bind<bool>("Image Settings", "Host Control", true, new ConfigDescription("choose if host controls seperate state", (AcceptableValueBase)null, Array.Empty<object>()));
SeperateImages = config.Bind<bool>("Image Settings", "Seperate paintings", false, new ConfigDescription("seperate square, landscape and portrait images on swap", (AcceptableValueBase)null, Array.Empty<object>()));
ChaosMode = config.Bind<bool>("Image Settings", "Chaos Mode", false, new ConfigDescription("adds a bunch of materials that shouldn't be changed to the pool", (AcceptableValueBase)null, Array.Empty<object>()));
Grunge.State = config.Bind<bool>("Grunge", "Grunge state", true, new ConfigDescription("Whether the grunge effect is enabled", (AcceptableValueBase)null, Array.Empty<object>()));
Grunge.Intensity = config.Bind<float>("Grunge", "Grunge intensity", 0.5f, new ConfigDescription("change how intense the grunge is applied", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.01f, 2f), Array.Empty<object>()));
Grunge._BaseColor = config.Bind<Color>("Grunge", "_GrungeBaseColor", new Color(0f, 0f, 0f, 1f), new ConfigDescription("The base color of the grunge", (AcceptableValueBase)null, Array.Empty<object>()));
Grunge._MainColor = config.Bind<Color>("Grunge", "_GrungeMainColor", new Color(0f, 0f, 0f, 0.5f), new ConfigDescription("The color of the main overlay of grunge", (AcceptableValueBase)null, Array.Empty<object>()));
Grunge._CracksColor = config.Bind<Color>("Grunge", "_GrungeCracksColor", new Color(0.25f, 0.25f, 0.25f, 1f), new ConfigDescription("The color of the cracks in the grunge", (AcceptableValueBase)null, Array.Empty<object>()));
Grunge._OutlineColor = config.Bind<Color>("Grunge", "_GrungeOutlineColor", new Color(0f, 0f, 0f, 1f), new ConfigDescription("The color of the grunge outlining the painting", (AcceptableValueBase)null, Array.Empty<object>()));
Graphics.PointFiltering = config.Bind<bool>("Graphics", "PointFiltering", true, new ConfigDescription("Point filtering will match the pixelated effect the game has", (AcceptableValueBase)null, Array.Empty<object>()));
}
}
public class CustomPaintingsGroupList
{
private readonly Logger logger;
public static readonly Dictionary<string, List<string>> MaterialNameToGroup = new Dictionary<string, List<string>>(StringComparer.OrdinalIgnoreCase)
{
{
"Painting_H_Landscape",
new List<string> { "Landscape", "Normal", "Chaos" }
},
{
"Painting_H_crow",
new List<string> { "Landscape", "Normal", "Chaos" }
},
{
"Painting_H_crow_0",
new List<string> { "Landscape", "Normal", "Chaos" }
},
{
"PaintingMedium",
new List<string> { "Landscape", "Normal", "Chaos" }
},
{
"Painting_Danish_Flag",
new List<string> { "Landscape", "Normal", "Chaos" }
},
{
"Painting_Board",
new List<string> { "Landscape", "Normal", "Chaos" }
},
{
"Painting Danish Flag",
new List<string> { "Landscape", "Normal", "Chaos" }
},
{
"Painting Board",
new List<string> { "Landscape", "Normal", "Chaos" }
},
{
"Shop Outside Billboard Ad",
new List<string> { "Landscape", "Normal", "Chaos" }
},
{
"Painting_S_Creep",
new List<string> { "Square", "Normal", "Chaos" }
},
{
"Painting_S_Creep 2_0",
new List<string> { "Square", "Normal", "Chaos" }
},
{
"Painting_S_Creep 2",
new List<string> { "Square", "Normal", "Chaos" }
},
{
"Painting Wizard Class",
new List<string> { "Square", "Normal", "Chaos" }
},
{
"Picture Frame - Picture 01",
new List<string> { "Square", "Normal", "Chaos" }
},
{
"Painting_Aurora",
new List<string> { "Square", "Normal", "Chaos" }
},
{
"Painting_McJannek",
new List<string> { "Square", "Normal", "Chaos" }
},
{
"Painting Aurora",
new List<string> { "Square", "Normal", "Chaos" }
},
{
"Painting McJannek",
new List<string> { "Square", "Normal", "Chaos" }
},
{
"Painting_V_jannk",
new List<string> { "Portrait", "Normal", "Chaos" }
},
{
"Painting_V_Furman",
new List<string> { "Portrait", "Normal", "Chaos" }
},
{
"Painting_V_surrealistic",
new List<string> { "Portrait", "Normal", "Chaos" }
},
{
"Painting_V_surrealistic_0",
new List<string> { "Portrait", "Normal", "Chaos" }
},
{
"painting teacher01",
new List<string> { "Portrait", "Normal", "Chaos" }
},
{
"painting teacher02",
new List<string> { "Portrait", "Normal", "Chaos" }
},
{
"painting teacher03",
new List<string> { "Portrait", "Normal", "Chaos" }
},
{
"painting teacher04",
new List<string> { "Portrait", "Normal", "Chaos" }
},
{
"Painting_S_Tree",
new List<string> { "Portrait", "Normal", "Chaos" }
},
{
"Painting Calendar",
new List<string> { "Portrait", "Normal", "Chaos" }
},
{
"Magazine01",
new List<string> { "Portrait", "Normal", "Chaos" }
},
{
"Magazine02",
new List<string> { "Portrait", "Normal", "Chaos" }
},
{
"Magazine03",
new List<string> { "Portrait", "Normal", "Chaos" }
},
{
"Magazine04",
new List<string> { "Portrait", "Normal", "Chaos" }
},
{
"Magazine05",
new List<string> { "Portrait", "Normal", "Chaos" }
},
{
"Valuable_Painting",
new List<string> { "Portrait", "Normal", "Chaos" }
},
{
"regular material 01",
new List<string> { "Chaos", "Square" }
},
{
"Arctic Sign Accounting",
new List<string> { "Chaos", "Landscape" }
},
{
"Arctic Sign Bathroom",
new List<string> { "Chaos", "Landscape" }
},
{
"Arctic Sign Botanical Research",
new List<string> { "Chaos", "Landscape" }
},
{
"Arctic Sign Brige 4B",
new List<string> { "Chaos", "Landscape" }
},
{
"Arctic Sign Brige 8N",
new List<string> { "Chaos", "Landscape" }
},
{
"Arctic Sign Cafeteria",
new List<string> { "Chaos", "Landscape" }
},
{
"Arctic Sign Cargo processing",
new List<string> { "Chaos", "Landscape" }
},
{
"Arctic Sign Catwalk L5",
new List<string> { "Chaos", "Landscape" }
},
{
"Arctic Sign Cooling Center",
new List<string> { "Chaos", "Landscape" }
},
{
"Arctic Sign Epsilon Station",
new List<string> { "Chaos", "Landscape" }
},
{
"Arctic Sign Exotic Materials Division",
new List<string> { "Chaos", "Landscape" }
},
{
"Arctic Sign Infirmary",
new List<string> { "Chaos", "Landscape" }
},
{
"Arctic Sign Kitchen",
new List<string> { "Chaos", "Landscape" }
},
{
"Arctic Sign Living Quarters",
new List<string> { "Chaos", "Landscape" }
},
{
"Arctic Sign Loading Dock",
new List<string> { "Chaos", "Landscape" }
},
{
"Arctic Sign Maintenance2",
new List<string> { "Chaos", "Landscape" }
},
{
"Arctic Sign Observation Platform",
new List<string> { "Chaos", "Landscape" }
},
{
"Arctic Sign Recreation",
new List<string> { "Chaos", "Landscape" }
},
{
"Arctic Sign Research Lab",
new List<string> { "Chaos", "Landscape" }
},
{
"Arctic Sign Storage Yard",
new List<string> { "Chaos", "Landscape" }
},
{
"Arctic Sign Testing Lab",
new List<string> { "Chaos", "Landscape" }
},
{
"Arctic Sign Vehicle Maintenance",
new List<string> { "Chaos", "Landscape" }
},
{
"Arctic Sign Ventilation Chamber",
new List<string> { "Chaos", "Landscape" }
},
{
"Arctic Sign Warehouse",
new List<string> { "Chaos", "Landscape" }
},
{
"Arctic Sign",
new List<string> { "Chaos", "Landscape" }
},
{
"Lobby Sign - Closed Road",
new List<string> { "Chaos", "Square" }
},
{
"Lobby Sign - No stopping",
new List<string> { "Chaos", "Square" }
},
{
"Robot Company Sign 2",
new List<string> { "Chaos", "Square" }
},
{
"Robot Company Sign 3",
new List<string> { "Chaos", "Landscape" }
},
{
"Robot Company Sign 4",
new List<string> { "Chaos", "Portrait" }
},
{
"Robot Company Sign 5",
new List<string> { "Chaos", "Landscape" }
},
{
"Robot Company Sign 6",
new List<string> { "Chaos", "Portrait" }
},
{
"Robot Company Sign 7",
new List<string> { "Chaos", "Square" }
},
{
"Robot Company Sign",
new List<string> { "Chaos", "Square" }
},
{
"Wizard Sign Cauldron Storage",
new List<string> { "Chaos", "Landscape" }
},
{
"Wizard Sign Common Room",
new List<string> { "Chaos", "Landscape" }
},
{
"Wizard Sign Courtyard",
new List<string> { "Chaos", "Landscape" }
},
{
"Wizard Sign Dark Arts",
new List<string> { "Chaos", "Landscape" }
},
{
"Wizard Sign Deathpit Corridor",
new List<string> { "Chaos", "Landscape" }
},
{
"Wizard Sign Dining Hall",
new List<string> { "Chaos", "Landscape" }
},
{
"Wizard Sign Dormatory",
new List<string> { "Chaos", "Landscape" }
},
{
"Wizard Sign Dungeon",
new List<string> { "Chaos", "Landscape" }
},
{
"Wizard Sign East Wing Lobby",
new List<string> { "Chaos", "Landscape" }
},
{
"Wizard Sign Enchanted Lava Room",
new List<string> { "Chaos", "Landscape" }
},
{
"Wizard Sign Gnome Alley",
new List<string> { "Chaos", "Landscape" }
},
{
"Wizard Sign Headmasters Study",
new List<string> { "Chaos", "Landscape" }
},
{
"Wizard Sign Lecture Hall",
new List<string> { "Chaos", "Landscape" }
},
{
"Wizard Sign Magic Plant School",
new List<string> { "Chaos", "Landscape" }
},
{
"Wizard Sign Potions And Spells",
new List<string> { "Chaos", "Landscape" }
},
{
"Wizard Sign Relaxation Room",
new List<string> { "Chaos", "Landscape" }
},
{
"Wizard Sign Sludge Pits of Joy",
new List<string> { "Chaos", "Landscape" }
},
{
"Wizard Sign Sludge Pits",
new List<string> { "Chaos", "Landscape" }
},
{
"Wizard Sign Sorcery Class",
new List<string> { "Chaos", "Landscape" }
},
{
"Wizard Sign Storage Room",
new List<string> { "Chaos", "Landscape" }
},
{
"Wizard Sign The Great Library",
new List<string> { "Chaos", "Landscape" }
},
{
"Wizard Sign Thinking Chamber",
new List<string> { "Chaos", "Landscape" }
},
{
"Wizard Sign West Wing Garden",
new List<string> { "Chaos", "Landscape" }
},
{
"Rug",
new List<string> { "Chaos", "Square" }
},
{
"Rug Plain Red",
new List<string> { "Chaos", "Landscape" }
},
{
"shop rug",
new List<string> { "Chaos", "Square" }
},
{
"Bathroom Rug",
new List<string> { "Chaos", "Square" }
},
{
"Wizard Wall Flag",
new List<string> { "Chaos", "Portrait" }
},
{
"upgrade_throw",
new List<string> { "Chaos", "Landscape" }
},
{
"upgrade_strength",
new List<string> { "Chaos", "Landscape" }
},
{
"upgrade_speed",
new List<string> { "Chaos", "Landscape" }
},
{
"upgrade_health",
new List<string> { "Chaos", "Landscape" }
},
{
"upgrade_grab range",
new List<string> { "Chaos", "Landscape" }
},
{
"upgrade_energy",
new List<string> { "Chaos", "Landscape" }
},
{
"upgrade_tumble_launch",
new List<string> { "Chaos", "Landscape" }
},
{
"upgrade_map_player_count",
new List<string> { "Chaos", "Landscape" }
},
{
"upgrade_extra_jump",
new List<string> { "Chaos", "Landscape" }
},
{
"Welcome_Flag_Front",
new List<string> { "Chaos", "Landscape" }
},
{
"Welcome_Flag_Back",
new List<string> { "Chaos", "Landscape" }
},
{
"Wizard Door Double",
new List<string> { "Chaos", "Portrait" }
},
{
"Wizard Door Double Blocked",
new List<string> { "Chaos", "Portrait" }
},
{
"Wizard Door Double Blocked Lock",
new List<string> { "Chaos", "Portrait" }
},
{
"Door Wizard",
new List<string> { "Chaos", "Portrait" }
},
{
"Shop Door",
new List<string> { "Chaos", "Portrait" }
},
{
"Door Shop WC",
new List<string> { "Chaos", "Portrait" }
},
{
"Garage Door",
new List<string> { "Chaos", "Landscape" }
},
{
"Arctic Door",
new List<string> { "Chaos", "Portrait" }
},
{
"Arctic Door Blocked",
new List<string> { "Chaos", "Portrait" }
},
{
"Museum Door",
new List<string> { "Chaos", "Portrait" }
},
{
"door base",
new List<string> { "Chaos", "Portrait" }
}
};
public CustomPaintingsGroupList(Logger logger)
{
this.logger = logger;
}
}
public class CustomPaintingsLoader
{
private const string IMAGE_FOLDER_NAME = "CustomPaintings";
private readonly Logger logger;
public Dictionary<string, List<Material>> MaterialGroups = new Dictionary<string, List<Material>>();
private const string GRUNGE_ASSET_BUNDLE = "GrungeAssets";
private const string MATERIAL_LANDSCAPE_ASSET_NAME = "GrungeHorizontalMaterial";
private const string MATERIAL_PORTRAIT_ASSET_NAME = "GrungeVerticalMaterial";
private static Material _LandscapeMaterial;
private static Material _PortraitMaterial;
public List<Material> LoadedMaterials { get; } = new List<Material>();
public CustomPaintingsLoader(Logger logger)
{
this.logger = logger;
}
public void LoadImagesFromAllPlugins()
{
string text = Path.Combine(Paths.PluginPath);
if (!Directory.Exists(text))
{
logger.LogWarning("Plugins directory not found: " + text);
return;
}
string[] directories = Directory.GetDirectories(text, "CustomPaintings", SearchOption.AllDirectories);
LoadGrungeMaterials();
BindConfigUpdates();
if (directories.Length == 0)
{
logger.LogWarning("No 'CustomPaintings' folders found in plugins.");
return;
}
string[] array = directories;
foreach (string text2 in array)
{
logger.LogInfo("Loading images from: " + text2);
LoadImagesFromDirectory(text2);
}
}
private void LoadImagesFromDirectory(string directoryPath)
{
if (!Directory.Exists(directoryPath))
{
logger.LogWarning("Directory does not exist: " + directoryPath);
return;
}
string[] validExtensions = new string[4] { ".png", ".jpg", ".jpeg", ".bmp" };
string[] array = (from file in Directory.EnumerateFiles(directoryPath, "*.*", SearchOption.AllDirectories)
where validExtensions.Contains(Path.GetExtension(file).ToLower())
select file).ToArray();
if (array.Length == 0)
{
logger.LogWarning("No images found in " + directoryPath);
return;
}
for (int i = 0; i < array.Length; i++)
{
string text = array[i];
Texture2D val = LoadTextureFromFile(text);
if ((Object)(object)val == (Object)null)
{
logger.LogWarning($"Failed to load image #{i + 1}: {text}");
continue;
}
float num = (float)((Texture)val).width / (float)((Texture)val).height;
if (num > 1.3f)
{
AddGrungeMaterial("Landscape", _LandscapeMaterial, val);
}
else if (num < 0.769f)
{
AddGrungeMaterial("Portrait", _PortraitMaterial, val);
}
else
{
AddGrungeMaterial("Square", _LandscapeMaterial, val);
}
logger.LogInfo($"Loaded image #{i + 1}: {Path.GetFileName(text)}");
}
foreach (KeyValuePair<string, List<Material>> materialGroup in MaterialGroups)
{
LoadedMaterials.AddRange(materialGroup.Value);
}
logger.LogInfo($"Total images loaded: {LoadedMaterials.Count}");
}
private Material AddGrungeMaterial(Material grungeMaterial, Texture2D texture)
{
//IL_002a: 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)
//IL_0037: Expected O, but got Unknown
//IL_0023: Unknown result type (might be due to invalid IL or missing references)
//IL_0029: Expected O, but got Unknown
if ((Object)(object)grungeMaterial == (Object)null)
{
logger.LogWarning("Falling back to default shader");
return new Material(Shader.Find("Standard"));
}
return new Material(grungeMaterial)
{
mainTexture = (Texture)(object)texture
};
}
private void AddGrungeMaterial(string paintingType, Material grungeMaterial, Texture2D texture)
{
if (!MaterialGroups.ContainsKey(paintingType))
{
MaterialGroups[paintingType] = new List<Material>();
}
Material item = AddGrungeMaterial(grungeMaterial, texture);
MaterialGroups[paintingType].Add(item);
}
private Texture2D LoadTextureFromFile(string filePath)
{
//IL_0009: Unknown result type (might be due to invalid IL or missing references)
//IL_000f: Expected O, but got Unknown
byte[] array = File.ReadAllBytes(filePath);
Texture2D val = new Texture2D(2, 2);
if (ImageConversion.LoadImage(val, array))
{
SetFilterMode((Texture)(object)val);
val.Apply();
return val;
}
return null;
}
private void LoadGrungeMaterials()
{
string? directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
string text = "GrungeAssets";
string text2 = Path.Combine(directoryName, text);
logger.LogInfo("Loading [" + text2 + "]");
if (File.Exists(text2))
{
logger.LogInfo("Grunge Asset Bundle exists.");
}
else
{
logger.LogWarning("Grunge Asset Bundle doesn't exist!");
}
AssetBundle val = AssetBundle.LoadFromFile(text2);
if ((Object)(object)val == (Object)null)
{
logger.LogError("Failed to load [" + text + "]!");
}
else
{
_LandscapeMaterial = val.LoadAsset<Material>("GrungeHorizontalMaterial");
if ((Object)(object)_LandscapeMaterial == (Object)null)
{
logger.LogError("Could not load landscape painting material [GrungeHorizontalMaterial]!");
}
_PortraitMaterial = val.LoadAsset<Material>("GrungeVerticalMaterial");
if ((Object)(object)_PortraitMaterial == (Object)null)
{
logger.LogError("Could not load portrait painting material [GrungeVerticalMaterial]!");
}
}
if ((Object)(object)_LandscapeMaterial != (Object)null && (Object)(object)_PortraitMaterial != (Object)null)
{
logger.LogInfo("Grunge materials successfully loaded!");
}
}
internal void BindConfigUpdates()
{
CustomPaintingsConfig.Grunge.State.SettingChanged += OnGrungeConfigOptionChanged;
CustomPaintingsConfig.Grunge.Intensity.SettingChanged += OnGrungeConfigOptionChanged;
CustomPaintingsConfig.Grunge._BaseColor.SettingChanged += OnGrungeConfigOptionChanged;
CustomPaintingsConfig.Grunge._BaseColor.SettingChanged += OnGrungeConfigOptionChanged;
CustomPaintingsConfig.Grunge._MainColor.SettingChanged += OnGrungeConfigOptionChanged;
CustomPaintingsConfig.Grunge._CracksColor.SettingChanged += OnGrungeConfigOptionChanged;
CustomPaintingsConfig.Grunge._OutlineColor.SettingChanged += OnGrungeConfigOptionChanged;
CustomPaintingsConfig.Graphics.PointFiltering.SettingChanged += OnPointFilteringConfigOptionChange;
}
internal void OnPointFilteringConfigOptionChange(object sender, EventArgs e)
{
foreach (Material loadedMaterial in LoadedMaterials)
{
SetFilterMode(loadedMaterial.mainTexture);
}
}
internal void SetFilterMode(Texture texture)
{
if (CustomPaintingsConfig.Graphics.PointFiltering.Value)
{
texture.filterMode = (FilterMode)0;
}
else
{
texture.filterMode = (FilterMode)2;
}
}
internal void OnGrungeConfigOptionChanged(object sender, EventArgs e)
{
UpdateGrungeMaterialParameters();
}
internal void UpdateGrungeMaterialParameters()
{
//IL_017c: Unknown result type (might be due to invalid IL or missing references)
//IL_0197: Unknown result type (might be due to invalid IL or missing references)
//IL_01b2: 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_00ed: Unknown result type (might be due to invalid IL or missing references)
//IL_010d: Unknown result type (might be due to invalid IL or missing references)
//IL_0112: Unknown result type (might be due to invalid IL or missing references)
//IL_0113: Unknown result type (might be due to invalid IL or missing references)
//IL_0133: 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_0139: Unknown result type (might be due to invalid IL or missing references)
//IL_0159: Unknown result type (might be due to invalid IL or missing references)
//IL_015e: Unknown result type (might be due to invalid IL or missing references)
//IL_015f: Unknown result type (might be due to invalid IL or missing references)
logger.LogDebug("Updating Grunge Material Parameters...");
bool value = CustomPaintingsConfig.Grunge.State.Value;
float value2 = CustomPaintingsConfig.Grunge.Intensity.Value;
Color val = default(Color);
((Color)(ref val))..ctor(1f, 1f, 1f, value2);
logger.LogDebug($"Grunge state is [{value}]!");
logger.LogDebug($"Grunge intensity is [{value2}]!");
logger.LogDebug($"Number of loaded painting materials = [{LoadedMaterials.Count}]");
foreach (Material loadedMaterial in LoadedMaterials)
{
if ((Object)(object)loadedMaterial == (Object)null)
{
logger.LogWarning("No material found!");
}
else if (value)
{
loadedMaterial.SetColor(((ConfigEntryBase)CustomPaintingsConfig.Grunge._BaseColor).Definition.Key, CustomPaintingsConfig.Grunge._BaseColor.Value);
loadedMaterial.SetColor(((ConfigEntryBase)CustomPaintingsConfig.Grunge._MainColor).Definition.Key, CustomPaintingsConfig.Grunge._MainColor.Value * val);
loadedMaterial.SetColor(((ConfigEntryBase)CustomPaintingsConfig.Grunge._CracksColor).Definition.Key, CustomPaintingsConfig.Grunge._CracksColor.Value * val);
loadedMaterial.SetColor(((ConfigEntryBase)CustomPaintingsConfig.Grunge._OutlineColor).Definition.Key, CustomPaintingsConfig.Grunge._OutlineColor.Value * val);
}
else
{
loadedMaterial.SetColor(((ConfigEntryBase)CustomPaintingsConfig.Grunge._BaseColor).Definition.Key, Color.clear);
loadedMaterial.SetColor(((ConfigEntryBase)CustomPaintingsConfig.Grunge._MainColor).Definition.Key, Color.clear);
loadedMaterial.SetColor(((ConfigEntryBase)CustomPaintingsConfig.Grunge._CracksColor).Definition.Key, Color.clear);
loadedMaterial.SetColor(((ConfigEntryBase)CustomPaintingsConfig.Grunge._OutlineColor).Definition.Key, Color.clear);
}
}
}
}
public class CustomPaintingsSwap
{
public enum ModState
{
Host,
Client,
SinglePlayer
}
private readonly Logger logger;
private readonly CustomPaintingsLoader loader;
private readonly CustomPaintingsGroupList grouper;
private static CustomPaintingsConfig configfile;
private static int randomSeed = 0;
public static int HostSeed = 0;
public static int ReceivedSeed = 0;
public static int Seed = 0;
public static string SeperateState = "Singleplayer";
public static string ImageMode = "Normal";
private int paintingsChangedCount;
private int LandscapeChangedCount;
private int SquareChangedCount;
private int PortraitChangedCount;
private static ModState currentState = ModState.SinglePlayer;
public ModState GetModState()
{
return currentState;
}
public CustomPaintingsSwap(Logger logger, CustomPaintingsLoader loader, CustomPaintingsGroupList grouper)
{
this.logger = logger;
this.loader = loader;
this.grouper = grouper;
logger.LogInfo($"Initial ModState: {currentState}");
if (randomSeed == 0)
{
randomSeed = Random.Range(0, int.MaxValue);
logger.LogInfo($"Generated initial random seed: {randomSeed}");
}
}
public void ReplacePaintings()
{
//IL_0063: Unknown result type (might be due to invalid IL or missing references)
//IL_0068: Unknown result type (might be due to invalid IL or missing references)
//IL_0100: Unknown result type (might be due to invalid IL or missing references)
//IL_0105: Unknown result type (might be due to invalid IL or missing references)
//IL_02a2: 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)
if (currentState == ModState.SinglePlayer)
{
Seed = randomSeed;
}
if (currentState == ModState.Host)
{
Seed = HostSeed;
}
if (currentState == ModState.Client)
{
Seed = ReceivedSeed;
}
if (CustomPaintingsConfig.ChaosMode.Value)
{
ImageMode = "Chaos";
}
else if (!CustomPaintingsConfig.ChaosMode.Value)
{
ImageMode = "Normal";
}
Scene activeScene = SceneManager.GetActiveScene();
logger.LogInfo($"Applying seed {Seed} for painting swaps in scene: {((Scene)(ref activeScene)).name}");
logger.LogInfo("Replacing all paintings with custom images...");
paintingsChangedCount = 0;
int num = 0;
Scene activeScene2;
if ((!CustomPaintingsConfig.SeperateImages.Value && SeperateState == "Singleplayer") || (SeperateState == "off" && CustomPaintingsConfig.HostControl.Value) || (!CustomPaintingsConfig.HostControl.Value && !CustomPaintingsConfig.SeperateImages.Value))
{
activeScene2 = SceneManager.GetActiveScene();
GameObject[] rootGameObjects = ((Scene)(ref activeScene2)).GetRootGameObjects();
for (int i = 0; i < rootGameObjects.Length; i++)
{
MeshRenderer[] componentsInChildren = rootGameObjects[i].GetComponentsInChildren<MeshRenderer>();
foreach (MeshRenderer val in componentsInChildren)
{
Material[] sharedMaterials = ((Renderer)val).sharedMaterials;
for (int k = 0; k < sharedMaterials.Length; k++)
{
num++;
string key = ((Object)sharedMaterials[k]).name.Trim();
if (CustomPaintingsGroupList.MaterialNameToGroup.TryGetValue(key, out var value) && (Object)(object)sharedMaterials[k] != (Object)null && value.Contains(ImageMode) && !((Object)sharedMaterials[k]).name.Contains("Painting Frame Vertical Gold") && !((Object)sharedMaterials[k]).name.Contains("Painting Frame Horizontal Gold") && loader.LoadedMaterials.Count > 0)
{
int index = Mathf.Abs((Seed + paintingsChangedCount) % loader.LoadedMaterials.Count);
sharedMaterials[k] = loader.LoadedMaterials[index];
paintingsChangedCount++;
}
}
((Renderer)val).sharedMaterials = sharedMaterials;
}
}
}
else
{
if ((!CustomPaintingsConfig.SeperateImages.Value || !(SeperateState == "Singleplayer")) && (!(SeperateState == "on") || !CustomPaintingsConfig.HostControl.Value) && (CustomPaintingsConfig.HostControl.Value || !CustomPaintingsConfig.SeperateImages.Value))
{
return;
}
activeScene2 = SceneManager.GetActiveScene();
GameObject[] rootGameObjects = ((Scene)(ref activeScene2)).GetRootGameObjects();
for (int i = 0; i < rootGameObjects.Length; i++)
{
MeshRenderer[] componentsInChildren = rootGameObjects[i].GetComponentsInChildren<MeshRenderer>();
foreach (MeshRenderer val2 in componentsInChildren)
{
Material[] sharedMaterials2 = ((Renderer)val2).sharedMaterials;
for (int l = 0; l < sharedMaterials2.Length; l++)
{
num++;
string key2 = ((Object)sharedMaterials2[l]).name.Trim();
if (CustomPaintingsGroupList.MaterialNameToGroup.TryGetValue(key2, out var value2) && (Object)(object)sharedMaterials2[l] != (Object)null && value2.Contains(ImageMode))
{
if (((Object)sharedMaterials2[l]).name.Contains("Painting Frame Vertical Gold") || ((Object)sharedMaterials2[l]).name.Contains("Painting Frame Horizontal Gold"))
{
continue;
}
if (value2.Contains("Landscape"))
{
int index2 = Mathf.Abs((Seed + LandscapeChangedCount) % loader.MaterialGroups["Landscape"].Count);
sharedMaterials2[l] = loader.MaterialGroups["Landscape"][index2];
LandscapeChangedCount++;
}
else if (value2.Contains("Square"))
{
int index3 = Mathf.Abs((Seed + SquareChangedCount) % loader.MaterialGroups["Square"].Count);
sharedMaterials2[l] = loader.MaterialGroups["Square"][index3];
SquareChangedCount++;
}
else if (value2.Contains("Portrait"))
{
int index4 = Mathf.Abs((Seed + PortraitChangedCount) % loader.MaterialGroups["Portrait"].Count);
sharedMaterials2[l] = loader.MaterialGroups["Portrait"][index4];
PortraitChangedCount++;
}
}
((Renderer)val2).sharedMaterials = sharedMaterials2;
}
}
}
logger.LogInfo($"Total materials checked: {num}");
logger.LogInfo($"Total paintings changed in this scene: {LandscapeChangedCount + SquareChangedCount + PortraitChangedCount}");
}
}
public void SetState(ModState newState)
{
currentState = newState;
logger.LogInfo($"Mod state set to: {currentState}");
}
}
public class CustomPaintingsSync : MonoBehaviourPunCallbacks, IOnEventCallback
{
private readonly Logger logger;
public const byte SeedEventCode = 1;
public const byte SeperateStateCode = 2;
public CustomPaintingsSync(Logger logger)
{
this.logger = logger;
}
public void SendSeed(int seed)
{
//IL_0020: Unknown result type (might be due to invalid IL or missing references)
//IL_0025: Unknown result type (might be due to invalid IL or missing references)
//IL_0027: Unknown result type (might be due to invalid IL or missing references)
//IL_002c: Unknown result type (might be due to invalid IL or missing references)
//IL_002e: Unknown result type (might be due to invalid IL or missing references)
//IL_0034: Expected O, but got Unknown
//IL_0037: Unknown result type (might be due to invalid IL or missing references)
object[] array = new object[1] { seed };
logger.LogInfo("sharing seed with other clients");
RaiseEventOptions val = new RaiseEventOptions
{
Receivers = (ReceiverGroup)1,
CachingOption = (EventCaching)4
};
PhotonNetwork.RaiseEvent((byte)1, (object)array, val, SendOptions.SendReliable);
}
public void SendSeperateState(string toggle)
{
//IL_001b: 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_0022: Unknown result type (might be due to invalid IL or missing references)
//IL_0027: Unknown result type (might be due to invalid IL or missing references)
//IL_0029: Unknown result type (might be due to invalid IL or missing references)
//IL_002f: Expected O, but got Unknown
//IL_0032: Unknown result type (might be due to invalid IL or missing references)
object[] array = new object[1] { toggle };
logger.LogInfo("sharing seperation setting");
RaiseEventOptions val = new RaiseEventOptions
{
Receivers = (ReceiverGroup)1,
CachingOption = (EventCaching)4
};
PhotonNetwork.RaiseEvent((byte)2, (object)array, val, SendOptions.SendReliable);
}
public void OnEvent(EventData photonEvent)
{
if (photonEvent.Code == 1)
{
int num = (int)((object[])photonEvent.CustomData)[0];
logger.LogInfo($"Received seed: {num}");
CustomPaintingsSwap.ReceivedSeed = num;
}
if (photonEvent.Code == 2)
{
string text = (string)((object[])photonEvent.CustomData)[0];
logger.LogInfo("Received seperate state: " + text);
CustomPaintingsSwap.SeperateState = text;
}
}
}
public class Logger
{
private readonly string logFilePath;
private readonly ManualLogSource logSource;
public Logger(string modName)
{
string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
logFilePath = Path.Combine(directoryName, modName + "_log.txt");
if (File.Exists(logFilePath))
{
File.Delete(logFilePath);
}
logSource = Logger.CreateLogSource(modName);
}
public void LogDebug(string message)
{
WriteLog("DEBUG", message);
logSource.LogDebug((object)message);
}
public void LogInfo(string message)
{
WriteLog("INFO", message);
logSource.LogInfo((object)message);
}
public void LogWarning(string message)
{
WriteLog("WARNING", message);
logSource.LogWarning((object)message);
}
public void LogError(string message)
{
WriteLog("ERROR", message);
logSource.LogError((object)message);
}
private void WriteLog(string level, string message)
{
string text = $"{DateTime.Now:yyyy-MM-dd HH:mm:ss} [{level}] {message}";
File.AppendAllText(logFilePath, text + Environment.NewLine);
}
public void LogMaterial(Material material)
{
if ((Object)(object)material != (Object)null && ((Object)material).name.ToLower().Contains("painting"))
{
LogInfo("Material containing 'painting': " + ((Object)material).name);
}
}
public void ClearLog()
{
if (File.Exists(logFilePath))
{
File.Delete(logFilePath);
}
}
}
}