Decompiled source of Graffiti mod cs v0.0.5

Graffiti-mod-cs.dll

Decompiled 2 days ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("Spray-mod-cs")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Spray-mod-cs")]
[assembly: AssemblyCopyright("Copyright ©  2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("f78edffd-51b7-44bc-99fa-d3023c34f05d")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace SprayMod;

[BepInPlugin("com.yourname.spraymod", "Graffiti-Mod", "1.0.0")]
public class Plugin : BaseUnityPlugin
{
	internal static ManualLogSource Logger;

	private static Plugin Instance;

	private readonly Harmony harmony = new Harmony("com.yourname.spraymod");

	private List<Texture2D> sprayTextures = new List<Texture2D>();

	private int currentTextureIndex = 0;

	private float spraySize = 1f;

	private float sprayOffset = 0.001f;

	private List<GameObject> sprayObjects = new List<GameObject>();

	private string sprayFolderPath;

	private void Awake()
	{
		Instance = this;
		Logger = ((BaseUnityPlugin)this).Logger;
		Logger.LogInfo((object)"Plugin com.yourname.spraymod is loaded!");
		sprayFolderPath = Path.Combine(Path.GetDirectoryName(typeof(Plugin).Assembly.Location), "Graffiti_images");
		if (!Directory.Exists(sprayFolderPath))
		{
			Directory.CreateDirectory(sprayFolderPath);
			Logger.LogInfo((object)("Created Graffiti_images folder at: " + sprayFolderPath));
		}
		LoadSprayTextures();
		harmony.PatchAll();
	}

	private void LoadSprayTextures()
	{
		sprayTextures.Clear();
		string[] array = new string[3] { "*.png", "*.jpg", "*.jpeg" };
		string[] array2 = array;
		foreach (string searchPattern in array2)
		{
			string[] files = Directory.GetFiles(sprayFolderPath, searchPattern);
			string[] array3 = files;
			foreach (string text in array3)
			{
				Texture2D val = LoadTexture(text);
				if ((Object)(object)val != (Object)null)
				{
					sprayTextures.Add(val);
					Logger.LogInfo((object)("Loaded spray texture: " + Path.GetFileName(text)));
				}
			}
		}
		if (sprayTextures.Count == 0)
		{
			Logger.LogWarning((object)("No spray images found in: " + sprayFolderPath));
			Logger.LogWarning((object)"Place .png or .jpg files in the Graffiti_images folder.");
		}
		else
		{
			Logger.LogInfo((object)$"Loaded {sprayTextures.Count} spray texture(s).");
		}
	}

	private Texture2D LoadTexture(string filePath)
	{
		//IL_000d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0013: Expected O, but got Unknown
		try
		{
			byte[] array = File.ReadAllBytes(filePath);
			Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false);
			if (ImageConversion.LoadImage(val, array))
			{
				((Object)val).name = Path.GetFileNameWithoutExtension(filePath);
				return val;
			}
		}
		catch (Exception ex)
		{
			Logger.LogError((object)("Failed to load texture " + filePath + ": " + ex.Message));
		}
		return null;
	}

	private void Update()
	{
		if (Input.GetKeyDown((KeyCode)116))
		{
			TrySpray();
		}
		if (Input.GetKeyDown((KeyCode)114) && sprayTextures.Count > 0)
		{
			currentTextureIndex = (currentTextureIndex + 1) % sprayTextures.Count;
			Logger.LogInfo((object)("Switched to spray: " + ((Object)sprayTextures[currentTextureIndex]).name));
		}
		if (Input.GetKeyDown((KeyCode)103))
		{
			UndoLastSpray();
		}
		float axis = Input.GetAxis("Mouse ScrollWheel");
		if (axis != 0f && (Input.GetKey((KeyCode)308) || Input.GetKey((KeyCode)307)))
		{
			spraySize = Mathf.Clamp(spraySize + axis * 0.5f, 0.1f, 10f);
			Logger.LogInfo((object)$"Spray size: {spraySize:F2}");
		}
	}

	private void TrySpray()
	{
		//IL_0082: 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_008c: Unknown result type (might be due to invalid IL or missing references)
		//IL_008d: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
		if (sprayTextures.Count == 0)
		{
			Logger.LogWarning((object)"No spray textures loaded! Put images in the Graffiti_images folder.");
			return;
		}
		Camera val = Camera.main;
		if ((Object)(object)val == (Object)null)
		{
			val = Object.FindObjectOfType<Camera>();
			if ((Object)(object)val == (Object)null)
			{
				Logger.LogError((object)"No camera found!");
				return;
			}
		}
		Ray val2 = val.ScreenPointToRay(new Vector3((float)Screen.width / 2f, (float)Screen.height / 2f, 0f));
		RaycastHit hit = default(RaycastHit);
		if (Physics.Raycast(val2, ref hit, 50f))
		{
			PlaceSpray(hit);
		}
	}

	private void PlaceSpray(RaycastHit hit)
	{
		//IL_0050: 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_0062: 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_007a: 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_0084: Unknown result type (might be due to invalid IL or missing references)
		//IL_0089: Unknown result type (might be due to invalid IL or missing references)
		//IL_0096: Unknown result type (might be due to invalid IL or missing references)
		//IL_009b: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f0: 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)
		//IL_00c0: 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)
		//IL_00ca: 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_0119: Unknown result type (might be due to invalid IL or missing references)
		//IL_0135: Unknown result type (might be due to invalid IL or missing references)
		//IL_013b: Expected O, but got Unknown
		//IL_0153: Unknown result type (might be due to invalid IL or missing references)
		//IL_0159: Expected O, but got Unknown
		//IL_0230: Unknown result type (might be due to invalid IL or missing references)
		//IL_0172: Unknown result type (might be due to invalid IL or missing references)
		//IL_0178: Expected O, but got Unknown
		GameObject val = GameObject.CreatePrimitive((PrimitiveType)5);
		((Object)val).name = "SprayDecal_" + sprayObjects.Count;
		Collider component = val.GetComponent<Collider>();
		if ((Object)(object)component != (Object)null)
		{
			Object.Destroy((Object)(object)component);
		}
		val.transform.position = ((RaycastHit)(ref hit)).point + ((RaycastHit)(ref hit)).normal * sprayOffset;
		val.transform.rotation = Quaternion.LookRotation(-((RaycastHit)(ref hit)).normal, Vector3.up);
		if (Mathf.Abs(Vector3.Dot(((RaycastHit)(ref hit)).normal, Vector3.up)) < 0.9f)
		{
			val.transform.rotation = Quaternion.LookRotation(-((RaycastHit)(ref hit)).normal, Vector3.up);
		}
		else
		{
			val.transform.rotation = Quaternion.LookRotation(-((RaycastHit)(ref hit)).normal, Vector3.forward);
		}
		val.transform.localScale = new Vector3(spraySize, spraySize, spraySize);
		Renderer component2 = val.GetComponent<Renderer>();
		Material val2 = new Material(Shader.Find("Sprites/Default"));
		if ((Object)(object)val2 == (Object)null)
		{
			val2 = new Material(Shader.Find("Transparent/Diffuse"));
		}
		if ((Object)(object)val2 == (Object)null)
		{
			val2 = new Material(Shader.Find("Standard"));
			val2.SetFloat("_Mode", 3f);
			val2.SetInt("_SrcBlend", 5);
			val2.SetInt("_DstBlend", 10);
			val2.SetInt("_ZWrite", 0);
			val2.DisableKeyword("_ALPHATEST_ON");
			val2.EnableKeyword("_ALPHABLEND_ON");
			val2.DisableKeyword("_ALPHAPREMULTIPLY_ON");
			val2.renderQueue = 3000;
		}
		Texture2D val4 = (Texture2D)(object)(val2.mainTexture = (Texture)(object)sprayTextures[currentTextureIndex]);
		component2.material = val2;
		component2.material.renderQueue = 2450;
		sprayObjects.Add(val);
		Logger.LogInfo((object)$"Spray placed at {((RaycastHit)(ref hit)).point} on object '{((Object)((Component)((RaycastHit)(ref hit)).collider).gameObject).name}' | Texture: {((Object)val4).name}");
	}

	private void UndoLastSpray()
	{
		if (sprayObjects.Count > 0)
		{
			GameObject val = sprayObjects[sprayObjects.Count - 1];
			sprayObjects.RemoveAt(sprayObjects.Count - 1);
			if ((Object)(object)val != (Object)null)
			{
				Object.Destroy((Object)(object)val);
			}
			Logger.LogInfo((object)"Removed last spray.");
		}
	}

	private void OnDestroy()
	{
		harmony.UnpatchSelf();
	}
}
internal static class MyPluginInfo
{
	public const string PLUGIN_GUID = "com.yourname.spraymod";

	public const string PLUGIN_NAME = "Graffiti-Mod";

	public const string PLUGIN_VERSION = "1.0.0";
}