mirror of
https://github.com/ZDoom/gzdoom.git
synced 2025-01-20 08:31:11 +00:00
- refactored all places which treated FileData as zero terminated.
This commit is contained in:
parent
79e6d068a9
commit
2c2bf0265f
19 changed files with 63 additions and 47 deletions
|
@ -182,7 +182,7 @@ static void SetupGenMidi()
|
|||
auto genmidi = fileSystem.ReadFile(lump);
|
||||
|
||||
if (genmidi.GetSize() < 8 + 175 * 36 || memcmp(genmidi.GetMem(), "#OPL_II#", 8)) return;
|
||||
ZMusic_SetGenMidi((uint8_t*)genmidi.GetString() + 8);
|
||||
ZMusic_SetGenMidi(genmidi.GetBytes() + 8);
|
||||
}
|
||||
|
||||
static void SetupWgOpn()
|
||||
|
|
|
@ -200,8 +200,11 @@ void FScanner :: OpenLumpNum (int lump)
|
|||
{
|
||||
Close ();
|
||||
{
|
||||
FileData mem = fileSystem.ReadFile(lump);
|
||||
ScriptBuffer = mem.GetString();
|
||||
auto mem = fileSystem.OpenFileReader(lump);
|
||||
auto buff = ScriptBuffer.LockNewBuffer(mem.GetLength());
|
||||
mem.Read(buff, mem.GetLength());
|
||||
buff[mem.GetLength()] = 0;
|
||||
ScriptBuffer.UnlockBuffer();
|
||||
}
|
||||
ScriptName = fileSystem.GetFileFullPath(lump).c_str();
|
||||
LumpNum = lump;
|
||||
|
|
|
@ -375,11 +375,9 @@ bool FShader::Load(const char * name, const char * vert_prog_lump, const char *
|
|||
|
||||
int vp_lump = fileSystem.CheckNumForFullName(vert_prog_lump, 0);
|
||||
if (vp_lump == -1) I_Error("Unable to load '%s'", vert_prog_lump);
|
||||
FileData vp_data = fileSystem.ReadFile(vp_lump);
|
||||
|
||||
int fp_lump = fileSystem.CheckNumForFullName(frag_prog_lump, 0);
|
||||
if (fp_lump == -1) I_Error("Unable to load '%s'", frag_prog_lump);
|
||||
FileData fp_data = fileSystem.ReadFile(fp_lump);
|
||||
|
||||
|
||||
|
||||
|
@ -410,8 +408,8 @@ bool FShader::Load(const char * name, const char * vert_prog_lump, const char *
|
|||
vp_comb << "#line 1\n";
|
||||
fp_comb << "#line 1\n";
|
||||
|
||||
vp_comb << RemoveLayoutLocationDecl(vp_data.GetString(), "out").GetChars() << "\n";
|
||||
fp_comb << RemoveLayoutLocationDecl(fp_data.GetString(), "in").GetChars() << "\n";
|
||||
vp_comb << RemoveLayoutLocationDecl(GetStringFromLump(vp_lump), "out").GetChars() << "\n";
|
||||
fp_comb << RemoveLayoutLocationDecl(GetStringFromLump(fp_lump), "in").GetChars() << "\n";
|
||||
FString placeholder = "\n";
|
||||
|
||||
if (proc_prog_lump != NULL)
|
||||
|
@ -423,7 +421,7 @@ bool FShader::Load(const char * name, const char * vert_prog_lump, const char *
|
|||
int pp_lump = fileSystem.CheckNumForFullName(proc_prog_lump, 0); // if it's a core shader, ignore overrides by user mods.
|
||||
if (pp_lump == -1) pp_lump = fileSystem.CheckNumForFullName(proc_prog_lump);
|
||||
if (pp_lump == -1) I_Error("Unable to load '%s'", proc_prog_lump);
|
||||
FString pp_data = fileSystem.ReadFile(pp_lump).GetString();
|
||||
FString pp_data = GetStringFromLump(pp_lump);
|
||||
|
||||
if (pp_data.IndexOf("ProcessMaterial") < 0 && pp_data.IndexOf("SetupMaterial") < 0)
|
||||
{
|
||||
|
@ -433,15 +431,13 @@ bool FShader::Load(const char * name, const char * vert_prog_lump, const char *
|
|||
{
|
||||
int pl_lump = fileSystem.CheckNumForFullName("shaders/glsl/func_defaultmat2.fp", 0);
|
||||
if (pl_lump == -1) I_Error("Unable to load '%s'", "shaders/glsl/func_defaultmat2.fp");
|
||||
FileData pl_data = fileSystem.ReadFile(pl_lump);
|
||||
fp_comb << "\n" << pl_data.GetString();
|
||||
fp_comb << "\n" << GetStringFromLump(pl_lump);
|
||||
}
|
||||
else
|
||||
{
|
||||
int pl_lump = fileSystem.CheckNumForFullName("shaders/glsl/func_defaultmat.fp", 0);
|
||||
if (pl_lump == -1) I_Error("Unable to load '%s'", "shaders/glsl/func_defaultmat.fp");
|
||||
FileData pl_data = fileSystem.ReadFile(pl_lump);
|
||||
fp_comb << "\n" << pl_data.GetString();
|
||||
fp_comb << "\n" << GetStringFromLump(pl_lump);
|
||||
|
||||
if (pp_data.IndexOf("ProcessTexel") < 0)
|
||||
{
|
||||
|
@ -467,8 +463,7 @@ bool FShader::Load(const char * name, const char * vert_prog_lump, const char *
|
|||
{
|
||||
int pl_lump = fileSystem.CheckNumForFullName("shaders/glsl/func_defaultlight.fp", 0);
|
||||
if (pl_lump == -1) I_Error("Unable to load '%s'", "shaders/glsl/func_defaultlight.fp");
|
||||
FileData pl_data = fileSystem.ReadFile(pl_lump);
|
||||
fp_comb << "\n" << pl_data.GetString();
|
||||
fp_comb << "\n" << GetStringFromLump(pl_lump);
|
||||
}
|
||||
|
||||
// ProcessMaterial must be considered broken because it requires the user to fill in data they possibly cannot know all about.
|
||||
|
@ -490,8 +485,7 @@ bool FShader::Load(const char * name, const char * vert_prog_lump, const char *
|
|||
{
|
||||
int pp_lump = fileSystem.CheckNumForFullName(light_fragprog, 0);
|
||||
if (pp_lump == -1) I_Error("Unable to load '%s'", light_fragprog);
|
||||
FileData pp_data = fileSystem.ReadFile(pp_lump);
|
||||
fp_comb << pp_data.GetString() << "\n";
|
||||
fp_comb << GetStringFromLump(pp_lump) << "\n";
|
||||
}
|
||||
|
||||
if (gl.flags & RFL_NO_CLIP_PLANES)
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
#include "hw_shaderpatcher.h"
|
||||
#include "filesystem.h"
|
||||
#include "printf.h"
|
||||
#include "cmdlib.h"
|
||||
|
||||
namespace OpenGLRenderer
|
||||
{
|
||||
|
@ -88,7 +89,9 @@ void FShaderProgram::Compile(ShaderType type, const char *lumpName, const char *
|
|||
{
|
||||
int lump = fileSystem.CheckNumForFullName(lumpName);
|
||||
if (lump == -1) I_FatalError("Unable to load '%s'", lumpName);
|
||||
FString code = fileSystem.ReadFile(lump).GetString();
|
||||
auto sp = fileSystem.ReadFile(lump);
|
||||
FString code = GetStringFromLump(lump);
|
||||
|
||||
Compile(type, lumpName, code, defines, maxGlslVersion);
|
||||
}
|
||||
|
||||
|
|
|
@ -410,8 +410,8 @@ bool FShader::Load(const char * name, const char * vert_prog_lump_, const char *
|
|||
vp_comb << "#line 1\n";
|
||||
fp_comb << "#line 1\n";
|
||||
|
||||
vp_comb << RemoveLayoutLocationDecl(vp_data.GetString(), "out").GetChars() << "\n";
|
||||
fp_comb << RemoveLayoutLocationDecl(fp_data.GetString(), "in").GetChars() << "\n";
|
||||
vp_comb << RemoveLayoutLocationDecl(GetStringFromLump(vp_lump), "out").GetChars() << "\n";
|
||||
fp_comb << RemoveLayoutLocationDecl(GetStringFromLump(fp_lump), "in").GetChars() << "\n";
|
||||
FString placeholder = "\n";
|
||||
|
||||
if (proc_prog_lump.Len())
|
||||
|
@ -422,7 +422,8 @@ bool FShader::Load(const char * name, const char * vert_prog_lump_, const char *
|
|||
{
|
||||
int pp_lump = fileSystem.CheckNumForFullName(proc_prog_lump);
|
||||
if (pp_lump == -1) I_Error("Unable to load '%s'", proc_prog_lump.GetChars());
|
||||
FString pp_data = fileSystem.ReadFile(pp_lump).GetString();
|
||||
auto ppf = fileSystem.ReadFile(pp_lump);
|
||||
FString pp_data = GetStringFromLump(pp_lump);
|
||||
|
||||
if (pp_data.IndexOf("ProcessMaterial") < 0 && pp_data.IndexOf("SetupMaterial") < 0)
|
||||
{
|
||||
|
@ -432,15 +433,13 @@ bool FShader::Load(const char * name, const char * vert_prog_lump_, const char *
|
|||
{
|
||||
int pl_lump = fileSystem.CheckNumForFullName("shaders_gles/glsl/func_defaultmat2.fp", 0);
|
||||
if (pl_lump == -1) I_Error("Unable to load '%s'", "shaders_gles/glsl/func_defaultmat2.fp");
|
||||
FileData pl_data = fileSystem.ReadFile(pl_lump);
|
||||
fp_comb << "\n" << pl_data.GetString();
|
||||
fp_comb << "\n" << GetStringFromLump(pl_lump);
|
||||
}
|
||||
else
|
||||
{
|
||||
int pl_lump = fileSystem.CheckNumForFullName("shaders_gles/glsl/func_defaultmat.fp", 0);
|
||||
if (pl_lump == -1) I_Error("Unable to load '%s'", "shaders_gles/glsl/func_defaultmat.fp");
|
||||
FileData pl_data = fileSystem.ReadFile(pl_lump);
|
||||
fp_comb << "\n" << pl_data.GetString();
|
||||
fp_comb << "\n" << GetStringFromLump(pl_lump);
|
||||
|
||||
if (pp_data.IndexOf("ProcessTexel") < 0)
|
||||
{
|
||||
|
@ -466,8 +465,7 @@ bool FShader::Load(const char * name, const char * vert_prog_lump_, const char *
|
|||
{
|
||||
int pl_lump = fileSystem.CheckNumForFullName("shaders_gles/glsl/func_defaultlight.fp", 0);
|
||||
if (pl_lump == -1) I_Error("Unable to load '%s'", "shaders_gles/glsl/func_defaultlight.fp");
|
||||
FileData pl_data = fileSystem.ReadFile(pl_lump);
|
||||
fp_comb << "\n" << pl_data.GetString();
|
||||
fp_comb << "\n" << GetStringFromLump(pl_lump);
|
||||
}
|
||||
|
||||
// ProcessMaterial must be considered broken because it requires the user to fill in data they possibly cannot know all about.
|
||||
|
@ -489,8 +487,7 @@ bool FShader::Load(const char * name, const char * vert_prog_lump_, const char *
|
|||
{
|
||||
int pp_lump = fileSystem.CheckNumForFullName(light_fragprog, 0);
|
||||
if (pp_lump == -1) I_Error("Unable to load '%s'", light_fragprog.GetChars());
|
||||
FileData pp_data = fileSystem.ReadFile(pp_lump);
|
||||
fp_comb << pp_data.GetString() << "\n";
|
||||
fp_comb << GetStringFromLump(pp_lump) << "\n";
|
||||
}
|
||||
|
||||
if (gles.flags & RFL_NO_CLIP_PLANES)
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
#include "hw_shaderpatcher.h"
|
||||
#include "filesystem.h"
|
||||
#include "printf.h"
|
||||
#include "cmdlib.h"
|
||||
|
||||
namespace OpenGLESRenderer
|
||||
{
|
||||
|
@ -88,7 +89,8 @@ void FShaderProgram::Compile(ShaderType type, const char *lumpName, const char *
|
|||
{
|
||||
int lump = fileSystem.CheckNumForFullName(lumpName);
|
||||
if (lump == -1) I_FatalError("Unable to load '%s'", lumpName);
|
||||
FString code = fileSystem.ReadFile(lump).GetString();
|
||||
auto sp = fileSystem.ReadFile(lump);
|
||||
FString code = GetStringFromLump(lump);
|
||||
Compile(type, lumpName, code, defines, maxGlslVersion);
|
||||
}
|
||||
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
#include "zvulkan/vulkanbuilders.h"
|
||||
#include "vulkan/system/vk_commandbuffer.h"
|
||||
#include "filesystem.h"
|
||||
#include "cmdlib.h"
|
||||
|
||||
VkPPShader::VkPPShader(VulkanRenderDevice* fb, PPShader *shader) : fb(fb)
|
||||
{
|
||||
|
@ -66,7 +67,8 @@ FString VkPPShader::LoadShaderCode(const FString &lumpName, const FString &defin
|
|||
{
|
||||
int lump = fileSystem.CheckNumForFullName(lumpName);
|
||||
if (lump == -1) I_FatalError("Unable to load '%s'", lumpName.GetChars());
|
||||
FString code = fileSystem.ReadFile(lump).GetString();
|
||||
auto sp = fileSystem.ReadFile(lump);
|
||||
FString code = GetStringFromLump(lump);
|
||||
|
||||
FString patchedCode;
|
||||
patchedCode.AppendFormat("#version %d\n", 450);
|
||||
|
|
|
@ -466,8 +466,7 @@ FString VkShaderManager::LoadPublicShaderLump(const char *lumpname)
|
|||
int lump = fileSystem.CheckNumForFullName(lumpname, 0);
|
||||
if (lump == -1) lump = fileSystem.CheckNumForFullName(lumpname);
|
||||
if (lump == -1) I_Error("Unable to load '%s'", lumpname);
|
||||
FileData data = fileSystem.ReadFile(lump);
|
||||
return data.GetString();
|
||||
return GetStringFromLump(lump);
|
||||
}
|
||||
|
||||
FString VkShaderManager::LoadPrivateShaderLump(const char *lumpname)
|
||||
|
@ -475,7 +474,7 @@ FString VkShaderManager::LoadPrivateShaderLump(const char *lumpname)
|
|||
int lump = fileSystem.CheckNumForFullName(lumpname, 0);
|
||||
if (lump == -1) I_Error("Unable to load '%s'", lumpname);
|
||||
FileData data = fileSystem.ReadFile(lump);
|
||||
return data.GetString();
|
||||
return GetStringFromLump(lump);
|
||||
}
|
||||
|
||||
VkPPShader* VkShaderManager::GetVkShader(PPShader* shader)
|
||||
|
|
|
@ -841,7 +841,7 @@ DEFINE_ACTION_FUNCTION(_Wads, ReadLump)
|
|||
PARAM_PROLOGUE;
|
||||
PARAM_INT(lump);
|
||||
const bool isLumpValid = lump >= 0 && lump < fileSystem.GetNumEntries();
|
||||
ACTION_RETURN_STRING(isLumpValid ? fileSystem.ReadFile(lump).GetString() : "");
|
||||
ACTION_RETURN_STRING(isLumpValid ? GetStringFromLump(lump) : FString());
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
|
|
|
@ -217,7 +217,7 @@ static inline void drawframe(anim_t *anim, uint16_t framenumber)
|
|||
}
|
||||
|
||||
// <length> is the file size, for consistency checking.
|
||||
int32_t ANIM_LoadAnim(anim_t *anim, uint8_t *buffer, size_t length)
|
||||
int32_t ANIM_LoadAnim(anim_t *anim, const uint8_t *buffer, size_t length)
|
||||
{
|
||||
if (memcmp(buffer, "LPF ", 4)) return -1;
|
||||
|
||||
|
|
|
@ -92,7 +92,7 @@ struct anim_t
|
|||
lp_descriptor * curlp; // header of large page currently in memory
|
||||
uint16_t * thepage; // buffer where current large page is loaded
|
||||
uint8_t imagebuffer[IMAGEBUFFERSIZE]; // buffer where anim frame is decoded
|
||||
uint8_t * buffer;
|
||||
const uint8_t * buffer;
|
||||
uint8_t pal[768];
|
||||
int32_t currentframe;
|
||||
};
|
||||
|
@ -105,7 +105,7 @@ struct anim_t
|
|||
//
|
||||
//****************************************************************************
|
||||
|
||||
int32_t ANIM_LoadAnim(anim_t *anim, uint8_t *buffer, size_t length);
|
||||
int32_t ANIM_LoadAnim(anim_t *anim, const uint8_t *buffer, size_t length);
|
||||
|
||||
//****************************************************************************
|
||||
//
|
||||
|
|
|
@ -104,7 +104,7 @@ FAnmTexture::FAnmTexture (int lumpnum, int w, int h)
|
|||
void FAnmTexture::ReadFrame(uint8_t *pixels, uint8_t *palette)
|
||||
{
|
||||
FileData lump = fileSystem.ReadFile (SourceLump);
|
||||
uint8_t *source = (uint8_t *)lump.GetMem();
|
||||
auto source = lump.GetBytes();
|
||||
|
||||
anim_t anim;
|
||||
if (ANIM_LoadAnim(&anim, source, (int)lump.GetSize()) >= 0)
|
||||
|
|
|
@ -36,6 +36,7 @@
|
|||
|
||||
#include "cmdlib.h"
|
||||
#include "fs_findfile.h"
|
||||
#include "filesystem.h"
|
||||
#include "files.h"
|
||||
#include "md5.h"
|
||||
|
||||
|
@ -1008,3 +1009,17 @@ void uppercopy(char* to, const char* from)
|
|||
to[i] = 0;
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// GetStringFromLump
|
||||
//
|
||||
// Loads a zero terminated string from a lump in the file system
|
||||
//==========================================================================
|
||||
|
||||
FString GetStringFromLump(int lump)
|
||||
{
|
||||
FileData fd = fileSystem.ReadFile(lump);
|
||||
FString ScriptBuffer(fd.GetString(), fd.GetSize());
|
||||
ScriptBuffer.Truncate(strlen(ScriptBuffer.GetChars())); // this is necessary to properly truncate the generated string to not contain 0 bytes.
|
||||
return ScriptBuffer;
|
||||
}
|
||||
|
|
|
@ -87,6 +87,7 @@ struct MD5Context;
|
|||
|
||||
void md5Update(FileReader& file, MD5Context& md5, unsigned len);
|
||||
void uppercopy(char* to, const char* from);
|
||||
FString GetStringFromLump(int lump);
|
||||
|
||||
inline void fillshort(void* buff, size_t count, uint16_t clear)
|
||||
{
|
||||
|
|
|
@ -681,8 +681,8 @@ FString V_GetColorStringByName(const char* name, FScriptPosition* sc)
|
|||
}
|
||||
|
||||
auto rgbNames = fileSystem.ReadFile(rgblump);
|
||||
rgb = (char*)rgbNames.GetMem();
|
||||
rgbEnd = rgb + fileSystem.FileLength(rgblump);
|
||||
rgb = rgbNames.GetString();
|
||||
rgbEnd = rgb + rgbNames.GetSize();
|
||||
step = 0;
|
||||
namelen = strlen(name);
|
||||
|
||||
|
|
|
@ -166,8 +166,8 @@ void D_LoadWadSettings ()
|
|||
while ((lump = fileSystem.FindLump ("KEYCONF", &lastlump)) != -1)
|
||||
{
|
||||
FileData data = fileSystem.ReadFile (lump);
|
||||
const char *eof = data.GetString() + fileSystem.FileLength (lump);
|
||||
const char *conf = data.GetString();
|
||||
const char* conf = data.GetString();
|
||||
const char *eof = conf + data.GetSize();
|
||||
|
||||
while (conf < eof)
|
||||
{
|
||||
|
|
|
@ -323,12 +323,12 @@ void FParseContext::ParseLump(const char *lumpname)
|
|||
}
|
||||
|
||||
// Read the lump into a buffer and add a 0-terminator
|
||||
auto lumpdata = fileSystem.ReadFile(lumpno);
|
||||
|
||||
SourceLine = 0;
|
||||
SourceFile = lumpname;
|
||||
|
||||
const char *sourcep = lumpdata.GetString();
|
||||
FString source = GetStringFromLump(lumpno);
|
||||
const char *sourcep = source.GetChars();
|
||||
while ( (tokentype = GetToken(sourcep, &token)) )
|
||||
{
|
||||
// It is much easier to handle include statements outside the main parser.
|
||||
|
|
|
@ -320,7 +320,7 @@ bool FIntermissionActionTextscreen::ParseKey(FScanner &sc)
|
|||
}
|
||||
}
|
||||
if (!done)
|
||||
mText = fileSystem.ReadFile(lump).GetString();
|
||||
mText = GetStringFromLump(lump);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -864,7 +864,7 @@ DIntermissionController* F_StartFinale (const char *music, int musicorder, int c
|
|||
int lump = fileSystem.CheckNumForFullName(text, true);
|
||||
if (lump > 0)
|
||||
{
|
||||
textscreen->mText = fileSystem.ReadFile(lump).GetString();
|
||||
textscreen->mText = GetStringFromLump(lump);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -754,7 +754,7 @@ static int FindGLNodesInWAD(int labellump)
|
|||
if (fileSystem.GetFileContainer(lump)==wadfile)
|
||||
{
|
||||
FileData mem = fileSystem.ReadFile(lump);
|
||||
if (MatchHeader(fileSystem.GetFileFullName(labellump), mem.GetString())) return lump;
|
||||
if (MatchHeader(fileSystem.GetFileFullName(labellump), GetStringFromLump(lump))) return lump;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue