wadinclude.cpp 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. #pragma warning(disable:4267) // 'size_t' to 'unsigned int', possible loss of data
  2. #include "csg.h"
  3. #ifdef HAVE_UNISTD_E
  4. #include <unistd.h>
  5. #endif
  6. void LoadWadincludeFile(const char* const filename)
  7. {
  8. char* fname;
  9. int i, x;
  10. char* pData = NULL;
  11. char* pszData;
  12. unsigned len = strlen(filename) + 5;
  13. fname = (char*)Alloc(len);
  14. safe_snprintf(fname, len, "%s.wic", filename);
  15. if (q_exists(fname))
  16. {
  17. i = LoadFile(fname, &pData);
  18. if (i == 0)
  19. {
  20. goto LoadWadincludeFileReturn;
  21. }
  22. }
  23. else
  24. {
  25. Warning("WadInclude file %s does not exist", fname);
  26. goto LoadWadincludeFileReturn;
  27. }
  28. for (pszData = pData, x = 0; x < i; x++)
  29. {
  30. if (pData[x] == ';')
  31. {
  32. pData[x] = 0;
  33. g_WadInclude.push_back(pszData);
  34. pszData = pData + x + 1;
  35. }
  36. }
  37. LoadWadincludeFileReturn:;
  38. Free(fname);
  39. if (pData)
  40. {
  41. Free(pData);
  42. }
  43. }
  44. void SaveWadincludeFile(const char* const filename)
  45. {
  46. char* fname;
  47. FILE* file;
  48. int x;
  49. unsigned len = strlen(filename) + 5;
  50. fname = (char*)Alloc(len);
  51. safe_snprintf(fname, len, "%s.wic", filename);
  52. _unlink(fname);
  53. file = SafeOpenWrite(fname);
  54. WadInclude_i it;
  55. for (it = g_WadInclude.begin(); it != g_WadInclude.end(); it++)
  56. {
  57. x = it->size();
  58. if (x)
  59. {
  60. SafeWrite(file, it->c_str(), x);
  61. SafeWrite(file, ";", 1);
  62. }
  63. }
  64. Free(fname);
  65. fclose(file);
  66. }
  67. // this function is called in place of tex_initfromwad for onlyents compiles
  68. void HandleWadinclude()
  69. {
  70. int i;
  71. char szTmpWad[1024]; // arbitrary, but needs to be large.
  72. char* pszWadFile;
  73. wadpath_t* currentwad;
  74. Log("\n\nChecking Wadfiles:\n\n"); //SILENCER //Indentation and blank lines make it much easier to view
  75. szTmpWad[0] = 0;
  76. #ifdef HLCSG_AUTOWAD
  77. if (g_bWadAutoDetect)
  78. {
  79. autowad_UpdateUsedWads();
  80. }
  81. #endif
  82. // for eachwadpath
  83. for (i = 0; i < g_iNumWadPaths; i++)
  84. {
  85. bool bExcludeThisWad = false;
  86. currentwad = g_pWadPaths[i];
  87. pszWadFile = currentwad->path;
  88. #ifdef HLCSG_AUTOWAD/*
  89. #ifdef _DEBUG
  90. Log("[dbg] HandleWIC: attempting to parse wad '%s'\n", currentwad->path);
  91. #endif*/
  92. if (g_bWadAutoDetect && !currentwad->usedtextures)
  93. continue;/*
  94. #ifdef _DEBUG
  95. Log("[dbg] HandleWIC: parsing wad\n");
  96. #endif*/
  97. #endif // HLCSG_AUTOWAD
  98. // look and see if we're supposed to include the textures from this WAD in the bsp.
  99. WadInclude_i it;
  100. for (it = g_WadInclude.begin(); it != g_WadInclude.end(); it++)
  101. {
  102. if (stristr(pszWadFile, it->c_str()))
  103. {
  104. Log(" Including Wadfile: %s:\n", pszWadFile); //SILENCER //Indentation and blank lines make it much easier to view
  105. bExcludeThisWad = true; // wadincluding this one
  106. }
  107. }
  108. if (!bExcludeThisWad)
  109. {
  110. Log(" Using Wadfile: %s:\n", pszWadFile); //SILENCER //Indentation and blank lines make it much easier to view
  111. safe_snprintf(szTmpWad, 1024, "%s%s;", szTmpWad, pszWadFile);
  112. }
  113. }
  114. Log("\"wad\" is \"%s\"\n", szTmpWad);
  115. SetKeyValue(&g_entities[0], "wad", szTmpWad);
  116. Log("\n");
  117. CheckFatal();
  118. }
  119. #if 0
  120. void HandleWadinclude()
  121. {
  122. // Code somewhat copied from TEX_InitFromWad()
  123. char szTmpPath[MAXTOKEN];
  124. char szNewWad[MAXTOKEN];
  125. char* pszWadFile;
  126. bool bExcludeThisWad;
  127. const char* path = ValueForKey(&g_entities[0], "wad");
  128. szNewWad[0] = 0;
  129. safe_strncpy(szTmpPath, path, MAXTOKEN);
  130. // temporary kludge so we don't have to deal with no occurances of a semicolon
  131. // in the path name ..
  132. if (strchr(szTmpPath, ';') == NULL)
  133. {
  134. safe_strncat(szTmpPath, ";", MAXTOKEN);
  135. }
  136. pszWadFile = strtok(szTmpPath, ";");
  137. while (pszWadFile)
  138. {
  139. bExcludeThisWad = false;
  140. // look and see if we're supposed to include the textures from this WAD in the bsp.
  141. WadInclude_i it;
  142. for (it = g_WadInclude.begin(); it != g_WadInclude.end(); it++)
  143. {
  144. if (stristr(pszWadFile, it->c_str()))
  145. {
  146. Log("Embedding textures from WAD File [%s] into BSP\n", pszWadFile);
  147. bExcludeThisWad = true;
  148. }
  149. }
  150. if (!bExcludeThisWad)
  151. {
  152. safe_strncat(szNewWad, pszWadFile, MAXTOKEN);
  153. safe_strncat(szNewWad, ";", MAXTOKEN);
  154. }
  155. if (!bExcludeThisWad)
  156. {
  157. Log("Using WAD File: %s\n", pszWadFile);
  158. }
  159. // next wad file
  160. pszWadFile = strtok(NULL, ";");
  161. }
  162. SetKeyValue(&g_entities[0], "wad", szNewWad);
  163. }
  164. #endif