Example #1
0
        internal MethodWrapper(int targetProcessId, string dllPath, bool randomiseDllName, bool methodIsManualMap)
        {
            // Ensure the users operating system is supported

            ValidationHandler.ValidateOperatingSystem();

            // Ensure the arguments passed in are valid

            if (targetProcessId <= 0 || string.IsNullOrWhiteSpace(dllPath))
            {
                throw new ArgumentException("One or more of the arguments provided were invalid");
            }

            if (randomiseDllName)
            {
                // Create a temporary DLL on disk

                var temporaryDllName = WrapperTools.GenerateRandomDllName();

                var temporaryDllPath = WrapperTools.CreateTemporaryDll(temporaryDllName, File.ReadAllBytes(dllPath));

                _propertyWrapper = methodIsManualMap ? new PropertyWrapper(targetProcessId, File.ReadAllBytes(temporaryDllPath)) : new PropertyWrapper(targetProcessId, temporaryDllPath);
            }

            else
            {
                _propertyWrapper = methodIsManualMap ? new PropertyWrapper(targetProcessId, File.ReadAllBytes(dllPath)) : new PropertyWrapper(targetProcessId, dllPath);
            }

            // Ensure the architecture of the DLL is valid

            ValidationHandler.ValidateDllArchitecture(_propertyWrapper);
        }
Example #2
0
        internal MethodWrapper(string targetProcessName, byte[] dllBytes, bool randomiseDllName, bool methodIsManualMap)
        {
            // Ensure the users operating system is supported

            ValidationHandler.ValidateOperatingSystem();

            // Ensure the arguments passed in are valid

            if (string.IsNullOrWhiteSpace(targetProcessName) || dllBytes is null || dllBytes.Length == 0)
            {
                throw new ArgumentException("One or more of the arguments provided were invalid");
            }

            if (methodIsManualMap)
            {
                _propertyWrapper = new PropertyWrapper(targetProcessName, dllBytes);
            }

            else
            {
                // Create a temporary DLL on disk

                var temporaryDllName = randomiseDllName ? WrapperTools.GenerateRandomDllName() : WrapperTools.GenerateDllName(dllBytes);

                var temporaryDllPath = WrapperTools.CreateTemporaryDll(temporaryDllName, dllBytes);

                _propertyWrapper = new PropertyWrapper(targetProcessName, temporaryDllPath);
            }

            // Ensure the architecture of the DLL is valid

            ValidationHandler.ValidateDllArchitecture(_propertyWrapper);
        }
 private bool Create(Type type, out string code, out string funcName)
 {
     EditableProperty[] ps = EditableProperty.GetProperties(type);
     if (ps.Length == 0)
     {
         code     = string.Empty;
         funcName = string.Empty;
         return(false);
     }
     funcName = type.Name + "_PropertyWrap";
     AppendUsing(type);
     _funcBuilder.AppendFormat("\t\tprivate void {0}(){1}\r\n", funcName, "{");
     _funcBuilder.AppendFormat("\t\t\tType t = typeof({0});\r\n", type.Name);
     _funcBuilder.AppendFormat("\t\t\tEditableProperty[] list = new EditableProperty[{0}];\r\n", ps.Length);
     for (int i = 0; i < ps.Length; i++)
     {
         string propertyTypeName = WrapperTools.GetTypeName(ps[i].propertyType, _usingList);
         _funcBuilder.AppendFormat("\t\t\t_info.setter=(a,b)=>{0}(({2})a).{3} = ({4}) b;{1};\r\n", "{", "}",
                                   type.Name, ps[i].propertyName, propertyTypeName);
         _funcBuilder.AppendFormat("\t\t\t_info.getter = a =>(({0}) a).{1};\r\n", type.Name, ps[i].propertyName);
         _funcBuilder.AppendFormat("\t\t\t_info.propertyType = typeof({0});\r\n", propertyTypeName);
         _funcBuilder.AppendFormat("\t\t\t_info.copier=(a,b)=>{0}(({1})b).{2}=(({1})a).{2};{3};\r\n", "{",
                                   type.Name, ps[i].propertyName, "}");
         _funcBuilder.AppendFormat("\t\t\tlist[{0}] = new EditableProperty(\"{1}\",_info);\r\n", i,
                                   ps[i].propertyName);
         _funcBuilder.Append("\t\t\tEditableProperty.AddProperties(t,list);\r\n");
     }
     _funcBuilder.Append("\t\t}\r\n");
     code = _funcBuilder.ToString();
     return(true);
 }
Example #4
0
    //	// resets the last valid right hand event
    //	public void ResetRightHandEvent()
    //	{
    //		lastRightHandEvent = InteractionWrapper.InteractionHandEventType.None;
    //	}

    //----------------------------------- end of public functions --------------------------------------//

    void Awake()
    {
        // ensure the needed dlls are in place
        if (WrapperTools.EnsureKinectWrapperPresence())
        {
            // reload the same level
            WrapperTools.RestartLevel(gameObject, "IM");
        }
    }
Example #5
0
        internal ExtensionWrapper(int targetProcessId, byte[] dllBytes, bool randomiseDllName)
        {
            // Ensure the users operating system is supported

            ValidationHandler.ValidateOperatingSystem();

            // Ensure the arguments passed in are valid

            if (targetProcessId <= 0 || dllBytes is null || dllBytes.Length == 0)
            {
                throw new ArgumentException("One or more of the arguments provided were invalid");
            }

            if (randomiseDllName)
            {
                // Assume the DLL is the newest file in the temporary directory

                var temporaryDirectoryInfo = new DirectoryInfo(Path.Combine(Path.GetTempPath(), "Bleak"));

                var newestTemporaryFile = temporaryDirectoryInfo.GetFiles().OrderByDescending(file => file.LastWriteTime).First();

                _propertyWrapper = new PropertyWrapper(targetProcessId, newestTemporaryFile.FullName);
            }

            else
            {
                // Get the file path of the DLL on disk

                var temporaryDirectory = Path.Combine(Path.GetTempPath(), "Bleak");

                var temporaryDllName = WrapperTools.GenerateDllName(dllBytes);

                var temporaryDllPath = Path.Combine(temporaryDirectory, temporaryDllName);

                _propertyWrapper = new PropertyWrapper(targetProcessId, temporaryDllPath);
            }

            // Ensure the architecture of the DLL is valid

            ValidationHandler.ValidateDllArchitecture(_propertyWrapper);
        }
    //----------------------------------- end of public functions --------------------------------------//

    void Awake()
    {
        // ensure the needed dlls are in place
        if (WrapperTools.EnsureKinectWrapperPresence())
        {
            // reload the same level
            WrapperTools.RestartLevel(gameObject, "SM");
        }

        // copy the grammar file from the resources, if not found
        if ((grammarFileName != "") && !File.Exists(grammarFileName))
        {
            TextAsset textRes = Resources.Load(grammarFileName, typeof(TextAsset)) as TextAsset;

            if (textRes != null)
            {
                string sResText = textRes.text;
                File.WriteAllText(grammarFileName, sResText);
            }
        }
    }
Example #7
0
 private void AppendUsing(Type runtime)
 {
     WrapperTools.AppendUsing(runtime, _usingList);
 }
    void Awake()
    {
        WrapperTools.EnsureKinectWrapperPresence();
        int hr = 0;

        try
        {
            hr = KinectWrapper.NuiInitialize(KinectWrapper.NuiInitializeFlags.UsesSkeleton |
                                             KinectWrapper.NuiInitializeFlags.UsesDepthAndPlayerIndex);
            if (hr != 0)
            {
                throw new Exception("NuiInitialize Failed");
            }

            hr = KinectWrapper.NuiSkeletonTrackingEnable(IntPtr.Zero, 8);              // 0, 12,8
            if (hr != 0)
            {
                throw new Exception("Cannot initialize Skeleton Data");
            }

            depthStreamHandle = IntPtr.Zero;

            // set kinect elevation angle
            KinectWrapper.NuiCameraElevationSetAngle(SensorAngle);

            // init skeleton structures
            skeletonFrame = new KinectWrapper.NuiSkeletonFrame()
            {
                SkeletonData = new KinectWrapper.NuiSkeletonData[KinectWrapper.Constants.NuiSkeletonCount]
            };

            // values used to pass to smoothing function
            smoothParameters = new KinectWrapper.NuiTransformSmoothParameters();

            switch (smoothing)
            {
            case Smoothing.Default:
                smoothParameters.fSmoothing          = 0.5f;
                smoothParameters.fCorrection         = 0.5f;
                smoothParameters.fPrediction         = 0.5f;
                smoothParameters.fJitterRadius       = 0.05f;
                smoothParameters.fMaxDeviationRadius = 0.04f;
                break;

            case Smoothing.Medium:
                smoothParameters.fSmoothing          = 0.5f;
                smoothParameters.fCorrection         = 0.1f;
                smoothParameters.fPrediction         = 0.5f;
                smoothParameters.fJitterRadius       = 0.1f;
                smoothParameters.fMaxDeviationRadius = 0.1f;
                break;

            case Smoothing.Aggressive:
                smoothParameters.fSmoothing          = 0.7f;
                smoothParameters.fCorrection         = 0.3f;
                smoothParameters.fPrediction         = 1.0f;
                smoothParameters.fJitterRadius       = 1.0f;
                smoothParameters.fMaxDeviationRadius = 1.0f;
                break;
            }

            // init the tracking state filter
            trackingStateFilter = new TrackingStateFilter[KinectWrapper.Constants.NuiSkeletonMaxTracked];
            for (int i = 0; i < trackingStateFilter.Length; i++)
            {
                trackingStateFilter[i] = new TrackingStateFilter();
                trackingStateFilter[i].Init();
            }

            // init the bone orientation filter
            boneOrientationFilter = new BoneOrientationsFilter[KinectWrapper.Constants.NuiSkeletonMaxTracked];
            for (int i = 0; i < boneOrientationFilter.Length; i++)
            {
                boneOrientationFilter[i] = new BoneOrientationsFilter();
                boneOrientationFilter[i].Init();
            }

            // init the clipped legs filter
            clippedLegsFilter = new ClippedLegsFilter[KinectWrapper.Constants.NuiSkeletonMaxTracked];
            for (int i = 0; i < clippedLegsFilter.Length; i++)
            {
                clippedLegsFilter[i] = new ClippedLegsFilter();
            }

            // init the bone orientation constraints
            boneConstraintsFilter = new BoneOrientationsConstraint();
            boneConstraintsFilter.AddDefaultConstraints();
            // init the self intersection constraints
            selfIntersectionConstraint = new SelfIntersectionConstraint();

            // create arrays for joint positions and joint orientations
            int skeletonJointsCount = (int)KinectWrapper.NuiSkeletonPositionIndex.Count;

            player1JointsTracked = new bool[skeletonJointsCount];
            player1PrevTracked   = new bool[skeletonJointsCount];

            player1JointsPos = new Vector3[skeletonJointsCount];

            player1JointsOri = new Matrix4x4[skeletonJointsCount];

            gestureTrackingAtTime = new float[KinectWrapper.Constants.NuiSkeletonMaxTracked];

            //create the transform matrix that converts from kinect-space to world-space
            Quaternion quatTiltAngle = new Quaternion();
            quatTiltAngle.eulerAngles = new Vector3(-SensorAngle, 0.0f, 0.0f);

            //float heightAboveHips = SensorHeight - 1.0f;

            // transform matrix - kinect to world
            kinectToWorld.SetTRS(new Vector3(0.0f, SensorHeight, 0.0f), quatTiltAngle, Vector3.one);
            flipMatrix       = Matrix4x4.identity;
            flipMatrix[2, 2] = -1;
        }
        catch (DllNotFoundException e)
        {
            string message = "Please check the Kinect SDK installation.";
            Debug.LogError(message);
            Debug.LogError(e.ToString());

            return;
        }
        catch (Exception e)
        {
            string message = e.Message + " - " + KinectWrapper.GetNuiErrorString(hr);
            Debug.LogError(message);
            Debug.LogError(e.ToString());

            return;
        }

        // Initialize user list to contain ALL users.
        allUsers = new List <uint>();

        KinectInitialized = true;
    }