Skip to content
This repository has been archived by the owner on Apr 9, 2024. It is now read-only.

Commit

Permalink
Small cutscenes now load runtime.
Browse files Browse the repository at this point in the history
Fixes to bridge texture selection.
Fixes to out of range floor textures.

Various other code cleanup ahead of release
  • Loading branch information
hankmorgan committed Feb 15, 2017
1 parent 864a35e commit 1ae6382
Show file tree
Hide file tree
Showing 19 changed files with 384 additions and 204 deletions.
7 changes: 5 additions & 2 deletions UnityScripts/scripts/Conversations/Conversation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -172,13 +172,16 @@ public void SetupConversation(int StringBlockNo)
///Sets up the portraits for the player and the NPC
RawImage portrait = UWHUD.instance.ConversationPortraits[0];
RawImage npcPortrait = UWHUD.instance.ConversationPortraits[1];
GRLoader grPCHead = new GRLoader(GRLoader.HEADS_GR);
if (GameWorldController.instance.playerUW.isFemale)
{
portrait.texture=Resources.Load <Texture2D> (_RES +"/HUD/PlayerHeads/heads_"+ (GameWorldController.instance.playerUW.Body+5).ToString("0000"));//TODO:playerbody
//portrait.texture=Resources.Load <Texture2D> (_RES +"/HUD/PlayerHeads/heads_"+ (GameWorldController.instance.playerUW.Body+5).ToString("0000"));//TODO:playerbody
portrait.texture= grPCHead.LoadImageAt(GameWorldController.instance.playerUW.Body+5);
}
else
{
portrait.texture=Resources.Load <Texture2D> (_RES +"/HUD/PlayerHeads/heads_"+ (GameWorldController.instance.playerUW.Body).ToString("0000"));//TODO:playerbody
//portrait.texture=Resources.Load <Texture2D> (_RES +"/HUD/PlayerHeads/heads_"+ (GameWorldController.instance.playerUW.Body).ToString("0000"));//TODO:playerbody
portrait.texture= grPCHead.LoadImageAt(GameWorldController.instance.playerUW.Body);
}


Expand Down
2 changes: 1 addition & 1 deletion UnityScripts/scripts/Loaders/ArtLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public virtual Texture2D LoadImageAt(int index, bool Alpha)
/// <param name="Alpha">If set to <c>true</c> alpha.</param>
public static Texture2D Image(char[] databuffer,long dataOffSet, int width, int height, string imageName, Palette pal , bool Alpha )
{
int pixelcount=0;
//int pixelcount=0;
Texture2D image = new Texture2D(width, height,TextureFormat.ARGB32,false);
Color32[] imageColors = new Color32[width * height];
long counter=0;
Expand Down
294 changes: 166 additions & 128 deletions UnityScripts/scripts/Loaders/CritterInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,150 +72,188 @@ public CritterInfo(int critter_id, Palette paletteToUse, int palno)

private int ReadPageFile(char[] PageFile, int XX, int YY ,int spriteIndex)
{
int addptr=0;
int slotbase = (int)DataLoader.getValAtAddress(PageFile,addptr++,8);
int NoOfSlots =(int)DataLoader.getValAtAddress(PageFile,addptr++,8);
int[] SlotIndices = new int[NoOfSlots];
int spriteCounter=0;
int k=0;
string XXo = DecimalToOct(XX.ToString());
string YYo = DecimalToOct(YY.ToString());
for (int i=0; i<NoOfSlots;i++)
int addptr=0;
int slotbase = (int)DataLoader.getValAtAddress(PageFile,addptr++,8);
int NoOfSlots =(int)DataLoader.getValAtAddress(PageFile,addptr++,8);
int[] SlotIndices = new int[NoOfSlots];
int spriteCounter=0;
int k=0;
string XXo = DecimalToOct(XX.ToString());
string YYo = DecimalToOct(YY.ToString());
for (int i=0; i<NoOfSlots;i++)
{
int val= (int)DataLoader.getValAtAddress(PageFile,addptr++,8);
if (val!=255)
{
int val= (int)DataLoader.getValAtAddress(PageFile,addptr++,8);
if (val!=255)
{
SlotIndices[k++] = i;
}
SlotIndices[k++] = i;
}
int NoOfSegs = (int)DataLoader.getValAtAddress(PageFile, addptr++, 8);
for (int i = 0; i < NoOfSegs; i++)
}
int NoOfSegs = (int)DataLoader.getValAtAddress(PageFile, addptr++, 8);
for (int i = 0; i < NoOfSegs; i++)
{
//string[] AnimFiles = new string[8];
string AnimName = PrintAnimName(slotbase + SlotIndices[i]);

int index=TranslateAnimToIndex(slotbase + SlotIndices[i]);
AnimInfo.animName[index]=AnimName;
int ValidCount=0;
for (int j=0; j<8;j++)
{
string[] AnimFiles = new string[8];
string AnimName = PrintAnimName(slotbase + SlotIndices[i]);
int val=(int)DataLoader.getValAtAddress(PageFile,addptr++,8);
if (val!=255)
{ //AnimFiles[j] = "CR" + XX.ToString("d2") + "PAGE_N" + YY.ToString("d2") + "_" + AuxPalNo + "_" + val;

AnimInfo.animSequence[index,j]= "CR" + XXo + "PAGE_N" + YYo + "_" + AuxPalNo + "_" + (val).ToString("d4");
AnimInfo.animIndices[index,j]= (val + spriteIndex);
ValidCount++;
}
}
}

int index=TranslateAnimToIndex(slotbase + SlotIndices[i]);
AnimInfo.animName[index]=AnimName;
int ValidCount=0;
for (int j=0; j<8;j++)
//Read in the palette
int NoOfPals = (int)DataLoader.getValAtAddress(PageFile, addptr, 8);//Will skip ahead this far.
addptr++;
char[] auxPalVal=new char[32];
for (int i = 0; i < 32; i++)
{
auxPalVal[i] =(char)DataLoader.getValAtAddress(PageFile, (addptr)+(AuxPalNo * 32) + i, 8);
}

//Skip past the palettes
addptr = addptr + NoOfPals * 32;
int NoOfFrames = (int)DataLoader.getValAtAddress(PageFile, addptr, 8);
//AnimInfo.animSprites=new Sprite[NoOfFrames];
addptr=addptr+2;
int addptr_start = addptr;//Bookmark my positiohn
int MaxWidth=0;
int MaxHeight=0;
int MaxHotSpotX=0;
int MaxHotSpotY=0;
for (int pass = 0; pass <= 1; pass++)
{
addptr=addptr_start;
if (pass == 0)
{//get the max width and height
for (int i = 0; i < NoOfFrames; i++)
{
int frameOffset = (int)DataLoader.getValAtAddress(PageFile, addptr + (i * 2), 16);
int BitMapWidth = (int)DataLoader.getValAtAddress(PageFile, frameOffset + 0, 8);
int BitMapHeight = (int)DataLoader.getValAtAddress(PageFile, frameOffset + 1, 8);
int hotspotx = (int)DataLoader.getValAtAddress(PageFile, frameOffset + 2, 8);
int hotspoty = (int)DataLoader.getValAtAddress(PageFile, frameOffset + 3, 8);
if (hotspotx>BitMapWidth)
{
hotspotx = BitMapWidth;
}
if (hotspoty>BitMapHeight)
{
int val=(int)DataLoader.getValAtAddress(PageFile,addptr++,8);
if (val!=255)
{ //AnimFiles[j] = "CR" + XX.ToString("d2") + "PAGE_N" + YY.ToString("d2") + "_" + AuxPalNo + "_" + val;
hotspoty = BitMapHeight;
}

AnimInfo.animSequence[index,j]= "CR" + XXo + "PAGE_N" + YYo + "_" + AuxPalNo + "_" + (val + spriteIndex).ToString("d4");
AnimInfo.animIndices[index,j]= (val + spriteIndex);
ValidCount++;
}
}
}
if (BitMapWidth > MaxWidth)
{
MaxWidth = BitMapWidth;
}
if (BitMapHeight > MaxHeight)
{
MaxHeight = BitMapHeight;
}

//Read in the palette
int NoOfPals = (int)DataLoader.getValAtAddress(PageFile, addptr, 8);//Will skip ahead this far.
addptr++;
char[] auxPalVal=new char[32];
for (int i = 0; i < 32; i++)
{
auxPalVal[i] =(char)DataLoader.getValAtAddress(PageFile, (addptr)+(AuxPalNo * 32) + i, 8);
if (hotspotx > MaxHotSpotX)
{
MaxHotSpotX = hotspotx;
}
if (hotspoty > MaxHotSpotY)
{
MaxHotSpotY = hotspoty;
}
}
}

//Skip past the palettes
addptr = addptr + NoOfPals * 32;
int NoOfFrames = (int)DataLoader.getValAtAddress(PageFile, addptr, 8);
//AnimInfo.animSprites=new Sprite[NoOfFrames];
addptr=addptr+2;
int addptr_start = addptr;//Bookmark my positiohn
int MaxWidth=0;
int MaxHeight=0;
int MaxHotSpotX=0;
int MaxHotSpotY=0;
for (int pass = 0; pass <= 1; pass++)
{
addptr=addptr_start;
if (pass == 0)
{//get the max width and height
for (int i = 0; i < NoOfFrames; i++)
{
int frameOffset = (int)DataLoader.getValAtAddress(PageFile, addptr + (i * 2), 16);
//fprintf(LOGFILE,"\n%d @ %d", i, frameOffset);
int BitMapWidth = (int)DataLoader.getValAtAddress(PageFile, frameOffset + 0, 8);
int BitMapHeight = (int)DataLoader.getValAtAddress(PageFile, frameOffset + 1, 8);
int hotspotx = (int)DataLoader.getValAtAddress(PageFile, frameOffset + 2, 8);
int hotspoty = (int)DataLoader.getValAtAddress(PageFile, frameOffset + 3, 8);
if (hotspotx>BitMapWidth)
{
hotspotx = BitMapWidth;
}
if (hotspoty>BitMapHeight)
{
hotspoty = BitMapHeight;
}

if (BitMapWidth > MaxWidth)
{
MaxWidth = BitMapWidth;
}
if (BitMapHeight > MaxHeight)
{
MaxHeight = BitMapHeight;
}

if (hotspotx > MaxHotSpotX)
{
MaxHotSpotX = hotspotx;
}
if (hotspoty > MaxHotSpotY)
{
MaxHotSpotY = hotspoty;
}
}
else
{//Extract
if (MaxHotSpotX * 2 > MaxWidth)
{//Try and center the hot spot in the image.
MaxWidth = MaxHotSpotX * 2;
}
else
{//Extract
if (MaxHotSpotX * 2 > MaxWidth)
{//Try and center the hot spot in the image.
MaxWidth = MaxHotSpotX * 2;
}
char[] outputImg;
outputImg = new char[MaxWidth*MaxHeight*2];
for (int i = 0; i < NoOfFrames; i++)
char[] outputImg;
outputImg = new char[MaxWidth*MaxHeight*2];
for (int i = 0; i < NoOfFrames; i++)
{
int frameOffset = (int)DataLoader.getValAtAddress(PageFile, addptr + (i * 2), 16);
int BitMapWidth = (int)DataLoader.getValAtAddress(PageFile, frameOffset + 0, 8);
int BitMapHeight = (int)DataLoader.getValAtAddress(PageFile, frameOffset + 1, 8);
int hotspotx = (int)DataLoader.getValAtAddress(PageFile, frameOffset + 2, 8);
int hotspoty = (int)DataLoader.getValAtAddress(PageFile, frameOffset + 3, 8);
int compression = (int)DataLoader.getValAtAddress(PageFile, frameOffset + 4, 8);
int datalen = (int)DataLoader.getValAtAddress(PageFile, frameOffset + 5, 16);

//Adjust the hotspots from the biggest point back to the image corners
int cornerX; int cornerY;
cornerX= MaxHotSpotX-hotspotx;
cornerY = MaxHotSpotY - hotspoty;
if (cornerX<=0)
{
cornerX = 0;
}
else
{
cornerX = cornerX - 1;
}
if (cornerY<=0)
{
cornerY = 0;
}

//Extract the image
char[] srcImg;
srcImg = new char[BitMapWidth*BitMapHeight*2];
outputImg = new char[MaxWidth*MaxHeight*2];
// Sprite.Create(Image(grBuffer,imageOffset, BitMapWidth, BitMapHeight,"name_goes_here",palLoader.Palettes[pal],true),new Rect(0f,0f,BitMapWidth,BitMapHeight),new Vector2 (0.5f,0.5f));
ArtLoader.ua_image_decode_rle(PageFile,srcImg, compression == 6 ? 5 : 4, datalen, BitMapWidth*BitMapHeight, frameOffset + 7, auxPalVal);


//*Put the sprite in the a frame of size max width & height
cornerY = MaxHeight-cornerY;//y is from the top left corner
int ColCounter = 0; int RowCounter = 0;
bool ImgStarted = false;
for (int y = 0; y < MaxHeight; y++)
{
for (int x = 0; x < MaxWidth; x++)
{
int frameOffset = (int)DataLoader.getValAtAddress(PageFile, addptr + (i * 2), 16);
int BitMapWidth = (int)DataLoader.getValAtAddress(PageFile, frameOffset + 0, 8);
int BitMapHeight = (int)DataLoader.getValAtAddress(PageFile, frameOffset + 1, 8);
int hotspotx = (int)DataLoader.getValAtAddress(PageFile, frameOffset + 2, 8);
int hotspoty = (int)DataLoader.getValAtAddress(PageFile, frameOffset + 3, 8);
int compression = (int)DataLoader.getValAtAddress(PageFile, frameOffset + 4, 8);
int datalen = (int)DataLoader.getValAtAddress(PageFile, frameOffset + 5, 16);

//Adjust the hotspots from the biggest point back to the image corners
int cornerX; int cornerY;
cornerX= MaxHotSpotX-hotspotx;
cornerY = MaxHotSpotY - hotspoty;
if (cornerX<=0)
{
cornerX = 0;
if ((cornerX + ColCounter == x) && (MaxHeight-cornerY + RowCounter == y) && (ColCounter<BitMapWidth) && (RowCounter<BitMapHeight))
{//the pixel from the source image is here
ImgStarted=true;
outputImg[x + (y*MaxWidth)] = srcImg[ColCounter+(RowCounter*BitMapWidth)];
ColCounter++;
}
else
{
cornerX = cornerX - 1;
outputImg[x + (y*MaxWidth)]=(char)0;//alpha
}
if (cornerY<=0)
{
cornerY = 0;
}

//Extract the image
char[] srcImg;
srcImg = new char[BitMapWidth*BitMapHeight*2];
// Sprite.Create(Image(grBuffer,imageOffset, BitMapWidth, BitMapHeight,"name_goes_here",palLoader.Palettes[pal],true),new Rect(0f,0f,BitMapWidth,BitMapHeight),new Vector2 (0.5f,0.5f));
ArtLoader.ua_image_decode_rle(PageFile,srcImg, compression == 6 ? 5 : 4, datalen, BitMapWidth*BitMapHeight, frameOffset + 7, auxPalVal);
Texture2D imgData= ArtLoader.Image(srcImg,0,BitMapWidth,BitMapHeight,"namehere",pal,true);
AnimInfo.animSprites[spriteIndex+ i]= Sprite.Create(imgData,new Rect(0f,0f,BitMapWidth,BitMapHeight),new Vector2 (0.5f,0.5f));
spriteCounter++;
}
if (ImgStarted == true)
{//New Row on the src image
RowCounter++;
ColCounter=0;
}
}
//Set the heights for output
BitMapWidth=MaxWidth;
BitMapHeight = MaxHeight;


//****************************



Texture2D imgData= ArtLoader.Image(outputImg,0,BitMapWidth,BitMapHeight,"namehere",pal,true);
AnimInfo.animSprites[spriteIndex+ i]= Sprite.Create(imgData,new Rect(0f,0f,BitMapWidth,BitMapHeight),new Vector2 (0.5f,0.0f));
//AnimInfo.animSprites[spriteIndex+ i].pixelsPerUnit=50;
AnimInfo.animSprites[spriteIndex+ i].texture.filterMode=FilterMode.Point;
spriteCounter++;
}

}//endextract
}//endextract
}
return spriteCounter;
}
Expand Down
2 changes: 1 addition & 1 deletion UnityScripts/scripts/Loaders/CutsLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ The whole header is 128 bytes long. After the header color cycling info
{
ppointer += 4;
}
char[] imgOut ;//= //new char[lpH.height*lpH.width+ 4000];
// char[] imgOut ;//= //new char[lpH.height*lpH.width+ 4000];
myPlayRunSkipDump(ppointer, pages);//Stores in the global memory
//output.texture=
ImageCache[imagecount++]= Image(dstImage,0,lpH.width,lpH.height,"name here", pal, Alpha);
Expand Down
2 changes: 1 addition & 1 deletion UnityScripts/scripts/Loaders/DataLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public static char[] unpackUW2(char[] tmp, long address_pointer, ref int datalen
//Robbed and changed slightly from the Labyrinth of Worlds implementation project.
//This decompresses UW2 blocks.
long len = (int)DataLoader.getValAtAddress(tmp,address_pointer,32); //lword(base);
long block_address=address_pointer;
//long block_address=address_pointer;
char[] buf = new char[len+100];
char[] up = buf;
long upPtr=0;
Expand Down
4 changes: 2 additions & 2 deletions UnityScripts/scripts/Loaders/GRLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -170,12 +170,12 @@ public override Texture2D LoadImageAt (int index, bool Alpha)
imgNibbles = new char[Mathf.Max(BitMapWidth*BitMapHeight*2,datalen*2)];
imageOffset = imageOffset + 6; //Start of raw data.
copyNibbles(ImageFileData, ref imgNibbles, datalen, imageOffset);
auxpal =PaletteLoader.LoadAuxilaryPal("c:\\games\\uw1\\DATA\\allpals.dat",GameWorldController.instance.palLoader.Palettes[PaletteNo],auxPalIndex);
auxpal =PaletteLoader.LoadAuxilaryPal(BasePath+ "DATA\\allpals.dat",GameWorldController.instance.palLoader.Palettes[PaletteNo],auxPalIndex);

ImageCache[index] = Image(imgNibbles,0, BitMapWidth, BitMapHeight,"name_goes_here",auxpal,Alpha);
return ImageCache[index];
}
break;
//break;
default:
//Check to see if the file is panels.gr
if (pathGR[FileToLoad].ToUpper().EndsWith("PANELS.GR"))
Expand Down
4 changes: 2 additions & 2 deletions UnityScripts/scripts/Loaders/ObjectLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ void BuildObjectListUW(TileInfo[,] LevelInfo, ObjectLoaderInfo[] objList,int[] t

//unsigned char *lev_ark;
//unsigned char *tmp_ark; //for uw2 decompression
long fileSize;
//long fileSize;
int NoOfBlocks;
long AddressOfBlockStart;
long objectsAddress;
Expand Down Expand Up @@ -76,7 +76,7 @@ void BuildObjectListUW(TileInfo[,] LevelInfo, ObjectLoaderInfo[] objList,int[] t
int compressionFlag=(int)DataLoader.getValAtAddress(tmp_ark,address_pointer + (NoOfBlocks*4) ,32);
int isCompressed =(compressionFlag>>1) & 0x01;

long dataSize = address_pointer + (2*NoOfBlocks*4); //????
//long dataSize = address_pointer + (2*NoOfBlocks*4); //????
address_pointer=(LevelNo * 4) + 6;
if (DataLoader.getValAtAddress(tmp_ark,address_pointer,32)==0)
{
Expand Down
Loading

0 comments on commit 1ae6382

Please sign in to comment.