*Added Standard IOS option to global settings. This decides with what IOS the Loader is gonna boot next.

This commit is contained in:
dimok321 2009-05-03 18:53:31 +00:00
commit c152f5c3d4
141 changed files with 20322 additions and 0 deletions

150
Makefile Normal file
View File

@ -0,0 +1,150 @@
#---------------------------------------------------------------------------------
# Clear the implicit built in rules
#---------------------------------------------------------------------------------
.SUFFIXES:
#---------------------------------------------------------------------------------
ifeq ($(strip $(DEVKITPPC)),)
$(error "Please set DEVKITPPC in your environment. export DEVKITPPC=<path to>devkitPPC")
endif
include $(DEVKITPPC)/wii_rules
#---------------------------------------------------------------------------------
# TARGET is the name of the output
# BUILD is the directory where object files & intermediate files will be placed
# SOURCES is a list of directories containing source code
# INCLUDES is a list of directories containing extra header files
#---------------------------------------------------------------------------------
TARGET := boot
BUILD := build
SOURCES := source source/libwiigui source/images source/fonts source/sounds source/libwbfs
INCLUDES := source
#---------------------------------------------------------------------------------
# options for code generation
#---------------------------------------------------------------------------------
CFLAGS = -g -O2 -Wall $(MACHDEP) $(INCLUDE)
CXXFLAGS = -save-temps -Xassembler -aln=$@.lst $(CFLAGS)
LDFLAGS = -g $(MACHDEP) -Wl,-Map,$(notdir $@).map,--section-start,.init=0x80a00100
#---------------------------------------------------------------------------------
# any extra libraries we wish to link with the project
#---------------------------------------------------------------------------------
LIBS := -lfat -lpngu -lpng -lmetaphrasis -lm -lz -lwiiuse -lbte -lasnd -logc -ltremor -lfreetype
#---------------------------------------------------------------------------------
# list of directories containing libraries, this must be the top level containing
# include and lib
#---------------------------------------------------------------------------------
LIBDIRS := $(DEVKITPPC)/lib $(CURDIR)
#---------------------------------------------------------------------------------
# no real need to edit anything past this point unless you need to add additional
# rules for different file extensions
#---------------------------------------------------------------------------------
ifneq ($(BUILD),$(notdir $(CURDIR)))
#---------------------------------------------------------------------------------
export OUTPUT := $(CURDIR)/$(TARGETDIR)/$(TARGET)
export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
$(foreach dir,$(DATA),$(CURDIR)/$(dir))
export DEPSDIR := $(CURDIR)/$(BUILD)
#---------------------------------------------------------------------------------
# automatically build a list of object files for our project
#---------------------------------------------------------------------------------
CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
sFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.S)))
BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))
TTFFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.ttf)))
PNGFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.png)))
OGGFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.ogg)))
PCMFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.pcm)))
#---------------------------------------------------------------------------------
# use CXX for linking C++ projects, CC for standard C
#---------------------------------------------------------------------------------
ifeq ($(strip $(CPPFILES)),)
export LD := $(CC)
else
export LD := $(CXX)
endif
export OFILES := $(addsuffix .o,$(BINFILES)) \
$(CPPFILES:.cpp=.o) $(CFILES:.c=.o) \
$(sFILES:.s=.o) $(SFILES:.S=.o) \
$(TTFFILES:.ttf=.ttf.o) $(PNGFILES:.png=.png.o) \
$(OGGFILES:.ogg=.ogg.o) $(PCMFILES:.pcm=.pcm.o)
#---------------------------------------------------------------------------------
# build a list of include paths
#---------------------------------------------------------------------------------
export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
-I$(CURDIR)/$(BUILD) \
-I$(LIBOGC_INC)
#---------------------------------------------------------------------------------
# build a list of library paths
#---------------------------------------------------------------------------------
export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) \
-L$(LIBOGC_LIB)
export OUTPUT := $(CURDIR)/$(TARGET)
.PHONY: $(BUILD) clean
#---------------------------------------------------------------------------------
$(BUILD):
@[ -d $@ ] || mkdir -p $@
@make --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
#---------------------------------------------------------------------------------
clean:
@echo clean ...
@rm -fr $(BUILD) $(OUTPUT).elf $(OUTPUT).dol
#---------------------------------------------------------------------------------
run:
wiiload $(OUTPUT).dol
#---------------------------------------------------------------------------------
reload:
wiiload -r $(OUTPUT).dol
#---------------------------------------------------------------------------------
else
DEPENDS := $(OFILES:.o=.d)
#---------------------------------------------------------------------------------
# main targets
#---------------------------------------------------------------------------------
$(OUTPUT).dol: $(OUTPUT).elf
$(OUTPUT).elf: $(OFILES)
#---------------------------------------------------------------------------------
# This rule links in binary data with .ttf, .png, and .mp3 extensions
#---------------------------------------------------------------------------------
%.ttf.o : %.ttf
@echo $(notdir $<)
$(bin2o)
%.png.o : %.png
@echo $(notdir $<)
$(bin2o)
%.ogg.o : %.ogg
@echo $(notdir $<)
$(bin2o)
%.pcm.o : %.pcm
@echo $(notdir $<)
$(bin2o)
-include $(DEPENDS)
#---------------------------------------------------------------------------------
endif
#---------------------------------------------------------------------------------

1
gui.pnproj Normal file

File diff suppressed because one or more lines are too long

1
gui.pnps Normal file
View File

@ -0,0 +1 @@
<pd><ViewState><e p="gui" x="true"></e><e p="gui\source" x="true"></e><e p="gui\source\fonts" x="false"></e><e p="gui\source\images" x="false"></e><e p="gui\source\libwbfs" x="false"></e><e p="gui\source\libwiigui" x="true"></e><e p="gui\source\sounds" x="false"></e></ViewState></pd>

718
source/FreeTypeGX.cpp Normal file
View File

@ -0,0 +1,718 @@
/*
* FreeTypeGX is a wrapper class for libFreeType which renders a compiled
* FreeType parsable font into a GX texture for Wii homebrew development.
* Copyright (C) 2008 Armin Tamzarian
* Modified by Tantric, 2009
*
* This file is part of FreeTypeGX.
*
* FreeTypeGX is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* FreeTypeGX is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with FreeTypeGX. If not, see <http://www.gnu.org/licenses/>.
*/
#include "FreeTypeGX.h"
/**
* Default constructor for the FreeTypeGX class.
*
* @param textureFormat Optional format (GX_TF_*) of the texture as defined by the libogc gx.h header file. If not specified default value is GX_TF_RGBA8.
* @param vertexIndex Optional vertex format index (GX_VTXFMT*) of the glyph textures as defined by the libogc gx.h header file. If not specified default value is GX_VTXFMT1.
*/
FreeTypeGX::FreeTypeGX(uint8_t textureFormat, uint8_t vertexIndex) {
FT_Init_FreeType(&this->ftLibrary);
this->textureFormat = textureFormat;
this->setVertexFormat(vertexIndex);
this->setCompatibilityMode(FTGX_COMPATIBILITY_NONE);
}
/**
* Default destructor for the FreeTypeGX class.
*/
FreeTypeGX::~FreeTypeGX() {
this->unloadFont();
}
/**
* Convert a short char sctring to a wide char string.
*
* This routine converts a supplied shot character string into a wide character string.
* Note that it is the user's responsibility to clear the returned buffer once it is no longer needed.
*
* @param strChar Character string to be converted.
* @return Wide character representation of supplied character string.
*/
wchar_t* FreeTypeGX::charToWideChar(char* strChar) {
wchar_t *strWChar;
strWChar = new wchar_t[strlen(strChar) + 1];
char *tempSrc = strChar;
wchar_t *tempDest = strWChar;
while((*tempDest++ = *tempSrc++));
return strWChar;
}
/**
*
* \overload
*/
wchar_t* FreeTypeGX::charToWideChar(const char* strChar) {
return FreeTypeGX::charToWideChar((char*) strChar);
}
/**
* Setup the vertex attribute formats for the glyph textures.
*
* This function sets up the vertex format for the glyph texture on the specified vertex format index.
* Note that this function should not need to be called except if the vertex formats are cleared or the specified
* vertex format index is modified.
*
* @param vertexIndex Vertex format index (GX_VTXFMT*) of the glyph textures as defined by the libogc gx.h header file.
*/
void FreeTypeGX::setVertexFormat(uint8_t vertexIndex) {
this->vertexIndex = vertexIndex;
GX_SetVtxAttrFmt(this->vertexIndex, GX_VA_POS, GX_POS_XY, GX_S16, 0);
GX_SetVtxAttrFmt(this->vertexIndex, GX_VA_TEX0, GX_TEX_ST, GX_F32, 0);
GX_SetVtxAttrFmt(this->vertexIndex, GX_VA_CLR0, GX_CLR_RGBA, GX_RGBA8, 0);
}
/**
* Sets the TEV and VTX rendering compatibility requirements for the class.
*
* This sets up the default TEV opertion and VTX descriptions rendering values for the class. This ensures that FreeTypeGX
* can remain compatible with external liraries or project code. Certain external libraries or code by design or lack of
* foresight assume that the TEV opertion and VTX descriptions values will remain constant or are always returned to a
* certain value. This will enable compatibility with those libraries and any other code which cannot or will not be changed.
*
* @param compatibilityMode Compatibility descritor (FTGX_COMPATIBILITY_*) as defined in FreeTypeGX.h
*/
void FreeTypeGX::setCompatibilityMode(uint32_t compatibilityMode) {
this->compatibilityMode = compatibilityMode;
}
/**
* Sets the TEV operation and VTX descriptor values after texture rendering it complete.
*
* This function calls the GX_SetTevOp and GX_SetVtxDesc functions with the compatibility parameters specified
* in setCompatibilityMode.
*/
void FreeTypeGX::setDefaultMode() {
if(this->compatibilityMode) {
switch(this->compatibilityMode & 0x00FF) {
case FTGX_COMPATIBILITY_DEFAULT_TEVOP_GX_MODULATE:
GX_SetTevOp(GX_TEVSTAGE0, GX_MODULATE);
break;
case FTGX_COMPATIBILITY_DEFAULT_TEVOP_GX_DECAL:
GX_SetTevOp(GX_TEVSTAGE0, GX_DECAL);
break;
case FTGX_COMPATIBILITY_DEFAULT_TEVOP_GX_BLEND:
GX_SetTevOp(GX_TEVSTAGE0, GX_BLEND);
break;
case FTGX_COMPATIBILITY_DEFAULT_TEVOP_GX_REPLACE:
GX_SetTevOp(GX_TEVSTAGE0, GX_REPLACE);
break;
case FTGX_COMPATIBILITY_DEFAULT_TEVOP_GX_PASSCLR:
GX_SetTevOp(GX_TEVSTAGE0, GX_PASSCLR);
break;
default:
break;
}
switch(this->compatibilityMode & 0xFF00) {
case FTGX_COMPATIBILITY_DEFAULT_VTXDESC_GX_NONE:
GX_SetVtxDesc(GX_VA_TEX0, GX_NONE);
break;
case FTGX_COMPATIBILITY_DEFAULT_VTXDESC_GX_DIRECT:
GX_SetVtxDesc(GX_VA_TEX0, GX_DIRECT);
break;
case FTGX_COMPATIBILITY_DEFAULT_VTXDESC_GX_INDEX8:
GX_SetVtxDesc(GX_VA_TEX0, GX_INDEX8);
break;
case FTGX_COMPATIBILITY_DEFAULT_VTXDESC_GX_INDEX16:
GX_SetVtxDesc(GX_VA_TEX0, GX_INDEX16);
break;
default:
break;
}
}
}
/**
* Loads and processes a specified true type font buffer to a specific point size.
*
* This routine takes a precompiled true type font buffer and loads the necessary processed data into memory. This routine should be called before drawText will succeed.
*
* @param fontBuffer A pointer in memory to a precompiled true type font buffer.
* @param bufferSize Size of the true type font buffer in bytes.
* @param pointSize The desired point size this wrapper's configured font face.
* @param cacheAll Optional flag to specify if all font characters should be cached when the class object is created. If specified as false the characters only become cached the first time they are used. If not specified default value is false.
*/
uint16_t FreeTypeGX::loadFont(uint8_t* fontBuffer, FT_Long bufferSize, FT_UInt pointSize, bool cacheAll) {
this->unloadFont();
this->ftPointSize = pointSize;
FT_New_Memory_Face(this->ftLibrary, (FT_Byte *)fontBuffer, bufferSize, 0, &this->ftFace);
if(this->ftPointSize > 0)
FT_Set_Pixel_Sizes(this->ftFace, 0, this->ftPointSize);
this->ftSlot = this->ftFace->glyph;
this->ftKerningEnabled = FT_HAS_KERNING(this->ftFace);
if (cacheAll) {
return this->cacheGlyphDataComplete();
}
return 0;
}
/**
*
* \overload
*/
uint16_t FreeTypeGX::loadFont(const uint8_t* fontBuffer, FT_Long bufferSize, FT_UInt pointSize, bool cacheAll) {
return this->loadFont((uint8_t *)fontBuffer, bufferSize, pointSize, cacheAll);
}
/**
* Clears all loaded font glyph data.
*
* This routine clears all members of the font map structure and frees all allocated memory back to the system.
*/
void FreeTypeGX::unloadFont() {
if(this->fontData.size() == 0)
return;
GX_DrawDone();
GX_Flush();
for( std::map<wchar_t, ftgxCharData>::iterator i = this->fontData.begin(); i != this->fontData.end(); i++) {
free(i->second.glyphDataTexture);
}
this->fontData.clear();
}
void FreeTypeGX::changeSize(FT_UInt pointSize) {
this->unloadFont();
this->ftPointSize = pointSize;
FT_Set_Pixel_Sizes(this->ftFace, 0, this->ftPointSize);
}
/**
* Adjusts the texture data buffer to necessary width for a given texture format.
*
* This routine determines adjusts the given texture width into the required width to hold the necessary texture data for proper alignment.
*
* @param textureWidth The initial guess for the texture width.
* @param textureFormat The texture format to which the data is to be converted.
* @return The correctly adjusted texture width.
*/
uint16_t FreeTypeGX::adjustTextureWidth(uint16_t textureWidth, uint8_t textureFormat) {
uint16_t alignment;
switch(textureFormat) {
case GX_TF_I4: /* 8x8 Tiles - 4-bit Intensity */
case GX_TF_I8: /* 8x4 Tiles - 8-bit Intensity */
case GX_TF_IA4: /* 8x4 Tiles - 4-bit Intensity, , 4-bit Alpha */
alignment = 8;
break;
case GX_TF_IA8: /* 4x4 Tiles - 8-bit Intensity, 8-bit Alpha */
case GX_TF_RGB565: /* 4x4 Tiles - RGB565 Format */
case GX_TF_RGB5A3: /* 4x4 Tiles - RGB5A3 Format */
case GX_TF_RGBA8: /* 4x4 Tiles - RGBA8 Dual Cache Line Format */
default:
alignment = 4;
break;
}
return textureWidth % alignment == 0 ? textureWidth : alignment + textureWidth - (textureWidth % alignment);
}
/**
* Adjusts the texture data buffer to necessary height for a given texture format.
*
* This routine determines adjusts the given texture height into the required height to hold the necessary texture data for proper alignment.
*
* @param textureHeight The initial guess for the texture height.
* @param textureFormat The texture format to which the data is to be converted.
* @return The correctly adjusted texture height.
*/
uint16_t FreeTypeGX::adjustTextureHeight(uint16_t textureHeight, uint8_t textureFormat) {
uint16_t alignment;
switch(textureFormat) {
case GX_TF_I4: /* 8x8 Tiles - 4-bit Intensity */
alignment = 8;
break;
case GX_TF_I8: /* 8x4 Tiles - 8-bit Intensity */
case GX_TF_IA4: /* 8x4 Tiles - 4-bit Intensity, , 4-bit Alpha */
case GX_TF_IA8: /* 4x4 Tiles - 8-bit Intensity, 8-bit Alpha */
case GX_TF_RGB565: /* 4x4 Tiles - RGB565 Format */
case GX_TF_RGB5A3: /* 4x4 Tiles - RGB5A3 Format */
case GX_TF_RGBA8: /* 4x4 Tiles - RGBA8 Dual Cache Line Format */
default:
alignment = 4;
break;
}
return textureHeight % alignment == 0 ? textureHeight : alignment + textureHeight - (textureHeight % alignment);
}
/**
* Caches the given font glyph in the instance font texture buffer.
*
* This routine renders and stores the requested glyph's bitmap and relevant information into its own quickly addressible
* structure within an instance-specific map.
*
* @param charCode The requested glyph's character code.
* @return A pointer to the allocated font structure.
*/
ftgxCharData *FreeTypeGX::cacheGlyphData(wchar_t charCode) {
FT_UInt gIndex;
uint16_t textureWidth = 0, textureHeight = 0;
gIndex = FT_Get_Char_Index( this->ftFace, charCode );
if (!FT_Load_Glyph(this->ftFace, gIndex, FT_LOAD_DEFAULT )) {
FT_Render_Glyph( this->ftSlot, FT_RENDER_MODE_NORMAL );
if(this->ftSlot->format == FT_GLYPH_FORMAT_BITMAP) {
FT_Bitmap *glyphBitmap = &this->ftSlot->bitmap;
textureWidth = adjustTextureWidth(glyphBitmap->width, this->textureFormat);
textureHeight = adjustTextureHeight(glyphBitmap->rows, this->textureFormat);
this->fontData[charCode] = (ftgxCharData){
this->ftSlot->advance.x >> 6,
gIndex,
textureWidth,
textureHeight,
this->ftSlot->bitmap_top,
this->ftSlot->bitmap_top,
textureHeight - this->ftSlot->bitmap_top,
NULL
};
this->loadGlyphData(glyphBitmap, &this->fontData[charCode]);
return &this->fontData[charCode];
}
}
return NULL;
}
/**
* Locates each character in this wrapper's configured font face and proccess them.
*
* This routine locates each character in the configured font face and renders the glyph's bitmap.
* Each bitmap and relevant information is loaded into its own quickly addressible structure within an instance-specific map.
*/
uint16_t FreeTypeGX::cacheGlyphDataComplete() {
uint16_t i = 0;
FT_UInt gIndex;
FT_ULong charCode = FT_Get_First_Char( this->ftFace, &gIndex );
while ( gIndex != 0 ) {
if(this->cacheGlyphData(charCode) != NULL) {
i++;
}
charCode = FT_Get_Next_Char( this->ftFace, charCode, &gIndex );
}
return i;
}
/**
* Loads the rendered bitmap into the relevant structure's data buffer.
*
* This routine does a simple byte-wise copy of the glyph's rendered 8-bit grayscale bitmap into the structure's buffer.
* Each byte is converted from the bitmap's intensity value into the a uint32_t RGBA value.
*
* @param bmp A pointer to the most recently rendered glyph's bitmap.
* @param charData A pointer to an allocated ftgxCharData structure whose data represent that of the last rendered glyph.
*/
void FreeTypeGX::loadGlyphData(FT_Bitmap *bmp, ftgxCharData *charData) {
uint32_t *glyphData = (uint32_t *)memalign(32, charData->textureWidth * charData->textureHeight * 4);
memset(glyphData, 0x00, charData->textureWidth * charData->textureHeight * 4);
for (uint16_t imagePosY = 0; imagePosY < bmp->rows; imagePosY++) {
for (uint16_t imagePosX = 0; imagePosX < bmp->width; imagePosX++) {
uint32_t pixel = (uint32_t) bmp->buffer[imagePosY * bmp->width + imagePosX];
glyphData[imagePosY * charData->textureWidth + imagePosX] = 0x00000000 | (pixel << 24) | (pixel << 16) | (pixel << 8) | pixel;
}
}
switch(this->textureFormat) {
case GX_TF_I4:
charData->glyphDataTexture = Metaphrasis::convertBufferToI4(glyphData, charData->textureWidth, charData->textureHeight);
break;
case GX_TF_I8:
charData->glyphDataTexture = Metaphrasis::convertBufferToI8(glyphData, charData->textureWidth, charData->textureHeight);
break;
case GX_TF_IA4:
charData->glyphDataTexture = Metaphrasis::convertBufferToIA4(glyphData, charData->textureWidth, charData->textureHeight);
break;
case GX_TF_IA8:
charData->glyphDataTexture = Metaphrasis::convertBufferToIA8(glyphData, charData->textureWidth, charData->textureHeight);
break;
case GX_TF_RGB565:
charData->glyphDataTexture = Metaphrasis::convertBufferToRGB565(glyphData, charData->textureWidth, charData->textureHeight);
break;
case GX_TF_RGB5A3:
charData->glyphDataTexture = Metaphrasis::convertBufferToRGB5A3(glyphData, charData->textureWidth, charData->textureHeight);
break;
case GX_TF_RGBA8:
default:
charData->glyphDataTexture = Metaphrasis::convertBufferToRGBA8(glyphData, charData->textureWidth, charData->textureHeight);
break;
}
free(glyphData);
}
/**
* Determines the x offset of the rendered string.
*
* This routine calculates the x offset of the rendered string based off of a supplied positional format parameter.
*
* @param width Current pixel width of the string.
* @param format Positional format of the string.
*/
uint16_t FreeTypeGX::getStyleOffsetWidth(uint16_t width, uint16_t format) {
if (format & FTGX_JUSTIFY_LEFT ) {
return 0;
}
else if (format & FTGX_JUSTIFY_CENTER ) {
return width >> 1;
}
else if (format & FTGX_JUSTIFY_RIGHT ) {
return width;
}
return 0;
}
/**
* Determines the y offset of the rendered string.
*
* This routine calculates the y offset of the rendered string based off of a supplied positional format parameter.
*
* @param offset Current pixel offset data of the string.
* @param format Positional format of the string.
*/
uint16_t FreeTypeGX::getStyleOffsetHeight(ftgxDataOffset offset, uint16_t format) {
if (format & FTGX_ALIGN_TOP ) {
return -offset.max;
}
else if (format & FTGX_ALIGN_MIDDLE ) {
return -offset.max;
}
else if (format & FTGX_ALIGN_BOTTOM ) {
return offset.min;
}
return 0;
}
/**
* Processes the supplied text string and prints the results at the specified coordinates.
*
* This routine processes each character of the supplied text string, loads the relevant preprocessed bitmap buffer,
* a texture from said buffer, and loads the resultant texture into the EFB.
*
* @param x Screen X coordinate at which to output the text.
* @param y Screen Y coordinate at which to output the text. Note that this value corresponds to the text string origin and not the top or bottom of the glyphs.
* @param text NULL terminated string to output.
* @param color Optional color to apply to the text characters. If not specified default value is ftgxWhite: (GXColor){0xff, 0xff, 0xff, 0xff}
* @param textStyle Flags which specify any styling which should be applied to the rendered string.
* @return The number of characters printed.
*/
uint16_t FreeTypeGX::drawText(int16_t x, int16_t y, wchar_t *text, GXColor color, uint16_t textStyle) {
uint16_t strLength = wcslen(text);
uint16_t x_pos = x, printed = 0;
uint16_t x_offset = 0, y_offset = 0;
GXTexObj glyphTexture;
FT_Vector pairDelta;
if(textStyle & 0x000F) {
x_offset = this->getStyleOffsetWidth(this->getWidth(text), textStyle);
}
if(textStyle & 0x00F0) {
y_offset = this->getStyleOffsetHeight(this->getOffset(text), textStyle);
}
for (uint16_t i = 0; i < strLength; i++) {
ftgxCharData* glyphData = NULL;
if( this->fontData.find(text[i]) != this->fontData.end() ) {
glyphData = &this->fontData[text[i]];
}
else {
glyphData = this->cacheGlyphData(text[i]);
}
if(glyphData != NULL) {
if(this->ftKerningEnabled && i) {
FT_Get_Kerning( this->ftFace, this->fontData[text[i - 1]].glyphIndex, glyphData->glyphIndex, FT_KERNING_DEFAULT, &pairDelta );
x_pos += pairDelta.x >> 6;
}
GX_InitTexObj(&glyphTexture, glyphData->glyphDataTexture, glyphData->textureWidth, glyphData->textureHeight, this->textureFormat, GX_CLAMP, GX_CLAMP, GX_FALSE);
this->copyTextureToFramebuffer(&glyphTexture, glyphData->textureWidth, glyphData->textureHeight, x_pos - x_offset, y - glyphData->renderOffsetY - y_offset, color);
x_pos += glyphData->glyphAdvanceX;
printed++;
}
}
if(textStyle & 0x0F00) {
this->drawTextFeature(x - x_offset, y, this->getWidth(text), this->getOffset(text), textStyle, color);
}
return printed;
}
/**
* \overload
*/
uint16_t FreeTypeGX::drawText(int16_t x, int16_t y, wchar_t const *text, GXColor color, uint16_t textStyle) {
return this->drawText(x, y, (wchar_t *)text, color, textStyle);
}
void FreeTypeGX::drawTextFeature(int16_t x, int16_t y, uint16_t width, ftgxDataOffset offsetData, uint16_t format, GXColor color) {
uint16_t featureHeight = this->ftPointSize >> 4 > 0 ? this->ftPointSize >> 4 : 1;
if (format & FTGX_STYLE_UNDERLINE ) {
switch(format & 0x00F0) {
case FTGX_ALIGN_TOP:
this->copyFeatureToFramebuffer(width, featureHeight, x, y + offsetData.max + 1, color);
break;
case FTGX_ALIGN_MIDDLE:
this->copyFeatureToFramebuffer(width, featureHeight, x, y + ((offsetData.max - offsetData.min) >> 1) + 1, color);
break;
case FTGX_ALIGN_BOTTOM:
this->copyFeatureToFramebuffer(width, featureHeight, x, y - offsetData.min, color);
break;
default:
this->copyFeatureToFramebuffer(width, featureHeight, x, y + 1, color);
break;
}
}
if (format & FTGX_STYLE_STRIKE ) {
switch(format & 0x00F0) {
case FTGX_ALIGN_TOP:
this->copyFeatureToFramebuffer(width, featureHeight, x, y + ((offsetData.max + offsetData.min) >> 1), color);
break;
case FTGX_ALIGN_MIDDLE:
this->copyFeatureToFramebuffer(width, featureHeight, x, y, color);
break;
case FTGX_ALIGN_BOTTOM:
this->copyFeatureToFramebuffer(width, featureHeight, x, y - ((offsetData.max + offsetData.min) >> 1), color);
break;
default:
this->copyFeatureToFramebuffer(width, featureHeight, x, y - ((offsetData.max - offsetData.min) >> 1), color);
break;
}
}
}
/**
* Processes the supplied string and return the width of the string in pixels.
*
* This routine processes each character of the supplied text string and calculates the width of the entire string.
* Note that if precaching of the entire font set is not enabled any uncached glyph will be cached after the call to this function.
*
* @param text NULL terminated string to calculate.
* @return The width of the text string in pixels.
*/
uint16_t FreeTypeGX::getWidth(wchar_t *text) {
uint16_t strLength = wcslen(text);
uint16_t strWidth = 0;
FT_Vector pairDelta;
for (uint16_t i = 0; i < strLength; i++) {
ftgxCharData* glyphData = NULL;
if( this->fontData.find(text[i]) != this->fontData.end() ) {
glyphData = &this->fontData[text[i]];
}
else {
glyphData = this->cacheGlyphData(text[i]);
}
if(glyphData != NULL) {
if(this->ftKerningEnabled && (i > 0)) {
FT_Get_Kerning( this->ftFace, this->fontData[text[i - 1]].glyphIndex, glyphData->glyphIndex, FT_KERNING_DEFAULT, &pairDelta );
strWidth += pairDelta.x >> 6;
}
strWidth += glyphData->glyphAdvanceX;
}
}
return strWidth;
}
/**
*
* \overload
*/
uint16_t FreeTypeGX::getWidth(wchar_t const *text) {
return this->getWidth((wchar_t *)text);
}
/**
* Processes the supplied string and return the height of the string in pixels.
*
* This routine processes each character of the supplied text string and calculates the height of the entire string.
* Note that if precaching of the entire font set is not enabled any uncached glyph will be cached after the call to this function.
*
* @param text NULL terminated string to calculate.
* @return The height of the text string in pixels.
*/
uint16_t FreeTypeGX::getHeight(wchar_t *text) {
ftgxDataOffset offset = this->getOffset(text);
return offset.max + offset.min;
}
/**
*
* \overload
*/
uint16_t FreeTypeGX::getHeight(wchar_t const *text) {
return this->getHeight((wchar_t *)text);
}
/**
* Get the maximum offset above and minimum offset below the font origin line.
*
* This function calculates the maximum pixel height above the font origin line and the minimum
* pixel height below the font origin line and returns the values in an addressible structure.
*
* @param text NULL terminated string to calculate.
* @return The max and min values above and below the font origin line.
*/
ftgxDataOffset FreeTypeGX::getOffset(wchar_t *text) {
uint16_t strLength = wcslen(text);
uint16_t strMax = 0, strMin = 0;
for (uint16_t i = 0; i < strLength; i++) {
ftgxCharData* glyphData = NULL;
if( this->fontData.find(text[i]) != this->fontData.end() ) {
glyphData = &this->fontData[text[i]];
}
else {
glyphData = this->cacheGlyphData(text[i]);
}
if(glyphData != NULL) {
strMax = glyphData->renderOffsetMax > strMax ? glyphData->renderOffsetMax : strMax;
strMin = glyphData->renderOffsetMin > strMin ? glyphData->renderOffsetMin : strMin;
}
}
return (ftgxDataOffset){strMax, strMin};
}
/**
*
* \overload
*/
ftgxDataOffset FreeTypeGX::getOffset(wchar_t const *text) {
return this->getOffset(text);
}
/**
* Copies the supplied texture quad to the EFB.
*
* This routine uses the in-built GX quad builder functions to define the texture bounds and location on the EFB target.
*
* @param texObj A pointer to the glyph's initialized texture object.
* @param texWidth The pixel width of the texture object.
* @param texHeight The pixel height of the texture object.
* @param screenX The screen X coordinate at which to output the rendered texture.
* @param screenY The screen Y coordinate at which to output the rendered texture.
* @param color Color to apply to the texture.
*/
void FreeTypeGX::copyTextureToFramebuffer(GXTexObj *texObj, f32 texWidth, f32 texHeight, int16_t screenX, int16_t screenY, GXColor color) {
GX_LoadTexObj(texObj, GX_TEXMAP0);
GX_InvalidateTexAll();
GX_SetTevOp (GX_TEVSTAGE0, GX_MODULATE);
GX_SetVtxDesc (GX_VA_TEX0, GX_DIRECT);
GX_Begin(GX_QUADS, this->vertexIndex, 4);
GX_Position2s16(screenX, screenY);
GX_Color4u8(color.r, color.g, color.b, color.a);
GX_TexCoord2f32(0.0f, 0.0f);
GX_Position2s16(texWidth + screenX, screenY);
GX_Color4u8(color.r, color.g, color.b, color.a);
GX_TexCoord2f32(1.0f, 0.0f);
GX_Position2s16(texWidth + screenX, texHeight + screenY);
GX_Color4u8(color.r, color.g, color.b, color.a);
GX_TexCoord2f32(1.0f, 1.0f);
GX_Position2s16(screenX, texHeight + screenY);
GX_Color4u8(color.r, color.g, color.b, color.a);
GX_TexCoord2f32(0.0f, 1.0f);
GX_End();
this->setDefaultMode();
}
/**
* Creates a feature quad to the EFB.
*
* This function creates a simple quad for displaying underline or strikeout text styling.
*
* @param featureWidth The pixel width of the quad.
* @param featureHeight The pixel height of the quad.
* @param screenX The screen X coordinate at which to output the quad.
* @param screenY The screen Y coordinate at which to output the quad.
* @param color Color to apply to the texture.
*/
void FreeTypeGX::copyFeatureToFramebuffer(f32 featureWidth, f32 featureHeight, int16_t screenX, int16_t screenY, GXColor color) {
GX_SetTevOp (GX_TEVSTAGE0, GX_PASSCLR);
GX_SetVtxDesc (GX_VA_TEX0, GX_NONE);
GX_Begin(GX_QUADS, this->vertexIndex, 4);
GX_Position2s16(screenX, screenY);
GX_Color4u8(color.r, color.g, color.b, color.a);
GX_Position2s16(featureWidth + screenX, screenY);
GX_Color4u8(color.r, color.g, color.b, color.a);
GX_Position2s16(featureWidth + screenX, featureHeight + screenY);
GX_Color4u8(color.r, color.g, color.b, color.a);
GX_Position2s16(screenX, featureHeight + screenY);
GX_Color4u8(color.r, color.g, color.b, color.a);
GX_End();
this->setDefaultMode();
}

286
source/FreeTypeGX.h Normal file
View File

@ -0,0 +1,286 @@
/*
* FreeTypeGX is a wrapper class for libFreeType which renders a compiled
* FreeType parsable font into a GX texture for Wii homebrew development.
* Copyright (C) 2008 Armin Tamzarian
* Modified by Tantric, 2009
*
* This file is part of FreeTypeGX.
*
* FreeTypeGX is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* FreeTypeGX is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with FreeTypeGX. If not, see <http://www.gnu.org/licenses/>.
*/
/** \mainpage FreeTypeGX
*
* \section sec_intro Introduction
*
* FreeTypeGX is a wrapper class for libFreeType which renders a compiled FreeType parsable font into a GX texture for Wii homebrew development.
* <br>
* FreeTypeGX is written in C++ and makes use of a selectable pre-buffered or buffer-on-demand methodology to allow fast and efficient printing of text to the EFB.
* <p>
* This library was developed in-full by Armin Tamzarian with the support of developers in \#wiibrew on EFnet.
*
* \section sec_installation_source Installation (Source Code)
*
* -# Ensure that you have the <a href = "http://www.tehskeen.com/forums/showthread.php?t=9404">libFreeType</a> Wii library installed in your development environment with the library added to your Makefile where appropriate.
* -# Ensure that you have the <a href = "http://code.google.com/p/metaphrasis">Metaphrasis</a> library installed in your development environment with the library added to your Makefile where appropriate.
* -# Extract the FreeTypeGX archive.
* -# Copy the contents of the <i>src</i> directory into your project's development path.
* -# Include the FreeTypeGX header file in your code using syntax such as the following:
* \code
* #include "FreeTypeGX.h"
* \endcode
*
* \section sec_installation_library Installation (Library)
*
* -# Ensure that you have the <a href = "http://www.tehskeen.com/forums/showthread.php?t=9404">libFreeType</a> Wii library installed in your development environment with the library added to your Makefile where appropriate.
* -# Ensure that you have the <a href = "http://code.google.com/p/metaphrasis">Metaphrasis</a> library installed in your development environment with the library added to your Makefile where appropriate.
* -# Extract the FreeTypeGX archive.
* -# Copy the contents of the <i>lib</i> directory into your <i>devKitPro/libogc</i> directory.
* -# Include the FreeTypeGX header file in your code using syntax such as the following:
* \code
* #include "FreeTypeGX.h"
* \endcode
*
* \section sec_freetypegx_prerequisites FreeTypeGX Prerequisites
*
* Before you begin using FreeTypeGX in your project you must ensure that the desired font in compiled into your project. For this example I will assume you are building your project with a Makefile using devKitPro evironment and are attempting to include a font whose filename is rursus_compact_mono.ttf.
*
* -# Copy the font into a directory which will be processed by the project's Makefile. If you are unsure about where you should place your font just copy the it into your project's source directory.
* \n\n
* -# Modify the Makefile to convert the font into an object file:
* \code
* %.ttf.o : %.ttf
* @echo $(notdir $<)
* $(bin2o)
* \endcode
* \n
* -# Include the font object's generated header file in your source code:
* \code
* #include "rursus_compact_mono_ttf.h"
* \endcode
* This header file defines the two variables that you will need for use within your project:
* \code
* extern const u8 rursus_compact_mono_ttf[]; A pointer to the font buffer within the compiled project.
* extern const u32 rursus_compact_mono_ttf_size; The size of the font's buffer in bytes.
* \endcode
*
* \section sec_freetypegx_usage FreeTypeGX Usage
*
* -# Within the file you included the FreeTypeGX.h header create an instance object of the FreeTypeGX class:
* \code
* FreeTypeGX *freeTypeGX = new FreeTypeGX();
* \endcode
* Alternately you can specify a texture format to which you would like to render the font characters. Note that the default value for this parameter is GX_TF_RGBA8.
* \code
* FreeTypeGX *freeTypeGX = new FreeTypeGX(GX_TF_RGB565);
* \endcode
* Furthermore, you can also specify a vertex format index to avoid conflicts with concurrent libraries or other systems. Note that the default value for this parameter is GX_VTXFMT1.
* \code
* FreeTypeGX *freeTypeGX = new FreeTypeGX(GX_TF_RGB565, GX_VTXFMT1);
* \endcode
* \n
* Currently supported textures are:
* \li <i>GX_TF_I4</i>
* \li <i>GX_TF_I8</i>
* \li <i>GX_TF_IA4</i>
* \li <i>GX_TF_IA8</i>
* \li <i>GX_TF_RGB565</i>
* \li <i>GX_TF_RGB5A3</i>
* \li <i>GX_TF_RGBA8</i>
*
* \n
* -# Using the allocated FreeTypeGX instance object call the loadFont function to load the font from the compiled buffer and specify the desired point size. Note that this function can be called multiple times to load a new:
* \code
* freeTypeGX->loadFont(rursus_compact_mono_ttf, rursus_compact_mono_ttf_size, 64);
* \endcode
* Alternately you can specify a flag which will load and cache all available font glyphs immidiately. Note that on large font sets enabling this feature could take a significant amount of time.
* \code
* freeTypeGX->loadFont(rursus_compact_mono_ttf, rursus_compact_mono_ttf_size, 64, true);
* \endcode
* \n
* -# If necessary you can enable compatibility modes with concurrent libraries or systems. For more information on this feature see the documentation for setCompatibilityMode:
* \code
* freeTypeGX->setCompatibilityMode(FTGX_COMPATIBILITY_GRRLIB);
* \endcode
* -# Using the allocated FreeTypeGX instance object call the drawText function to print a string at the specified screen X and Y coordinates to the current EFB:
* \code
* freeTypeGX->drawText(10, 25, _TEXT("FreeTypeGX Rocks!"));
* \endcode
* Alternately you can specify a <i>GXColor</i> object you would like to apply to the printed characters:
* \code
* freeTypeGX->drawText(10, 25, _TEXT("FreeTypeGX Rocks!"),
* (GXColor){0xff, 0xee, 0xaa, 0xff});
* \endcode
* Furthermore you can also specify a group of styling parameters which will modify the positioning or style of the text:
* \code
* freeTypeGX->drawText(10, 25, _TEXT("FreeTypeGX Rocks!"),
* (GXColor){0xff, 0xee, 0xaa, 0xff},
* FTGX_JUSTIFY_CENTER | FTGX_ALIGN_BOTTOM | FTGX_STYLE_UNDERLINE);
* \endcode
* \n
* Currently style parameters are:
* \li <i>FTGX_JUSTIFY_LEFT</i>
* \li <i>FTGX_JUSTIFY_CENTER</i>
* \li <i>FTGX_JUSTIFY_RIGHT</i>
* \li <i>FTGX_ALIGN_TOP</i>
* \li <i>FTGX_ALIGN_MIDDLE</i>
* \li <i>FTGX_ALIGN_BOTTOM</i>
* \li <i>FTGX_STYLE_UNDERLINE</i>
* \li <i>FTGX_STYLE_STRIKE</i>
*
* \section sec_license License
*
* FreeTypeGX is distributed under the GNU Lesser General Public License.
*
* \section sec_contact Contact
*
* If you have any suggestions, questions, or comments regarding this library feel free to e-mail me at tamzarian1989 [at] gmail [dawt] com.
*/
#ifndef FREETYPEGX_H_
#define FREETYPEGX_H_
#include <gccore.h>
#include <ft2build.h>
#include FT_FREETYPE_H
#include FT_BITMAP_H
#include <Metaphrasis.h>
#include <malloc.h>
#include <string.h>
#include <map>
/*! \struct ftgxCharData_
*
* Font face character glyph relevant data structure.
*/
typedef struct ftgxCharData_ {
uint16_t glyphAdvanceX; /**< Character glyph X coordinate advance in pixels. */
uint16_t glyphIndex; /**< Charachter glyph index in the font face. */
uint16_t textureWidth; /**< Texture width in pixels/bytes. */
uint16_t textureHeight; /**< Texture glyph height in pixels/bytes. */
uint16_t renderOffsetY; /**< Texture Y axis bearing offset. */
uint16_t renderOffsetMax; /**< Texture Y axis bearing maximum value. */
uint16_t renderOffsetMin; /**< Texture Y axis bearing minimum value. */
uint32_t* glyphDataTexture; /**< Glyph texture bitmap data buffer. */
} ftgxCharData;
/*! \struct ftgxDataOffset_
*
* Offset structure which hold both a maximum and minimum value.
*/
typedef struct ftgxDataOffset_ {
int16_t max; /**< Maximum data offset. */
int16_t min; /**< Minimum data offset. */
} ftgxDataOffset;
#define _TEXT(t) L ## t /**< Unicode helper macro. */
#define FTGX_NULL 0x0000
#define FTGX_JUSTIFY_LEFT 0x0001
#define FTGX_JUSTIFY_CENTER 0x0002
#define FTGX_JUSTIFY_RIGHT 0x0004
#define FTGX_ALIGN_TOP 0x0010
#define FTGX_ALIGN_MIDDLE 0x0020
#define FTGX_ALIGN_BOTTOM 0x0040
#define FTGX_STYLE_UNDERLINE 0x0100
#define FTGX_STYLE_STRIKE 0x0200
#define FTGX_COMPATIBILITY_DEFAULT_TEVOP_GX_MODULATE 0X0001
#define FTGX_COMPATIBILITY_DEFAULT_TEVOP_GX_DECAL 0X0002
#define FTGX_COMPATIBILITY_DEFAULT_TEVOP_GX_BLEND 0X0004
#define FTGX_COMPATIBILITY_DEFAULT_TEVOP_GX_REPLACE 0X0008
#define FTGX_COMPATIBILITY_DEFAULT_TEVOP_GX_PASSCLR 0X0010
#define FTGX_COMPATIBILITY_DEFAULT_VTXDESC_GX_NONE 0X0100
#define FTGX_COMPATIBILITY_DEFAULT_VTXDESC_GX_DIRECT 0X0200
#define FTGX_COMPATIBILITY_DEFAULT_VTXDESC_GX_INDEX8 0X0400
#define FTGX_COMPATIBILITY_DEFAULT_VTXDESC_GX_INDEX16 0X0800
#define FTGX_COMPATIBILITY_NONE 0x0000
#define FTGX_COMPATIBILITY_GRRLIB FTGX_COMPATIBILITY_DEFAULT_TEVOP_GX_PASSCLR | FTGX_COMPATIBILITY_DEFAULT_VTXDESC_GX_NONE
#define FTGX_COMPATIBILITY_LIBWIISPRITE FTGX_COMPATIBILITY_DEFAULT_TEVOP_GX_MODULATE | FTGX_COMPATIBILITY_DEFAULT_VTXDESC_GX_DIRECT
const GXColor ftgxWhite = (GXColor){0xff, 0xff, 0xff, 0xff}; /**< Constant color value used only to sanitize Doxygen documentation. */
/*! \class FreeTypeGX
* \brief Wrapper class for the libFreeType library with GX rendering.
* \author Armin Tamzarian
* \version 0.2.4
*
* FreeTypeGX acts as a wrapper class for the libFreeType library. It supports precaching of transformed glyph data into
* a specified texture format. Rendering of the data to the EFB is accomplished through the application of high performance
* GX texture functions resulting in high throughput of string rendering.
*/
class FreeTypeGX {
private:
FT_Library ftLibrary; /**< FreeType FT_Library instance. */
FT_Face ftFace; /**< FreeType reusable FT_Face typographic object. */
FT_GlyphSlot ftSlot; /**< FreeType reusable FT_GlyphSlot glyph container object. */
FT_UInt ftPointSize; /**< Requested size of the rendered font. */
bool ftKerningEnabled; /**< Flag indicating the availability of font kerning data. */
uint8_t textureFormat; /**< Defined texture format of the target EFB. */
uint8_t vertexIndex; /**< Vertex format descriptor index. */
uint32_t compatibilityMode; /**< Compatibility mode for default tev operations and vertex descriptors. */
std::map<wchar_t, ftgxCharData> fontData; /**< Map which holds the glyph data structures for the corresponding characters. */
static uint16_t adjustTextureWidth(uint16_t textureWidth, uint8_t textureFormat);
static uint16_t adjustTextureHeight(uint16_t textureHeight, uint8_t textureFormat);
static uint16_t getStyleOffsetWidth(uint16_t width, uint16_t format);
static uint16_t getStyleOffsetHeight(ftgxDataOffset offset, uint16_t format);
void unloadFont();
ftgxCharData *cacheGlyphData(wchar_t charCode);
uint16_t cacheGlyphDataComplete();
void loadGlyphData(FT_Bitmap *bmp, ftgxCharData *charData);
void setDefaultMode();
void drawTextFeature(int16_t x, int16_t y, uint16_t width, ftgxDataOffset offsetData, uint16_t format, GXColor color);
void copyTextureToFramebuffer(GXTexObj *texObj, f32 texWidth, f32 texHeight, int16_t screenX, int16_t screenY, GXColor color);
void copyFeatureToFramebuffer(f32 featureWidth, f32 featureHeight, int16_t screenX, int16_t screenY, GXColor color);
public:
FreeTypeGX(uint8_t textureFormat = GX_TF_RGBA8, uint8_t vertexIndex = GX_VTXFMT1);
~FreeTypeGX();
static wchar_t* charToWideChar(char* p);
static wchar_t* charToWideChar(const char* p);
void setVertexFormat(uint8_t vertexIndex);
void setCompatibilityMode(uint32_t compatibilityMode);
uint16_t loadFont(uint8_t* fontBuffer, FT_Long bufferSize, FT_UInt pointSize, bool cacheAll = false);
uint16_t loadFont(const uint8_t* fontBuffer, FT_Long bufferSize, FT_UInt pointSize, bool cacheAll = false);
void changeSize(FT_UInt pointSize);
uint16_t drawText(int16_t x, int16_t y, wchar_t *text, GXColor color = ftgxWhite, uint16_t textStyling = FTGX_NULL);
uint16_t drawText(int16_t x, int16_t y, wchar_t const *text, GXColor color = ftgxWhite, uint16_t textStyling = FTGX_NULL);
uint16_t getWidth(wchar_t *text);
uint16_t getWidth(wchar_t const *text);
uint16_t getHeight(wchar_t *text);
uint16_t getHeight(wchar_t const *text);
ftgxDataOffset getOffset(wchar_t *text);
ftgxDataOffset getOffset(wchar_t const *text);
};
#endif /* FREETYPEGX_H_ */

327
source/apploader.c Normal file
View File

@ -0,0 +1,327 @@
#include <stdio.h>
#include <ogcsys.h>
#include <string.h>
#include "apploader.h"
#include "wdvd.h"
#include "wpad.h"
#include "patchcode.h"
#include "kenobiwii.h" /*FISHEARS*/
/*KENOBI! - FISHEARS*/
extern const unsigned char kenobiwii[];
extern const int kenobiwii_size;
/*KENOBI! - FISHEARS*/
/* Apploader function pointers */
typedef int (*app_main)(void **dst, int *size, int *offset);
typedef void (*app_init)(void (*report)(const char *fmt, ...));
typedef void *(*app_final)();
typedef void (*app_entry)(void (**init)(void (*report)(const char *fmt, ...)), int (**main)(), void *(**final)());
/* Apploader pointers */
static u8 *appldr = (u8 *)0x81200000;
/* Constants */
#define APPLDR_OFFSET 0x2440
/* Variables */
static u32 buffer[0x20] ATTRIBUTE_ALIGN(32);
static void __noprint(const char *fmt, ...)
{
}
bool compare_videomodes(GXRModeObj* mode1, GXRModeObj* mode2)
{
if (mode1->viTVMode != mode2->viTVMode || mode1->fbWidth != mode2->fbWidth || mode1->efbHeight != mode2->efbHeight || mode1->xfbHeight != mode2->xfbHeight ||
mode1->viXOrigin != mode2->viXOrigin || mode1->viYOrigin != mode2->viYOrigin || mode1->viWidth != mode2->viWidth || mode1->viHeight != mode2->viHeight ||
mode1->xfbMode != mode2->xfbMode || mode1->field_rendering != mode2->field_rendering || mode1->aa != mode2->aa || mode1->sample_pattern[0][0] != mode2->sample_pattern[0][0] ||
mode1->sample_pattern[1][0] != mode2->sample_pattern[1][0] || mode1->sample_pattern[2][0] != mode2->sample_pattern[2][0] ||
mode1->sample_pattern[3][0] != mode2->sample_pattern[3][0] || mode1->sample_pattern[4][0] != mode2->sample_pattern[4][0] ||
mode1->sample_pattern[5][0] != mode2->sample_pattern[5][0] || mode1->sample_pattern[6][0] != mode2->sample_pattern[6][0] ||
mode1->sample_pattern[7][0] != mode2->sample_pattern[7][0] || mode1->sample_pattern[8][0] != mode2->sample_pattern[8][0] ||
mode1->sample_pattern[9][0] != mode2->sample_pattern[9][0] || mode1->sample_pattern[10][0] != mode2->sample_pattern[10][0] ||
mode1->sample_pattern[11][0] != mode2->sample_pattern[11][0] || mode1->sample_pattern[0][1] != mode2->sample_pattern[0][1] ||
mode1->sample_pattern[1][1] != mode2->sample_pattern[1][1] || mode1->sample_pattern[2][1] != mode2->sample_pattern[2][1] ||
mode1->sample_pattern[3][1] != mode2->sample_pattern[3][1] || mode1->sample_pattern[4][1] != mode2->sample_pattern[4][1] ||
mode1->sample_pattern[5][1] != mode2->sample_pattern[5][1] || mode1->sample_pattern[6][1] != mode2->sample_pattern[6][1] ||
mode1->sample_pattern[7][1] != mode2->sample_pattern[7][1] || mode1->sample_pattern[8][1] != mode2->sample_pattern[8][1] ||
mode1->sample_pattern[9][1] != mode2->sample_pattern[9][1] || mode1->sample_pattern[10][1] != mode2->sample_pattern[10][1] ||
mode1->sample_pattern[11][1] != mode2->sample_pattern[11][1] || mode1->vfilter[0] != mode2->vfilter[0] ||
mode1->vfilter[1] != mode2->vfilter[1] || mode1->vfilter[2] != mode2->vfilter[2] || mode1->vfilter[3] != mode2->vfilter[3] || mode1->vfilter[4] != mode2->vfilter[4] ||
mode1->vfilter[5] != mode2->vfilter[5] || mode1->vfilter[6] != mode2->vfilter[6] )
{
return false;
} else
{
return true;
}
}
void patch_videomode(GXRModeObj* mode1, GXRModeObj* mode2)
{
mode1->viTVMode = mode2->viTVMode;
mode1->fbWidth = mode2->fbWidth;
mode1->efbHeight = mode2->efbHeight;
mode1->xfbHeight = mode2->xfbHeight;
mode1->viXOrigin = mode2->viXOrigin;
mode1->viYOrigin = mode2->viYOrigin;
mode1->viWidth = mode2->viWidth;
mode1->viHeight = mode2->viHeight;
mode1->xfbMode = mode2->xfbMode;
mode1->field_rendering = mode2->field_rendering;
mode1->aa = mode2->aa;
mode1->sample_pattern[0][0] = mode2->sample_pattern[0][0];
mode1->sample_pattern[1][0] = mode2->sample_pattern[1][0];
mode1->sample_pattern[2][0] = mode2->sample_pattern[2][0];
mode1->sample_pattern[3][0] = mode2->sample_pattern[3][0];
mode1->sample_pattern[4][0] = mode2->sample_pattern[4][0];
mode1->sample_pattern[5][0] = mode2->sample_pattern[5][0];
mode1->sample_pattern[6][0] = mode2->sample_pattern[6][0];
mode1->sample_pattern[7][0] = mode2->sample_pattern[7][0];
mode1->sample_pattern[8][0] = mode2->sample_pattern[8][0];
mode1->sample_pattern[9][0] = mode2->sample_pattern[9][0];
mode1->sample_pattern[10][0] = mode2->sample_pattern[10][0];
mode1->sample_pattern[11][0] = mode2->sample_pattern[11][0];
mode1->sample_pattern[0][1] = mode2->sample_pattern[0][1];
mode1->sample_pattern[1][1] = mode2->sample_pattern[1][1];
mode1->sample_pattern[2][1] = mode2->sample_pattern[2][1];
mode1->sample_pattern[3][1] = mode2->sample_pattern[3][1];
mode1->sample_pattern[4][1] = mode2->sample_pattern[4][1];
mode1->sample_pattern[5][1] = mode2->sample_pattern[5][1];
mode1->sample_pattern[6][1] = mode2->sample_pattern[6][1];
mode1->sample_pattern[7][1] = mode2->sample_pattern[7][1];
mode1->sample_pattern[8][1] = mode2->sample_pattern[8][1];
mode1->sample_pattern[9][1] = mode2->sample_pattern[9][1];
mode1->sample_pattern[10][1] = mode2->sample_pattern[10][1];
mode1->sample_pattern[11][1] = mode2->sample_pattern[11][1];
mode1->vfilter[0] = mode2->vfilter[0];
mode1->vfilter[1] = mode2->vfilter[1];
mode1->vfilter[2] = mode2->vfilter[2];
mode1->vfilter[3] = mode2->vfilter[3];
mode1->vfilter[4] = mode2->vfilter[4];
mode1->vfilter[5] = mode2->vfilter[5];
mode1->vfilter[6] = mode2->vfilter[6];
}
GXRModeObj* vmodes[] = {
&TVNtsc240Ds,
&TVNtsc240DsAa,
&TVNtsc240Int,
&TVNtsc240IntAa,
&TVNtsc480IntDf,
&TVNtsc480IntAa,
&TVNtsc480Prog,
&TVMpal480IntDf,
&TVPal264Ds,
&TVPal264DsAa,
&TVPal264Int,
&TVPal264IntAa,
&TVPal524IntAa,
&TVPal528Int,
&TVPal528IntDf,
&TVPal574IntDfScale,
&TVEurgb60Hz240Ds,
&TVEurgb60Hz240DsAa,
&TVEurgb60Hz240Int,
&TVEurgb60Hz240IntAa,
&TVEurgb60Hz480Int,
&TVEurgb60Hz480IntDf,
&TVEurgb60Hz480IntAa,
&TVEurgb60Hz480Prog,
&TVEurgb60Hz480ProgSoft,
&TVEurgb60Hz480ProgAa
};
GXRModeObj* PAL2NTSC[]={
&TVMpal480IntDf, &TVNtsc480IntDf,
&TVPal264Ds, &TVNtsc240Ds,
&TVPal264DsAa, &TVNtsc240DsAa,
&TVPal264Int, &TVNtsc240Int,
&TVPal264IntAa, &TVNtsc240IntAa,
&TVPal524IntAa, &TVNtsc480IntAa,
&TVPal528Int, &TVNtsc480IntAa,
&TVPal528IntDf, &TVNtsc480IntDf,
&TVPal574IntDfScale, &TVNtsc480IntDf,
&TVEurgb60Hz240Ds, &TVNtsc240Ds,
&TVEurgb60Hz240DsAa, &TVNtsc240DsAa,
&TVEurgb60Hz240Int, &TVNtsc240Int,
&TVEurgb60Hz240IntAa, &TVNtsc240IntAa,
&TVEurgb60Hz480Int, &TVNtsc480IntAa,
&TVEurgb60Hz480IntDf, &TVNtsc480IntDf,
&TVEurgb60Hz480IntAa, &TVNtsc480IntAa,
&TVEurgb60Hz480Prog, &TVNtsc480Prog,
&TVEurgb60Hz480ProgSoft,&TVNtsc480Prog,
&TVEurgb60Hz480ProgAa, &TVNtsc480Prog,
0,0
};
GXRModeObj* NTSC2PAL[]={
&TVNtsc240Ds, &TVPal264Ds,
&TVNtsc240DsAa, &TVPal264DsAa,
&TVNtsc240Int, &TVPal264Int,
&TVNtsc240IntAa, &TVPal264IntAa,
&TVNtsc480IntDf, &TVPal528IntDf,
&TVNtsc480IntAa, &TVPal524IntAa,
&TVNtsc480Prog, &TVPal528IntDf,
0,0
};
GXRModeObj* NTSC2PAL60[]={
&TVNtsc240Ds, &TVEurgb60Hz240Ds,
&TVNtsc240DsAa, &TVEurgb60Hz240DsAa,
&TVNtsc240Int, &TVEurgb60Hz240Int,
&TVNtsc240IntAa, &TVEurgb60Hz240IntAa,
&TVNtsc480IntDf, &TVEurgb60Hz480IntDf,
&TVNtsc480IntAa, &TVEurgb60Hz480IntAa,
&TVNtsc480Prog, &TVEurgb60Hz480Prog,
0,0
};
bool Search_and_patch_Video_Modes(void *Address, u32 Size, GXRModeObj* Table[])
{
u8 *Addr = (u8 *)Address;
bool found = 0;
u32 i;
while(Size >= sizeof(GXRModeObj))
{
for(i = 0; Table[i]; i+=2)
{
if(compare_videomodes(Table[i], (GXRModeObj*)Addr))
{
found = 1;
patch_videomode((GXRModeObj*)Addr, Table[i+1]);
Addr += (sizeof(GXRModeObj)-4);
Size -= (sizeof(GXRModeObj)-4);
break;
}
}
Addr += 4;
Size -= 4;
}
return found;
}
s32 Apploader_Run(entry_point *entry, u8 cheat, u8 videoSelected, u8 vipatch)
{
app_entry appldr_entry;
app_init appldr_init;
app_main appldr_main;
app_final appldr_final;
u32 appldr_len;
s32 ret;
/* Read apploader header */
ret = WDVD_Read(buffer, 0x20, APPLDR_OFFSET);
if (ret < 0)
return ret;
/* Calculate apploader length */
appldr_len = buffer[5] + buffer[6];
/* Read apploader code */
ret = WDVD_Read(appldr, appldr_len, APPLDR_OFFSET + 0x20);
if (ret < 0)
return ret;
/* Set apploader entry function */
appldr_entry = (app_entry)buffer[4];
/* Call apploader entry */
appldr_entry(&appldr_init, &appldr_main, &appldr_final);
/* Initialize apploader */
appldr_init(__noprint);
if (cheat)
{
/*HOOKS STUFF - FISHEARS*/
memset((void*)0x80001800,0,kenobiwii_size);
memcpy((void*)0x80001800,kenobiwii,kenobiwii_size);
DCFlushRange((void*)0x80001800,kenobiwii_size);
hooktype = 1;
memcpy((void*)0x80001800, (char*)0x80000000, 6); // For WiiRD
/*HOOKS STUFF - FISHEARS*/
}
for (;;) {
void *dst = NULL;
int len = 0, offset = 0;
GXRModeObj** table = NULL;
/* Run apploader main function */
ret = appldr_main(&dst, &len, &offset);
if (!ret)
break;
/* Read data from DVD */
WDVD_Read(dst, len, (u64)(offset << 2));
if (videoSelected == 5) // patch
{
switch(CONF_GetVideo())
{
case CONF_VIDEO_PAL:
if(CONF_GetEuRGB60() > 0)
{
table = NTSC2PAL60;
}
else
{
table = NTSC2PAL;
}
break;
case CONF_VIDEO_MPAL:
table = NTSC2PAL;
break;
default:
table = PAL2NTSC;
break;
}
Search_and_patch_Video_Modes(dst, len, table);
}
/*GAME HOOK - FISHEARS*/
dogamehooks(dst,len);
if (vipatch)
vidolpatcher(dst,len);
/*LANGUAGE PATCH - FISHEARS*/
langpatcher(dst,len);
DCFlushRange(dst, len);
}
/* Set entry point from apploader */
*entry = appldr_final();
return 0;
}
#ifdef __cplusplus
}
#endif

10
source/apploader.h Normal file
View File

@ -0,0 +1,10 @@
#ifndef _APPLOADER_H_
#define _APPLOADER_H_
/* Entry point */
typedef void (*entry_point)(void);
/* Prototypes */
s32 Apploader_Run(entry_point *, u8, u8, u8);
#endif

35
source/audio.cpp Normal file
View File

@ -0,0 +1,35 @@
/****************************************************************************
* libwiigui Template
* Tantric 2009
*
* audio.cpp
* Audio support
***************************************************************************/
#include <gccore.h>
#include <ogcsys.h>
#include <asndlib.h>
/****************************************************************************
* InitAudio
*
* Initializes the Wii's audio subsystem
***************************************************************************/
void InitAudio()
{
AUDIO_Init(NULL);
ASND_Init();
ASND_Pause(0);
}
/****************************************************************************
* ShutdownAudio
*
* Shuts down audio subsystem. Useful to avoid unpleasant sounds if a
* crash occurs during shutdown.
***************************************************************************/
void ShutdownAudio()
{
ASND_Pause(1);
ASND_End();
}

15
source/audio.h Normal file
View File

@ -0,0 +1,15 @@
/****************************************************************************
* libwiigui Template
* Tantric 2009
*
* audio.h
* Audio support
***************************************************************************/
#ifndef _AUDIO_H_
#define _AUDIO_H_
void InitAudio();
void ShutdownAudio();
#endif

1065
source/cfg.c Normal file

File diff suppressed because it is too large Load Diff

261
source/cfg.h Normal file
View File

@ -0,0 +1,261 @@
#ifndef _CFG_H_
#define _CFG_H_
#include <gctypes.h>
#include "disc.h"
#ifdef __cplusplus
extern "C"
{
#endif
#define CFG_HOME_REBOOT 0
#define CFG_HOME_EXIT 1
#define CFG_VIDEO_SYS 0 // system default
#define CFG_VIDEO_DEFAULT 1
#define CFG_VIDEO_GAME 1 // game default
#define CFG_VIDEO_PATCH 2 // patch mode
#define CFG_VIDEO_PAL50 3 // force PAL
#define CFG_VIDEO_PAL60 4 // force PAL60
#define CFG_VIDEO_NTSC 5 // force NTSC
#define CFG_VIDEO_COUNT 6
#define CFG_LANG_CONSOLE 0
#define CFG_LANG_JAPANESE 1
#define CFG_LANG_ENGLISH 2
#define CFG_LANG_GERMAN 3
#define CFG_LANG_FRENCH 4
#define CFG_LANG_SPANISH 5
#define CFG_LANG_ITALIAN 6
#define CFG_LANG_DUTCH 7
#define CFG_LANG_S_CHINESE 8
#define CFG_LANG_T_CHINESE 9
#define CFG_LANG_KOREAN 10
#define CFG_LANG_COUNT 11
#define CFG_ALIGN_LEFT 0
#define CFG_ALIGN_RIGHT 1
#define CFG_ALIGN_CENTRE 2
#define CFG_ALIGN_TOP 3
#define CFG_ALIGN_BOTTOM 4
#define CFG_ALIGN_MIDDLE 5
extern char *cfg_path;
//extern char *cfg_images_path;
struct CFG
{
// char *background;
// short covers;
// short simple;
// short video;
// short language;
// short ocarina;
// short vipatch;
// short home;
// short download;
// short installdownload;
// short hidesettingmenu;
// short savesettings;
short widescreen;
short parentalcontrol;
short maxcharacters;
short godmode;
char unlockCode[20];
char covers_path[100];
char theme_path[100];
char disc_path[100];
};
struct THEME
{
int selection_x;
int selection_y;
int selection_w;
int selection_h;
int cover_x;
int cover_y;
short showID;
int id_x;
int id_y;
int region_x;
int region_y;
int power_x;
int power_y;
int home_x;
int home_y;
int battery1_x;
int battery2_x;
int battery3_x;
int battery4_x;
int battery1_y;
int battery2_y;
int battery3_y;
int battery4_y;
// short showPower;
// short showHome;
int setting_x;
int setting_y;
int install_x;
int install_y;
short showHDD;
short hddInfoAlign;
int hddInfo_x;
int hddInfo_y;
short showGameCnt;
short gameCntAlign;
int gameCnt_x;
int gameCnt_y;
short showRegion;
short showBattery;
short showToolTip;
//color
short info_r;
short info_g;
short info_b;
short clock_x;
short clock_y;
short clockAlign;
int sdcard_x;
int sdcard_y;
};
extern struct CFG CFG;
extern struct THEME THEME;
extern u8 ocarinaChoice;
extern u8 videoChoice;
extern u8 languageChoice;
extern u8 viChoice;
extern u8 iosChoice;
extern u8 parentalcontrolChoice;
struct Game_CFG
{
u8 id[8];
u8 video;
u8 language;
u8 ocarina;
u8 vipatch;
u8 ios;
u8 parentalcontrol;
};
void CFG_Default();
void CFG_Load(int argc, char **argv);
struct Game_CFG* CFG_get_game_opt(u8 *id);
bool CFG_save_game_opt(u8 *id);
bool CFG_forget_game_opt(u8 *id);
//Astidof - Begin of modification
enum {
ConsoleLangDefault,
jap,
eng,
ger,
fren,
esp,
it,
dut,
schin,
tchin,
kor
};
enum {
systemdefault,
discdefault,
patch,
pal50,
pal60,
ntsc
};
enum {
off,
on,
};
enum {
GameID,
GameRegion,
Both,
Neither,
};
enum {
i249,
i222,
};
enum {
ios249,
ios222,
};
enum {
HDDInfo,
Clock,
};
enum {
RumbleOff,
RumbleOn,
};
enum {
TooltipsOff,
TooltipsOn,
};
enum {
v10,
v20,
v30,
v40,
v50,
v60,
v70,
v80,
v90,
v100,
v0,
};
enum {
ParentalControlOff,
ParentalControlLevel1,
ParentalControlLevel2,
ParentalControlLevel3
};
struct SSettings {
int video;
int language;
int ocarina;
int vpatch;
int sinfo;
int hddinfo;
int rumble;
int volume;
int tooltips;
char unlockCode[20];
int parentalcontrol;
int cios;
};
void CFG_LoadGlobal(void);
bool cfg_save_global(void);
//Astidof - End of modification
char *get_title(struct discHdr *header);
u8 get_block(struct discHdr *header);
void CFG_Cleanup(void);
#ifdef __cplusplus
}
#endif
#endif

310
source/disc.c Normal file
View File

@ -0,0 +1,310 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ogcsys.h>
#include <ogc/lwp_watchdog.h>
#include <wiiuse/wpad.h>
#include "apploader.h"
#include "disc.h"
#include "video.h"
#include "wdvd.h"
#include "fst.h"
/* Constants */
#define PTABLE_OFFSET 0x40000
#define WII_MAGIC 0x5D1C9EA3
/* Disc pointers */
static u32 *buffer = (u32 *)0x93000000;
static u8 *diskid = (u8 *)0x80000000;
static char gameid[8];
void __Disc_SetLowMem(void)
{
/* Setup low memory */
*(vu32 *)0x80000030 = 0x00000000;
*(vu32 *)0x80000060 = 0x38A00040;
*(vu32 *)0x800000E4 = 0x80431A80;
*(vu32 *)0x800000EC = 0x81800000;
*(vu32 *)0x800000F4 = 0x817E5480;
*(vu32 *)0x800000F8 = 0x0E7BE2C0;
*(vu32 *)0x800000FC = 0x2B73A840;
/* Copy disc ID */
memcpy((void *)0x80003180, (void *)0x80000000, 4);
/* Flush cache */
DCFlushRange((void *)0x80000000, 0x3F00);
}
void __Disc_SetVMode(u8 videoselected)
{
GXRModeObj *vmode = NULL;
u32 progressive, tvmode, vmode_reg = 0;
/* Get video mode configuration */
progressive = (CONF_GetProgressiveScan() > 0) && VIDEO_HaveComponentCable();
tvmode = CONF_GetVideo();
/* Select video mode register */
switch (tvmode) {
case CONF_VIDEO_PAL:
vmode_reg = (CONF_GetEuRGB60() > 0) ? 5 : 1;
break;
case CONF_VIDEO_MPAL:
vmode_reg = 4;
break;
case CONF_VIDEO_NTSC:
vmode_reg = 0;
break;
}
switch (videoselected) {
case 0:
/* Select video mode */
switch(diskid[3]) {
/* PAL */
case 'D':
case 'F':
case 'P':
case 'X':
case 'Y':
if (tvmode != CONF_VIDEO_PAL) {
vmode_reg = 5;
vmode = (progressive) ? &TVNtsc480Prog : &TVEurgb60Hz480IntDf;
}
break;
/* NTSC or unknown */
case 'E':
case 'J':
if (tvmode != CONF_VIDEO_NTSC) {
vmode_reg = 0;
vmode = (progressive) ? &TVNtsc480Prog : &TVNtsc480IntDf;
}
break;
}
break;
case 1:
vmode_reg = 1;
progressive = (CONF_GetProgressiveScan() > 0) && VIDEO_HaveComponentCable();
vmode = (progressive) ? &TVEurgb60Hz480Prog : &TVPal528IntDf;
break;
case 2:
vmode_reg = 5;
progressive = (CONF_GetProgressiveScan() > 0) && VIDEO_HaveComponentCable();
vmode = (progressive) ? &TVEurgb60Hz480Prog : &TVEurgb60Hz480IntDf;
break;
case 3:
vmode_reg = 0;
progressive = (CONF_GetProgressiveScan() > 0) && VIDEO_HaveComponentCable();
vmode = (progressive) ? &TVNtsc480Prog : &TVNtsc480IntDf;
break;
case 4:
// vmode = VIDEO_GetPreferredMode(NULL);
break;
}
/* Set video mode register */
*(vu32 *)0x800000CC = vmode_reg;
/* Set video mode */
if (vmode) {
VIDEO_Configure(vmode);
/* Setup video */
VIDEO_SetBlack(FALSE);
VIDEO_Flush();
VIDEO_WaitVSync();
if (vmode->viTVMode & VI_NON_INTERLACE)
VIDEO_WaitVSync();
}
}
void __Disc_SetTime(void)
{
/* Extern */
extern void settime(long long);
/* Set proper time */
settime(secs_to_ticks(time(NULL) - 946684800));
}
s32 __Disc_FindPartition(u64 *outbuf)
{
u64 offset = 0, table_offset = 0;
u32 cnt, nb_partitions;
s32 ret;
/* Read partition info */
ret = WDVD_UnencryptedRead(buffer, 0x20, PTABLE_OFFSET);
if (ret < 0)
return ret;
/* Get data */
nb_partitions = buffer[0];
table_offset = buffer[1] << 2;
/* Read partition table */
ret = WDVD_UnencryptedRead(buffer, 0x20, table_offset);
if (ret < 0)
return ret;
/* Find game partition */
for (cnt = 0; cnt < nb_partitions; cnt++) {
u32 type = buffer[cnt * 2 + 1];
/* Game partition */
if(!type)
offset = buffer[cnt * 2] << 2;
}
/* No game partition found */
if (!offset)
return -1;
/* Set output buffer */
*outbuf = offset;
return 0;
}
s32 Disc_Init(void)
{
/* Init DVD subsystem */
return WDVD_Init();
}
s32 Disc_Open(void)
{
s32 ret;
/* Reset drive */
ret = WDVD_Reset();
if (ret < 0)
return ret;
/* Read disc ID */
return WDVD_ReadDiskId(diskid);
}
s32 Disc_Wait(void)
{
u32 cover = 0;
s32 ret;
/* Wait for disc */
while (!(cover & 0x2)) {
/* Get cover status */
ret = WDVD_GetCoverStatus(&cover);
if (ret < 0)
return ret;
}
return 0;
}
s32 Disc_SetUSB(u8 *id, int ios222)
{
/* Set USB mode */
return WDVD_SetUSBMode(id, ios222);
}
s32 Disc_ReadHeader(void *outbuf)
{
/* Read disc header */
return WDVD_UnencryptedRead(outbuf, sizeof(struct discHdr), 0);
}
s32 Disc_IsWii(void)
{
struct discHdr *header = (struct discHdr *)buffer;
s32 ret;
/* Read disc header */
ret = Disc_ReadHeader(header);
if (ret < 0)
return ret;
/* Check magic word */
if (header->magic != WII_MAGIC)
return -1;
return 0;
}
s32 Disc_BootPartition(u64 offset, u8 videoselected, u8 cheat, u8 vipatch)
{
entry_point p_entry;
s32 ret;
/* Open specified partition */
ret = WDVD_OpenPartition(offset);
if (ret < 0)
return ret;
/* Run apploader */
ret = Apploader_Run(&p_entry, cheat, videoselected, vipatch);
if (ret < 0)
return ret;
/* Setup low memory */
__Disc_SetLowMem();
/* Set an appropiate video mode */
__Disc_SetVMode(videoselected);
/* Set time */
__Disc_SetTime();
if (cheat == 1) {
/* OCARINA STUFF - FISHEARS*/
memset(gameid, 0, 8);
memcpy(gameid, (char*)0x80000000, 6);
do_sd_code(gameid);
/* OCARINA STUFF - FISHEARS*/
}
/* Disconnect Wiimote */
WPAD_Flush(0);
WPAD_Disconnect(0);
WPAD_Shutdown();
/* Shutdown IOS subsystems */
SYS_ResetSystem(SYS_SHUTDOWN, 0, 0);
/* Jump to entry point */
p_entry();
return 0;
}
s32 Disc_WiiBoot(u8 videoselected, u8 cheat, u8 vipatch)
{
u64 offset;
s32 ret;
/* Find game partition offset */
ret = __Disc_FindPartition(&offset);
if (ret < 0)
return ret;
/* Boot partition */
return Disc_BootPartition(offset, videoselected, cheat, vipatch);
}

58
source/disc.h Normal file
View File

@ -0,0 +1,58 @@
#ifndef _DISC_H_
#define _DISC_H_
#include <asndlib.h>
#ifdef __cplusplus
extern "C"
{
#endif
/* Disc header structure */
struct discHdr
{
/* Game ID */
u8 id[6];
/* Game version */
u16 version;
/* Audio streaming */
u8 streaming;
u8 bufsize;
/* Padding */
u8 unused1[14];
/* Magic word */
u32 magic;
/* Padding */
u8 unused2[4];
/* Game title */
char title[64];
/* Encryption/Hashing */
u8 encryption;
u8 h3_verify;
/* Padding */
u8 unused3[30];
} ATTRIBUTE_PACKED;
/* Prototypes */
s32 Disc_Init(void);
s32 Disc_Open(void);
s32 Disc_Wait(void);
void __Disc_SetLowMem(void);
s32 Disc_SetUSB(u8 *, int ios222);
s32 Disc_ReadHeader(void *);
s32 Disc_IsWii(void);
s32 Disc_BootPartition(u64, u8, u8, u8);
s32 Disc_WiiBoot(u8, u8, u8);
#ifdef __cplusplus
}
#endif
#endif

122
source/dns.c Normal file
View File

@ -0,0 +1,122 @@
#include "dns.h"
/**
* Resolves a domainname to an ip address
* It makes use of net_gethostbyname from libogc, which in turn makes use of a Wii BIOS function
* Just like the net_gethostbyname function this function is NOT threadsafe!
*
* @param char* The domain name to resolve
* @return u32 The ipaddress represented by four bytes inside an u32 (in network order)
*/
u32 getipbyname(char *domain)
{
//Care should be taken when using net_gethostbyname,
//it returns a static buffer which makes it not threadsafe
//TODO: implement some locking mechanism to make below code atomic
struct hostent *host = net_gethostbyname(domain);
if(host == NULL) {
return 0;
}
u32 *ip = (u32*)host->h_addr_list[0];
return *ip;
}
//Defines how many DNS entries should be cached by getipbynamecached()
#define MAX_DNS_CACHE_ENTRIES 20
//The cache is defined as a linked list,
//The last resolved domain name will always be at the front
//This will allow heavily used domainnames to always stay cached
struct dnsentry {
char *domain;
u32 ip;
struct dnsentry *nextnode;
} ;
static struct dnsentry *firstdnsentry = NULL;
static int dnsentrycount = 0;
/**
* Performs the same function as getipbyname(),
* except that it will prevent extremely expensive net_gethostbyname() calls by caching the result
*/
u32 getipbynamecached(char *domain)
{
//Search if this domainname is already cached
struct dnsentry *node = firstdnsentry;
struct dnsentry *previousnode = NULL;
while(node != NULL)
{
if(strcmp(node->domain, domain) == 0)
{
//DNS node found in the cache, move it to the front of the list
if(previousnode != NULL)
previousnode->nextnode = node->nextnode;
if(node != firstdnsentry)
node->nextnode = firstdnsentry;
firstdnsentry = node;
return node->ip;
}
//Go to the next element in the list
previousnode = node;
node = node->nextnode;
}
u32 ip = getipbyname(domain);
//No cache of this domain could be found, create a cache node and add it to the front of the cache
struct dnsentry *newnode = malloc(sizeof(struct dnsentry));
if(newnode == NULL) {
return ip;
}
newnode->ip = ip;
newnode->domain = malloc(strlen(domain)+1);
if(newnode->domain == NULL)
{
free(newnode);
return ip;
}
strcpy(newnode->domain, domain);
newnode->nextnode = firstdnsentry;
firstdnsentry = newnode;
dnsentrycount++;
//If the cache grows too big delete the last (and probably least important) node of the list
if(dnsentrycount > MAX_DNS_CACHE_ENTRIES)
{
struct dnsentry *node = firstdnsentry;
struct dnsentry *previousnode = NULL;
//Fetch the last two elements of the list
while(node->nextnode != NULL)
{
previousnode = node;
node = node->nextnode;
}
if(node == NULL)
{
printf("Configuration error, MAX_DNS_ENTRIES reached while the list is empty\n");
exit(1);
} else if(previousnode == NULL)
{
firstdnsentry = NULL;
} else {
previousnode->nextnode = NULL;
}
free(node->domain);
free(node);
dnsentrycount--;
}
return newnode->ip;
}

23
source/dns.h Normal file
View File

@ -0,0 +1,23 @@
#ifndef _DNS_H_
#define _DNS_H_
#include <network.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h> //usleep
#ifdef __cplusplus
extern "C"
{
#endif
u32 getipbyname(char *domain);
u32 getipbynamecached(char *domain);
#ifdef __cplusplus
}
#endif
#endif /* _DNS_H_ */

612
source/dvd_broadway.c Normal file
View File

@ -0,0 +1,612 @@
/*
* Copyright (C) 2008 Nuke (wiinuke@gmail.com)
*
* this file is part of GeckoOS for USB Gecko
* http://www.usbgecko.com
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <malloc.h>
#include <time.h>
#include <gcutil.h>
#include <ogc/lwp_queue.h>
#include <gccore.h>
#include "dvd_broadway.h"
#define DI_CMDCTX_CNT 4
#define DVD_DISKIDSIZE 0x20
#define DVD_DRVINFSIZE 0x20
#define IOCTL_DI_INQUIRY 0x12
#define IOCTL_DI_READID 0x70
#define IOCTL_DI_READ 0x71
#define IOCTL_DI_WAITCVRCLOSE 0x79
#define IOCTL_DI_COVER 0x7A
#define IOCTL_DI_RESETNOTIFY 0x7E
#define IOCTL_DI_RESET 0x8A
#define IOCTL_DI_OPENPART 0x8B
#define IOCTL_DI_CLOSEPART 0x8C
#define IOCTL_DI_UNENCREAD 0x8D
#define IOCTL_DI_ENABLE_DVD 0x8E
#define IOCTL_DI_SEEK 0xAB
#define IOCTL_DI_READ_DVDVIDEO 0xD0
#define IOCTL_DI_STOPLASER 0xD2
#define IOCTL_DI_OFFSET 0xD9
#define IOCTL_DI_REQERROR 0xE0
#define IOCTL_DI_STOPMOTOR 0xE3
#define IOCTL_DI_SETOFFBASE 0xF0
#define IOCTL_DI_GETOFFBASE 0xF1
#define IOCTL_DI_SETCRYPTMODE 0xF2
#define IOCTL_DI_GETCRYPTMODE 0xF3
#define IOCTL_DI_SETDVDROMMODE 0xF4
#define IOCTL_DI_GETDVDROMMODE 0xF5
#define _SHIFTL(v, s, w) \
((u32) (((u32)(v) & ((0x01 << (w)) - 1)) << (s)))
#define _SHIFTR(v, s, w) \
((u32)(((u32)(v) >> (s)) & ((0x01 << (w)) - 1)))
struct dicommand
{
u32 diReg[8];
};
struct dicontext
{
lwp_node node;
dvdcallbacklow cb;
struct dicommand *cmd;
};
static s32 __dvd_fd = -1;
static u32 __dvd_spinupval = 1;
static lwp_queue __di_contextq;
static u32 __dvd_readlength = 0;
static u32 __dvd_cbinprogress = 0;
static u32 __dvd_reqinprogress = 0;
static u32 __dvd_lowinitcalled = 0;
static struct dicommand *__di_commands = NULL;
static struct dicontext __di_contexts[DI_CMDCTX_CNT];
static u32 __di_regbuffer[0x08] ATTRIBUTE_ALIGN(32);
static u32 __di_regvalcache[0x08] ATTRIBUTE_ALIGN(32);
static u32 __di_lastticketerror[0x08] ATTRIBUTE_ALIGN(32);
static ioctlv __di_iovector[0x08] ATTRIBUTE_ALIGN(32);
static char __di_fs[] ATTRIBUTE_ALIGN(32) = "/dev/di";
extern u32 __IPC_ClntInit();
static __inline__ lwp_node* __lwp_queue_head(lwp_queue *queue)
{
return (lwp_node*)queue;
}
static __inline__ lwp_node* __lwp_queue_tail(lwp_queue *queue)
{
return (lwp_node*)&queue->perm_null;
}
static __inline__ void __lwp_queue_init_empty(lwp_queue *queue)
{
queue->first = __lwp_queue_tail(queue);
queue->perm_null = NULL;
queue->last = __lwp_queue_head(queue);
}
static struct dicontext* __dvd_getcontext(dvdcallbacklow cb)
{
struct dicontext *ctx;
ctx = (struct dicontext*)__lwp_queue_get(&__di_contextq);
if(ctx!=NULL) ctx->cb = cb;
return ctx;
}
static s32 __dvd_iostransactionCB(s32 result,void *usrdata)
{
struct dicontext *ctx = (struct dicontext*)usrdata;
__dvd_reqinprogress = 0;
if(ctx->cb!=NULL) {
__dvd_cbinprogress = 1;
if(result!=0) __dvd_readlength = 0;
ctx->cb(result);
__dvd_cbinprogress = 0;
}
__lwp_queue_append(&__di_contextq,&ctx->node);
return 0;
}
static s32 __dvd_ioscoverregisterCB(s32 result,void *usrdata)
{
struct dicontext *ctx = (struct dicontext*)usrdata;
__dvd_reqinprogress = 0;
__di_regvalcache[1] = __di_regbuffer[0];
if(ctx->cb!=NULL) {
__dvd_cbinprogress = 1;
ctx->cb(result);
__dvd_cbinprogress = 0;
}
__lwp_queue_append(&__di_contextq,&ctx->node);
return 0;
}
static s32 __dvd_ioscovercloseCB(s32 result,void *usrdata)
{
struct dicontext *ctx = (struct dicontext*)usrdata;
__dvd_reqinprogress = 0;
if(ctx->cb!=NULL) {
__dvd_cbinprogress = 1;
ctx->cb(result);
__dvd_cbinprogress = 0;
}
__lwp_queue_append(&__di_contextq,&ctx->node);
return 0;
}
s32 bwDVD_LowInit()
{
s32 i,ret = 0;
u32 ipclo,ipchi;
lwp_queue inactives;
struct dicontext *ctx;
if(__dvd_lowinitcalled==0) {
ret = __IPC_ClntInit();
if(ret<0) return ret;
ipclo = (((u32)IPC_GetBufferLo()+0x1f)&~0x1f);
ipchi = (u32)IPC_GetBufferHi();
if(ipchi>=(ipclo+(sizeof(struct dicommand)*DI_CMDCTX_CNT))) {
__di_commands = (struct dicommand*)ipclo;
IPC_SetBufferLo((void*)(ipclo+(sizeof(struct dicommand)*DI_CMDCTX_CNT)));
memset(__di_commands,0,(sizeof(struct dicommand)*DI_CMDCTX_CNT));
i = 0;
__lwp_queue_init_empty(&__di_contextq);
__lwp_queue_initialize(&inactives,__di_contexts,DI_CMDCTX_CNT,sizeof(struct dicontext));
while((ctx=(struct dicontext*)__lwp_queue_get(&inactives))!=NULL) {
ctx->cmd = &__di_commands[i];
ctx->cb = NULL;
__lwp_queue_append(&__di_contextq,&ctx->node);
i++;
}
}
ret = IOS_Open(__di_fs,0);
if(ret<0) return ret;
__dvd_fd = ret;
// __dvd_lowinitcalled = 1;
// printf("DVD_LowInit(%d)\n",ret);
}
return 0;
}
s32 bwDVD_LowInquiry(dvddrvinfo *info,dvdcallbacklow cb)
{
s32 ret;
struct dicontext *ctx;
struct dicommand *cmd;
__dvd_reqinprogress = 1;
ctx = __dvd_getcontext(cb);
if(ctx==NULL) return IPC_ENOMEM;
cmd = ctx->cmd;
cmd->diReg[0] = (IOCTL_DI_INQUIRY<<24);
ret = IOS_IoctlAsync(__dvd_fd,IOCTL_DI_INQUIRY,cmd->diReg,sizeof(struct dicommand),info,DVD_DRVINFSIZE,__dvd_iostransactionCB,ctx);
return ret;
}
s32 bwDVD_LowReadID(dvddiskid *diskID,dvdcallbacklow cb)
{
s32 ret = 0;
struct dicontext *ctx;
struct dicommand *cmd;
// printf("DVD_LowReadID()\n");
__dvd_reqinprogress = 1;
ctx = __dvd_getcontext(cb);
if(ctx==NULL) return IPC_ENOMEM;
cmd = ctx->cmd;
cmd->diReg[0] = (IOCTL_DI_READID<<24);
ret = IOS_IoctlAsync(__dvd_fd,IOCTL_DI_READID,cmd->diReg,sizeof(struct dicommand),diskID,DVD_DISKIDSIZE,__dvd_iostransactionCB,ctx);
// printf("DVD_LowReadID(%d)\n",ret);
return ret;
}
s32 bwDVD_LowRead(void *buf,u32 len,u32 offset,dvdcallbacklow cb)
{
s32 ret;
struct dicontext *ctx;
struct dicommand *cmd;
if(buf==NULL || ((u32)buf%32)!=0) return -1;
__dvd_reqinprogress = 1;
__dvd_readlength = len;
ctx = __dvd_getcontext(cb);
if(ctx==NULL) return IPC_ENOMEM;
cmd = ctx->cmd;
cmd->diReg[0] = (IOCTL_DI_READ<<24);
cmd->diReg[1] = len;
cmd->diReg[2] = offset;
ret = IOS_IoctlAsync(__dvd_fd,IOCTL_DI_READ,cmd->diReg,sizeof(struct dicommand),buf,len,__dvd_iostransactionCB,ctx);
return ret;
}
// never got this function working, probably removed from wii
s32 bwDVD_LowReadVideo(void *buf,u32 len,u32 offset,dvdcallbacklow cb)
{
s32 ret;
struct dicontext *ctx;
struct dicommand *cmd;
__dvd_reqinprogress = 1;
__dvd_readlength = len;
ctx = __dvd_getcontext(cb);
if(ctx==NULL) return IPC_ENOMEM;
cmd = ctx->cmd;
cmd->diReg[0] = (IOCTL_DI_READ_DVDVIDEO<<24);
cmd->diReg[1] = len;
cmd->diReg[2] = offset;
ret = IOS_IoctlAsync(__dvd_fd,IOCTL_DI_READ_DVDVIDEO,cmd->diReg,sizeof(struct dicommand),buf,len,__dvd_iostransactionCB,ctx);
return ret;
}
s32 bwDVD_LowStopLaser(dvdcallbacklow cb)
{
s32 ret;
struct dicontext *ctx;
struct dicommand *cmd;
__dvd_reqinprogress = 1;
ctx = __dvd_getcontext(cb);
if(ctx==NULL) return IPC_ENOMEM;
cmd = ctx->cmd;
cmd->diReg[0] = (IOCTL_DI_STOPLASER<<24);
ret = IOS_IoctlAsync(__dvd_fd,IOCTL_DI_STOPLASER,cmd->diReg,sizeof(struct dicommand),__di_regvalcache,0x20,__dvd_iostransactionCB,ctx);
return ret;
}
// never got this function working, probably removed from wii
s32 bwDVD_EnableVideo(dvdcallbacklow cb)
{
s32 ret;
struct dicontext *ctx;
struct dicommand *cmd;
__dvd_reqinprogress = 1;
ctx = __dvd_getcontext(cb);
if(ctx==NULL) return IPC_ENOMEM;
cmd = ctx->cmd;
cmd->diReg[0] = (IOCTL_DI_ENABLE_DVD<<24);
ret = IOS_IoctlAsync(__dvd_fd,IOCTL_DI_ENABLE_DVD,cmd->diReg,sizeof(struct dicommand),__di_regvalcache,0x20,__dvd_iostransactionCB,ctx);
return ret;
}
s32 bwDVD_LowSeek(u32 offset,dvdcallbacklow cb)
{
s32 ret;
struct dicontext *ctx;
struct dicommand *cmd;
__dvd_reqinprogress = 1;
ctx = __dvd_getcontext(cb);
if(ctx==NULL) return IPC_ENOMEM;
cmd = ctx->cmd;
cmd->diReg[0] = (IOCTL_DI_SEEK<<24);
cmd->diReg[1] = offset;
ret = IOS_IoctlAsync(__dvd_fd,IOCTL_DI_SEEK,cmd->diReg,sizeof(struct dicommand),NULL,0,__dvd_iostransactionCB,ctx);
return ret;
}
s32 bwDVD_LowOffset(u64 offset,dvdcallbacklow cb)
{
s32 ret;
u32 *off = (u32*)(void*)(&offset);
struct dicontext *ctx;
struct dicommand *cmd;
__dvd_reqinprogress = 1;
ctx = __dvd_getcontext(cb);
if(ctx==NULL) return IPC_ENOMEM;
cmd = ctx->cmd;
cmd->diReg[0] = (IOCTL_DI_OFFSET<<24);
cmd->diReg[1] = 0;
if(off[0]) cmd->diReg[1] = 1;
cmd->diReg[2] = off[1];
ret = IOS_IoctlAsync(__dvd_fd,IOCTL_DI_OFFSET,cmd->diReg,sizeof(struct dicommand),__di_regvalcache,0x20,__dvd_iostransactionCB,ctx);
return ret;
}
s32 bwDVD_LowPrepareCoverRegister(dvdcallbacklow cb)
{
s32 ret;
struct dicontext *ctx;
struct dicommand *cmd;
__dvd_reqinprogress = 1;
ctx = __dvd_getcontext(cb);
if(ctx==NULL) return IPC_ENOMEM;
cmd = ctx->cmd;
cmd->diReg[0] = (IOCTL_DI_COVER<<24);
ret = IOS_IoctlAsync(__dvd_fd,IOCTL_DI_COVER,cmd->diReg,sizeof(struct dicommand),__di_regbuffer,0x20,__dvd_ioscoverregisterCB,ctx);
return ret;
}
s32 bwDVD_LowOpenPartition(u32 offset,void *eticket,u32 certin_len,void *certificate_in,void *certificate_out,dvdcallbacklow cb)
{
s32 ret;
struct dicontext *ctx;
struct dicommand *cmd;
if(eticket!=NULL && ((u32)eticket%32)!=0) return -1;
if(certificate_in!=NULL && ((u32)certificate_in%32)!=0) return -1;
if(certificate_out!=NULL && ((u32)certificate_out%32)!=0) return -1;
__dvd_reqinprogress = 1;
ctx = __dvd_getcontext(cb);
if(ctx==NULL) return IPC_ENOMEM;
cmd = ctx->cmd;
cmd->diReg[0] = (IOCTL_DI_OPENPART<<24);
cmd->diReg[1] = offset;
__di_iovector[0].data = cmd;
__di_iovector[0].len = sizeof(struct dicommand);
__di_iovector[1].data = eticket;
if(eticket==NULL) __di_iovector[1].len = 0;
else __di_iovector[1].len = 676;
__di_iovector[2].data = certificate_in;
if(certificate_in==NULL) __di_iovector[2].len = 0;
else __di_iovector[2].len = certin_len;
__di_iovector[3].data = certificate_out;
__di_iovector[3].len = 18916;
__di_iovector[4].data = __di_lastticketerror;
__di_iovector[4].len = 0x20;
ret = IOS_IoctlvAsync(__dvd_fd,IOCTL_DI_OPENPART,3,2,__di_iovector,__dvd_iostransactionCB,ctx);
return ret;
}
s32 bwDVD_LowClosePartition(dvdcallbacklow cb)
{
s32 ret;
struct dicontext *ctx;
struct dicommand *cmd;
__dvd_reqinprogress = 1;
ctx = __dvd_getcontext(cb);
if(ctx==NULL) return IPC_ENOMEM;
cmd = ctx->cmd;
cmd->diReg[0] = (IOCTL_DI_CLOSEPART<<24);
ret = IOS_IoctlAsync(__dvd_fd,IOCTL_DI_CLOSEPART,cmd->diReg,sizeof(struct dicommand),NULL,0,__dvd_iostransactionCB,ctx);
return ret;
}
s32 bwDVD_LowUnencryptedRead(void *buf,u32 len,u32 offset,dvdcallbacklow cb)
{
s32 ret;
struct dicontext *ctx;
struct dicommand *cmd;
__dvd_reqinprogress = 1;
__dvd_readlength = len;
ctx = __dvd_getcontext(cb);
if(ctx==NULL) return IPC_ENOMEM;
cmd = ctx->cmd;
cmd->diReg[0] = (IOCTL_DI_UNENCREAD<<24);
cmd->diReg[1] = len;
cmd->diReg[2] = offset;
ret = IOS_IoctlAsync(__dvd_fd,IOCTL_DI_UNENCREAD,cmd->diReg,sizeof(struct dicommand),buf,len,__dvd_iostransactionCB,ctx);
return ret;
}
s32 bwDVD_LowWaitCoverClose(dvdcallbacklow cb)
{
s32 ret;
struct dicontext *ctx;
struct dicommand *cmd;
__dvd_reqinprogress = 1;
ctx = __dvd_getcontext(cb);
if(ctx==NULL) return IPC_ENOMEM;
cmd = ctx->cmd;
cmd->diReg[0] = (IOCTL_DI_WAITCVRCLOSE<<24);
ret = IOS_IoctlAsync(__dvd_fd,IOCTL_DI_WAITCVRCLOSE,cmd->diReg,sizeof(struct dicommand),NULL,0,__dvd_ioscovercloseCB,ctx);
return ret;
}
s32 bwDVD_LowResetNotify()
{
s32 ret;
struct dicontext *ctx;
struct dicommand *cmd;
if(__dvd_cbinprogress==1) return -1;
ctx = __dvd_getcontext(NULL);
if(ctx==NULL) return IPC_ENOMEM;
cmd = ctx->cmd;
cmd->diReg[0] = (IOCTL_DI_RESETNOTIFY<<24);
ret = IOS_Ioctl(__dvd_fd,IOCTL_DI_RESETNOTIFY,cmd->diReg,sizeof(struct dicommand),NULL,0);
return ret;
}
s32 bwDVD_LowReset(dvdcallbacklow cb)
{
s32 ret;
struct dicontext *ctx;
struct dicommand *cmd;
// printf("DVD_LowReset()\n");
__dvd_reqinprogress = 1;
ctx = __dvd_getcontext(cb);
if(ctx==NULL) return IPC_ENOMEM;
cmd = ctx->cmd;
cmd->diReg[0] = (IOCTL_DI_RESET<<24);
cmd->diReg[1] = __dvd_spinupval;
ret = IOS_IoctlAsync(__dvd_fd,IOCTL_DI_RESET,cmd->diReg,sizeof(struct dicommand),NULL,0,__dvd_iostransactionCB,ctx);
// printf("DVD_LowReset(%d)\n",ret);
return ret;
}
s32 bwDVD_LowStopMotor(u8 stop1,u8 stop2,dvdcallbacklow cb)
{
s32 ret;
struct dicontext *ctx;
struct dicommand *cmd;
__dvd_reqinprogress = 1;
ctx = __dvd_getcontext(cb);
if(ctx==NULL) return IPC_ENOMEM;
cmd = ctx->cmd;
cmd->diReg[0] = (IOCTL_DI_STOPMOTOR<<24);
cmd->diReg[1] = (stop1<<24);
cmd->diReg[2] = (stop2<<24);
ret = IOS_IoctlAsync(__dvd_fd,IOCTL_DI_STOPMOTOR,cmd->diReg,sizeof(struct dicommand),__di_regvalcache,0x20,__dvd_iostransactionCB,ctx);
return ret;
}
s32 bwDVD_LowRequestError(dvdcallbacklow cb)
{
s32 ret;
struct dicontext *ctx;
struct dicommand *cmd;
__dvd_reqinprogress = 1;
ctx = __dvd_getcontext(cb);
if(ctx==NULL) return IPC_ENOMEM;
cmd = ctx->cmd;
cmd->diReg[0] = (IOCTL_DI_REQERROR<<24);
ret = IOS_IoctlAsync(__dvd_fd,IOCTL_DI_REQERROR,cmd->diReg,sizeof(struct dicommand),__di_regvalcache,0x20,__dvd_iostransactionCB,ctx);
return ret;
}
s32 bwDVD_SetDecryption(s32 mode, dvdcallbacklow cb)
{
s32 ret;
struct dicontext *ctx;
struct dicommand *cmd;
__dvd_reqinprogress = 1;
ctx = __dvd_getcontext(cb);
if(ctx==NULL) return IPC_ENOMEM;
cmd = ctx->cmd;
cmd->diReg[0] = (IOCTL_DI_SETCRYPTMODE<<24);
cmd->diReg[1] = mode;
ret = IOS_IoctlAsync(__dvd_fd,IOCTL_DI_SETCRYPTMODE,cmd->diReg,sizeof(struct dicommand),__di_regvalcache,0x20,__dvd_iostransactionCB,ctx);
return ret;
}
s32 bwDVD_SetOffset(u32 offset, dvdcallbacklow cb)
{
s32 ret;
struct dicontext *ctx;
struct dicommand *cmd;
__dvd_reqinprogress = 1;
ctx = __dvd_getcontext(cb);
if(ctx==NULL) return IPC_ENOMEM;
cmd = ctx->cmd;
cmd->diReg[0] = (IOCTL_DI_SETOFFBASE<<24);
cmd->diReg[1] = offset;
ret = IOS_IoctlAsync(__dvd_fd,IOCTL_DI_SETOFFBASE,cmd->diReg,sizeof(struct dicommand),__di_regvalcache,0x20,__dvd_iostransactionCB,ctx);
return ret;
}

53
source/dvd_broadway.h Normal file
View File

@ -0,0 +1,53 @@
/*
* Copyright (C) 2008 Nuke (wiinuke@gmail.com)
*
* this file is part of GeckoOS for USB Gecko
* http://www.usbgecko.com
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef __DVD_BROADWAY_H__
#define __DVD_BROADWAY_H__
#include <gctypes.h>
#include <ogc/ipc.h>
#include <ogc/dvd.h>
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
typedef void (*dvdcallbacklow)(s32 result);
s32 bwDVD_LowInit();
s32 bwDVD_LowInquiry(dvddrvinfo *info,dvdcallbacklow cb);
s32 bwDVD_LowReadID(dvddiskid *diskID,dvdcallbacklow cb);
s32 bwDVD_LowClosePartition(dvdcallbacklow cb);
s32 bwDVD_LowOpenPartition(u32 offset,void *eticket,u32 certin_len,void *certificate_in,void *certificate_out,dvdcallbacklow cb);
s32 bwDVD_LowUnencryptedRead(void *buf,u32 len,u32 offset,dvdcallbacklow cb);
s32 bwDVD_LowReset(dvdcallbacklow cb);
s32 bwDVD_LowWaitCoverClose(dvdcallbacklow cb);
s32 bwDVD_LowRead(void *buf,u32 len,u32 offset,dvdcallbacklow cb);
s32 bwDVD_EnableVideo(dvdcallbacklow cb);
s32 bwDVD_LowReadVideo(void *buf,u32 len,u32 offset,dvdcallbacklow cb);
s32 bwDVD_SetDecryption(s32 mode, dvdcallbacklow cb);
s32 bwDVD_SetOffset(u32 offset, dvdcallbacklow cb);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif

212
source/filelist.h Normal file
View File

@ -0,0 +1,212 @@
/****************************************************************************
* libwiigui Template
* Tantric 2009
*
* imagelist.h
* Contains a list of all of the files in the images, fonts, sounds folders
***************************************************************************/
#ifndef _FILELIST_H_
#define _FILELIST_H_
#include <gccore.h>
extern const u8 font_ttf[];
extern const u32 font_ttf_size;
extern const u8 sdcard_png[];
extern const u32 sdcard_png_size;
extern const u8 bg_music_ogg[];
extern const u32 bg_music_ogg_size;
extern const u8 credits_music_ogg[];
extern const u32 credits_music_ogg_size;
extern const u8 credits_button_png[];
extern const u32 credits_button_png_size;
extern const u8 credits_button_over_png[];
extern const u32 credits_button_over_png_size;
extern const u8 button_over_pcm[];
extern const u32 button_over_pcm_size;
extern const u8 button_click_pcm[];
extern const u32 button_click_pcm_size;
extern const u8 button_click2_pcm[];
extern const u32 button_click2_pcm_size;
extern const u8 tooltip_png[];
extern const u32 tooltip_png_size;
extern const u8 startgame_arrow_left_png[];
extern const u32 startgame_arrow_left_png_size;
extern const u8 startgame_arrow_right_png[];
extern const u32 startgame_arrow_right_png_size;
extern const u8 tooltip_medium_png[];
extern const u32 tooltip_medium_png_size;
extern const u8 tooltip_large_png[];
extern const u32 tooltip_large_png_size;
extern const u8 credits_bg_png[];
extern const u32 credits_bg_png_size;
extern const u8 little_star_png[];
extern const u32 little_star_png_size;
extern const u8 background_png[];
extern const u32 background_png_size;
extern const u8 wbackground_png[];
extern const u32 wbackground_png_size;
extern const u8 bg_options_settings_png[];
extern const u32 bg_options_settings_png_size;
extern const u8 settings_background_png[];
extern const u32 settings_background_png_size;
extern const u8 nocover_png[];
extern const u32 nocover_png_size;
extern const u8 nodisc_png[];
extern const u32 nodisc_png_size;
extern const u8 button_install_png[];
extern const u32 button_install_png_size;
extern const u8 button_install_over_png[];
extern const u32 button_install_over_png_size;
extern const u8 dialogue_box_startgame_png[];
extern const u32 dialogue_box_startgame_png_size;
extern const u8 wdialogue_box_startgame_png[];
extern const u32 wdialogue_box_startgame_png_size;
extern const u8 button_dialogue_box_startgame_png[];
extern const u32 button_dialogue_box_startgame_size;
extern const u8 button_dialogue_box_png[];
extern const u32 button_dialogue_box_size;
extern const u8 keyboard_textbox_png[];
extern const u32 keyboard_textbox_png_size;
extern const u8 keyboard_key_png[];
extern const u32 keyboard_key_png_size;
extern const u8 keyboard_key_over_png[];
extern const u32 keyboard_key_over_png_size;
extern const u8 keyboard_mediumkey_png[];
extern const u32 keyboard_mediumkey_png_size;
extern const u8 keyboard_mediumkey_over_png[];
extern const u32 keyboard_mediumkey_over_png_size;
extern const u8 keyboard_largekey_png[];
extern const u32 keyboard_largekey_png_size;
extern const u8 keyboard_largekey_over_png[];
extern const u32 keyboard_largekey_over_png_size;
extern const u8 menu_button_png[];
extern const u32 menu_button_size;
extern const u8 menu_button_over_png[];
extern const u32 menu_button_over_size;
extern const u8 settings_button_png[];
extern const u32 settings_button_size;
extern const u8 settings_button_over_png[];
extern const u32 settings_button_over_size;
extern const u8 settings_menu_button_png[];
extern const u32 settings_menu_button_size;
extern const u8 wiimote_poweroff_png[];
extern const u32 wiimote_poweroff_png_size;
extern const u8 dialogue_box_png[];
extern const u32 dialogue_box_png_size;
extern const u8 wiimote_poweroff_over_png[];
extern const u32 wiimote_poweroff_over_png_size;
extern const u8 bg_options_png[];
extern const u32 bg_options_png_size;
extern const u8 bg_options_entry_png[];
extern const u32 bg_options_entry_png_size;
extern const u8 scrollbar_png[];
extern const u32 scrollbar_png_size;
extern const u8 scrollbar_arrowup_png[];
extern const u32 scrollbar_arrowup_png_size;
extern const u8 scrollbar_arrowup_over_png[];
extern const u32 scrollbar_arrowup_over_png_size;
extern const u8 scrollbar_arrowdown_png[];
extern const u32 scrollbar_arrowdown_png_size;
extern const u8 scrollbar_arrowdown_over_png[];
extern const u32 scrollbar_arrowdown_over_png_size;
extern const u8 scrollbar_box_png[];
extern const u32 scrollbar_box_png_size;
extern const u8 scrollbar_box_over_png[];
extern const u32 scrollbar_box_over_png_size;
extern const u8 progressbar_png[];
extern const u32 progressbar_png_size;
extern const u8 progressbar_empty_png[];
extern const u32 progressbar_empty_png_size;
extern const u8 progressbar_outline_png[];
extern const u32 progressbar_outline_png_size;
extern const u8 player1_point_png[];
extern const u32 player1_point_png_size;
extern const u8 player2_point_png[];
extern const u32 player2_point_png_size;
extern const u8 player3_point_png[];
extern const u32 player3_point_png_size;
extern const u8 player4_point_png[];
extern const u32 player4_point_png_size;
extern const u8 player1_grab_png[];
extern const u32 player1_grab_png_size;
extern const u8 player2_grab_png[];
extern const u32 player2_grab_png_size;
extern const u8 player3_grab_png[];
extern const u32 player3_grab_png_size;
extern const u8 player4_grab_png[];
extern const u32 player4_grab_png_size;
extern const u8 battery_bar_png[];
extern const u32 battery_bar_png_size;
extern const u8 battery_red_png[];
extern const u32 battery_red_png_size;
extern const u8 battery_png[];
extern const u32 battery_png_size;
#endif

BIN
source/fonts/font.ttf Normal file

Binary file not shown.

115
source/fst.c Normal file
View File

@ -0,0 +1,115 @@
/*
* Copyright (C) 2008 Nuke (wiinuke@gmail.com)
*
* this file is part of GeckoOS for USB Gecko
* http://www.usbgecko.com
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <gccore.h>
#include <malloc.h>
#include <sys/unistd.h>
#include <fat.h>
#include <sdcard/wiisd_io.h>
#include "ogc/ipc.h"
#include "fst.h"
#include "dvd_broadway.h"
#include "wpad.h"
#define FSTDIRTYPE 1
#define FSTFILETYPE 0
#define ENTRYSIZE 0xC
#define FILEDIR "SD:/codes"
#define MAX_FILENAME_LEN 128
static vu32 dvddone = 0;
// Real basic
u32 do_sd_code(char *filename)
{
FILE *fp;
u8 *filebuff;
u32 filesize;
u32 ret;
char filepath[128];
__io_wiisd.startup();
ret = fatMountSimple("SD", &__io_wiisd);
if (!ret) {
return 0;
}
fflush(stdout);
sprintf(filepath, FILEDIR "/%s", filename);
filepath[16] = 0x2E;
filepath[17] = 0x67;
filepath[18] = 0x63;
filepath[19] = 0x74;
filepath[20] = 0;
//printf("filename %s\n",filepath);
fp = fopen(filepath, "rb");
if (!fp) {
fatUnmount("SD");
__io_wiisd.shutdown();
return 0;
}
fseek(fp, 0, SEEK_END);
filesize = ftell(fp);
fseek(fp, 0, SEEK_SET);
filebuff = (u8*) malloc (filesize);
if(filebuff == 0){
fclose(fp);
sleep(2);
return 0;
}
ret = fread(filebuff, 1, filesize, fp);
if(ret != filesize){
free(filebuff);
fclose(fp);
fatUnmount("SD");
__io_wiisd.shutdown();
return 0;
}
memcpy((void*)0x800027E8,filebuff,filesize);
*(vu8*)0x80001807 = 0x01;
free(filebuff);
fclose(fp);
fatUnmount("SD");
__io_wiisd.shutdown();
return 1;
}

27
source/fst.h Normal file
View File

@ -0,0 +1,27 @@
/*
* Copyright (C) 2008 Nuke (wiinuke@gmail.com)
*
* this file is part of GeckoOS for USB Gecko
* http://www.usbgecko.com
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef __FST_H__
#define __FST_H__
//u32 do_fst(u32 fstlocation);
u32 do_sd_code(char *filename);
#endif

15
source/fwrite_patch.h Normal file
View File

@ -0,0 +1,15 @@
unsigned char fwrite_patch_bin[] = {
0x7c, 0x84, 0x29, 0xd6, 0x39, 0x40, 0x00, 0x00, 0x94, 0x21, 0xff, 0xf0,
0x93, 0xe1, 0x00, 0x0c, 0x7f, 0x8a, 0x20, 0x00, 0x40, 0x9c, 0x00, 0x64,
0x3d, 0x00, 0xcd, 0x00, 0x3d, 0x60, 0xcd, 0x00, 0x3d, 0x20, 0xcd, 0x00,
0x61, 0x08, 0x68, 0x14, 0x61, 0x6b, 0x68, 0x24, 0x61, 0x29, 0x68, 0x20,
0x39, 0x80, 0x00, 0xd0, 0x38, 0xc0, 0x00, 0x19, 0x38, 0xe0, 0x00, 0x00,
0x91, 0x88, 0x00, 0x00, 0x7c, 0x03, 0x50, 0xae, 0x54, 0x00, 0xa0, 0x16,
0x64, 0x00, 0xb0, 0x00, 0x90, 0x0b, 0x00, 0x00, 0x90, 0xc9, 0x00, 0x00,
0x80, 0x09, 0x00, 0x00, 0x70, 0x1f, 0x00, 0x01, 0x40, 0x82, 0xff, 0xf8,
0x80, 0x0b, 0x00, 0x00, 0x90, 0xe8, 0x00, 0x00, 0x54, 0x00, 0x37, 0xfe,
0x7d, 0x4a, 0x02, 0x14, 0x7f, 0x8a, 0x20, 0x00, 0x41, 0x9c, 0xff, 0xc8,
0x7c, 0xa3, 0x2b, 0x78, 0x83, 0xe1, 0x00, 0x0c, 0x38, 0x21, 0x00, 0x10,
0x4e, 0x80, 0x00, 0x20
};
unsigned int fwrite_patch_bin_len = 136;

60
source/geckomenu.h Normal file
View File

@ -0,0 +1,60 @@
/*
* Copyright (C) 2008 Nuke (wiinuke@gmail.com)
*
* this file is part of GeckoOS for USB Gecko
* http://www.usbgecko.com
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef __GECKOMENU_H__
#define __GECKOMENU_H__
#define ROOTMENU 0
#define ABOUTMENU 1
#define CONFIGMENU 2
#define REBOOTMENU 3
#define root_itemcount 7
#define about_itemcount 4
#define config_itemcount 9
#define rebooter_itemcount 6
u32 currentmenu; // 0 ROOT
u32 rootmenu_item;
u32 menufreeze;
u32 langselect;
u32 langsaved;
u32 pal60select;
u32 pal50select;
u32 viselect;
u32 ntscselect;
u32 hookselect;
u32 ocarinaselect;
u32 recoveryselect;
u32 regionfreeselect;
u32 nocopyselect;
u32 buttonskipselect;
u32 doprogress(u32 progstate, u32 noelements);
void drawmenu(u32 menuid);
void drawselected(u32 menuidpos);
void processwpad();
void clearscreen(u32 *framebuffer, u16 xscreen, u16 yscreen, u16 width, u16 height, u32 color);
void drawicon(u32 *framebuffer, u16 xscreen, u16 yscreen, u16 width, u16 height, u32 gicon);
u32 CvtRGB (u8 r1, u8 g1, u8 b1, u8 r2, u8 g2, u8 b2);
#endif // __GECKOLOAD_H__

234
source/http.c Normal file
View File

@ -0,0 +1,234 @@
#include "http.h"
/**
* Emptyblock is a statically defined variable for functions to return if they are unable
* to complete a request
*/
const struct block emptyblock = {0, NULL};
//The maximum amount of bytes to send per net_write() call
#define NET_BUFFER_SIZE 1024
// Write our message to the server
static s32 send_message(s32 server, char *msg) {
s32 bytes_transferred = 0;
s32 remaining = strlen(msg);
while (remaining) {
if ((bytes_transferred = net_write(server, msg, remaining > NET_BUFFER_SIZE ? NET_BUFFER_SIZE : remaining)) > 0) {
remaining -= bytes_transferred;
usleep (20 * 1000);
} else if (bytes_transferred < 0) {
return bytes_transferred;
} else {
return -ENODATA;
}
}
return 0;
}
/**
* Connect to a remote server via TCP on a specified port
*
* @param u32 ip address of the server to connect to
* @param u32 the port to connect to on the server
* @return s32 The connection to the server (negative number if connection could not be established)
*/
static s32 server_connect(u32 ipaddress, u32 socket_port) {
//Initialize socket
s32 connection = net_socket(AF_INET, SOCK_STREAM, IPPROTO_IP);
if (connection < 0) return connection;
struct sockaddr_in connect_addr;
memset(&connect_addr, 0, sizeof(connect_addr));
connect_addr.sin_family = AF_INET;
connect_addr.sin_port = socket_port;
connect_addr.sin_addr.s_addr= ipaddress;
//Attemt to open the socket
if (net_connect(connection, (struct sockaddr*)&connect_addr, sizeof(connect_addr)) == -1) {
net_close(connection);
return -1;
}
return connection;
}
//The amount of memory in bytes reserved initially to store the HTTP response in
//Be careful in increasing this number, reading from a socket on the Wii
//will fail if you request more than 20k or so
#define HTTP_BUFFER_SIZE 1024 * 5
//The amount of memory the buffer should expanded with if the buffer is full
#define HTTP_BUFFER_GROWTH 1024 * 5
/**
* This function reads all the data from a connection into a buffer which it returns.
* It will return an empty buffer if something doesn't go as planned
*
* @param s32 connection The connection identifier to suck the response out of
* @return block A 'block' struct (see http.h) in which the buffer is located
*/
struct block read_message(s32 connection)
{
//Create a block of memory to put in the response
struct block buffer;
buffer.data = malloc(HTTP_BUFFER_SIZE);
buffer.size = HTTP_BUFFER_SIZE;
if(buffer.data == NULL) {
return emptyblock;
}
//The offset variable always points to the first byte of memory that is free in the buffer
u32 offset = 0;
while(1)
{
//Fill the buffer with a new batch of bytes from the connection,
//starting from where we left of in the buffer till the end of the buffer
s32 bytes_read = net_read(connection, buffer.data + offset, buffer.size - offset);
//Anything below 0 is an error in the connection
if(bytes_read < 0)
{
//printf("Connection error from net_read() Errorcode: %i\n", bytes_read);
return emptyblock;
}
//No more bytes were read into the buffer,
//we assume this means the HTTP response is done
if(bytes_read == 0)
{
break;
}
offset += bytes_read;
//Check if we have enough buffer left over,
//if not expand it with an additional HTTP_BUFFER_GROWTH worth of bytes
if(offset >= buffer.size)
{
buffer.size += HTTP_BUFFER_GROWTH;
buffer.data = realloc(buffer.data, buffer.size);
if(buffer.data == NULL)
{
return emptyblock;
}
}
}
//At the end of above loop offset should be precisely the amount of bytes that were read from the connection
buffer.size = offset;
//Shrink the size of the buffer so the data fits exactly in it
realloc(buffer.data, buffer.size);
return buffer;
}
/**
* Downloads the contents of a URL to memory
* This method is not threadsafe (because networking is not threadsafe on the Wii)
*/
struct block downloadfile(const char *url)
{
//Check if the url starts with "http://", if not it is not considered a valid url
if(strncmp(url, "http://", strlen("http://")) != 0)
{
//printf("URL '%s' doesn't start with 'http://'\n", url);
return emptyblock;
}
//Locate the path part of the url by searching for '/' past "http://"
char *path = strchr(url + strlen("http://"), '/');
//At the very least the url has to end with '/', ending with just a domain is invalid
if(path == NULL)
{
//printf("URL '%s' has no PATH part\n", url);
return emptyblock;
}
//Extract the domain part out of the url
int domainlength = path - url - strlen("http://");
if(domainlength == 0)
{
//printf("No domain part in URL '%s'\n", url);
return emptyblock;
}
char domain[domainlength + 1];
strncpy(domain, url + strlen("http://"), domainlength);
domain[domainlength] = '\0';
//Parsing of the URL is done, start making an actual connection
u32 ipaddress = getipbynamecached(domain);
if(ipaddress == 0)
{
//printf("\ndomain %s could not be resolved", domain);
return emptyblock;
}
s32 connection = server_connect(ipaddress, 80);
if(connection < 0) {
//printf("Error establishing connection");
return emptyblock;
}
//Form a nice request header to send to the webserver
char* headerformat = "GET %s HTTP/1.0\r\nHost: %s\r\nUser-Agent: WiiEarthh 1.0\r\n\r\n";;
char header[strlen(headerformat) + strlen(domain) + strlen(path)];
sprintf(header, headerformat, path, domain);
//Do the request and get the response
send_message(connection, header);
struct block response = read_message(connection);
net_close(connection);
//Search for the 4-character sequence \r\n\r\n in the response which signals the start of the http payload (file)
unsigned char *filestart = NULL;
u32 filesize = 0;
int i;
for(i = 3; i < response.size; i++)
{
if(response.data[i] == '\n' &&
response.data[i-1] == '\r' &&
response.data[i-2] == '\n' &&
response.data[i-3] == '\r')
{
filestart = response.data + i + 1;
filesize = response.size - i - 1;
break;
}
}
if(filestart == NULL)
{
//printf("HTTP Response was without a file\n");
free(response.data);
return emptyblock;
}
//Copy the file part of the response into a new memoryblock to return
struct block file;
file.data = malloc(filesize);
file.size = filesize;
if(file.data == NULL)
{
//printf("No more memory to copy file from HTTP response\n");
free(response.data);
return emptyblock;
}
memcpy(file.data, filestart, filesize);
//Dispose of the original response
free(response.data);
return file;
}

38
source/http.h Normal file
View File

@ -0,0 +1,38 @@
#ifndef _HTTP_H_
#define _HTTP_H_
#include <errno.h>
#include <network.h>
#include <ogcsys.h>
#include <string.h>
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include <errno.h>
#ifdef __cplusplus
extern "C"
{
#endif
#include "dns.h"
/**
* A simple structure to keep track of the size of a malloc()ated block of memory
*/
struct block
{
u32 size;
unsigned char *data;
};
extern const struct block emptyblock;
struct block downloadfile(const char *url);
#ifdef __cplusplus
}
#endif
#endif /* _HTTP_H_ */

Binary file not shown.

After

Width:  |  Height:  |  Size: 50 KiB

BIN
source/images/battery.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 118 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 225 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 225 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 59 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 653 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 907 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1017 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1005 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 961 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 952 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.9 KiB

BIN
source/images/nocover.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

BIN
source/images/nodisc.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 241 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 224 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

BIN
source/images/scrollbar.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 441 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 945 B

BIN
source/images/sdcard.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

BIN
source/images/tooltip.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 43 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

115
source/input.cpp Normal file
View File

@ -0,0 +1,115 @@
/****************************************************************************
* libwiigui Template
* Tantric 2009
*
* input.cpp
* Wii/GameCube controller management
***************************************************************************/
#include <gccore.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <ogcsys.h>
#include <unistd.h>
#include <wiiuse/wpad.h>
#include "menu.h"
#include "video.h"
#include "input.h"
#include "libwiigui/gui.h"
int rumbleRequest[4] = {0,0,0,0};
GuiTrigger userInput[4];
static int rumbleCount[4] = {0,0,0,0};
/****************************************************************************
* ShutoffRumble
***************************************************************************/
void ShutoffRumble()
{
for(int i=0;i<4;i++)
{
WPAD_Rumble(i, 0);
rumbleCount[i] = 0;
}
}
/****************************************************************************
* DoRumble
***************************************************************************/
void DoRumble(int i)
{
if(rumbleRequest[i] && rumbleCount[i] < 3)
{
WPAD_Rumble(i, 1); // rumble on
rumbleCount[i]++;
}
else if(rumbleRequest[i])
{
rumbleCount[i] = 20;
rumbleRequest[i] = 0;
}
else
{
if(rumbleCount[i])
rumbleCount[i]--;
WPAD_Rumble(i, 0); // rumble off
}
}
/****************************************************************************
* WPAD_Stick
*
* Get X/Y value from Wii Joystick (classic, nunchuk) input
***************************************************************************/
s8 WPAD_Stick(u8 chan, u8 right, int axis)
{
float mag = 0.0;
float ang = 0.0;
WPADData *data = WPAD_Data(chan);
switch (data->exp.type)
{
case WPAD_EXP_NUNCHUK:
case WPAD_EXP_GUITARHERO3:
if (right == 0)
{
mag = data->exp.nunchuk.js.mag;
ang = data->exp.nunchuk.js.ang;
}
break;
case WPAD_EXP_CLASSIC:
if (right == 0)
{
mag = data->exp.classic.ljs.mag;
ang = data->exp.classic.ljs.ang;
}
else
{
mag = data->exp.classic.rjs.mag;
ang = data->exp.classic.rjs.ang;
}
break;
default:
break;
}
/* calculate x/y value (angle need to be converted into radian) */
if (mag > 1.0) mag = 1.0;
else if (mag < -1.0) mag = -1.0;
double val;
if(axis == 0) // x-axis
val = mag * sin((PI * ang)/180.0f);
else // y-axis
val = mag * cos((PI * ang)/180.0f);
return (s8)(val * 128.0f);
}

23
source/input.h Normal file
View File

@ -0,0 +1,23 @@
/****************************************************************************
* libwiigui Template
* Tantric 2009
*
* input.h
* Wii/GameCube controller management
***************************************************************************/
#ifndef _INPUT_H_
#define _INPUT_H_
#include <gccore.h>
#include <wiiuse/wpad.h>
#define PI 3.14159265f
#define PADCAL 50
extern int rumbleRequest[4];
void ShutoffRumble();
void DoRumble(int i);
#endif

264
source/kenobiwii.h Normal file
View File

@ -0,0 +1,264 @@
/*
This file was autogenerated by raw2c.
Visit http://www.devkitpro.org
*/
const unsigned char kenobiwii[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x26, 0xa0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x94, 0x21, 0xff, 0x58, 0x90, 0x01, 0x00, 0x08,
0x7c, 0x08, 0x02, 0xa6, 0x90, 0x01, 0x00, 0xac, 0x7c, 0x00, 0x00, 0x26, 0x90, 0x01, 0x00, 0x0c,
0x7c, 0x09, 0x02, 0xa6, 0x90, 0x01, 0x00, 0x10, 0x7c, 0x01, 0x02, 0xa6, 0x90, 0x01, 0x00, 0x14,
0xbc, 0x61, 0x00, 0x18, 0x7f, 0x20, 0x00, 0xa6, 0x63, 0x3a, 0x20, 0x00, 0x73, 0x5a, 0xf9, 0xff,
0x7f, 0x40, 0x01, 0x24, 0xd8, 0x41, 0x00, 0x98, 0xd8, 0x61, 0x00, 0xa0, 0x3f, 0xe0, 0x80, 0x00,
0x3e, 0x80, 0xcc, 0x00, 0xa3, 0x94, 0x40, 0x10, 0x63, 0x95, 0x00, 0xff, 0xb2, 0xb4, 0x40, 0x10,
0x48, 0x00, 0x06, 0xb1, 0x3a, 0xa0, 0x00, 0x00, 0x3a, 0xc0, 0x00, 0x19, 0x3a, 0xe0, 0x00, 0xd0,
0x3f, 0x00, 0xcd, 0x00, 0x63, 0xf2, 0x26, 0xa0, 0x80, 0x01, 0x00, 0xac, 0x90, 0x12, 0x00, 0x04,
0x92, 0xb8, 0x64, 0x3c, 0x48, 0x00, 0x04, 0x85, 0x41, 0x82, 0x05, 0xfc, 0x2c, 0x1d, 0x00, 0x04,
0x40, 0x80, 0x00, 0x10, 0x2c, 0x1d, 0x00, 0x01, 0x41, 0x80, 0x05, 0xec, 0x48, 0x00, 0x03, 0xa8,
0x41, 0x82, 0x05, 0x48, 0x2c, 0x1d, 0x00, 0x06, 0x41, 0x82, 0x00, 0x8c, 0x2c, 0x1d, 0x00, 0x07,
0x41, 0x82, 0x03, 0x8c, 0x2c, 0x1d, 0x00, 0x08, 0x41, 0x82, 0x05, 0xd8, 0x2c, 0x1d, 0x00, 0x09,
0x41, 0x82, 0x00, 0xa0, 0x2c, 0x1d, 0x00, 0x10, 0x41, 0x82, 0x00, 0x98, 0x2c, 0x1d, 0x00, 0x2f,
0x41, 0x82, 0x00, 0x70, 0x2c, 0x1d, 0x00, 0x30, 0x41, 0x82, 0x00, 0x78, 0x2c, 0x1d, 0x00, 0x38,
0x41, 0x82, 0x05, 0x80, 0x2c, 0x1d, 0x00, 0x40, 0x41, 0x82, 0x03, 0x9c, 0x2c, 0x1d, 0x00, 0x41,
0x41, 0x82, 0x03, 0xb0, 0x2c, 0x1d, 0x00, 0x44, 0x41, 0x82, 0x00, 0x68, 0x2c, 0x1d, 0x00, 0x50,
0x41, 0x82, 0x00, 0x20, 0x2c, 0x1d, 0x00, 0x60, 0x41, 0x82, 0x00, 0x24, 0x2c, 0x1d, 0x00, 0x89,
0x41, 0x82, 0x00, 0x50, 0x2c, 0x1d, 0x00, 0x99, 0x41, 0x82, 0x05, 0x64, 0x48, 0x00, 0x05, 0x68,
0x80, 0x72, 0x00, 0x00, 0x48, 0x00, 0x04, 0x81, 0x48, 0x00, 0x05, 0x5c, 0x48, 0x00, 0x05, 0xe5,
0x48, 0x00, 0x05, 0x54, 0x38, 0x80, 0x00, 0x01, 0x90, 0x92, 0x00, 0x00, 0x48, 0x00, 0x05, 0x48,
0x48, 0x00, 0x04, 0x61, 0x3a, 0x00, 0x00, 0xa0, 0x63, 0xec, 0x26, 0xc4, 0x48, 0x00, 0x03, 0x6c,
0x38, 0x60, 0x01, 0x20, 0x63, 0xec, 0x26, 0xc4, 0x48, 0x00, 0x04, 0x21, 0x48, 0x00, 0x05, 0x28,
0x2f, 0x1d, 0x00, 0x10, 0x2e, 0x9d, 0x00, 0x44, 0x63, 0xe4, 0x1a, 0xb4, 0x3c, 0x60, 0x80, 0x00,
0x60, 0x63, 0x03, 0x00, 0x48, 0x00, 0x05, 0x65, 0x38, 0x63, 0x0a, 0x00, 0x48, 0x00, 0x05, 0x5d,
0x38, 0x63, 0x06, 0x00, 0x48, 0x00, 0x05, 0x55, 0x63, 0xec, 0x26, 0xb4, 0x92, 0xac, 0x00, 0x00,
0x92, 0xac, 0x00, 0x04, 0x92, 0xac, 0x00, 0x08, 0x63, 0xe4, 0x26, 0xc4, 0x81, 0x24, 0x00, 0x18,
0x80, 0x72, 0x00, 0x00, 0x2c, 0x03, 0x00, 0x02, 0x40, 0x82, 0x00, 0x0c, 0x41, 0x96, 0x00, 0x0c,
0x48, 0x00, 0x00, 0x20, 0x38, 0x60, 0x00, 0x00, 0x90, 0x6c, 0x00, 0x0c, 0x40, 0x82, 0x00, 0x14,
0x40, 0x96, 0x00, 0x10, 0x61, 0x29, 0x04, 0x00, 0x91, 0x24, 0x00, 0x18, 0x48, 0x00, 0x02, 0x70,
0x55, 0x29, 0x05, 0xa8, 0x91, 0x24, 0x00, 0x18, 0x41, 0x96, 0x04, 0xac, 0x41, 0x9a, 0x00, 0x08,
0x39, 0x8c, 0x00, 0x04, 0x38, 0x60, 0x00, 0x04, 0x48, 0x00, 0x03, 0x61, 0x40, 0x99, 0x00, 0x10,
0x39, 0x8c, 0x00, 0x04, 0x38, 0x60, 0x00, 0x04, 0x48, 0x00, 0x03, 0x51, 0x63, 0xe4, 0x26, 0xb4,
0x80, 0x64, 0x00, 0x00, 0x80, 0x84, 0x00, 0x04, 0x7c, 0x72, 0xfb, 0xa6, 0x7c, 0x95, 0xfb, 0xa6,
0x48, 0x00, 0x04, 0x74, 0x7c, 0x32, 0x43, 0xa6, 0x7c, 0x3a, 0x02, 0xa6, 0x7c, 0x73, 0x43, 0xa6,
0x7c, 0x7b, 0x02, 0xa6, 0x54, 0x63, 0x05, 0xa8, 0x90, 0x60, 0x26, 0xdc, 0x54, 0x63, 0x06, 0x20,
0x60, 0x63, 0x20, 0x00, 0x54, 0x63, 0x04, 0x5e, 0x7c, 0x7b, 0x03, 0xa6, 0x3c, 0x60, 0x80, 0x00,
0x60, 0x63, 0x1a, 0xf4, 0x7c, 0x7a, 0x03, 0xa6, 0x4c, 0x00, 0x01, 0x2c, 0x7c, 0x00, 0x04, 0xac,
0x4c, 0x00, 0x00, 0x64, 0x3c, 0x60, 0x80, 0x00, 0x60, 0x63, 0x26, 0xc4, 0x90, 0x23, 0x00, 0x14,
0x7c, 0x61, 0x1b, 0x78, 0x7c, 0x73, 0x42, 0xa6, 0xbc, 0x41, 0x00, 0x24, 0x7c, 0x24, 0x0b, 0x78,
0x7c, 0x32, 0x42, 0xa6, 0x90, 0x04, 0x00, 0x1c, 0x90, 0x24, 0x00, 0x20, 0x7c, 0x68, 0x02, 0xa6,
0x90, 0x64, 0x00, 0x9c, 0x7c, 0x60, 0x00, 0x26, 0x90, 0x64, 0x00, 0x00, 0x7c, 0x61, 0x02, 0xa6,
0x90, 0x64, 0x00, 0x04, 0x7c, 0x69, 0x02, 0xa6, 0x90, 0x64, 0x00, 0x08, 0x7c, 0x72, 0x02, 0xa6,
0x90, 0x64, 0x00, 0x0c, 0x7c, 0x73, 0x02, 0xa6, 0x90, 0x64, 0x00, 0x10, 0x39, 0x20, 0x00, 0x00,
0x7d, 0x32, 0xfb, 0xa6, 0x7d, 0x35, 0xfb, 0xa6, 0xd0, 0x04, 0x00, 0xa0, 0xd0, 0x24, 0x00, 0xa4,
0xd0, 0x44, 0x00, 0xa8, 0xd0, 0x64, 0x00, 0xac, 0xd0, 0x84, 0x00, 0xb0, 0xd0, 0xa4, 0x00, 0xb4,
0xd0, 0xc4, 0x00, 0xb8, 0xd0, 0xe4, 0x00, 0xbc, 0xd1, 0x04, 0x00, 0xc0, 0xd1, 0x24, 0x00, 0xc4,
0xd1, 0x44, 0x00, 0xc8, 0xd1, 0x64, 0x00, 0xcc, 0xd1, 0x84, 0x00, 0xd0, 0xd1, 0xa4, 0x00, 0xd4,
0xd1, 0xc4, 0x00, 0xd8, 0xd1, 0xe4, 0x00, 0xdc, 0xd2, 0x04, 0x00, 0xe0, 0xd2, 0x24, 0x00, 0xe4,
0xd2, 0x44, 0x00, 0xe8, 0xd2, 0x64, 0x00, 0xec, 0xd2, 0x84, 0x00, 0xf0, 0xd2, 0xa4, 0x00, 0xf4,
0xd2, 0xc4, 0x00, 0xf8, 0xd2, 0xe4, 0x00, 0xfc, 0xd3, 0x04, 0x01, 0x00, 0xd3, 0x24, 0x01, 0x04,
0xd3, 0x44, 0x01, 0x08, 0xd3, 0x64, 0x01, 0x0c, 0xd3, 0x84, 0x01, 0x10, 0xd3, 0xa4, 0x01, 0x14,
0xd3, 0xc4, 0x01, 0x18, 0xd3, 0xe4, 0x01, 0x1c, 0x3f, 0xe0, 0x80, 0x00, 0x63, 0xe5, 0x26, 0xb4,
0x82, 0x05, 0x00, 0x00, 0x82, 0x25, 0x00, 0x04, 0x82, 0x65, 0x00, 0x0c, 0x2c, 0x13, 0x00, 0x00,
0x41, 0x82, 0x00, 0x74, 0x2c, 0x13, 0x00, 0x02, 0x40, 0x82, 0x00, 0x18, 0x81, 0x24, 0x00, 0x14,
0x39, 0x33, 0x00, 0x03, 0x91, 0x25, 0x00, 0x00, 0x91, 0x25, 0x00, 0x0c, 0x48, 0x00, 0x00, 0x6c,
0x7c, 0x10, 0x98, 0x00, 0x41, 0x82, 0x00, 0x38, 0x7c, 0x11, 0x98, 0x00, 0x41, 0x82, 0x00, 0x30,
0x7d, 0x30, 0x8a, 0x14, 0x91, 0x25, 0x00, 0x0c, 0x82, 0x05, 0x00, 0x08, 0x2c, 0x10, 0x00, 0x00,
0x41, 0x82, 0x00, 0x48, 0x80, 0x64, 0x00, 0x10, 0x7c, 0x10, 0x18, 0x00, 0x40, 0x82, 0x00, 0x10,
0x3a, 0x00, 0x00, 0x00, 0x92, 0x05, 0x00, 0x08, 0x48, 0x00, 0x00, 0x30, 0x3a, 0x20, 0x00, 0x00,
0x92, 0x25, 0x00, 0x0c, 0x81, 0x24, 0x00, 0x18, 0x61, 0x29, 0x04, 0x00, 0x91, 0x24, 0x00, 0x18,
0x48, 0x00, 0x00, 0x30, 0x7e, 0x12, 0xfb, 0xa6, 0x7e, 0x35, 0xfb, 0xa6, 0x39, 0x20, 0x00, 0x01,
0x91, 0x25, 0x00, 0x0c, 0x48, 0x00, 0x00, 0x1c, 0x38, 0xa0, 0x00, 0x02, 0x63, 0xe4, 0x26, 0xa0,
0x90, 0xa4, 0x00, 0x00, 0x38, 0x60, 0x00, 0x11, 0x48, 0x00, 0x01, 0xbd, 0x4b, 0xff, 0xfc, 0x1d,
0x7c, 0x20, 0x00, 0xa6, 0x54, 0x21, 0x07, 0xfa, 0x54, 0x21, 0x04, 0x5e, 0x7c, 0x20, 0x01, 0x24,
0x63, 0xe1, 0x26, 0xc4, 0x80, 0x61, 0x00, 0x00, 0x7c, 0x6f, 0xf1, 0x20, 0x80, 0x61, 0x00, 0x14,
0x7c, 0x7a, 0x03, 0xa6, 0x80, 0x61, 0x00, 0x18, 0x7c, 0x7b, 0x03, 0xa6, 0x80, 0x61, 0x00, 0x9c,
0x7c, 0x68, 0x03, 0xa6, 0xb8, 0x41, 0x00, 0x24, 0x80, 0x01, 0x00, 0x1c, 0x80, 0x21, 0x00, 0x20,
0x4c, 0x00, 0x01, 0x2c, 0x7c, 0x00, 0x04, 0xac, 0x4c, 0x00, 0x00, 0x64, 0x92, 0xb2, 0x00, 0x00,
0x48, 0x00, 0x02, 0x50, 0x2e, 0x9d, 0x00, 0x02, 0x38, 0x60, 0x00, 0x08, 0x63, 0xec, 0x26, 0xa8,
0x48, 0x00, 0x00, 0xf9, 0x80, 0xac, 0x00, 0x00, 0x80, 0x6c, 0x00, 0x04, 0x98, 0x65, 0x00, 0x00,
0x41, 0x94, 0x00, 0x10, 0xb0, 0x65, 0x00, 0x00, 0x41, 0x96, 0x00, 0x08, 0x90, 0x65, 0x00, 0x00,
0x7c, 0x00, 0x28, 0xac, 0x7c, 0x00, 0x04, 0xac, 0x7c, 0x00, 0x2f, 0xac, 0x4c, 0x00, 0x01, 0x2c,
0x48, 0x00, 0x02, 0x04, 0x48, 0x00, 0x01, 0x1d, 0x38, 0x60, 0x00, 0x04, 0x63, 0xec, 0x26, 0xa8,
0x48, 0x00, 0x00, 0xb9, 0x82, 0x0c, 0x00, 0x00, 0x63, 0xec, 0x27, 0xe8, 0x48, 0x00, 0x00, 0x1c,
0x48, 0x00, 0x01, 0x01, 0x38, 0x60, 0x00, 0x08, 0x63, 0xec, 0x26, 0xa8, 0x48, 0x00, 0x00, 0x9d,
0x82, 0x0c, 0x00, 0x04, 0x81, 0x8c, 0x00, 0x00, 0x63, 0xfb, 0x26, 0xb0, 0x3a, 0x20, 0x0f, 0x80,
0x48, 0x00, 0x02, 0x3d, 0x41, 0x82, 0x00, 0x20, 0x7e, 0x23, 0x8b, 0x78, 0x48, 0x00, 0x00, 0x7d,
0x48, 0x00, 0x00, 0xd1, 0x41, 0x82, 0xff, 0xfc, 0x7d, 0x8c, 0x72, 0x14, 0x35, 0x6b, 0xff, 0xff,
0x41, 0x81, 0xff, 0xe8, 0x80, 0x7b, 0x00, 0x00, 0x2c, 0x03, 0x00, 0x00, 0x41, 0x82, 0x00, 0x08,
0x48, 0x00, 0x00, 0x59, 0x7c, 0x00, 0x60, 0xac, 0x7c, 0x00, 0x04, 0xac, 0x7c, 0x00, 0x67, 0xac,
0x4c, 0x00, 0x01, 0x2c, 0x48, 0x00, 0x01, 0x80, 0x7f, 0xc8, 0x02, 0xa6, 0x3c, 0x60, 0xa0, 0x00,
0x48, 0x00, 0x00, 0x15, 0x76, 0x03, 0x08, 0x00, 0x56, 0x1d, 0x86, 0x3e, 0x7f, 0xc8, 0x03, 0xa6,
0x4e, 0x80, 0x00, 0x20, 0x92, 0xf8, 0x68, 0x14, 0x90, 0x78, 0x68, 0x24, 0x92, 0xd8, 0x68, 0x20,
0x80, 0xb8, 0x68, 0x20, 0x70, 0xa5, 0x00, 0x01, 0x40, 0x82, 0xff, 0xf8, 0x82, 0x18, 0x68, 0x24,
0x90, 0xb8, 0x68, 0x14, 0x4e, 0x80, 0x00, 0x20, 0x7d, 0x48, 0x02, 0xa6, 0x7c, 0x69, 0x03, 0xa6,
0x39, 0xc0, 0x00, 0x00, 0x48, 0x00, 0x00, 0x79, 0x48, 0x00, 0x00, 0x75, 0x4b, 0xff, 0xff, 0xad,
0x41, 0x82, 0xff, 0xf4, 0x7f, 0xae, 0x61, 0xae, 0x39, 0xce, 0x00, 0x01, 0x42, 0x00, 0xff, 0xe8,
0x7d, 0x48, 0x03, 0xa6, 0x4e, 0x80, 0x00, 0x20, 0x7d, 0x48, 0x02, 0xa6, 0x7c, 0x69, 0x03, 0xa6,
0x39, 0xc0, 0x00, 0x00, 0x7c, 0x6c, 0x70, 0xae, 0x48, 0x00, 0x00, 0x1d, 0x41, 0x82, 0xff, 0xf8,
0x39, 0xce, 0x00, 0x01, 0x42, 0x00, 0xff, 0xf0, 0x7d, 0x48, 0x03, 0xa6, 0x4e, 0x80, 0x00, 0x20,
0x38, 0x60, 0x00, 0xaa, 0x7f, 0xc8, 0x02, 0xa6, 0x54, 0x63, 0xa0, 0x16, 0x64, 0x63, 0xb0, 0x00,
0x3a, 0xc0, 0x00, 0x19, 0x3a, 0xe0, 0x00, 0xd0, 0x3f, 0x00, 0xcd, 0x00, 0x4b, 0xff, 0xff, 0x69,
0x56, 0x03, 0x37, 0xff, 0x7f, 0xc8, 0x03, 0xa6, 0x4e, 0x80, 0x00, 0x20, 0x7f, 0xc8, 0x02, 0xa6,
0x3c, 0x60, 0xd0, 0x00, 0x4b, 0xff, 0xff, 0x51, 0x56, 0x03, 0x37, 0xff, 0x41, 0x82, 0xff, 0xf4,
0x7f, 0xc8, 0x03, 0xa6, 0x4e, 0x80, 0x00, 0x20, 0x4b, 0xff, 0xff, 0xb9, 0x38, 0x60, 0x00, 0x08,
0x63, 0xec, 0x26, 0xa8, 0x4b, 0xff, 0xff, 0x55, 0x80, 0xac, 0x00, 0x04, 0x81, 0x8c, 0x00, 0x00,
0x63, 0xfb, 0x26, 0xb0, 0x62, 0xb1, 0xf8, 0x00, 0x7e, 0x0c, 0x28, 0x50, 0x48, 0x00, 0x00, 0xf1,
0x41, 0x81, 0x00, 0x10, 0x82, 0x3b, 0x00, 0x00, 0x2c, 0x11, 0x00, 0x00, 0x41, 0x82, 0x00, 0x68,
0x7e, 0x23, 0x8b, 0x78, 0x4b, 0xff, 0xff, 0x55, 0x4b, 0xff, 0xff, 0xa5, 0x4b, 0xff, 0xff, 0xa1,
0x4b, 0xff, 0xfe, 0xd9, 0x41, 0x82, 0xff, 0xf4, 0x2c, 0x1d, 0x00, 0xcc, 0x41, 0x82, 0x00, 0x48,
0x2c, 0x1d, 0x00, 0xbb, 0x41, 0x82, 0xff, 0xdc, 0x2c, 0x1d, 0x00, 0xaa, 0x40, 0x82, 0xff, 0xdc,
0x7d, 0x8c, 0x72, 0x14, 0x35, 0x6b, 0xff, 0xff, 0x41, 0x80, 0x00, 0x2c, 0x4b, 0xff, 0xff, 0xb4,
0x7e, 0xb5, 0xfb, 0xa6, 0x7e, 0xb2, 0xfb, 0xa6, 0x63, 0xe4, 0x26, 0xc4, 0x81, 0x24, 0x00, 0x18,
0x55, 0x29, 0x05, 0xa8, 0x91, 0x24, 0x00, 0x18, 0x48, 0x00, 0x00, 0x0c, 0x38, 0x60, 0x00, 0x80,
0x4b, 0xff, 0xff, 0x25, 0x80, 0x92, 0x00, 0x00, 0x2c, 0x04, 0x00, 0x00, 0x40, 0x82, 0xf9, 0xf8,
0xb3, 0x94, 0x40, 0x10, 0xc8, 0x41, 0x00, 0x98, 0xc8, 0x61, 0x00, 0xa0, 0x7f, 0x20, 0x00, 0xa6,
0x80, 0x01, 0x00, 0xac, 0x7c, 0x08, 0x03, 0xa6, 0x80, 0x01, 0x00, 0x0c, 0x7c, 0x0f, 0xf1, 0x20,
0x80, 0x01, 0x00, 0x10, 0x7c, 0x09, 0x03, 0xa6, 0x80, 0x01, 0x00, 0x14, 0x7c, 0x01, 0x03, 0xa6,
0xb8, 0x61, 0x00, 0x18, 0x80, 0x01, 0x00, 0x08, 0x38, 0x21, 0x00, 0xa8, 0x4c, 0x00, 0x01, 0x2c,
0x7c, 0x00, 0x04, 0xac, 0x4e, 0x80, 0x00, 0x20, 0x7e, 0x23, 0x20, 0x50, 0x3c, 0xa0, 0x48, 0x00,
0x52, 0x25, 0x01, 0xba, 0x90, 0xa3, 0x00, 0x00, 0x7c, 0x00, 0x18, 0xac, 0x7c, 0x00, 0x04, 0xac,
0x7c, 0x00, 0x1f, 0xac, 0x4c, 0x00, 0x01, 0x2c, 0x4e, 0x80, 0x00, 0x20, 0x7d, 0x70, 0x8b, 0xd7,
0x7d, 0x4b, 0x89, 0xd6, 0x7d, 0x4a, 0x80, 0x50, 0x91, 0x5b, 0x00, 0x00, 0x4e, 0x80, 0x00, 0x20,
0x7f, 0xa8, 0x02, 0xa6, 0x63, 0xef, 0x27, 0xe8, 0x63, 0xe7, 0x18, 0x08, 0x3c, 0xc0, 0x80, 0x00,
0x7c, 0xd0, 0x33, 0x78, 0x39, 0x00, 0x00, 0x00, 0x3c, 0x60, 0x00, 0xd0, 0x60, 0x63, 0xc0, 0xde,
0x80, 0x8f, 0x00, 0x00, 0x7c, 0x03, 0x20, 0x00, 0x40, 0x82, 0x00, 0x18, 0x80, 0x8f, 0x00, 0x04,
0x7c, 0x03, 0x20, 0x00, 0x40, 0x82, 0x00, 0x0c, 0x39, 0xef, 0x00, 0x08, 0x48, 0x00, 0x00, 0x0c,
0x7f, 0xa8, 0x03, 0xa6, 0x4e, 0x80, 0x00, 0x20, 0x80, 0x6f, 0x00, 0x00, 0x80, 0x8f, 0x00, 0x04,
0x39, 0xef, 0x00, 0x08, 0x71, 0x09, 0x00, 0x01, 0x2f, 0x89, 0x00, 0x00, 0x39, 0x20, 0x00, 0x00,
0x54, 0x6a, 0x1f, 0x7e, 0x54, 0x65, 0x3f, 0x7e, 0x74, 0x6b, 0x10, 0x00, 0x54, 0x63, 0x01, 0xfe,
0x40, 0x82, 0x00, 0x0c, 0x54, 0xcc, 0x00, 0x0c, 0x48, 0x00, 0x00, 0x08, 0x7e, 0x0c, 0x83, 0x78,
0x2e, 0x05, 0x00, 0x00, 0x2c, 0x0a, 0x00, 0x01, 0x41, 0xa0, 0x00, 0x2c, 0x41, 0xa2, 0x00, 0xe4,
0x2c, 0x0a, 0x00, 0x03, 0x41, 0xa0, 0x01, 0xb0, 0x41, 0x82, 0x02, 0x54, 0x2c, 0x0a, 0x00, 0x05,
0x41, 0x80, 0x02, 0xdc, 0x41, 0xa2, 0x04, 0xe8, 0x2c, 0x0a, 0x00, 0x07, 0x41, 0xa0, 0x05, 0x14,
0x48, 0x00, 0x05, 0xf8, 0x7d, 0x8c, 0x1a, 0x14, 0x2c, 0x05, 0x00, 0x03, 0x41, 0x82, 0x00, 0x48,
0x41, 0x81, 0x00, 0x60, 0x40, 0xbe, 0xff, 0x84, 0x2e, 0x05, 0x00, 0x01, 0x41, 0x91, 0x00, 0x2c,
0x54, 0x8a, 0x84, 0x3e, 0x41, 0x92, 0x00, 0x10, 0x7c, 0x89, 0x61, 0xae, 0x39, 0x29, 0x00, 0x01,
0x48, 0x00, 0x00, 0x0c, 0x7c, 0x89, 0x63, 0x2e, 0x39, 0x29, 0x00, 0x02, 0x35, 0x4a, 0xff, 0xff,
0x40, 0xa0, 0xff, 0xe4, 0x4b, 0xff, 0xff, 0x54, 0x55, 0x8c, 0x00, 0x3a, 0x90, 0x8c, 0x00, 0x00,
0x4b, 0xff, 0xff, 0x48, 0x7c, 0x89, 0x23, 0x78, 0x40, 0x9e, 0x04, 0xd0, 0x35, 0x29, 0xff, 0xff,
0x41, 0x80, 0x04, 0xc8, 0x7c, 0xa9, 0x78, 0xae, 0x7c, 0xa9, 0x61, 0xae, 0x4b, 0xff, 0xff, 0xf0,
0x39, 0xef, 0x00, 0x08, 0x40, 0xbe, 0xff, 0x24, 0x80, 0xaf, 0xff, 0xf8, 0x81, 0x6f, 0xff, 0xfc,
0x54, 0xb1, 0x04, 0x3e, 0x54, 0xaa, 0x85, 0x3e, 0x54, 0xa5, 0x27, 0x3e, 0x2e, 0x85, 0x00, 0x01,
0x41, 0x96, 0x00, 0x10, 0x41, 0xb5, 0x00, 0x14, 0x7c, 0x89, 0x61, 0xae, 0x48, 0x00, 0x00, 0x10,
0x7c, 0x89, 0x63, 0x2e, 0x48, 0x00, 0x00, 0x08, 0x7c, 0x89, 0x61, 0x2e, 0x7c, 0x84, 0x5a, 0x14,
0x7d, 0x29, 0x8a, 0x14, 0x35, 0x4a, 0xff, 0xff, 0x40, 0x80, 0xff, 0xd4, 0x4b, 0xff, 0xfe, 0xdc,
0x54, 0x69, 0x07, 0xff, 0x41, 0x82, 0x00, 0x10, 0x55, 0x08, 0xf8, 0x7e, 0x71, 0x09, 0x00, 0x01,
0x2f, 0x89, 0x00, 0x00, 0x2e, 0x85, 0x00, 0x04, 0x2d, 0x8a, 0x00, 0x05, 0x7d, 0x13, 0x43, 0x78,
0x52, 0x68, 0x08, 0x3c, 0x40, 0x9e, 0x00, 0x78, 0x41, 0x8d, 0x04, 0xbc, 0x7d, 0x8c, 0x1a, 0x14,
0x41, 0x8c, 0x00, 0x0c, 0x41, 0x94, 0x00, 0x30, 0x48, 0x00, 0x00, 0x1c, 0x40, 0x94, 0x00, 0x10,
0x55, 0x8c, 0x00, 0x3a, 0x81, 0x6c, 0x00, 0x00, 0x48, 0x00, 0x00, 0x1c, 0x55, 0x8c, 0x00, 0x3c,
0xa1, 0x6c, 0x00, 0x00, 0x7c, 0x89, 0x20, 0xf8, 0x55, 0x29, 0x84, 0x3e, 0x7d, 0x6b, 0x48, 0x38,
0x54, 0x84, 0x04, 0x3e, 0x7f, 0x0b, 0x20, 0x40, 0x70, 0xa9, 0x00, 0x03, 0x41, 0x82, 0x00, 0x18,
0x2c, 0x09, 0x00, 0x02, 0x41, 0x82, 0x00, 0x18, 0x41, 0x81, 0x00, 0x1c, 0x40, 0x9a, 0x00, 0x20,
0x48, 0x00, 0x00, 0x18, 0x41, 0x9a, 0x00, 0x18, 0x48, 0x00, 0x00, 0x10, 0x41, 0x99, 0x00, 0x10,
0x48, 0x00, 0x00, 0x08, 0x41, 0x98, 0x00, 0x08, 0x61, 0x08, 0x00, 0x01, 0x40, 0x8e, 0xfe, 0x3c,
0x41, 0x94, 0xfe, 0x38, 0x81, 0x6f, 0xff, 0xf8, 0x40, 0x9e, 0x00, 0x20, 0x70, 0x6c, 0x00, 0x08,
0x41, 0x82, 0x00, 0x0c, 0x71, 0x0c, 0x00, 0x01, 0x41, 0x82, 0x00, 0x10, 0x39, 0x8b, 0x00, 0x10,
0x51, 0x8b, 0x03, 0x36, 0x48, 0x00, 0x00, 0x08, 0x55, 0x6b, 0x07, 0x16, 0x91, 0x6f, 0xff, 0xf8,
0x4b, 0xff, 0xfe, 0x08, 0x40, 0xbe, 0xfe, 0x04, 0x54, 0x69, 0x16, 0xba, 0x54, 0x6e, 0x87, 0xfe,
0x2d, 0x8e, 0x00, 0x00, 0x2e, 0x05, 0x00, 0x04, 0x70, 0xae, 0x00, 0x03, 0x2e, 0x8e, 0x00, 0x02,
0x41, 0x94, 0x00, 0x14, 0x41, 0x96, 0x00, 0x50, 0x7c, 0x64, 0x07, 0x34, 0x7c, 0x84, 0x7a, 0x14,
0x48, 0x00, 0x00, 0x68, 0x54, 0x65, 0xa7, 0xff, 0x41, 0x82, 0x00, 0x0c, 0x7d, 0x27, 0x48, 0x2e,
0x7c, 0x84, 0x4a, 0x14, 0x41, 0x8e, 0x00, 0x08, 0x7c, 0x8c, 0x22, 0x14, 0x2e, 0x8e, 0x00, 0x01,
0x41, 0x96, 0x00, 0x08, 0x80, 0x84, 0x00, 0x00, 0x54, 0x63, 0x67, 0xff, 0x41, 0x82, 0x00, 0x3c,
0x40, 0x90, 0x00, 0x0c, 0x7c, 0x84, 0x32, 0x14, 0x48, 0x00, 0x00, 0x30, 0x7c, 0x84, 0x82, 0x14,
0x48, 0x00, 0x00, 0x28, 0x54, 0x65, 0xa7, 0xff, 0x41, 0x82, 0x00, 0x0c, 0x7d, 0x27, 0x48, 0x2e,
0x7c, 0x84, 0x4a, 0x14, 0x40, 0x90, 0x00, 0x0c, 0x7c, 0xcc, 0x21, 0x2e, 0x4b, 0xff, 0xfd, 0x7c,
0x7e, 0x0c, 0x21, 0x2e, 0x4b, 0xff, 0xfd, 0x74, 0x40, 0x90, 0x00, 0x0c, 0x7c, 0x86, 0x23, 0x78,
0x4b, 0xff, 0xfd, 0x68, 0x7c, 0x90, 0x23, 0x78, 0x4b, 0xff, 0xfd, 0x60, 0x54, 0x89, 0x1e, 0x78,
0x39, 0x29, 0x00, 0x40, 0x2c, 0x05, 0x00, 0x02, 0x41, 0x80, 0x00, 0x4c, 0x54, 0x6b, 0x67, 0xbf,
0x2c, 0x0b, 0x00, 0x01, 0x41, 0x80, 0x00, 0x14, 0x41, 0x82, 0x00, 0x08, 0x48, 0x00, 0x00, 0x10,
0x41, 0xbe, 0xfd, 0x38, 0x48, 0x00, 0x00, 0x08, 0x40, 0xbe, 0xfd, 0x30, 0x2c, 0x05, 0x00, 0x03,
0x41, 0x81, 0x00, 0x10, 0x41, 0xa2, 0x00, 0x10, 0x7d, 0xe7, 0x48, 0x2e, 0x4b, 0xff, 0xfd, 0x1c,
0x7d, 0xe7, 0x49, 0x2e, 0x7c, 0x64, 0x07, 0x34, 0x54, 0x84, 0x1a, 0x78, 0x7d, 0xef, 0x22, 0x14,
0x4b, 0xff, 0xfd, 0x08, 0x40, 0xbe, 0xfd, 0x04, 0x7c, 0xa7, 0x4a, 0x14, 0x40, 0x92, 0x00, 0x14,
0x54, 0x64, 0x04, 0x3e, 0x91, 0xe5, 0x00, 0x00, 0x90, 0x85, 0x00, 0x04, 0x4b, 0xff, 0xfc, 0xec,
0x81, 0x25, 0x00, 0x04, 0x2c, 0x09, 0x00, 0x00, 0x41, 0xa2, 0xfc, 0xe0, 0x39, 0x29, 0xff, 0xff,
0x91, 0x25, 0x00, 0x04, 0x81, 0xe5, 0x00, 0x00, 0x4b, 0xff, 0xfc, 0xd0, 0x40, 0xbe, 0xfc, 0xcc,
0x54, 0x6b, 0x16, 0xba, 0x7f, 0x47, 0x5a, 0x14, 0x81, 0x3a, 0x00, 0x00, 0x54, 0x6e, 0x67, 0xbe,
0x41, 0x92, 0x00, 0x84, 0x2e, 0x05, 0x00, 0x05, 0x40, 0x90, 0x01, 0x74, 0x2e, 0x05, 0x00, 0x03,
0x40, 0x90, 0x00, 0x90, 0x2e, 0x05, 0x00, 0x01, 0x54, 0x65, 0x87, 0xff, 0x41, 0x82, 0x00, 0x08,
0x7c, 0x8c, 0x22, 0x14, 0x2f, 0x0e, 0x00, 0x01, 0x40, 0x92, 0x00, 0x24, 0x41, 0xb9, 0x00, 0x18,
0x41, 0x9a, 0x00, 0x0c, 0x88, 0x84, 0x00, 0x00, 0x48, 0x00, 0x00, 0xf8, 0xa0, 0x84, 0x00, 0x00,
0x48, 0x00, 0x00, 0xf0, 0x80, 0x84, 0x00, 0x00, 0x48, 0x00, 0x00, 0xe8, 0x54, 0x73, 0xe5, 0x3e,
0x41, 0xb9, 0x00, 0x20, 0x41, 0x9a, 0x00, 0x10, 0x99, 0x24, 0x00, 0x00, 0x38, 0x84, 0x00, 0x01,
0x48, 0x00, 0x00, 0x18, 0xb1, 0x24, 0x00, 0x00, 0x38, 0x84, 0x00, 0x02, 0x48, 0x00, 0x00, 0x0c,
0x91, 0x24, 0x00, 0x00, 0x38, 0x84, 0x00, 0x04, 0x36, 0x73, 0xff, 0xff, 0x40, 0x80, 0xff, 0xd4,
0x4b, 0xff, 0xfc, 0x38, 0x54, 0x65, 0x87, 0xff, 0x41, 0x82, 0x00, 0x08, 0x7c, 0x84, 0x62, 0x14,
0x71, 0xc5, 0x00, 0x01, 0x41, 0x82, 0x00, 0x9c, 0x7c, 0x84, 0x4a, 0x14, 0x48, 0x00, 0x00, 0x94,
0x54, 0x6a, 0x87, 0xbe, 0x54, 0x8e, 0x16, 0xba, 0x7e, 0x67, 0x72, 0x14, 0x40, 0x92, 0x00, 0x08,
0x3a, 0x6f, 0xff, 0xfc, 0x80, 0x9a, 0x00, 0x00, 0x81, 0x33, 0x00, 0x00, 0x71, 0x4b, 0x00, 0x01,
0x41, 0x82, 0x00, 0x08, 0x7c, 0x9a, 0x23, 0x78, 0x71, 0x4b, 0x00, 0x02, 0x41, 0x82, 0x00, 0x10,
0x7d, 0x33, 0x4b, 0x78, 0x40, 0xb2, 0x00, 0x08, 0x7e, 0x6c, 0x9a, 0x14, 0x54, 0x65, 0x67, 0x3f,
0x2c, 0x05, 0x00, 0x09, 0x40, 0x80, 0x00, 0x54, 0x48, 0x00, 0x00, 0x79, 0x7c, 0x89, 0x22, 0x14,
0x48, 0x00, 0x00, 0x40, 0x7c, 0x89, 0x21, 0xd6, 0x48, 0x00, 0x00, 0x38, 0x7d, 0x24, 0x23, 0x78,
0x48, 0x00, 0x00, 0x30, 0x7d, 0x24, 0x20, 0x38, 0x48, 0x00, 0x00, 0x28, 0x7d, 0x24, 0x22, 0x78,
0x48, 0x00, 0x00, 0x20, 0x7d, 0x24, 0x20, 0x30, 0x48, 0x00, 0x00, 0x18, 0x7d, 0x24, 0x24, 0x30,
0x48, 0x00, 0x00, 0x10, 0x5d, 0x24, 0x20, 0x3e, 0x48, 0x00, 0x00, 0x08, 0x7d, 0x24, 0x26, 0x30,
0x90, 0x9a, 0x00, 0x00, 0x4b, 0xff, 0xfb, 0x84, 0x2c, 0x05, 0x00, 0x0a, 0x41, 0x81, 0xfb, 0x7c,
0xc0, 0x5a, 0x00, 0x00, 0xc0, 0x73, 0x00, 0x00, 0x41, 0x82, 0x00, 0x0c, 0xec, 0x43, 0x10, 0x2a,
0x48, 0x00, 0x00, 0x08, 0xec, 0x43, 0x00, 0xb2, 0xd0, 0x5a, 0x00, 0x00, 0x4b, 0xff, 0xfb, 0x5c,
0x7d, 0x48, 0x02, 0xa6, 0x54, 0xa5, 0x1e, 0x78, 0x7d, 0x4a, 0x2a, 0x14, 0x80, 0x9a, 0x00, 0x00,
0x81, 0x33, 0x00, 0x00, 0x7d, 0x48, 0x03, 0xa6, 0x4e, 0x80, 0x00, 0x20, 0x40, 0xbe, 0xfb, 0x3c,
0x54, 0x69, 0xc0, 0x3e, 0x7d, 0x8e, 0x63, 0x78, 0x48, 0x00, 0x00, 0x35, 0x41, 0x92, 0x00, 0x0c,
0x7e, 0x31, 0x22, 0x14, 0x48, 0x00, 0x00, 0x08, 0x7d, 0x29, 0x22, 0x14, 0x54, 0x64, 0xc4, 0x3f,
0x38, 0xa0, 0x00, 0x00, 0x41, 0x82, 0xfb, 0x14, 0x7d, 0x45, 0x88, 0xae, 0x7d, 0x45, 0x49, 0xae,
0x38, 0xa5, 0x00, 0x01, 0x7c, 0x05, 0x20, 0x00, 0x4b, 0xff, 0xff, 0xec, 0x2e, 0x8a, 0x00, 0x04,
0x55, 0x31, 0x36, 0xba, 0x2c, 0x11, 0x00, 0x3c, 0x7e, 0x27, 0x88, 0x2e, 0x40, 0x82, 0x00, 0x08,
0x7d, 0xd1, 0x73, 0x78, 0x41, 0x96, 0x00, 0x08, 0xa2, 0x31, 0x00, 0x00, 0x55, 0x29, 0x56, 0xba,
0x2c, 0x09, 0x00, 0x3c, 0x7d, 0x27, 0x48, 0x2e, 0x40, 0x82, 0x00, 0x08, 0x7d, 0xc9, 0x73, 0x78,
0x41, 0x96, 0x00, 0x08, 0xa1, 0x29, 0x00, 0x00, 0x4e, 0x80, 0x00, 0x20, 0x2c, 0x05, 0x00, 0x04,
0x40, 0x80, 0x00, 0x28, 0x7c, 0x89, 0x23, 0x78, 0x7d, 0xc3, 0x62, 0x14, 0x55, 0xce, 0x00, 0x3c,
0x4b, 0xff, 0xff, 0xad, 0x7c, 0x84, 0x20, 0xf8, 0x54, 0x84, 0x04, 0x3e, 0x7d, 0x2b, 0x20, 0x38,
0x7e, 0x24, 0x20, 0x38, 0x4b, 0xff, 0xfb, 0xbc, 0x54, 0x6b, 0xe4, 0x3e, 0x4b, 0xff, 0xfb, 0xb4,
0x7c, 0x9a, 0x23, 0x78, 0x54, 0x84, 0x18, 0x38, 0x40, 0x92, 0x00, 0x20, 0x40, 0x9e, 0x00, 0x0c,
0x7d, 0xe8, 0x03, 0xa6, 0x4e, 0x80, 0x00, 0x21, 0x7d, 0xe4, 0x7a, 0x14, 0x39, 0xef, 0x00, 0x07,
0x55, 0xef, 0x00, 0x38, 0x4b, 0xff, 0xfa, 0x64, 0x2e, 0x05, 0x00, 0x03, 0x41, 0x91, 0x00, 0x5c,
0x3c, 0xa0, 0x48, 0x00, 0x7d, 0x83, 0x62, 0x14, 0x55, 0x8c, 0x00, 0x3a, 0x40, 0x92, 0x00, 0x20,
0x40, 0xbe, 0xfa, 0x48, 0x57, 0x44, 0x00, 0x3a, 0x7c, 0x8c, 0x20, 0x50, 0x50, 0x85, 0x01, 0xba,
0x50, 0x65, 0x07, 0xfe, 0x90, 0xac, 0x00, 0x00, 0x4b, 0xff, 0xfa, 0x30, 0x40, 0xbe, 0xff, 0xbc,
0x7d, 0x2c, 0x78, 0x50, 0x51, 0x25, 0x01, 0xba, 0x90, 0xac, 0x00, 0x00, 0x39, 0x8c, 0x00, 0x04,
0x7d, 0x6f, 0x22, 0x14, 0x39, 0x6b, 0xff, 0xfc, 0x7d, 0x2b, 0x60, 0x50, 0x51, 0x25, 0x01, 0xba,
0x90, 0xab, 0x00, 0x00, 0x4b, 0xff, 0xff, 0x94, 0x2e, 0x05, 0x00, 0x06, 0x41, 0x92, 0x00, 0x28,
0x4b, 0xff, 0xfb, 0x20, 0x55, 0x8c, 0x84, 0x3e, 0x57, 0x44, 0x84, 0x3e, 0x57, 0x5a, 0x04, 0x3e,
0x7c, 0x0c, 0x20, 0x00, 0x41, 0x80, 0xfb, 0xa4, 0x7c, 0x0c, 0xd0, 0x00, 0x40, 0x80, 0xfb, 0x9c,
0x4b, 0xff, 0xf9, 0xd8, 0x57, 0x45, 0xff, 0xfe, 0x68, 0xa5, 0x00, 0x01, 0x71, 0x03, 0x00, 0x01,
0x7c, 0x05, 0x18, 0x00, 0x41, 0x82, 0x00, 0x1c, 0x51, 0x1a, 0x0f, 0xbc, 0x6b, 0x5a, 0x00, 0x02,
0x57, 0x45, 0xff, 0xff, 0x41, 0x82, 0x00, 0x08, 0x6b, 0x5a, 0x00, 0x01, 0x93, 0x4f, 0xff, 0xfc,
0x53, 0x48, 0x07, 0xfe, 0x4b, 0xff, 0xf9, 0xa4, 0x2c, 0x0b, 0x00, 0x00, 0x40, 0x82, 0xf9, 0x94,
0x40, 0x92, 0x00, 0x0c, 0x39, 0x00, 0x00, 0x00, 0x48, 0x00, 0x00, 0x14, 0x54, 0x69, 0x06, 0xff,
0x40, 0x82, 0x00, 0x08, 0x40, 0x9e, 0x00, 0x10, 0x54, 0x65, 0x67, 0xfe, 0x7d, 0x08, 0x4c, 0x30,
0x7d, 0x08, 0x2a, 0x78, 0x54, 0x85, 0x00, 0x1f, 0x41, 0x82, 0x00, 0x08, 0x7c, 0xa6, 0x2b, 0x78,
0x54, 0x85, 0x80, 0x1f, 0x41, 0x82, 0x00, 0x08, 0x7c, 0xb0, 0x2b, 0x78, 0x4b, 0xff, 0xf9, 0x5c,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
const int kenobiwii_size = sizeof(kenobiwii);

618
source/libwbfs/libwbfs.c Normal file
View File

@ -0,0 +1,618 @@
// Copyright 2009 Kwiirk
// Licensed under the terms of the GNU GPL, version 2
// http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
#include "libwbfs.h"
#define likely(x) __builtin_expect(!!(x), 1)
#define unlikely(x) __builtin_expect(!!(x), 0)
#define ERROR(x) do {wbfs_error(x);goto error;}while(0)
#define ALIGN_LBA(x) (((x)+p->hd_sec_sz-1)&(~(p->hd_sec_sz-1)))
static int force_mode=0;
void wbfs_set_force_mode(int force)
{
force_mode = force;
}
static u8 size_to_shift(u32 size)
{
u8 ret = 0;
while(size)
{
ret++;
size>>=1;
}
return ret-1;
}
#define read_le32_unaligned(x) ((x)[0]|((x)[1]<<8)|((x)[2]<<16)|((x)[3]<<24))
wbfs_t*wbfs_open_hd(rw_sector_callback_t read_hdsector,
rw_sector_callback_t write_hdsector,
void *callback_data,
int hd_sector_size, int num_hd_sector __attribute((unused)), int reset)
{
int i=num_hd_sector,ret;
u8 *ptr,*tmp_buffer = wbfs_ioalloc(hd_sector_size);
u8 part_table[16*4];
ret = read_hdsector(callback_data,0,1,tmp_buffer);
if(ret)
return 0;
//find wbfs partition
wbfs_memcpy(part_table,tmp_buffer+0x1be,16*4);
ptr = part_table;
for(i=0;i<4;i++,ptr+=16)
{
u32 part_lba = read_le32_unaligned(ptr+0x8);
wbfs_head_t *head = (wbfs_head_t *)tmp_buffer;
ret = read_hdsector(callback_data,part_lba,1,tmp_buffer);
// verify there is the magic.
if (head->magic == wbfs_htonl(WBFS_MAGIC))
{
wbfs_t*p = wbfs_open_partition(read_hdsector,write_hdsector,
callback_data,hd_sector_size,0,part_lba,reset);
return p;
}
}
if(reset)// XXX make a empty hd partition..
{
}
return 0;
}
wbfs_t*wbfs_open_partition(rw_sector_callback_t read_hdsector,
rw_sector_callback_t write_hdsector,
void *callback_data,
int hd_sector_size, int num_hd_sector, u32 part_lba, int reset)
{
wbfs_t *p = wbfs_malloc(sizeof(wbfs_t));
wbfs_head_t *head = wbfs_ioalloc(hd_sector_size?hd_sector_size:512);
//constants, but put here for consistancy
p->wii_sec_sz = 0x8000;
p->wii_sec_sz_s = size_to_shift(0x8000);
p->n_wii_sec = (num_hd_sector/0x8000)*hd_sector_size;
p->n_wii_sec_per_disc = 143432*2;//support for double layers discs..
p->head = head;
p->part_lba = part_lba;
// init the partition
if (reset)
{
u8 sz_s;
wbfs_memset(head,0,hd_sector_size);
head->magic = wbfs_htonl(WBFS_MAGIC);
head->hd_sec_sz_s = size_to_shift(hd_sector_size);
head->n_hd_sec = wbfs_htonl(num_hd_sector);
// choose minimum wblk_sz that fits this partition size
for(sz_s=6;sz_s<11;sz_s++)
{
// ensure that wbfs_sec_sz is big enough to address every blocks using 16 bits
if(p->n_wii_sec <((1U<<16)*(1<<sz_s)))
break;
}
head->wbfs_sec_sz_s = sz_s+p->wii_sec_sz_s;
}else
read_hdsector(callback_data,p->part_lba,1,head);
if (head->magic != wbfs_htonl(WBFS_MAGIC))
ERROR("bad magic");
if(!force_mode && hd_sector_size && head->hd_sec_sz_s != size_to_shift(hd_sector_size))
ERROR("hd sector size doesn't match");
if(!force_mode && num_hd_sector && head->n_hd_sec != wbfs_htonl(num_hd_sector))
ERROR("hd num sector doesn't match");
p->hd_sec_sz = 1<<head->hd_sec_sz_s;
p->hd_sec_sz_s = head->hd_sec_sz_s;
p->n_hd_sec = wbfs_ntohl(head->n_hd_sec);
p->n_wii_sec = (p->n_hd_sec/p->wii_sec_sz)*(p->hd_sec_sz);
p->wbfs_sec_sz_s = head->wbfs_sec_sz_s;
p->wbfs_sec_sz = 1<<p->wbfs_sec_sz_s;
p->n_wbfs_sec = p->n_wii_sec >> (p->wbfs_sec_sz_s - p->wii_sec_sz_s);
p->n_wbfs_sec_per_disc = p->n_wii_sec_per_disc >> (p->wbfs_sec_sz_s - p->wii_sec_sz_s);
p->disc_info_sz = ALIGN_LBA(sizeof(wbfs_disc_info_t) + p->n_wbfs_sec_per_disc*2);
//printf("hd_sector_size %X wii_sector size %X wbfs sector_size %X\n",p->hd_sec_sz,p->wii_sec_sz,p->wbfs_sec_sz);
p->read_hdsector = read_hdsector;
p->write_hdsector = write_hdsector;
p->callback_data = callback_data;
p->freeblks_lba = (p->wbfs_sec_sz - p->n_wbfs_sec/8)>>p->hd_sec_sz_s;
if(!reset)
p->freeblks = 0; // will alloc and read only if needed
else
{
// init with all free blocks
p->freeblks = wbfs_ioalloc(ALIGN_LBA(p->n_wbfs_sec/8));
wbfs_memset(p->freeblks,0xff,p->n_wbfs_sec/8);
}
p->max_disc = (p->freeblks_lba-1)/(p->disc_info_sz>>p->hd_sec_sz_s);
if(p->max_disc > p->hd_sec_sz - sizeof(wbfs_head_t))
p->max_disc = p->hd_sec_sz - sizeof(wbfs_head_t);
p->tmp_buffer = wbfs_ioalloc(p->hd_sec_sz);
p->n_disc_open = 0;
return p;
error:
wbfs_free(p);
wbfs_iofree(head);
return 0;
}
void wbfs_sync(wbfs_t*p)
{
// copy back descriptors
if(p->write_hdsector){
p->write_hdsector(p->callback_data,p->part_lba+0,1, p->head);
if(p->freeblks)
p->write_hdsector(p->callback_data,p->part_lba+p->freeblks_lba,ALIGN_LBA(p->n_wbfs_sec/8)>>p->hd_sec_sz_s, p->freeblks);
}
}
void wbfs_close(wbfs_t*p)
{
wbfs_sync(p);
if(p->n_disc_open)
ERROR("trying to close wbfs while discs still open");
wbfs_iofree(p->head);
wbfs_iofree(p->tmp_buffer);
if(p->freeblks)
wbfs_iofree(p->freeblks);
wbfs_free(p);
error:
return;
}
wbfs_disc_t *wbfs_open_disc(wbfs_t* p, u8 *discid)
{
u32 i;
int disc_info_sz_lba = p->disc_info_sz>>p->hd_sec_sz_s;
wbfs_disc_t *d = 0;
for(i=0;i<p->max_disc;i++)
{
if (p->head->disc_table[i]){
p->read_hdsector(p->callback_data,
p->part_lba+1+i*disc_info_sz_lba,1,p->tmp_buffer);
if(wbfs_memcmp(discid,p->tmp_buffer,6)==0){
d = wbfs_malloc(sizeof(*d));
if(!d)
ERROR("allocating memory");
d->p = p;
d->i = i;
d->header = wbfs_ioalloc(p->disc_info_sz);
if(!d->header)
ERROR("allocating memory");
p->read_hdsector(p->callback_data,
p->part_lba+1+i*disc_info_sz_lba,
disc_info_sz_lba,d->header);
p->n_disc_open ++;
// for(i=0;i<p->n_wbfs_sec_per_disc;i++)
// printf("%d,",wbfs_ntohs(d->header->wlba_table[i]));
return d;
}
}
}
return 0;
error:
if(d)
wbfs_iofree(d);
return 0;
}
void wbfs_close_disc(wbfs_disc_t*d)
{
d->p->n_disc_open --;
wbfs_iofree(d->header);
wbfs_free(d);
}
// offset is pointing 32bit words to address the whole dvd, although len is in bytes
int wbfs_disc_read(wbfs_disc_t*d,u32 offset, u8 *data, u32 len)
{
wbfs_t *p = d->p;
u16 wlba = offset>>(p->wbfs_sec_sz_s-2);
u32 iwlba_shift = p->wbfs_sec_sz_s - p->hd_sec_sz_s;
u32 lba_mask = (p->wbfs_sec_sz-1)>>(p->hd_sec_sz_s);
u32 lba = (offset>>(p->hd_sec_sz_s-2))&lba_mask;
u32 off = offset&((p->hd_sec_sz>>2)-1);
u16 iwlba = wbfs_ntohs(d->header->wlba_table[wlba]);
u32 len_copied;
int err = 0;
u8 *ptr = data;
if(unlikely(iwlba==0))
return 1;
if(unlikely(off)){
off*=4;
err = p->read_hdsector(p->callback_data,
p->part_lba + (iwlba<<iwlba_shift) + lba, 1, p->tmp_buffer);
if(err)
return err;
len_copied = p->hd_sec_sz - off;
if(likely(len < len_copied))
len_copied = len;
wbfs_memcpy(ptr, p->tmp_buffer + off, len_copied);
len -= len_copied;
ptr += len_copied;
lba++;
if(unlikely(lba>lba_mask && len)){
lba=0;
iwlba = wbfs_ntohs(d->header->wlba_table[++wlba]);
if(unlikely(iwlba==0))
return 1;
}
}
while(likely(len>=p->hd_sec_sz))
{
u32 nlb = len>>(p->hd_sec_sz_s);
if(unlikely(lba + nlb > p->wbfs_sec_sz)) // dont cross wbfs sectors..
nlb = p->wbfs_sec_sz-lba;
err = p->read_hdsector(p->callback_data,
p->part_lba + (iwlba<<iwlba_shift) + lba, nlb, ptr);
if(err)
return err;
len -= nlb<<p->hd_sec_sz_s;
ptr += nlb<<p->hd_sec_sz_s;
lba += nlb;
if(unlikely(lba>lba_mask && len)){
lba = 0;
iwlba =wbfs_ntohs(d->header->wlba_table[++wlba]);
if(unlikely(iwlba==0))
return 1;
}
}
if(unlikely(len)){
err = p->read_hdsector(p->callback_data,
p->part_lba + (iwlba<<iwlba_shift) + lba, 1, p->tmp_buffer);
if(err)
return err;
wbfs_memcpy(ptr, p->tmp_buffer, len);
}
return 0;
}
// disc listing
u32 wbfs_count_discs(wbfs_t*p)
{
u32 i,count=0;
for(i=0;i<p->max_disc;i++)
if (p->head->disc_table[i])
count++;
return count;
}
u32 wbfs_sector_used(wbfs_t *p,wbfs_disc_info_t *di)
{
u32 tot_blk=0,j;
for(j=0;j<p->n_wbfs_sec_per_disc;j++)
if(wbfs_ntohs(di->wlba_table[j]))
tot_blk++;
return tot_blk;
}
u32 wbfs_get_disc_info(wbfs_t*p, u32 index,u8 *header,int header_size,u32 *size)//size in 32 bit
{
u32 i,count=0;
int disc_info_sz_lba = p->disc_info_sz>>p->hd_sec_sz_s;
for(i=0;i<p->max_disc;i++)
if (p->head->disc_table[i]){
if(count++==index)
{
p->read_hdsector(p->callback_data,
p->part_lba+1+i*disc_info_sz_lba,1,p->tmp_buffer);
if(header_size > (int)p->hd_sec_sz)
header_size = p->hd_sec_sz;
u32 magic = wbfs_ntohl(*(u32*)(p->tmp_buffer+24));
if(magic!=0x5D1C9EA3){
p->head->disc_table[i]=0;
return 1;
}
memcpy(header,p->tmp_buffer,header_size);
if(size)
{
u8 *header = wbfs_ioalloc(p->disc_info_sz);
p->read_hdsector(p->callback_data,
p->part_lba+1+i*disc_info_sz_lba,disc_info_sz_lba,header);
u32 sec_used = wbfs_sector_used(p,(wbfs_disc_info_t *)header);
wbfs_iofree(header);
*size = sec_used<<(p->wbfs_sec_sz_s-2);
}
return 0;
}
}
return 1;
}
static void load_freeblocks(wbfs_t*p)
{
if(p->freeblks)
return;
// XXX should handle malloc error..
p->freeblks = wbfs_ioalloc(ALIGN_LBA(p->n_wbfs_sec/8));
p->read_hdsector(p->callback_data,p->part_lba+p->freeblks_lba,ALIGN_LBA(p->n_wbfs_sec/8)>>p->hd_sec_sz_s, p->freeblks);
}
u32 wbfs_count_usedblocks(wbfs_t*p)
{
u32 i,j,count=0;
load_freeblocks(p);
for(i=0;i<p->n_wbfs_sec/(8*4);i++)
{
u32 v = wbfs_ntohl(p->freeblks[i]);
if(v == ~0U)
count+=32;
else if(v!=0)
for(j=0;j<32;j++)
if (v & (1<<j))
count++;
}
return count;
}
// write access
static int block_used(u8 *used,u32 i,u32 wblk_sz)
{
u32 k;
i*=wblk_sz;
for(k=0;k<wblk_sz;k++)
if(i+k<143432*2 && used[i+k])
return 1;
return 0;
}
static u32 alloc_block(wbfs_t*p)
{
u32 i,j;
for(i=0;i<p->n_wbfs_sec/(8*4);i++)
{
u32 v = wbfs_ntohl(p->freeblks[i]);
if(v != 0)
{
for(j=0;j<32;j++)
if (v & (1<<j))
{
p->freeblks[i] = wbfs_htonl(v & ~(1<<j));
return (i*32)+j+1;
}
}
}
return ~0;
}
static void free_block(wbfs_t *p,int bl)
{
int i = (bl-1)/(32);
int j = (bl-1)&31;
u32 v = wbfs_ntohl(p->freeblks[i]);
p->freeblks[i] = wbfs_htonl(v | 1<<j);
}
u32 wbfs_add_disc(wbfs_t*p,read_wiidisc_callback_t read_src_wii_disc,
void *callback_data,progress_callback_t spinner,partition_selector_t sel,int copy_1_1)
{
int i,discn;
u32 tot,cur;
u32 wii_sec_per_wbfs_sect = 1<<(p->wbfs_sec_sz_s-p->wii_sec_sz_s);
wiidisc_t *d = 0;
u8 *used = 0;
wbfs_disc_info_t *info = 0;
u8* copy_buffer = 0;
used = wbfs_malloc(p->n_wii_sec_per_disc);
if(!used)
ERROR("unable to alloc memory");
if(!copy_1_1)
{
d = wd_open_disc(read_src_wii_disc,callback_data);
if(!d)
ERROR("unable to open wii disc");
wd_build_disc_usage(d,sel,used);
wd_close_disc(d);
d = 0;
}
for(i=0;i<p->max_disc;i++)// find a free slot.
if(p->head->disc_table[i]==0)
break;
if(i==p->max_disc)
ERROR("no space left on device (table full)");
p->head->disc_table[i] = 1;
discn = i;
load_freeblocks(p);
// build disc info
info = wbfs_ioalloc(p->disc_info_sz);
read_src_wii_disc(callback_data,0,0x100,info->disc_header_copy);
copy_buffer = wbfs_ioalloc(p->wii_sec_sz);
if(!copy_buffer)
ERROR("alloc memory");
tot=0;
cur=0;
if(spinner){
// count total number to write for spinner
for(i=0; i<p->n_wbfs_sec_per_disc;i++)
if(copy_1_1 || block_used(used,i,wii_sec_per_wbfs_sect)) tot += wii_sec_per_wbfs_sect;
spinner(0,tot);
}
for(i=0; i<p->n_wbfs_sec_per_disc;i++){
u16 bl = 0;
if(copy_1_1 || block_used(used,i,wii_sec_per_wbfs_sect)) {
u16 j;
bl = alloc_block(p);
if (bl==0xffff)
ERROR("no space left on device (disc full)");
for(j=0; j<wii_sec_per_wbfs_sect;j++) {
u32 offset = (i*(p->wbfs_sec_sz>>2)) + (j*(p->wii_sec_sz>>2));
read_src_wii_disc(callback_data,offset,p->wii_sec_sz,copy_buffer);
//fix the partition table
if(offset == (0x40000>>2))
wd_fix_partition_table(d, sel, copy_buffer);
p->write_hdsector(p->callback_data,p->part_lba+bl*(p->wbfs_sec_sz/p->hd_sec_sz)+j*(p->wii_sec_sz/p->hd_sec_sz),
p->wii_sec_sz/p->hd_sec_sz,copy_buffer);
cur++;
if(spinner)
spinner(cur,tot);
}
}
info->wlba_table[i] = wbfs_htons(bl);
}
// write disc info
int disc_info_sz_lba = p->disc_info_sz>>p->hd_sec_sz_s;
p->write_hdsector(p->callback_data,p->part_lba+1+discn*disc_info_sz_lba,disc_info_sz_lba,info);
wbfs_sync(p);
error:
if(d)
wd_close_disc(d);
if(used)
wbfs_free(used);
if(info)
wbfs_iofree(info);
if(copy_buffer)
wbfs_iofree(copy_buffer);
// init with all free blocks
return 0;
}
u32 wbfs_rm_disc(wbfs_t*p, u8* discid)
{
wbfs_disc_t *d = wbfs_open_disc(p,discid);
int i;
int discn = 0;
int disc_info_sz_lba = p->disc_info_sz>>p->hd_sec_sz_s;
if(!d)
return 1;
load_freeblocks(p);
discn = d->i;
for( i=0; i< p->n_wbfs_sec_per_disc; i++)
{
u32 iwlba = wbfs_ntohs(d->header->wlba_table[i]);
if (iwlba)
free_block(p,iwlba);
}
memset(d->header,0,p->disc_info_sz);
p->write_hdsector(p->callback_data,p->part_lba+1+discn*disc_info_sz_lba,disc_info_sz_lba,d->header);
p->head->disc_table[discn] = 0;
wbfs_close_disc(d);
wbfs_sync(p);
return 0;
}
u32 wbfs_ren_disc(wbfs_t*p, u8* discid, u8* newname)
{
wbfs_disc_t *d = wbfs_open_disc(p,discid);
int disc_info_sz_lba = p->disc_info_sz>>p->hd_sec_sz_s;
if(!d)
return 1;
memset(d->header->disc_header_copy+0x20, 0, 0x40);
strncpy(d->header->disc_header_copy+0x20, newname, 0x39);
p->write_hdsector(p->callback_data,p->part_lba+1+d->i*disc_info_sz_lba,disc_info_sz_lba,d->header);
wbfs_close_disc(d);
return 0;
}
// trim the file-system to its minimum size
u32 wbfs_trim(wbfs_t*p);
// data extraction
u32 wbfs_extract_disc(wbfs_disc_t*d, rw_sector_callback_t write_dst_wii_sector,void *callback_data,progress_callback_t spinner)
{
wbfs_t *p = d->p;
u8* copy_buffer = 0;
int i;
int src_wbs_nlb=p->wbfs_sec_sz/p->hd_sec_sz;
int dst_wbs_nlb=p->wbfs_sec_sz/p->wii_sec_sz;
copy_buffer = wbfs_ioalloc(p->wbfs_sec_sz);
if(!copy_buffer)
ERROR("alloc memory");
for( i=0; i< p->n_wbfs_sec_per_disc; i++)
{
u32 iwlba = wbfs_ntohs(d->header->wlba_table[i]);
if (iwlba)
{
if(spinner)
spinner(i,p->n_wbfs_sec_per_disc);
p->read_hdsector(p->callback_data, p->part_lba + iwlba*src_wbs_nlb, src_wbs_nlb, copy_buffer);
write_dst_wii_sector(callback_data, i*dst_wbs_nlb, dst_wbs_nlb, copy_buffer);
}
}
wbfs_iofree(copy_buffer);
return 0;
error:
return 1;
}
u32 wbfs_extract_file(wbfs_disc_t*d, char *path);
u32 wbfs_estimate_disc(
wbfs_t *p, read_wiidisc_callback_t read_src_wii_disc,
void *callback_data,
partition_selector_t sel)
{
u8 *b;
int disc_info_sz_lba;
int i;
u32 tot;
u32 wii_sec_per_wbfs_sect = 1 << (p->wbfs_sec_sz_s-p->wii_sec_sz_s);
wiidisc_t *d = 0;
u8 *used = 0;
wbfs_disc_info_t *info = 0;
tot = 0;
used = wbfs_malloc(p->n_wii_sec_per_disc);
if (!used)
{
ERROR("unable to alloc memory");
}
d = wd_open_disc(read_src_wii_disc, callback_data);
if (!d)
{
ERROR("unable to open wii disc");
}
wd_build_disc_usage(d,sel,used);
wd_close_disc(d);
d = 0;
info = wbfs_ioalloc(p->disc_info_sz);
b = (u8 *)info;
read_src_wii_disc(callback_data, 0, 0x100, info->disc_header_copy);
fprintf(stderr, "estimating %c%c%c%c%c%c %s...\n",b[0], b[1], b[2], b[3], b[4], b[5], b + 0x20);
for (i = 0; i < p->n_wbfs_sec_per_disc; i++)
{
if (block_used(used, i, wii_sec_per_wbfs_sect))
{
tot++;
}
}
error:
if (d)
wd_close_disc(d);
if (used)
wbfs_free(used);
if (info)
wbfs_iofree(info);
return tot * ((p->wbfs_sec_sz / p->hd_sec_sz) * 512);
}

223
source/libwbfs/libwbfs.h Normal file
View File

@ -0,0 +1,223 @@
#ifndef LIBWBFS_H
#define LIBWBFS_H
#include "libwbfs_os.h" // this file is provided by the project wanting to compile libwbfs
#include "wiidisc.h"
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
typedef u32 be32_t;
typedef u16 be16_t;
typedef struct wbfs_head
{
be32_t magic;
// parameters copied in the partition for easy dumping, and bug reports
be32_t n_hd_sec; // total number of hd_sec in this partition
u8 hd_sec_sz_s; // sector size in this partition
u8 wbfs_sec_sz_s; // size of a wbfs sec
u8 padding3[2];
u8 disc_table[0]; // size depends on hd sector size
}__attribute((packed)) wbfs_head_t ;
typedef struct wbfs_disc_info
{
u8 disc_header_copy[0x100];
be16_t wlba_table[0];
}wbfs_disc_info_t;
// WBFS first wbfs_sector structure:
//
// -----------
// | wbfs_head | (hd_sec_sz)
// -----------
// | |
// | disc_info |
// | |
// -----------
// | |
// | disc_info |
// | |
// -----------
// | |
// | ... |
// | |
// -----------
// | |
// | disc_info |
// | |
// -----------
// | |
// |freeblk_tbl|
// | |
// -----------
//
// callback definition. Return 1 on fatal error (callback is supposed to make retries until no hopes..)
typedef int (*rw_sector_callback_t)(void*fp,u32 lba,u32 count,void*iobuf);
typedef void (*progress_callback_t)(int status,int total);
typedef struct wbfs_s
{
wbfs_head_t *head;
/* hdsectors, the size of the sector provided by the hosting hard drive */
u32 hd_sec_sz;
u8 hd_sec_sz_s; // the power of two of the last number
u32 n_hd_sec; // the number of hd sector in the wbfs partition
/* standard wii sector (0x8000 bytes) */
u32 wii_sec_sz;
u8 wii_sec_sz_s;
u32 n_wii_sec;
u32 n_wii_sec_per_disc;
/* The size of a wbfs sector */
u32 wbfs_sec_sz;
u32 wbfs_sec_sz_s;
u16 n_wbfs_sec; // this must fit in 16 bit!
u16 n_wbfs_sec_per_disc; // size of the lookup table
u32 part_lba;
/* virtual methods to read write the partition */
rw_sector_callback_t read_hdsector;
rw_sector_callback_t write_hdsector;
void *callback_data;
u16 max_disc;
u32 freeblks_lba;
u32 *freeblks;
u16 disc_info_sz;
u8 *tmp_buffer; // pre-allocated buffer for unaligned read
u32 n_disc_open;
}wbfs_t;
typedef struct wbfs_disc_s
{
wbfs_t *p;
wbfs_disc_info_t *header; // pointer to wii header
int i; // disc index in the wbfs header (disc_table)
}wbfs_disc_t;
#define WBFS_MAGIC (('W'<<24)|('B'<<16)|('F'<<8)|('S'))
/*! @brief open a MSDOS partitionned harddrive. This tries to find a wbfs partition into the harddrive
@param read_hdsector,write_hdsector: accessors to a harddrive
@hd_sector_size: size of the hd sector. Can be set to zero if the partition in already initialized
@num_hd_sector: number of sectors in this disc. Can be set to zero if the partition in already initialized
@reset: not implemented, This will format the whole harddrive with one wbfs partition that fits the whole disk.
calls wbfs_error() to have textual meaning of errors
@return NULL in case of error
*/
wbfs_t*wbfs_open_hd(rw_sector_callback_t read_hdsector,
rw_sector_callback_t write_hdsector,
void *callback_data,
int hd_sector_size, int num_hd_sector, int reset);
/*! @brief open a wbfs partition
@param read_hdsector,write_hdsector: accessors to the partition
@hd_sector_size: size of the hd sector. Can be set to zero if the partition in already initialized
@num_hd_sector: number of sectors in this partition. Can be set to zero if the partition in already initialized
@partition_lba: The partitio offset if you provided accessors to the whole disc.
@reset: initialize the partition with an empty wbfs.
calls wbfs_error() to have textual meaning of errors
@return NULL in case of error
*/
wbfs_t*wbfs_open_partition(rw_sector_callback_t read_hdsector,
rw_sector_callback_t write_hdsector,
void *callback_data,
int hd_sector_size, int num_hd_sector, u32 partition_lba, int reset);
/*! @brief close a wbfs partition, and sync the metadatas to the disc */
void wbfs_close(wbfs_t*);
/*! @brief open a disc inside a wbfs partition use a 6 char discid+vendorid
@return NULL if discid is not present
*/
wbfs_disc_t *wbfs_open_disc(wbfs_t* p, u8 *diskid);
/*! @brief close a already open disc inside a wbfs partition */
void wbfs_close_disc(wbfs_disc_t*d);
u32 wbfs_sector_used(wbfs_t *p,wbfs_disc_info_t *di);
/*! @brief accessor to the wii disc
@param d: a pointer to already open disc
@param offset: an offset inside the disc, *points 32bit words*, allowing to access 16GB data
@param len: The length of the data to fetch, in *bytes*
*/
// offset is pointing 32bit words to address the whole dvd, although len is in bytes
int wbfs_disc_read(wbfs_disc_t*d,u32 offset, u8 *data, u32 len);
/*! @return the number of discs inside the paritition */
u32 wbfs_count_discs(wbfs_t*p);
/*! get the disc info of ith disc inside the partition. It correspond to the first 0x100 bytes of the wiidvd
http://www.wiibrew.org/wiki/Wiidisc#Header
@param i: index of the disc inside the partition
@param header: pointer to 0x100 bytes to write the header
@size: optional pointer to a 32bit word that will get the size in 32bit words of the DVD taken on the partition.
*/
u32 wbfs_get_disc_info(wbfs_t*p, u32 i,u8 *header,int header_size,u32 *size);
/*! get the number of used block of the partition.
to be multiplied by p->wbfs_sec_sz (use 64bit multiplication) to have the number in bytes
*/
u32 wbfs_count_usedblocks(wbfs_t*p);
/******************* write access ******************/
/*! add a wii dvd inside the partition
@param read_src_wii_disc: a callback to access the wii dvd. offsets are in 32bit, len in bytes!
@callback_data: private data passed to the callback
@spinner: a pointer to a function that is regulary called to update a progress bar.
@sel: selects which partitions to copy.
@copy_1_1: makes a 1:1 copy, whenever a game would not use the wii disc format, and some data is hidden outside the filesystem.
*/
u32 wbfs_add_disc(wbfs_t*p,read_wiidisc_callback_t read_src_wii_disc, void *callback_data,
progress_callback_t spinner,partition_selector_t sel,int copy_1_1);
/*! remove a wiidvd inside a partition */
u32 wbfs_rm_disc(wbfs_t*p, u8* discid);
/*! rename a game */
u32 wbfs_ren_disc(wbfs_t*p, u8* discid, u8* newname);
/*! trim the file-system to its minimum size
This allows to use wbfs as a wiidisc container
*/
u32 wbfs_trim(wbfs_t*p);
/*! extract a disc from the wbfs, unused sectors are just untouched, allowing descent filesystem to only really usefull space to store the disc.
Even if the filesize is 4.7GB, the disc usage will be less.
*/
u32 wbfs_extract_disc(wbfs_disc_t*d, rw_sector_callback_t write_dst_wii_sector,void *callback_data,progress_callback_t spinner);
/*! extract a file from the wii disc filesystem.
E.G. Allows to extract the opening.bnr to install a game as a system menu channel
*/
u32 wbfs_extract_file(wbfs_disc_t*d, char *path);
// remove some sanity checks
void wbfs_set_force_mode(int force);
u32 wbfs_estimate_disc(
wbfs_t *p, read_wiidisc_callback_t read_src_wii_disc,
void *callback_data,
partition_selector_t sel);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif

View File

@ -0,0 +1,33 @@
#ifndef LIBWBFS_GLUE_H
#define LIBWBFS_GLUE_H
#include <gctypes.h>
#define debug_printf(fmt, ...);
#include <stdio.h>
#define wbfs_fatal(x) do { printf("\nwbfs panic: %s\n\n",x); while(1); } while(0)
#define wbfs_error(x) do { printf("\nwbfs error: %s\n\n",x); } while(0)
#include <stdlib.h>
#include <malloc.h>
#define wbfs_malloc(x) malloc(x)
#define wbfs_free(x) free(x)
#define wbfs_ioalloc(x) memalign(32, x)
#define wbfs_iofree(x) free(x)
#define wbfs_be16(x) (*((u16*)(x)))
#define wbfs_be32(x) (*((u32*)(x)))
#define wbfs_ntohl(x) (x)
#define wbfs_htonl(x) (x)
#define wbfs_ntohs(x) (x)
#define wbfs_htons(x) (x)
#include <string.h>
#define wbfs_memcmp(x,y,z) memcmp(x,y,z)
#define wbfs_memcpy(x,y,z) memcpy(x,y,z)
#define wbfs_memset(x,y,z) memset(x,y,z)
#endif

398
source/libwbfs/rijndael.c Normal file
View File

@ -0,0 +1,398 @@
/* Rijndael Block Cipher - rijndael.c
Written by Mike Scott 21st April 1999
mike@compapp.dcu.ie
Permission for free direct or derivative use is granted subject
to compliance with any conditions that the originators of the
algorithm place on its exploitation.
*/
#include <stdio.h>
#include <string.h>
#define u8 unsigned char /* 8 bits */
#define u32 unsigned long /* 32 bits */
#define u64 unsigned long long
/* rotates x one bit to the left */
#define ROTL(x) (((x)>>7)|((x)<<1))
/* Rotates 32-bit word left by 1, 2 or 3 byte */
#define ROTL8(x) (((x)<<8)|((x)>>24))
#define ROTL16(x) (((x)<<16)|((x)>>16))
#define ROTL24(x) (((x)<<24)|((x)>>8))
/* Fixed Data */
static u8 InCo[4]={0xB,0xD,0x9,0xE}; /* Inverse Coefficients */
static u8 fbsub[256];
static u8 rbsub[256];
static u8 ptab[256],ltab[256];
static u32 ftable[256];
static u32 rtable[256];
static u32 rco[30];
/* Parameter-dependent data */
int Nk,Nb,Nr;
u8 fi[24],ri[24];
u32 fkey[120];
u32 rkey[120];
static u32 pack(u8 *b)
{ /* pack bytes into a 32-bit Word */
return ((u32)b[3]<<24)|((u32)b[2]<<16)|((u32)b[1]<<8)|(u32)b[0];
}
static void unpack(u32 a,u8 *b)
{ /* unpack bytes from a word */
b[0]=(u8)a;
b[1]=(u8)(a>>8);
b[2]=(u8)(a>>16);
b[3]=(u8)(a>>24);
}
static u8 xtime(u8 a)
{
u8 b;
if (a&0x80) b=0x1B;
else b=0;
a<<=1;
a^=b;
return a;
}
static u8 bmul(u8 x,u8 y)
{ /* x.y= AntiLog(Log(x) + Log(y)) */
if (x && y) return ptab[(ltab[x]+ltab[y])%255];
else return 0;
}
static u32 SubByte(u32 a)
{
u8 b[4];
unpack(a,b);
b[0]=fbsub[b[0]];
b[1]=fbsub[b[1]];
b[2]=fbsub[b[2]];
b[3]=fbsub[b[3]];
return pack(b);
}
static u8 product(u32 x,u32 y)
{ /* dot product of two 4-byte arrays */
u8 xb[4],yb[4];
unpack(x,xb);
unpack(y,yb);
return bmul(xb[0],yb[0])^bmul(xb[1],yb[1])^bmul(xb[2],yb[2])^bmul(xb[3],yb[3]);
}
static u32 InvMixCol(u32 x)
{ /* matrix Multiplication */
u32 y,m;
u8 b[4];
m=pack(InCo);
b[3]=product(m,x);
m=ROTL24(m);
b[2]=product(m,x);
m=ROTL24(m);
b[1]=product(m,x);
m=ROTL24(m);
b[0]=product(m,x);
y=pack(b);
return y;
}
u8 ByteSub(u8 x)
{
u8 y=ptab[255-ltab[x]]; /* multiplicative inverse */
x=y; x=ROTL(x);
y^=x; x=ROTL(x);
y^=x; x=ROTL(x);
y^=x; x=ROTL(x);
y^=x; y^=0x63;
return y;
}
void gentables(void)
{ /* generate tables */
int i;
u8 y,b[4];
/* use 3 as primitive root to generate power and log tables */
ltab[0]=0;
ptab[0]=1; ltab[1]=0;
ptab[1]=3; ltab[3]=1;
for (i=2;i<256;i++)
{
ptab[i]=ptab[i-1]^xtime(ptab[i-1]);
ltab[ptab[i]]=i;
}
/* affine transformation:- each bit is xored with itself shifted one bit */
fbsub[0]=0x63;
rbsub[0x63]=0;
for (i=1;i<256;i++)
{
y=ByteSub((u8)i);
fbsub[i]=y; rbsub[y]=i;
}
for (i=0,y=1;i<30;i++)
{
rco[i]=y;
y=xtime(y);
}
/* calculate forward and reverse tables */
for (i=0;i<256;i++)
{
y=fbsub[i];
b[3]=y^xtime(y); b[2]=y;
b[1]=y; b[0]=xtime(y);
ftable[i]=pack(b);
y=rbsub[i];
b[3]=bmul(InCo[0],y); b[2]=bmul(InCo[1],y);
b[1]=bmul(InCo[2],y); b[0]=bmul(InCo[3],y);
rtable[i]=pack(b);
}
}
void gkey(int nb,int nk,char *key)
{ /* blocksize=32*nb bits. Key=32*nk bits */
/* currently nb,bk = 4, 6 or 8 */
/* key comes as 4*Nk bytes */
/* Key Scheduler. Create expanded encryption key */
int i,j,k,m,N;
int C1,C2,C3;
u32 CipherKey[8];
Nb=nb; Nk=nk;
/* Nr is number of rounds */
if (Nb>=Nk) Nr=6+Nb;
else Nr=6+Nk;
C1=1;
if (Nb<8) { C2=2; C3=3; }
else { C2=3; C3=4; }
/* pre-calculate forward and reverse increments */
for (m=j=0;j<nb;j++,m+=3)
{
fi[m]=(j+C1)%nb;
fi[m+1]=(j+C2)%nb;
fi[m+2]=(j+C3)%nb;
ri[m]=(nb+j-C1)%nb;
ri[m+1]=(nb+j-C2)%nb;
ri[m+2]=(nb+j-C3)%nb;
}
N=Nb*(Nr+1);
for (i=j=0;i<Nk;i++,j+=4)
{
CipherKey[i]=pack((u8 *)&key[j]);
}
for (i=0;i<Nk;i++) fkey[i]=CipherKey[i];
for (j=Nk,k=0;j<N;j+=Nk,k++)
{
fkey[j]=fkey[j-Nk]^SubByte(ROTL24(fkey[j-1]))^rco[k];
if (Nk<=6)
{
for (i=1;i<Nk && (i+j)<N;i++)
fkey[i+j]=fkey[i+j-Nk]^fkey[i+j-1];
}
else
{
for (i=1;i<4 &&(i+j)<N;i++)
fkey[i+j]=fkey[i+j-Nk]^fkey[i+j-1];
if ((j+4)<N) fkey[j+4]=fkey[j+4-Nk]^SubByte(fkey[j+3]);
for (i=5;i<Nk && (i+j)<N;i++)
fkey[i+j]=fkey[i+j-Nk]^fkey[i+j-1];
}
}
/* now for the expanded decrypt key in reverse order */
for (j=0;j<Nb;j++) rkey[j+N-Nb]=fkey[j];
for (i=Nb;i<N-Nb;i+=Nb)
{
k=N-Nb-i;
for (j=0;j<Nb;j++) rkey[k+j]=InvMixCol(fkey[i+j]);
}
for (j=N-Nb;j<N;j++) rkey[j-N+Nb]=fkey[j];
}
/* There is an obvious time/space trade-off possible here. *
* Instead of just one ftable[], I could have 4, the other *
* 3 pre-rotated to save the ROTL8, ROTL16 and ROTL24 overhead */
void encrypt(char *buff)
{
int i,j,k,m;
u32 a[8],b[8],*x,*y,*t;
for (i=j=0;i<Nb;i++,j+=4)
{
a[i]=pack((u8 *)&buff[j]);
a[i]^=fkey[i];
}
k=Nb;
x=a; y=b;
/* State alternates between a and b */
for (i=1;i<Nr;i++)
{ /* Nr is number of rounds. May be odd. */
/* if Nb is fixed - unroll this next
loop and hard-code in the values of fi[] */
for (m=j=0;j<Nb;j++,m+=3)
{ /* deal with each 32-bit element of the State */
/* This is the time-critical bit */
y[j]=fkey[k++]^ftable[(u8)x[j]]^
ROTL8(ftable[(u8)(x[fi[m]]>>8)])^
ROTL16(ftable[(u8)(x[fi[m+1]]>>16)])^
ROTL24(ftable[x[fi[m+2]]>>24]);
}
t=x; x=y; y=t; /* swap pointers */
}
/* Last Round - unroll if possible */
for (m=j=0;j<Nb;j++,m+=3)
{
y[j]=fkey[k++]^(u32)fbsub[(u8)x[j]]^
ROTL8((u32)fbsub[(u8)(x[fi[m]]>>8)])^
ROTL16((u32)fbsub[(u8)(x[fi[m+1]]>>16)])^
ROTL24((u32)fbsub[x[fi[m+2]]>>24]);
}
for (i=j=0;i<Nb;i++,j+=4)
{
unpack(y[i],(u8 *)&buff[j]);
x[i]=y[i]=0; /* clean up stack */
}
return;
}
void decrypt(char *buff)
{
int i,j,k,m;
u32 a[8],b[8],*x,*y,*t;
for (i=j=0;i<Nb;i++,j+=4)
{
a[i]=pack((u8 *)&buff[j]);
a[i]^=rkey[i];
}
k=Nb;
x=a; y=b;
/* State alternates between a and b */
for (i=1;i<Nr;i++)
{ /* Nr is number of rounds. May be odd. */
/* if Nb is fixed - unroll this next
loop and hard-code in the values of ri[] */
for (m=j=0;j<Nb;j++,m+=3)
{ /* This is the time-critical bit */
y[j]=rkey[k++]^rtable[(u8)x[j]]^
ROTL8(rtable[(u8)(x[ri[m]]>>8)])^
ROTL16(rtable[(u8)(x[ri[m+1]]>>16)])^
ROTL24(rtable[x[ri[m+2]]>>24]);
}
t=x; x=y; y=t; /* swap pointers */
}
/* Last Round - unroll if possible */
for (m=j=0;j<Nb;j++,m+=3)
{
y[j]=rkey[k++]^(u32)rbsub[(u8)x[j]]^
ROTL8((u32)rbsub[(u8)(x[ri[m]]>>8)])^
ROTL16((u32)rbsub[(u8)(x[ri[m+1]]>>16)])^
ROTL24((u32)rbsub[x[ri[m+2]]>>24]);
}
for (i=j=0;i<Nb;i++,j+=4)
{
unpack(y[i],(u8 *)&buff[j]);
x[i]=y[i]=0; /* clean up stack */
}
return;
}
void aes_set_key(u8 *key) {
gentables();
gkey(4, 4,(char*) key);
}
// CBC mode decryption
void aes_decrypt(u8 *iv, u8 *inbuf, u8 *outbuf, unsigned long long len) {
u8 block[16];
unsigned int blockno = 0, i;
//printf("aes_decrypt(%p, %p, %p, %lld)\n", iv, inbuf, outbuf, len);
for (blockno = 0; blockno <= (len / sizeof(block)); blockno++) {
unsigned int fraction;
if (blockno == (len / sizeof(block))) { // last block
fraction = len % sizeof(block);
if (fraction == 0) break;
memset(block, 0, sizeof(block));
} else fraction = 16;
// debug_printf("block %d: fraction = %d\n", blockno, fraction);
memcpy(block, inbuf + blockno * sizeof(block), fraction);
decrypt((char*)block);
u8 *ctext_ptr;
if (blockno == 0) ctext_ptr = iv;
else ctext_ptr = inbuf + (blockno-1) * sizeof(block);
for(i=0; i < fraction; i++)
outbuf[blockno * sizeof(block) + i] =
ctext_ptr[i] ^ block[i];
// debug_printf("Block %d output: ", blockno);
// hexdump(outbuf + blockno*sizeof(block), 16);
}
}
// CBC mode encryption
void aes_encrypt(u8 *iv, u8 *inbuf, u8 *outbuf, unsigned long long len) {
u8 block[16];
unsigned int blockno = 0, i;
// debug_printf("aes_decrypt(%p, %p, %p, %lld)\n", iv, inbuf, outbuf, len);
for (blockno = 0; blockno <= (len / sizeof(block)); blockno++) {
unsigned int fraction;
if (blockno == (len / sizeof(block))) { // last block
fraction = len % sizeof(block);
if (fraction == 0) break;
memset(block, 0, sizeof(block));
} else fraction = 16;
// debug_printf("block %d: fraction = %d\n", blockno, fraction);
memcpy(block, inbuf + blockno * sizeof(block), fraction);
for(i=0; i < fraction; i++)
block[i] = inbuf[blockno * sizeof(block) + i] ^ iv[i];
encrypt((char*)block);
memcpy(iv, block, sizeof(block));
memcpy(outbuf + blockno * sizeof(block), block, sizeof(block));
// debug_printf("Block %d output: ", blockno);
// hexdump(outbuf + blockno*sizeof(block), 16);
}
}

337
source/libwbfs/wiidisc.c Normal file
View File

@ -0,0 +1,337 @@
// Copyright 2009 Kwiirk based on negentig.c:
// Copyright 2007,2008 Segher Boessenkool <segher@kernel.crashing.org>
// Licensed under the terms of the GNU GPL, version 2
// http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
#include "wiidisc.h"
void aes_set_key(u8 *key);
void aes_decrypt(u8 *iv, u8 *inbuf, u8 *outbuf, unsigned long long len);
static void _decrypt_title_key(u8 *tik, u8 *title_key)
{
u8 common_key[16]={
0xeb, 0xe4, 0x2a, 0x22, 0x5e, 0x85, 0x93, 0xe4, 0x48, 0xd9, 0xc5, 0x45,
0x73, 0x81, 0xaa, 0xf7
};;
u8 iv[16];
wbfs_memset(iv, 0, sizeof iv);
wbfs_memcpy(iv, tik + 0x01dc, 8);
aes_set_key(common_key);
//_aes_cbc_dec(common_key, iv, tik + 0x01bf, 16, title_key);
aes_decrypt(iv, tik + 0x01bf,title_key,16);
}
static u32 _be32(const u8 *p)
{
return (p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3];
}
static void disc_read(wiidisc_t *d,u32 offset, u8 *data, u32 len)
{
if(data){
int ret=0;
if(len==0)
return ;
ret = d->read(d->fp,offset,len,data);
if(ret)
wbfs_fatal("error reading disc");
}
if(d->sector_usage_table)
{
u32 blockno = offset>>13;
do
{
d->sector_usage_table[blockno]=1;
blockno+=1;
if(len>0x8000)
len-=0x8000;
}while(len>0x8000);
}
}
static void partition_raw_read(wiidisc_t *d,u32 offset, u8 *data, u32 len)
{
disc_read(d, d->partition_raw_offset + offset, data, len);
}
static void partition_read_block(wiidisc_t *d,u32 blockno, u8 *block)
{
u8*raw = d->tmp_buffer;
u8 iv[16];
u32 offset;
if(d->sector_usage_table)
d->sector_usage_table[d->partition_block+blockno]=1;
offset = d->partition_data_offset + ((0x8000>>2) * blockno);
partition_raw_read(d,offset, raw, 0x8000);
// decrypt data
memcpy(iv, raw + 0x3d0, 16);
aes_set_key(d->disc_key);
aes_decrypt(iv, raw + 0x400,block,0x7c00);
}
static void partition_read(wiidisc_t *d,u32 offset, u8 *data, u32 len,int fake)
{
u8 *block = d->tmp_buffer2;
u32 offset_in_block;
u32 len_in_block;
if(fake && d->sector_usage_table==0)
return;
while(len) {
offset_in_block = offset % (0x7c00>>2);
len_in_block = 0x7c00 - (offset_in_block<<2);
if (len_in_block > len)
len_in_block = len;
if(!fake){
partition_read_block(d,offset / (0x7c00>>2), block);
wbfs_memcpy(data, block + (offset_in_block<<2), len_in_block);
}else
d->sector_usage_table[d->partition_block+(offset/(0x7c00>>2))]=1;
data += len_in_block;
offset += len_in_block>>2;
len -= len_in_block;
}
}
static u32 do_fst(wiidisc_t *d,u8 *fst, const char *names, u32 i)
{
u32 offset;
u32 size;
const char *name;
u32 j;
name = names + (_be32(fst + 12*i) & 0x00ffffff);
size = _be32(fst + 12*i + 8);
if (i == 0) {
for (j = 1; j < size && !d->extracted_buffer; ){
j = do_fst(d,fst, names, j);
}
return size;
}
//printf("name %s\n",name);
if (fst[12*i]) {
for (j = i + 1; j < size && !d->extracted_buffer; )
j = do_fst(d,fst, names, j);
return size;
} else {
offset = _be32(fst + 12*i + 4);
if(d->extract_pathname && strcmp(name, d->extract_pathname)==0)
{
d->extracted_buffer = wbfs_ioalloc(size);
partition_read(d,offset, d->extracted_buffer, size,0);
}else
partition_read(d,offset, 0, size,1);
return i + 1;
}
}
static void do_files(wiidisc_t*d)
{
u8 *b = wbfs_ioalloc(0x480); // XXX: determine actual header size
u32 dol_offset;
u32 fst_offset;
u32 fst_size;
u32 apl_offset;
u32 apl_size;
u8 *apl_header = wbfs_ioalloc(0x20);
u8 *fst;
u32 n_files;
partition_read(d,0, b, 0x480,0);
dol_offset = _be32(b + 0x0420);
fst_offset = _be32(b + 0x0424);
fst_size = _be32(b + 0x0428)<<2;
apl_offset = 0x2440>>2;
partition_read(d,apl_offset, apl_header, 0x20,0);
apl_size = 0x20 + _be32(apl_header + 0x14) + _be32(apl_header + 0x18);
// fake read dol and partition
partition_read(d,apl_offset, 0, apl_size,1);
partition_read(d,dol_offset, 0, (fst_offset - dol_offset)<<2,1);
fst = wbfs_ioalloc(fst_size);
if (fst == 0)
wbfs_fatal("malloc fst");
partition_read(d,fst_offset, fst, fst_size,0);
n_files = _be32(fst + 8);
if (n_files > 1)
do_fst(d,fst, (char *)fst + 12*n_files, 0);
wbfs_iofree(b);
wbfs_iofree(apl_header);
wbfs_iofree(fst);
}
static void do_partition(wiidisc_t*d)
{
u8 *tik = wbfs_ioalloc(0x2a4);
u8 *b = wbfs_ioalloc(0x1c);
u64 tmd_offset;
u32 tmd_size;
u8 *tmd;
u64 cert_offset;
u32 cert_size;
u8 *cert;
u64 h3_offset;
// read ticket, and read some offsets and sizes
partition_raw_read(d,0, tik, 0x2a4);
partition_raw_read(d,0x2a4>>2, b, 0x1c);
tmd_size = _be32(b);
tmd_offset = _be32(b + 4);
cert_size = _be32(b + 8);
cert_offset = _be32(b + 0x0c);
h3_offset = _be32(b + 0x10);
d->partition_data_offset = _be32(b + 0x14);
d->partition_block = (d->partition_raw_offset+d->partition_data_offset)>>13;
tmd = wbfs_ioalloc(tmd_size);
if (tmd == 0)
wbfs_fatal("malloc tmd");
partition_raw_read(d,tmd_offset, tmd, tmd_size);
cert = wbfs_ioalloc(cert_size);
if (cert == 0)
wbfs_fatal("malloc cert");
partition_raw_read(d,cert_offset, cert, cert_size);
_decrypt_title_key(tik, d->disc_key);
partition_raw_read(d,h3_offset, 0, 0x18000);
wbfs_iofree(b);
wbfs_iofree(tik);
wbfs_iofree(cert);
wbfs_iofree(tmd);
do_files(d);
}
static int test_parition_skip(u32 partition_type,partition_selector_t part_sel)
{
switch(part_sel)
{
case ALL_PARTITIONS:
return 0;
case REMOVE_UPDATE_PARTITION:
return (partition_type==1);
case ONLY_GAME_PARTITION:
return (partition_type!=0);
default:
return (partition_type!=part_sel);
}
}
static void do_disc(wiidisc_t*d)
{
u8 *b = wbfs_ioalloc(0x100);
u64 partition_offset[32]; // XXX: don't know the real maximum
u64 partition_type[32]; // XXX: don't know the real maximum
u32 n_partitions;
u32 magic;
u32 i;
disc_read(d,0, b, 0x100);
magic=_be32(b+24);
if(magic!=0x5D1C9EA3){
wbfs_error("not a wii disc");
return ;
}
disc_read(d,0x40000>>2, b, 0x100);
n_partitions = _be32(b);
disc_read(d,_be32(b + 4), b, 0x100);
for (i = 0; i < n_partitions; i++){
partition_offset[i] = _be32(b + 8 * i);
partition_type[i] = _be32(b + 8 * i+4);
}
for (i = 0; i < n_partitions; i++) {
d->partition_raw_offset = partition_offset[i];
if(!test_parition_skip(partition_type[i],d->part_sel))
do_partition(d);
}
wbfs_iofree(b);
}
wiidisc_t *wd_open_disc(read_wiidisc_callback_t read,void*fp)
{
wiidisc_t *d = wbfs_malloc(sizeof(wiidisc_t));
if(!d)
return 0;
wbfs_memset(d,0,sizeof(wiidisc_t));
d->read = read;
d->fp = fp;
d->part_sel = ALL_PARTITIONS;
d->tmp_buffer = wbfs_ioalloc(0x8000);
d->tmp_buffer2 = wbfs_malloc(0x8000);
return d;
}
void wd_close_disc(wiidisc_t *d)
{
wbfs_iofree(d->tmp_buffer);
wbfs_free(d->tmp_buffer2);
wbfs_free(d);
}
// returns a buffer allocated with wbfs_ioalloc() or NULL if not found of alloc error
// XXX pathname not implemented. files are extracted by their name.
// first file found with that name is returned.
u8 * wd_extract_file(wiidisc_t *d, partition_selector_t partition_type, char *pathname)
{
u8 *retval = 0;
d->extract_pathname = pathname;
d->extracted_buffer = 0;
d->part_sel = partition_type;
do_disc(d);
d->extract_pathname = 0;
d->part_sel = ALL_PARTITIONS;
retval = d->extracted_buffer;
d->extracted_buffer = 0;
return retval;
}
void wd_build_disc_usage(wiidisc_t *d, partition_selector_t selector, u8* usage_table)
{
d->sector_usage_table = usage_table;
wbfs_memset(usage_table,0,143432*2);
d->part_sel = selector;
do_disc(d);
d->part_sel = ALL_PARTITIONS;
d->sector_usage_table = 0;
}
void wd_fix_partition_table(wiidisc_t *d, partition_selector_t selector, u8* partition_table)
{
u8 *b = partition_table;
u32 partition_offset;
u32 partition_type;
u32 n_partitions,i,j;
u32 *b32;
if(selector == ALL_PARTITIONS)
return;
n_partitions = _be32(b);
if(_be32(b + 4)-(0x40000>>2) >0x50)
wbfs_fatal("cannot modify this partition table. Please report the bug.");
b += (_be32(b + 4)-(0x40000>>2))*4;
j=0;
for (i = 0; i < n_partitions; i++){
partition_offset = _be32(b + 8 * i);
partition_type = _be32(b + 8 * i+4);
if(!test_parition_skip(partition_type,selector))
{
b32 = (u32*)(b + 8 * j);
b32[0] = wbfs_htonl(partition_offset);
b32[1] = wbfs_htonl(partition_type);
j++;
}
}
b32 = (u32*)(partition_table);
*b32 = wbfs_htonl(j);
}

67
source/libwbfs/wiidisc.h Normal file
View File

@ -0,0 +1,67 @@
#ifndef WIIDISC_H
#define WIIDISC_H
#include <stdio.h>
#include "libwbfs_os.h" // this file is provided by the project wanting to compile libwbfs and wiidisc
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
#if 0 //removes extra automatic indentation by editors
}
#endif
// callback definition. Return 1 on fatal error (callback is supposed to make retries until no hopes..)
// offset points 32bit words, count counts bytes
typedef int (*read_wiidisc_callback_t)(void*fp,u32 offset,u32 count,void*iobuf);
typedef enum{
UPDATE_PARTITION_TYPE=0,
GAME_PARTITION_TYPE,
OTHER_PARTITION_TYPE,
// value in between selects partition types of that value
ALL_PARTITIONS=0xffffffff-3,
REMOVE_UPDATE_PARTITION, // keeps game + channel installers
ONLY_GAME_PARTITION,
}partition_selector_t;
typedef struct wiidisc_s
{
read_wiidisc_callback_t read;
void *fp;
u8 *sector_usage_table;
// everything points 32bit words.
u32 disc_raw_offset;
u32 partition_raw_offset;
u32 partition_data_offset;
u32 partition_data_size;
u32 partition_block;
u8 *tmp_buffer;
u8 *tmp_buffer2;
u8 disc_key[16];
int dont_decrypt;
partition_selector_t part_sel;
char *extract_pathname;
u8 *extracted_buffer;
}wiidisc_t;
wiidisc_t *wd_open_disc(read_wiidisc_callback_t read,void*fp);
void wd_close_disc(wiidisc_t *);
// returns a buffer allocated with wbfs_ioalloc() or NULL if not found of alloc error
u8 * wd_extract_file(wiidisc_t *d, partition_selector_t partition_type, char *pathname);
void wd_build_disc_usage(wiidisc_t *d, partition_selector_t selector, u8* usage_table);
// effectively remove not copied partition from the partition table.
void wd_fix_partition_table(wiidisc_t *d, partition_selector_t selector, u8* partition_table);
#if 0
{
#endif
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif

839
source/libwiigui/gui.h Normal file
View File

@ -0,0 +1,839 @@
/*!\mainpage libwiigui Documentation
*
* \section Introduction
* libwiigui is a GUI library for the Wii, created to help structure the
* design of a complicated GUI interface, and to enable an author to create
* a sophisticated, feature-rich GUI. It was originally conceived and written
* after I started to design a GUI for Snes9x GX, and found libwiisprite and
* GRRLIB inadequate for the purpose. It uses GX for drawing, and makes use
* of PNGU for displaying images and FreeTypeGX for text. It was designed to
* be flexible and is easy to modify - don't be afraid to change the way it
* works or expand it to suit your GUI's purposes! If you do, and you think
* your changes might benefit others, please share them so they might be
* added to the project!
*
* \section Quickstart
* Start from the supplied template example. For more advanced uses, see the
* source code for Snes9x GX, FCE Ultra GX, and Visual Boy Advance GX.
* \section Contact
* If you have any suggestions for the library or documentation, or want to
* contribute, please visit the libwiigui website:
* http://code.google.com/p/libwiigui/
* \section Credits
* This library was wholly designed and written by Tantric. Thanks to the
* authors of PNGU and FreeTypeGX, of which this library makes use. Thanks
* also to the authors of GRRLIB and libwiisprite for laying the foundations.
*
*/
#ifndef LIBWIIGUI_H
#define LIBWIIGUI_H
#include <gccore.h>
#include <malloc.h>
#include <stdlib.h>
#include <string.h>
#include <vector>
#include <math.h>
#include <asndlib.h>
#include <wiiuse/wpad.h>
#include "pngu/pngu.h"
#include "FreeTypeGX.h"
#include "video.h"
#include "filelist.h"
#include "input.h"
#include "oggplayer.h"
extern FreeTypeGX *fontSystem;
#define SCROLL_INITIAL_DELAY 20
#define SCROLL_LOOP_DELAY 3
#define PAGESIZE 9
#define MAX_OPTIONS 170
typedef void (*UpdateCallback)(void * e);
enum
{
ALIGN_LEFT,
ALIGN_RIGHT,
ALIGN_CENTRE,
ALIGN_TOP,
ALIGN_BOTTOM,
ALIGN_MIDDLE
};
enum
{
STATE_DEFAULT,
STATE_SELECTED,
STATE_CLICKED,
STATE_HELD,
STATE_DISABLED
};
enum
{
SOUND_PCM,
SOUND_OGG
};
enum
{
IMAGE_TEXTURE,
IMAGE_COLOR,
IMAGE_DATA
};
enum
{
TRIGGER_SIMPLE,
TRIGGER_HELD,
TRIGGER_BUTTON_ONLY,
TRIGGER_BUTTON_ONLY_IN_FOCUS
};
typedef struct _paddata {
u16 btns_d;
u16 btns_u;
u16 btns_h;
s8 stickX;
s8 stickY;
s8 substickX;
s8 substickY;
u8 triggerL;
u8 triggerR;
} PADData;
#define EFFECT_SLIDE_TOP 1
#define EFFECT_SLIDE_BOTTOM 2
#define EFFECT_SLIDE_RIGHT 4
#define EFFECT_SLIDE_LEFT 8
#define EFFECT_SLIDE_IN 16
#define EFFECT_SLIDE_OUT 32
#define EFFECT_FADE 64
#define EFFECT_SCALE 128
#define EFFECT_COLOR_TRANSITION 256
//!Sound conversion and playback. A wrapper for other sound libraries - ASND, libmad, ltremor, etc
class GuiSound
{
public:
//!Constructor
//!\param s Pointer to the sound data
//!\param l Length of sound data
//!\param t Sound format type (SOUND_PCM or SOUND_OGG)
GuiSound(const u8 * s, int l, int t);
GuiSound(const u8 * s, int l, int t, int v);
//!Destructor
~GuiSound();
//!Start sound playback
void Play();
//!Stop sound playback
void Stop();
//!Pause sound playback
void Pause();
//!Resume sound playback
void Resume();
//!Checks if the sound is currently playing
//!\return true if sound is playing, false otherwise
bool IsPlaying();
//!Set sound volume
//!\param v Sound volume (0-100)
void SetVolume(int v);
//!Set the sound to loop playback (only applies to OGG)
//!\param l Loop (true to loop)
void SetLoop(bool l);
protected:
const u8 * sound; //!< Pointer to the sound data
int type; //!< Sound format type (SOUND_PCM or SOUND_OGG)
s32 length; //!< Length of sound data
s32 voice; //!< Currently assigned ASND voice channel
s32 volume; //!< Sound volume (0-100)
bool loop; //!< Loop sound playback
};
//!Menu input trigger management. Determine if action is neccessary based on input data by comparing controller input data to a specific trigger element.
class GuiTrigger
{
public:
//!Constructor
GuiTrigger();
//!Destructor
~GuiTrigger();
//!Sets a simple trigger. Requires: element is selected, and trigger button is pressed
//!\param ch Controller channel number
//!\param wiibtns Wii controller trigger button(s) - classic controller buttons are considered separately
//!\param gcbtns GameCube controller trigger button(s)
void SetSimpleTrigger(s32 ch, u32 wiibtns, u16 gcbtns);
//!Sets a held trigger. Requires: element is selected, and trigger button is pressed
//!\param ch Controller channel number
//!\param wiibtns Wii controller trigger button(s) - classic controller buttons are considered separately
//!\param gcbtns GameCube controller trigger button(s)
void SetHeldTrigger(s32 ch, u32 wiibtns, u16 gcbtns);
//!Sets a button-only trigger. Requires: Trigger button is pressed
//!\param ch Controller channel number
//!\param wiibtns Wii controller trigger button(s) - classic controller buttons are considered separately
//!\param gcbtns GameCube controller trigger button(s)
void SetButtonOnlyTrigger(s32 ch, u32 wiibtns, u16 gcbtns);
//!Sets a button-only trigger. Requires: trigger button is pressed and parent window of element is in focus
//!\param ch Controller channel number
//!\param wiibtns Wii controller trigger button(s) - classic controller buttons are considered separately
//!\param gcbtns GameCube controller trigger button(s)
void SetButtonOnlyInFocusTrigger(s32 ch, u32 wiibtns, u16 gcbtns);
//!Get X/Y value from Wii Joystick (classic, nunchuk) input
//!\param right Controller stick (left = 0, right = 1)
//!\param axis Controller stick axis (x-axis = 0, y-axis = 1)
//!\return Stick value
s8 WPAD_Stick(u8 right, int axis);
//!Move menu selection left (via pad/joystick). Allows scroll delay and button overriding
//!\return true if selection should be moved left, false otherwise
bool Left();
//!Move menu selection right (via pad/joystick). Allows scroll delay and button overriding
//!\return true if selection should be moved right, false otherwise
bool Right();
//!Move menu selection up (via pad/joystick). Allows scroll delay and button overriding
//!\return true if selection should be moved up, false otherwise
bool Up();
//!Move menu selection down (via pad/joystick). Allows scroll delay and button overriding
//!\return true if selection should be moved down, false otherwise
bool Down();
u8 type; //!< trigger type (TRIGGER_SIMPLE, TRIGGER_HELD, TRIGGER_BUTTON_ONLY, TRIGGER_BUTTON_ONLY_IN_FOCUS)
s32 chan; //!< Trigger controller channel (0-3, -1 for all)
WPADData wpad; //!< Wii controller trigger data
PADData pad; //!< GameCube controller trigger data
};
extern GuiTrigger userInput[4];
//!Primary GUI class. Most other classes inherit from this class.
class GuiElement
{
public:
//!Constructor
GuiElement();
//!Destructor
~GuiElement();
//!Set the element's parent
//!\param e Pointer to parent element
void SetParent(GuiElement * e);
//!Gets the current leftmost coordinate of the element
//!Considers horizontal alignment, x offset, width, and parent element's GetLeft() / GetWidth() values
//!\return left coordinate
int GetLeft();
//!Gets the current topmost coordinate of the element
//!Considers vertical alignment, y offset, height, and parent element's GetTop() / GetHeight() values
//!\return top coordinate
int GetTop();
//!Sets the minimum y offset of the element
//!\param y Y offset
void SetMinY(int y);
//!Gets the minimum y offset of the element
//!\return Minimum Y offset
int GetMinY();
//!Sets the maximum y offset of the element
//!\param y Y offset
void SetMaxY(int y);
//!Gets the maximum y offset of the element
//!\return Maximum Y offset
int GetMaxY();
//!Sets the minimum x offset of the element
//!\param x X offset
void SetMinX(int x);
//!Gets the minimum x offset of the element
//!\return Minimum X offset
int GetMinX();
//!Sets the maximum x offset of the element
//!\param x X offset
void SetMaxX(int x);
//!Gets the maximum x offset of the element
//!\return Maximum X offset
int GetMaxX();
//!Gets the current width of the element. Does not currently consider the scale
//!\return width
int GetWidth();
//!Gets the height of the element. Does not currently consider the scale
//!\return height
int GetHeight();
//!Sets the size (width/height) of the element
//!\param w Width of element
//!\param h Height of element
void SetSize(int w, int h);
//!Checks whether or not the element is visible
//!\return true if visible, false otherwise
bool IsVisible();
//!Checks whether or not the element is selectable
//!\return true if selectable, false otherwise
bool IsSelectable();
//!Checks whether or not the element is clickable
//!\return true if clickable, false otherwise
bool IsClickable();
//!Checks whether or not the element is holdable
//!\return true if holdable, false otherwise
bool IsHoldable();
//!Sets whether or not the element is selectable
//!\param s Selectable
void SetSelectable(bool s);
//!Sets whether or not the element is clickable
//!\param c Clickable
void SetClickable(bool c);
//!Sets whether or not the element is holdable
//!\param c Holdable
void SetHoldable(bool d);
//!Gets the element's current state
//!\return state
int GetState();
//!Gets the controller channel that last changed the element's state
//!\return Channel number (0-3, -1 = no channel)
int GetStateChan();
//!Sets the element's alpha value
//!\param a alpha value
void SetAlpha(int a);
//!Gets the element's alpha value
//!Considers alpha, alphaDyn, and the parent element's GetAlpha() value
//!\return alpha
int GetAlpha();
//!Sets the element's scale
//!\param s scale (1 is 100%)
void SetScale(float s);
//!Gets the element's current scale
//!Considers scale, scaleDyn, and the parent element's GetScale() value
float GetScale();
//!Set a new GuiTrigger for the element
//!\param t Pointer to GuiTrigger
void SetTrigger(GuiTrigger * t);
//!\overload
//!\param i Index of trigger array to set
//!\param t Pointer to GuiTrigger
void SetTrigger(u8 i, GuiTrigger * t);
//!Checks whether rumble was requested by the element
//!\return true is rumble was requested, false otherwise
bool Rumble();
//!Sets whether or not the element is requesting a rumble event
//!\param r true if requesting rumble, false if not
void SetRumble(bool r);
//!Set an effect for the element
//!\param e Effect to enable
//!\param a Amount of the effect (usage varies on effect)
//!\param t Target amount of the effect (usage varies on effect)
void SetEffect(int e, int a, int t=0);
//!Sets an effect to be enabled on wiimote cursor over
//!\param e Effect to enable
//!\param a Amount of the effect (usage varies on effect)
//!\param t Target amount of the effect (usage varies on effect)
void SetEffectOnOver(int e, int a, int t=0);
//!Shortcut to SetEffectOnOver(EFFECT_SCALE, 4, 110)
void SetEffectGrow();
//!Gets the current element effects
//!\return element effects
int GetEffect();
//!Checks whether the specified coordinates are within the element's boundaries
//!\param x X coordinate
//!\param y Y coordinate
//!\return true if contained within, false otherwise
bool IsInside(int x, int y);
//!Sets the element's position
//!\param x X coordinate
//!\param y Y coordinate
void SetPosition(int x, int y);
//!Updates the element's effects (dynamic values)
//!Called by Draw(), used for animation purposes
void UpdateEffects();
//!Sets a function to called after after Update()
//!Callback function can be used to response to changes in the state of the element, and/or update the element's attributes
void SetUpdateCallback(UpdateCallback u);
//!Checks whether the element is in focus
//!\return true if element is in focus, false otherwise
int IsFocused();
//!Sets the element's visibility
//!\param v Visibility (true = visible)
virtual void SetVisible(bool v);
//!Sets the element's focus
//!\param f Focus (true = in focus)
virtual void SetFocus(int f);
//!Sets the element's state
//!\param s State (STATE_DEFAULT, STATE_SELECTED, STATE_CLICKED, STATE_DISABLED)
//!\param c Controller channel (0-3, -1 = none)
virtual void SetState(int s, int c = -1);
//!Resets the element's state to STATE_DEFAULT
virtual void ResetState();
//!Gets whether or not the element is in STATE_SELECTED
//!\return true if selected, false otherwise
virtual int GetSelected();
//!Sets the element's alignment respective to its parent element
//!\param hor Horizontal alignment (ALIGN_LEFT, ALIGN_RIGHT, ALIGN_CENTRE)
//!\param vert Vertical alignment (ALIGN_TOP, ALIGN_BOTTOM, ALIGN_MIDDLE)
virtual void SetAlignment(int hor, int vert);
//!Called constantly to allow the element to respond to the current input data
//!\param t Pointer to a GuiTrigger, containing the current input data from PAD/WPAD
virtual void Update(GuiTrigger * t);
//!Called constantly to redraw the element
virtual void Draw();
protected:
//int position2; //! B Scrollbariable
bool visible; //!< Visibility of the element. If false, Draw() is skipped
int focus; //!< Element focus (-1 = focus disabled, 0 = not focused, 1 = focused)
int width; //!< Element width
int height; //!< Element height
int xoffset; //!< Element X offset
int yoffset; //!< Element Y offset
int ymin; //!< Element's min Y offset allowed
int ymax; //!< Element's max Y offset allowed
int xmin; //!< Element's min X offset allowed
int xmax; //!< Element's max X offset allowed
int xoffsetDyn; //!< Element X offset, dynamic (added to xoffset value for animation effects)
int yoffsetDyn; //!< Element Y offset, dynamic (added to yoffset value for animation effects)
int alpha; //!< Element alpha value (0-255)
f32 scale; //!< Element scale (1 = 100%)
int alphaDyn; //!< Element alpha, dynamic (multiplied by alpha value for blending/fading effects)
f32 scaleDyn; //!< Element scale, dynamic (multiplied by alpha value for blending/fading effects)
bool rumble; //!< Wiimote rumble (on/off) - set to on when this element requests a rumble event
int effects; //!< Currently enabled effect(s). 0 when no effects are enabled
int effectAmount; //!< Effect amount. Used by different effects for different purposes
int effectTarget; //!< Effect target amount. Used by different effects for different purposes
int effectsOver; //!< Effects to enable when wiimote cursor is over this element. Copied to effects variable on over event
int effectAmountOver; //!< EffectAmount to set when wiimote cursor is over this element
int effectTargetOver; //!< EffectTarget to set when wiimote cursor is over this element
int alignmentHor; //!< Horizontal element alignment, respective to parent element (LEFT, RIGHT, CENTRE)
int alignmentVert; //!< Horizontal element alignment, respective to parent element (TOP, BOTTOM, MIDDLE)
int state; //!< Element state (DEFAULT, SELECTED, CLICKED, DISABLED)
int stateChan; //!< Which controller channel is responsible for the last change in state
bool selectable; //!< Whether or not this element selectable (can change to SELECTED state)
bool clickable; //!< Whether or not this element is clickable (can change to CLICKED state)
bool holdable; //!< Whether or not this element is holdable (can change to HELD state)
GuiTrigger * trigger[5]; //!< GuiTriggers (input actions) that this element responds to
GuiElement * parentElement; //!< Parent element
UpdateCallback updateCB; //!< Callback function to call when this element is updated
};
//!Allows GuiElements to be grouped together into a "window"
class GuiWindow : public GuiElement
{
public:
//!Constructor
GuiWindow();
//!\overload
//!\param w Width of window
//!\param h Height of window
GuiWindow(int w, int h);
//!Destructor
~GuiWindow();
//!Appends a GuiElement to the GuiWindow
//!\param e The GuiElement to append. If it is already in the GuiWindow, it is removed first
void Append(GuiElement* e);
//!Inserts a GuiElement into the GuiWindow at the specified index
//!\param e The GuiElement to insert. If it is already in the GuiWindow, it is removed first
//!\param i Index in which to insert the element
void Insert(GuiElement* e, u32 i);
//!Removes the specified GuiElement from the GuiWindow
//!\param e GuiElement to be removed
void Remove(GuiElement* e);
//!Removes all GuiElements
void RemoveAll();
//!Returns the GuiElement at the specified index
//!\param index The index of the element
//!\return A pointer to the element at the index, NULL on error (eg: out of bounds)
GuiElement* GetGuiElementAt(u32 index) const;
//!Returns the size of the list of elements
//!\return The size of the current element list
u32 GetSize();
//!Sets the visibility of the window
//!\param v visibility (true = visible)
void SetVisible(bool v);
//!Resets the window's state to STATE_DEFAULT
void ResetState();
//!Sets the window's state
//!\param s State
void SetState(int s);
//!Gets the index of the GuiElement inside the window that is currently selected
//!\return index of selected GuiElement
int GetSelected();
//!Sets the window focus
//!\param f Focus
void SetFocus(int f);
//!Change the focus to the specified element
//!This is intended for the primary GuiWindow only
//!\param e GuiElement that should have focus
void ChangeFocus(GuiElement * e);
//!Changes window focus to the next focusable window or element
//!If no element is in focus, changes focus to the first available element
//!If B or 1 button is pressed, changes focus to the next available element
//!This is intended for the primary GuiWindow only
//!\param t Pointer to a GuiTrigger, containing the current input data from PAD/WPAD
void ToggleFocus(GuiTrigger * t);
//!Moves the selected element to the element to the left or right
//!\param d Direction to move (-1 = left, 1 = right)
void MoveSelectionHor(int d);
//!Moves the selected element to the element above or below
//!\param d Direction to move (-1 = up, 1 = down)
void MoveSelectionVert(int d);
//!Draws all the elements in this GuiWindow
void Draw();
//!Updates the window and all elements contains within
//!Allows the GuiWindow and all elements to respond to the input data specified
//!\param t Pointer to a GuiTrigger, containing the current input data from PAD/WPAD
void Update(GuiTrigger * t);
protected:
std::vector<GuiElement*> _elements; //!< Contains all elements within the GuiWindow
};
//!Converts image data into GX-useable RGBA8. Currently designed for use only with PNG files
class GuiImageData
{
public:
//!Constructor
//!Converts the image data to RGBA8 - expects PNG format
//!\param i Image data
GuiImageData(const u8 * i);
GuiImageData(const char * imgPath, const u8 * buffer);
//!Destructor
~GuiImageData();
//!Gets a pointer to the image data
//!\return pointer to image data
u8 * GetImage();
//!Gets the image width
//!\return image width
int GetWidth();
//!Gets the image height
//!\return image height
int GetHeight();
protected:
u8 * data; //!< Image data
int height; //!< Height of image
int width; //!< Width of image
};
//!Display, manage, and manipulate images in the GUI
class GuiImage : public GuiElement
{
public:
//!Constructor
GuiImage();
//!\overload
//!\param img Pointer to GuiImageData element
GuiImage(GuiImageData * img);
//!\overload
//!Sets up a new image from the image data specified
//!\param img
//!\param w Image width
//!\param h Image height
GuiImage(u8 * img, int w, int h);
//!\overload
//!Creates an image filled with the specified color
//!\param w Image width
//!\param h Image height
//!\param c Image color
GuiImage(int w, int h, GXColor c);
//!Destructor
~GuiImage();
//!Sets the image rotation angle for drawing
//!\param a Angle (in degrees)
void SetAngle(float a);
//!Sets the number of times to draw the image horizontally
//!\param t Number of times to draw the image
void SetTile(int t);
// not NULL set horizontal scale to 0.8 //added
void SetWidescreen(short w);
//!Constantly called to draw the image
void Draw();
//!Gets the image data
//!\return pointer to image data
u8 * GetImage();
//!Sets up a new image using the GuiImageData object specified
//!\param img Pointer to GuiImageData object
void SetImage(GuiImageData * img);
//!\overload
//!\param img Pointer to image data
//!\param w Width
//!\param h Height
void SetImage(u8 * img, int w, int h);
//!Gets the pixel color at the specified coordinates of the image
//!\param x X coordinate
//!\param y Y coordinate
GXColor GetPixel(int x, int y);
//!Sets the pixel color at the specified coordinates of the image
//!\param x X coordinate
//!\param y Y coordinate
//!\param color Pixel color
void SetPixel(int x, int y, GXColor color);
//!Directly modifies the image data to create a color-striped effect
//!Alters the RGB values by the specified amount
//!\param s Amount to increment/decrement the RGB values in the image
void ColorStripe(int s);
//!Sets a stripe effect on the image, overlaying alpha blended rectangles
//!Does not alter the image data
//!\param s Alpha amount to draw over the image
void SetStripe(int s);
protected:
int imgType; //!< Type of image data (IMAGE_TEXTURE, IMAGE_COLOR, IMAGE_DATA)
u8 * image; //!< Poiner to image data. May be shared with GuiImageData data
f32 imageangle; //!< Angle to draw the image
int tile; //!< Number of times to draw (tile) the image horizontally
int stripe; //!< Alpha value (0-255) to apply a stripe effect to the texture
short widescreen; //added
};
//!Display, manage, and manipulate text in the GUI
class GuiText : public GuiElement
{
public:
//!Constructor
//!\param t Text
//!\param s Font size
//!\param c Font color
GuiText(const char * t, int s, GXColor c);
//!\overload
//!\Assumes SetPresets() has been called to setup preferred text attributes
//!\param t Text
GuiText(const char * t);
//!Destructor
~GuiText();
//!Sets the text of the GuiText element
//!\param t Text
void SetText(const char * t);
//!Sets up preset values to be used by GuiText(t)
//!Useful when printing multiple text elements, all with the same attributes set
//!\param sz Font size
//!\param c Font color
//!\param w Maximum width of texture image (for text wrapping)
//!\param s Font size
//!\param h Text alignment (horizontal)
//!\param v Text alignment (vertical)
void SetPresets(int sz, GXColor c, int w, u16 s, int h, int v);
//!Sets the font size
//!\param s Font size
void SetFontSize(int s);
//!Sets the maximum width of the drawn texture image
//!If the text exceeds this, it is wrapped to the next line
//!\param w Maximum width
void SetMaxWidth(int w);
//!Sets the font color
//!\param c Font color
void SetColor(GXColor c);
//!Sets the FreeTypeGX style attributes
//!\param s Style attributes
void SetStyle(u16 s);
//!Sets the text alignment
//!\param hor Horizontal alignment (ALIGN_LEFT, ALIGN_RIGHT, ALIGN_CENTRE)
//!\param vert Vertical alignment (ALIGN_TOP, ALIGN_BOTTOM, ALIGN_MIDDLE)
void SetAlignment(int hor, int vert);
//!Constantly called to draw the text
void Draw();
protected:
wchar_t* text; //!< Unicode text value
int size; //!< Font size
int maxWidth; //!< Maximum width of the generated text object (for text wrapping)
u16 style; //!< FreeTypeGX style attributes
GXColor color; //!< Font color
};
//!Display, manage, and manipulate buttons in the GUI. Buttons can have images, icons, text, and sound set (all of which are optional)
class GuiButton : public GuiElement
{
public:
//!Constructor
//!\param w Width
//!\param h Height
GuiButton(int w, int h);
//!Destructor
~GuiButton();
//!Sets the button's image
//!\param i Pointer to GuiImage object
void SetImage(GuiImage* i);
//!Sets the button's image on over
//!\param i Pointer to GuiImage object
void SetImageOver(GuiImage* i);
//!Sets the button's image on hold
//!\param i Pointer to GuiImage object
void SetAngle(float a);
void SetImageHold(GuiImage* i);
//!Sets the button's image on click
//!\param i Pointer to GuiImage object
void SetImageClick(GuiImage* i);
//!Sets the button's icon
//!\param i Pointer to GuiImage object
void SetIcon(GuiImage* i);
//!Sets the button's icon on over
//!\param i Pointer to GuiImage object
void SetIconOver(GuiImage* i);
//!Sets the button's icon on hold
//!\param i Pointer to GuiImage object
void SetIconHold(GuiImage* i);
//!Sets the button's icon on click
//!\param i Pointer to GuiImage object
void SetIconClick(GuiImage* i);
//!Sets the button's label
//!\param t Pointer to GuiText object
//!\param n Index of label to set (optional, default is 0)
void SetLabel(GuiText* t, int n = 0);
//!Sets the button's label on over (eg: different colored text)
//!\param t Pointer to GuiText object
//!\param n Index of label to set (optional, default is 0)
void SetLabelOver(GuiText* t, int n = 0);
//!Sets the button's label on hold
//!\param t Pointer to GuiText object
//!\param n Index of label to set (optional, default is 0)
void SetLabelHold(GuiText* t, int n = 0);
//!Sets the button's label on click
//!\param t Pointer to GuiText object
//!\param n Index of label to set (optional, default is 0)
void SetLabelClick(GuiText* t, int n = 0);
//!Sets the sound to play on over
//!\param s Pointer to GuiSound object
void SetSoundOver(GuiSound * s);
//!Sets the sound to play on hold
//!\param s Pointer to GuiSound object
void SetSoundHold(GuiSound * s);
//!Sets the sound to play on click
//!\param s Pointer to GuiSound object
void SetSoundClick(GuiSound * s);
//!Constantly called to draw the GuiButtons ToolTip
//!Sets the button's Tooltip on over
//!\param i Pointer to GuiImage object, t Pointer to GuiText, x & y Positioning
void SetToolTip(GuiImage* i, GuiText * t, int x, int y);
//!Constantly called to draw the GuiButton
void Draw();
//!Constantly called to allow the GuiButton to respond to updated input data
//!\param t Pointer to a GuiTrigger, containing the current input data from PAD/WPAD
void Update(GuiTrigger * t);
//!Deactivate/Activate pointing on Games while B scrolling
void ScrollIsOn(int f);
protected:
GuiImage * image; //!< Button image (default)
GuiImage * imageOver; //!< Button image for STATE_SELECTED
GuiImage * imageHold; //!< Button image for STATE_HELD
GuiImage * imageClick; //!< Button image for STATE_CLICKED
GuiImage * icon; //!< Button icon (drawn after button image)
GuiImage * iconOver; //!< Button icon for STATE_SELECTED
GuiImage * iconHold; //!< Button icon for STATE_HELD
GuiImage * iconClick; //!< Button icon for STATE_CLICKED
GuiImage * toolTip; //!< Tooltip for STATE_SELECTED
GuiText * toolTipTxt;//!< Tooltip Text
time_t time1, time2;//!< Tooltip timeconstants
GuiText * label[3]; //!< Label(s) to display (default)
GuiText * labelOver[3]; //!< Label(s) to display for STATE_SELECTED
GuiText * labelHold[3]; //!< Label(s) to display for STATE_HELD
GuiText * labelClick[3]; //!< Label(s) to display for STATE_CLICKED
GuiSound * soundOver; //!< Sound to play for STATE_SELECTED
GuiSound * soundHold; //!< Sound to play for STATE_HELD
GuiSound * soundClick; //!< Sound to play for STATE_CLICKED
};
typedef struct _keytype {
char ch, chShift;
} Key;
//!On-screen keyboard
class GuiKeyboard : public GuiWindow
{
public:
GuiKeyboard(char * t, u32 m);
~GuiKeyboard();
void Update(GuiTrigger * t);
char kbtextstr[256];
protected:
u32 kbtextmaxlen;
Key keys[4][11];
int shift;
int caps;
GuiText * kbText;
GuiImage * keyTextboxImg;
GuiText * keyCapsText;
GuiImage * keyCapsImg;
GuiImage * keyCapsOverImg;
GuiButton * keyCaps;
GuiText * keyShiftText;
GuiImage * keyShiftImg;
GuiImage * keyShiftOverImg;
GuiButton * keyShift;
GuiText * keyBackText;
GuiImage * keyBackImg;
GuiImage * keyBackOverImg;
GuiButton * keyBack;
GuiImage * keySpaceImg;
GuiImage * keySpaceOverImg;
GuiButton * keySpace;
GuiButton * keyBtn[4][11];
GuiImage * keyImg[4][11];
GuiImage * keyImgOver[4][11];
GuiText * keyTxt[4][11];
GuiImageData * keyTextbox;
GuiImageData * key;
GuiImageData * keyOver;
GuiImageData * keyMedium;
GuiImageData * keyMediumOver;
GuiImageData * keyLarge;
GuiImageData * keyLargeOver;
GuiSound * keySoundOver;
GuiSound * keySoundClick;
GuiTrigger * trigA;
GuiTrigger * trigB;
};
typedef struct _optionlist {
int length;
char name[MAX_OPTIONS][60];
char value[MAX_OPTIONS][30];
} OptionList;
//!Display a list of menu options
class GuiOptionBrowser : public GuiElement
{
public:
GuiOptionBrowser(int w, int h, OptionList * l, const u8 *imagebg, int scrollbar);
GuiOptionBrowser(int w, int h, OptionList * l, const char * themePath, const u8 *imagebg, int scrollbar, int start);
~GuiOptionBrowser();
void SetCol2Position(int x);
int FindMenuItem(int c, int d);
int GetClickedOption();
int GetSelectedOption();
void ResetState();
void SetFocus(int f);
void Draw();
void Update(GuiTrigger * t);
GuiText * optionVal[PAGESIZE];
protected:
int selectedItem;
int listOffset;
OptionList * options;
int optionIndex[PAGESIZE];
GuiButton * optionBtn[PAGESIZE];
GuiText * optionTxt[PAGESIZE];
GuiImage * optionBg[PAGESIZE];
GuiButton * arrowUpBtn;
GuiButton * arrowDownBtn;
GuiButton * scrollbarBoxBtn;
GuiImage * bgOptionsImg;
GuiImage * bgOptionsOverImg;
GuiImage * scrollbarImg;
GuiImage * arrowDownImg;
GuiImage * arrowDownOverImg;
GuiImage * arrowUpImg;
GuiImage * arrowUpOverImg;
GuiImage * scrollbarBoxImg;
GuiImage * scrollbarBoxOverImg;
GuiImageData * bgOptions;
GuiImageData * bgOptionsOver;
GuiImageData * bgOptionsEntry;
GuiImageData * scrollbar;
GuiImageData * arrowDown;
GuiImageData * arrowDownOver;
GuiImageData * arrowUp;
GuiImageData * arrowUpOver;
GuiImageData * scrollbarBox;
GuiImageData * scrollbarBoxOver;
GuiSound * btnSoundOver;
GuiSound * btnSoundClick;
GuiTrigger * trigA;
GuiTrigger * trigB;
GuiTrigger * trigHeldA;
};
#endif

View File

@ -0,0 +1,355 @@
/****************************************************************************
* libwiigui
*
* Tantric 2009
*
* gui_button.cpp
*
* GUI class definitions
***************************************************************************/
#include "gui.h"
static int scrollison;
/**
* Constructor for the GuiButton class.
*/
GuiButton::GuiButton(int w, int h)
{
width = w;
height = h;
image = NULL;
imageOver = NULL;
imageHold = NULL;
imageClick = NULL;
icon = NULL;
iconOver = NULL;
iconHold = NULL;
iconClick = NULL;
toolTip = NULL;
toolTipTxt = NULL;
for(int i=0; i < 3; i++)
{
label[i] = NULL;
labelOver[i] = NULL;
labelHold[i] = NULL;
labelClick[i] = NULL;
}
soundOver = NULL;
soundHold = NULL;
soundClick = NULL;
selectable = true;
holdable = false;
clickable = true;
}
/**
* Destructor for the GuiButton class.
*/
GuiButton::~GuiButton()
{
}
void GuiButton::SetImage(GuiImage* img)
{
image = img;
if(img) img->SetParent(this);
}
void GuiButton::SetImageOver(GuiImage* img)
{
imageOver = img;
if(img) img->SetParent(this);
}
void GuiButton::SetImageHold(GuiImage* img)
{
imageHold = img;
if(img) img->SetParent(this);
}
void GuiButton::SetImageClick(GuiImage* img)
{
imageClick = img;
if(img) img->SetParent(this);
}
void GuiButton::SetIcon(GuiImage* img)
{
icon = img;
if(img) img->SetParent(this);
}
void GuiButton::SetIconOver(GuiImage* img)
{
iconOver = img;
if(img) img->SetParent(this);
}
void GuiButton::SetIconHold(GuiImage* img)
{
iconHold = img;
if(img) img->SetParent(this);
}
void GuiButton::SetIconClick(GuiImage* img)
{
iconClick = img;
if(img) img->SetParent(this);
}
void GuiButton::SetLabel(GuiText* txt, int n)
{
label[n] = txt;
if(txt) txt->SetParent(this);
}
void GuiButton::SetLabelOver(GuiText* txt, int n)
{
labelOver[n] = txt;
if(txt) txt->SetParent(this);
}
void GuiButton::SetLabelHold(GuiText* txt, int n)
{
labelHold[n] = txt;
if(txt) txt->SetParent(this);
}
void GuiButton::SetLabelClick(GuiText* txt, int n)
{
labelClick[n] = txt;
if(txt) txt->SetParent(this);
}
void GuiButton::SetSoundOver(GuiSound * snd)
{
soundOver = snd;
}
void GuiButton::SetSoundHold(GuiSound * snd)
{
soundHold = snd;
}
void GuiButton::SetSoundClick(GuiSound * snd)
{
soundClick = snd;
}
//No delay for now
void GuiButton::SetToolTip(GuiImage* img, GuiText * txt, int x, int y)
{
if(img)
{
toolTip = img;
img->SetParent(this);
img->SetAlignment(ALIGN_RIGHT, ALIGN_TOP);
img->SetPosition(x,y);
if(txt)
{
toolTipTxt = txt;
txt->SetParent(img);
}
}
}
/**
* Draw the button on screen
*/
void GuiButton::Draw()
{
if(!this->IsVisible())
return;
// draw image
if((state == STATE_SELECTED || state == STATE_HELD) && imageOver)
imageOver->Draw();
else if(image)
image->Draw();
// draw icon
if((state == STATE_SELECTED || state == STATE_HELD) && iconOver)
iconOver->Draw();
else if(icon)
icon->Draw();
// draw text
for(int i=0; i<3; i++)
{
if((state == STATE_SELECTED || state == STATE_HELD) && labelOver[i])
labelOver[i]->Draw();
else if(label[i])
label[i]->Draw();
}
//draw ToolTip
if(state == STATE_SELECTED && toolTip)
{
if (time2 == 0)
time(&time2);
time(&time1);
if (difftime(time1, time2) >= 2) {
toolTip->Draw();
if (toolTipTxt)
{
toolTipTxt->Draw();
}
}
}
this->UpdateEffects();
}
void GuiButton::ScrollIsOn(int f)
{
scrollison = f;
}
void GuiButton::Update(GuiTrigger * t)
{
if(state == STATE_CLICKED || state == STATE_DISABLED || !t)
return;
else if(parentElement && parentElement->GetState() == STATE_DISABLED)
return;
if(state != STATE_SELECTED && toolTip) {
time2 = 0;
}
#ifdef HW_RVL
// cursor
if(t->wpad.ir.valid)
{
if(this->IsInside(t->wpad.ir.x, t->wpad.ir.y))
{
if(state == STATE_DEFAULT) // we weren't on the button before!
{
if(scrollison == 0) {
this->SetState(STATE_SELECTED, t->chan);
}
if(this->Rumble() && scrollison == 0)
rumbleRequest[t->chan] = 1;
if(soundOver && scrollison == 0)
soundOver->Play();
if(effectsOver && !effects && scrollison == 0)
{
// initiate effects
effects = effectsOver;
effectAmount = effectAmountOver;
effectTarget = effectTargetOver;
}
}
}
else
{
if(state == STATE_SELECTED && (stateChan == t->chan || stateChan == -1))
this->ResetState();
if(effectTarget == effectTargetOver && effectAmount == effectAmountOver)
{
// initiate effects (in reverse)
effects = effectsOver;
effectAmount = -effectAmountOver;
effectTarget = 100;
}
}
}
#endif
// button triggers
if(this->IsClickable() && scrollison == 0)
{
s32 wm_btns, wm_btns_trig, cc_btns, cc_btns_trig;
for(int i=0; i<6; i++)
{
if(trigger[i] && (trigger[i]->chan == -1 || trigger[i]->chan == t->chan))
{
// higher 16 bits only (wiimote)
wm_btns = t->wpad.btns_d << 16;
wm_btns_trig = trigger[i]->wpad.btns_d << 16;
// lower 16 bits only (classic controller)
cc_btns = t->wpad.btns_d >> 16;
cc_btns_trig = trigger[i]->wpad.btns_d >> 16;
if(
(t->wpad.btns_d > 0 &&
wm_btns == wm_btns_trig ||
(cc_btns == cc_btns_trig && t->wpad.exp.type == EXP_CLASSIC)) ||
(t->pad.btns_d == trigger[i]->pad.btns_d && t->pad.btns_d > 0))
{
if(t->chan == stateChan || stateChan == -1)
{
if(state == STATE_SELECTED)
{
this->SetState(STATE_CLICKED, t->chan);
if(soundClick)
soundClick->Play();
}
else if(trigger[i]->type == TRIGGER_BUTTON_ONLY)
{
this->SetState(STATE_CLICKED, t->chan);
}
else if(trigger[i]->type == TRIGGER_BUTTON_ONLY_IN_FOCUS &&
parentElement->IsFocused())
{
this->SetState(STATE_CLICKED, t->chan);
}
}
}
}
}
}
if(this->IsHoldable())
{
bool held = false;
s32 wm_btns, wm_btns_h, wm_btns_trig, cc_btns, cc_btns_h, cc_btns_trig;
for(int i=0; i<6; i++)
{
if(trigger[i] && (trigger[i]->chan == -1 || trigger[i]->chan == t->chan))
{
// higher 16 bits only (wiimote)
wm_btns = t->wpad.btns_d << 16;
wm_btns_h = t->wpad.btns_h << 16;
wm_btns_trig = trigger[i]->wpad.btns_h << 16;
// lower 16 bits only (classic controller)
cc_btns = t->wpad.btns_d >> 16;
cc_btns_h = t->wpad.btns_h >> 16;
cc_btns_trig = trigger[i]->wpad.btns_h >> 16;
if(
(t->wpad.btns_d > 0 &&
wm_btns == wm_btns_trig ||
(cc_btns == cc_btns_trig && t->wpad.exp.type == EXP_CLASSIC)) ||
(t->pad.btns_d == trigger[i]->pad.btns_h && t->pad.btns_d > 0))
{
if(trigger[i]->type == TRIGGER_HELD && state == STATE_SELECTED &&
(t->chan == stateChan || stateChan == -1))
this->SetState(STATE_CLICKED, t->chan);
}
if(
(t->wpad.btns_h > 0 &&
wm_btns_h == wm_btns_trig ||
(cc_btns_h == cc_btns_trig && t->wpad.exp.type == EXP_CLASSIC)) ||
(t->pad.btns_h == trigger[i]->pad.btns_h && t->pad.btns_h > 0))
{
if(trigger[i]->type == TRIGGER_HELD)
held = true;
}
if(!held && state == STATE_HELD && stateChan == t->chan)
{
this->ResetState();
}
else if(held && state == STATE_CLICKED && stateChan == t->chan)
{
this->SetState(STATE_HELD, t->chan);
}
}
}
}
if(updateCB)
updateCB(this);
}

View File

@ -0,0 +1,531 @@
/****************************************************************************
* libwiigui
*
* gui_customoptionbrowser.cpp
*
* GUI class definitions
***************************************************************************/
#include "gui.h"
#include "../wpad.h"
#include "gui_customoptionbrowser.h"
#include <unistd.h>
#define GAMESELECTSIZE 30
static int scrollbaron = 0;
//int vol;
extern const int vol;
/**
* Constructor for the GuiCustomOptionBrowser class.
*/
GuiCustomOptionBrowser::GuiCustomOptionBrowser(int w, int h, customOptionList * l, const char *themePath, const char *custombg, const u8 *imagebg, int scrollon)
{
width = w;
height = h;
options = l;
size = ((l->length > PAGESIZE)? PAGESIZE: l->length);
scrollbaron = scrollon;
selectable = true;
listOffset = this->FindMenuItem(-1, 1);
selectedItem = 0;
focus = 1; // allow focus
char imgPath[100];
trigA = new GuiTrigger;
trigA->SetSimpleTrigger(-1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A);
trigHeldA = new GuiTrigger;
trigHeldA->SetHeldTrigger(-1, WPAD_BUTTON_A, PAD_BUTTON_A);
btnSoundClick = new GuiSound(button_click_pcm, button_click_pcm_size, SOUND_PCM, vol);
snprintf(imgPath, sizeof(imgPath), "%s%s", themePath, custombg);
bgOptions = new GuiImageData(imgPath, imagebg);
bgOptionsImg = new GuiImage(bgOptions);
bgOptionsImg->SetParent(this);
bgOptionsImg->SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE);
snprintf(imgPath, sizeof(imgPath), "%sbg_options_entry.png", themePath);
bgOptionsEntry = new GuiImageData(imgPath, bg_options_entry_png);
if (scrollbaron == 1) {
snprintf(imgPath, sizeof(imgPath), "%sscrollbar.png", themePath);
scrollbar = new GuiImageData(imgPath, scrollbar_png);
scrollbarImg = new GuiImage(scrollbar);
scrollbarImg->SetParent(this);
scrollbarImg->SetAlignment(ALIGN_RIGHT, ALIGN_TOP);
scrollbarImg->SetPosition(0, 4);
snprintf(imgPath, sizeof(imgPath), "%sscrollbar_arrowdown.png", themePath);
arrowDown = new GuiImageData(imgPath, scrollbar_arrowdown_png);
arrowDownImg = new GuiImage(arrowDown);
arrowDownOver = new GuiImageData(imgPath, scrollbar_arrowdown_png);
arrowDownOverImg = new GuiImage(arrowDownOver);
snprintf(imgPath, sizeof(imgPath), "%sscrollbar_arrowup.png", themePath);
arrowUp = new GuiImageData(imgPath, scrollbar_arrowup_png);
arrowUpImg = new GuiImage(arrowUp);
arrowUpOver = new GuiImageData(imgPath, scrollbar_arrowup_png);
arrowUpOverImg = new GuiImage(arrowUpOver);
snprintf(imgPath, sizeof(imgPath), "%sscrollbar_box.png", themePath);
scrollbarBox = new GuiImageData(imgPath, scrollbar_box_png);
scrollbarBoxImg = new GuiImage(scrollbarBox);
scrollbarBoxOver = new GuiImageData(imgPath, scrollbar_box_png);
scrollbarBoxOverImg = new GuiImage(scrollbarBoxOver);
arrowUpBtn = new GuiButton(arrowUpImg->GetWidth(), arrowUpImg->GetHeight());
arrowUpBtn->SetParent(this);
arrowUpBtn->SetImage(arrowUpImg);
arrowUpBtn->SetImageOver(arrowUpOverImg);
arrowUpBtn->SetImageHold(arrowUpOverImg);
arrowUpBtn->SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
arrowUpBtn->SetPosition(width/2-18+7,-18);
arrowUpBtn->SetSelectable(false);
arrowUpBtn->SetTrigger(trigA);
arrowUpBtn->SetEffectOnOver(EFFECT_SCALE, 50, 130);
arrowUpBtn->SetSoundClick(btnSoundClick);
arrowDownBtn = new GuiButton(arrowDownImg->GetWidth(), arrowDownImg->GetHeight());
arrowDownBtn->SetParent(this);
arrowDownBtn->SetImage(arrowDownImg);
arrowDownBtn->SetImageOver(arrowDownOverImg);
arrowDownBtn->SetImageHold(arrowDownOverImg);
arrowDownBtn->SetAlignment(ALIGN_CENTRE, ALIGN_BOTTOM);
arrowDownBtn->SetPosition(width/2-18+7,18);
arrowDownBtn->SetSelectable(false);
arrowDownBtn->SetTrigger(trigA);
arrowDownBtn->SetEffectOnOver(EFFECT_SCALE, 50, 130);
arrowDownBtn->SetSoundClick(btnSoundClick);
scrollbarBoxBtn = new GuiButton(scrollbarBoxImg->GetWidth(), scrollbarBoxImg->GetHeight());
scrollbarBoxBtn->SetParent(this);
scrollbarBoxBtn->SetImage(scrollbarBoxImg);
scrollbarBoxBtn->SetImageOver(scrollbarBoxOverImg);
scrollbarBoxBtn->SetImageHold(scrollbarBoxOverImg);
scrollbarBoxBtn->SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
scrollbarBoxBtn->SetSelectable(false);
scrollbarBoxBtn->SetEffectOnOver(EFFECT_SCALE, 50, 120);
scrollbarBoxBtn->SetMinY(0);
scrollbarBoxBtn->SetMaxY(height-30);
scrollbarBoxBtn->SetHoldable(true);
scrollbarBoxBtn->SetTrigger(trigHeldA);
}
optionIndex = new int[size];
optionVal = new GuiText * [size];
optionBtn = new GuiButton * [size];
optionTxt = new GuiText * [size];
optionBg = new GuiImage * [size];
for(int i=0; i < size; i++)
{
optionTxt[i] = new GuiText(options->name[i], 20, (GXColor){0, 0, 0, 0xff});
optionTxt[i]->SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE);
optionTxt[i]->SetPosition(24,0);
optionBg[i] = new GuiImage(bgOptionsEntry);
optionVal[i] = new GuiText(NULL, 20, (GXColor){0, 0, 0, 0xff});
optionVal[i]->SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE);
optionVal[i]->SetPosition(250,0);
optionBtn[i] = new GuiButton(width-28,GAMESELECTSIZE);
optionBtn[i]->SetParent(this);
optionBtn[i]->SetLabel(optionTxt[i], 0);
optionBtn[i]->SetLabel(optionVal[i], 1);
optionBtn[i]->SetImageOver(optionBg[i]);
optionBtn[i]->SetPosition(5,GAMESELECTSIZE*i+4);
optionBtn[i]->SetRumble(false);
optionBtn[i]->SetTrigger(trigA);
optionBtn[i]->SetSoundClick(btnSoundClick);
}
}
/**
* Destructor for the GuiCustomOptionBrowser class.
*/
GuiCustomOptionBrowser::~GuiCustomOptionBrowser()
{
if (scrollbaron == 1) {
delete arrowUpBtn;
delete arrowDownBtn;
delete scrollbarBoxBtn;
delete scrollbarImg;
delete arrowDownImg;
delete arrowDownOverImg;
delete arrowUpImg;
delete arrowUpOverImg;
delete scrollbarBoxImg;
delete scrollbarBoxOverImg;
delete scrollbar;
delete arrowDown;
delete arrowDownOver;
delete arrowUp;
delete arrowUpOver;
delete scrollbarBox;
delete scrollbarBoxOver;
}
delete bgOptionsImg;
delete bgOptions;
delete bgOptionsEntry;
delete trigA;
delete btnSoundClick;
// delete optionBg;
for(int i = 0; i < size; i++)
{
delete optionTxt[i];
delete optionVal[i];
delete optionBg[i];
delete optionBtn[i];
}
delete [] optionIndex;
delete [] optionVal;
delete [] optionBtn;
delete [] optionTxt;
delete [] optionBg;
}
void GuiCustomOptionBrowser::SetCol2Position(int x)
{
for(int i = 0; i < size; i++)
optionVal[i]->SetPosition(x,0);
}
void GuiCustomOptionBrowser::SetFocus(int f)
{
focus = f;
for(int i = 0; i < size; i++)
optionBtn[i]->ResetState();
if(f == 1)
optionBtn[selectedItem]->SetState(STATE_SELECTED);
}
void GuiCustomOptionBrowser::ResetState()
{
if(state != STATE_DISABLED)
{
state = STATE_DEFAULT;
stateChan = -1;
}
for(int i = 0; i < size; i++)
{
optionBtn[i]->ResetState();
}
}
int GuiCustomOptionBrowser::GetClickedOption()
{
int found = -1;
for(int i = 0; i < size; i++)
{
if(optionBtn[i]->GetState() == STATE_CLICKED)
{
optionBtn[i]->SetState(STATE_SELECTED);
found = optionIndex[i];
break;
}
}
return found;
}
int GuiCustomOptionBrowser::GetSelectedOption()
{
int found = -1;
for(int i = 0; i < size; i++)
{
if(optionBtn[i]->GetState() == STATE_SELECTED)
{
found = optionIndex[i];
break;
}
}
return found;
}
/****************************************************************************
* FindMenuItem
*
* Help function to find the next visible menu item on the list
***************************************************************************/
int GuiCustomOptionBrowser::FindMenuItem(int currentItem, int direction)
{
int nextItem = currentItem + direction;
if(nextItem < 0 || nextItem >= options->length)
return -1;
if(strlen(options->name[nextItem]) > 0)
return nextItem;
else
return FindMenuItem(nextItem, direction);
}
/**
* Draw the button on screen
*/
void GuiCustomOptionBrowser::Draw()
{
if(!this->IsVisible())
return;
bgOptionsImg->Draw();
int next = listOffset;
for(int i=0; i < size; i++)
{
if(next >= 0)
{
optionBtn[i]->Draw();
next = this->FindMenuItem(next, 1);
}
else
break;
}
if(scrollbaron == 1) {
scrollbarImg->Draw();
arrowUpBtn->Draw();
arrowDownBtn->Draw();
scrollbarBoxBtn->Draw();
}
this->UpdateEffects();
}
void GuiCustomOptionBrowser::Update(GuiTrigger * t)
{ int next, prev, lang = options->length;
if(state == STATE_DISABLED || !t)
return;
// scrolldelay affects how fast the list scrolls
// when the arrows are clicked
float scrolldelay = 3.5;
if (scrollbaron == 1) {
// update the location of the scroll box based on the position in the option list
arrowUpBtn->Update(t);
arrowDownBtn->Update(t);
scrollbarBoxBtn->Update(t);
}
next = listOffset;
for(int i=0; i < size; i++)
{
if(next >= 0)
{
if(optionBtn[i]->GetState() == STATE_DISABLED)
{
optionBtn[i]->SetVisible(true);
optionBtn[i]->SetState(STATE_DEFAULT);
}
optionTxt[i]->SetText(options->name[next]);
optionVal[i]->SetText(options->value[next]);
optionIndex[i] = next;
next = this->FindMenuItem(next, 1);
}
else
{
optionBtn[i]->SetVisible(false);
optionBtn[i]->SetState(STATE_DISABLED);
}
if(focus)
{
if(i != selectedItem && optionBtn[i]->GetState() == STATE_SELECTED)
optionBtn[i]->ResetState();
else if(i == selectedItem && optionBtn[i]->GetState() == STATE_DEFAULT)
optionBtn[selectedItem]->SetState(STATE_SELECTED, t->chan);
}
optionBtn[i]->Update(t);
if(optionBtn[i]->GetState() == STATE_SELECTED)
{
selectedItem = i;
}
}
// pad/joystick navigation
if(!focus)
return; // skip navigation
if (scrollbaron == 1) {
if (t->Down() ||
arrowDownBtn->GetState() == STATE_CLICKED || ////////////////////////////////////////////down
arrowDownBtn->GetState() == STATE_HELD)
{
next = this->FindMenuItem(optionIndex[selectedItem], 1);
if(next >= 0)
{
if(selectedItem == size-1)
{
// move list down by 1
listOffset = this->FindMenuItem(listOffset, 1);
}
else if(optionBtn[selectedItem+1]->IsVisible())
{
optionBtn[selectedItem]->ResetState();
optionBtn[selectedItem+1]->SetState(STATE_SELECTED, t->chan);
selectedItem++;
}
scrollbarBoxBtn->Draw();
usleep(10000 * scrolldelay);
}WPAD_ScanPads();
u8 cnt, buttons = NULL;
/* Get pressed buttons */
for (cnt = 0; cnt < 4; cnt++)
buttons |= WPAD_ButtonsHeld(cnt);
if (buttons == WPAD_BUTTON_A) {
} else {
arrowDownBtn->ResetState();
}
}
else if(t->Up() ||
arrowUpBtn->GetState() == STATE_CLICKED || ////////////////////////////////////////////up
arrowUpBtn->GetState() == STATE_HELD)
{
prev = this->FindMenuItem(optionIndex[selectedItem], -1);
if(prev >= 0)
{
if(selectedItem == 0)
{
// move list up by 1
listOffset = prev;
}
else
{
optionBtn[selectedItem]->ResetState();
optionBtn[selectedItem-1]->SetState(STATE_SELECTED, t->chan);
selectedItem--;
}
scrollbarBoxBtn->Draw();
usleep(10000 * scrolldelay);
}WPAD_ScanPads();
u8 cnt, buttons = NULL;
/* Get pressed buttons */
for (cnt = 0; cnt < 4; cnt++)
buttons |= WPAD_ButtonsHeld(cnt);
if (buttons == WPAD_BUTTON_A) {
} else {
arrowUpBtn->ResetState();
}
}
if(scrollbarBoxBtn->GetState() == STATE_HELD &&
scrollbarBoxBtn->GetStateChan() == t->chan &&
t->wpad.ir.valid && options->length > size)
{
scrollbarBoxBtn->SetPosition(width/2-18+7,0);
int position = t->wpad.ir.y - 50 - scrollbarBoxBtn->GetTop();
listOffset = (position * lang)/180 - selectedItem;
if(listOffset <= 0)
{
listOffset = 0;
selectedItem = 0;
}
else if(listOffset+size >= lang)
{
listOffset = lang-size;
selectedItem = size-1;
}
}
int positionbar = 237*(listOffset + selectedItem) / lang;
if(positionbar > 216)
positionbar = 216;
scrollbarBoxBtn->SetPosition(width/2-18+7, positionbar+8);
if(t->Right())
{
if(listOffset < lang && lang > size)
{
listOffset =listOffset+ size;
if(listOffset+size >= lang)
listOffset = lang-size;
}
}
else if(t->Left())
{
if(listOffset > 0)
{
listOffset =listOffset- size;
if(listOffset < 0)
listOffset = 0;
}
}
} else {
if(t->Down())
{
next = this->FindMenuItem(optionIndex[selectedItem], 1);
if(next >= 0)
{
if(selectedItem == size-1)
{
// move list down by 1
listOffset = this->FindMenuItem(listOffset, 1);
}
else if(optionBtn[selectedItem+1]->IsVisible())
{
optionBtn[selectedItem]->ResetState();
optionBtn[selectedItem+1]->SetState(STATE_SELECTED, t->chan);
selectedItem++;
}
}
}
else if(t->Up())
{
prev = this->FindMenuItem(optionIndex[selectedItem], -1);
if(prev >= 0)
{
if(selectedItem == 0)
{
// move list up by 1
listOffset = prev;
}
else
{
optionBtn[selectedItem]->ResetState();
optionBtn[selectedItem-1]->SetState(STATE_SELECTED, t->chan);
selectedItem--;
}
}
}
}
if(updateCB)
updateCB(this);
}

View File

@ -0,0 +1,85 @@
#include "gui.h"
class customOptionList {
public:
customOptionList(int size) {
name = new char * [size];
value = new char * [size];
for (int i = 0; i < size; i++)
{
name[i] = new char[30];
value[i] = new char[20];
}
length = size;
};
~customOptionList(){
for (int i = 0; i < length; i++)
{
delete [] name[i];
delete [] value[i];
}
delete [] name;
delete [] value;
};
public:
int length;
char ** name;
char ** value;
};
//!Display a list of menu options
class GuiCustomOptionBrowser : public GuiElement
{
public:
GuiCustomOptionBrowser(int w, int h, customOptionList * l, const char * themePath, const char *custombg, const u8 *imagebg, int scrollbar);
~GuiCustomOptionBrowser();
void SetCol2Position(int x);
int FindMenuItem(int c, int d);
int GetClickedOption();
int GetSelectedOption();
void ResetState();
void SetFocus(int f);
void Draw();
void Update(GuiTrigger * t);
GuiText ** optionVal;
protected:
int selectedItem;
int listOffset;
int size;
customOptionList * options;
int * optionIndex;
GuiButton ** optionBtn;
GuiText ** optionTxt;
GuiImage ** optionBg;
GuiButton * arrowUpBtn;
GuiButton * arrowDownBtn;
GuiButton * scrollbarBoxBtn;
GuiImage * bgOptionsImg;
GuiImage * scrollbarImg;
GuiImage * arrowDownImg;
GuiImage * arrowDownOverImg;
GuiImage * arrowUpImg;
GuiImage * arrowUpOverImg;
GuiImage * scrollbarBoxImg;
GuiImage * scrollbarBoxOverImg;
GuiImageData * bgOptions;
GuiImageData * bgOptionsEntry;
GuiImageData * scrollbar;
GuiImageData * arrowDown;
GuiImageData * arrowDownOver;
GuiImageData * arrowUp;
GuiImageData * arrowUpOver;
GuiImageData * scrollbarBox;
GuiImageData * scrollbarBoxOver;
GuiSound * btnSoundOver;
GuiSound * btnSoundClick;
GuiTrigger * trigA;
GuiTrigger * trigB;
GuiTrigger * trigHeldA;
};

View File

@ -0,0 +1,577 @@
/****************************************************************************
* libwiigui
*
* Tantric 2009
*
* gui_element.cpp
*
* GUI class definitions
***************************************************************************/
#include "gui.h"
/**
* Constructor for the Object class.
*/
GuiElement::GuiElement()
{
xoffset = 0;
yoffset = 0;
xmin = 0;
xmax = 0;
ymin = 0;
ymax = 0;
width = 0;
height = 0;
alpha = 255;
scale = 1;
state = STATE_DEFAULT;
stateChan = -1;
trigger[0] = NULL;
trigger[1] = NULL;
trigger[2] = NULL;
trigger[3] = NULL;
trigger[4] = NULL;
trigger[6] = NULL;
parentElement = NULL;
rumble = true;
selectable = false;
clickable = false;
holdable = false;
visible = true;
focus = -1; // cannot be focused
updateCB = NULL;
yoffsetDyn = 0;
xoffsetDyn = 0;
alphaDyn = -1;
scaleDyn = 1;
effects = 0;
effectAmount = 0;
effectTarget = 0;
effectsOver = 0;
effectAmountOver = 0;
effectTargetOver = 0;
// default alignment - align to top left
alignmentVert = ALIGN_TOP;
alignmentHor = ALIGN_LEFT;
}
/**
* Destructor for the GuiElement class.
*/
GuiElement::~GuiElement()
{
}
void GuiElement::SetParent(GuiElement * e)
{
parentElement = e;
}
/**
* Get the left position of the GuiElement.
* @see SetLeft()
* @return Left position in pixel.
*/
int GuiElement::GetLeft()
{
int x = 0;
int pWidth = 0;
int pLeft = 0;
if(parentElement)
{
pWidth = parentElement->GetWidth();
pLeft = parentElement->GetLeft();
}
if(effects & (EFFECT_SLIDE_IN | EFFECT_SLIDE_OUT))
pLeft += xoffsetDyn;
switch(alignmentHor)
{
case ALIGN_LEFT:
x = pLeft;
break;
case ALIGN_CENTRE:
x = pLeft + (pWidth/2) - (width/2);
break;
case ALIGN_RIGHT:
x = pLeft + pWidth - width;
break;
}
return x + xoffset;
}
/**
* Get the top position of the GuiElement.
* @see SetTop()
* @return Top position in pixel.
*/
int GuiElement::GetTop()
{
int y = 0;
int pHeight = 0;
int pTop = 0;
if(parentElement)
{
pHeight = parentElement->GetHeight();
pTop = parentElement->GetTop();
}
if(effects & (EFFECT_SLIDE_IN | EFFECT_SLIDE_OUT))
pTop += yoffsetDyn;
switch(alignmentVert)
{
case ALIGN_TOP:
y = pTop;
break;
case ALIGN_MIDDLE:
y = pTop + (pHeight/2) - (height/2);
break;
case ALIGN_BOTTOM:
y = pTop + pHeight - height;
break;
}
return y + yoffset;
}
void GuiElement::SetMinX(int x)
{
xmin = x;
}
int GuiElement::GetMinX()
{
return xmin;
}
void GuiElement::SetMaxX(int x)
{
xmax = x;
}
int GuiElement::GetMaxX()
{
return xmax;
}
void GuiElement::SetMinY(int y)
{
ymin = y;
}
int GuiElement::GetMinY()
{
return ymin;
}
void GuiElement::SetMaxY(int y)
{
ymax = y;
}
int GuiElement::GetMaxY()
{
return ymax;
}
/**
* Get the width of the GuiElement.
* @see SetWidth()
* @return Width of the GuiElement.
*/
int GuiElement::GetWidth()
{
return width;
}
/**
* Get the height of the GuiElement.
* @see SetHeight()
* @return Height of the GuiElement.
*/
int GuiElement::GetHeight()
{
return height;
}
/**
* Set the width and height of the GuiElement.
* @param[in] Width Width in pixel.
* @param[in] Height Height in pixel.
* @see SetWidth()
* @see SetHeight()
*/
void GuiElement::SetSize(int w, int h)
{
width = w;
height = h;
}
/**
* Get visible.
* @see SetVisible()
* @return true if visible, false otherwise.
*/
bool GuiElement::IsVisible()
{
return visible;
}
/**
* Set visible.
* @param[in] Visible Set to true to show GuiElement.
* @see IsVisible()
*/
void GuiElement::SetVisible(bool v)
{
visible = v;
}
void GuiElement::SetAlpha(int a)
{
alpha = a;
}
int GuiElement::GetAlpha()
{
int a;
if(alphaDyn >= 0)
a = alphaDyn;
else
a = alpha;
if(parentElement)
a *= parentElement->GetAlpha()/255.0;
return a;
}
void GuiElement::SetScale(float s)
{
scale = s;
}
float GuiElement::GetScale()
{
float s = scale * scaleDyn;
if(parentElement)
s *= parentElement->GetScale();
return s;
}
int GuiElement::GetState()
{
return state;
}
int GuiElement::GetStateChan()
{
return stateChan;
}
void GuiElement::SetState(int s, int c)
{
state = s;
stateChan = c;
}
void GuiElement::ResetState()
{
if(state != STATE_DISABLED)
{
state = STATE_DEFAULT;
stateChan = -1;
}
}
void GuiElement::SetClickable(bool c)
{
clickable = c;
}
void GuiElement::SetSelectable(bool s)
{
selectable = s;
}
void GuiElement::SetHoldable(bool d)
{
holdable = d;
}
bool GuiElement::IsSelectable()
{
if(state == STATE_DISABLED || state == STATE_CLICKED)
return false;
else
return selectable;
}
bool GuiElement::IsClickable()
{
if(state == STATE_DISABLED ||
state == STATE_CLICKED ||
state == STATE_HELD)
return false;
else
return clickable;
}
bool GuiElement::IsHoldable()
{
if(state == STATE_DISABLED)
return false;
else
return holdable;
}
void GuiElement::SetFocus(int f)
{
focus = f;
}
int GuiElement::IsFocused()
{
return focus;
}
void GuiElement::SetTrigger(GuiTrigger * t)
{
if(!trigger[0])
trigger[0] = t;
else if(!trigger[1])
trigger[1] = t;
else if(!trigger[2])
trigger[2] = t;
else if(!trigger[3])
trigger[3] = t;
else if(!trigger[4])
trigger[4] = t;
else if(!trigger[5])
trigger[5] = t;
else // both were assigned, so we'll just overwrite the first one
trigger[0] = t;
}
void GuiElement::SetTrigger(u8 i, GuiTrigger * t)
{
trigger[i] = t;
}
bool GuiElement::Rumble()
{
return rumble;
}
void GuiElement::SetRumble(bool r)
{
rumble = r;
}
int GuiElement::GetEffect()
{
return effects;
}
void GuiElement::SetEffect(int eff, int amount, int target)
{
if(eff & EFFECT_SLIDE_IN)
{
// these calculations overcompensate a little
if(eff & EFFECT_SLIDE_TOP)
yoffsetDyn = -screenheight;
else if(eff & EFFECT_SLIDE_LEFT)
xoffsetDyn = -screenwidth;
else if(eff & EFFECT_SLIDE_BOTTOM)
yoffsetDyn = screenheight;
else if(eff & EFFECT_SLIDE_RIGHT)
xoffsetDyn = screenwidth;
}
if(eff & EFFECT_FADE && amount > 0)
{
alphaDyn = 0;
}
else if(eff & EFFECT_FADE && amount < 0)
{
alphaDyn = alpha;
}
effects |= eff;
effectAmount = amount;
effectTarget = target;
}
void GuiElement::SetEffectOnOver(int eff, int amount, int target)
{
effectsOver |= eff;
effectAmountOver = amount;
effectTargetOver = target;
}
void GuiElement::SetEffectGrow()
{
SetEffectOnOver(EFFECT_SCALE, 4, 110);
}
void GuiElement::UpdateEffects()
{
if(effects & (EFFECT_SLIDE_IN | EFFECT_SLIDE_OUT))
{
if(effects & EFFECT_SLIDE_IN)
{
if(effects & EFFECT_SLIDE_LEFT)
{
xoffsetDyn += effectAmount;
if(xoffsetDyn >= 0)
{
xoffsetDyn = 0;
effects = 0;
}
}
else if(effects & EFFECT_SLIDE_RIGHT)
{
xoffsetDyn -= effectAmount;
if(xoffsetDyn <= 0)
{
xoffsetDyn = 0;
effects = 0;
}
}
else if(effects & EFFECT_SLIDE_TOP)
{
yoffsetDyn += effectAmount;
if(yoffsetDyn >= 0)
{
yoffsetDyn = 0;
effects = 0;
}
}
else if(effects & EFFECT_SLIDE_BOTTOM)
{
yoffsetDyn -= effectAmount;
if(yoffsetDyn <= 0)
{
yoffsetDyn = 0;
effects = 0;
}
}
}
else
{
if(effects & EFFECT_SLIDE_LEFT)
{
xoffsetDyn -= effectAmount;
if(xoffsetDyn <= -screenwidth)
effects = 0; // shut off effect
}
else if(effects & EFFECT_SLIDE_RIGHT)
{
xoffsetDyn += effectAmount;
if(xoffsetDyn >= screenwidth)
effects = 0; // shut off effect
}
else if(effects & EFFECT_SLIDE_TOP)
{
yoffsetDyn -= effectAmount;
if(yoffsetDyn <= -screenheight)
effects = 0; // shut off effect
}
else if(effects & EFFECT_SLIDE_BOTTOM)
{
yoffsetDyn += effectAmount;
if(yoffsetDyn >= screenheight)
effects = 0; // shut off effect
}
}
}
if(effects & EFFECT_FADE)
{
alphaDyn += effectAmount;
if(effectAmount < 0 && alphaDyn <= 0)
{
alphaDyn = 0;
effects = 0; // shut off effect
}
else if(effectAmount > 0 && alphaDyn >= alpha)
{
alphaDyn = alpha;
effects = 0; // shut off effect
}
}
if(effects & EFFECT_SCALE)
{
scaleDyn += effectAmount/100.0;
if((effectAmount < 0 && scaleDyn <= effectTarget/100.0)
|| (effectAmount > 0 && scaleDyn >= effectTarget/100.0))
{
scaleDyn = effectTarget/100.0;
effects = 0; // shut off effect
}
}
}
void GuiElement::Update(GuiTrigger * t)
{
if(updateCB)
updateCB(this);
}
void GuiElement::SetUpdateCallback(UpdateCallback u)
{
updateCB = u;
}
void GuiElement::SetPosition(int xoff, int yoff)
{
xoffset = xoff;
yoffset = yoff;
}
void GuiElement::SetAlignment(int hor, int vert)
{
alignmentHor = hor;
alignmentVert = vert;
}
int GuiElement::GetSelected()
{
return -1;
}
/**
* Draw an element on screen.
*/
void GuiElement::Draw()
{
}
/**
* Check if a position is inside the GuiElement.
* @param[in] x X position in pixel.
* @param[in] y Y position in pixel.
*/
bool GuiElement::IsInside(int x, int y)
{
if(x > this->GetLeft() && x < (this->GetLeft()+width)
&& y > this->GetTop() && y < (this->GetTop()+height))
return true;
return false;
}

View File

@ -0,0 +1,615 @@
/****************************************************************************
* libwiigui
*
* gui_gamebrowser.cpp
*
* GUI class definitions
***************************************************************************/
#include "gui.h"
#include "../wpad.h"
#include <unistd.h>
#include "gui_gamebrowser.h"
#include "cfg.h"
#define GAMESELECTSIZE 30
extern const int vol;
/**
* Constructor for the GuiGameBrowser class.
*/
GuiGameBrowser::GuiGameBrowser(int w, int h, struct discHdr * l, int gameCnt, const char *themePath, const u8 *imagebg, int selected, int offset)
{
width = w;
height = h;
this->gameCnt = gameCnt;
gameList = l;
pagesize = (gameCnt > PAGESIZE) ? PAGESIZE : gameCnt;
scrollbaron = (gameCnt > PAGESIZE) ? 1 : 0;
selectable = true;
listOffset = (offset == 0) ? this->FindMenuItem(-1, 1) : offset;
selectedItem = selected - offset;
focus = 1; // allow focus
char imgPath[100];
trigA = new GuiTrigger;
trigA->SetSimpleTrigger(-1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A);
trigHeldA = new GuiTrigger;
trigHeldA->SetHeldTrigger(-1, WPAD_BUTTON_A, PAD_BUTTON_A);
btnSoundClick = new GuiSound(button_click_pcm, button_click_pcm_size, SOUND_PCM, vol);
snprintf(imgPath, sizeof(imgPath), "%sbg_options.png", themePath);
bgGames = new GuiImageData(imgPath, imagebg);
bgGameImg = new GuiImage(bgGames);
bgGameImg->SetParent(this);
bgGameImg->SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE);
snprintf(imgPath, sizeof(imgPath), "%sbg_options_entry.png", themePath);
bgGamesEntry = new GuiImageData(imgPath, bg_options_entry_png);
if (scrollbaron == 1) {
snprintf(imgPath, sizeof(imgPath), "%sscrollbar.png", themePath);
scrollbar = new GuiImageData(imgPath, scrollbar_png);
scrollbarImg = new GuiImage(scrollbar);
scrollbarImg->SetParent(this);
scrollbarImg->SetAlignment(ALIGN_RIGHT, ALIGN_TOP);
scrollbarImg->SetPosition(0, 4);
snprintf(imgPath, sizeof(imgPath), "%sscrollbar_arrowdown.png", themePath);
arrowDown = new GuiImageData(imgPath, scrollbar_arrowdown_png);
arrowDownImg = new GuiImage(arrowDown);
arrowDownOver = new GuiImageData(imgPath, scrollbar_arrowdown_png);
arrowDownOverImg = new GuiImage(arrowDownOver);
snprintf(imgPath, sizeof(imgPath), "%sscrollbar_arrowup.png", themePath);
arrowUp = new GuiImageData(imgPath, scrollbar_arrowup_png);
arrowUpImg = new GuiImage(arrowUp);
arrowUpOver = new GuiImageData(imgPath, scrollbar_arrowup_png);
arrowUpOverImg = new GuiImage(arrowUpOver);
snprintf(imgPath, sizeof(imgPath), "%sscrollbar_box.png", themePath);
scrollbarBox = new GuiImageData(imgPath, scrollbar_box_png);
scrollbarBoxImg = new GuiImage(scrollbarBox);
scrollbarBoxOver = new GuiImageData(imgPath, scrollbar_box_png);
scrollbarBoxOverImg = new GuiImage(scrollbarBoxOver);
arrowUpBtn = new GuiButton(arrowUpImg->GetWidth(), arrowUpImg->GetHeight());
arrowUpBtn->SetParent(this);
arrowUpBtn->SetImage(arrowUpImg);
arrowUpBtn->SetImageOver(arrowUpOverImg);
arrowUpBtn->SetImageHold(arrowUpOverImg);
arrowUpBtn->SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
arrowUpBtn->SetPosition(width/2-18+7,-18);
arrowUpBtn->SetSelectable(false);
arrowUpBtn->SetTrigger(trigA);
arrowUpBtn->SetEffectOnOver(EFFECT_SCALE, 50, 130);
arrowUpBtn->SetSoundClick(btnSoundClick);
arrowDownBtn = new GuiButton(arrowDownImg->GetWidth(), arrowDownImg->GetHeight());
arrowDownBtn->SetParent(this);
arrowDownBtn->SetImage(arrowDownImg);
arrowDownBtn->SetImageOver(arrowDownOverImg);
arrowDownBtn->SetImageHold(arrowDownOverImg);
arrowDownBtn->SetAlignment(ALIGN_CENTRE, ALIGN_BOTTOM);
arrowDownBtn->SetPosition(width/2-18+7,18);
arrowDownBtn->SetSelectable(false);
arrowDownBtn->SetTrigger(trigA);
arrowDownBtn->SetEffectOnOver(EFFECT_SCALE, 50, 130);
arrowDownBtn->SetSoundClick(btnSoundClick);
scrollbarBoxBtn = new GuiButton(scrollbarBoxImg->GetWidth(), scrollbarBoxImg->GetHeight());
scrollbarBoxBtn->SetParent(this);
scrollbarBoxBtn->SetImage(scrollbarBoxImg);
scrollbarBoxBtn->SetImageOver(scrollbarBoxOverImg);
scrollbarBoxBtn->SetImageHold(scrollbarBoxOverImg);
scrollbarBoxBtn->SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
scrollbarBoxBtn->SetSelectable(false);
scrollbarBoxBtn->SetEffectOnOver(EFFECT_SCALE, 50, 120);
scrollbarBoxBtn->SetMinY(0);
scrollbarBoxBtn->SetMaxY(height-30);
scrollbarBoxBtn->SetHoldable(true);
scrollbarBoxBtn->SetTrigger(trigHeldA);
}
gameIndex = new int[pagesize];
game = new GuiButton * [pagesize];
gameTxt = new GuiText * [pagesize];
gameBg = new GuiImage * [pagesize];
char buffer[CFG.maxcharacters + 4];
for(int i=0; i < pagesize; i++)
{
if (strlen(get_title(&gameList[i])) < (u32)(CFG.maxcharacters + 3))
{
sprintf(buffer, "%s", get_title(&gameList[i]));
}
else
{
sprintf(buffer, get_title(&gameList[i]), CFG.maxcharacters);
buffer[CFG.maxcharacters] = '\0';
strncat(buffer, "...", 3);
}
gameTxt[i] = new GuiText(buffer, 20, (GXColor){0, 0, 0, 0xff});
gameTxt[i]->SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE);
gameTxt[i]->SetPosition(24,0);
gameBg[i] = new GuiImage(bgGamesEntry);
game[i] = new GuiButton(width-28,GAMESELECTSIZE);
game[i]->SetParent(this);
game[i]->SetLabel(gameTxt[i]);
game[i]->SetImageOver(gameBg[i]);
game[i]->SetPosition(5,GAMESELECTSIZE*i+4);
game[i]->SetRumble(false);
game[i]->SetTrigger(trigA);
game[i]->SetSoundClick(btnSoundClick);
}
}
/**
* Destructor for the GuiGameBrowser class.
*/
GuiGameBrowser::~GuiGameBrowser()
{
if (scrollbaron == 1) {
delete arrowUpBtn;
delete arrowDownBtn;
delete scrollbarBoxBtn;
delete scrollbarImg;
delete arrowDownImg;
delete arrowDownOverImg;
delete arrowUpImg;
delete arrowUpOverImg;
delete scrollbarBoxImg;
delete scrollbarBoxOverImg;
delete scrollbar;
delete arrowDown;
delete arrowDownOver;
delete arrowUp;
delete arrowUpOver;
delete scrollbarBox;
delete scrollbarBoxOver;
}
delete bgGameImg;
delete bgGames;
delete bgGamesEntry;
delete trigA;
delete btnSoundClick;
// delete optionBg;
for(int i=0; i<pagesize; i++)
{
delete gameTxt[i];
delete gameBg[i];
delete game[i];
}
delete [] gameIndex;
delete [] game;
delete [] gameTxt;
delete [] gameBg;
}
void GuiGameBrowser::SetFocus(int f)
{
focus = f;
for(int i=0; i<pagesize; i++)
game[i]->ResetState();
if(f == 1)
game[selectedItem]->SetState(STATE_SELECTED);
}
void GuiGameBrowser::ResetState()
{
if(state != STATE_DISABLED)
{
state = STATE_DEFAULT;
stateChan = -1;
}
for(int i=0; i<pagesize; i++)
{
game[i]->ResetState();
}
}
int GuiGameBrowser::GetOffset()
{
return listOffset;
}
int GuiGameBrowser::GetClickedOption()
{
int found = -1;
for(int i=0; i<pagesize; i++)
{
if(game[i]->GetState() == STATE_CLICKED)
{
game[i]->SetState(STATE_SELECTED);
found = gameIndex[i];
break;
}
}
return found;
}
int GuiGameBrowser::GetSelectedOption()
{
int found = -1;
for(int i=0; i<pagesize; i++)
{
if(game[i]->GetState() == STATE_SELECTED)
{
game[i]->SetState(STATE_SELECTED);
found = gameIndex[i];
break;
}
}
return found;
}
/****************************************************************************
* FindMenuItem
*
* Help function to find the next visible menu item on the list
***************************************************************************/
int GuiGameBrowser::FindMenuItem(int currentItem, int direction)
{
int nextItem = currentItem + direction;
if(nextItem < 0 || nextItem >= gameCnt)
return -1;
if(strlen(get_title(&gameList[nextItem])) > 0)
return nextItem;
else
return FindMenuItem(nextItem, direction);
}
/**
* Draw the button on screen
*/
void GuiGameBrowser::Draw()
{
if(!this->IsVisible())
return;
bgGameImg->Draw();
int next = listOffset;
for(int i=0; i<pagesize; i++)
{
if(next >= 0)
{
game[i]->Draw();
next = this->FindMenuItem(next, 1);
}
else
break;
}
if(scrollbaron == 1) {
scrollbarImg->Draw();
arrowUpBtn->Draw();
arrowDownBtn->Draw();
scrollbarBoxBtn->Draw();
}
this->UpdateEffects();
}
void GuiGameBrowser::Update(GuiTrigger * t)
{
if(state == STATE_DISABLED || !t)
return;
int next, prev;
static int position2;
// scrolldelay affects how fast the list scrolls
// when the arrows are clicked
float scrolldelay = 3.5;
if (scrollbaron == 1) {
// update the location of the scroll box based on the position in the option list
arrowUpBtn->Update(t);
arrowDownBtn->Update(t);
scrollbarBoxBtn->Update(t);
}
next = listOffset;
char buffer[CFG.maxcharacters + 4];
for(int i=0; i<pagesize; i++)
{
if(next >= 0)
{
if(game[i]->GetState() == STATE_DISABLED)
{
game[i]->SetVisible(true);
game[i]->SetState(STATE_DEFAULT);
}
if (strlen(get_title(&gameList[next])) < (u32)(CFG.maxcharacters + 3))
{
sprintf(buffer, "%s", get_title(&gameList[next]));
}
else
{
sprintf(buffer, get_title(&gameList[next]), CFG.maxcharacters);
buffer[CFG.maxcharacters] = '\0';
strncat(buffer, "...", 3);
}
gameTxt[i]->SetText(buffer);
gameIndex[i] = next;
next = this->FindMenuItem(next, 1);
}
else
{
game[i]->SetVisible(false);
game[i]->SetState(STATE_DISABLED);
}
if(focus)
{
if(i != selectedItem && game[i]->GetState() == STATE_SELECTED)
game[i]->ResetState();
else if(i == selectedItem && game[i]->GetState() == STATE_DEFAULT)
game[selectedItem]->SetState(STATE_SELECTED, t->chan);
}
game[i]->Update(t);
if(game[i]->GetState() == STATE_SELECTED)
{
selectedItem = i;
}
}
// pad/joystick navigation
if(!focus)
return; // skip navigation
if (scrollbaron == 1) {
if (t->Down() ||
arrowDownBtn->GetState() == STATE_CLICKED || ////////////////////////////////////////////down
arrowDownBtn->GetState() == STATE_HELD)
{
next = this->FindMenuItem(gameIndex[selectedItem], 1);
if(next >= 0)
{
if(selectedItem == pagesize-1)
{
// move list down by 1
listOffset = this->FindMenuItem(listOffset, 1);
}
else if(game[selectedItem+1]->IsVisible())
{
game[selectedItem]->ResetState();
game[selectedItem+1]->SetState(STATE_SELECTED, t->chan);
selectedItem++;
}
scrollbarBoxBtn->Draw();
usleep(10000 * scrolldelay);
}WPAD_ScanPads();
u8 cnt, buttons = NULL;
/* Get pressed buttons */
for (cnt = 0; cnt < 4; cnt++)
buttons |= WPAD_ButtonsHeld(cnt);
if (buttons == WPAD_BUTTON_A) {
} else {
arrowDownBtn->ResetState();
}
}
else if(t->Up() ||
arrowUpBtn->GetState() == STATE_CLICKED || ////////////////////////////////////////////up
arrowUpBtn->GetState() == STATE_HELD)
{
prev = this->FindMenuItem(gameIndex[selectedItem], -1);
if(prev >= 0)
{
if(selectedItem == 0)
{
// move list up by 1
listOffset = prev;
}
else
{
game[selectedItem]->ResetState();
game[selectedItem-1]->SetState(STATE_SELECTED, t->chan);
selectedItem--;
}
scrollbarBoxBtn->Draw();
usleep(10000 * scrolldelay);
}
WPAD_ScanPads();
u8 cnt, buttons = NULL;
/* Get pressed buttons */
for (cnt = 0; cnt < 4; cnt++)
buttons |= WPAD_ButtonsHeld(cnt);
if (buttons == WPAD_BUTTON_A) {
} else {
arrowUpBtn->ResetState();
}
}
WPAD_ScanPads();
u8 cnt, buttons = NULL;
int position1 = 0;
position1 = t->wpad.ir.y;
if (position2 == 0 && position1 > 0) {
position2 = position1;
}
for (cnt = 0; cnt < 4; cnt++)
buttons |= WPAD_ButtonsHeld(cnt);
if (buttons == WPAD_BUTTON_B && position1 > 0) {
scrollbarBoxBtn->ScrollIsOn(1);
if (position2 > position1) {
prev = this->FindMenuItem(gameIndex[selectedItem], -1);
if(prev >= 0)
{
if(selectedItem == 0)
{
// move list up by 1
listOffset = prev;
}
else
{
game[selectedItem]->ResetState();
game[selectedItem-1]->SetState(STATE_SELECTED, t->chan);
selectedItem--;
}
scrollbarBoxBtn->Draw();
usleep(10000 * scrolldelay);
}
} else if (position2 < position1) {
next = this->FindMenuItem(gameIndex[selectedItem], 1);
if(next >= 0)
{
if(selectedItem == pagesize-1)
{
// move list down by 1
listOffset = this->FindMenuItem(listOffset, 1);
}
else if(game[selectedItem+1]->IsVisible())
{
game[selectedItem]->ResetState();
game[selectedItem+1]->SetState(STATE_SELECTED, t->chan);
selectedItem++;
}
scrollbarBoxBtn->Draw();
usleep(10000 * scrolldelay);
}
}
} else if (!buttons) {
scrollbarBoxBtn->ScrollIsOn(0);
position2 = 0;
}
if(scrollbarBoxBtn->GetState() == STATE_HELD &&
scrollbarBoxBtn->GetStateChan() == t->chan &&
t->wpad.ir.valid && gameCnt > pagesize)
{
scrollbarBoxBtn->SetPosition(width/2-18+7,0);
int position = t->wpad.ir.y - 50 - scrollbarBoxBtn->GetTop();
listOffset = (position * gameCnt)/180 - selectedItem;
if(listOffset <= 0)
{
listOffset = 0;
selectedItem = 0;
}
else if(listOffset+pagesize >= gameCnt)
{
listOffset = gameCnt - pagesize;
selectedItem = pagesize-1;
}
}
int positionbar = 237*(listOffset + selectedItem) / gameCnt;
if(positionbar > 216)
positionbar = 216;
scrollbarBoxBtn->SetPosition(width/2-18+7, positionbar+8);
if(t->Right())
{
if(listOffset < gameCnt && gameCnt > pagesize)
{
listOffset =listOffset+ pagesize;
if(listOffset+pagesize >= gameCnt)
listOffset = gameCnt-pagesize;
}
}
else if(t->Left())
{
if(listOffset > 0)
{
listOffset =listOffset- pagesize;
if(listOffset < 0)
listOffset = 0;
}
}
} else {
if(t->Down())
{
next = this->FindMenuItem(gameIndex[selectedItem], 1);
if(next >= 0)
{
if(selectedItem == pagesize-1)
{
// move list down by 1
listOffset = this->FindMenuItem(listOffset, 1);
}
else if(game[selectedItem+1]->IsVisible())
{
game[selectedItem]->ResetState();
game[selectedItem+1]->SetState(STATE_SELECTED, t->chan);
selectedItem++;
}
}
}
else if(t->Up())
{
prev = this->FindMenuItem(gameIndex[selectedItem], -1);
if(prev >= 0)
{
if(selectedItem == 0)
{
// move list up by 1
listOffset = prev;
}
else
{
game[selectedItem]->ResetState();
game[selectedItem-1]->SetState(STATE_SELECTED, t->chan);
selectedItem--;
}
}
}
}
if(updateCB)
updateCB(this);
}

View File

@ -0,0 +1,88 @@
#ifndef _GUIGAMEBROWSER_H_
#define _GUIGAMEBROWSER_H_
#include "gui.h"
#include "../disc.h"
/*
class GameBrowserList {
public:
GameBrowserList(int size) {
name = new char * [size];
for (int i = 0; i < size; i++)
{
name[i] = new char[50];
}
length = size;
};
~GameBrowserList(){
for (int i = 0; i < length; i++)
{
delete [] name[i];
}
delete [] name;
};
public:
int length;
char ** name;
};
*/
class GuiGameBrowser : public GuiElement
{
public:
GuiGameBrowser(int w, int h, struct discHdr * l, int gameCnt, const char *themePath, const u8 *imagebg, int selected = 0, int offset = 0);
~GuiGameBrowser();
int FindMenuItem(int c, int d);
int GetClickedOption();
int GetSelectedOption();
void ResetState();
void SetFocus(int f);
void Draw();
void Update(GuiTrigger * t);
int GetOffset();
//GuiText * optionVal[PAGESIZE];
protected:
int selectedItem;
int listOffset;
int scrollbaron;
int pagesize;
struct discHdr * gameList;
int gameCnt;
int * gameIndex;
GuiButton ** game;
GuiText ** gameTxt;
GuiImage ** gameBg;
GuiButton * arrowUpBtn;
GuiButton * arrowDownBtn;
GuiButton * scrollbarBoxBtn;
GuiImage * bgGameImg;
GuiImage * scrollbarImg;
GuiImage * arrowDownImg;
GuiImage * arrowDownOverImg;
GuiImage * arrowUpImg;
GuiImage * arrowUpOverImg;
GuiImage * scrollbarBoxImg;
GuiImage * scrollbarBoxOverImg;
GuiImageData * bgGames;
GuiImageData * bgGamesEntry;
GuiImageData * scrollbar;
GuiImageData * arrowDown;
GuiImageData * arrowDownOver;
GuiImageData * arrowUp;
GuiImageData * arrowUpOver;
GuiImageData * scrollbarBox;
GuiImageData * scrollbarBoxOver;
GuiSound * btnSoundOver;
GuiSound * btnSoundClick;
GuiTrigger * trigA;
GuiTrigger * trigHeldA;
};
#endif

View File

@ -0,0 +1,239 @@
/****************************************************************************
* libwiigui
*
* Tantric 2009
*
* gui_image.cpp
*
* GUI class definitions
***************************************************************************/
#include "gui.h"
/**
* Constructor for the GuiImage class.
*/
GuiImage::GuiImage()
{
image = NULL;
width = 0;
height = 0;
imageangle = 0;
tile = -1;
stripe = 0;
widescreen = 0;
imgType = IMAGE_DATA;
}
GuiImage::GuiImage(GuiImageData * img)
{
image = img->GetImage();
width = img->GetWidth();
height = img->GetHeight();
imageangle = 0;
tile = -1;
stripe = 0;
widescreen = 0;
imgType = IMAGE_DATA;
}
GuiImage::GuiImage(u8 * img, int w, int h)
{
image = img;
width = w;
height = h;
imageangle = 0;
tile = -1;
stripe = 0;
widescreen = 0;
imgType = IMAGE_TEXTURE;
}
GuiImage::GuiImage(int w, int h, GXColor c)
{
image = (u8 *)memalign (32, w * h * 4);
width = w;
height = h;
imageangle = 0;
tile = -1;
stripe = 0;
widescreen = 0;
imgType = IMAGE_COLOR;
if(!image)
return;
int x, y;
for(y=0; y < h; y++)
{
for(x=0; x < w; x++)
{
this->SetPixel(x, y, c);
}
}
int len = w*h*4;
if(len%32) len += (32-len%32);
DCFlushRange(image, len);
}
/**
* Destructor for the GuiImage class.
*/
GuiImage::~GuiImage()
{
if(imgType == IMAGE_COLOR && image)
free(image);
}
u8 * GuiImage::GetImage()
{
return image;
}
void GuiImage::SetImage(GuiImageData * img)
{
image = img->GetImage();
width = img->GetWidth();
height = img->GetHeight();
imgType = IMAGE_DATA;
}
void GuiImage::SetImage(u8 * img, int w, int h)
{
image = img;
width = w;
height = h;
imgType = IMAGE_TEXTURE;
}
void GuiImage::SetAngle(float a)
{
imageangle = a;
}
void GuiImage::SetTile(int t)
{
tile = t;
}
void GuiImage::SetWidescreen(short w)
{
widescreen = w;
}
GXColor GuiImage::GetPixel(int x, int y)
{
if(!image || this->GetWidth() <= 0 || x < 0 || y < 0)
return (GXColor){0, 0, 0, 0};
u32 offset = (((y >> 2)<<4)*this->GetWidth()) + ((x >> 2)<<6) + (((y%4 << 2) + x%4 ) << 1);
GXColor color;
color.a = *(image+offset);
color.r = *(image+offset+1);
color.g = *(image+offset+32);
color.b = *(image+offset+33);
return color;
}
void GuiImage::SetPixel(int x, int y, GXColor color)
{
if(!image || this->GetWidth() <= 0 || x < 0 || y < 0)
return;
u32 offset = (((y >> 2)<<4)*this->GetWidth()) + ((x >> 2)<<6) + (((y%4 << 2) + x%4 ) << 1);
*(image+offset) = color.a;
*(image+offset+1) = color.r;
*(image+offset+32) = color.g;
*(image+offset+33) = color.b;
}
void GuiImage::SetStripe(int s)
{
stripe = s;
}
void GuiImage::ColorStripe(int shift)
{
int x, y;
GXColor color;
int alt = 0;
for(y=0; y < this->GetHeight(); y++)
{
if(y % 3 == 0)
alt ^= 1;
for(x=0; x < this->GetWidth(); x++)
{
color = GetPixel(x, y);
if(alt)
{
if(color.r < 255-shift)
color.r += shift;
else
color.r = 255;
if(color.g < 255-shift)
color.g += shift;
else
color.g = 255;
if(color.b < 255-shift)
color.b += shift;
else
color.b = 255;
color.a = 255;
}
else
{
if(color.r > shift)
color.r -= shift;
else
color.r = 0;
if(color.g > shift)
color.g -= shift;
else
color.g = 0;
if(color.b > shift)
color.b -= shift;
else
color.b = 0;
color.a = 255;
}
SetPixel(x, y, color);
}
}
}
/**
* Draw the button on screen
*/
void GuiImage::Draw()
{
if(!image || !this->IsVisible() || tile == 0)
return;
float currScale = this->GetScale();
int currLeft = this->GetLeft();
if(tile > 0)
{
for(int i=0; i<tile; i++)
Menu_DrawImg(currLeft+width*i, this->GetTop(), width, height, image, imageangle, widescreen ? currScale*0.8 : currScale, currScale, this->GetAlpha());
}
else
{
// temporary (maybe), used to correct offset for scaled images
if(scale != 1)
currLeft = currLeft - width/2 + (width*scale)/2;
Menu_DrawImg(currLeft, this->GetTop(), width, height, image, imageangle, widescreen ? currScale*0.8 : currScale, currScale, this->GetAlpha());
}
if(stripe > 0)
for(int y=0; y < this->GetHeight(); y+=6)
Menu_DrawRectangle(currLeft,this->GetTop()+y,this->GetWidth(),3,(GXColor){0, 0, 0, stripe},1);
this->UpdateEffects();
}

View File

@ -0,0 +1,171 @@
/****************************************************************************
* libwiigui
*
* Tantric 2009
*
* gui_imagedata.cpp
*
* GUI class definitions
***************************************************************************/
#include "gui.h"
/**
* Constructor for the GuiImageData class.
*/
GuiImageData::GuiImageData(const u8 * img)
{
data = NULL;
width = 0;
height = 0;
if(img)
{
PNGUPROP imgProp;
IMGCTX ctx = PNGU_SelectImageFromBuffer(img);
if(!ctx)
return;
int res = PNGU_GetImageProperties(ctx, &imgProp);
if(res == PNGU_OK)
{
int len = imgProp.imgWidth * imgProp.imgHeight * 4;
if(len%32) len += (32-len%32);
data = (u8 *)memalign (32, len);
if(data)
{
res = PNGU_DecodeTo4x4RGBA8 (ctx, imgProp.imgWidth, imgProp.imgHeight, data, 255);
if(res == PNGU_OK)
{
width = imgProp.imgWidth;
height = imgProp.imgHeight;
DCFlushRange(data, len);
}
else
{
free(data);
data = NULL;
}
}
}
PNGU_ReleaseImageContext (ctx);
}
}
/**
* Constructor for the GuiImageData class.
*/
GuiImageData::GuiImageData(const char * imgPath, const u8 * buffer)
{
data = NULL;
width = 0;
height = 0;
if(imgPath)
{
PNGUPROP imgProp;
IMGCTX ctx = PNGU_SelectImageFromDevice(imgPath);
if(ctx)
{
int res = PNGU_GetImageProperties(ctx, &imgProp);
if(res == PNGU_OK)
{
int len = imgProp.imgWidth * imgProp.imgHeight * 4;
if(len%32) len += (32-len%32);
data = (u8 *)memalign (32, len);
if(data)
{
res = PNGU_DecodeTo4x4RGBA8 (ctx, imgProp.imgWidth, imgProp.imgHeight, data, 255);
if(res == PNGU_OK)
{
width = imgProp.imgWidth;
height = imgProp.imgHeight;
DCFlushRange(data, len);
}
else
{
free(data);
data = NULL;
}
}
}
PNGU_ReleaseImageContext (ctx);
}
}
if (!data) //use buffer data instead
{
width = 0;
height = 0;
if(buffer)
{
PNGUPROP imgProp;
IMGCTX ctx = PNGU_SelectImageFromBuffer(buffer);
if(!ctx)
return;
int res = PNGU_GetImageProperties(ctx, &imgProp);
if(res == PNGU_OK)
{
int len = imgProp.imgWidth * imgProp.imgHeight * 4;
if(len%32) len += (32-len%32);
data = (u8 *)memalign (32, len);
if(data)
{
res = PNGU_DecodeTo4x4RGBA8 (ctx, imgProp.imgWidth, imgProp.imgHeight, data, 255);
if(res == PNGU_OK)
{
width = imgProp.imgWidth;
height = imgProp.imgHeight;
DCFlushRange(data, len);
}
else
{
free(data);
data = NULL;
}
}
}
PNGU_ReleaseImageContext (ctx);
}
}
}
/**
* Destructor for the GuiImageData class.
*/
GuiImageData::~GuiImageData()
{
if(data)
{
free(data);
data = NULL;
}
}
u8 * GuiImageData::GetImage()
{
return data;
}
int GuiImageData::GetWidth()
{
return width;
}
int GuiImageData::GetHeight()
{
return height;
}

Some files were not shown because too many files have changed in this diff Show More