bool DwarfPointer::relocateToAddr(uintptr_t addr, uintptr_t originalBlockStart, uintptr_t originalBlockEnd) { if (!(encoding & 0x10)) // DW_EH_PE_pcrel; == cannot be used because pcrel can be combined with indirect... return false; if (originalLocation+getSigned() >= originalBlockStart && originalLocation+getSigned() < originalBlockEnd) return false; // nothing to change, it was inside of the EH block setSigned(getSigned() + (originalLocation - addr)); originalLocation = addr; return true; }
bool loadSpriteBank (int fileNum, spriteBank & loadhere, bool isFont) { int i, tex_num, total, picwidth, picheight, spriteBankVersion = 0, howmany=0, startIndex=0; int * totalwidth, * maxheight; int numTextures = 0; byte * data; setResourceForFatal (fileNum); if (! openFileFromNum (fileNum)) return fatal ("Can't open sprite bank / font"); loadhere.isFont = isFont; total = get2bytes (bigDataFile); if (! total) { spriteBankVersion = fgetc (bigDataFile); if (spriteBankVersion == 1) { total = 0; } else { total = get2bytes (bigDataFile); } } if (total <= 0) return fatal ("No sprites in bank or invalid sprite bank file"); if (spriteBankVersion > 3) return fatal ("Unsupported sprite bank file format"); loadhere.total = total; loadhere.sprites = new sprite [total]; if (! checkNew (loadhere.sprites)) return false; byte ** spriteData = new byte * [total]; if (! checkNew (spriteData)) return false; totalwidth = new int[total]; if (! checkNew (totalwidth)) return false; maxheight = new int[total]; if (! checkNew (maxheight)) return false; loadhere.myPalette.tex_names = new GLuint [total]; if (! checkNew (loadhere.myPalette.tex_names)) return false; if (isFont) { loadhere.myPalette.burnTex_names = new GLuint [total]; if (! checkNew (loadhere.myPalette.burnTex_names)) return false; } loadhere.myPalette.tex_w = new int [total]; if (! checkNew (loadhere.myPalette.tex_w)) return false; loadhere.myPalette.tex_h = new int [total]; if (! checkNew (loadhere.myPalette.tex_h)) return false; if (spriteBankVersion && spriteBankVersion < 3) { howmany = fgetc (bigDataFile); startIndex = 1; } totalwidth[0] = maxheight[0] = 1; for (i = 0; i < total; i ++) { switch (spriteBankVersion) { case 3: { loadhere.sprites[i].xhot = getSigned (bigDataFile); loadhere.sprites[i].yhot = getSigned (bigDataFile); png_structp png_ptr = png_create_read_struct (PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); if (!png_ptr) { return fatal ("Can't open sprite bank / font."); } png_infop info_ptr = png_create_info_struct(png_ptr); if (!info_ptr) { png_destroy_read_struct(&png_ptr, (png_infopp) NULL, (png_infopp) NULL); return fatal ("Can't open sprite bank / font."); } png_infop end_info = png_create_info_struct(png_ptr); if (!end_info) { png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp)NULL); return fatal ("Can't open sprite bank / font."); } png_init_io(png_ptr, bigDataFile); // Tell libpng which file to read png_set_sig_bytes(png_ptr, 8); // No sig png_read_info(png_ptr, info_ptr); png_uint_32 width, height; int bit_depth, color_type, interlace_type, compression_type, filter_method; png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, &interlace_type, &compression_type, &filter_method); int rowbytes = png_get_rowbytes(png_ptr, info_ptr); unsigned char * row_pointers[height]; spriteData[i] = new unsigned char [rowbytes*height]; if (! checkNew (spriteData[i])) return false; for (unsigned int row = 0; row<height; row++) row_pointers[row] = spriteData[i] + row*rowbytes; png_read_image(png_ptr, (png_byte **) row_pointers); png_read_end(png_ptr, NULL); png_destroy_read_struct(&png_ptr, &info_ptr, &end_info); picwidth = loadhere.sprites[i].width = width; picheight = loadhere.sprites[i].height = height; break; } case 2: picwidth = get2bytes (bigDataFile); picheight = get2bytes (bigDataFile); loadhere.sprites[i].xhot = getSigned (bigDataFile); loadhere.sprites[i].yhot = getSigned (bigDataFile); break; default: picwidth = (byte) fgetc (bigDataFile); picheight = (byte) fgetc (bigDataFile); loadhere.sprites[i].xhot = fgetc (bigDataFile); loadhere.sprites[i].yhot = fgetc (bigDataFile); break; } if (totalwidth[numTextures] + picwidth < 2047) { loadhere.sprites[i].tex_x = totalwidth[numTextures]; totalwidth[numTextures] += (loadhere.sprites[i].width = picwidth) + 1; if ((loadhere.sprites[i].height = picheight)+2 > maxheight[numTextures]) maxheight[numTextures] = picheight+2; } else { numTextures++; if (numTextures > 255) return fatal ("Can't open sprite bank / font - it's too big."); loadhere.sprites[i].tex_x = 0; totalwidth[numTextures] = (loadhere.sprites[i].width = picwidth); maxheight[numTextures] = loadhere.sprites[i].height = picheight; } loadhere.sprites[i].texNum = numTextures; if (spriteBankVersion < 3) { data = (byte *) new byte [picwidth * (picheight + 1)]; if (! checkNew (data)) return false; int ooo = picwidth * picheight; for (int tt = 0; tt < picwidth; tt ++) { data[ooo ++] = 0; } spriteData[i] = data; switch (spriteBankVersion) { case 2: // RUN LENGTH COMPRESSED DATA { unsigned size = picwidth * picheight; unsigned pip = 0; while (pip < size) { byte col = fgetc (bigDataFile); int looper; if (col > howmany) { col -= howmany + 1; looper = fgetc (bigDataFile) + 1; } else looper = 1; while (looper --) { data[pip ++] = col; } } } break; default: // RAW DATA size_t bytes_read = fread (data, picwidth, picheight, bigDataFile); if (bytes_read != picwidth * picheight && ferror (bigDataFile)) { debugOut("Reading error in loadSpriteBank.\n"); } break; } } } numTextures++; if (! spriteBankVersion) { howmany = fgetc (bigDataFile); startIndex = fgetc (bigDataFile); } if (spriteBankVersion < 3) { if (! reserveSpritePal (loadhere.myPalette, howmany + startIndex)) return false; for (i = 0; i < howmany; i ++) { loadhere.myPalette.r[i + startIndex] = (byte) fgetc (bigDataFile); loadhere.myPalette.g[i + startIndex] = (byte) fgetc (bigDataFile); loadhere.myPalette.b[i + startIndex] = (byte) fgetc (bigDataFile); loadhere.myPalette.pal[i + startIndex] = makeColour (loadhere.myPalette.r[i + startIndex], loadhere.myPalette.g[i + startIndex], loadhere.myPalette.b[i + startIndex]); } } loadhere.myPalette.originalRed = loadhere.myPalette.originalGreen = loadhere.myPalette.originalBlue = 255; loadhere.myPalette.numTextures = numTextures; GLubyte * tmp[numTextures]; GLubyte * tmp2[numTextures]; for (tex_num = 0; tex_num < numTextures; tex_num++) { if (! NPOT_textures) { totalwidth[tex_num] = getNextPOT(totalwidth[tex_num]); maxheight[tex_num] = getNextPOT(maxheight[tex_num]); } tmp[tex_num] = new GLubyte [(maxheight[tex_num]+1)*totalwidth[tex_num]*4]; if (! checkNew (tmp[tex_num])) return false; memset (tmp[tex_num], 0, maxheight[tex_num]*totalwidth[tex_num]*4); if (isFont) { tmp2[tex_num] = new GLubyte [(maxheight[tex_num]+1)*totalwidth[tex_num]*4]; if (! checkNew (tmp2[tex_num])) return false; memset (tmp2[tex_num], 0, maxheight[tex_num]*totalwidth[tex_num]*4); } loadhere.myPalette.tex_w[tex_num] = totalwidth[tex_num]; loadhere.myPalette.tex_h[tex_num] = maxheight[tex_num]; } int fromhere; unsigned char s; for (i = 0; i < total; i ++) { fromhere = 0; int transColour = -1; if (spriteBankVersion < 3) { int size = loadhere.sprites[i].height * loadhere.sprites[i].width; while (fromhere < size) { s = spriteData[i][fromhere++]; if (s) { transColour = s; break; } } fromhere = 0; } for (int y = 1; y < 1 + loadhere.sprites[i].height; y ++) { for (int x = loadhere.sprites[i].tex_x; x < loadhere.sprites[i].tex_x+loadhere.sprites[i].width; x ++) { GLubyte * target = tmp[loadhere.sprites[i].texNum] + 4*totalwidth[loadhere.sprites[i].texNum]*y + x*4; if (spriteBankVersion < 3) { s = spriteData[i][fromhere++]; if (s) { target[0] = (GLubyte) loadhere.myPalette.r[s]; target[1] = (GLubyte) loadhere.myPalette.g[s]; target[2] = (GLubyte) loadhere.myPalette.b[s]; target[3] = (GLubyte) 255; transColour = s; } else if (transColour >=0) { target[0] = (GLubyte) loadhere.myPalette.r[transColour]; target[1] = (GLubyte) loadhere.myPalette.g[transColour]; target[2] = (GLubyte) loadhere.myPalette.b[transColour]; target[3] = (GLubyte) 0; } if (isFont) { target = tmp2[loadhere.sprites[i].texNum] + 4*totalwidth[loadhere.sprites[i].texNum]*y + x*4; target[0] = (GLubyte) 255; target[1] = (GLubyte) 255; target[2] = (GLubyte) 255; if (s) target[3] = (GLubyte) loadhere.myPalette.r[s]; /*else target[3] = (GLubyte) 0;*/ } } else { target[0] = (GLubyte) spriteData[i][fromhere++]; target[1] = (GLubyte) spriteData[i][fromhere++]; target[2] = (GLubyte) spriteData[i][fromhere++]; target[3] = (GLubyte) spriteData[i][fromhere++]; } } } delete spriteData[i]; } delete spriteData; spriteData = NULL; glPixelStorei (GL_UNPACK_ALIGNMENT, 1); glGenTextures (numTextures, loadhere.myPalette.tex_names); if (isFont) glGenTextures (numTextures, loadhere.myPalette.burnTex_names); for (tex_num = 0; tex_num < numTextures; tex_num++) { glBindTexture (GL_TEXTURE_2D, loadhere.myPalette.tex_names[tex_num]); glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); if (gameSettings.antiAlias < 0) { glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); } else { glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); } texImage2D (GL_TEXTURE_2D, 0, GL_RGBA, totalwidth[tex_num], maxheight[tex_num], 0, GL_RGBA, GL_UNSIGNED_BYTE, tmp[tex_num], loadhere.myPalette.tex_names[tex_num]); delete tmp[tex_num]; tmp[tex_num] = NULL; if (isFont) { glBindTexture (GL_TEXTURE_2D, loadhere.myPalette.burnTex_names[tex_num]); glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); if (gameSettings.antiAlias < 0) { glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); } else { glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); } texImage2D (GL_TEXTURE_2D, 0, GL_RGBA, totalwidth[tex_num], maxheight[tex_num], 0, GL_RGBA, GL_UNSIGNED_BYTE, tmp2[tex_num], loadhere.myPalette.burnTex_names[tex_num]); delete tmp2[tex_num]; tmp2[tex_num] = NULL; } } finishAccess (); setResourceForFatal (-1); return true; }
bool loadSpriteBank (const char * filename, spriteBank *loadhere) { int i, total, picwidth, picheight, spriteBankVersion = 0, howmany, startIndex; int totalwidth[65535], maxheight[65535]; int numTextures = 0; // Open the file FILE * fp = fopen (filename, "rb"); if (fp == NULL) { return errorBox ("Can't open sprite bank", "The file can't be opened. I don't know why."); } total = get2bytes(fp); if (! total) { spriteBankVersion = fgetc(fp); if (spriteBankVersion == 1) { total = 0; } else { total = get2bytes(fp); } } if (spriteBankVersion > 3) return errorBox ("Error opening sprite bank", "Unsupported sprite bank file format"); if (total <= 0) return errorBox ("Error opening sprite bank", "No sprites in bank or invalid sprite bank file"); if (spriteBankVersion == 3) { loadhere->type = 2; loadhere->total = total; loadhere->sprites = new sprite [total]; for (int index = 0; index < total; index ++) { loadhere->sprites[index].xhot = getSigned (fp); loadhere->sprites[index].yhot = getSigned (fp); png_structp png_ptr = png_create_read_struct (PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); if (!png_ptr) { fclose (fp); return errorBox ("Can't open PNG file", "Error reading the file."); } png_infop info_ptr = png_create_info_struct(png_ptr); if (!info_ptr) { png_destroy_read_struct(&png_ptr, (png_infopp) NULL, (png_infopp) NULL); fclose (fp); return errorBox ("Can't open PNG file", "Error reading the file."); } png_infop end_info = png_create_info_struct(png_ptr); if (!end_info) { png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp)NULL); fclose (fp); return errorBox ("Can't open PNG file", "Error reading the file."); } png_init_io(png_ptr, fp); // Tell libpng which file to read png_set_sig_bytes(png_ptr, 8); // No sig png_read_info(png_ptr, info_ptr); png_uint_32 width, height; int bit_depth, color_type, interlace_type, compression_type, filter_method; png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, &interlace_type, &compression_type, &filter_method); int rowbytes = png_get_rowbytes(png_ptr, info_ptr); unsigned char * row_pointers[height]; unsigned char * data = new unsigned char [rowbytes*height]; for (int i = 0; i<height; i++) row_pointers[i] = data + i*rowbytes; png_read_image(png_ptr, (png_byte **) row_pointers); png_read_end(png_ptr, NULL); png_destroy_read_struct(&png_ptr, &info_ptr, &end_info); loadhere->sprites[index].data = data; loadhere->sprites[index].width = width; loadhere->sprites[index].height = height; } fclose(fp); return true; } loadhere->type = 0; loadhere->total = total; loadhere->sprites = new sprite [total]; //if (! checkNew (loadhere->sprites)) return false; if (spriteBankVersion) { howmany = fgetc(fp); startIndex = 1; } totalwidth[0] = maxheight[0] = 0; for (i = 0; i < total; i ++) { switch (spriteBankVersion) { case 2: picwidth = get2bytes(fp); picheight = get2bytes(fp); loadhere->sprites[i].xhot = getSigned (fp); loadhere->sprites[i].yhot = getSigned (fp); break; default: picwidth = (unsigned char) fgetc(fp); picheight = (unsigned char) fgetc(fp); loadhere->sprites[i].xhot = fgetc(fp); loadhere->sprites[i].yhot = fgetc(fp); break; } if (totalwidth[numTextures] + picwidth < 2048) { loadhere->sprites[i].tex_x = totalwidth[numTextures]; totalwidth[numTextures] += (loadhere->sprites[i].width = picwidth); if ((loadhere->sprites[i].height = picheight) > maxheight[numTextures]) maxheight[numTextures] = picheight; } else { numTextures++; if (numTextures > 65535) return false;//fatal ("Can't open sprite bank / font - it's too big."); loadhere->sprites[i].tex_x = 0; totalwidth[numTextures] = (loadhere->sprites[i].width = picwidth); maxheight[numTextures] = loadhere->sprites[i].height = picheight; } loadhere->sprites[i].texNum = numTextures; loadhere->sprites[i].data = (unsigned char *) new unsigned char [picwidth * (picheight + 1)]; //if (! checkNew (data)) return false; int ooo = picwidth * picheight; for (int tt = 0; tt < picwidth; tt ++) { loadhere->sprites[i].data[ooo ++] = 0; } switch (spriteBankVersion) { case 2: // RUN LENGTH COMPRESSED DATA { unsigned size = picwidth * picheight; unsigned pip = 0; while (pip < size) { unsigned char col = fgetc(fp); int looper; if (col > howmany) { col -= howmany + 1; looper = fgetc(fp) + 1; } else looper = 1; while (looper --) { loadhere->sprites[i].data[pip ++] = col; } } } break; default: // RAW DATA size_t bytes_read = fread (loadhere->sprites[i].data, picwidth, picheight, fp); if (bytes_read != picwidth * picheight && ferror (fp)) { fprintf(stderr, "Reading error in loadSpriteBank.\n"); } break; } } numTextures++; if (! spriteBankVersion) { howmany = fgetc(fp); startIndex = fgetc(fp); } if (! reserveSpritePal (&loadhere->myPalette, howmany + startIndex)) return false; for (i = 0; i < howmany; i ++) { loadhere->myPalette.r[i + startIndex] = (unsigned char) fgetc(fp); loadhere->myPalette.g[i + startIndex] = (unsigned char) fgetc(fp); loadhere->myPalette.b[i + startIndex] = (unsigned char) fgetc(fp); loadhere->myPalette.pal[i + startIndex] = makeColour (loadhere->myPalette.r[i + startIndex], loadhere->myPalette.g[i + startIndex], loadhere->myPalette.b[i + startIndex]); } fclose(fp); return true; }
void DwarfPointer::prepareForRelocation() { if (encoding != 0xff) // DW_EH_PE_omit setSigned(getSigned()); }
bool loadPeople (FILE * fp) { onScreenPerson * * pointy = & allPeople; onScreenPerson * me; scaleHorizon = getSigned (fp); scaleDivide = getSigned (fp); int countPeople = get2bytes (fp); int a; allPeople = NULL; for (a = 0; a < countPeople; a ++) { me = new onScreenPerson; if (! checkNew (me)) return false; me -> myPersona = new persona; if (! checkNew (me -> myPersona)) return false; me -> myAnim = new personaAnimation; if (! checkNew (me -> myAnim)) return false; me -> x = getFloat (fp); me -> y = getFloat (fp); loadCostume (me -> myPersona, fp); loadAnim (me -> myAnim, fp); me -> lastUsedAnim = fgetc (fp) ? me -> myAnim : NULL; me -> scale = getFloat (fp); me -> extra = get2bytes (fp); me -> height = get2bytes (fp); me -> walkToX = get2bytes (fp); me -> walkToY = get2bytes (fp); me -> thisStepX = get2bytes (fp); me -> thisStepY = get2bytes (fp); me -> frameNum = get2bytes (fp); me -> frameTick = get2bytes (fp); me -> walkSpeed = get2bytes (fp); me -> spinSpeed = get2bytes (fp); me -> floaty = getSigned (fp); me -> show = fgetc (fp); me -> walking = fgetc (fp); me -> spinning = fgetc (fp); if (fgetc (fp)) { me -> continueAfterWalking = loadFunction (fp); if (! me -> continueAfterWalking) return false; } else { me -> continueAfterWalking = NULL; } me -> direction = get2bytes(fp); me -> angle = get2bytes(fp); if (ssgVersion >= VERSION(2,0)) { me -> angleOffset = get2bytes(fp); } else { me -> angleOffset = 0; } me -> wantAngle = get2bytes(fp); me -> directionWhenDoneWalking = getSigned(fp); me -> inPoly = getSigned(fp); me -> walkToPoly = getSigned(fp); if (ssgVersion >= VERSION(2,0)) { me -> r = fgetc (fp); me -> g = fgetc (fp); me -> b = fgetc (fp); me -> colourmix = fgetc (fp); me -> transparency = fgetc (fp); } else { setMyDrawMode(me, get2bytes(fp)); } me -> thisType = loadObjectRef (fp); // Anti-aliasing settings if (ssgVersion >= VERSION(1,6)) { if (ssgVersion < VERSION (2,0)) { // aaLoad fgetc (fp); getFloat (fp); getFloat (fp); } } me -> next = NULL; * pointy = me; pointy = & (me -> next); } // db ("End of loadPeople"); return true; }