From 4b776010906f52a82805cb54c9619dc77d84d4d7 Mon Sep 17 00:00:00 2001 From: SnowyWalk <69317828+SnowyWalk@users.noreply.github.com> Date: Sun, 23 Mar 2025 20:07:45 +0900 Subject: [PATCH 1/2] =?UTF-8?q?Inspector=EC=97=90=EC=84=9C=20=EB=B3=B4?= =?UTF-8?q?=EC=97=AC=EC=A3=BC=EB=8A=94=20Key=EC=9D=98=20=EB=B2=94=EC=9C=84?= =?UTF-8?q?=EB=A5=BC=2015=20->=2016=EC=9C=BC=EB=A1=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Key0~15까지 존재하나 Inspector에서는 Key0~14까지만 보여주고 있어서 수정 --- Editor/liltoonCustom/CustomInspector.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Editor/liltoonCustom/CustomInspector.cs b/Editor/liltoonCustom/CustomInspector.cs index 9829dea..2ca6fba 100644 --- a/Editor/liltoonCustom/CustomInspector.cs +++ b/Editor/liltoonCustom/CustomInspector.cs @@ -11,7 +11,7 @@ public class ShellProtectorInspector : lilToonInspector MaterialProperty mip_tex; MaterialProperty encrypted_tex0; MaterialProperty encrypted_tex1; - MaterialProperty[] key = new MaterialProperty[15]; + MaterialProperty[] key = new MaterialProperty[16]; MaterialProperty fallback; private static bool isShowCustomProperties; @@ -165,4 +165,4 @@ private static void ConvertMaterialToCustomShaderMenu() } } #endif -#endif \ No newline at end of file +#endif From 15797af9b9e71e410e59d29c28df9936a54108cb Mon Sep 17 00:00:00 2001 From: SnowyWalk Date: Sun, 23 Mar 2025 23:53:48 +0900 Subject: [PATCH 2/2] =?UTF-8?q?=EB=B3=B5=ED=98=B8=ED=99=94=20=EC=99=84?= =?UTF-8?q?=EB=A3=8C=EC=97=90=20=EB=8C=80=ED=95=9C=20=ED=8C=90=EB=8B=A8=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Editor/liltoonCustom/CustomInspector.cs | 7 ++- Runtime/Decrypt.cginc | 7 +++ Runtime/DecryptChacha.cginc | 7 +++ .../liltoonProtector/Shaders/Decrypt.cginc | 7 +++ .../Shaders/DecryptChacha.cginc | 7 +++ Runtime/liltoonProtector/Shaders/custom.hlsl | 15 ++++- .../lilCustomShaderProperties.lilblock | 3 +- SnowyWalkCustom.meta | 8 +++ SnowyWalkCustom/Editor.meta | 8 +++ SnowyWalkCustom/Editor/HashFloat4Editor.cs | 62 +++++++++++++++++++ .../Editor/HashFloat4Editor.cs.meta | 11 ++++ 11 files changed, 137 insertions(+), 5 deletions(-) create mode 100644 SnowyWalkCustom.meta create mode 100644 SnowyWalkCustom/Editor.meta create mode 100644 SnowyWalkCustom/Editor/HashFloat4Editor.cs create mode 100644 SnowyWalkCustom/Editor/HashFloat4Editor.cs.meta diff --git a/Editor/liltoonCustom/CustomInspector.cs b/Editor/liltoonCustom/CustomInspector.cs index 9829dea..8459a5c 100644 --- a/Editor/liltoonCustom/CustomInspector.cs +++ b/Editor/liltoonCustom/CustomInspector.cs @@ -11,8 +11,9 @@ public class ShellProtectorInspector : lilToonInspector MaterialProperty mip_tex; MaterialProperty encrypted_tex0; MaterialProperty encrypted_tex1; - MaterialProperty[] key = new MaterialProperty[15]; + MaterialProperty[] key = new MaterialProperty[16]; MaterialProperty fallback; + MaterialProperty decrypt_complete_key; private static bool isShowCustomProperties; private static bool show_pwd = false; @@ -34,6 +35,7 @@ protected override void LoadCustomProperties(MaterialProperty[] props, Material encrypted_tex0 = FindProperty("_EncryptTex0", props); encrypted_tex1 = FindProperty("_EncryptTex1", props); fallback = FindProperty("_fallback", props); + decrypt_complete_key = FindProperty("_Decrypt_complete_key", props); for (int i = 0; i < key.Length; ++i) key[i] = FindProperty("_Key" + i, props); @@ -68,6 +70,9 @@ protected override void DrawCustomProperties(Material material) EditorGUILayout.EndVertical(); EditorGUILayout.EndVertical(); + if (decrypt_complete_key != null) + m_MaterialEditor.ShaderProperty(decrypt_complete_key, "Decrypt complete key"); + show_pwd = Foldout("Keys", "Keys", show_pwd); if(show_pwd) { diff --git a/Runtime/Decrypt.cginc b/Runtime/Decrypt.cginc index 7de41a0..a676f12 100644 --- a/Runtime/Decrypt.cginc +++ b/Runtime/Decrypt.cginc @@ -163,4 +163,11 @@ half4 DecryptTextureDXT(half2 uv, int m) result = lerp(col2, col1, color1 > color2 ? col.rgb : 0.5); return half4(GammaCorrection(result), col.a); +} + +float4 HashFloat4(float4 v0, float4 v1, float4 v2, float4 v3) +{ + float4 seed = v0 * 0.1031 + v1 * 0.11369 + v2 * 0.13787 + v3 * 0.09997; + seed = frac(sin(seed) * 43758.5453); + return seed; } \ No newline at end of file diff --git a/Runtime/DecryptChacha.cginc b/Runtime/DecryptChacha.cginc index 3264d5c..f596361 100644 --- a/Runtime/DecryptChacha.cginc +++ b/Runtime/DecryptChacha.cginc @@ -165,4 +165,11 @@ half4 DecryptTextureDXT(half2 uv, int m) result = lerp(col2, col1, color1 > color2 ? col.rgb : 0.5); return half4(GammaCorrection(result), col.a); +} + +float4 HashFloat4(float4 v0, float4 v1, float4 v2, float4 v3) +{ + float4 seed = v0 * 0.1031 + v1 * 0.11369 + v2 * 0.13787 + v3 * 0.09997; + seed = frac(sin(seed) * 43758.5453); + return seed; } \ No newline at end of file diff --git a/Runtime/liltoonProtector/Shaders/Decrypt.cginc b/Runtime/liltoonProtector/Shaders/Decrypt.cginc index 7de41a0..a676f12 100644 --- a/Runtime/liltoonProtector/Shaders/Decrypt.cginc +++ b/Runtime/liltoonProtector/Shaders/Decrypt.cginc @@ -163,4 +163,11 @@ half4 DecryptTextureDXT(half2 uv, int m) result = lerp(col2, col1, color1 > color2 ? col.rgb : 0.5); return half4(GammaCorrection(result), col.a); +} + +float4 HashFloat4(float4 v0, float4 v1, float4 v2, float4 v3) +{ + float4 seed = v0 * 0.1031 + v1 * 0.11369 + v2 * 0.13787 + v3 * 0.09997; + seed = frac(sin(seed) * 43758.5453); + return seed; } \ No newline at end of file diff --git a/Runtime/liltoonProtector/Shaders/DecryptChacha.cginc b/Runtime/liltoonProtector/Shaders/DecryptChacha.cginc index 3264d5c..f596361 100644 --- a/Runtime/liltoonProtector/Shaders/DecryptChacha.cginc +++ b/Runtime/liltoonProtector/Shaders/DecryptChacha.cginc @@ -165,4 +165,11 @@ half4 DecryptTextureDXT(half2 uv, int m) result = lerp(col2, col1, color1 > color2 ? col.rgb : 0.5); return half4(GammaCorrection(result), col.a); +} + +float4 HashFloat4(float4 v0, float4 v1, float4 v2, float4 v3) +{ + float4 seed = v0 * 0.1031 + v1 * 0.11369 + v2 * 0.13787 + v3 * 0.09997; + seed = frac(sin(seed) * 43758.5453); + return seed; } \ No newline at end of file diff --git a/Runtime/liltoonProtector/Shaders/custom.hlsl b/Runtime/liltoonProtector/Shaders/custom.hlsl index 921fd50..73827fa 100644 --- a/Runtime/liltoonProtector/Shaders/custom.hlsl +++ b/Runtime/liltoonProtector/Shaders/custom.hlsl @@ -2,8 +2,9 @@ // Macro #define LIL_CUSTOM_PROPERTIES\ - half4 _EncryptTex0_TexelSize;\ - fixed _fallback; + half4 _EncryptTex0_TexelSize; \ + fixed _fallback; \ + float4 _Decrypt_complete_key; // Custom textures #define LIL_CUSTOM_TEXTURES\ @@ -59,10 +60,18 @@ fd.col *= _Color; #endif +#define DECRYPT_CHECK_FUNC \ + (all(abs(_Decrypt_complete_key - HashFloat4(\ + float4(_Key0, _Key1, _Key2, _Key3), \ + float4(_Key4, _Key5, _Key6, _Key7), \ + float4(_Key8, _Key9, _Key10, _Key11), \ + float4(_Key12, _Key13, _Key14, _Key15) \ + )) < 1e-1)) + #define OVERRIDE_MAIN\ LIL_GET_MAIN_TEX\ UNITY_BRANCH\ - if(_fallback == 1)\ + if(DECRYPT_CHECK_FUNC == false)\ {\ LIL_APPLY_MAIN_TONECORRECTION\ fd.col *= _Color;\ diff --git a/Runtime/liltoonProtector/Shaders/lilCustomShaderProperties.lilblock b/Runtime/liltoonProtector/Shaders/lilCustomShaderProperties.lilblock index 3fdb2a1..ca25171 100644 --- a/Runtime/liltoonProtector/Shaders/lilCustomShaderProperties.lilblock +++ b/Runtime/liltoonProtector/Shaders/lilCustomShaderProperties.lilblock @@ -22,4 +22,5 @@ _Hoffset ("Hoffset", integer) = 0 _Nonce0 ("Nonce", integer) = 0 _Nonce1 ("Nonce", integer) = 0 - _Nonce2 ("Nonce", integer) = 0 \ No newline at end of file + _Nonce2 ("Nonce", integer) = 0 + _Decrypt_complete_key ("Decrypt Complete Key", Vector) = (0, 0, 0, 0) \ No newline at end of file diff --git a/SnowyWalkCustom.meta b/SnowyWalkCustom.meta new file mode 100644 index 0000000..bf96995 --- /dev/null +++ b/SnowyWalkCustom.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: f93e766cd672ee6478d527420e02ccdb +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/SnowyWalkCustom/Editor.meta b/SnowyWalkCustom/Editor.meta new file mode 100644 index 0000000..869bbe4 --- /dev/null +++ b/SnowyWalkCustom/Editor.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: b2c169cd0e6511446b745a2ac88f7c67 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/SnowyWalkCustom/Editor/HashFloat4Editor.cs b/SnowyWalkCustom/Editor/HashFloat4Editor.cs new file mode 100644 index 0000000..2982cbe --- /dev/null +++ b/SnowyWalkCustom/Editor/HashFloat4Editor.cs @@ -0,0 +1,62 @@ +using UnityEngine; +using UnityEditor; + +public class HashFloat4Editor : EditorWindow +{ + Vector4 v0 = new Vector4(112f, 97f, 115f, 115f); + Vector4 v1 = Vector4.zero; + Vector4 v2 = Vector4.zero; + Vector4 v3 = Vector4.zero; + + Vector4 result; + + [MenuItem("SnowyWalk/HashFloat4 Editor")] + public static void ShowWindow() + { + GetWindow("HashFloat4 Editor"); + } + + void OnGUI() + { + // 벡터 입력 + v0 = EditorGUILayout.Vector4Field("v0", v0); + v1 = EditorGUILayout.Vector4Field("v1", v1); + v2 = EditorGUILayout.Vector4Field("v2", v2); + v3 = EditorGUILayout.Vector4Field("v3", v3); + + if (GUILayout.Button("Calculate")) + { + result = HashFloat4(v0, v1, v2, v3); + } + + EditorGUILayout.LabelField("Result", result.ToString("F5")); + } + + Vector4 HashFloat4(Vector4 a, Vector4 b, Vector4 c, Vector4 d) + { + // (1) seed 계산 + // float4 seed = v0*0.1031 + v1*0.11369 + v2*0.13787 + v3*0.09997; + Vector4 seed = a * 0.1031f + b * 0.11369f + c * 0.13787f + d * 0.09997f; + + // (2) sin(seed) * 43758.5453 => frac(...) + // sin()과 floor()는 C#에서 Mathf.Sin, Mathf.Floor 사용 + Vector4 sinVal = new Vector4( + Mathf.Sin(seed.x), + Mathf.Sin(seed.y), + Mathf.Sin(seed.z), + Mathf.Sin(seed.w) + ); + + sinVal *= 43758.5453f; + + // frac(x) = x - floor(x) + Vector4 fracVal = new Vector4( + sinVal.x - Mathf.Floor(sinVal.x), + sinVal.y - Mathf.Floor(sinVal.y), + sinVal.z - Mathf.Floor(sinVal.z), + sinVal.w - Mathf.Floor(sinVal.w) + ); + + return fracVal; + } +} diff --git a/SnowyWalkCustom/Editor/HashFloat4Editor.cs.meta b/SnowyWalkCustom/Editor/HashFloat4Editor.cs.meta new file mode 100644 index 0000000..c42ea0e --- /dev/null +++ b/SnowyWalkCustom/Editor/HashFloat4Editor.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 0618600a6526c23498f578069f4e01fd +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: