├── .gitignore ├── README.md └── Runtime ├── AntiCheatHelper.cs ├── AntiCheatHelper.cs.meta ├── JBool.cs ├── JBool.cs.meta ├── JByte.cs ├── JByte.cs.meta ├── JChar.cs ├── JChar.cs.meta ├── JDecimal.cs ├── JDecimal.cs.meta ├── JDouble.cs ├── JDouble.cs.meta ├── JFloat.cs ├── JFloat.cs.meta ├── JInt.cs ├── JInt.cs.meta ├── JLong.cs ├── JLong.cs.meta ├── JRandom.cs ├── JRandom.cs.meta ├── JSByte.cs ├── JSByte.cs.meta ├── JShort.cs ├── JShort.cs.meta ├── JString.cs ├── JString.cs.meta ├── JUInt.cs ├── JUInt.cs.meta ├── JULong.cs ├── JULong.cs.meta ├── JUShort.cs └── JUShort.cs.meta /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # JEngine.AntiCheat 2 | AntiCheat package for [JEngine](https://github.com/JasonXuDeveloper/JEngine). 3 | 4 | [JEngine](https://github.com/JasonXuDeveloper/JEngine)框架的多语言AntiCheat扩展包。 5 | 6 | 7 | 8 | ## Important 9 | 10 | This repo is only compatible with [JEngine](https://github.com/JasonXuDeveloper/JEngine) repo, otherwise it may not be able to compile or to execute. 11 | 12 | 该仓库仅与[JEngine](https://github.com/JasonXuDeveloper/JEngine)兼容,否则将无法编译或运行。 13 | 14 | 15 | 16 | ## What is this 17 | 18 | This is an additional package for JEngine framework, which provides AntiCheat for unity games. It provides the ability to ```encrypt data stored in memory```. 19 | 20 | 这是JEngine框架的额外扩展,对Unity游戏提供了反内存修改功能。提供了```内存数据加密```。 21 | 22 | 23 | 24 | ## How to use 25 | 26 | Please install [JEngine](https://github.com/JasonXuDeveloper/JEngine) (at least v0.8.0), then download this repo, finally move the repo directory into JEngine project's ```Assets/Dependencies``` path. 27 | 28 | Alternatively, you can use ```JEngine Package Manager``` to install. 29 | 30 | Refer JEngine's documentation for further usage. 31 | 32 | 请安装[JEngine](https://github.com/JasonXuDeveloper/JEngine)(至少v0.8.0),然后下载本仓库,接着将本仓库的文件夹移动到JEngine工程内的```Assets/Dependencies```目录下。 33 | 34 | 或者,你可以使用```JEngine Package Manager```来安装。 35 | 36 | 参考JEngine的文档以继续 37 | -------------------------------------------------------------------------------- /Runtime/AntiCheatHelper.cs: -------------------------------------------------------------------------------- 1 | // 2 | // AntiCheatHelper.cs 3 | // 4 | // Author: 5 | // JasonXuDeveloper(傑) 6 | // 7 | // Copyright (c) 2020 JEngine 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining a copy 10 | // of this software and associated documentation files (the "Software"), to deal 11 | // in the Software without restriction, including without limitation the rights 12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | // copies of the Software, and to permit persons to whom the Software is 14 | // furnished to do so, subject to the following conditions: 15 | // 16 | // The above copyright notice and this permission notice shall be included in 17 | // all copies or substantial portions of the Software. 18 | // 19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | // THE SOFTWARE. 26 | 27 | using System; 28 | using JEngine.Core; 29 | 30 | namespace JEngine.AntiCheat 31 | { 32 | public class AntiCheatHelper 33 | { 34 | private static Action _onDetected= () => 35 | { 36 | Log.Print("被抓到修改内存了哦~"); 37 | }; 38 | 39 | public static void OnMemoryCheatDetected(Action toDo) 40 | { 41 | _onDetected = toDo; 42 | } 43 | 44 | internal static void OnDetected() 45 | { 46 | _onDetected?.Invoke(); 47 | } 48 | } 49 | } -------------------------------------------------------------------------------- /Runtime/AntiCheatHelper.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 911f43300ca143dfbb26ea8ca03355b7 3 | timeCreated: 1602228730 -------------------------------------------------------------------------------- /Runtime/JBool.cs: -------------------------------------------------------------------------------- 1 | // 2 | // JBool.cs 3 | // 4 | // Author: 5 | // JasonXuDeveloper(傑) 6 | // 7 | // Copyright (c) 2020 JEngine 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining a copy 10 | // of this software and associated documentation files (the "Software"), to deal 11 | // in the Software without restriction, including without limitation the rights 12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | // copies of the Software, and to permit persons to whom the Software is 14 | // furnished to do so, subject to the following conditions: 15 | // 16 | // The above copyright notice and this permission notice shall be included in 17 | // all copies or substantial portions of the Software. 18 | // 19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | // THE SOFTWARE. 26 | namespace JEngine.AntiCheat 27 | { 28 | public struct JBool 29 | { 30 | private int _value; 31 | private int _randomValue; 32 | private bool _originalValue; 33 | 34 | private bool Value 35 | { 36 | get 37 | { 38 | unchecked 39 | { 40 | var result = _value - _randomValue != 0; 41 | if (!_originalValue.Equals(result)) 42 | { 43 | AntiCheatHelper.OnDetected(); 44 | } 45 | return result; 46 | } 47 | } 48 | 49 | set 50 | { 51 | _originalValue = value; 52 | unchecked 53 | { 54 | _randomValue = JRandom.RandomNum(1024); 55 | _value = (value ? 1 : 0) + _randomValue; 56 | } 57 | } 58 | 59 | } 60 | 61 | public JBool(bool value = false) 62 | { 63 | _value = 0; 64 | _randomValue = 0; 65 | _originalValue = true; 66 | Value = value; 67 | } 68 | 69 | public JBool(string value = "true") 70 | { 71 | _value = 0; 72 | _randomValue = 0; 73 | _originalValue = true; 74 | Value = value == "True"; 75 | } 76 | 77 | public static implicit operator JBool(bool value) => new JBool(value); 78 | 79 | public static implicit operator bool(JBool value) => value.Value; 80 | 81 | public static bool operator == (JBool a, JBool b) => a.Value == b.Value; 82 | public static bool operator == (JBool a, bool b) => a.Value == b; 83 | 84 | public static bool operator != (JBool a, JBool b) => a.Value != b.Value; 85 | public static bool operator != (JBool a, bool b) => a.Value != b; 86 | 87 | public static bool operator ! (JBool a) 88 | { 89 | return !a.Value; 90 | } 91 | 92 | public override string ToString() => Value.ToString(); 93 | 94 | public override int GetHashCode() => Value.GetHashCode(); 95 | 96 | public override bool Equals(object obj) => Value.Equals((obj is JBool ? (JBool) obj : default).Value); 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /Runtime/JBool.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c8389ba7c0744b68aad792ac72c6ec13 3 | timeCreated: 1601437084 -------------------------------------------------------------------------------- /Runtime/JByte.cs: -------------------------------------------------------------------------------- 1 | // 2 | // JByte.cs 3 | // 4 | // Author: 5 | // JasonXuDeveloper(傑) 6 | // 7 | // Copyright (c) 2020 JEngine 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining a copy 10 | // of this software and associated documentation files (the "Software"), to deal 11 | // in the Software without restriction, including without limitation the rights 12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | // copies of the Software, and to permit persons to whom the Software is 14 | // furnished to do so, subject to the following conditions: 15 | // 16 | // The above copyright notice and this permission notice shall be included in 17 | // all copies or substantial portions of the Software. 18 | // 19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | // THE SOFTWARE. 26 | 27 | using JEngine.Core; 28 | 29 | namespace JEngine.AntiCheat 30 | { 31 | public struct JByte 32 | { 33 | private byte _obscuredByte; 34 | private byte _obscuredKey; 35 | private byte _originalValue; 36 | 37 | private byte Value 38 | { 39 | get 40 | { 41 | var result = (byte) (_obscuredByte - _obscuredKey); 42 | if (!_originalValue.Equals(result)) 43 | { 44 | AntiCheatHelper.OnDetected(); 45 | } 46 | return result; 47 | } 48 | 49 | set 50 | { 51 | _originalValue = value; 52 | unchecked 53 | { 54 | _obscuredKey = (byte) JRandom.RandomNum(byte.MaxValue - value); 55 | _obscuredByte = (byte) (value + _obscuredKey); 56 | } 57 | } 58 | } 59 | 60 | public JByte(byte val = 0) 61 | { 62 | _obscuredByte = 0; 63 | _obscuredKey = 0; 64 | _originalValue = 0; 65 | Value = val; 66 | } 67 | public JByte(int val = 0) 68 | { 69 | _obscuredByte = 0; 70 | _obscuredKey = 0; 71 | _originalValue = 0; 72 | Value = val > byte.MaxValue ? byte.MaxValue : (byte) val; 73 | } 74 | 75 | public JByte(string val = "0") 76 | { 77 | _obscuredByte = 0; 78 | _obscuredKey = 0; 79 | _originalValue = 0; 80 | var result = byte.TryParse(val,out var _value); 81 | if (!result) 82 | { 83 | Log.PrintError($"无法将{val}变为{Value.GetType()},已改为0"); 84 | Value = 0; 85 | } 86 | else 87 | { 88 | Value = _value; 89 | } 90 | } 91 | 92 | public static implicit operator JByte(byte val) => new JByte(val); 93 | public static implicit operator byte(JByte val) => val.Value; 94 | public static bool operator ==(JByte a, JByte b) => a.Value == b.Value; 95 | public static bool operator !=(JByte a, JByte b) => a.Value != b.Value; 96 | 97 | public static JByte operator ++(JByte a) 98 | { 99 | a.Value++; 100 | return a; 101 | } 102 | 103 | public static JByte operator --(JByte a) 104 | { 105 | a.Value--; 106 | return a; 107 | } 108 | 109 | public static JByte operator + (JByte a, JByte b) => new JByte(a.Value + b.Value); 110 | public static JByte operator + (JByte a, byte b) => new JByte(a.Value + b); 111 | 112 | public static JByte operator - (JByte a, JByte b) => new JByte(a.Value - b.Value); 113 | public static JByte operator - (JByte a, byte b) => new JByte(a.Value - b); 114 | 115 | public static JByte operator * (JByte a, JByte b) => new JByte(a.Value * b.Value); 116 | public static JByte operator * (JByte a, byte b) => new JByte(a.Value * b); 117 | 118 | public static JByte operator / (JByte a, JByte b) => new JByte(a.Value / b.Value); 119 | public static JByte operator / (JByte a, byte b) => new JByte(a.Value / b); 120 | 121 | public static JByte operator % (JByte a, JByte b) => new JByte(a.Value % b.Value); 122 | public static JByte operator % (JByte a, byte b) => new JByte(a.Value % b); 123 | 124 | public override string ToString() => Value.ToString(); 125 | 126 | public override int GetHashCode() => Value.GetHashCode(); 127 | 128 | public override bool Equals(object obj) => Value.Equals((obj is JByte ? (JByte) obj : default).Value); 129 | } 130 | } -------------------------------------------------------------------------------- /Runtime/JByte.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 989e6e2c980e47e48c393680cc105923 3 | timeCreated: 1601438057 -------------------------------------------------------------------------------- /Runtime/JChar.cs: -------------------------------------------------------------------------------- 1 | // 2 | // JChar.cs 3 | // 4 | // Author: 5 | // JasonXuDeveloper(傑) 6 | // 7 | // Copyright (c) 2020 JEngine 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining a copy 10 | // of this software and associated documentation files (the "Software"), to deal 11 | // in the Software without restriction, including without limitation the rights 12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | // copies of the Software, and to permit persons to whom the Software is 14 | // furnished to do so, subject to the following conditions: 15 | // 16 | // The above copyright notice and this permission notice shall be included in 17 | // all copies or substantial portions of the Software. 18 | // 19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | // THE SOFTWARE. 26 | 27 | using System; 28 | using JEngine.Core; 29 | 30 | namespace JEngine.AntiCheat 31 | { 32 | public struct JChar 33 | { 34 | private int _obscuredChar; 35 | private int _obscuredKey; 36 | private char _originalValue; 37 | 38 | private char Value 39 | { 40 | get 41 | { 42 | var result = (char)(_obscuredChar-_obscuredKey); 43 | if (!_originalValue.Equals(result)) 44 | { 45 | AntiCheatHelper.OnDetected(); 46 | } 47 | return result; 48 | } 49 | 50 | set 51 | { 52 | _originalValue = value; 53 | unchecked 54 | { 55 | _obscuredKey = JRandom.RandomNum(value); 56 | _obscuredChar = value + _obscuredKey; 57 | } 58 | } 59 | } 60 | 61 | public JChar(int val = 0) 62 | { 63 | _obscuredChar = 0; 64 | _obscuredKey = 0; 65 | _originalValue = ' '; 66 | try 67 | { 68 | Value = Convert.ToChar(val); 69 | } 70 | catch 71 | { 72 | Log.PrintError($"无法将{val}变为{Value.GetType()},已改为{Char.MinValue}"); 73 | Value = Char.MinValue; 74 | } 75 | } 76 | 77 | public JChar(string val = "") 78 | { 79 | _obscuredChar = 0; 80 | _obscuredKey = 0; 81 | _originalValue = ' '; 82 | var result = char.TryParse(val,out var _value); 83 | if (!result) 84 | { 85 | Log.PrintError($"无法将{val}变为{Value.GetType()},已改为0"); 86 | Value = Char.MinValue; 87 | } 88 | else 89 | { 90 | Value = _value; 91 | } 92 | } 93 | 94 | public static implicit operator JChar(int val) => new JChar(val); 95 | public static implicit operator int(JChar val) => val.Value; 96 | public static bool operator ==(JChar a, JChar b) => a.Value == b.Value; 97 | public static bool operator !=(JChar a, JChar b) => a.Value != b.Value; 98 | 99 | public static JChar operator ++(JChar a) 100 | { 101 | a.Value++; 102 | return a; 103 | } 104 | 105 | public static JChar operator --(JChar a) 106 | { 107 | a.Value--; 108 | return a; 109 | } 110 | 111 | public static JChar operator + (JChar a, JChar b) => new JChar(a.Value + b.Value); 112 | public static JChar operator + (JChar a, int b) => new JChar(a.Value + b); 113 | 114 | public static JChar operator - (JChar a, JChar b) => new JChar(a.Value - b.Value); 115 | public static JChar operator - (JChar a, int b) => new JChar(a.Value - b); 116 | 117 | public static JChar operator * (JChar a, JChar b) => new JChar(a.Value * b.Value); 118 | public static JChar operator * (JChar a, int b) => new JChar(a.Value * b); 119 | 120 | public static JChar operator / (JChar a, JChar b) => new JChar(a.Value / b.Value); 121 | public static JChar operator / (JChar a, int b) => new JChar(a.Value / b); 122 | 123 | public static JChar operator % (JChar a, JChar b) => new JChar(a.Value % b.Value); 124 | public static JChar operator % (JChar a, int b) => new JChar(a.Value % b); 125 | 126 | public override string ToString() => Value.ToString(); 127 | 128 | public override int GetHashCode() => Value.GetHashCode(); 129 | 130 | public override bool Equals(object obj) => Value.Equals((obj is JChar ? (JChar) obj : default).Value); 131 | } 132 | } -------------------------------------------------------------------------------- /Runtime/JChar.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 04c3957823354138b091d8db1ca3a098 3 | timeCreated: 1601449994 -------------------------------------------------------------------------------- /Runtime/JDecimal.cs: -------------------------------------------------------------------------------- 1 | // 2 | // JDecimal.cs 3 | // 4 | // Author: 5 | // JasonXuDeveloper(傑) 6 | // 7 | // Copyright (c) 2020 JEngine 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining a copy 10 | // of this software and associated documentation files (the "Software"), to deal 11 | // in the Software without restriction, including without limitation the rights 12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | // copies of the Software, and to permit persons to whom the Software is 14 | // furnished to do so, subject to the following conditions: 15 | // 16 | // The above copyright notice and this permission notice shall be included in 17 | // all copies or substantial portions of the Software. 18 | // 19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | // THE SOFTWARE. 26 | 27 | using JEngine.Core; 28 | 29 | namespace JEngine.AntiCheat 30 | { 31 | public struct JDecimal 32 | { 33 | private decimal _obscuredDecimal; 34 | private int _obscuredKey; 35 | private decimal _originalValue; 36 | 37 | private decimal Value 38 | { 39 | get 40 | { 41 | var result = _obscuredDecimal - _obscuredKey; 42 | if (!_originalValue.Equals(result)) 43 | { 44 | AntiCheatHelper.OnDetected(); 45 | } 46 | 47 | return result; 48 | } 49 | 50 | set 51 | { 52 | _originalValue = value; 53 | unchecked 54 | { 55 | _obscuredKey = JRandom.RandomNum((int) value); 56 | _obscuredDecimal = value + _obscuredKey; 57 | } 58 | } 59 | } 60 | 61 | public JDecimal(decimal val = 0) 62 | { 63 | _obscuredDecimal = 0; 64 | _obscuredKey = 0; 65 | _originalValue = 0; 66 | Value = val; 67 | } 68 | 69 | public JDecimal(string val = "0") 70 | { 71 | _obscuredDecimal = 0; 72 | _obscuredKey = 0; 73 | _originalValue = 0; 74 | var result = decimal.TryParse(val,out var _value); 75 | if (!result) 76 | { 77 | Log.PrintError($"无法将{val}变为{Value.GetType()},已改为0"); 78 | Value = 0; 79 | } 80 | else 81 | { 82 | Value = _value; 83 | } 84 | } 85 | 86 | public static implicit operator JDecimal(decimal val) => new JDecimal(val); 87 | public static implicit operator decimal(JDecimal val) => val.Value; 88 | public static bool operator ==(JDecimal a, JDecimal b) => a.Value == b.Value; 89 | public static bool operator !=(JDecimal a, JDecimal b) => a.Value != b.Value; 90 | 91 | public static JDecimal operator ++(JDecimal a) 92 | { 93 | a.Value++; 94 | return a; 95 | } 96 | 97 | public static JDecimal operator --(JDecimal a) 98 | { 99 | a.Value--; 100 | return a; 101 | } 102 | 103 | public static JDecimal operator + (JDecimal a, JDecimal b) => new JDecimal(a.Value + b.Value); 104 | public static JDecimal operator + (JDecimal a, decimal b) => new JDecimal(a.Value + b); 105 | 106 | public static JDecimal operator - (JDecimal a, JDecimal b) => new JDecimal(a.Value - b.Value); 107 | public static JDecimal operator - (JDecimal a, decimal b) => new JDecimal(a.Value - b); 108 | 109 | public static JDecimal operator * (JDecimal a, JDecimal b) => new JDecimal(a.Value * b.Value); 110 | public static JDecimal operator * (JDecimal a, decimal b) => new JDecimal(a.Value * b); 111 | 112 | public static JDecimal operator / (JDecimal a, JDecimal b) => new JDecimal(a.Value / b.Value); 113 | public static JDecimal operator / (JDecimal a, decimal b) => new JDecimal(a.Value / b); 114 | 115 | public static JDecimal operator % (JDecimal a, JDecimal b) => new JDecimal(a.Value % b.Value); 116 | public static JDecimal operator % (JDecimal a, decimal b) => new JDecimal(a.Value % b); 117 | 118 | public override string ToString() => Value.ToString(); 119 | 120 | public override int GetHashCode() => Value.GetHashCode(); 121 | 122 | public override bool Equals(object obj) => Value.Equals((obj is JDecimal ? (JDecimal) obj : default).Value); 123 | } 124 | } -------------------------------------------------------------------------------- /Runtime/JDecimal.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 808654af4a444c0d855ed3546f4eda28 3 | timeCreated: 1601453867 -------------------------------------------------------------------------------- /Runtime/JDouble.cs: -------------------------------------------------------------------------------- 1 | // 2 | // JDouble.cs 3 | // 4 | // Author: 5 | // JasonXuDeveloper(傑) 6 | // 7 | // Copyright (c) 2020 JEngine 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining a copy 10 | // of this software and associated documentation files (the "Software"), to deal 11 | // in the Software without restriction, including without limitation the rights 12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | // copies of the Software, and to permit persons to whom the Software is 14 | // furnished to do so, subject to the following conditions: 15 | // 16 | // The above copyright notice and this permission notice shall be included in 17 | // all copies or substantial portions of the Software. 18 | // 19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | // THE SOFTWARE. 26 | 27 | using System; 28 | using System.Globalization; 29 | using JEngine.Core; 30 | 31 | namespace JEngine.AntiCheat 32 | { 33 | public struct JDouble 34 | { 35 | private ulong _obscuredDouble; 36 | private int _obscuredKey; 37 | private ulong _originalValue; 38 | 39 | private unsafe double Value 40 | { 41 | get 42 | { 43 | ulong result = _obscuredDouble - (ulong)_obscuredKey; 44 | var invalid = _originalValue != result; 45 | if (invalid) 46 | { 47 | AntiCheatHelper.OnDetected(); 48 | } 49 | 50 | return *(double*)&result; 51 | } 52 | 53 | set 54 | { 55 | _originalValue = *(ulong*)&value; 56 | unchecked 57 | { 58 | _obscuredKey = JRandom.RandomNum((int)value); 59 | _obscuredDouble = _originalValue + (ulong)_obscuredKey; 60 | } 61 | } 62 | } 63 | 64 | public JDouble(double val = 0) 65 | { 66 | _obscuredDouble = 0; 67 | _obscuredKey = 0; 68 | _originalValue = 0; 69 | Value = val; 70 | } 71 | 72 | public JDouble(string val = "0") 73 | { 74 | _obscuredDouble = 0; 75 | _obscuredKey = 0; 76 | _originalValue = 0; 77 | var result = double.TryParse(val, out var value); 78 | if (!result) 79 | { 80 | Log.PrintError($"无法将{val}变为{Value.GetType()},已改为0"); 81 | Value = 0; 82 | } 83 | else 84 | { 85 | Value = value; 86 | } 87 | } 88 | 89 | public static implicit operator JDouble(double val) => new JDouble(val); 90 | public static implicit operator double(JDouble val) => val.Value; 91 | public static bool operator ==(JDouble a, JDouble b) => a.Value.Equals(b.Value); 92 | public static bool operator !=(JDouble a, JDouble b) => !a.Value.Equals(b.Value); 93 | 94 | public static JDouble operator ++(JDouble a) 95 | { 96 | a.Value++; 97 | return a; 98 | } 99 | 100 | public static JDouble operator --(JDouble a) 101 | { 102 | a.Value--; 103 | return a; 104 | } 105 | 106 | public static JDouble operator +(JDouble a, JDouble b) => new JDouble(a.Value + b.Value); 107 | public static JDouble operator +(JDouble a, double b) => new JDouble(a.Value + b); 108 | public static JDouble operator +(JDouble a, float b) => new JDouble(a.Value + b); 109 | public static JDouble operator +(JDouble a, int b) => new JDouble(a.Value + b); 110 | 111 | public static JDouble operator -(JDouble a, JDouble b) => new JDouble(a.Value - b.Value); 112 | public static JDouble operator -(JDouble a, double b) => new JDouble(a.Value - b); 113 | public static JDouble operator -(JDouble a, float b) => new JDouble(a.Value - b); 114 | public static JDouble operator -(JDouble a, int b) => new JDouble(a.Value - b); 115 | 116 | public static JDouble operator *(JDouble a, JDouble b) => new JDouble(a.Value * b.Value); 117 | public static JDouble operator *(JDouble a, double b) => new JDouble(a.Value * b); 118 | public static JDouble operator *(JDouble a, float b) => new JDouble(a.Value * b); 119 | public static JDouble operator *(JDouble a, int b) => new JDouble(a.Value * b); 120 | 121 | public static JDouble operator /(JDouble a, JDouble b) => new JDouble(a.Value / b.Value); 122 | public static JDouble operator /(JDouble a, double b) => new JDouble(a.Value / b); 123 | public static JDouble operator /(JDouble a, float b) => new JDouble(a.Value / b); 124 | public static JDouble operator /(JDouble a, int b) => new JDouble(a.Value / b); 125 | 126 | public static JDouble operator %(JDouble a, JDouble b) => new JDouble(a.Value % b.Value); 127 | public static JDouble operator %(JDouble a, double b) => new JDouble(a.Value % b); 128 | public static JDouble operator %(JDouble a, float b) => new JDouble(a.Value % b); 129 | public static JDouble operator %(JDouble a, int b) => new JDouble(a.Value % b); 130 | 131 | public override string ToString() => Value.ToString(CultureInfo.CurrentCulture); 132 | 133 | public override int GetHashCode() => Value.GetHashCode(); 134 | 135 | public override bool Equals(object obj) => Value.Equals((obj is JDouble ? (JDouble)obj : default).Value); 136 | } 137 | } -------------------------------------------------------------------------------- /Runtime/JDouble.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5de6c032f03c4f6187dcd2a553833739 3 | timeCreated: 1601454013 -------------------------------------------------------------------------------- /Runtime/JFloat.cs: -------------------------------------------------------------------------------- 1 | // 2 | // JFloat.cs 3 | // 4 | // Author: 5 | // JasonXuDeveloper(傑) 6 | // 7 | // Copyright (c) 2020 JEngine 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining a copy 10 | // of this software and associated documentation files (the "Software"), to deal 11 | // in the Software without restriction, including without limitation the rights 12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | // copies of the Software, and to permit persons to whom the Software is 14 | // furnished to do so, subject to the following conditions: 15 | // 16 | // The above copyright notice and this permission notice shall be included in 17 | // all copies or substantial portions of the Software. 18 | // 19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | // THE SOFTWARE. 26 | 27 | using System; 28 | using System.Globalization; 29 | using JEngine.Core; 30 | 31 | namespace JEngine.AntiCheat 32 | { 33 | public struct JFloat 34 | { 35 | private uint _obscuredFloat; 36 | private int _obscuredKey; 37 | private uint _originalValue; 38 | 39 | private unsafe float Value 40 | { 41 | get 42 | { 43 | uint result = _obscuredDouble - (uint)_obscuredKey; 44 | var invalid = _originalValue != result; 45 | if (invalid) 46 | { 47 | AntiCheatHelper.OnDetected(); 48 | } 49 | 50 | return *(float*)&result; 51 | } 52 | 53 | set 54 | { 55 | _originalValue = *(uint*)&value; 56 | unchecked 57 | { 58 | _obscuredKey = JRandom.RandomNum((int)value); 59 | _obscuredDouble = _originalValue + (uint)_obscuredKey; 60 | } 61 | } 62 | } 63 | 64 | public JFloat(float val = 0) 65 | { 66 | _obscuredFloat = 0; 67 | _obscuredKey = 0; 68 | _originalValue = 0; 69 | Value = val; 70 | } 71 | 72 | public JFloat(string val = "0") 73 | { 74 | _obscuredFloat = 0; 75 | _obscuredKey = 0; 76 | _originalValue = 0; 77 | var result = float.TryParse(val,out var value); 78 | if (!result) 79 | { 80 | Log.PrintError($"无法将{val}变为{Value.GetType()},已改为0"); 81 | Value = 0; 82 | } 83 | else 84 | { 85 | Value = value; 86 | } 87 | } 88 | 89 | public static implicit operator JFloat(float val) => new JFloat(val); 90 | public static implicit operator float(JFloat val) => val.Value; 91 | public static bool operator ==(JFloat a, JFloat b) => Math.Abs(a.Value - b.Value) <= float.Epsilon; 92 | public static bool operator !=(JFloat a, JFloat b) => Math.Abs(a.Value - b.Value) > float.Epsilon; 93 | 94 | public static JFloat operator ++(JFloat a) 95 | { 96 | a.Value++; 97 | return a; 98 | } 99 | 100 | public static JFloat operator --(JFloat a) 101 | { 102 | a.Value--; 103 | return a; 104 | } 105 | 106 | public static JFloat operator + (JFloat a, JFloat b) => new JFloat(a.Value + b.Value); 107 | public static JFloat operator + (JFloat a, float b) => new JFloat(a.Value + b); 108 | public static JFloat operator + (JFloat a, int b) => new JFloat(a.Value + b); 109 | 110 | public static JFloat operator - (JFloat a, JFloat b) => new JFloat(a.Value - b.Value); 111 | public static JFloat operator - (JFloat a, float b) => new JFloat(a.Value - b); 112 | public static JFloat operator - (JFloat a, int b) => new JFloat(a.Value - b); 113 | 114 | public static JFloat operator * (JFloat a, JFloat b) => new JFloat(a.Value * b.Value); 115 | public static JFloat operator * (JFloat a, float b) => new JFloat(a.Value * b); 116 | public static JFloat operator * (JFloat a, int b) => new JFloat(a.Value * b); 117 | 118 | public static JFloat operator / (JFloat a, JFloat b) => new JFloat(a.Value / b.Value); 119 | public static JFloat operator / (JFloat a, float b) => new JFloat(a.Value / b); 120 | public static JFloat operator / (JFloat a, int b) => new JFloat(a.Value / b); 121 | 122 | public static JFloat operator % (JFloat a, JFloat b) => new JFloat(a.Value % b.Value); 123 | public static JFloat operator % (JFloat a, float b) => new JFloat(a.Value % b); 124 | public static JFloat operator %(JFloat a, int b) => new JFloat(a.Value % b); 125 | 126 | public override string ToString() => Value.ToString(CultureInfo.CurrentCulture); 127 | 128 | public override int GetHashCode() => Value.GetHashCode(); 129 | 130 | public override bool Equals(object obj) => Value.Equals((obj is JFloat jFloat ? jFloat : default).Value); 131 | } 132 | } -------------------------------------------------------------------------------- /Runtime/JFloat.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2432ee413afc4204b5721e0821d9c391 3 | timeCreated: 1601451462 -------------------------------------------------------------------------------- /Runtime/JInt.cs: -------------------------------------------------------------------------------- 1 | // 2 | // JInt.cs 3 | // 4 | // Author: 5 | // JasonXuDeveloper(傑) 6 | // 7 | // Copyright (c) 2020 JEngine 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining a copy 10 | // of this software and associated documentation files (the "Software"), to deal 11 | // in the Software without restriction, including without limitation the rights 12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | // copies of the Software, and to permit persons to whom the Software is 14 | // furnished to do so, subject to the following conditions: 15 | // 16 | // The above copyright notice and this permission notice shall be included in 17 | // all copies or substantial portions of the Software. 18 | // 19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | // THE SOFTWARE. 26 | 27 | using JEngine.Core; 28 | 29 | namespace JEngine.AntiCheat 30 | { 31 | public struct JInt 32 | { 33 | internal int ObscuredInt; 34 | internal int ObscuredKey; 35 | internal int OriginalValue; 36 | 37 | private int Value 38 | { 39 | get 40 | { 41 | var result = ObscuredInt - ObscuredKey; 42 | if (!OriginalValue.Equals(result)) 43 | { 44 | AntiCheatHelper.OnDetected(); 45 | } 46 | return result; 47 | } 48 | 49 | set 50 | { 51 | OriginalValue = value; 52 | unchecked 53 | { 54 | ObscuredKey = JRandom.RandomNum(int.MaxValue - value); 55 | ObscuredInt = value + ObscuredKey; 56 | } 57 | } 58 | } 59 | 60 | public JInt(int val = 0) 61 | { 62 | ObscuredInt = 0; 63 | ObscuredKey = 0; 64 | OriginalValue = 0; 65 | Value = val; 66 | } 67 | 68 | public JInt(string val = "0") 69 | { 70 | ObscuredInt = 0; 71 | ObscuredKey = 0; 72 | OriginalValue = 0; 73 | var result = int.TryParse(val,out var _value); 74 | if (!result) 75 | { 76 | Log.PrintError($"无法将{val}变为{Value.GetType()},已改为0"); 77 | Value = 0; 78 | } 79 | else 80 | { 81 | Value = _value; 82 | } 83 | } 84 | 85 | public static implicit operator JInt(int val) => new JInt(val); 86 | public static implicit operator int(JInt val) => val.Value; 87 | 88 | public static bool operator ==(JInt a, JInt b) => a.Value == b.Value; 89 | public static bool operator ==(JInt a, int b) => a.Value == b; 90 | public static bool operator !=(JInt a, JInt b) => a.Value != b.Value; 91 | public static bool operator !=(JInt a, int b) => a.Value != b; 92 | 93 | public static JInt operator ++(JInt a) 94 | { 95 | a.Value++; 96 | return a; 97 | } 98 | 99 | public static JInt operator --(JInt a) 100 | { 101 | a.Value--; 102 | return a; 103 | } 104 | 105 | public static JInt operator + (JInt a, JInt b) => new JInt(a.Value + b.Value); 106 | public static JInt operator + (JInt a, int b) => new JInt(a.Value + b); 107 | 108 | public static JInt operator - (JInt a, JInt b) => new JInt(a.Value - b.Value); 109 | public static JInt operator - (JInt a, int b) => new JInt(a.Value - b); 110 | 111 | public static JInt operator * (JInt a, JInt b) => new JInt(a.Value * b.Value); 112 | public static JInt operator * (JInt a, int b) => new JInt(a.Value * b); 113 | 114 | public static JInt operator / (JInt a, JInt b) => new JInt(a.Value / b.Value); 115 | public static JInt operator / (JInt a, int b) => new JInt(a.Value / b); 116 | 117 | public static JInt operator % (JInt a, JInt b) => new JInt(a.Value % b.Value); 118 | public static JInt operator % (JInt a, int b) => new JInt(a.Value % b); 119 | 120 | public override string ToString() => Value.ToString(); 121 | 122 | public override int GetHashCode() => Value.GetHashCode(); 123 | 124 | public override bool Equals(object obj) => Value.Equals(obj is JInt ? ((JInt) obj).Value : obj); 125 | } 126 | } -------------------------------------------------------------------------------- /Runtime/JInt.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 64b49f4c10f64055b743660e361a1b9f 3 | timeCreated: 1601430677 -------------------------------------------------------------------------------- /Runtime/JLong.cs: -------------------------------------------------------------------------------- 1 | // 2 | // JLong.cs 3 | // 4 | // Author: 5 | // JasonXuDeveloper(傑) 6 | // 7 | // Copyright (c) 2020 JEngine 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining a copy 10 | // of this software and associated documentation files (the "Software"), to deal 11 | // in the Software without restriction, including without limitation the rights 12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | // copies of the Software, and to permit persons to whom the Software is 14 | // furnished to do so, subject to the following conditions: 15 | // 16 | // The above copyright notice and this permission notice shall be included in 17 | // all copies or substantial portions of the Software. 18 | // 19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | // THE SOFTWARE. 26 | 27 | using JEngine.Core; 28 | 29 | namespace JEngine.AntiCheat 30 | { 31 | public struct JLong 32 | { 33 | private long _obscuredLong; 34 | private long _obscuredKey; 35 | private long _originalValue; 36 | 37 | private long Value 38 | { 39 | get 40 | { 41 | var result =_obscuredLong-_obscuredKey; 42 | if (!_originalValue.Equals(result)) 43 | { 44 | AntiCheatHelper.OnDetected(); 45 | } 46 | return result; 47 | } 48 | 49 | set 50 | { 51 | _originalValue = value; 52 | unchecked 53 | { 54 | _obscuredKey = JRandom.RandomNum(long.MaxValue - value); 55 | _obscuredLong = value + _obscuredKey; 56 | } 57 | } 58 | } 59 | 60 | public JLong(long val = 0) 61 | { 62 | _obscuredLong = 0; 63 | _obscuredKey = 0; 64 | _originalValue = 0; 65 | Value = val; 66 | } 67 | 68 | public JLong(string val = "0") 69 | { 70 | _obscuredLong = 0; 71 | _obscuredKey = 0; 72 | _originalValue = 0; 73 | var result = long.TryParse(val,out var _value); 74 | if (!result) 75 | { 76 | Log.PrintError($"无法将{val}变为{Value.GetType()},已改为0"); 77 | Value = 0; 78 | } 79 | else 80 | { 81 | Value = _value; 82 | } 83 | } 84 | 85 | public static implicit operator JLong(long val) => new JLong(val); 86 | public static implicit operator long(JLong val) => val.Value; 87 | public static bool operator ==(JLong a, JLong b) => a.Value == b.Value; 88 | public static bool operator !=(JLong a, JLong b) => a.Value != b.Value; 89 | 90 | public static JLong operator ++(JLong a) 91 | { 92 | a.Value++; 93 | return a; 94 | } 95 | 96 | public static JLong operator --(JLong a) 97 | { 98 | a.Value--; 99 | return a; 100 | } 101 | 102 | public static JLong operator + (JLong a, JLong b) => new JLong(a.Value + b.Value); 103 | public static JLong operator + (JLong a, long b) => new JLong(a.Value + b); 104 | 105 | public static JLong operator - (JLong a, JLong b) => new JLong(a.Value - b.Value); 106 | public static JLong operator - (JLong a, long b) => new JLong(a.Value - b); 107 | 108 | public static JLong operator * (JLong a, JLong b) => new JLong(a.Value * b.Value); 109 | public static JLong operator * (JLong a, long b) => new JLong(a.Value * b); 110 | 111 | public static JLong operator / (JLong a, JLong b) => new JLong(a.Value / b.Value); 112 | public static JLong operator / (JLong a, long b) => new JLong(a.Value / b); 113 | 114 | public static JLong operator % (JLong a, JLong b) => new JLong(a.Value % b.Value); 115 | public static JLong operator % (JLong a, long b) => new JLong(a.Value % b); 116 | 117 | public override string ToString() => Value.ToString(); 118 | 119 | public override int GetHashCode() => Value.GetHashCode(); 120 | 121 | public override bool Equals(object obj) => Value.Equals((obj is JLong ? (JLong) obj : default).Value); 122 | } 123 | } -------------------------------------------------------------------------------- /Runtime/JLong.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 9463145b46294a4db54ad2735f3270bb 3 | timeCreated: 1601440124 -------------------------------------------------------------------------------- /Runtime/JRandom.cs: -------------------------------------------------------------------------------- 1 | // 2 | // JRandom.cs 3 | // 4 | // Author: 5 | // JasonXuDeveloper(傑) 6 | // 7 | // Copyright (c) 2020 JEngine 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining a copy 10 | // of this software and associated documentation files (the "Software"), to deal 11 | // in the Software without restriction, including without limitation the rights 12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | // copies of the Software, and to permit persons to whom the Software is 14 | // furnished to do so, subject to the following conditions: 15 | // 16 | // The above copyright notice and this permission notice shall be included in 17 | // all copies or substantial portions of the Software. 18 | // 19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | // THE SOFTWARE. 26 | 27 | using System; 28 | 29 | namespace JEngine.AntiCheat 30 | { 31 | public class JRandom 32 | { 33 | private static Random _random = new Random(); 34 | 35 | private JRandom() 36 | { 37 | 38 | } 39 | 40 | public static int RandomNum(int max = 1024) 41 | { 42 | return _random.Next(0, max < 0 ? 1024 : max); 43 | } 44 | 45 | public static int RandomNum(uint max = 1024) 46 | { 47 | return _random.Next(0, max > int.MaxValue ? int.MaxValue : (int) max); 48 | } 49 | 50 | public static int RandomNum(long max = 1024) 51 | { 52 | return _random.Next(0, max > int.MaxValue || max < int.MaxValue? int.MaxValue : (int) max); 53 | } 54 | 55 | public static int RandomNum(ulong max = 1024) 56 | { 57 | return _random.Next(0, max > int.MaxValue || max < int.MaxValue ? int.MaxValue : (int) max); 58 | } 59 | 60 | public static int RandomNum(float max = 1024) 61 | { 62 | return _random.Next(0, max > int.MaxValue || max < int.MaxValue ? int.MaxValue : (int) max); 63 | } 64 | } 65 | } -------------------------------------------------------------------------------- /Runtime/JRandom.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b125386c6ba34824855a5a4f99b8f3ac 3 | timeCreated: 1601436903 -------------------------------------------------------------------------------- /Runtime/JSByte.cs: -------------------------------------------------------------------------------- 1 | // 2 | // JSByte.cs 3 | // 4 | // Author: 5 | // JasonXuDeveloper(傑) 6 | // 7 | // Copyright (c) 2020 JEngine 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining a copy 10 | // of this software and associated documentation files (the "Software"), to deal 11 | // in the Software without restriction, including without limitation the rights 12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | // copies of the Software, and to permit persons to whom the Software is 14 | // furnished to do so, subject to the following conditions: 15 | // 16 | // The above copyright notice and this permission notice shall be included in 17 | // all copies or substantial portions of the Software. 18 | // 19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | // THE SOFTWARE. 26 | 27 | using JEngine.Core; 28 | 29 | namespace JEngine.AntiCheat 30 | { 31 | public struct JSByte 32 | { 33 | private sbyte _obscuredSByte; 34 | private sbyte _obscuredKey; 35 | private sbyte _originalValue; 36 | 37 | private sbyte Value 38 | { 39 | get 40 | { 41 | var result=(sbyte)(_obscuredSByte-_obscuredKey); 42 | if (!_originalValue.Equals(result)) 43 | { 44 | AntiCheatHelper.OnDetected(); 45 | } 46 | return result; 47 | } 48 | 49 | set 50 | { 51 | _originalValue = value; 52 | unchecked 53 | { 54 | _obscuredKey = (sbyte) JRandom.RandomNum(sbyte.MaxValue - value); 55 | _obscuredSByte = (sbyte) (value + _obscuredKey); 56 | } 57 | } 58 | } 59 | 60 | public JSByte(sbyte val = 0) 61 | { 62 | _obscuredSByte = 0; 63 | _obscuredKey = 0; 64 | _originalValue = 0; 65 | Value = val; 66 | } 67 | public JSByte(int val = 0) 68 | { 69 | _obscuredSByte = 0; 70 | _obscuredKey = 0; 71 | _originalValue = 0; 72 | 73 | Value = val > sbyte.MaxValue ? sbyte.MaxValue : (sbyte) val; 74 | } 75 | 76 | public JSByte(string val = "0") 77 | { 78 | _obscuredSByte = 0; 79 | _obscuredKey = 0; 80 | _originalValue = 0; 81 | var result = sbyte.TryParse(val,out var _value); 82 | if (!result) 83 | { 84 | Log.PrintError($"无法将{val}变为{Value.GetType()},已改为0"); 85 | Value = 0; 86 | } 87 | else 88 | { 89 | Value = _value; 90 | } 91 | } 92 | 93 | public static implicit operator JSByte(sbyte val) => new JSByte(val); 94 | public static implicit operator sbyte(JSByte val) => val.Value; 95 | public static bool operator ==(JSByte a, JSByte b) => a.Value == b.Value; 96 | public static bool operator !=(JSByte a, JSByte b) => a.Value != b.Value; 97 | 98 | public static JSByte operator ++(JSByte a) 99 | { 100 | a.Value++; 101 | return a; 102 | } 103 | 104 | public static JSByte operator --(JSByte a) 105 | { 106 | a.Value--; 107 | return a; 108 | } 109 | 110 | public static JSByte operator + (JSByte a, JSByte b) => new JSByte(a.Value + b.Value); 111 | public static JSByte operator + (JSByte a, sbyte b) => new JSByte(a.Value + b); 112 | 113 | public static JSByte operator - (JSByte a, JSByte b) => new JSByte(a.Value - b.Value); 114 | public static JSByte operator - (JSByte a, sbyte b) => new JSByte(a.Value - b); 115 | 116 | public static JSByte operator * (JSByte a, JSByte b) => new JSByte(a.Value * b.Value); 117 | public static JSByte operator * (JSByte a, sbyte b) => new JSByte(a.Value * b); 118 | 119 | public static JSByte operator / (JSByte a, JSByte b) => new JSByte(a.Value / b.Value); 120 | public static JSByte operator / (JSByte a, sbyte b) => new JSByte(a.Value / b); 121 | 122 | public static JSByte operator % (JSByte a, JSByte b) => new JSByte(a.Value % b.Value); 123 | public static JSByte operator % (JSByte a, sbyte b) => new JSByte(a.Value % b); 124 | 125 | public override string ToString() => Value.ToString(); 126 | 127 | public override int GetHashCode() => Value.GetHashCode(); 128 | 129 | public override bool Equals(object obj) => Value.Equals((obj is JSByte ? (JSByte) obj : default).Value); 130 | } 131 | } -------------------------------------------------------------------------------- /Runtime/JSByte.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 84835539cb4a4f00a869f1153891bbc6 3 | timeCreated: 1601439699 -------------------------------------------------------------------------------- /Runtime/JShort.cs: -------------------------------------------------------------------------------- 1 | // 2 | // JShort.cs 3 | // 4 | // Author: 5 | // JasonXuDeveloper(傑) 6 | // 7 | // Copyright (c) 2020 JEngine 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining a copy 10 | // of this software and associated documentation files (the "Software"), to deal 11 | // in the Software without restriction, including without limitation the rights 12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | // copies of the Software, and to permit persons to whom the Software is 14 | // furnished to do so, subject to the following conditions: 15 | // 16 | // The above copyright notice and this permission notice shall be included in 17 | // all copies or substantial portions of the Software. 18 | // 19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | // THE SOFTWARE. 26 | 27 | using JEngine.Core; 28 | 29 | namespace JEngine.AntiCheat 30 | { 31 | public struct JShort 32 | { 33 | private short _obscuredShort; 34 | private short _obscuredKey; 35 | private short _originalValue; 36 | 37 | private short Value 38 | { 39 | get 40 | { 41 | var result = (short)(_obscuredShort-_obscuredKey); 42 | if (!_originalValue.Equals(result)) 43 | { 44 | AntiCheatHelper.OnDetected(); 45 | } 46 | return result; 47 | } 48 | 49 | set 50 | { 51 | _originalValue = value; 52 | unchecked 53 | { 54 | _obscuredKey = (short) JRandom.RandomNum(short.MaxValue - value); 55 | _obscuredShort = (short) (value + _obscuredKey); 56 | } 57 | } 58 | } 59 | 60 | public JShort(short val = 0) 61 | { 62 | _obscuredShort = 0; 63 | _obscuredKey = 0; 64 | _originalValue = 0; 65 | Value = val; 66 | } 67 | public JShort(int val = 0) 68 | { 69 | _obscuredShort = 0; 70 | _obscuredKey = 0; 71 | _originalValue = 0; 72 | Value = val > short.MaxValue ? short.MaxValue : (short) val; 73 | } 74 | 75 | public JShort(string val = "0") 76 | { 77 | _obscuredShort = 0; 78 | _obscuredKey = 0; 79 | _originalValue = 0; 80 | var result = short.TryParse(val,out var _value); 81 | if (!result) 82 | { 83 | Log.PrintError($"无法将{val}变为{Value.GetType()},已改为0"); 84 | Value = 0; 85 | } 86 | else 87 | { 88 | Value = _value; 89 | } 90 | } 91 | 92 | public static implicit operator JShort(short val) => new JShort(val); 93 | public static implicit operator short(JShort val) => val.Value; 94 | public static bool operator ==(JShort a, JShort b) => a.Value == b.Value; 95 | public static bool operator !=(JShort a, JShort b) => a.Value != b.Value; 96 | 97 | public static JShort operator ++(JShort a) 98 | { 99 | a.Value++; 100 | return a; 101 | } 102 | 103 | public static JShort operator --(JShort a) 104 | { 105 | a.Value--; 106 | return a; 107 | } 108 | 109 | public static JShort operator + (JShort a, JShort b) => new JShort(a.Value + b.Value); 110 | public static JShort operator + (JShort a, short b) => new JShort(a.Value + b); 111 | 112 | public static JShort operator - (JShort a, JShort b) => new JShort(a.Value - b.Value); 113 | public static JShort operator - (JShort a, short b) => new JShort(a.Value - b); 114 | 115 | public static JShort operator * (JShort a, JShort b) => new JShort(a.Value * b.Value); 116 | public static JShort operator * (JShort a, short b) => new JShort(a.Value * b); 117 | 118 | public static JShort operator / (JShort a, JShort b) => new JShort(a.Value / b.Value); 119 | public static JShort operator / (JShort a, short b) => new JShort(a.Value / b); 120 | 121 | public static JShort operator % (JShort a, JShort b) => new JShort(a.Value % b.Value); 122 | public static JShort operator % (JShort a, short b) => new JShort(a.Value % b); 123 | 124 | public override string ToString() => Value.ToString(); 125 | 126 | public override int GetHashCode() => Value.GetHashCode(); 127 | 128 | public override bool Equals(object obj) => Value.Equals((obj is JShort ? (JShort) obj : default).Value); 129 | } 130 | } -------------------------------------------------------------------------------- /Runtime/JShort.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f60be290e121435da0c65a6b88d1d99d 3 | timeCreated: 1601437248 -------------------------------------------------------------------------------- /Runtime/JString.cs: -------------------------------------------------------------------------------- 1 | // 2 | // JString.cs 3 | // 4 | // Author: 5 | // JasonXuDeveloper(傑) 6 | // 7 | // Copyright (c) 2020 JEngine 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining a copy 10 | // of this software and associated documentation files (the "Software"), to deal 11 | // in the Software without restriction, including without limitation the rights 12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | // copies of the Software, and to permit persons to whom the Software is 14 | // furnished to do so, subject to the following conditions: 15 | // 16 | // The above copyright notice and this permission notice shall be included in 17 | // all copies or substantial portions of the Software. 18 | // 19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | // THE SOFTWARE. 26 | 27 | using JEngine.Core; 28 | 29 | namespace JEngine.AntiCheat 30 | { 31 | public struct JString 32 | { 33 | private string _obscuredString; 34 | private string _originalValue; 35 | 36 | private string Value { 37 | get 38 | { 39 | if (_obscuredString == null) return null; 40 | var result = CryptoMgr.DecryptStr(_obscuredString,InitJEngine.Instance.key); 41 | if (!_originalValue.Equals(result)) 42 | { 43 | AntiCheatHelper.OnDetected(); 44 | } 45 | return result; 46 | } 47 | 48 | set 49 | { 50 | _originalValue = value; 51 | unchecked 52 | { 53 | if (value == null) 54 | { 55 | _obscuredString = null; 56 | return; 57 | } 58 | _obscuredString = CryptoMgr.EncryptStr(value, InitJEngine.Instance.key); 59 | } 60 | } 61 | } 62 | 63 | public JString(string val = "") 64 | { 65 | _obscuredString = ""; 66 | _originalValue = ""; 67 | Value = val; 68 | } 69 | 70 | public static implicit operator JString(string val) => new JString(val); 71 | public static implicit operator string(JString val) => val.Value; 72 | public static bool operator ==(JString a, JString b) => a.Value == b.Value; 73 | public static bool operator !=(JString a, JString b) => a.Value != b.Value; 74 | 75 | public static JString operator + (JString a, JString b) => new JString(a.Value + b.Value); 76 | public static JString operator + (JString a, string b) => new JString(a.Value + b); 77 | 78 | public override string ToString() => Value; 79 | 80 | public override int GetHashCode() => Value.GetHashCode(); 81 | 82 | public override bool Equals(object obj) => Value.Equals((obj is JString ? (JString) obj : default).Value); 83 | } 84 | } -------------------------------------------------------------------------------- /Runtime/JString.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f53a929aa90b4fd1b1f879fe46556e81 3 | timeCreated: 1601450732 -------------------------------------------------------------------------------- /Runtime/JUInt.cs: -------------------------------------------------------------------------------- 1 | // 2 | // JUInt.cs 3 | // 4 | // Author: 5 | // JasonXuDeveloper(傑) 6 | // 7 | // Copyright (c) 2020 JEngine 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining a copy 10 | // of this software and associated documentation files (the "Software"), to deal 11 | // in the Software without restriction, including without limitation the rights 12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | // copies of the Software, and to permit persons to whom the Software is 14 | // furnished to do so, subject to the following conditions: 15 | // 16 | // The above copyright notice and this permission notice shall be included in 17 | // all copies or substantial portions of the Software. 18 | // 19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | // THE SOFTWARE. 26 | 27 | using JEngine.Core; 28 | 29 | namespace JEngine.AntiCheat 30 | { 31 | public struct JUInt 32 | { 33 | private uint _obscuredUInt; 34 | private int _obscuredKey; 35 | private uint _originalValue; 36 | 37 | private uint Value 38 | { 39 | get 40 | { 41 | var result = (uint) (_obscuredUInt - _obscuredKey); 42 | if (!_originalValue.Equals(result)) 43 | { 44 | AntiCheatHelper.OnDetected(); 45 | } 46 | 47 | return result; 48 | } 49 | 50 | set 51 | { 52 | _originalValue = value; 53 | unchecked 54 | { 55 | _obscuredKey = JRandom.RandomNum((int)(int.MaxValue - value)); 56 | _obscuredUInt = (uint) (value + _obscuredKey); 57 | } 58 | } 59 | } 60 | 61 | public JUInt(uint val = 0) 62 | { 63 | _obscuredUInt = 0; 64 | _obscuredKey = 0; 65 | _originalValue = 0; 66 | Value = val; 67 | } 68 | public JUInt(int val = 0) 69 | { 70 | _obscuredUInt = 0; 71 | _obscuredKey = 0; 72 | _originalValue = 0; 73 | #pragma warning disable 652 74 | Value = val > uint.MaxValue ? uint.MaxValue : (uint) val; 75 | #pragma warning restore 652 76 | } 77 | 78 | public JUInt(string val = "0") 79 | { 80 | _obscuredUInt = 0; 81 | _obscuredKey = 0; 82 | _originalValue = 0; 83 | var result = uint.TryParse(val,out var _value); 84 | if (!result) 85 | { 86 | Log.PrintError($"无法将{val}变为{Value.GetType()},已改为0"); 87 | Value = 0; 88 | } 89 | else 90 | { 91 | Value = _value; 92 | } 93 | } 94 | 95 | public static implicit operator JUInt(uint val) => new JUInt(val); 96 | public static implicit operator uint(JUInt val) => val.Value; 97 | public static bool operator ==(JUInt a, JUInt b) => a.Value == b.Value; 98 | public static bool operator !=(JUInt a, JUInt b) => a.Value != b.Value; 99 | 100 | public static JUInt operator ++(JUInt a) 101 | { 102 | a.Value++; 103 | return a; 104 | } 105 | 106 | public static JUInt operator --(JUInt a) 107 | { 108 | a.Value--; 109 | return a; 110 | } 111 | 112 | public static JUInt operator + (JUInt a, JUInt b) => new JUInt(a.Value + b.Value); 113 | public static JUInt operator + (JUInt a, uint b) => new JUInt(a.Value + b); 114 | 115 | public static JUInt operator - (JUInt a, JUInt b) => new JUInt(a.Value - b.Value); 116 | public static JUInt operator - (JUInt a, uint b) => new JUInt(a.Value - b); 117 | 118 | public static JUInt operator * (JUInt a, JUInt b) => new JUInt(a.Value * b.Value); 119 | public static JUInt operator * (JUInt a, uint b) => new JUInt(a.Value * b); 120 | 121 | public static JUInt operator / (JUInt a, JUInt b) => new JUInt(a.Value / b.Value); 122 | public static JUInt operator / (JUInt a, uint b) => new JUInt(a.Value / b); 123 | 124 | public static JUInt operator % (JUInt a, JUInt b) => new JUInt(a.Value % b.Value); 125 | public static JUInt operator % (JUInt a, uint b) => new JUInt(a.Value % b); 126 | 127 | public override string ToString() => Value.ToString(); 128 | 129 | public override int GetHashCode() => Value.GetHashCode(); 130 | 131 | public override bool Equals(object obj) => Value.Equals((obj is JUInt ? (JUInt) obj : default).Value); 132 | } 133 | } -------------------------------------------------------------------------------- /Runtime/JUInt.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 21ca6c44f6364d398a33d1c42a1c7c23 3 | timeCreated: 1601439899 -------------------------------------------------------------------------------- /Runtime/JULong.cs: -------------------------------------------------------------------------------- 1 | // 2 | // JULong.cs 3 | // 4 | // Author: 5 | // JasonXuDeveloper(傑) 6 | // 7 | // Copyright (c) 2020 JEngine 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining a copy 10 | // of this software and associated documentation files (the "Software"), to deal 11 | // in the Software without restriction, including without limitation the rights 12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | // copies of the Software, and to permit persons to whom the Software is 14 | // furnished to do so, subject to the following conditions: 15 | // 16 | // The above copyright notice and this permission notice shall be included in 17 | // all copies or substantial portions of the Software. 18 | // 19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | // THE SOFTWARE. 26 | 27 | using JEngine.Core; 28 | 29 | namespace JEngine.AntiCheat 30 | { 31 | public struct JULong 32 | { 33 | private ulong _obscuredULong; 34 | private ulong _obscuredKey; 35 | private ulong _originalValue; 36 | 37 | private ulong Value 38 | { 39 | get 40 | { 41 | var result = _obscuredULong-_obscuredKey; 42 | if (!_originalValue.Equals(result)) 43 | { 44 | AntiCheatHelper.OnDetected(); 45 | } 46 | return result; 47 | } 48 | 49 | set 50 | { 51 | _originalValue = value; 52 | unchecked 53 | { 54 | _obscuredKey = (ulong) JRandom.RandomNum(ulong.MaxValue - value); 55 | _obscuredULong = value + _obscuredKey; 56 | } 57 | } 58 | } 59 | 60 | public JULong(ulong val = 0) 61 | { 62 | _obscuredULong = 0; 63 | _obscuredKey = 0; 64 | _originalValue = 0; 65 | Value = val; 66 | } 67 | public JULong(int val = 0) 68 | { 69 | _obscuredULong = 0; 70 | _obscuredKey = 0; 71 | _originalValue = 0; 72 | Value = (ulong) val; 73 | } 74 | 75 | public JULong(string val = "0") 76 | { 77 | _obscuredULong = 0; 78 | _obscuredKey = 0; 79 | _originalValue = 0; 80 | var result = ulong.TryParse(val,out var _value); 81 | if (!result) 82 | { 83 | Log.PrintError($"无法将{val}变为{Value.GetType()},已改为0"); 84 | Value = 0; 85 | } 86 | else 87 | { 88 | Value = _value; 89 | } 90 | } 91 | 92 | public static implicit operator JULong(ulong val) => new JULong(val); 93 | public static implicit operator ulong(JULong val) => val.Value; 94 | public static bool operator ==(JULong a, JULong b) => a.Value == b.Value; 95 | public static bool operator !=(JULong a, JULong b) => a.Value != b.Value; 96 | 97 | public static JULong operator ++(JULong a) 98 | { 99 | a.Value++; 100 | return a; 101 | } 102 | 103 | public static JULong operator --(JULong a) 104 | { 105 | a.Value--; 106 | return a; 107 | } 108 | 109 | public static JULong operator + (JULong a, JULong b) => new JULong(a.Value + b.Value); 110 | public static JULong operator + (JULong a, ulong b) => new JULong(a.Value + b); 111 | 112 | public static JULong operator - (JULong a, JULong b) => new JULong(a.Value - b.Value); 113 | public static JULong operator - (JULong a, ulong b) => new JULong(a.Value - b); 114 | 115 | public static JULong operator * (JULong a, JULong b) => new JULong(a.Value * b.Value); 116 | public static JULong operator * (JULong a, ulong b) => new JULong(a.Value * b); 117 | 118 | public static JULong operator / (JULong a, JULong b) => new JULong(a.Value / b.Value); 119 | public static JULong operator / (JULong a, ulong b) => new JULong(a.Value / b); 120 | 121 | public static JULong operator % (JULong a, JULong b) => new JULong(a.Value % b.Value); 122 | public static JULong operator % (JULong a, ulong b) => new JULong(a.Value % b); 123 | 124 | public override string ToString() => Value.ToString(); 125 | 126 | public override int GetHashCode() => Value.GetHashCode(); 127 | 128 | public override bool Equals(object obj) => Value.Equals((obj is JULong ? (JULong) obj : default).Value); 129 | } 130 | } -------------------------------------------------------------------------------- /Runtime/JULong.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 9325dd97ace84aeda9c7b1c78d5d1977 3 | timeCreated: 1601440288 -------------------------------------------------------------------------------- /Runtime/JUShort.cs: -------------------------------------------------------------------------------- 1 | // 2 | // JUShort.cs 3 | // 4 | // Author: 5 | // JasonXuDeveloper(傑) 6 | // 7 | // Copyright (c) 2020 JEngine 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining a copy 10 | // of this software and associated documentation files (the "Software"), to deal 11 | // in the Software without restriction, including without limitation the rights 12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | // copies of the Software, and to permit persons to whom the Software is 14 | // furnished to do so, subject to the following conditions: 15 | // 16 | // The above copyright notice and this permission notice shall be included in 17 | // all copies or substantial portions of the Software. 18 | // 19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | // THE SOFTWARE. 26 | 27 | using JEngine.Core; 28 | 29 | namespace JEngine.AntiCheat 30 | { 31 | public struct JUShort 32 | { 33 | private ushort _obscuredUShort; 34 | private ushort _obscuredKey; 35 | private ushort _originalValue; 36 | 37 | private ushort Value 38 | { 39 | get 40 | { 41 | var result = (ushort)(_obscuredUShort-_obscuredKey); 42 | if (!_originalValue.Equals(result)) 43 | { 44 | AntiCheatHelper.OnDetected(); 45 | } 46 | 47 | return result; 48 | } 49 | 50 | set 51 | { 52 | _originalValue = value; 53 | unchecked 54 | { 55 | _obscuredKey = (ushort) JRandom.RandomNum(ushort.MaxValue - value); 56 | _obscuredUShort = (ushort) (value + _obscuredKey); 57 | } 58 | } 59 | } 60 | 61 | public JUShort(ushort val = 0) 62 | { 63 | _obscuredUShort = 0; 64 | _obscuredKey = 0; 65 | _originalValue = 0; 66 | Value = val; 67 | } 68 | public JUShort(int val = 0) 69 | { 70 | _obscuredUShort = 0; 71 | _obscuredKey = 0; 72 | _originalValue = 0; 73 | Value = val > ushort.MaxValue ? ushort.MaxValue : (ushort) val; 74 | } 75 | 76 | public JUShort(string val = "0") 77 | { 78 | _obscuredUShort = 0; 79 | _obscuredKey = 0; 80 | _originalValue = 0; 81 | var result = ushort.TryParse(val,out var _value); 82 | if (!result) 83 | { 84 | Log.PrintError($"无法将{val}变为{Value.GetType()},已改为0"); 85 | Value = 0; 86 | } 87 | else 88 | { 89 | Value = _value; 90 | } 91 | } 92 | 93 | public static implicit operator JUShort(ushort val) => new JUShort(val); 94 | public static implicit operator ushort(JUShort val) => val.Value; 95 | public static bool operator ==(JUShort a, JUShort b) => a.Value == b.Value; 96 | public static bool operator !=(JUShort a, JUShort b) => a.Value != b.Value; 97 | 98 | public static JUShort operator ++(JUShort a) 99 | { 100 | a.Value++; 101 | return a; 102 | } 103 | 104 | public static JUShort operator --(JUShort a) 105 | { 106 | a.Value--; 107 | return a; 108 | } 109 | 110 | public static JUShort operator + (JUShort a, JUShort b) => new JUShort(a.Value + b.Value); 111 | public static JUShort operator + (JUShort a, ushort b) => new JUShort(a.Value + b); 112 | 113 | public static JUShort operator - (JUShort a, JUShort b) => new JUShort(a.Value - b.Value); 114 | public static JUShort operator - (JUShort a, ushort b) => new JUShort(a.Value - b); 115 | 116 | public static JUShort operator * (JUShort a, JUShort b) => new JUShort(a.Value * b.Value); 117 | public static JUShort operator * (JUShort a, ushort b) => new JUShort(a.Value * b); 118 | 119 | public static JUShort operator / (JUShort a, JUShort b) => new JUShort(a.Value / b.Value); 120 | public static JUShort operator / (JUShort a, ushort b) => new JUShort(a.Value / b); 121 | 122 | public static JUShort operator % (JUShort a, JUShort b) => new JUShort(a.Value % b.Value); 123 | public static JUShort operator % (JUShort a, ushort b) => new JUShort(a.Value % b); 124 | 125 | public override string ToString() => Value.ToString(); 126 | 127 | public override int GetHashCode() => Value.GetHashCode(); 128 | 129 | public override bool Equals(object obj) => Value.Equals((obj is JUShort ? (JUShort) obj : default).Value); 130 | } 131 | } -------------------------------------------------------------------------------- /Runtime/JUShort.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f2f3098cd0694cfdaffaf3dbc8c1c538 3 | timeCreated: 1601439769 --------------------------------------------------------------------------------