public static FuncRef funcref(Object instance, string funcname) { var ret = new FuncRef(); ret.set_instance(instance); ret.set_function(funcname); return(ret); }
internal MarshalItemFuncRef(FuncRef func, T1 arg1, T2 arg2, TRef1 arg3, TRef2 arg4) { _func = func; _arg1 = arg1; _arg2 = arg2; _arg3 = arg3; _arg4 = arg4; _retValTask = new Task <TRet>(() => _retVal); }
internal MarshalItemFuncRef([NotNull] FuncRef func, T1 arg1, T2 arg2, TRef1 arg3, TRef2 arg4) { this.func = func; this.arg1 = arg1; this.arg2 = arg2; this.arg3 = arg3; this.arg4 = arg4; this.retValTask = new Task <TRet>(() => this.retVal); }
public override void Read(byte[] data, ushort offset, int length) { var magic = ReadShortBE(data, ref offset); if (magic != 0x1234) { throw new System.Exception("Wrong class magic"); } var varOffset = ReadShortBE(data, ref offset); if (varOffset != 0) { throw new System.Exception("Wrong class var offset"); } funcList = ReadShortBE(data, ref offset); int selectorsCount = ReadShortBE(data, ref offset); Selectors = new BaseElement[selectorsCount]; for (int i = 0; i < selectorsCount; i++) { var addr = offset; var val = ReadShortBE(data, ref offset); Selectors[i] = new ShortElement(_script, addr, val); } if (Type == SectionType.Class) { varselectors = new ushort[selectorsCount]; for (int i = 0; i < selectorsCount; i++) { varselectors[i] = ReadShortBE(data, ref offset); } } int fs = ReadShortBE(data, ref offset); FuncNames = new ushort[fs]; for (int i = 0; i < fs; i++) { FuncNames[i] = ReadShortBE(data, ref offset); } offset += 2; FuncCode = new FuncRef[fs]; for (int i = 0; i < fs; i++) { var addr = offset; FuncCode[i] = new FuncRef(_script, addr, ReadShortBE(data, ref offset)) { Source = this }; } }
public void Collided(PhysicsBody _body) { if (!_hitSomething && _body.HasMethod("BulletHit")) { _callback = GD.FuncRef(_body, "BulletHit"); _callback.CallFunc(BulletDamage, GlobalTransform); } _hitSomething = true; QueueFree(); }
static void InvokeFunc(FuncRef func) { if (func == null) { return; } Console.WriteLine("Enter a number"); int data = int.Parse(Console.ReadLine()); func(data); }
public override bool TryGetFuncRef(ILGeneratorContext context, out FuncRef funcRef, out ASTNode memberOf) { if (context.Module.TryGetConst(Source.Value.ToString(), out var constVal)) { if (constVal is FuncRef constFuncRef) { funcRef = constFuncRef; memberOf = null; return(true); } } funcRef = default; memberOf = null; return(false); }
public FSM(String[] statesInfo, Godot.Object instance) { int size = statesInfo.Length; states = new State[size]; currentState = new State(-1, "test"); function = new FuncRef(); funcUpdate = new FuncRef(); function.SetInstance(instance); funcUpdate.SetInstance(instance); for (int i = 0; i < size; i++) { RegisterState(statesInfo[i], i); } ChangeState(statesInfo[0], true); }
private bool TryGetMemberFunc(TypeInfo lhsType, ILGeneratorContext context, out FuncRef funcRef) { funcRef = default; var nameMangledFunc = NameUtils.MangleMemberFunc(lhsType, RHS.Source.Value.ToString()); if (context.Module.TryGetConst(nameMangledFunc, out var constVal)) { if (constVal is FuncRef constFuncRef) { funcRef = constFuncRef; return(true); } } return(false); }
public void FireBullet() { if (_useRaycast) { _nodeRaycast.LookAt(_currentKinematic.GlobalTransform.origin + new Vector3(0, _playerHeight, 0), new Vector3(0, 1, 0)); _nodeRaycast.ForceRaycastUpdate(); if (_nodeRaycast.IsColliding()) { Godot.Object _body = _nodeRaycast.GetCollider(); if (_body.HasMethod("BulletHit")) { _callback = GD.FuncRef(_body, "BulletHit"); _callback.CallFunc(_TurretDamageRaycast, _nodeRaycast.GetCollisionPoint()); } _ammoInTurret--; } } else { StandardBullet _clone = (StandardBullet)_bulletScene.Instance(); Node _sceneRoot = GetTree().Root.GetChild(0); _sceneRoot.AddChild(_clone); _clone.GlobalTransform = GetNode <Spatial>("Head/Barrel_End").GlobalTransform; _clone.Scale = new Vector3(10, 10, 5); _clone.BulletDamage = _TurretDamageBullet; _clone.BulletSpeed = 5; _clone.Gravity = -0.1f; _ammoInTurret--; } _nodeFlashOne.Visible = true; _nodeFlashTwo.Visible = true; _flashTimer = _flashTime; _fireTimer = _fireTime; if (_ammoInTurret <= 0) { _ammoReloadTimer = _ammoReloadTime; } }
public void RefMethodCallingRefMethodWithLocalReturnLocalCalled() { int SetIntoLocalVariableAndCallOtherRef(ref int localByRef) { var objVal1 = localByRef; var objVal2 = localByRef; Set1AndMinus1(ref localByRef, ref objVal2); return(objVal2); } var objRef = Parameter(typeof(int).MakeByRefType()); var variable1 = Variable(typeof(int)); var variable2 = Variable(typeof(int)); var call = typeof(Issue55_CompileFast_crash_with_ref_parameter).GetTypeInfo().DeclaredMethods.First(m => m.Name == nameof(Set1AndMinus1)); var lambda = Lambda <FuncRef <int, int> >(Block(new[] { variable1, variable2 }, Assign(variable1, objRef), Assign(variable2, objRef), Call(call, objRef, variable2), variable2 ), objRef); void LocalAssert(FuncRef <int, int> invoke) { var exampleA = default(int); Assert.AreEqual(-1, invoke(ref exampleA)); Assert.AreEqual(1, exampleA); } var compiledA = lambda.Compile(); LocalAssert(compiledA); var compiledB = lambda.CompileFast <FuncRef <int, int> >(true); LocalAssert(compiledB); FuncRef <int, int> direct = SetIntoLocalVariableAndCallOtherRef; LocalAssert(direct); }
public void RefDoNothingReturnCostant() { int DoNothing(ref int localByRef) => default(int); var objRef = Parameter(typeof(int).MakeByRefType()); var lambda = Lambda <FuncRef <int, int> >(Constant(default(int)), objRef); var compiledB = lambda.CompileFast <FuncRef <int, int> >(true); var exampleB = default(int); Assert.AreEqual(0, compiledB(ref exampleB)); Assert.AreEqual(0, exampleB); FuncRef <int, int> direct = DoNothing; var exampleC = default(int); Assert.AreEqual(0, direct(ref exampleC)); Assert.AreEqual(0, exampleC); }
public void VariableVariableRefVariableRefParameterReturn() { int SetIntoLocalVariableAndCallOtherRef(ref int localByRef) { var x = localByRef; var z = localByRef; SetVariableOneAndMinusForParameter(ref x, ref localByRef); return(1); } var objRef = Parameter(typeof(int).MakeByRefType()); var variable1 = Variable(typeof(int)); var variable2 = Variable(typeof(int)); var call = typeof(Issue55_CompileFast_crash_with_ref_parameter).GetTypeInfo().DeclaredMethods.First(m => m.Name == nameof(SetVariableOneAndMinusForParameter)); var lambda = Lambda <FuncRef <int, int> >(Block(new ParameterExpression[] { variable1, variable2 }, Assign(variable1, objRef), Assign(variable2, objRef), Call(call, variable1, objRef), Constant(1) ), objRef); void LocalAssert(FuncRef <int, int> invoke) { var exampleA = default(int); Assert.AreEqual(1, invoke(ref exampleA)); Assert.AreEqual(-1, exampleA); } var compiledA = lambda.Compile(); LocalAssert(compiledA); var compiledB = lambda.CompileFast <FuncRef <int, int> >(true); LocalAssert(compiledB); FuncRef <int, int> direct = SetIntoLocalVariableAndCallOtherRef; LocalAssert(direct); }
public void SetMinusOneAndOneForDoubleRefParameterInCall() { int SetIntoLocalVariableAndCallOtherRef(ref int localByRef) { Set1AndMinus1(ref localByRef, ref localByRef); return(-1); } var objRef = Parameter(typeof(int).MakeByRefType()); var call = GetType().GetTypeInfo().GetDeclaredMethod(nameof(SetMinusOneAndOneForDoubleRefParameterInCallCall)); var lambda = Lambda <FuncRef <int, int> >( Block(new ParameterExpression[0], Call(call, objRef, objRef), Constant(-1) ), objRef); var compiledB = lambda.CompileFast <FuncRef <int, int> >(true); compiledB.Method.AssertOpCodes( OpCodes.Ldarg_1, OpCodes.Ldarg_1, OpCodes.Call, OpCodes.Ldc_I4_M1, OpCodes.Ret); LocalAssert(compiledB); FuncRef <int, int> direct = SetIntoLocalVariableAndCallOtherRef; LocalAssert(direct); void LocalAssert(FuncRef <int, int> invoke) { var exampleA = default(int); Assert.AreEqual(-1, invoke(ref exampleA)); Assert.AreEqual(1, exampleA); } }
public override bool TryGetFuncRef(ILGeneratorContext context, out FuncRef funcRef, out ASTNode memberOf) { funcRef = default; memberOf = LHS; var lhsType = LHS.GetLoadType(context); if (TryGetMemberFunc(lhsType, context, out funcRef)) { return(true); } else if (lhsType is ReferenceTypeInfo refType) { return(TryGetMemberFunc(refType.InnerType, context, out funcRef)); } else if (lhsType is PointerTypeInfo pointerType) { return(TryGetMemberFunc(pointerType.InnerType, context, out funcRef)); } return(false); }
public void GenericRefFromConstantReturn() { ushort SetSmallConstant(ref uint localByRef) { localByRef = 3; return(7); } var objRef = Parameter(typeof(uint).MakeByRefType()); var lambda = Lambda <FuncRef <uint, ushort> >(Block(Assign(objRef, Constant((uint)3)), Constant((ushort)7)), objRef); var compiledB = lambda.CompileFast <FuncRef <uint, ushort> >(true); var exampleB = default(uint); Assert.AreEqual(7, compiledB(ref exampleB)); Assert.AreEqual(3, exampleB); FuncRef <uint, ushort> direct = SetSmallConstant; var exampleC = default(uint); Assert.AreEqual(7, direct(ref exampleC)); Assert.AreEqual(3, exampleC); }
/// <summary> /// Use the password as a string in a secure fashion /// </summary> public T UseString <T>(FuncRef <string, T> callback) { var chars = new char[_encoded.Length]; string str; try { for (var i = 0; i < chars.Length; i++) { chars[i] = (char)(_encoded[i] ^ Cipher); } str = new string(chars); return(callback(ref str)); } finally { str = null; for (var i = 0; i < chars.Length; i++) { chars[i] = '\0'; } } }
public void SetMinusOneAndOneForDoubleRefParameterInCall() { int SetIntoLocalVariableAndCallOtherRef(ref int localByRef) { Set1AndMinus1(ref localByRef, ref localByRef); return(-1); } var objRef = Parameter(typeof(int).MakeByRefType()); var call = typeof(Issue55_CompileFast_crash_with_ref_parameter).GetTypeInfo().DeclaredMethods.First(m => m.Name == nameof(SetMinusOneAndOneForDoubleRefParameterInCallCall)); var lambda = Lambda <FuncRef <int, int> >(Block(new ParameterExpression[] { }, Call(call, objRef, objRef), Constant(-1) ), objRef); void LocalAssert(FuncRef <int, int> invoke) { var exampleA = default(int); Assert.AreEqual(-1, invoke(ref exampleA)); Assert.AreEqual(1, exampleA); } var compiledA = lambda.Compile(); LocalAssert(compiledA); var compiledB = lambda.CompileFast <FuncRef <int, int> >(true); LocalAssert(compiledB); FuncRef <int, int> direct = SetIntoLocalVariableAndCallOtherRef; LocalAssert(direct); }
/// <summary> /// Use the password as a string in a secure fashion /// </summary> public T UseBytes <T>(FuncRef <byte[], T> callback) { T result = default(T); unsafe { int length = _encrypted.Length; var insecureBuffer = new byte[length * 2 + 2]; byte[] param = null; var gch = new GCHandle(); RuntimeHelpers.PrepareConstrainedRegions(); try { // Pin the string in memory RuntimeHelpers.PrepareConstrainedRegions(); try { } finally { gch = GCHandle.Alloc(insecureBuffer, GCHandleType.Pinned); } IntPtr passwordPtr = IntPtr.Zero; try { // Get a pointer to an insecure version of the string RuntimeHelpers.PrepareConstrainedRegions(); try { } finally { passwordPtr = Marshal.SecureStringToBSTR(_encrypted); } // Copy the unmanaged insecure version to managed one var pPassword = (char *)passwordPtr; var pInsecurePassword = (byte *)gch.AddrOfPinnedObject(); var byteLength = Encoding.ASCII.GetBytes(pPassword, _encrypted.Length, pInsecurePassword, insecureBuffer.Length); param = new byte[byteLength]; for (int index = 0; index < param.Length; index++) { param[index] = pInsecurePassword[index]; pInsecurePassword[index] = 0; } gch.Free(); // Use the byte array result = callback(ref param); } finally { // Zero out the unmanaged insecure version if (passwordPtr != IntPtr.Zero) { Marshal.ZeroFreeBSTR(passwordPtr); } } } finally { if (param != null) { // Zero the managed array and free the memory for (int index = 0; index < param.Length; index++) { param[index] = 0; } } } } return(result); }
public SmartFunctionEnumerator(FuncRef <T, bool> func) { _func = func; _value = default(T); }
public Shim With <T1, TResult>(FuncRef <T1, TResult> replacement, bool isAuto = false) => WithImpl(replacement, isAuto);
/// <summary> /// Use the password as a string in a secure fashion /// </summary> public T UseString <T>(FuncRef <string, T> callback) { T result = default(T); unsafe { int length = _encrypted.Length; var insecurePassword = new string('\0', length); var gch = new GCHandle(); RuntimeHelpers.PrepareConstrainedRegions(); try { // Pin the string in memory RuntimeHelpers.PrepareConstrainedRegions(); try { } finally { gch = GCHandle.Alloc(insecurePassword, GCHandleType.Pinned); } IntPtr passwordPtr = IntPtr.Zero; try { // Get a pointer to an insecure version of the string RuntimeHelpers.PrepareConstrainedRegions(); try { } finally { passwordPtr = Marshal.SecureStringToBSTR(_encrypted); } // Copy the unmanaged insecure version to managed one var pPassword = (char *)passwordPtr; var pInsecurePassword = (char *)gch.AddrOfPinnedObject(); for (int index = 0; index < length; index++) { pInsecurePassword[index] = pPassword[index]; } // Use the string result = callback(ref insecurePassword); } finally { // Zero out the unmanaged insecure version if (passwordPtr != IntPtr.Zero) { Marshal.ZeroFreeBSTR(passwordPtr); } } } finally { if (gch.IsAllocated) { // Zero the managed insecure string and free the memory var pInsecurePassword = (char *)gch.AddrOfPinnedObject(); for (int index = 0; index < length; index++) { pInsecurePassword[index] = '\0'; } gch.Free(); } } } return(result); }
public Shim With <T1, TResult>(FuncRef <T1, TResult> replacement) => WithImpl(replacement);
public Shim With(FuncRef <T, T1, T2, TResult> funcRef) { return(default(Shim)); }
public SmartFunctionEnumerator(FuncRef <TVal, bool> func, TVal value = default) { _func = func; _value = value; }
public virtual bool TryGetFuncRef(ILGeneratorContext context, out FuncRef funcRef, out ASTNode memberOf) { funcRef = default; memberOf = null; return(false); }
// Called when the node enters the scene tree for the first time. public override void _Ready() { // Constructor: _states.Add("Idle_unarmed", new List <string> { "Knife_equip", "Pistol_equip", "Rifle_equip", "Idle_unarmed" }); _states.Add("Pistol_equip", new List <string> { "Pistol_idle" }); _states.Add("Pistol_fire", new List <string> { "Pistol_idle" }); _states.Add("Pistol_idle", new List <string> { "Pistol_fire", "Pistol_reload", "Pistol_unequip", "Pistol_idle" }); _states.Add("Pistol_reload", new List <string> { "Pistol_idle" }); _states.Add("Pistol_unequip", new List <string> { "Idle_unarmed" }); _states.Add("Rifle_equip", new List <string> { "Rifle_idle" }); _states.Add("Rifle_fire", new List <string> { "Rifle_idle" }); _states.Add("Rifle_idle", new List <string> { "Rifle_fire", "Rifle_reload", "Rifle_unequip", "Rifle_idle" }); _states.Add("Rifle_reload", new List <string> { "Rifle_idle" }); _states.Add("Rifle_unequip", new List <string> { "Idle_unarmed" }); _states.Add("Knife_equip", new List <string> { "Knife_idle" }); _states.Add("Knife_fire", new List <string> { "Knife_idle" }); _states.Add("Knife_idle", new List <string> { "Knife_fire", "Knife_unequip", "Knife_idle" }); _states.Add("Knife_unequip", new List <string> { "Idle_unarmed" }); _animationSpeeds.Add("Idle_unarmed", 1f); _animationSpeeds.Add("Pistol_equip", 2.5f); _animationSpeeds.Add("Pistol_fire", 1.8f); _animationSpeeds.Add("Pistol_idle", 1f); _animationSpeeds.Add("Pistol_reload", 1f); _animationSpeeds.Add("Pistol_unequip", 2.5f); _animationSpeeds.Add("Rifle_equip", 1.5f); _animationSpeeds.Add("Rifle_fire", 6f); _animationSpeeds.Add("Rifle_idle", 1f); _animationSpeeds.Add("Rifle_reload", 1.5f); _animationSpeeds.Add("Rifle_unequip", 1.5f); _animationSpeeds.Add("Knife_equip", 3f); _animationSpeeds.Add("Knife_fire", 1.35f); _animationSpeeds.Add("Knife_idle", 1f); _animationSpeeds.Add("Knife_unequip", 3f); CurrentState = "Idle_unarmed"; CallbackFunction = new FuncRef(); // Methods SetAnimation("Idle_unarmed"); Connect("animation_finished", this, nameof(AnimationEnded)); }
public Shim With <T1, T2, T3, T4, T5, T6, TResult>(FuncRef <T1, T2, T3, T4, T5, T6, TResult> replacement) => WithImpl(replacement);
public DynamoRenderCoreDataStore(FuncRef <bool> onUpdateDataAction) { updateAction = onUpdateDataAction; }