Beta Build 4!

New update!
This commit is contained in:
DavidSM64 2015-10-30 16:09:35 -05:00
parent 735ff9092a
commit a039ec8bbd
16 changed files with 4462 additions and 77 deletions

View file

@ -1,6 +1,6 @@
#include "Globals.h"
char versionText[34] = "BETA BUILD 3";
char versionText[34] = "BETA BUILD 4";
char fpsstr[34];
u8 currentMenu = 0;
@ -143,7 +143,7 @@ void hurtEntity(Entity* e, int damage, int dir, u32 hurtColor){
e->zombie.health -= damage;
if(e->zombie.health < 1){
addItemsToWorld(newItem(ITEM_FLESH,1),e->x+8, e->y+8, (rand()%2) + 1);
player.p.score += 50 * e->zombie.lvl;
player.p.score += 50 * (e->zombie.lvl + 1);
removeEntityFromList(e,e->level,&eManager);
trySpawn(3, currentLevel);
return;
@ -153,7 +153,7 @@ void hurtEntity(Entity* e, int damage, int dir, u32 hurtColor){
e->slime.health -= damage;
if(e->slime.health < 1){
addItemsToWorld(newItem(ITEM_SLIME,1),e->x+8, e->y+8, (rand()%2) + 1);
player.p.score += 25 * e->slime.lvl;
player.p.score += 25 * (e->slime.lvl + 1);
removeEntityFromList(e,e->level,&eManager);
trySpawn(3, currentLevel);
return;
@ -333,6 +333,8 @@ bool tileIsSolid(int tile, Entity * e){
return true;
case TILE_WATER:
if(e != NULL && !e->canSwim) return true;
case TILE_HOLE:
if(e != NULL && e->type != ENTITY_PLAYER) return true;
}
return false;
}

View file

@ -3,6 +3,10 @@
#include "SaveLoad.h"
#include "Input.h"
#include "icons2_png.h"
#include "Font_png.h"
#include "bottombg_png.h"
#define CIRCLEPAD 0xF0000000
#define CSTICK 0x0F000000
@ -18,6 +22,8 @@
#define MENU_LOSE 9
#define MENU_PAUSED 10
#define MENU_LOADGAME 11
#define MENU_SETTINGS_REBIND 12
#define MENU_SETTINGS_TP 13
#define TILE_NULL 255
#define TILE_GRASS 0
@ -43,19 +49,27 @@
#define TILE_CLOUDCACTUS 20
#define TILE_HOLE 21
#define SWAP_UINT32(x) (((x) >> 24) | (((x) & 0x00FF0000) >> 8) | (((x) & 0x0000FF00) << 8) | ((x) << 24))
bool screenShot;
int loadedtp;
extern char versionText[34];
Entity player;
bool shouldRenderDebug;
sf2d_texture *icons;
sf2d_texture *font;
sf2d_texture *bottombg;
sf2d_texture * minimap[5];
u8 map[5][128*128];
u8 data[5][128*128];
u8 treeTable[256];
u16 rockTable[256];
u16 grassTable[16];
int dirtColor[5];
u32 dirtColor[5];
char currentFileName[256];
extern u8 currentMenu;
extern char fpsstr[];

View file

@ -3,6 +3,7 @@
char options[][12] = {"Start Game", "How To Play","Settings", "About", "Exit"};
char pOptions[][24] = {"Return to game", "Save Progress", "Exit to title"};
char keybOptions[][24] = {"Exit and Save", "Exit and Don't save","Reset to default"};
char setOptions[][24] = {"Rebind Buttons", "Texture packs", "Debug Text: ", "Return to title"};
// Rebind buttons menu (Settings)
int keys[] = {
@ -33,10 +34,16 @@ bool isTouching = false;
int touchX = 0, touchY = 0, touchW = 0, touchH = 0;
s8 errorFileName = 0;
// Load Texturepacks Menu
char tpFileNames[1000][256];
char tpFileComment[1000][60];
s16 tpFileCount = 0;
s8 isLoadingTP = 0;
s16 pauseSaveDisplayTimer = 0;
void readFiles(){
memset(&fileNames, 0, 256000); // reset fileNames
memset(&fileNames, 0, sizeof(fileNames)); // reset fileNames
worldFileCount = 0;
DIR * d;
struct dirent * dir;
@ -56,6 +63,35 @@ void readFiles(){
}
}
void readTPFiles(){
memset(&tpFileNames, 0, sizeof(tpFileNames)); // reset tp fileNames
memset(&tpFileComment, 0, sizeof(tpFileComment)); // reset zip comments
tpFileCount = 1; // 0 = default.
DIR * d;
struct dirent * dir;
d = opendir("./texturepacks/");
if (d){
while ((dir = readdir(d)) != NULL) {
if (strstr(dir->d_name, ".zip") != NULL) { // Check if filename contains ".zip"
strncpy(tpFileNames[tpFileCount], dir->d_name, strlen(dir->d_name)-4);
char fullDirName[256];
sprintf(fullDirName,"./texturepacks/%s",dir->d_name);
//int err =
getTexturePackComment(fullDirName, tpFileComment[tpFileCount]);
/*
if(err > 0){
char errorText[10];
sprintf(errorText,"err:%d",err);
strncpy(tpFileComment[tpFileCount], errorText, strlen(errorText));
}*/
++tpFileCount;
}
}
closedir(d);
}
}
s8 checkFileNameForErrors(){
int length = strlen(fileNames[worldFileCount]);
if(length < 1)return 1; // Error: Length cannot be 0.
@ -236,7 +272,7 @@ s8 checkPropButtons(){
Item median;
void tickMenu(int menu){
switch(menu){
case MENU_SETTINGS:
case MENU_SETTINGS_REBIND:
if(!bindOpt){
if(!selBut){
if (k_up.clicked){ --currentSelection; if(currentSelection < 0)currentSelection=21;}
@ -281,17 +317,17 @@ void tickMenu(int menu){
k_delete.input = keyProp[9];
FILE *fs=fopen("btnSave.bin","wb");
fwrite(keyProp,sizeof(int),9,fs);
fwrite(keyProp,sizeof(int),10,fs);
fclose(fs);
currentSelection = 2;
currentMenu = MENU_TITLE;
currentSelection = 0;
currentMenu = MENU_SETTINGS;
errorBut = -1;
} else errorBut = checkPropButtons();
break;
case 1: // Exit and DON'T save
currentSelection = 2;
currentMenu = MENU_TITLE;
currentSelection = 0;
currentMenu = MENU_SETTINGS;
errorBut = -1;
break;
case 2: // reset defaults
@ -391,6 +427,7 @@ void tickMenu(int menu){
case MENU_WIN:
if (k_accept.clicked){
sf2d_set_clear_color(0xFF);
currentSelection = 0;
currentMenu = MENU_TITLE;
saveCurrentWorld(currentFileName, &eManager, &player, (u8*)map, (u8*)data);
}
@ -398,6 +435,7 @@ void tickMenu(int menu){
case MENU_LOSE:
if (k_accept.clicked){
sf2d_set_clear_color(0xFF);
currentSelection = 0;
currentMenu = MENU_TITLE;
}
break;
@ -506,7 +544,82 @@ void tickMenu(int menu){
if(touchDelay > 0) --touchDelay;
}
break;
case MENU_SETTINGS_TP:
if (k_up.clicked){ --currentSelection; if(currentSelection < 0)currentSelection = tpFileCount-1;}
if (k_down.clicked){ ++currentSelection; if(currentSelection > tpFileCount-1)currentSelection=0;}
if (k_decline.clicked){
if(isLoadingTP < 1){
currentMenu = MENU_SETTINGS;
currentSelection = 1;
}
}
if (k_accept.clicked){
if(currentSelection > 0){
isLoadingTP = 4;
} else {
icons = sfil_load_PNG_buffer(icons2_png, SF2D_PLACE_RAM);
dirtColor[0] = SWAP_UINT32(sf2d_get_pixel(icons, 16, 0));
dirtColor[1] = SWAP_UINT32(sf2d_get_pixel(icons, 16, 1));
dirtColor[2] = SWAP_UINT32(sf2d_get_pixel(icons, 16, 2));
dirtColor[3] = SWAP_UINT32(sf2d_get_pixel(icons, 16, 3));
dirtColor[4] = SWAP_UINT32(sf2d_get_pixel(icons, 16, 4));
font = sfil_load_PNG_buffer(Font_png, SF2D_PLACE_RAM);
bottombg = sfil_load_PNG_buffer(bottombg_png, SF2D_PLACE_RAM);
currentMenu = MENU_SETTINGS;
currentSelection = 1;
remove("lastTP.bin");
}
}
break;
case MENU_SETTINGS:
if (k_up.clicked){ --currentSelection; if(currentSelection < 0)currentSelection=3;}
if (k_down.clicked){ ++currentSelection; if(currentSelection > 3)currentSelection=0;}
if(k_decline.clicked){
currentMenu = MENU_TITLE;
currentSelection = 2;
}
if(k_accept.clicked){
switch(currentSelection){
case 0:
keyProp[0] = k_up.input;
keyProp[1] = k_down.input;
keyProp[2] = k_left.input;
keyProp[3] = k_right.input;
keyProp[4] = k_attack.input;
keyProp[5] = k_menu.input;
keyProp[6] = k_pause.input;
keyProp[7] = k_accept.input;
keyProp[8] = k_decline.input;
keyProp[9] = k_delete.input;
left = true;
selBut = false;
bindOpt = false;
currentSelection = 0;
currentMenu = MENU_SETTINGS_REBIND;
break;
case 1:
readTPFiles();
currentMenu = MENU_SETTINGS_TP;
currentSelection = 0;
break;
case 2:
shouldRenderDebug = !shouldRenderDebug; // toggle option
break;
case 3:
if(true){
FILE * fset = fopen("settings.bin","wb");
fwrite(&shouldRenderDebug,sizeof(bool),1,fset);
fclose(fset);
}
currentMenu = MENU_TITLE;
currentSelection = 2;
break;
}
}
break;
case MENU_TITLE:
if (k_up.clicked){ --currentSelection; if(currentSelection < 0)currentSelection=4;}
if (k_down.clicked){ ++currentSelection; if(currentSelection > 4)currentSelection=0;}
@ -521,19 +634,6 @@ void tickMenu(int menu){
areYouSure = false;
break;
case 2:
keyProp[0] = k_up.input;
keyProp[1] = k_down.input;
keyProp[2] = k_left.input;
keyProp[3] = k_right.input;
keyProp[4] = k_attack.input;
keyProp[5] = k_menu.input;
keyProp[6] = k_pause.input;
keyProp[7] = k_accept.input;
keyProp[8] = k_decline.input;
keyProp[9] = k_delete.input;
left = true;
selBut = false;
bindOpt = false;
currentSelection = 0;
currentMenu = MENU_SETTINGS;
break;
@ -586,6 +686,61 @@ char guiText4[] = " SPACE BACKSPACE";
void renderMenu(int menu,int xscr,int yscr){
int i = 0;
switch(menu){
case MENU_SETTINGS_TP:
offsetX = 0;offsetY = (currentSelection * 40) - 48;
sf2d_start_frame(GFX_TOP, GFX_LEFT);
drawText("Texture Packs",122,-16);
for(i = 0; i < tpFileCount; ++i){
int color = 0x323292FF;
char * text = tpFileNames[i];
char * cmtText = tpFileComment[i];
if(i == 0){
text = "Default";
cmtText = "Regular look of the game";
color = 0x601092FF;
}
if(i != currentSelection) color &= 0xFFFFFF7F; // Darken color.
else if(areYouSure)color = 0xDF1010FF;
renderFrame(1,i*5,24,(i*5)+5,color);
drawText(text,(400-(strlen(text)*12))/2,i*80+16);
if(strlen(cmtText) > 29){
char cmtTxt1[30],cmtTxt2[30];
strncpy(cmtTxt1, cmtText, 29);
strncpy(cmtTxt2, cmtText + 29, strlen(cmtText)-29);
drawTextColor(cmtTxt1,(400-(strlen(cmtTxt1)*12))/2,i*80+36,0xAFAFAFFF);
drawTextColor(cmtTxt2,(400-(strlen(cmtTxt2)*12))/2,i*80+50,0xAFAFAFFF);
} else {
drawTextColor(cmtText,(400-(strlen(cmtText)*12))/2,i*80+43,0xAFAFAFFF);
}
}
offsetX = 0;offsetY = 0;
if(isLoadingTP > 0){
--isLoadingTP;
renderFrame(1,5,24,9,0x666666FF);
drawTextColor("Loading Texture pack...",(400-(23*12))/2,108,0xFFFF10FF);
if(isLoadingTP == 0){
char fullDirName[256];
sprintf(fullDirName,"texturepacks/%s.zip",tpFileNames[currentSelection]);
loadedtp = loadTexturePack(fullDirName);
FILE * fs=fopen("lastTP.bin","w");
fprintf(fs,"%s", fullDirName);
fclose(fs);
currentMenu = MENU_SETTINGS;
currentSelection = 1;
}
}
sf2d_end_frame();
sf2d_start_frame(GFX_BOTTOM, GFX_LEFT);
drawText("Press to select", 58, 100);
renderButtonIcon(k_accept.input & -k_accept.input, 128, 98, 1);
drawText("Press to return", 58, 150);
renderButtonIcon(k_decline.input & -k_decline.input, 128, 148, 1);
sf2d_end_frame();
break;
case MENU_LOADGAME:
sf2d_start_frame(GFX_TOP, GFX_LEFT);
if(!enteringName){ // World select
@ -674,7 +829,7 @@ void renderMenu(int menu,int xscr,int yscr){
sf2d_end_frame();
break;
case MENU_SETTINGS:
case MENU_SETTINGS_REBIND:
sf2d_start_frame(GFX_TOP, GFX_LEFT);
drawTextColor("Rebind Buttons",116,12,0xAFAF00FF);
drawText("Button",16,32);
@ -923,6 +1078,41 @@ void renderMenu(int menu,int xscr,int yscr){
renderButtonIcon(k_decline.input & -k_decline.input, 128, 218, 1);
sf2d_end_frame();
break;
case MENU_SETTINGS:
sf2d_start_frame(GFX_TOP, GFX_LEFT);
drawText("Settings",(400-(8*12))/2,40);
for(i = 3; i >= 0; --i){
char* msg = setOptions[i];
u32 color = 0x7F7F7FFF;
if(i == currentSelection) color = 0xFFFFFFFF;
if(i == 2){
if(shouldRenderDebug) drawSizedTextColor("On",142, ((8 + i) * 32 - 170) >> 1,2.0, 0x00DF00FF);
else drawSizedTextColor("Off",142, ((8 + i) * 32 - 170) >> 1,2.0, 0xDF0000FF);
}
drawSizedTextColor(msg,(200 - (strlen(msg) * 8))/2, ((8 + i) * 32 - 170) >> 1,2.0, color);
}
sf2d_end_frame();
sf2d_start_frame(GFX_BOTTOM, GFX_LEFT);
switch(currentSelection){
case 0:
drawTextColor("Change the controls",(320 - (19 * 12))/2,24,0xFFFF7FFF);
break;
case 1:
drawTextColor("Change the game's art",(320 - (21 * 12))/2,24,0xFFFF7FFF);
break;
case 2:
drawTextColor("Show FPS/Pos/Entities",(320 - (22 * 12))/2,24,0xFFFF7FFF);
break;
case 3:
drawTextColor("Back to the titlescreen",(320 - (23 * 12))/2,24,0xFFFF7FFF);
break;
}
drawText("Press to select", 58, 100);
renderButtonIcon(k_accept.input & -k_accept.input, 128, 98, 1);
drawText("Press to return", 58, 150);
renderButtonIcon(k_decline.input & -k_decline.input, 128, 148, 1);
sf2d_end_frame();
break;
case MENU_TITLE:
/* Top Screen */
sf2d_start_frame(GFX_TOP, GFX_LEFT);
@ -934,7 +1124,7 @@ void renderMenu(int menu,int xscr,int yscr){
if(i == currentSelection) color = 0xFFFFFFFF;
drawSizedTextColor(msg,(200 - (strlen(msg) * 8))/2, ((8 + i) * 20 - 50) >> 1,2.0, color);
}
drawText(versionText,2,225);
sf2d_end_frame();

View file

@ -7,6 +7,7 @@
#include <ctype.h>
#include "Render.h"
#include "texturepack.h"
void renderMenu(int menu,int xscr,int yscr);
void tickMenu(int menu);

View file

@ -414,17 +414,27 @@ void renderLightsToStencil() {
GPU_STENCIL_KEEP);
GPU_SetAlphaTest(true, GPU_GREATER, 0);
renderLight(player.x, player.y, playerLightBake);
if(player.p.activeItem->id == ITEM_LANTERN) renderLight(player.x, player.y, lanternLightBake);
else renderLight(player.x, player.y, playerLightBake);
int i;
for (i = 0; i < eManager.lastSlot[currentLevel]; ++i) {
Entity e = eManager.entities[currentLevel][i];
if (e.type != ENTITY_FURNITURE)
continue;
if (e.entityFurniture.itemID == ITEM_LANTERN && e.x > player.x - 160
&& e.y > player.y - 125 && e.x < player.x + 160
&& e.y < player.y + 125)
renderLight(e.x, e.y, lanternLightBake);
if (e.type != ENTITY_FURNITURE)continue;
if (e.entityFurniture.itemID == ITEM_LANTERN && e.x > player.x - 160
&& e.y > player.y - 125 && e.x < player.x + 160 && e.y < player.y + 125)
renderLight(e.x, e.y, lanternLightBake);
}
int xo = offsetX >> 4;
int yo = offsetY >> 4;
int x, y;
for (x = xo; x <= 13 + xo; ++x) {
for (y = yo; y <= 8 + yo; ++y)
if(getTile(x, y) == TILE_LAVA) renderLight(x << 4, y << 4, playerLightBake);
}
GPU_SetDepthTestAndWriteMask(true, GPU_GEQUAL, GPU_WRITE_ALL);
GPU_SetStencilTest(true, GPU_EQUAL, 1, 0xFF, 0x0);
GPU_SetAlphaTest(false, GPU_ALWAYS, 0x00);
@ -470,8 +480,7 @@ void bakeLight(sf2d_texture* texture, int x, int y, int r) {
int xd = xx - x;
int dist = xd * xd + yd;
if (dist <= r * r)
if ((dist >= (r - (r / 6)) * (r - (r / 5))) ?
rand() % 3 != 0 : true)
if ((dist >= (r - (r / 6)) * (r - (r / 5))) ? rand() % 4 != 0 : true)
sf2d_set_pixel(texture, xx, yy, RGBA8(0, 0, 0, 255)); // set transparent pixel
}
}
@ -628,18 +637,26 @@ void renderTile(int i, int x, int y) {
}
char scoreT[32];
void renderGui() {
//renderFrame(0,0,11,3,0x201092FF);
//renderFrame(11,0,20,3,0x201092FF);
int i;
for (i = 0; i < 10; ++i) {
if (i < player.p.health)
render(i * 8 + 1, 1, 168, 152, 0);
render(i * 8 + 6, 5, 168, 152, 0);
else
render(i * 8 + 1, 1, 176, 152, 0);
render(i * 8 + 6, 5, 176, 152, 0);
if (i < player.p.stamina)
render(i * 8 + 1, 10, 184, 152, 0);
render(i * 8 + 6, 14, 184, 152, 0);
else
render(i * 8 + 1, 10, 191, 152, 0);
render(i * 8 + 6, 14, 191, 152, 0);
}
sf2d_draw_texture(minimap[currentLevel], 96, 102);
renderItemWithTextCentered(player.p.activeItem, 320, 66);
itoa(player.p.score, scoreT, 10); // integer to base10 string
drawText("Score:",214,12);
drawText(scoreT,(140-(strlen(scoreT)*12))/2 + 180,29);
}
void renderPlayer() {
@ -1020,6 +1037,20 @@ void renderItemWithText(Item* item, int x, int y) {
y + 2, 0xD2D2D2FF, 0xFFFFFFFF);
}
/* For bottom screen */
void renderItemWithTextCentered(Item* item, int width, int y) {
char * tn = getItemName(item->id, item->countLevel);
int x = (width - ((strlen(tn) + 2) * 12))/2;
renderItemIcon(item->id, item->countLevel, x >> 1, y >> 1);
if (item->onlyOne)
drawText(getItemName(item->id, item->countLevel), x + 18, y + 2);
else
drawTextColorSpecial(getItemName(item->id, item->countLevel), x + 18,
y + 2, 0xD2D2D2FF, 0xFFFFFFFF);
}
void renderItemIcon2(int itemID, int countLevel, int x, int y, int z) {
switch (itemID) {
case ITEM_NULL:

View file

@ -7,8 +7,6 @@
#include "Globals.h"
#include "MapGen.h"
sf2d_texture *icons;
sf2d_texture *font;
sf2d_texture *playerLightBake;
sf2d_texture *lanternLightBake;
int offsetX, offsetY;
@ -58,6 +56,7 @@ void renderRecipes(RecipeManager * r, int xo, int yo, int x1, int y1,
void renderItemList(Inventory * inv, int xo, int yo, int x1, int y1,
int selected);
void renderItemWithText(Item* item, int x, int y);
void renderItemWithTextCentered(Item* item, int width, int y);
void renderItemIcon(int itemID, int countLevel, int x, int y);
void renderItemIcon2(int itemID, int countLevel, int x, int y, int z);

View file

@ -7,13 +7,11 @@
#include <stdlib.h>
#include <time.h>
#include "icons2_png.h"
#include "Font_png.h"
#include "Globals.h"
#include "Render.h"
#include "MapGen.h"
#include "Menu.h"
#include "texturepack.h"
void initMiniMap(bool loadUpWorld) {
int i, x, y;
@ -199,16 +197,14 @@ int main() {
sf2d_init();
csndInit();
noItem = newItem(ITEM_NULL, 0);
currentMenu = MENU_TITLE;
currentSelection = 0;
quitGame = false;
icons = sfil_load_PNG_buffer(icons2_png, SF2D_PLACE_RAM);
font = sfil_load_PNG_buffer(Font_png, SF2D_PLACE_RAM);
//consoleInit(GFX_BOTTOM, NULL);
// printf("Press 'Start' to exit.\n");
bottombg = sfil_load_PNG_buffer(bottombg_png, SF2D_PLACE_RAM);
loadSound(&snd_playerHurt, "resources/playerhurt.raw");
loadSound(&snd_playerDeath, "resources/playerdeath.raw");
@ -220,11 +216,6 @@ int main() {
bakeLights();
dirtColor[0] = 0xAD9291FF;
dirtColor[1] = 0x826D6CFF;
dirtColor[2] = 0x666666FF;
dirtColor[3] = 0x555555FF;
dirtColor[4] = 0x444444FF;
int i;
for (i = 0; i < 5; ++i) {
@ -232,6 +223,13 @@ int main() {
SF2D_PLACE_RAM);
sf2d_texture_tile32(minimap[i]);
}
dirtColor[0] = SWAP_UINT32(sf2d_get_pixel(icons, 16, 0));
dirtColor[1] = SWAP_UINT32(sf2d_get_pixel(icons, 16, 1));
dirtColor[2] = SWAP_UINT32(sf2d_get_pixel(icons, 16, 2));
dirtColor[3] = SWAP_UINT32(sf2d_get_pixel(icons, 16, 3));
dirtColor[4] = SWAP_UINT32(sf2d_get_pixel(icons, 16, 4));
sf2d_set_vblank_wait(true);
@ -264,8 +262,20 @@ int main() {
fread(&k_delete.input, sizeof(int), 1, file);
fclose(file);
}
//screenShot = false;
/* If lastTP exists, then use that. */
if ((file = fopen("lastTP.bin", "r"))) {
char fnbuf[256];
fgets(fnbuf, 256, file); // get directory to texturepack
loadTexturePack(fnbuf);
fclose(file);
}
shouldRenderDebug = true;
if ((file = fopen("settings.bin", "r"))) {
fread(&shouldRenderDebug,sizeof(bool),1,file);
fclose(file);
}
tickCount = 0;
initRecipes();
@ -275,29 +285,20 @@ int main() {
hidScanInput();
tickKeys(hidKeysHeld(), hidKeysDown());
//if (quitGame || hidKeysHeld() & KEY_SELECT) break;
if (quitGame)
break;
//if (hidKeysDown() & (KEY_L | KEY_R)) screenShot = true;
// else screenShot = false;
if (quitGame) break;
if (initGame > 0)
setupGame(initGame == 1 ? true : false);
if (initGame > 0) setupGame(initGame == 1 ? true : false);
if (currentMenu == 0) {
tick();
sprintf(fpsstr, " FPS: %.0f, X:%d, Y:%d, E:%d", sf2d_get_fps(),
player.x, player.y, eManager.lastSlot[currentLevel]);
sf2d_start_frame(GFX_TOP, GFX_LEFT);
if (currentLevel == 0) {
sf2d_draw_texture_part_scale(minimap[1], (-xscr / 3) - 256,
(-yscr / 3) - 32, 0, 0, 128, 128, 12.5, 7.5);
//sf2d_draw_rectangle(0, 0, 400, 240, 0xDFDFDFAF);
sf2d_draw_texture_part_scale(minimap[1], (-xscr / 3) - 256, (-yscr / 3) - 32, 0, 0, 128, 128, 12.5, 7.5);
sf2d_draw_rectangle(0, 0, 400, 240, 0xDFDFDFAF);
}
offsetX = xscr;
offsetY = yscr;
//if(currentLevel)
sf2d_draw_rectangle(0, 0, 400, 240, RGBA8(12, 12, 12, 255)); //You might think "real" black would be better, but it actually looks better that way
renderLightsToStencil();
@ -308,19 +309,16 @@ int main() {
resetStencilStuff();
offsetX = 0;
offsetY = 0;
renderItemWithText(player.p.activeItem, 10, 205);
// drawText(debugText,2,208);
drawText(fpsstr, 2, 225);
if(shouldRenderDebug){
sprintf(fpsstr, " FPS: %.0f, X:%d, Y:%d, E:%d", sf2d_get_fps(), player.x, player.y, eManager.lastSlot[currentLevel]);
drawText(fpsstr, 2, 225);
}
sf2d_end_frame();
sf2d_start_frame(GFX_BOTTOM, GFX_LEFT);
if (currentLevel == 0 && airWizardHealthDisplay > 0) {
sprintf(bossHealthText, "BOSS: %.0f%%",
((float) airWizardHealthDisplay / 2000.0) * 100);
drawText(bossHealthText, 2, 225);
}
sf2d_draw_texture(bottombg, 0, 0);
renderGui();
sf2d_draw_texture(minimap[currentLevel], 192, 112); //y:56
sf2d_end_frame();
} else {
tickMenu(currentMenu);

132
source/minizip/crypt.h Normal file
View file

@ -0,0 +1,132 @@
/* crypt.h -- base code for crypt/uncrypt ZIPfile
Version 1.01h, December 28th, 2009
Copyright (C) 1998-2009 Gilles Vollant
This code is a modified version of crypting code in Infozip distribution
The encryption/decryption parts of this source code (as opposed to the
non-echoing password parts) were originally written in Europe. The
whole source package can be freely distributed, including from the USA.
(Prior to January 2000, re-export from the US was a violation of US law.)
This encryption code is a direct transcription of the algorithm from
Roger Schlafly, described by Phil Katz in the file appnote.txt. This
file (appnote.txt) is distributed with the PKZIP program (even in the
version without encryption capabilities).
If you don't need crypting in your application, just define symbols
NOCRYPT and NOUNCRYPT.
This code support the "Traditional PKWARE Encryption".
The new AES encryption added on Zip format by Winzip (see the page
http://www.winzip.com/aes_info.htm ) and PKWare PKZip 5.x Strong
Encryption is not supported.
*/
#define CRC32(c, b) ((*(pcrc_32_tab+(((int)(c) ^ (b)) & 0xff))) ^ ((c) >> 8))
/***********************************************************************
* Return the next byte in the pseudo-random sequence
*/
static int decrypt_byte(unsigned long* pkeys, const unsigned long* pcrc_32_tab)
{
unsigned temp; /* POTENTIAL BUG: temp*(temp^1) may overflow in an
* unpredictable manner on 16-bit systems; not a problem
* with any known compiler so far, though */
temp = ((unsigned)(*(pkeys+2)) & 0xffff) | 2;
return (int)(((temp * (temp ^ 1)) >> 8) & 0xff);
}
/***********************************************************************
* Update the encryption keys with the next byte of plain text
*/
static int update_keys(unsigned long* pkeys,const unsigned long* pcrc_32_tab,int c)
{
(*(pkeys+0)) = CRC32((*(pkeys+0)), c);
(*(pkeys+1)) += (*(pkeys+0)) & 0xff;
(*(pkeys+1)) = (*(pkeys+1)) * 134775813L + 1;
{
register int keyshift = (int)((*(pkeys+1)) >> 24);
(*(pkeys+2)) = CRC32((*(pkeys+2)), keyshift);
}
return c;
}
/***********************************************************************
* Initialize the encryption keys and the random header according to
* the given password.
*/
static void init_keys(const char* passwd,unsigned long* pkeys,const unsigned long* pcrc_32_tab)
{
*(pkeys+0) = 305419896L;
*(pkeys+1) = 591751049L;
*(pkeys+2) = 878082192L;
while (*passwd != '\0') {
update_keys(pkeys,pcrc_32_tab,(int)*passwd);
passwd++;
}
}
#define zdecode(pkeys,pcrc_32_tab,c) \
(update_keys(pkeys,pcrc_32_tab,c ^= decrypt_byte(pkeys,pcrc_32_tab)))
#define zencode(pkeys,pcrc_32_tab,c,t) \
(t=decrypt_byte(pkeys,pcrc_32_tab), update_keys(pkeys,pcrc_32_tab,c), t^(c))
#ifdef INCLUDECRYPTINGCODE_IFCRYPTALLOWED
#define RAND_HEAD_LEN 12
/* "last resort" source for second part of crypt seed pattern */
# ifndef ZCR_SEED2
# define ZCR_SEED2 3141592654UL /* use PI as default pattern */
# endif
static int crypthead(passwd, buf, bufSize, pkeys, pcrc_32_tab, crcForCrypting)
const char *passwd; /* password string */
unsigned char *buf; /* where to write header */
int bufSize;
unsigned long* pkeys;
const unsigned long* pcrc_32_tab;
unsigned long crcForCrypting;
{
int n; /* index in random header */
int t; /* temporary */
int c; /* random byte */
unsigned char header[RAND_HEAD_LEN-2]; /* random header */
static unsigned calls = 0; /* ensure different random header each time */
if (bufSize<RAND_HEAD_LEN)
return 0;
/* First generate RAND_HEAD_LEN-2 random bytes. We encrypt the
* output of rand() to get less predictability, since rand() is
* often poorly implemented.
*/
if (++calls == 1)
{
srand((unsigned)(time(NULL) ^ ZCR_SEED2));
}
init_keys(passwd, pkeys, pcrc_32_tab);
for (n = 0; n < RAND_HEAD_LEN-2; n++)
{
c = (rand() >> 7) & 0xff;
header[n] = (unsigned char)zencode(pkeys, pcrc_32_tab, c, t);
}
/* Encrypt random header (last two bytes is high word of crc) */
init_keys(passwd, pkeys, pcrc_32_tab);
for (n = 0; n < RAND_HEAD_LEN-2; n++)
{
buf[n] = (unsigned char)zencode(pkeys, pcrc_32_tab, header[n], t);
}
buf[n++] = zencode(pkeys, pcrc_32_tab, (int)(crcForCrypting >> 16) & 0xff, t);
buf[n++] = zencode(pkeys, pcrc_32_tab, (int)(crcForCrypting >> 24) & 0xff, t);
return n;
}
#endif

178
source/minizip/ioapi.c Normal file
View file

@ -0,0 +1,178 @@
/* ioapi.c -- IO base function header for compress/uncompress .zip
files using zlib + zip or unzip API
Version 1.01h, December 28th, 2009
Copyright (C) 1998-2009 Gilles Vollant
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "zlib.h"
#include "ioapi.h"
/* I've found an old Unix (a SunOS 4.1.3_U1) without all SEEK_* defined.... */
#ifndef SEEK_CUR
#define SEEK_CUR 1
#endif
#ifndef SEEK_END
#define SEEK_END 2
#endif
#ifndef SEEK_SET
#define SEEK_SET 0
#endif
voidpf ZCALLBACK fopen_file_func OF((
voidpf opaque,
const char* filename,
int mode));
uLong ZCALLBACK fread_file_func OF((
voidpf opaque,
voidpf stream,
void* buf,
uLong size));
uLong ZCALLBACK fwrite_file_func OF((
voidpf opaque,
voidpf stream,
const void* buf,
uLong size));
long ZCALLBACK ftell_file_func OF((
voidpf opaque,
voidpf stream));
long ZCALLBACK fseek_file_func OF((
voidpf opaque,
voidpf stream,
uLong offset,
int origin));
int ZCALLBACK fclose_file_func OF((
voidpf opaque,
voidpf stream));
int ZCALLBACK ferror_file_func OF((
voidpf opaque,
voidpf stream));
voidpf ZCALLBACK fopen_file_func (opaque, filename, mode)
voidpf opaque;
const char* filename;
int mode;
{
FILE* file = NULL;
const char* mode_fopen = NULL;
if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ)
mode_fopen = "rb";
else
if (mode & ZLIB_FILEFUNC_MODE_EXISTING)
mode_fopen = "r+b";
else
if (mode & ZLIB_FILEFUNC_MODE_CREATE)
mode_fopen = "wb";
if ((filename!=NULL) && (mode_fopen != NULL))
file = fopen(filename, mode_fopen);
return file;
}
uLong ZCALLBACK fread_file_func (opaque, stream, buf, size)
voidpf opaque;
voidpf stream;
void* buf;
uLong size;
{
uLong ret;
ret = (uLong)fread(buf, 1, (size_t)size, (FILE *)stream);
return ret;
}
uLong ZCALLBACK fwrite_file_func (opaque, stream, buf, size)
voidpf opaque;
voidpf stream;
const void* buf;
uLong size;
{
uLong ret;
ret = (uLong)fwrite(buf, 1, (size_t)size, (FILE *)stream);
return ret;
}
long ZCALLBACK ftell_file_func (opaque, stream)
voidpf opaque;
voidpf stream;
{
long ret;
ret = ftell((FILE *)stream);
return ret;
}
long ZCALLBACK fseek_file_func (opaque, stream, offset, origin)
voidpf opaque;
voidpf stream;
uLong offset;
int origin;
{
int fseek_origin=0;
long ret;
switch (origin)
{
case ZLIB_FILEFUNC_SEEK_CUR :
fseek_origin = SEEK_CUR;
break;
case ZLIB_FILEFUNC_SEEK_END :
fseek_origin = SEEK_END;
break;
case ZLIB_FILEFUNC_SEEK_SET :
fseek_origin = SEEK_SET;
break;
default: return -1;
}
ret = 0;
if (fseek((FILE *)stream, offset, fseek_origin) != 0)
ret = -1;
return ret;
}
int ZCALLBACK fclose_file_func (opaque, stream)
voidpf opaque;
voidpf stream;
{
int ret;
ret = fclose((FILE *)stream);
return ret;
}
int ZCALLBACK ferror_file_func (opaque, stream)
voidpf opaque;
voidpf stream;
{
int ret;
ret = ferror((FILE *)stream);
return ret;
}
void fill_fopen_filefunc (pzlib_filefunc_def)
zlib_filefunc_def* pzlib_filefunc_def;
{
pzlib_filefunc_def->zopen_file = fopen_file_func;
pzlib_filefunc_def->zread_file = fread_file_func;
pzlib_filefunc_def->zwrite_file = fwrite_file_func;
pzlib_filefunc_def->ztell_file = ftell_file_func;
pzlib_filefunc_def->zseek_file = fseek_file_func;
pzlib_filefunc_def->zclose_file = fclose_file_func;
pzlib_filefunc_def->zerror_file = ferror_file_func;
pzlib_filefunc_def->opaque = NULL;
}

75
source/minizip/ioapi.h Normal file
View file

@ -0,0 +1,75 @@
/* ioapi.h -- IO base function header for compress/uncompress .zip
files using zlib + zip or unzip API
Version 1.01h, December 28th, 2009
Copyright (C) 1998-2009 Gilles Vollant
*/
#ifndef _ZLIBIOAPI_H
#define _ZLIBIOAPI_H
#define ZLIB_FILEFUNC_SEEK_CUR (1)
#define ZLIB_FILEFUNC_SEEK_END (2)
#define ZLIB_FILEFUNC_SEEK_SET (0)
#define ZLIB_FILEFUNC_MODE_READ (1)
#define ZLIB_FILEFUNC_MODE_WRITE (2)
#define ZLIB_FILEFUNC_MODE_READWRITEFILTER (3)
#define ZLIB_FILEFUNC_MODE_EXISTING (4)
#define ZLIB_FILEFUNC_MODE_CREATE (8)
#ifndef ZCALLBACK
#if (defined(WIN32) || defined (WINDOWS) || defined (_WINDOWS)) && defined(CALLBACK) && defined (USEWINDOWS_CALLBACK)
#define ZCALLBACK CALLBACK
#else
#define ZCALLBACK
#endif
#endif
#ifdef __cplusplus
extern "C" {
#endif
typedef voidpf (ZCALLBACK *open_file_func) OF((voidpf opaque, const char* filename, int mode));
typedef uLong (ZCALLBACK *read_file_func) OF((voidpf opaque, voidpf stream, void* buf, uLong size));
typedef uLong (ZCALLBACK *write_file_func) OF((voidpf opaque, voidpf stream, const void* buf, uLong size));
typedef long (ZCALLBACK *tell_file_func) OF((voidpf opaque, voidpf stream));
typedef long (ZCALLBACK *seek_file_func) OF((voidpf opaque, voidpf stream, uLong offset, int origin));
typedef int (ZCALLBACK *close_file_func) OF((voidpf opaque, voidpf stream));
typedef int (ZCALLBACK *testerror_file_func) OF((voidpf opaque, voidpf stream));
typedef struct zlib_filefunc_def_s
{
open_file_func zopen_file;
read_file_func zread_file;
write_file_func zwrite_file;
tell_file_func ztell_file;
seek_file_func zseek_file;
close_file_func zclose_file;
testerror_file_func zerror_file;
voidpf opaque;
} zlib_filefunc_def;
void fill_fopen_filefunc OF((zlib_filefunc_def* pzlib_filefunc_def));
#define ZREAD(filefunc,filestream,buf,size) ((*((filefunc).zread_file))((filefunc).opaque,filestream,buf,size))
#define ZWRITE(filefunc,filestream,buf,size) ((*((filefunc).zwrite_file))((filefunc).opaque,filestream,buf,size))
#define ZTELL(filefunc,filestream) ((*((filefunc).ztell_file))((filefunc).opaque,filestream))
#define ZSEEK(filefunc,filestream,pos,mode) ((*((filefunc).zseek_file))((filefunc).opaque,filestream,pos,mode))
#define ZCLOSE(filefunc,filestream) ((*((filefunc).zclose_file))((filefunc).opaque,filestream))
#define ZERROR(filefunc,filestream) ((*((filefunc).zerror_file))((filefunc).opaque,filestream))
#ifdef __cplusplus
}
#endif
#endif

1700
source/minizip/unzip.c Normal file

File diff suppressed because it is too large Load diff

360
source/minizip/unzip.h Normal file
View file

@ -0,0 +1,360 @@
/* unzip.h -- IO for uncompress .zip files using zlib
Version 1.01h, December 28th, 2009
Copyright (C) 1998-2009 Gilles Vollant
This unzip package allow extract file from .ZIP file, compatible with PKZip 2.04g
WinZip, InfoZip tools and compatible.
Multi volume ZipFile (span) are not supported.
Encryption compatible with pkzip 2.04g only supported
Old compressions used by old PKZip 1.x are not supported
I WAIT FEEDBACK at mail info@winimage.com
Visit also http://www.winimage.com/zLibDll/unzip.htm for evolution
Condition of use and distribution are the same than zlib :
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
/* for more info about .ZIP format, see
http://www.info-zip.org/pub/infozip/doc/appnote-981119-iz.zip
http://www.info-zip.org/pub/infozip/doc/
PkWare has also a specification at :
ftp://ftp.pkware.com/probdesc.zip
*/
#ifndef _unz_H
#define _unz_H
#ifdef __cplusplus
extern "C" {
#endif
#ifndef _ZLIB_H
#include "zlib.h"
#endif
#ifndef _ZLIBIOAPI_H
#include "ioapi.h"
#endif
#ifdef HAVE_BZIP2
#include "bzlib.h"
#endif
#define Z_BZIP2ED 12
#if defined(STRICTUNZIP) || defined(STRICTZIPUNZIP)
/* like the STRICT of WIN32, we define a pointer that cannot be converted
from (void*) without cast */
typedef struct TagunzFile__ { int unused; } unzFile__;
typedef unzFile__ *unzFile;
#else
typedef voidp unzFile;
#endif
#define UNZ_OK (0)
#define UNZ_END_OF_LIST_OF_FILE (-100)
#define UNZ_ERRNO (Z_ERRNO)
#define UNZ_EOF (0)
#define UNZ_PARAMERROR (-102)
#define UNZ_BADZIPFILE (-103)
#define UNZ_INTERNALERROR (-104)
#define UNZ_CRCERROR (-105)
/* tm_unz contain date/time info */
typedef struct tm_unz_s
{
uInt tm_sec; /* seconds after the minute - [0,59] */
uInt tm_min; /* minutes after the hour - [0,59] */
uInt tm_hour; /* hours since midnight - [0,23] */
uInt tm_mday; /* day of the month - [1,31] */
uInt tm_mon; /* months since January - [0,11] */
uInt tm_year; /* years - [1980..2044] */
} tm_unz;
/* unz_global_info structure contain global data about the ZIPfile
These data comes from the end of central dir */
typedef struct unz_global_info_s
{
uLong number_entry; /* total number of entries in
the central dir on this disk */
uLong size_comment; /* size of the global comment of the zipfile */
} unz_global_info;
/* unz_file_info contain information about a file in the zipfile */
typedef struct unz_file_info_s
{
uLong version; /* version made by 2 bytes */
uLong version_needed; /* version needed to extract 2 bytes */
uLong flag; /* general purpose bit flag 2 bytes */
uLong compression_method; /* compression method 2 bytes */
uLong dosDate; /* last mod file date in Dos fmt 4 bytes */
uLong crc; /* crc-32 4 bytes */
uLong compressed_size; /* compressed size 4 bytes */
uLong uncompressed_size; /* uncompressed size 4 bytes */
uLong size_filename; /* filename length 2 bytes */
uLong size_file_extra; /* extra field length 2 bytes */
uLong size_file_comment; /* file comment length 2 bytes */
uLong disk_num_start; /* disk number start 2 bytes */
uLong internal_fa; /* internal file attributes 2 bytes */
uLong external_fa; /* external file attributes 4 bytes */
tm_unz tmu_date;
} unz_file_info;
extern int ZEXPORT unzStringFileNameCompare OF ((const char* fileName1,
const char* fileName2,
int iCaseSensitivity));
/*
Compare two filename (fileName1,fileName2).
If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp)
If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi
or strcasecmp)
If iCaseSenisivity = 0, case sensitivity is defaut of your operating system
(like 1 on Unix, 2 on Windows)
*/
extern unzFile ZEXPORT unzOpen OF((const char *path));
/*
Open a Zip file. path contain the full pathname (by example,
on a Windows XP computer "c:\\zlib\\zlib113.zip" or on an Unix computer
"zlib/zlib113.zip".
If the zipfile cannot be opened (file don't exist or in not valid), the
return value is NULL.
Else, the return value is a unzFile Handle, usable with other function
of this unzip package.
*/
extern unzFile ZEXPORT unzOpen2 OF((const char *path,
zlib_filefunc_def* pzlib_filefunc_def));
/*
Open a Zip file, like unzOpen, but provide a set of file low level API
for read/write the zip file (see ioapi.h)
*/
extern int ZEXPORT unzClose OF((unzFile file));
/*
Close a ZipFile opened with unzipOpen.
If there is files inside the .Zip opened with unzOpenCurrentFile (see later),
these files MUST be closed with unzipCloseCurrentFile before call unzipClose.
return UNZ_OK if there is no problem. */
extern int ZEXPORT unzGetGlobalInfo OF((unzFile file,
unz_global_info *pglobal_info));
/*
Write info about the ZipFile in the *pglobal_info structure.
No preparation of the structure is needed
return UNZ_OK if there is no problem. */
extern int ZEXPORT unzGetGlobalComment OF((unzFile file,
char *szComment,
uLong uSizeBuf));
/*
Get the global comment string of the ZipFile, in the szComment buffer.
uSizeBuf is the size of the szComment buffer.
return the number of byte copied or an error code <0
*/
/***************************************************************************/
/* Unzip package allow you browse the directory of the zipfile */
extern int ZEXPORT unzGoToFirstFile OF((unzFile file));
/*
Set the current file of the zipfile to the first file.
return UNZ_OK if there is no problem
*/
extern int ZEXPORT unzGoToNextFile OF((unzFile file));
/*
Set the current file of the zipfile to the next file.
return UNZ_OK if there is no problem
return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest.
*/
extern int ZEXPORT unzLocateFile OF((unzFile file,
const char *szFileName,
int iCaseSensitivity));
/*
Try locate the file szFileName in the zipfile.
For the iCaseSensitivity signification, see unzStringFileNameCompare
return value :
UNZ_OK if the file is found. It becomes the current file.
UNZ_END_OF_LIST_OF_FILE if the file is not found
*/
/* ****************************************** */
/* Ryan supplied functions */
/* unz_file_info contain information about a file in the zipfile */
typedef struct unz_file_pos_s
{
uLong pos_in_zip_directory; /* offset in zip file directory */
uLong num_of_file; /* # of file */
} unz_file_pos;
extern int ZEXPORT unzGetFilePos(
unzFile file,
unz_file_pos* file_pos);
extern int ZEXPORT unzGoToFilePos(
unzFile file,
unz_file_pos* file_pos);
/* ****************************************** */
extern int ZEXPORT unzGetCurrentFileInfo OF((unzFile file,
unz_file_info *pfile_info,
char *szFileName,
uLong fileNameBufferSize,
void *extraField,
uLong extraFieldBufferSize,
char *szComment,
uLong commentBufferSize));
/*
Get Info about the current file
if pfile_info!=NULL, the *pfile_info structure will contain somes info about
the current file
if szFileName!=NULL, the filemane string will be copied in szFileName
(fileNameBufferSize is the size of the buffer)
if extraField!=NULL, the extra field information will be copied in extraField
(extraFieldBufferSize is the size of the buffer).
This is the Central-header version of the extra field
if szComment!=NULL, the comment string of the file will be copied in szComment
(commentBufferSize is the size of the buffer)
*/
/***************************************************************************/
/* for reading the content of the current zipfile, you can open it, read data
from it, and close it (you can close it before reading all the file)
*/
extern int ZEXPORT unzOpenCurrentFile OF((unzFile file));
/*
Open for reading data the current file in the zipfile.
If there is no error, the return value is UNZ_OK.
*/
extern int ZEXPORT unzOpenCurrentFilePassword OF((unzFile file,
const char* password));
/*
Open for reading data the current file in the zipfile.
password is a crypting password
If there is no error, the return value is UNZ_OK.
*/
extern int ZEXPORT unzOpenCurrentFile2 OF((unzFile file,
int* method,
int* level,
int raw));
/*
Same than unzOpenCurrentFile, but open for read raw the file (not uncompress)
if raw==1
*method will receive method of compression, *level will receive level of
compression
note : you can set level parameter as NULL (if you did not want known level,
but you CANNOT set method parameter as NULL
*/
extern int ZEXPORT unzOpenCurrentFile3 OF((unzFile file,
int* method,
int* level,
int raw,
const char* password));
/*
Same than unzOpenCurrentFile, but open for read raw the file (not uncompress)
if raw==1
*method will receive method of compression, *level will receive level of
compression
note : you can set level parameter as NULL (if you did not want known level,
but you CANNOT set method parameter as NULL
*/
extern int ZEXPORT unzCloseCurrentFile OF((unzFile file));
/*
Close the file in zip opened with unzOpenCurrentFile
Return UNZ_CRCERROR if all the file was read but the CRC is not good
*/
extern int ZEXPORT unzReadCurrentFile OF((unzFile file,
voidp buf,
unsigned len));
/*
Read bytes from the current file (opened by unzOpenCurrentFile)
buf contain buffer where data must be copied
len the size of buf.
return the number of byte copied if somes bytes are copied
return 0 if the end of file was reached
return <0 with error code if there is an error
(UNZ_ERRNO for IO error, or zLib error for uncompress error)
*/
extern z_off_t ZEXPORT unztell OF((unzFile file));
/*
Give the current position in uncompressed data
*/
extern int ZEXPORT unzeof OF((unzFile file));
/*
return 1 if the end of file was reached, 0 elsewhere
*/
extern int ZEXPORT unzGetLocalExtrafield OF((unzFile file,
voidp buf,
unsigned len));
/*
Read extra field from the current file (opened by unzOpenCurrentFile)
This is the local-header version of the extra field (sometimes, there is
more info in the local-header version than in the central-header)
if buf==NULL, it return the size of the local extra field
if buf!=NULL, len is the size of the buffer, the extra header is copied in
buf.
the return value is the number of bytes copied in buf, or (if <0)
the error code
*/
/***************************************************************************/
/* Get the current file offset */
extern uLong ZEXPORT unzGetOffset (unzFile file);
/* Set the current file offset */
extern int ZEXPORT unzSetOffset (unzFile file, uLong pos);
#ifdef __cplusplus
}
#endif
#endif /* _unz_H */

1263
source/minizip/zip.c Normal file

File diff suppressed because it is too large Load diff

257
source/minizip/zip.h Normal file
View file

@ -0,0 +1,257 @@
/* zip.h -- IO for compress .zip files using zlib
Version 1.01h, December 28th, 2009
Copyright (C) 1998-2009 Gilles Vollant
This unzip package allow creates .ZIP file, compatible with PKZip 2.04g
WinZip, InfoZip tools and compatible.
Multi volume ZipFile (span) are not supported.
Encryption compatible with pkzip 2.04g only supported
Old compressions used by old PKZip 1.x are not supported
For uncompress .zip file, look at unzip.h
I WAIT FEEDBACK at mail info@winimage.com
Visit also http://www.winimage.com/zLibDll/unzip.html for evolution
Condition of use and distribution are the same than zlib :
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
/* for more info about .ZIP format, see
http://www.info-zip.org/pub/infozip/doc/appnote-981119-iz.zip
http://www.info-zip.org/pub/infozip/doc/
PkWare has also a specification at :
ftp://ftp.pkware.com/probdesc.zip
*/
#ifndef _zip_H
#define _zip_H
#ifdef __cplusplus
extern "C" {
#endif
#ifndef _ZLIB_H
#include "zlib.h"
#endif
#ifndef _ZLIBIOAPI_H
#include "ioapi.h"
#endif
#if defined(STRICTZIP) || defined(STRICTZIPUNZIP)
/* like the STRICT of WIN32, we define a pointer that cannot be converted
from (void*) without cast */
typedef struct TagzipFile__ { int unused; } zipFile__;
typedef zipFile__ *zipFile;
#else
typedef voidp zipFile;
#endif
#define ZIP_OK (0)
#define ZIP_EOF (0)
#define ZIP_ERRNO (Z_ERRNO)
#define ZIP_PARAMERROR (-102)
#define ZIP_BADZIPFILE (-103)
#define ZIP_INTERNALERROR (-104)
#ifndef DEF_MEM_LEVEL
# if MAX_MEM_LEVEL >= 8
# define DEF_MEM_LEVEL 8
# else
# define DEF_MEM_LEVEL MAX_MEM_LEVEL
# endif
#endif
/* default memLevel */
/* tm_zip contain date/time info */
typedef struct tm_zip_s
{
uInt tm_sec; /* seconds after the minute - [0,59] */
uInt tm_min; /* minutes after the hour - [0,59] */
uInt tm_hour; /* hours since midnight - [0,23] */
uInt tm_mday; /* day of the month - [1,31] */
uInt tm_mon; /* months since January - [0,11] */
uInt tm_year; /* years - [1980..2044] */
} tm_zip;
typedef struct
{
tm_zip tmz_date; /* date in understandable format */
uLong dosDate; /* if dos_date == 0, tmu_date is used */
/* uLong flag; */ /* general purpose bit flag 2 bytes */
uLong internal_fa; /* internal file attributes 2 bytes */
uLong external_fa; /* external file attributes 4 bytes */
} zip_fileinfo;
typedef const char* zipcharpc;
#define APPEND_STATUS_CREATE (0)
#define APPEND_STATUS_CREATEAFTER (1)
#define APPEND_STATUS_ADDINZIP (2)
extern zipFile ZEXPORT zipOpen OF((const char *pathname, int append));
/*
Create a zipfile.
pathname contain on Windows XP a filename like "c:\\zlib\\zlib113.zip" or on
an Unix computer "zlib/zlib113.zip".
if the file pathname exist and append==APPEND_STATUS_CREATEAFTER, the zip
will be created at the end of the file.
(useful if the file contain a self extractor code)
if the file pathname exist and append==APPEND_STATUS_ADDINZIP, we will
add files in existing zip (be sure you don't add file that doesn't exist)
If the zipfile cannot be opened, the return value is NULL.
Else, the return value is a zipFile Handle, usable with other function
of this zip package.
*/
/* Note : there is no delete function into a zipfile.
If you want delete file into a zipfile, you must open a zipfile, and create another
Of couse, you can use RAW reading and writing to copy the file you did not want delte
*/
extern zipFile ZEXPORT zipOpen2 OF((const char *pathname,
int append,
zipcharpc* globalcomment,
zlib_filefunc_def* pzlib_filefunc_def));
extern int ZEXPORT zipOpenNewFileInZip OF((zipFile file,
const char* filename,
const zip_fileinfo* zipfi,
const void* extrafield_local,
uInt size_extrafield_local,
const void* extrafield_global,
uInt size_extrafield_global,
const char* comment,
int method,
int level));
/*
Open a file in the ZIP for writing.
filename : the filename in zip (if NULL, '-' without quote will be used
*zipfi contain supplemental information
if extrafield_local!=NULL and size_extrafield_local>0, extrafield_local
contains the extrafield data the the local header
if extrafield_global!=NULL and size_extrafield_global>0, extrafield_global
contains the extrafield data the the local header
if comment != NULL, comment contain the comment string
method contain the compression method (0 for store, Z_DEFLATED for deflate)
level contain the level of compression (can be Z_DEFAULT_COMPRESSION)
*/
extern int ZEXPORT zipOpenNewFileInZip2 OF((zipFile file,
const char* filename,
const zip_fileinfo* zipfi,
const void* extrafield_local,
uInt size_extrafield_local,
const void* extrafield_global,
uInt size_extrafield_global,
const char* comment,
int method,
int level,
int raw));
/*
Same than zipOpenNewFileInZip, except if raw=1, we write raw file
*/
extern int ZEXPORT zipOpenNewFileInZip3 OF((zipFile file,
const char* filename,
const zip_fileinfo* zipfi,
const void* extrafield_local,
uInt size_extrafield_local,
const void* extrafield_global,
uInt size_extrafield_global,
const char* comment,
int method,
int level,
int raw,
int windowBits,
int memLevel,
int strategy,
const char* password,
uLong crcForCrypting));
/*
Same than zipOpenNewFileInZip2, except
windowBits,memLevel,,strategy : see parameter strategy in deflateInit2
password : crypting password (NULL for no crypting)
crcForCtypting : crc of file to compress (needed for crypting)
*/
extern int ZEXPORT zipOpenNewFileInZip4 OF((zipFile file,
const char* filename,
const zip_fileinfo* zipfi,
const void* extrafield_local,
uInt size_extrafield_local,
const void* extrafield_global,
uInt size_extrafield_global,
const char* comment,
int method,
int level,
int raw,
int windowBits,
int memLevel,
int strategy,
const char* password,
uLong crcForCrypting,
uLong versionMadeBy,
uLong flagBase));
/*
Same than zipOpenNewFileInZip4, except
versionMadeBy : value for Version made by field
flag : value for flag field (compression level info will be added)
*/
extern int ZEXPORT zipWriteInFileInZip OF((zipFile file,
const void* buf,
unsigned len));
/*
Write data in the zipfile
*/
extern int ZEXPORT zipCloseFileInZip OF((zipFile file));
/*
Close the current file in the zipfile
*/
extern int ZEXPORT zipCloseFileInZipRaw OF((zipFile file,
uLong uncompressed_size,
uLong crc32));
/*
Close the current file in the zipfile, for fiel opened with
parameter raw=1 in zipOpenNewFileInZip2
uncompressed_size and crc32 are value for the uncompressed size
*/
extern int ZEXPORT zipClose OF((zipFile file,
const char* global_comment));
/*
Close the zipfile
*/
#ifdef __cplusplus
}
#endif
#endif /* _zip_H */

173
source/texturepack.c Normal file
View file

@ -0,0 +1,173 @@
#include "texturepack.h"
#define dir_delimter '/'
#define MAX_FILENAME 256
#define READ_SIZE 9216
void toLowerString(char * str){
int i;
for (i = 0; str[i] != '\0'; i++)str[i] = (char)tolower((unsigned char)str[i]);
}
int getTexturePackComment(char * filename, char * cmmtBuf){
// Open the zip file
unzFile *zipfile = unzOpen(filename);
if ( zipfile == NULL ) return 1; // Error: ZipFile could not be opened.
// Get info about the zip file
unz_global_info global_info;
if (unzGetGlobalInfo(zipfile, &global_info ) != UNZ_OK )
{
unzClose( zipfile );
return 2; // Error: Could not read global info
}
unzGetGlobalComment(zipfile, cmmtBuf, 58);
unzClose( zipfile );
return 0;
}
int loadTexturePack(char * filename){
bool useDefaultIcons = true;
bool useDefaultFont = true;
bool useDefaultBottom = true;
// Open the zip file
unzFile *zipfile = unzOpen(filename);
if ( zipfile == NULL ) return 1; // Error: ZipFile could not be opened.
// Get info about the zip file
unz_global_info global_info;
if (unzGetGlobalInfo(zipfile, &global_info ) != UNZ_OK )
{
unzClose( zipfile );
return 2; // Error: Could not read global info
}
// Buffer to hold data read from the zip file.
char read_buffer[ READ_SIZE ];
// Loop to extract all files
uLong i;
for ( i = 0; i < global_info.number_entry; ++i )
{
// Get info about current file.
unz_file_info file_info;
char filename[ MAX_FILENAME ];
if (unzGetCurrentFileInfo(zipfile,&file_info,filename,MAX_FILENAME,NULL, 0, NULL, 0 ) != UNZ_OK ){
unzClose( zipfile );
return 3; // Error: Could not read file info
}
// Check if this entry is NOT a directory or file.
const size_t filename_length = strlen( filename );
if ( filename[ filename_length-1 ] != dir_delimter ){
if ( unzOpenCurrentFile( zipfile ) != UNZ_OK )
{
unzClose( zipfile );
return 4;
}
// Open a file to write out the data.
FILE * out = fopen(filename, "wb" );
if ( out == NULL )
{
unzCloseCurrentFile( zipfile );
unzClose( zipfile );
return 5;
}
int error = UNZ_OK;
do
{
error = unzReadCurrentFile( zipfile, read_buffer, READ_SIZE );
if ( error < 0 )
{
//printf( "error %d\n", error );
unzCloseCurrentFile( zipfile );
unzClose( zipfile );
return 6;
}
// Write data to file.
if ( error > 0 )
{
fwrite( read_buffer, error, 1, out ); // You should check return of fwrite...
}
} while ( error > 0 );
fclose(out);
char lowerFilename[MAX_FILENAME];
strcpy(lowerFilename,filename);
toLowerString(lowerFilename);
if(strcmp(lowerFilename,"icons.png") == 0){
if(sfil_load_PNG_file(filename, SF2D_PLACE_RAM) == NULL){
unzCloseCurrentFile( zipfile );
unzClose( zipfile );
return 7;
}
icons = sfil_load_PNG_file(filename, SF2D_PLACE_RAM);
dirtColor[0] = SWAP_UINT32(sf2d_get_pixel(icons, 16, 0));
dirtColor[1] = SWAP_UINT32(sf2d_get_pixel(icons, 16, 1));
dirtColor[2] = SWAP_UINT32(sf2d_get_pixel(icons, 16, 2));
dirtColor[3] = SWAP_UINT32(sf2d_get_pixel(icons, 16, 3));
dirtColor[4] = SWAP_UINT32(sf2d_get_pixel(icons, 16, 4));
useDefaultIcons = false;
} else if(strcmp(lowerFilename,"font.png") == 0){
if(sfil_load_PNG_file(filename, SF2D_PLACE_RAM) == NULL){
unzCloseCurrentFile( zipfile );
unzClose( zipfile );
return 7;
}
font = sfil_load_PNG_file(filename, SF2D_PLACE_RAM);
useDefaultFont = false;
} else if(strcmp(lowerFilename,"bottombg.png") == 0){
if(sfil_load_PNG_file(filename, SF2D_PLACE_RAM) == NULL){
unzCloseCurrentFile( zipfile );
unzClose( zipfile );
return 7;
}
bottombg = sfil_load_PNG_file(filename, SF2D_PLACE_RAM);
useDefaultBottom = false;
}
remove(filename);
}
unzCloseCurrentFile( zipfile );
// Go the the next entry listed in the zip file.
if ( ( i+1 ) < global_info.number_entry )
{
if ( unzGoToNextFile( zipfile ) != UNZ_OK )
{
unzClose( zipfile );
return 7;
}
}
}
if(useDefaultIcons){
icons = sfil_load_PNG_buffer(icons2_png, SF2D_PLACE_RAM);
dirtColor[0] = SWAP_UINT32(sf2d_get_pixel(icons, 16, 0));
dirtColor[1] = SWAP_UINT32(sf2d_get_pixel(icons, 16, 1));
dirtColor[2] = SWAP_UINT32(sf2d_get_pixel(icons, 16, 2));
dirtColor[3] = SWAP_UINT32(sf2d_get_pixel(icons, 16, 3));
dirtColor[4] = SWAP_UINT32(sf2d_get_pixel(icons, 16, 4));
}
if(useDefaultFont) font = sfil_load_PNG_buffer(Font_png, SF2D_PLACE_RAM);
if(useDefaultBottom) bottombg = sfil_load_PNG_buffer(bottombg_png, SF2D_PLACE_RAM);
unzClose( zipfile );
return 0;
}

12
source/texturepack.h Normal file
View file

@ -0,0 +1,12 @@
#pragma once
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <sf2d.h>
#include <sfil.h>
#include "Globals.h"
#include "minizip/unzip.h"
int loadTexturePack(char * filename);
int getTexturePackComment(char * filename, char * cmmtBuf);