Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions Editor/liltoonCustom/CustomInspector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -165,4 +170,4 @@ private static void ConvertMaterialToCustomShaderMenu()
}
}
#endif
#endif
#endif
7 changes: 7 additions & 0 deletions Runtime/Decrypt.cginc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
7 changes: 7 additions & 0 deletions Runtime/DecryptChacha.cginc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
7 changes: 7 additions & 0 deletions Runtime/liltoonProtector/Shaders/Decrypt.cginc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
7 changes: 7 additions & 0 deletions Runtime/liltoonProtector/Shaders/DecryptChacha.cginc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
15 changes: 12 additions & 3 deletions Runtime/liltoonProtector/Shaders/custom.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -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\
Expand Down Expand Up @@ -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;\
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@
_Hoffset ("Hoffset", integer) = 0
_Nonce0 ("Nonce", integer) = 0
_Nonce1 ("Nonce", integer) = 0
_Nonce2 ("Nonce", integer) = 0
_Nonce2 ("Nonce", integer) = 0
_Decrypt_complete_key ("Decrypt Complete Key", Vector) = (0, 0, 0, 0)
8 changes: 8 additions & 0 deletions SnowyWalkCustom.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions SnowyWalkCustom/Editor.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

62 changes: 62 additions & 0 deletions SnowyWalkCustom/Editor/HashFloat4Editor.cs
Original file line number Diff line number Diff line change
@@ -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<HashFloat4Editor>("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;
}
}
11 changes: 11 additions & 0 deletions SnowyWalkCustom/Editor/HashFloat4Editor.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.