亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? scripting.cpp

?? VC中使用C#作為腳本引擎編程
?? CPP
字號:
//--------------------------------------------------------------------------------------
// File: Scripting.cpp
//
// Scripting code for Managed Scripting sample
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//--------------------------------------------------------------------------------------
#include "dxstdafx.h"

#pragma managed

// Undef this
#ifdef GetTempFileName
#undef GetTempFileName
#endif

// User defined types
#define SCRIPT_TYPE_NAME S"ScriptClass"
#define SCRIPT_UPDATE_POSITION S"UpdatePosition"
#define SCRIPT_UPDATE_ANGLEX S"UpdateRotationX"
#define SCRIPT_UPDATE_ANGLEY S"UpdateRotationY"
#define SCRIPT_UPDATE_ANGLEZ S"UpdateRotationZ"

// We will need to have the CLR loaded
#using <mscorlib.dll>
#using <system.dll>

// These are the namespaces required
using namespace System;
using namespace System::IO;
using namespace System::Reflection;
using namespace System::CodeDom;
using namespace System::CodeDom::Compiler;
// Security namespaces
using namespace System::Security;
using namespace System::Security::Policy;
using namespace System::Security::Permissions;
// For code compiler
using namespace Microsoft::CSharp;

__sealed public __gc class ScriptEngine
{
private:
    static Assembly* pScriptAssembly = NULL; // The assembly that hold the scripts
    static Type* pScriptType = NULL; // The class that holds the scripts
    static String* pSavedFile = NULL; // The assembly saved location

    static bool canUpdatePosition = true;
    static bool canUpdateRotationX = true;
    static bool canUpdateRotationY = true;
    static bool canUpdateRotationZ = true;
    static bool hasNotifiedSecurityException = false;

    // Reset script options
    static void ResetObjects()
    {
        pScriptAssembly = NULL;
        pScriptType = NULL;
        canUpdatePosition = true;
        canUpdateRotationX = true;
        canUpdateRotationY = true;
        canUpdateRotationZ = true;
        hasNotifiedSecurityException = false;

        // Delete the saved file if possible
        if ( (pSavedFile != NULL) && (pSavedFile->Length > 0) )
        {
            try
            {
                File::Delete(pSavedFile);
            }
            catch(Exception*)
            {
                // Ignore
            }
            pSavedFile = NULL;
        }
    }

public:
    // Initialize the Scripting engine's app domain
    static HRESULT Initialize()
    {
        try
        {
            // Create the security policy level for this application domain
            PolicyLevel* pSecurityLevel = PolicyLevel::CreateAppDomainLevel();

            // Create a new, empty permission set so we don't mistakenly grant some permission we don't want
            PermissionSet* pPermissions = new PermissionSet(PermissionState::None);

            // Set the permissions that you will allow, in this case we only want to allow execution of code
            pPermissions->AddPermission(new SecurityPermission(SecurityPermissionFlag::Execution));
                                                                           
            // Make sure we have the permissions currently
            pPermissions->Demand();

            // Give the policy level's root code group a new policy statement based
            // on the new permission set.
            pSecurityLevel->RootCodeGroup->PolicyStatement = new PolicyStatement(pPermissions);

            // Update the application domain's policy now
            AppDomain::CurrentDomain->SetAppDomainPolicy(pSecurityLevel);
        }
        catch(Exception*)
        {
            return E_FAIL;
        }

        return S_OK;
    }

    static HRESULT LoadScriptData(System::String* pScriptName)
    {
        // Make sure to reset the objects first
        ResetObjects();

        // Make sure a valid name was passed in
        if (pScriptName == NULL || pScriptName->Length == 0)
            return E_INVALIDARG;
        // First try to open the script file
        StreamReader* pReader = NULL;
        try
        {
            pReader = new StreamReader(pScriptName);

            // Now try to read the text
            System::String* pScriptText = pReader->ReadToEnd();
            
            // Make sure something was read
            if (pScriptText == NULL || pScriptText->Length == 0)
                return E_INVALIDARG;

            // First create the compilers
            CSharpCodeProvider* pProvider = new CSharpCodeProvider();
#ifndef VS2005 // VS2005 this method is deprecated
            ICodeCompiler* pCompiler = pProvider->CreateCompiler();
#endif
            CompilerParameters* pParams = new CompilerParameters();

            // Now try to compile this script, first make sure we compile an assembly, not exe
            pParams->GenerateExecutable = false;

            // Make sure the assembly is generated in the temp files, first get a temp file name
            pSavedFile = System::String::Concat(Path::GetTempFileName(), S".dll");
            // Next mark it as not being generated in memory
            pParams->GenerateInMemory = false;
            // Finally, update the output file
            pParams->OutputAssembly = pSavedFile;
            #if defined(DEBUG) | defined(_DEBUG)
            // If you want to include debug information, do so
            pParams->IncludeDebugInformation = true;
            #endif

            // Finally compile the code
#ifndef VS2005 // VS2005 this method is deprecated
            CompilerResults* pResult = pCompiler->CompileAssemblyFromSource(pParams, pScriptText);
#else
            CompilerResults* pResult = pProvider->CompileAssemblyFromSource(pParams, new System::String* __gc[] { pScriptText } );
#endif            
            if (pResult->Errors->Count > 0)
            {
                // Some errors occurred
                return E_FAIL;
            }
            else
            {
                // The compilation was a success, load the assembly 
                pScriptAssembly = System::Reflection::Assembly::LoadFrom(pResult->PathToAssembly);
                // Try to load the type
                pScriptType = pScriptAssembly->GetType(SCRIPT_TYPE_NAME, false, true);
                if (pScriptType == NULL)
                {
                    // Couldn't find the type, fail
                    pScriptAssembly = NULL;
                    pScriptType = NULL;
                    return E_FAIL;
                }
                
                // Finished
                return S_OK;
            }
        }
        catch (Exception* e)
        {
            System::Diagnostics::Debugger::Log(0, NULL, e->ToString());
            // Reset objects
            ResetObjects();
            // Reading the script file failed, return failure
            return E_FAIL;
        }
        __finally
        {
            // Make sure to close the file down no matter what
            if (pReader != NULL)
            {
                IDisposable* pDisposeObject = dynamic_cast<IDisposable*>(pReader);
                if (pDisposeObject != NULL)
                    pDisposeObject->Dispose();
            }
        }

    }
    static HRESULT UpdatePlayerPosition(double appTime, float __nogc* pX, float __nogc* pY, float __nogc* pZ)
    {
        // Check params
        if (pX == NULL || pY == NULL || pZ == NULL)
            return E_INVALIDARG;

        // Check options
        if (pScriptAssembly == NULL || pScriptType == NULL)
            return E_FAIL;

        // Can the position be updated?
        if (!canUpdatePosition)
            return E_FAIL;

        // Now try to call the method
        try
        {
            // Create the parameters
            System::Object* pParams __gc[] = { __box(appTime), __box(*pX), __box(*pY), __box(*pZ) };
            pScriptType->InvokeMember(SCRIPT_UPDATE_POSITION, (BindingFlags)(BindingFlags::InvokeMethod | BindingFlags::DeclaredOnly |
                BindingFlags::Public | BindingFlags::NonPublic | BindingFlags::Static), NULL, NULL, pParams);

            // The method succeeded, update the data
            *pX = *static_cast<__box float*>(pParams[1]);
            *pY = *static_cast<__box float*>(pParams[2]);
            *pZ = *static_cast<__box float*>(pParams[3]);
        }
        catch(TargetInvocationException* e)
        {
            if ( (dynamic_cast<SecurityException*>(e->InnerException) != NULL) 
                || (dynamic_cast<PolicyException*>(e->InnerException) != NULL) )
            {
                // Special case the security exceptions
                if (!hasNotifiedSecurityException)
                {
                    bool bWindowed = DXUTIsWindowed();
                    if( !bWindowed )
                        DXUTToggleFullScreen();

                    MessageBox(NULL, L"This script has attempted to do something the security system will not allow.  Please verify this script is safe to run.", 
                        L"Security Exception", MB_OK);
                    hasNotifiedSecurityException = true;

                    if( !bWindowed )
                        DXUTToggleFullScreen();
                }
            }
            canUpdatePosition = false;
            // Invoke failed
            return E_FAIL;
        }

        return S_OK;
    }
    static HRESULT UpdatePlayerRotation(System::String* pMethodName, double appTime, float __nogc* pAngle)
    {
        // Check params
        if (pAngle == NULL)
            return E_INVALIDARG;

        // Make sure a valid name was passed in
        if (pMethodName == NULL || pMethodName->Length == 0)
            return E_INVALIDARG;

        // Check options
        if (pScriptAssembly == NULL || pScriptType == NULL)
            return E_FAIL;

        // Can we call?
        if (pMethodName->Equals(SCRIPT_UPDATE_ANGLEX))
            if (!canUpdateRotationX)
                return E_FAIL;
        if (pMethodName->Equals(SCRIPT_UPDATE_ANGLEY))
            if (!canUpdateRotationY)
                return E_FAIL;
        if (pMethodName->Equals(SCRIPT_UPDATE_ANGLEZ))
            if (!canUpdateRotationZ)
                return E_FAIL;

        // Now try to call the method
        try
        {
            // Create the parameters
            System::Object* pParams __gc[] = { __box(appTime), __box(*pAngle) };
            pScriptType->InvokeMember(pMethodName, (BindingFlags)(BindingFlags::InvokeMethod | BindingFlags::DeclaredOnly |
                BindingFlags::Public | BindingFlags::NonPublic | BindingFlags::Static), NULL, NULL, pParams);

            // The method succeeded, update the data
            *pAngle = *static_cast<__box float*>(pParams[1]);
        }
        catch(Exception*)
        {
            if (pMethodName->Equals(SCRIPT_UPDATE_ANGLEX))
                canUpdateRotationX = false;
            if (pMethodName->Equals(SCRIPT_UPDATE_ANGLEY))
                canUpdateRotationY = false;
            if (pMethodName->Equals(SCRIPT_UPDATE_ANGLEZ))
                canUpdateRotationZ = false;
            // Invoke failed
            return E_FAIL;
        }

        return S_OK;
    }
};

// Initializes the Scripting engine
HRESULT InitializeScriptEngine()
{
    return ScriptEngine::Initialize();
}

// Call in to load a script
HRESULT LoadScript(LPWSTR pScriptFileName)
{
    return ScriptEngine::LoadScriptData(pScriptFileName);
}

// Call in to the update player position script
HRESULT UpdatePlayerPosition(double appTime, float __nogc* pX, float __nogc* pY, float __nogc* pZ)
{
    return ScriptEngine::UpdatePlayerPosition(appTime, pX, pY, pZ);
}

// Call in to the update player rotation script
HRESULT UpdatePlayerRotationX(double appTime, D3DXMATRIX __nogc* pMatrix)
{
    // Calculate the new rotation angle
    float angle;
    if ( SUCCEEDED(ScriptEngine::UpdatePlayerRotation(SCRIPT_UPDATE_ANGLEX, appTime, &angle)) )
    {
        D3DXMATRIX mRotation;
        // Rotate the X
        D3DXMatrixRotationX(&mRotation, angle);
        D3DXMatrixMultiply(pMatrix, pMatrix, &mRotation );
    }
    else
        return E_FAIL;

    return S_OK;
}

HRESULT UpdatePlayerRotationY(double appTime, D3DXMATRIX __nogc* pMatrix)
{
    // Calculate the new rotation angle
    float angle;
    if ( SUCCEEDED(ScriptEngine::UpdatePlayerRotation(SCRIPT_UPDATE_ANGLEY, appTime, &angle)) )
    {
        D3DXMATRIX mRotation;
        // Rotate the Y
        D3DXMatrixRotationY(&mRotation, angle);
        D3DXMatrixMultiply(pMatrix, pMatrix, &mRotation );
    }
    else
        return E_FAIL;

    return S_OK;
}

HRESULT UpdatePlayerRotationZ(double appTime, D3DXMATRIX __nogc* pMatrix)
{
    // Calculate the new rotation angle
    float angle;
    if ( SUCCEEDED(ScriptEngine::UpdatePlayerRotation(SCRIPT_UPDATE_ANGLEZ, appTime, &angle)) )
    {
        D3DXMATRIX mRotation;
        // Rotate the Z
        D3DXMatrixRotationZ(&mRotation, angle);
        D3DXMatrixMultiply(pMatrix, pMatrix, &mRotation );
    }
    else
        return E_FAIL;

    return S_OK;
}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
亚洲大片一区二区三区| 成人免费视频网站在线观看| 国精产品一区一区三区mba视频| 国产成人综合亚洲网站| 欧美亚洲自拍偷拍| 欧美精品一区二区在线观看| 一区二区三区四区不卡在线| 国模套图日韩精品一区二区 | 欧美日韩高清一区二区三区| 国产精品污网站| 久久精品72免费观看| 欧美日韩精品综合在线| 最新国产成人在线观看| 韩日精品视频一区| 欧美一区二区视频观看视频| 亚洲主播在线观看| 91蜜桃免费观看视频| 欧美激情一区不卡| 丁香啪啪综合成人亚洲小说| 久久无码av三级| 久久99精品国产.久久久久久| 欧美日韩一区二区欧美激情 | 亚洲午夜久久久| 91首页免费视频| 国产精品家庭影院| 成人一区二区三区视频在线观看 | 欧美一区二区三区四区五区| 亚洲制服丝袜av| 色偷偷久久人人79超碰人人澡| 国产精品女同互慰在线看| 国产大陆精品国产| 国产精品狼人久久影院观看方式| 成人做爰69片免费看网站| 国产欧美一区二区精品性色 | 色婷婷av一区二区| 亚洲人亚洲人成电影网站色| 91网址在线看| 亚洲人成网站影音先锋播放| 欧洲视频一区二区| 亚洲va欧美va人人爽午夜| 欧美三级在线播放| 免费看黄色91| 久久天天做天天爱综合色| 国产成人亚洲综合色影视| 国产精品美女久久久久久久久| 成人影视亚洲图片在线| 最新国产精品久久精品| 欧美日韩在线播放三区| 日本不卡高清视频| 国产亚洲一二三区| 色狠狠av一区二区三区| 日本成人中文字幕| 国产色爱av资源综合区| 91日韩一区二区三区| 五月综合激情网| 久久综合久久99| 97se狠狠狠综合亚洲狠狠| 午夜精品成人在线视频| 精品国产91九色蝌蚪| 91啪亚洲精品| 久久99精品国产| 一区二区三区欧美久久| 日韩精品中文字幕一区二区三区| 成人sese在线| 亚洲chinese男男1069| 国产欧美日韩视频一区二区| 色国产综合视频| 激情综合亚洲精品| 一卡二卡欧美日韩| 国产丝袜美腿一区二区三区| 欧美影视一区二区三区| 国产精品一二一区| 午夜精品一区在线观看| 国产欧美精品区一区二区三区 | 国产欧美一区二区精品忘忧草| 欧美亚洲国产一区二区三区| 精品在线免费视频| 亚洲欧美激情小说另类| 精品免费国产二区三区| 91九色最新地址| 国产91富婆露脸刺激对白| 丝袜亚洲另类欧美综合| 中文字幕亚洲不卡| 久久综合av免费| 欧美日韩国产小视频| 91小视频在线免费看| 国产成人亚洲综合a∨婷婷| 天天综合网天天综合色| 亚洲天堂免费看| 国产日本亚洲高清| 26uuu精品一区二区| 欧美日韩www| 91成人网在线| 91麻豆精东视频| 成人精品小蝌蚪| 国产成人一区在线| 精品综合久久久久久8888| 日韩在线一二三区| 亚洲第一会所有码转帖| 亚洲欧美一区二区三区孕妇| 国产精品美女一区二区在线观看| 精品国产网站在线观看| 欧美一区二区三区啪啪| 欧美在线999| 91国偷自产一区二区三区成为亚洲经典 | 国产日韩欧美在线一区| 日韩午夜激情电影| 3atv一区二区三区| 欧美系列一区二区| 欧美日韩午夜在线视频| 欧美在线影院一区二区| 色呦呦网站一区| 在线视频一区二区三| 一本久久精品一区二区| 99re成人在线| 91黄色小视频| 欧美女孩性生活视频| 欧美日韩国产a| 日韩一级欧美一级| 日韩欧美高清一区| 久久久精品人体av艺术| 中文字幕成人av| 中文字幕日韩一区二区| 亚洲老司机在线| 亚洲综合视频在线观看| 三级一区在线视频先锋| 蜜臀91精品一区二区三区| 久草热8精品视频在线观看| 久久精品99久久久| 国产福利精品一区二区| 91在线云播放| 欧美美女黄视频| 亚洲精品一线二线三线无人区| 久久伊人蜜桃av一区二区| 欧美韩国日本综合| 亚洲免费在线观看| 图片区小说区国产精品视频| 久久成人免费网| 成人一级视频在线观看| 在线观看亚洲精品| 欧美一区二区性放荡片| 久久久久久久久久久电影| 国产精品动漫网站| 日韩国产欧美三级| 国产成人免费在线视频| 欧美亚洲国产怡红院影院| 日韩欧美一级二级三级| 国产精品久久久一区麻豆最新章节| 亚洲黄色录像片| 久久国产剧场电影| 色猫猫国产区一区二在线视频| 欧美一区二区视频网站| 中文字幕一区二区三区色视频| 亚洲国产va精品久久久不卡综合| 国产一区二区三区在线观看免费视频| 99亚偷拍自图区亚洲| 日韩欧美国产系列| 亚洲视频中文字幕| 国模套图日韩精品一区二区| 91国偷自产一区二区三区观看 | 欧美精品乱码久久久久久| 久久理论电影网| 午夜精品久久久久久久| 97超碰欧美中文字幕| 久久新电视剧免费观看| 午夜日韩在线电影| 91最新地址在线播放| 久久久久久毛片| 日韩av一区二区三区四区| 91视频精品在这里| 欧美国产日韩a欧美在线观看| 视频在线在亚洲| 在线欧美日韩国产| 中文字幕亚洲不卡| 国产一区福利在线| 欧美一级高清大全免费观看| 亚洲天堂av一区| 成人深夜在线观看| 久久综合给合久久狠狠狠97色69| 婷婷久久综合九色综合绿巨人| 一本色道久久综合亚洲aⅴ蜜桃| 久久久久久久性| 极品销魂美女一区二区三区| 91精品国产一区二区三区| 亚洲国产精品久久艾草纯爱| 91网站最新地址| 国产精品美女久久久久aⅴ国产馆 国产精品美女久久久久av爽李琼 国产精品美女久久久久高潮 | 不卡在线观看av| 久久久久久久久久久久久夜| 久久91精品久久久久久秒播| 91精品国产免费| 青青国产91久久久久久| 制服丝袜在线91| 天使萌一区二区三区免费观看| 欧洲国内综合视频| 亚洲精品福利视频网站| 91久久精品日日躁夜夜躁欧美| 亚洲精品一二三区| 91久久精品一区二区三| 亚洲动漫第一页|