Bootstrap.cs 1008 B

12345678910111213141516171819202122232425262728293031323334
  1. using Obfuz;
  2. using Obfuz.EncryptionVM;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using UnityEngine;
  6. public class Bootstrap : MonoBehaviour
  7. {
  8. // [ObfuzIgnore]指示Obfuz不要混淆这个函数
  9. // 初始化EncryptionService后被混淆的代码才能正常运行,
  10. // 因此尽可能地早地初始化它。
  11. [ObfuzIgnore]
  12. [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.AfterAssembliesLoaded)]
  13. private static void SetUpStaticSecretKey()
  14. {
  15. Debug.Log("SetUpStaticSecret begin");
  16. EncryptionService<DefaultStaticEncryptionScope>.Encryptor = new GeneratedEncryptionVirtualMachine(Resources.Load<TextAsset>("Obfuz/defaultStaticSecretKey").bytes);
  17. Debug.Log("SetUpStaticSecret end");
  18. }
  19. int Add(int a, int b)
  20. {
  21. return a + b + 1;
  22. }
  23. // Start is called before the first frame update
  24. void Start()
  25. {
  26. Debug.Log("Hello, Obfuz");
  27. int a = Add(10, 20);
  28. Debug.Log($"a = {a}");
  29. }
  30. }