1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
/*
obfuscate integer -- against Cheat Engine Users.
Copyright (C) 2021 Neutron3529
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#[macro_use]
pub mod custom_ops {
/// Custom Initialize and Assign statement with macro `cai!`
/// # Example
/// ```
/// #[macro_use] // if you want to import the macro
/// extern crate obfuscate_integer;
/// use obfuscate_integer::custom_ops::*;
/// fn main(){
/// cai!{
/// let _a=1; // a normal statement
/// let mut a:i32 :=0; // Custom Initialize (let mut a:i32 =CustomInitialize::custom_initialize())
/// a+=1; // stmt
/// println!("{}: cai! works directly in the environment of macro",a);
/// for i in 0i32..1{
/// let j:i32 :=3;
/// println!("{}: cai! also works in for-loop",j-a+i)
/// }
/// a~2; // Custom Assign (bind to `~`)
/// if a==2{
/// let j:i32 :=1;
/// println!("{}: cai! also works in if statement",a+j)
/// }
/// a.custom_assign(6i32); // expr with no ending semicolon
/// if a==1i32{
/// }else{
/// let j:i32 :=2;
/// println!("{}: cai! also works in if statement with `else` clause, empty block, etc.",a-j)
/// }
/// while a!=1{
/// a:=1; // := could be used without let clause.
/// println!("5: cai! also works in while statement.")
/// }
/// loop{
/// println!("{}: cai! also works in loop statement.",a+5);
/// break {
/// let b:i32 := 7 ;
/// println!("{}: cai! also works in loop statement.",b) ;
/// b
/// }
/// }
/// println!("{}: as a special remainder, cai does not works in closure nor blocks in a statement that is not mentioned above.",a+7)
/// }
/// }
/// ```
#[macro_export]
macro_rules! cai {
(@expr_block ($($ex:tt)+) => { $($b1:tt)* } else { $($b2:tt)* } $($tail:tt)*) =>{
$($ex)+ {
cai!($($b1)*);
}else{
cai!($($b2)*);
}
cai!($($tail)*)
};
(@expr_block ($($ex:tt)+) => { $($b1:tt)* } $($tail:tt)*) =>{
$($ex)+ {
cai!($($b1)*);
}
cai!($($tail)*)
};
({ $($b1:tt)* } $($tail:tt)*) =>{
{
cai!($($b1)*);
};
cai!($($tail)*)
};
(@split_exp_block ($($ex:tt)+) => { $($b:tt)* } $($tail:tt)*) => {
cai!(@expr_block ($($ex)+) => {$($b)*} $($tail)*)
};
(@split_exp_block ($($ex:tt)+) => $t:tt $($tail:tt)*) => {
cai!(@split_exp_block ($($ex)+ $t) => $($tail)*)
};
(if $t:tt $($tail:tt)*) => {
cai!(@split_exp_block (if $t) => $($tail)*)
};
(while $t:tt $($tail:tt)*) => {
cai!(@split_exp_block (while $t) => $($tail)*)
};
(break { $($b:tt)* } $($tail:tt)*) => {
break { cai!($($b)*); };
cai!($($tail)*)
};
(loop { $($b:tt)* } $($tail:tt)*) => {
loop { cai!($($b)*); } ;
cai!($($tail)*)
};
(for $t:tt $($tail:tt)*) => {
cai!(@split_exp_block (for $t) => $($tail)*)
};
({ $($b:tt)* } $($tail:tt)*) => {
{ cai!($($b:tt)*) }
cai!($($tail)*)
};
($id:ident ~ $ex:expr; $($tail:tt)*) => {
$id.custom_assign(cai!($ex));
cai!($($tail)*)
};
($($id:ident)+ $(: $type:ty)? : = $ex:expr; $($tail:tt)*) => {
$($id)+ $(: $type)? = CustomInitialize::custom_initialize(cai!($ex));
cai!($($tail)*)
};
($st:stmt; $($tail:tt)*) => {
$st
cai!($($tail)*)
};
($ex:expr) => {
$ex
};
() => {};
}
/// this trait is mainly for the incoming CustomAssign stmt `a~b` implemented by my incoming marco cai!
pub trait CustomAssign<Rhs=Self>{ // bind to a~b
fn custom_assign(&mut self, rhs:Rhs); // a~b means a.custom_assign(b)
}
/// this trait is mainly for the incoming CustomInitialize stmt `let a:Type :=b` implemented by my incoming marco cai!
pub trait CustomInitialize<Rhs=Self>{ // bind to a:=b
fn custom_initialize(rhs:Rhs)->Self; // a:=b means a=<type of a>::custom_initialize(rhs);
}
impl<T> CustomAssign<T> for T{
#[inline(always)]
default fn custom_assign(&mut self, rhs:T){
*self=rhs
}
}
impl<T:Copy> CustomAssign<&T> for T{
#[inline(always)]
default fn custom_assign(&mut self, rhs:&T){
*self=*rhs
}
}
impl<'a,T:CustomAssign<&'a T>> CustomAssign<&'a mut T> for T{
#[inline(always)]
default fn custom_assign(&mut self, rhs:&'a mut T){
self.custom_assign(rhs as &T)
}
}
impl<T> CustomInitialize<T> for T{
#[inline(always)]
default fn custom_initialize(rhs:T)->Self{
rhs
}
}
impl<T:Copy> CustomInitialize<&T> for T{
#[inline(always)]
default fn custom_initialize(rhs:&T)->Self{
*rhs
}
}
impl<'a,T:CustomInitialize<&'a T>> CustomInitialize<&'a mut T> for T{
#[inline(always)]
default fn custom_initialize(rhs:&'a mut T)->Self{
Self::custom_initialize(rhs as &T)
}
}
}
pub mod prelude {
pub use super::{Oi32,Ei32,Ou32,Eu32,custom_ops::*};
}