Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of GoDump v0.1.6
GoDump.dll
Decompiled 5 months agousing System; using System.Collections; 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.Security; using System.Security.Permissions; using BepInEx; using BepInEx.Configuration; using GODump; using GoDump; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: IgnoresAccessChecksTo("Assembly-CSharp")] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyCompany("GoDump")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0+ac3604369a31c1537b492ddbf23b21ebbc193598")] [assembly: AssemblyProduct("GoDump")] [assembly: AssemblyTitle("GoDump")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.0.0.0")] [module: UnverifiableCode] namespace GODump { internal static class SpriteDump { public struct RectP { public int x { get; set; } public int y { get; set; } public int width { get; set; } public int height { get; set; } public int xmin { get; set; } public int ymin { get; set; } public int xmax { get; set; } public int ymax { get; set; } public RectP(int _x, int _y, int _width, int _height) { x = _x; y = _y; width = _width; height = _height; xmin = _x; ymin = _y; xmax = _x + _width - 1; ymax = _y + _height - 1; } } private static readonly Color[] colors = (Color[])(object)new Color[16777216]; public static void Tk2dFlip(ref Texture2D texture2D) { //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_0014: Expected O, but got Unknown //IL_0023: Unknown result type (might be due to invalid IL or missing references) Texture2D val = new Texture2D(((Texture)texture2D).height, ((Texture)texture2D).width); for (int i = 0; i < ((Texture)texture2D).width; i++) { for (int j = 0; j < ((Texture)texture2D).height; j++) { val.SetPixel(j, i, texture2D.GetPixel(i, j)); } } texture2D = val; } public static Texture2D TextureReadHack(Texture2D in_tex) { //IL_0034: Unknown result type (might be due to invalid IL or missing references) //IL_0039: Unknown result type (might be due to invalid IL or missing references) //IL_0052: 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_0071: Expected O, but got Unknown RenderTexture temporary = RenderTexture.GetTemporary(((Texture)in_tex).width, ((Texture)in_tex).height, 0, (RenderTextureFormat)7, (RenderTextureReadWrite)1); Graphics.Blit((Texture)(object)in_tex, temporary); RenderTexture active = RenderTexture.active; RenderTexture.active = temporary; Texture2D val = new Texture2D(((Texture)in_tex).width, ((Texture)in_tex).height); val.ReadPixels(new Rect(0f, 0f, (float)((Texture)temporary).width, (float)((Texture)temporary).height), 0, 0); val.Apply(); RenderTexture.active = active; RenderTexture.ReleaseTemporary(temporary); return val; } public static Texture2D SubTexture(Texture2D in_tex, RectP rectP) { //IL_000e: 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_003b: Unknown result type (might be due to invalid IL or missing references) //IL_0042: Expected O, but got Unknown Texture2D val = new Texture2D(rectP.width, rectP.height); val.SetPixels(in_tex.GetPixels(rectP.x, rectP.y, rectP.width, rectP.height)); val.Apply(); return val; } public static Texture2D SubTexturePosition(Texture2D in_tex, RectP rectP) { //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_001c: 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_0067: Expected O, but got Unknown Texture2D val = new Texture2D(((Texture)in_tex).width, ((Texture)in_tex).height); val.SetPixels(colors); val.SetPixels(rectP.x, rectP.y, rectP.width, rectP.height, in_tex.GetPixels(rectP.x, rectP.y, rectP.width, rectP.height)); val.Apply(); return val; } public static Texture2D SpriteSizeFix(Texture2D in_tex, RectP rectP, RectP border) { //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_0014: Expected O, but got Unknown //IL_00c9: Unknown result type (might be due to invalid IL or missing references) Texture2D val = new Texture2D(border.width, border.height); val.SetPixels(colors); val.SetPixels(rectP.x, rectP.y, rectP.width, rectP.height, in_tex.GetPixels()); if (global::GoDump.GoDump.Instance.isDrawRectBorder.Value) { for (int i = 0; i < ((Texture)val).width; i++) { for (int j = 0; j < ((Texture)val).height; j++) { if (((i == rectP.xmin - 1 || i == rectP.xmax + 1) && rectP.ymin - 1 <= j && j <= rectP.ymax + 1) || (rectP.xmin - 1 <= i && i <= rectP.xmax + 1 && (j == rectP.ymin - 1 || j == rectP.ymax + 1))) { val.SetPixel(i, j, Color.red); } } } } val.Apply(); return val; } public static Texture2D SpriteSizeFixError(Texture2D in_tex, RectP rectP, RectP border) { //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_0014: Expected O, but got Unknown //IL_026a: Unknown result type (might be due to invalid IL or missing references) Texture2D val = new Texture2D(border.width, border.height); val.SetPixels(colors); if (rectP.x < 0 || rectP.y < 0 || rectP.x + rectP.width > ((Texture)in_tex).width || rectP.y + rectP.height > ((Texture)in_tex).height || rectP.x + rectP.width > ((Texture)val).width || rectP.y + rectP.height > ((Texture)val).height) { global::GoDump.GoDump.logInfo($"Invalid rectP bounds in SpriteSizeFix for rectP: x={rectP.x}, y={rectP.y}, width={rectP.width}, height={rectP.height}. Adjusting."); rectP.x = Mathf.Max(0, rectP.x); rectP.y = Mathf.Max(0, rectP.y); rectP.width = Mathf.Min(rectP.width, Mathf.Min(((Texture)in_tex).width - rectP.x, ((Texture)val).width - rectP.x)); rectP.height = Mathf.Min(rectP.height, Mathf.Min(((Texture)in_tex).height - rectP.y, ((Texture)val).height - rectP.y)); if (rectP.width <= 0 || rectP.height <= 0) { global::GoDump.GoDump.logInfo($"Invalid rectP after adjustment: width={rectP.width}, height={rectP.height}. Returning empty texture."); return val; } } val.SetPixels(rectP.x, rectP.y, rectP.width, rectP.height, in_tex.GetPixels(0, 0, rectP.width, rectP.height)); if (global::GoDump.GoDump.Instance.isDrawRectBorder.Value) { for (int i = 0; i < ((Texture)val).width; i++) { for (int j = 0; j < ((Texture)val).height; j++) { if (((i == rectP.xmin - 1 || i == rectP.xmax + 1) && rectP.ymin - 1 <= j && j <= rectP.ymax + 1) || (rectP.xmin - 1 <= i && i <= rectP.xmax + 1 && (j == rectP.ymin - 1 || j == rectP.ymax + 1))) { val.SetPixel(i, j, Color.red); } } } } val.Apply(); return val; } public static void SaveTextureToFile(Texture2D tex, string fileName) { byte[] buffer = ImageConversion.EncodeToPNG(tex); Directory.CreateDirectory(Path.GetDirectoryName(fileName)); BinaryWriter binaryWriter = new BinaryWriter(new FileStream(fileName, FileMode.Create, FileAccess.ReadWrite)); binaryWriter.Write(buffer); binaryWriter.Close(); } } [Serializable] public class SpriteInfo { public List<int> sid; public List<int> sx; public List<int> sy; public List<int> sxr; public List<int> syr; public List<int> swidth; public List<int> sheight; public List<string> scollectionname; public List<string> spath; public List<bool> sfilpped; public SpriteInfo() { sid = new List<int>(); sx = new List<int>(); sy = new List<int>(); sxr = new List<int>(); syr = new List<int>(); swidth = new List<int>(); sheight = new List<int>(); scollectionname = new List<string>(); spath = new List<string>(); sfilpped = new List<bool>(); } public void Add(int _sid, int _sx, int _sy, int _sxr, int _syr, int _swidth, int _sheight, string _scollectionname, string _spath, bool _sfilpped) { sid.Add(_sid); sx.Add(_sx); sy.Add(_sy); sxr.Add(_sxr); syr.Add(_syr); swidth.Add(_swidth); sheight.Add(_sheight); scollectionname.Add(_scollectionname); spath.Add(_spath); sfilpped.Add(_sfilpped); } } } namespace GoDump { [BepInPlugin("Yuki.GoDump", "GoDump", "1.0.0")] public class GoDump : BaseUnityPlugin { private const string modGUID = "Yuki.GoDump"; private const string modName = "GoDump"; private const string modVersion = "1.0.0"; private static string _spritePath = ""; private static string _atlasPath = ""; private List<tk2dSpriteCollectionData> clns; private List<tk2dSpriteAnimation> anims; private tk2dSpriteAnimation anim; private string[] animNames; private int num; private ConfigEntry<string> dumpAnimName; private ConfigEntry<string> exportPath; private ConfigEntry<bool> logCurrentClipId; private ConfigEntry<KeyCode> logClnKey; private ConfigEntry<KeyCode> dumpClnKey; public ConfigEntry<bool> isDrawRectBorder; private string currClipAndId = ""; public static GoDump Instance { get; private set; } private void Awake() { ((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin Yuki.GoDump is loaded!"); dumpAnimName = ((BaseUnityPlugin)this).Config.Bind<string>("", "dumpAnimName", "", (ConfigDescription)null); exportPath = ((BaseUnityPlugin)this).Config.Bind<string>("", "exportPath", "", (ConfigDescription)null); logCurrentClipId = ((BaseUnityPlugin)this).Config.Bind<bool>("", "LogCurrentClipId", false, (ConfigDescription)null); logClnKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Key", "logClnKey", (KeyCode)284, (ConfigDescription)null); dumpClnKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Key", "dumpClnKey", (KeyCode)285, (ConfigDescription)null); isDrawRectBorder = ((BaseUnityPlugin)this).Config.Bind<bool>("", "isDrawRectBorder", true, (ConfigDescription)null); } private void Start() { Instance = this; clns = new List<tk2dSpriteCollectionData>(); anims = new List<tk2dSpriteAnimation>(); animNames = new string[0]; } private void Update() { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0081: Unknown result type (might be due to invalid IL or missing references) if (Input.GetKeyDown(logClnKey.Value)) { ((BaseUnityPlugin)this).Logger.LogInfo((object)"Log tk2dSpriteAnimation Start"); ((BaseUnityPlugin)this).Logger.LogInfo((object)"= = = = = = = = = = = = = = = ="); tk2dSpriteAnimation[] array = Resources.FindObjectsOfTypeAll<tk2dSpriteAnimation>(); foreach (tk2dSpriteAnimation val in array) { ((BaseUnityPlugin)this).Logger.LogInfo((object)((Object)val).name); } ((BaseUnityPlugin)this).Logger.LogInfo((object)"= = = = = = = = = = = = = = = ="); ((BaseUnityPlugin)this).Logger.LogInfo((object)"Log tk2dSpriteAnimation End"); } if (Input.GetKeyDown(dumpClnKey.Value)) { if (exportPath.Value == "") { ((BaseUnityPlugin)this).Logger.LogInfo((object)"export Path is Empty"); return; } if (!Directory.Exists(exportPath.Value)) { ((BaseUnityPlugin)this).Logger.LogInfo((object)("Export Path: " + exportPath.Value + " not exist")); return; } clns.Clear(); anims.Clear(); tk2dSpriteAnimation animation = getAnimation(dumpAnimName.Value); anims.Add(animation); animNames = anims.Select((tk2dSpriteAnimation a) => ((Object)a).name).ToArray(); ((MonoBehaviour)this).StartCoroutine(HornetSprite()); } if (!Object.op_Implicit((Object)(object)HeroController.instance) || !logCurrentClipId.Value) { return; } HeroController instance = HeroController.instance; tk2dSpriteAnimator component = ((Component)instance).GetComponent<tk2dSpriteAnimator>(); tk2dSprite component2 = ((Component)instance).GetComponent<tk2dSprite>(); if (!((Object)(object)component != (Object)null) || !((Object)(object)component2 != (Object)null)) { return; } tk2dSpriteAnimationClip currentClip = component.CurrentClip; if (currentClip != null) { int num = Math.Clamp(component.CurrentFrame, 0, currentClip.frames.Length - 1); tk2dSpriteAnimationFrame val2 = currentClip.frames[num]; string text = (((Object)(object)val2.spriteCollection != (Object)null) ? ((Object)val2.spriteCollection).name : "Unknown"); string name = currentClip.name; int spriteId = ((tk2dBaseSprite)component2).spriteId; string text2 = $"[{text}] {name} (Frame: {num}, ID: {spriteId})"; if (currClipAndId != text2) { currClipAndId = text2; ((BaseUnityPlugin)this).Logger.LogInfo((object)text2); } } } private IEnumerator HornetSprite() { this.num = 0; foreach (tk2dSpriteAnimation anim in anims) { if (!animNames.Contains(((Object)anim).name)) { continue; } int num = 0; SpriteInfo spriteInfo = new SpriteInfo(); ((BaseUnityPlugin)this).Logger.LogInfo((object)("Begin Dumping sprites in tk2dSpriteAnimator [" + ((Object)anim).name + "].")); tk2dSpriteAnimationClip[] clips = anim.clips; foreach (tk2dSpriteAnimationClip val in clips) { ((BaseUnityPlugin)this).Logger.LogInfo((object)val.name); num++; int num2 = -1; float num3 = -10000f; float num4 = -10000f; float num5 = 10000f; float num6 = 10000f; tk2dSpriteAnimationFrame[] frames = val.frames; foreach (tk2dSpriteAnimationFrame val2 in frames) { Vector3[] positions = val2.spriteCollection.spriteDefinitions[val2.spriteId].positions; float num7 = positions.Min((Vector3 v) => v.x); float num8 = positions.Min((Vector3 v) => v.y); float num9 = positions.Max((Vector3 v) => v.x); float num10 = positions.Max((Vector3 v) => v.y); num5 = ((num5 < num7) ? num5 : num7); num6 = ((num6 < num8) ? num6 : num8); num3 = ((num3 > num9) ? num3 : num9); num4 = ((num4 > num10) ? num4 : num10); } frames = val.frames; foreach (tk2dSpriteAnimationFrame val3 in frames) { num2++; if (val.name == "") { continue; } tk2dSpriteDefinition val4 = val3.spriteCollection.spriteDefinitions[val3.spriteId]; Vector2[] uvs = val4.uvs; Vector3[] positions2 = val4.positions; Texture2D val5 = SpriteDump.TextureReadHack((Texture2D)val4.material.mainTexture); string text = val3.spriteCollection.spriteCollectionName + "_" + ((Object)val4.material.mainTexture).name; string text2 = exportPath.Value + "/sprites/" + ((Object)anim).name + "/0.Atlases/" + text + ".png"; string path = exportPath.Value + "/sprites/" + ((Object)anim).name + "/" + $"{num:D3}" + "." + val.name + "/" + text + ".png"; string path2 = exportPath.Value + "/sprites/" + ((Object)anim).name + "/" + $"{num:D3}" + "." + val.name + "/" + $"{num:D3}" + "-" + $"{num2:D2}" + "-" + $"{val3.spriteId:D3}" + "_position.png"; string text3 = ((Object)anim).name + "/" + $"{num:D3}" + "." + val.name + "/" + $"{num:D3}" + "-" + $"{num2:D2}" + "-" + $"{val3.spriteId:D3}" + ".png"; string text4 = exportPath.Value + "/sprites/" + text3; bool flag = (int)val4.flipped == 1; float num11 = positions2.Min((Vector3 v) => v.x); float num12 = positions2.Min((Vector3 v) => v.y); float num13 = positions2.Max((Vector3 v) => v.x); float num14 = positions2.Max((Vector3 v) => v.y); int num15 = (int)(uvs.Min((Vector2 v) => v.x) * (float)((Texture)val5).width); int num16 = (int)(uvs.Min((Vector2 v) => v.y) * (float)((Texture)val5).height); int num17 = (int)(uvs.Max((Vector2 v) => v.x) * (float)((Texture)val5).width); int num18 = (int)(uvs.Max((Vector2 v) => v.y) * (float)((Texture)val5).height); int num19 = num15; int num20 = num16; int num21 = num17; int num22 = num18; if (flag) { num21 = num18 + num15 - num16; num22 = num17 - num15 + num16; } int num23 = (int)((num5 - num5) / val4.texelSize.x); int num24 = (int)((num6 - num6) / val4.texelSize.y); int num25 = (int)((num3 - num5) / val4.texelSize.x); int num26 = (int)((num4 - num6) / val4.texelSize.y); int num27 = (int)((num11 - num5) / val4.texelSize.x); int num28 = (int)((num12 - num6) / val4.texelSize.y); _ = (num13 - num5) / val4.texelSize.x; _ = (num14 - num6) / val4.texelSize.y; SpriteDump.RectP rectP = new SpriteDump.RectP(num15, num16, num17 - num15 + 1, num18 - num16 + 1); SpriteDump.RectP border = new SpriteDump.RectP(num19 - num27 + num23, num20 - num28 + num24, num25 - num23 + 1, num26 - num24 + 1); SpriteDump.RectP rectP2 = new SpriteDump.RectP(num27 - num23, num28 - num24, num21 - num19 + 1, num22 - num20 + 1); if (!File.Exists(text2)) { SpriteDump.SaveTextureToFile(val5, text2); this.num++; } File.Exists(path); File.Exists(path2); spriteInfo.Add(val3.spriteId, num15, num16, rectP2.x, rectP2.y, rectP2.width, rectP2.height, text, text3, flag); if (!File.Exists(text4)) { try { if (rectP.x < 0 || rectP.y < 0 || rectP.x + rectP.width > ((Texture)val5).width || rectP.y + rectP.height > ((Texture)val5).height) { ((BaseUnityPlugin)this).Logger.LogWarning((object)("Texture rectangle out of bounds for " + text3 + ". Adjusting uvpixel.")); rectP.x = Mathf.Max(0, rectP.x); rectP.y = Mathf.Max(0, rectP.y); rectP.width = Mathf.Min(rectP.width, ((Texture)val5).width - rectP.x); rectP.height = Mathf.Min(rectP.height, ((Texture)val5).height - rectP.y); if (rectP.width <= 0 || rectP.height <= 0) { ((BaseUnityPlugin)this).Logger.LogError((object)("Invalid texture rectangle after adjustment for " + text3 + ". Skipping.")); continue; } } Texture2D texture2D = SpriteDump.SubTexture(val5, rectP); if (flag) { SpriteDump.Tk2dFlip(ref texture2D); } Texture2D obj = SpriteDump.SpriteSizeFix(texture2D, rectP2, border); SpriteDump.SaveTextureToFile(obj, text4); Object.DestroyImmediate((Object)(object)obj); Object.DestroyImmediate((Object)(object)texture2D); this.num++; } catch (Exception ex) { Texture2D texture2D2 = SpriteDump.SubTexture(val5, rectP); if (flag) { SpriteDump.Tk2dFlip(ref texture2D2); } Texture2D obj2 = SpriteDump.SpriteSizeFixError(texture2D2, rectP2, border); SpriteDump.SaveTextureToFile(obj2, text4); Object.DestroyImmediate((Object)(object)obj2); ((BaseUnityPlugin)this).Logger.LogInfo((object)(ex.ToString() + " " + text3)); } } Object.DestroyImmediate((Object)(object)val5); } } string path3 = exportPath.Value + "/sprites/" + ((Object)anim).name + "/0.Atlases/SpriteInfo.json"; if (!File.Exists(path3)) { using FileStream stream = File.Create(path3); using StreamWriter streamWriter = new StreamWriter(stream); string value = JsonUtility.ToJson((object)spriteInfo, true); streamWriter.Write(value); } ((BaseUnityPlugin)this).Logger.LogInfo((object)("End Dumping sprites in tk2dSpriteAnimator [" + ((Object)anim).name + "].")); } ((BaseUnityPlugin)this).Logger.LogInfo((object)("End Dumping Sprite.png " + this.num + " sprites dumped.")); yield break; } private List<tk2dSpriteAnimation> GetUsedIns(tk2dSpriteCollectionData cln, List<tk2dSpriteAnimation> anims) { List<tk2dSpriteAnimation> list = new List<tk2dSpriteAnimation>(); foreach (tk2dSpriteAnimation anim in anims) { tk2dSpriteAnimationClip[] clips = anim.clips; for (int i = 0; i < clips.Length; i++) { tk2dSpriteAnimationFrame[] frames = clips[i].frames; for (int j = 0; j < frames.Length; j++) { if (((Object)frames[j].spriteCollection).name == ((Object)cln).name && !list.Contains(anim)) { list.Add(anim); } } } } return list; } private tk2dSpriteAnimation getAnimation(string name) { tk2dSpriteAnimation[] array = Resources.FindObjectsOfTypeAll<tk2dSpriteAnimation>(); foreach (tk2dSpriteAnimation val in array) { if (((Object)val).name == name) { anim = val; } } return anim; } public static void logInfo(string msg) { ((BaseUnityPlugin)Instance).Logger.LogInfo((object)msg); } } } namespace System.Runtime.CompilerServices { [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)] internal sealed class IgnoresAccessChecksToAttribute : Attribute { public IgnoresAccessChecksToAttribute(string assemblyName) { } } }