Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
e8080de
feat: set sync size for speed
cstria0106 Dec 6, 2024
10da6db
fix: backward compatibility for modified pkey
cstria0106 Dec 6, 2024
cc8ecdf
refactor: organize parameter names / simplify AddKeyParameter method
cstria0106 Dec 6, 2024
4cbc21a
feat: save on multiplexing
cstria0106 Dec 6, 2024
d0b6f26
fix: local only mux
cstria0106 Dec 6, 2024
4b77601
Inspector에서 보여주는 Key의 범위를 15 -> 16으로 수정
SnowyWalk Mar 23, 2025
7097638
Refactor: deduplicate shader/injector codes
cstria0106 Mar 23, 2025
34e8baa
Merge commit 'refs/pull/26/head' of https://github.com/Shell4026/Shel…
cstria0106 Mar 23, 2025
15797af
복호화 완료에 대한 판단 추가
Mar 23, 2025
f63915d
Merge branch 'main' of https://github.com/SnowyWalk/ShellProtector
Mar 23, 2025
798a1f6
Merge remote-tracking branch 'SnowyWalk/main'
cstria0106 Mar 24, 2025
cd1dc83
fix: fallback 애니메이션 제거
cstria0106 Mar 24, 2025
15043e6
fix: Poiyomi 대응
cstria0106 Mar 24, 2025
f220300
refactor: 하위호환성 파라미터 이름 제거
cstria0106 Mar 24, 2025
d2577fd
fix: multiplexing 선택 제거 (항상 활성화)
cstria0106 Mar 24, 2025
9b1addf
Refactor: extract format interface
cstria0106 Mar 25, 2025
194b1ee
fix: change log error to throw error in DXTFormat
cstria0106 Mar 25, 2025
34d1fa2
fix: remove bc7.cginc
cstria0106 Mar 25, 2025
22b0cd5
fix: remove bc7.cginc
cstria0106 Mar 25, 2025
1c0c3b7
Merge branch 'main' of https://github.com/cstria0106/ShellProtector
cstria0106 Mar 25, 2025
018d6d8
fix: fix upload error
cstria0106 Mar 26, 2025
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
19 changes: 9 additions & 10 deletions Editor/MaterialAdvancedSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,16 @@ private void OnGUI()
{
GUILayout.Label(Lang("The main texture is empty."), redStyle);
}
else if ((mainTex is Texture2D) == false)
else if (!TextureEncryptManager.IsSupportedTexture(mainTex))
{
GUILayout.Label(Lang("The main texture is not Texture2D."), redStyle);
}
else if (
mainTex.format != TextureFormat.DXT1 &&
mainTex.format != TextureFormat.DXT5 &&
mainTex.format != TextureFormat.RGB24 &&
mainTex.format != TextureFormat.RGBA32)
{
GUILayout.Label(Lang("The main texture is not supported format."), redStyle);
if (!(mainTex is Texture2D))
{
GUILayout.Label(Lang("The main texture is not Texture2D."), redStyle);
}
else
{
GUILayout.Label(Lang("The main texture is not supported format."), redStyle);
}
}
}
}
Expand Down
112 changes: 28 additions & 84 deletions Editor/ShellProtectorEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,11 @@ public class ShellProtectorEditor : Editor
SerializedProperty algorithm;
SerializedProperty key_size;
SerializedProperty key_size_idx;
SerializedProperty sync_size;
SerializedProperty animation_speed;
SerializedProperty delete_folders;
SerializedProperty parameter_multiplexing;
SerializedProperty bUseSmallMipTexture;
SerializedProperty bPreserveMMD;
SerializedProperty fallbackTime;
SerializedProperty turnOnAllSafetyFallback;
bool debug = false;
bool option = true;
Expand Down Expand Up @@ -110,12 +109,11 @@ void OnEnable()
algorithm = serializedObject.FindProperty("algorithm");
key_size = serializedObject.FindProperty("key_size");
key_size_idx = serializedObject.FindProperty("key_size_idx");
sync_size = serializedObject.FindProperty("sync_size");
animation_speed = serializedObject.FindProperty("animation_speed");
delete_folders = serializedObject.FindProperty("delete_folders");
parameter_multiplexing = serializedObject.FindProperty("parameter_multiplexing");
delete_folders = serializedObject.FindProperty("delete_folders");
bUseSmallMipTexture = serializedObject.FindProperty("bUseSmallMipTexture");
bPreserveMMD = serializedObject.FindProperty("bPreserveMMD");
fallbackTime = serializedObject.FindProperty("fallbackTime");
turnOnAllSafetyFallback = serializedObject.FindProperty("turnOnAllSafetyFallback");
#endregion

Expand Down Expand Up @@ -228,26 +226,9 @@ public override void OnInspectorGUI()
free_parameter = 256 - parameters.CalcTotalCost();
GUILayout.Label(Lang("Free parameter:") + free_parameter, EditorStyles.wordWrappedLabel);
}
int using_parameter = (key_size.intValue * 8);
if(parameter_multiplexing.boolValue == true)
{
int keys = key_size.intValue;
switch(keys)
{
case 4:
using_parameter = 8 + 3;
break;
case 8:
using_parameter = 8 + 4;
break;
case 12:
using_parameter = 8 + 5;
break;
case 16:
using_parameter = 8 + 5;
break;
}
}
int lock_size = 1;
int switch_count = ShellProtector.GetRequiredSwitchCount(key_size.intValue, sync_size.intValue);
int using_parameter = switch_count + lock_size + sync_size.intValue * 8;
GUILayout.Label(Lang("Parameters to be used:") + using_parameter, EditorStyles.wordWrappedLabel);

serializedObject.Update();
Expand Down Expand Up @@ -285,6 +266,21 @@ public override void OnInspectorGUI()
break;
}

var sync_size_value = sync_size.intValue;
int sync_size_index = 0;
int[] sync_size_caldidate = { 1, 2, 4};
string[] selectable_values = { "1", "2", "4" };
for (int i = 0; i < sync_size_caldidate.Length; i++)
if (sync_size_caldidate[i] == sync_size_value)
sync_size_index = i;

if(key_size.intValue > 0)
{
GUILayout.Label(Lang("Sync speed"), EditorStyles.boldLabel);
sync_size_index = EditorGUILayout.Popup(sync_size_index, selectable_values, GUILayout.Width(100));
sync_size.intValue = sync_size_caldidate[sync_size_index];
}

GUILayout.Label(Lang("Encrytion algorithm"), EditorStyles.boldLabel);
algorithm.intValue = EditorGUILayout.Popup(algorithm.intValue, enc_funcs, GUILayout.Width(120));

Expand Down Expand Up @@ -330,15 +326,6 @@ public override void OnInspectorGUI()

GUILayout.Space(10);

GUILayout.BeginHorizontal();
GUILayout.Label(Lang("parameter-multiplexing"), EditorStyles.boldLabel);
parameter_multiplexing.boolValue = EditorGUILayout.Toggle(parameter_multiplexing.boolValue);
GUILayout.FlexibleSpace();
GUILayout.EndHorizontal();
GUILayout.Label(Lang("The OSC program must always be on, but it consumes fewer parameters."), EditorStyles.wordWrappedLabel);

GUILayout.Space(10);

GUILayout.BeginHorizontal();
GUILayout.Label(Lang("Small mip texture"), EditorStyles.boldLabel);
bUseSmallMipTexture.boolValue = EditorGUILayout.Toggle(bUseSmallMipTexture.boolValue);
Expand Down Expand Up @@ -368,20 +355,6 @@ public override void OnInspectorGUI()
{
GUILayout.Label(Lang("Opponents with Safety option turned on will see degraded textures instead of noise."));

GUILayout.Label(Lang("Fallback wait time"), EditorStyles.boldLabel);
GUILayout.BeginHorizontal();
fallbackTime.floatValue = GUILayout.HorizontalSlider(fallbackTime.floatValue, 0.0f, 10.0f, GUILayout.Width(100));
fallbackTime.floatValue = EditorGUILayout.FloatField("", fallbackTime.floatValue, GUILayout.Width(50));
fallbackTime.floatValue = Mathf.Clamp(fallbackTime.floatValue, 0.0f, 10.0f);
#if UNITY_2022
fallbackTime.floatValue = MathF.Round(fallbackTime.floatValue, 1);
#endif
GUILayout.FlexibleSpace();
GUILayout.Label(Lang("After this time, the fallback is turned off. (Only who is Safety OFF)"), EditorStyles.wordWrappedLabel);
GUILayout.EndHorizontal();

GUILayout.Space(10);

GUILayout.BeginHorizontal();
GUILayout.Label(Lang("Change all Safety Fallback settings of shader to Unlit."), EditorStyles.boldLabel);
turnOnAllSafetyFallback.boolValue = EditorGUILayout.Toggle(turnOnAllSafetyFallback.boolValue);
Expand All @@ -406,7 +379,7 @@ public override void OnInspectorGUI()
if (game_object_list.count == 0 && material_list.count == 0)
GUI.enabled = false;


#if MODULAR
if (GUILayout.Button(Lang("Manual Encrypt!")))
#else
Expand Down Expand Up @@ -449,19 +422,19 @@ public override void OnInspectorGUI()

TextureSettings.SetRWEnableTexture(texture);

Texture2D[] encrypted_texture = root.GetEncryptTexture().TextureEncrypt(texture, KeyGenerator.MakeKeyBytes(root.pwd, root.pwd2, key_size.intValue), new XXTEA());
var result = TextureEncryptManager.EncryptTexture(texture, KeyGenerator.MakeKeyBytes(root.pwd, root.pwd2, key_size.intValue), new XXTEA());

last = encrypted_texture[0];
last = result.Texture1;

if (!AssetDatabase.IsValidFolder(root.asset_dir + '/' + root.descriptor.gameObject.name))
AssetDatabase.CreateFolder(root.asset_dir, root.descriptor.gameObject.name);
if (!AssetDatabase.IsValidFolder(root.asset_dir + '/' + root.descriptor.gameObject.name + "/mat"))
AssetDatabase.CreateFolder(root.asset_dir + '/' + root.descriptor.gameObject.name, "mat");

AssetDatabase.CreateAsset(encrypted_texture[0], root.asset_dir + '/' + root.descriptor.gameObject.name + '/' + texture.name + "_encrypt.asset");
File.WriteAllBytes(root.asset_dir + '/' + root.descriptor.gameObject.name + '/' + texture.name + "_encrypt.png", encrypted_texture[1].EncodeToPNG());
if (encrypted_texture[1] != null)
AssetDatabase.CreateAsset(encrypted_texture[1], root.asset_dir + '/' + root.descriptor.gameObject.name + '/' + texture.name + "_encrypt2.asset");
AssetDatabase.CreateAsset(result.Texture1, root.asset_dir + '/' + root.descriptor.gameObject.name + '/' + texture.name + "_encrypt.asset");
File.WriteAllBytes(root.asset_dir + '/' + root.descriptor.gameObject.name + '/' + texture.name + "_encrypt.png", result.Texture2.EncodeToPNG());
if (result.Texture2 != null)
AssetDatabase.CreateAsset(result.Texture2, root.asset_dir + '/' + root.descriptor.gameObject.name + '/' + texture.name + "_encrypt2.asset");
AssetDatabase.SaveAssets();

AssetDatabase.Refresh();
Expand All @@ -470,35 +443,6 @@ public override void OnInspectorGUI()
Selection.activeObject = last;
}

/*if (GUILayout.Button("Decrypt"))
{
Texture2D last = null;
for (int i = 0; i < texture_list.count; i++)
{
SerializedProperty textureProperty = texture_list.serializedProperty.GetArrayElementAtIndex(i);
Texture2D texture = textureProperty.objectReferenceValue as Texture2D;

root.SetRWEnableTexture(texture);

Texture2D tmp = root.GetEncryptTexture().TextureDecryptXXTEA(texture, root.MakeKeyBytes(root.pwd));

if (root.asset_dir[root.asset_dir.Length - 1] == '/')
root.asset_dir = root.asset_dir.Remove(root.asset_dir.Length - 1);

if (!AssetDatabase.IsValidFolder(root.asset_dir + '/' + root.gameObject.name))
AssetDatabase.CreateFolder(root.asset_dir, root.gameObject.name);
if (!AssetDatabase.IsValidFolder(root.asset_dir + '/' + root.gameObject.name + "/mat"))
AssetDatabase.CreateFolder(root.asset_dir + '/' + root.gameObject.name, "mat");

System.IO.File.WriteAllBytes(root.asset_dir + '/' + root.gameObject.name + '/' + texture.name + "_decrypt.png", tmp.EncodeToPNG());
last = (Texture2D)AssetDatabase.LoadAssetAtPath(root.asset_dir + '/' + root.gameObject.name + '/' + texture.name + "_decrypt.png", typeof(Texture2D));

AssetDatabase.Refresh();
}
if (last != null)
Selection.activeObject = last;
}*/

GUILayout.EndHorizontal();
}
serializedObject.ApplyModifiedProperties();
Expand Down
15 changes: 0 additions & 15 deletions Editor/TesterEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,21 +64,6 @@ public override void OnInspectorGUI()

GUILayout.Space(10);

GUILayout.BeginHorizontal();
if (GUILayout.Button(Lang("Off fallback")))
{
root.ResetEncryption();
root.protector.SetMaterialFallbackValue(root.transform.root.gameObject, false);
}
if (GUILayout.Button(Lang("On fallback")))
{
root.ResetEncryption();
root.protector.SetMaterialFallbackValue(root.transform.root.gameObject, true);
}
GUILayout.EndHorizontal();

GUILayout.Space(10);

if (root.userKeyLength == 0)
{
GUILayout.Label(Lang("It's okay for the 0-digit password to be the same as the original."));
Expand Down
17 changes: 11 additions & 6 deletions Editor/liltoonCustom/CustomInspector.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#if UNITY_EDITOR
using System.Linq;
using Shell.Protector;
using UnityEditor;
using UnityEngine;

Expand All @@ -11,8 +13,8 @@ public class ShellProtectorInspector : lilToonInspector
MaterialProperty mip_tex;
MaterialProperty encrypted_tex0;
MaterialProperty encrypted_tex1;
MaterialProperty[] key = new MaterialProperty[15];
MaterialProperty fallback;
MaterialProperty[] key = new MaterialProperty[16];
MaterialProperty password_hash;

private static bool isShowCustomProperties;
private static bool show_pwd = false;
Expand All @@ -33,7 +35,7 @@ protected override void LoadCustomProperties(MaterialProperty[] props, Material
mip_tex = FindProperty("_MipTex", props);
encrypted_tex0 = FindProperty("_EncryptTex0", props);
encrypted_tex1 = FindProperty("_EncryptTex1", props);
fallback = FindProperty("_fallback", props);
password_hash = FindProperty("_PasswordHash", props);

for (int i = 0; i < key.Length; ++i)
key[i] = FindProperty("_Key" + i, props);
Expand All @@ -52,8 +54,6 @@ protected override void DrawCustomProperties(Material material)
isShowCustomProperties = Foldout("ShellProtector", "ShellProtector", isShowCustomProperties);
if(isShowCustomProperties)
{
m_MaterialEditor.ShaderProperty(fallback, "fallback");

EditorGUILayout.BeginVertical(boxOuter);
EditorGUILayout.LabelField(GetLoc("ShellProtector"), customToggleFont);
EditorGUILayout.BeginVertical(boxInnerHalf);
Expand All @@ -68,6 +68,8 @@ protected override void DrawCustomProperties(Material material)
EditorGUILayout.EndVertical();
EditorGUILayout.EndVertical();

m_MaterialEditor.ShaderProperty(password_hash, "Password hash");

show_pwd = Foldout("Keys", "Keys", show_pwd);
if(show_pwd)
{
Expand All @@ -78,6 +80,9 @@ protected override void DrawCustomProperties(Material material)
m_MaterialEditor.ShaderProperty(key[i], "Key" + i);
}
}

var hash = ShellProtector.SimpleHash(key.Select(k => (byte)Mathf.RoundToInt(k.floatValue)).ToArray());
EditorGUILayout.LabelField("Password hash", hash.ToString());
}
}

Expand Down Expand Up @@ -165,4 +170,4 @@ private static void ConvertMaterialToCustomShaderMenu()
}
}
#endif
#endif
#endif
Loading