Beispiel #1
0
int CommandData::IsProcessFile(FileHeader &FileHead,bool *ExactMatch,int MatchType,
                               wchar *MatchedArg,uint MatchedArgSize)
{
  if (MatchedArg!=NULL && MatchedArgSize>0)
    *MatchedArg=0;
//  if (wcslen(FileHead.FileName)>=NM)
//    return 0;
  bool Dir=FileHead.Dir;
  if (ExclCheck(FileHead.FileName,Dir,false,true))
    return 0;
#ifndef SFX_MODULE
  if (TimeCheck(FileHead.mtime))
    return 0;
  if ((FileHead.FileAttr & ExclFileAttr)!=0 || InclAttrSet && (FileHead.FileAttr & InclFileAttr)==0)
    return 0;
  if (!Dir && SizeCheck(FileHead.UnpSize))
    return 0;
#endif
  wchar *ArgName;
  FileArgs.Rewind();
  for (int StringCount=1;(ArgName=FileArgs.GetString())!=NULL;StringCount++)
    if (CmpName(ArgName,FileHead.FileName,MatchType))
    {
      if (ExactMatch!=NULL)
        *ExactMatch=wcsicompc(ArgName,FileHead.FileName)==0;
      if (MatchedArg!=NULL)
        wcsncpyz(MatchedArg,ArgName,MatchedArgSize);
      return StringCount;
    }
  return 0;
}
Beispiel #2
0
int CommandData::IsProcessFile(FileHeader &NewLhd,bool *ExactMatch,int MatchType)
{
  if (strlen(NewLhd.FileName)>=NM || wcslen(NewLhd.FileNameW)>=NM)
    return(0);
  bool Dir=(NewLhd.Flags & LHD_WINDOWMASK)==LHD_DIRECTORY;
  if (ExclCheck(NewLhd.FileName,Dir,false,true))
    return(0);
#ifndef SFX_MODULE
  if (TimeCheck(NewLhd.mtime))
    return(0);
  if ((NewLhd.FileAttr & ExclFileAttr)!=0 || InclAttrSet && (NewLhd.FileAttr & InclFileAttr)==0)
    return(0);
  if (!Dir && SizeCheck(NewLhd.FullUnpSize))
    return(0);
#endif
  char *ArgName;
  wchar *ArgNameW;
  FileArgs->Rewind();
  for (int StringCount=1;FileArgs->GetString(&ArgName,&ArgNameW);StringCount++)
  {
#ifndef SFX_MODULE
    bool Unicode=(NewLhd.Flags & LHD_UNICODE) || ArgNameW!=NULL && *ArgNameW!=0;
    if (Unicode)
    {
      wchar NameW[NM],ArgW[NM],*NamePtr=NewLhd.FileNameW;
      bool CorrectUnicode=true;
      if (ArgNameW==NULL || *ArgNameW==0)
      {
        if (!CharToWide(ArgName,ArgW) || *ArgW==0)
          CorrectUnicode=false;
        ArgNameW=ArgW;
      }
      if ((NewLhd.Flags & LHD_UNICODE)==0)
      {
        if (!CharToWide(NewLhd.FileName,NameW) || *NameW==0)
          CorrectUnicode=false;
        NamePtr=NameW;
      }
      if (CmpName(ArgNameW,NamePtr,MatchType))
      {
        if (ExactMatch!=NULL)
          *ExactMatch=wcsicompc(ArgNameW,NamePtr)==0;
        return(StringCount);
      }
      if (CorrectUnicode)
        continue;
    }
#endif
    if (CmpName(ArgName,NewLhd.FileName,MatchType))
    {
      if (ExactMatch!=NULL)
        *ExactMatch=stricompc(ArgName,NewLhd.FileName)==0;
      return(StringCount);
    }
  }
  return(0);
}
Beispiel #3
0
void Mesh::Construct(ID3D11Device* d3dDevice)
{
    if (pos.size() == 0)
    {
        return;
    }

    // validate sizes are the same
    if (!SizeCheck(nor.size(), pos.size(), "nor", "pos") || !SizeCheck(tex.size(), pos.size(), "tex", "pos"))
    {
        return;
    }

    // if tangents exist, then validate they are the same size as pos
    if (!SizeCheck(tan.size(), pos.size(), "tan", "pos"))
    {
        return;
    }

    SAFE_DELETE(vertexBuffer);
    SAFE_DELETE(indexBuffer);

    // create index buffer
    if(indices.size() > 0)
    {
        indexBuffer = GpuResourceFactory::CreateIndexBuffer(&indices[0], (uint32_t)indices.size() );
        indexBuffer->SetDebugName(name.c_str());
    }

    if(tan.size() > 0)
    {
        std::vector<VertexPNTT> verts;
        verts.reserve(pos.size());
        for(unsigned int i = 0; i < pos.size(); ++i)
        {
            VertexPNTT vert;
            vert.Position = pos[i];
            vert.Normal = nor[i];
            vert.Tangent = tan[i];
            vert.Tex = tex[i];
            verts.push_back(vert);
        }
        vertexBuffer = GpuResourceFactory::CreateVertexBuffer(&verts[0], VertexFormat::VF_PNTT, (uint32_t)verts.size());
    }
    else if (tex.size() > 0)
    {
        std::vector<VertexPNT> verts;
        verts.reserve(pos.size());
        for(unsigned int i = 0; i < pos.size(); ++i)
        {
            VertexPNT vert;
            vert.Position = pos[i];
            vert.Normal = nor[i];
            vert.Tex = tex[i];
            verts.push_back(vert);
        }
        vertexBuffer = GpuResourceFactory::CreateVertexBuffer(&verts[0],VertexFormat::VF_PNT, (uint32_t)verts.size());
    }
    else if (nor.size() > 0)
    {
        std::vector<VertexPN> verts;
        verts.reserve(pos.size());
        for(unsigned int i = 0; i < pos.size(); ++i)
        {
            VertexPN vert;
            vert.Position = pos[i];
            vert.Normal = nor[i];
            verts.push_back(vert);
        }
        vertexBuffer = GpuResourceFactory::CreateVertexBuffer(&verts[0],VertexFormat::VF_PN, (uint32_t)verts.size());
    }
    else
    {
        vertexBuffer = GpuResourceFactory::CreateVertexBuffer(&pos[0],VertexFormat::VF_P, (uint32_t)pos.size());        
    }

    FreeVectorMemory(tex);
    FreeVectorMemory(tan);    
}
int main(int argc, char** argv)
{
    Aes    aes;
    byte*  key;       /* user entered key */
    FILE*  inFile;
    FILE*  outFile = NULL;

    const char* in;
    const char* out;

    int    option;    /* choice of how to run program */
    int    ret = 0;   /* return value */
    int    size = 0;
    int    inCheck = 0;
    int    outCheck = 0;
    char   choice = 'n';

    while ((option = getopt(argc, argv, "d:e:i:o:h")) != -1) {
        switch (option) {
            case 'd': /* if entered decrypt */
                size = atoi(optarg);
                ret = SizeCheck(size);
                choice = 'd';
                break;
            case 'e': /* if entered encrypt */
                size = atoi(optarg);
                ret = SizeCheck(size);
                choice = 'e';
                break;
            case 'h': /* if entered 'help' */
                help();
                break;
            case 'i': /* input file */
                in = optarg;
                inCheck = 1;
                inFile = fopen(in, "r");
                break;
            case 'o': /* output file */
                out = optarg;
                outCheck = 1;
                outFile = fopen(out, "w");
                break;
            case '?':
                if (optopt) {
                    printf("Ending Session\n");
                    return -111;
                }
            default:
                abort();
        }
    }
    if (inCheck == 0 || outCheck == 0) {
            printf("Must have both input and output file");
            printf(": -i filename -o filename\n");
    }
    else if (ret == 0 && choice != 'n') {
        key = malloc(size);    /* sets size memory of key */
        ret = NoEcho((char*)key, size);
        if (choice == 'e')
            AesEncrypt(&aes, key, size, inFile, outFile);
        else if (choice == 'd')
            AesDecrypt(&aes, key, size, inFile, outFile);
    }
    else if (choice == 'n') {
        printf("Must select either -e or -d for encryption and decryption\n");
        ret = -110;
    }

    return ret;
}
Beispiel #5
0
void Mesh::ComputeTangents()
{
    int triangleCount = (int)indices.size();
    int vertexCount = (int)pos.size();
    if (triangleCount == 0 || vertexCount == 0 || nor.size() == 0)
    {
        return;
    }

    if (!SizeCheck(tex.size(), vertexCount, "tex", "pos") || !SizeCheck(nor.size(), vertexCount, "nor", "pos"))
    {
        return;
    }

    std::vector<float3> tan1;
    tan1.resize(vertexCount);
    tan.clear();
    tan.resize(vertexCount);

    for (long a = 0; a + 2 < triangleCount; a += 3)
    {
        long i1 = indices[a + 0];
        long i2 = indices[a + 1];
        long i3 = indices[a + 2];

        if (!BoundsCheck(i1, vertexCount) || !BoundsCheck(i2, vertexCount) || !BoundsCheck(i3, vertexCount))
        {
            return;
        }

        float3 v1 = pos[i1];
        float3 v2 = pos[i2];
        float3 v3 = pos[i3];

        float2 w1 = tex[i1];
        float2 w2 = tex[i2];
        float2 w3 = tex[i3];

        // position differences
        float x1 = v2.x - v1.x;
        float x2 = v3.x - v1.x;
        float y1 = v2.y - v1.y;
        float y2 = v3.y - v1.y;
        float z1 = v2.z - v1.z;
        float z2 = v3.z - v1.z;

        // texcoord differences
        float s1 = w2.x - w1.x;
        float s2 = w3.x - w1.x;
        float t1 = w2.y - w1.y;
        float t2 = w3.y - w1.y;

        // ratio
        float r = 1.0f / (s1 * t2 - s2 * t1);

        // vector in the s direction ( tangent )
        float3 sdir = float3((t2 * x1 - t1 * x2) * r, (t2 * y1 - t1 * y2) * r, (t2 * z1 - t1 * z2) * r);

        //accumulate tangents for each triangle
        tan1[i1] += sdir;
        tan1[i2] += sdir;
        tan1[i3] += sdir;
    }

    // loop through and ortho normalize the tangents
    for (long a = 0; a < vertexCount; ++a)
    {
        float3 n = nor[a];
        float3 t = tan1[a];
        OrthoNormalize(&n,&t);
        tan[a].x = t.x;
        tan[a].y = t.y;
        tan[a].z = t.z;
    }
}