Пример #1
0
void            SaveWadincludeFile(const char* const filename)
{
    char*           fname;
    FILE*           file;
    int             x;
    unsigned        len = strlen(filename) + 5;

    fname = (char*)Alloc(len);
    safe_snprintf(fname, len, "%s.wic", filename);

    _unlink(fname);

    file = SafeOpenWrite(fname);

    WadInclude_i it;
    for (it = g_WadInclude.begin(); it != g_WadInclude.end(); it++)
    {
        x = it->size();
        if (x)
        {
            SafeWrite(file, it->c_str(), x);
            SafeWrite(file, ";", 1);
        }
    }

    Free(fname);
    fclose(file);
}
Пример #2
0
void            HandleWadinclude()
{
    // Code somewhat copied from TEX_InitFromWad()

    char            szTmpPath[MAXTOKEN];
    char            szNewWad[MAXTOKEN];
    char*           pszWadFile;
    bool            bExcludeThisWad;

    const char*     path = ValueForKey(&g_entities[0], "wad");
    
    szNewWad[0] = 0;
    safe_strncpy(szTmpPath, path, MAXTOKEN);

    // temporary kludge so we don't have to deal with no occurances of a semicolon
    //  in the path name ..
    if (strchr(szTmpPath, ';') == NULL)
    {
        safe_strncat(szTmpPath, ";", MAXTOKEN);
    }

    pszWadFile = strtok(szTmpPath, ";");

    while (pszWadFile)
    {
        bExcludeThisWad = false;

        // look and see if we're supposed to include the textures from this WAD in the bsp.
        WadInclude_i it;
        for (it = g_WadInclude.begin(); it != g_WadInclude.end(); it++)
        {
            if (stristr(pszWadFile, it->c_str()))
            {
                Log("Embedding textures from WAD File [%s] into BSP\n", pszWadFile);
                bExcludeThisWad = true;
            }
        }

        if (!bExcludeThisWad)
        {
            safe_strncat(szNewWad, pszWadFile, MAXTOKEN);
            safe_strncat(szNewWad, ";", MAXTOKEN);
        }

        if (!bExcludeThisWad)
        {
            Log("Using WAD File: %s\n", pszWadFile);
        }

        // next wad file
        pszWadFile = strtok(NULL, ";");
    }

    SetKeyValue(&g_entities[0], "wad", szNewWad);
}
Пример #3
0
// this function is called in place of tex_initfromwad for onlyents compiles
void            HandleWadinclude()
{
    int             i;
    char            szTmpWad[1024]; // arbitrary, but needs to be large.
    char*           pszWadFile;
    wadpath_t*      currentwad;

    Log("\n"); // looks cleaner

    szTmpWad[0] = 0;

#ifdef HLCSG_AUTOWAD
    if (g_bWadAutoDetect)
    {
        autowad_UpdateUsedWads();
    }
#endif

    // for eachwadpath
    for (i = 0; i < g_iNumWadPaths; i++)
    {
        bool            bExcludeThisWad = false;

        currentwad = g_pWadPaths[i];
        pszWadFile = currentwad->path;
        
#ifdef HLCSG_AUTOWAD/*
    #ifdef _DEBUG
        Log("[dbg] HandleWIC: attempting to parse wad '%s'\n", currentwad->path);
    #endif*/
        if (g_bWadAutoDetect && !currentwad->usedtextures)
            continue;/*
    #ifdef _DEBUG
        Log("[dbg] HandleWIC: parsing wad\n");
    #endif*/
#endif // HLCSG_AUTOWAD

        // look and see if we're supposed to include the textures from this WAD in the bsp.
        WadInclude_i it;
        for (it = g_WadInclude.begin(); it != g_WadInclude.end(); it++)
        {
            if (stristr(pszWadFile, it->c_str()))
            {
                Log("Including Wadfile: %s\n", pszWadFile);
                bExcludeThisWad = true;             // wadincluding this one
            }
        }

        if (!bExcludeThisWad)
        {
            Log("Using Wadfile: %s\n", pszWadFile);
#ifdef HLCSG_STRIPWADPATH
			char tmp[_MAX_PATH];
			ExtractFile (pszWadFile, tmp);
            safe_snprintf(szTmpWad, 1024, "%s%s;", szTmpWad, tmp);
#else
            safe_snprintf(szTmpWad, 1024, "%s%s;", szTmpWad, pszWadFile);
#endif
        }
    }

    Log("\"wad\" is \"%s\"\n", szTmpWad);

    SetKeyValue(&g_entities[0], "wad", szTmpWad);

    Log("\n");
    CheckFatal();
}
Пример #4
0
void        autowad_UpdateUsedWads()
{
    // see which wadfiles are needed
    // code for this wad loop somewhat copied from below
    wadinfo_t       thiswad;
    lumpinfo_t*     thislump = NULL;
    wadpath_t*      currentwad;
    char*           pszWadFile;
    FILE*           texfile;
    const char*     pszWadroot = getenv("WADROOT");
    int             i, j;
    int             nTexLumps = 0;

#ifdef _DEBUG
    Log("[dbg] Starting wad dependency check\n");
#endif

    // open each wadpath and sort though its contents
    for (i = 0; i < g_iNumWadPaths; i++)
    {
        currentwad = g_pWadPaths[i];
        pszWadFile = currentwad->path;
        currentwad->usedbymap = false;  // guilty until proven innocent

#ifdef _DEBUG
        Log(" Parsing wad: '%s'\n", pszWadFile);
#endif

        texfile = fopen(pszWadFile, "rb");

#ifdef SYSTEM_WIN32
        if (!texfile)
        {
            // cant find it, maybe this wad file has a hard code drive
            if (pszWadFile[1] == ':')
            {
                pszWadFile += 2;                           // skip past the drive
                texfile = fopen(pszWadFile, "rb");
            }
        }
#endif

        char            szTmp[_MAX_PATH];
        if (!texfile && pszWadroot)
        {
            char            szFile[_MAX_PATH];
            char            szSubdir[_MAX_PATH];

            ExtractFile(pszWadFile, szFile);

            ExtractFilePath(pszWadFile, szTmp);
            ExtractFile(szTmp, szSubdir);

            // szSubdir will have a trailing separator
            safe_snprintf(szTmp, _MAX_PATH, "%s" SYSTEM_SLASH_STR "%s%s", pszWadroot, szSubdir, szFile);
            texfile = fopen(szTmp, "rb");

#ifdef SYSTEM_POSIX
            if (!texfile)
            {
                // cant find it, Convert to lower case and try again
                strlwr(szTmp);
                texfile = fopen(szTmp, "rb");
            }
#endif
        }

#ifdef HLCSG_SEARCHWADPATH_VL
#ifdef SYSTEM_WIN32
        if (!texfile && pszWadFile[0] == '\\')
        {
            char tmp[_MAX_PATH];
            int l;
            for (l = 'C'; l <= 'Z'; ++l)
            {
                safe_snprintf (tmp, _MAX_PATH, "%c:%s", l, pszWadFile);
                texfile = fopen (tmp, "rb");
                if (texfile)
                {
                    break;
                }
            }
        }
#endif
#endif

        if (!texfile) // still cant find it, skip this one
        {
#ifdef HLCSG_SEARCHWADPATH_VL
            pszWadFile = currentwad->path; // correct it back
#endif
            if(pszWadroot)
            {
                Warning("Wad file '%s' not found, also tried '%s'",pszWadFile,szTmp);
            }
            else
            {
                Warning("Wad file '%s' not found",pszWadFile);
            }
            continue;
        }

        // look and see if we're supposed to include the textures from this WAD in the bsp.
        {
            WadInclude_i    it;
            bool            including = false;
            for (it = g_WadInclude.begin(); it != g_WadInclude.end(); it++)
            {
                if (stristr(pszWadFile, it->c_str()))
                {
#ifdef _DEBUG
                    Log("  - including wad\n");
#endif
                    including = true;
                    currentwad->usedbymap = true;
                    break;
                }
            }
            if (including)
            {
                //fclose(texfile);
                //continue;
            }
        }

        // read in this wadfiles information
        SafeRead(texfile, &thiswad, sizeof(thiswad));

        // make sure its a valid format
        if (strncmp(thiswad.identification, "WAD2", 4) && strncmp(thiswad.identification, "WAD3", 4))
        {
            fclose(texfile);
            continue;
        }

        thiswad.numlumps        = LittleLong(thiswad.numlumps);
        thiswad.infotableofs    = LittleLong(thiswad.infotableofs);

        // read in lump
        if (fseek(texfile, thiswad.infotableofs, SEEK_SET))
        {
            fclose(texfile);
            continue;   // had trouble reading, skip this wad
        }

        // memalloc for this lump
        thislump = (lumpinfo_t*)realloc(thislump, (nTexLumps + thiswad.numlumps) * sizeof(lumpinfo_t));
        // BUGBUG: is this destructed?

        // for each texlump
        for (j = 0; j < thiswad.numlumps; j++, nTexLumps++)
        {
            SafeRead(texfile, &thislump[nTexLumps], (sizeof(lumpinfo_t) - sizeof(int)) );  // iTexFile is NOT read from file

            CleanupName(thislump[nTexLumps].name, thislump[nTexLumps].name);

            if (autowad_IsUsedTexture(thislump[nTexLumps].name))
            {
                currentwad->usedbymap = true;
                currentwad->usedtextures++;
#ifdef _DEBUG
                Log("    - Used wadfile: [%s]\n", thislump[nTexLumps].name);
#endif
                autowad_PurgeName(thislump[nTexLumps].name);
            }
        }

        fclose(texfile);
    }

#ifdef _DEBUG
    Log("[dbg] End wad dependency check\n\n");
#endif
    return;
}
Пример #5
0
// =====================================================================================
//  TEX_InitFromWad
// =====================================================================================
bool            TEX_InitFromWad()
{
    int             i, j;
    wadinfo_t       wadinfo;
    char            szTmpWad[1024]; // arbitrary, but needs to be large.
    char*           pszWadFile;
    const char*     pszWadroot;
    wadpath_t*      currentwad;

    Log("\n"); // looks cleaner

    szTmpWad[0] = 0;
    pszWadroot = getenv("WADROOT");

#ifdef HLCSG_AUTOWAD
    autowad_UpdateUsedWads();
#endif

    // for eachwadpath
    for (i = 0; i < g_iNumWadPaths; i++)
    {
        FILE*           texfile;                           // temporary used in this loop
        bool            bExcludeThisWad = false;

        currentwad = g_pWadPaths[i];
        pszWadFile = currentwad->path;


#ifdef HLCSG_AUTOWAD
        #ifdef _DEBUG
        Log("[dbg] Attempting to parse wad: '%s'\n", pszWadFile);
        #endif

        if (g_bWadAutoDetect && !currentwad->usedtextures)
            continue;

        #ifdef _DEBUG
        Log("[dbg] Parsing wad\n");
        #endif
#endif

        texfiles[nTexFiles] = fopen(pszWadFile, "rb");

        #ifdef SYSTEM_WIN32
        if (!texfiles[nTexFiles])
        {
            // cant find it, maybe this wad file has a hard code drive
            if (pszWadFile[1] == ':')
            {
                pszWadFile += 2;                           // skip past the drive
                texfiles[nTexFiles] = fopen(pszWadFile, "rb");
            }
        }
        #endif

        if (!texfiles[nTexFiles] && pszWadroot)
        {
            char            szTmp[_MAX_PATH];
            char            szFile[_MAX_PATH];
            char            szSubdir[_MAX_PATH];

            ExtractFile(pszWadFile, szFile);

            ExtractFilePath(pszWadFile, szTmp);
            ExtractFile(szTmp, szSubdir);

            // szSubdir will have a trailing separator
            safe_snprintf(szTmp, _MAX_PATH, "%s" SYSTEM_SLASH_STR "%s%s", pszWadroot, szSubdir, szFile);
            texfiles[nTexFiles] = fopen(szTmp, "rb");

            #ifdef SYSTEM_POSIX
            if (!texfiles[nTexFiles])
            {
                // if we cant find it, Convert to lower case and try again
                strlwr(szTmp);
                texfiles[nTexFiles] = fopen(szTmp, "rb");
            }
            #endif
        }

        if (!texfiles[nTexFiles])
        {
            // still cant find it, error out
            Fatal(assume_COULD_NOT_FIND_WAD, "Could not open wad file %s", pszWadFile);
            continue;
        }

        // look and see if we're supposed to include the textures from this WAD in the bsp.
        WadInclude_i it;
        for (it = g_WadInclude.begin(); it != g_WadInclude.end(); it++)
        {
            if (stristr(pszWadFile, it->c_str()))
            {
                Log("Including Wadfile: %s\n", pszWadFile);
                bExcludeThisWad = true;             // wadincluding this one
                s_WadIncludeMap[nTexFiles] = true;
                break;
            }
        }

        if (!bExcludeThisWad)
        {
            Log("Using Wadfile: %s\n", pszWadFile);
            safe_snprintf(szTmpWad, 1024, "%s%s;", szTmpWad, pszWadFile);
        }

        // temp assignment to make things cleaner:
        texfile = texfiles[nTexFiles];

        // read in this wadfiles information
        SafeRead(texfile, &wadinfo, sizeof(wadinfo));

        // make sure its a valid format
        if (strncmp(wadinfo.identification, "WAD2", 4) && strncmp(wadinfo.identification, "WAD3", 4))
        {
            Log(" - ");
            Error("%s isn't a Wadfile!", pszWadFile);
        }

        wadinfo.numlumps        = LittleLong(wadinfo.numlumps);
        wadinfo.infotableofs    = LittleLong(wadinfo.infotableofs);

        // read in lump
        if (fseek(texfile, wadinfo.infotableofs, SEEK_SET))
            Warning("fseek to %d in wadfile %s failed\n", wadinfo.infotableofs, pszWadFile);

        // memalloc for this lump
        lumpinfo = (lumpinfo_t*)realloc(lumpinfo, (nTexLumps + wadinfo.numlumps) * sizeof(lumpinfo_t));

        // for each texlump
        for (j = 0; j < wadinfo.numlumps; j++, nTexLumps++)
        {
            SafeRead(texfile, &lumpinfo[nTexLumps], (sizeof(lumpinfo_t) - sizeof(int)) );  // iTexFile is NOT read from file

            if (!TerminatedString(lumpinfo[nTexLumps].name, MAXWADNAME))
            {
                lumpinfo[nTexLumps].name[MAXWADNAME - 1] = 0;
                Log(" - ");
                Warning("Unterminated texture name : wad[%s] texture[%d] name[%s]\n", pszWadFile, nTexLumps, lumpinfo[nTexLumps].name);
            }

            CleanupName(lumpinfo[nTexLumps].name, lumpinfo[nTexLumps].name);

            lumpinfo[nTexLumps].filepos = LittleLong(lumpinfo[nTexLumps].filepos);
            lumpinfo[nTexLumps].disksize = LittleLong(lumpinfo[nTexLumps].disksize);
            lumpinfo[nTexLumps].iTexFile = nTexFiles;

            if (lumpinfo[nTexLumps].disksize > MAX_TEXTURE_SIZE)
            {
                Log(" - ");
                Warning("Larger than expected texture (%d bytes): '%s'",
                    lumpinfo[nTexLumps].disksize, lumpinfo[nTexLumps].name);
            }

        }

        // AJM: this feature is dependant on autowad. :(
        // CONSIDER: making it standard?
#ifdef HLCSG_AUTOWAD
        {
            double percused = ((float)(currentwad->usedtextures) / (float)(g_numUsedTextures)) * 100;
            Log(" - Contains %i used texture%s, %2.2f percent of map (%d textures in wad)\n",
                currentwad->usedtextures, currentwad->usedtextures == 1 ? "" : "s", percused, wadinfo.numlumps);
        }
#endif

        nTexFiles++;
        hlassume(nTexFiles < MAX_TEXFILES, assume_MAX_TEXFILES);
    }

    //Log("num of used textures: %i\n", g_numUsedTextures);

    // AJM: Tommy suggested i add this warning message in, and  it certianly doesnt
    //  hurt to be cautious. Especially one of the possible side effects he mentioned was svc_bad
    if (nTexFiles > 8)
    {
        Log("\n");
        Warning("More than 8 wadfiles are in use. (%i)\n"
                "This may be harmless, and if no strange side effects are occurring, then\n"
                "it can safely be ignored. However, if your map starts exhibiting strange\n"
                "or obscure errors, consider this as suspect.\n"
                , nTexFiles);
    }

    // sort texlumps in memory by name
    qsort((void*)lumpinfo, (size_t) nTexLumps, sizeof(lumpinfo[0]), lump_sorter_by_name);

    SetKeyValue(&g_entities[0], "wad", szTmpWad);

    Log("\n");
    CheckFatal();
    return true;
}