Midnight Club: Street Racing (Ps2) .strtbl

Extraction and unpacking of game archives and compression, encryption, obfuscation, decoding of unknown files
ISKA
Posts: 223
Joined: Mon Apr 09, 2018 11:09 pm

Midnight Club: Street Racing (Ps2) .strtbl

Post by ISKA »

I tried:
Rdr strtbl - swuforce
Midnight Club 3 DUB Edition Remix - Delutto
Doesn't work nothing.
LokiReborn
Posts: 190
Joined: Fri Aug 26, 2016 3:11 pm

Re: Midnight Club: Street Racing (Ps2) .strtbl

Post by LokiReborn »

ISKA wrote:I tried:
Rdr strtbl - swuforce
Midnight Club 3 DUB Edition Remix - Delutto
Doesn't work nothing.


Is this all you're trying to get at?

I just used the code below, the basic structure is count of offsets, followed by offsets. Some of them overlap assuming it's a lookup to a specific section used for something.
Then after that it's another count for string entries, followed by the entries themselves until the end of the file. The 8 bytes before the string I'm not sure if it's a hash or what the 8 after the string seem to always be 0000803F0000803F


Code: Select all

OpenFileDialog OD = new OpenFileDialog();
if (OD.ShowDialog() == DialogResult.OK)
{
    FileStream fs = new FileStream(OD.FileName, FileMode.Open);
    BinaryReader br = new BinaryReader(fs);
    fs.Position = br.ReadInt32() * 4 + 4;

    int count = br.ReadInt32();
    List<string> stringEntries = new List<string>();

    for (int i = 0; i < count; i++)
    {
        br.ReadInt64();
        string check = Encoding.Unicode.GetString(br.ReadBytes(br.ReadInt32() * 2));
        stringEntries.Add(check);
        br.ReadInt64();
    }

    File.WriteAllLines(OD.FileName + ".txt", stringEntries);

    br.Close();
    fs.Close();
}
ISKA
Posts: 223
Joined: Mon Apr 09, 2018 11:09 pm

Re: Midnight Club: Street Racing (Ps2) .strtbl

Post by ISKA »

LokiReborn wrote:
ISKA wrote:I tried:
Rdr strtbl - swuforce
Midnight Club 3 DUB Edition Remix - Delutto
Doesn't work nothing.


Is this all you're trying to get at?

I just used the code below, the basic structure is count of offsets, followed by offsets. Some of them overlap assuming it's a lookup to a specific section used for something.
Then after that it's another count for string entries, followed by the entries themselves until the end of the file. The 8 bytes before the string I'm not sure if it's a hash or what the 8 after the string seem to always be 0000803F0000803F


Code: Select all

OpenFileDialog OD = new OpenFileDialog();
if (OD.ShowDialog() == DialogResult.OK)
{
    FileStream fs = new FileStream(OD.FileName, FileMode.Open);
    BinaryReader br = new BinaryReader(fs);
    fs.Position = br.ReadInt32() * 4 + 4;

    int count = br.ReadInt32();
    List<string> stringEntries = new List<string>();

    for (int i = 0; i < count; i++)
    {
        br.ReadInt64();
        string check = Encoding.Unicode.GetString(br.ReadBytes(br.ReadInt32() * 2));
        stringEntries.Add(check);
        br.ReadInt64();
    }

    File.WriteAllLines(OD.FileName + ".txt", stringEntries);

    br.Close();
    fs.Close();
}


I just need unpack, edit and repack strtbl files.
LokiReborn
Posts: 190
Joined: Fri Aug 26, 2016 3:11 pm

Re: Midnight Club: Street Racing (Ps2) .strtbl

Post by LokiReborn »

ISKA wrote:
LokiReborn wrote:
ISKA wrote:I tried:
Rdr strtbl - swuforce
Midnight Club 3 DUB Edition Remix - Delutto
Doesn't work nothing.


Is this all you're trying to get at?

I just used the code below, the basic structure is count of offsets, followed by offsets. Some of them overlap assuming it's a lookup to a specific section used for something.
Then after that it's another count for string entries, followed by the entries themselves until the end of the file. The 8 bytes before the string I'm not sure if it's a hash or what the 8 after the string seem to always be 0000803F0000803F


Code: Select all

OpenFileDialog OD = new OpenFileDialog();
if (OD.ShowDialog() == DialogResult.OK)
{
    FileStream fs = new FileStream(OD.FileName, FileMode.Open);
    BinaryReader br = new BinaryReader(fs);
    fs.Position = br.ReadInt32() * 4 + 4;

    int count = br.ReadInt32();
    List<string> stringEntries = new List<string>();

    for (int i = 0; i < count; i++)
    {
        br.ReadInt64();
        string check = Encoding.Unicode.GetString(br.ReadBytes(br.ReadInt32() * 2));
        stringEntries.Add(check);
        br.ReadInt64();
    }

    File.WriteAllLines(OD.FileName + ".txt", stringEntries);

    br.Close();
    fs.Close();
}


I just need unpack, edit and repack strtbl files.


Okay going to take some tweaking, I missed a piece and know what the offsets at the start are.
Basically the game supports 10 languages, so the offsets at the start are the pointer to the table for each language. They reuse the same table for multiple languages so depending which language you want to edit depends on what strings you want to do (mind you I can't see if it lists 10 in game so it may only have 3 and it's just the file format supports 10)

From what I saw it seems like there are 6 unique language tables for in game and 7 of the 10 used. The one marked for reuse is Japanese which is weird but it is what it is.
ISKA
Posts: 223
Joined: Mon Apr 09, 2018 11:09 pm

Re: Midnight Club: Street Racing (Ps2) .strtbl

Post by ISKA »

LokiReborn wrote:
ISKA wrote:
LokiReborn wrote:
Is this all you're trying to get at?

I just used the code below, the basic structure is count of offsets, followed by offsets. Some of them overlap assuming it's a lookup to a specific section used for something.
Then after that it's another count for string entries, followed by the entries themselves until the end of the file. The 8 bytes before the string I'm not sure if it's a hash or what the 8 after the string seem to always be 0000803F0000803F


Code: Select all

OpenFileDialog OD = new OpenFileDialog();
if (OD.ShowDialog() == DialogResult.OK)
{
    FileStream fs = new FileStream(OD.FileName, FileMode.Open);
    BinaryReader br = new BinaryReader(fs);
    fs.Position = br.ReadInt32() * 4 + 4;

    int count = br.ReadInt32();
    List<string> stringEntries = new List<string>();

    for (int i = 0; i < count; i++)
    {
        br.ReadInt64();
        string check = Encoding.Unicode.GetString(br.ReadBytes(br.ReadInt32() * 2));
        stringEntries.Add(check);
        br.ReadInt64();
    }

    File.WriteAllLines(OD.FileName + ".txt", stringEntries);

    br.Close();
    fs.Close();
}


I just need unpack, edit and repack strtbl files.


Okay going to take some tweaking, I missed a piece and know what the offsets at the start are.
Basically the game supports 10 languages, so the offsets at the start are the pointer to the table for each language. They reuse the same table for multiple languages so depending which language you want to edit depends on what strings you want to do (mind you I can't see if it lists 10 in game so it may only have 3 and it's just the file format supports 10)

From what I saw it seems like there are 6 unique language tables for in game and 7 of the 10 used. The one marked for reuse is Japanese which is weird but it is what it is.


These files for european version.
LokiReborn
Posts: 190
Joined: Fri Aug 26, 2016 3:11 pm

Re: Midnight Club: Street Racing (Ps2) .strtbl

Post by LokiReborn »

ISKA wrote:
LokiReborn wrote:
ISKA wrote:
I just need unpack, edit and repack strtbl files.


Okay going to take some tweaking, I missed a piece and know what the offsets at the start are.
Basically the game supports 10 languages, so the offsets at the start are the pointer to the table for each language. They reuse the same table for multiple languages so depending which language you want to edit depends on what strings you want to do (mind you I can't see if it lists 10 in game so it may only have 3 and it's just the file format supports 10)

From what I saw it seems like there are 6 unique language tables for in game and 7 of the 10 used. The one marked for reuse is Japanese which is weird but it is what it is.


These files for european version.


So it doesn't seem to like encoding the Japanese as Unicode and back and is screwing up the last entry. Since they're the last language in the list I just had it skip that one and use the original and not read it from the files. You should be able to pick any one of the other 5 languages and translate whichever you choose.
ISKA
Posts: 223
Joined: Mon Apr 09, 2018 11:09 pm

Re: Midnight Club: Street Racing (Ps2) .strtbl

Post by ISKA »

LokiReborn wrote:
ISKA wrote:
LokiReborn wrote:
Okay going to take some tweaking, I missed a piece and know what the offsets at the start are.
Basically the game supports 10 languages, so the offsets at the start are the pointer to the table for each language. They reuse the same table for multiple languages so depending which language you want to edit depends on what strings you want to do (mind you I can't see if it lists 10 in game so it may only have 3 and it's just the file format supports 10)

From what I saw it seems like there are 6 unique language tables for in game and 7 of the 10 used. The one marked for reuse is Japanese which is weird but it is what it is.


These files for european version.


So it doesn't seem to like encoding the Japanese as Unicode and back and is screwing up the last entry. Since they're the last language in the list I just had it skip that one and use the original and not read it from the files. You should be able to pick any one of the other 5 languages and translate whichever you choose.

Thanks buddy. I will try and let you know.
ISKA
Posts: 223
Joined: Mon Apr 09, 2018 11:09 pm

Re: Midnight Club: Street Racing (Ps2) .strtbl

Post by ISKA »

ISKA wrote:
LokiReborn wrote:
ISKA wrote:
These files for european version.


So it doesn't seem to like encoding the Japanese as Unicode and back and is screwing up the last entry. Since they're the last language in the list I just had it skip that one and use the original and not read it from the files. You should be able to pick any one of the other 5 languages and translate whichever you choose.

Thanks buddy. I will try and let you know.


It worked. I have another question. Actually last question. I need to edit font files to completely translating for my language. I guess .tex file entensions actually font files and they are in different places. I will send the some examples. Would you help me about this?
http://mm2kiwi.apan.is-a-geek.com/index.php?title=TEX
http://forum.mm2c.com/viewtopic.php?t=1 ... d9f080313c

This noesis script export fonts but maybe can't support import.
https://forum.xentax.com/viewtopic.php? ... ArjVXmCdHg
LokiReborn
Posts: 190
Joined: Fri Aug 26, 2016 3:11 pm

Re: Midnight Club: Street Racing (Ps2) .strtbl

Post by LokiReborn »

ISKA wrote:
ISKA wrote:
LokiReborn wrote:
So it doesn't seem to like encoding the Japanese as Unicode and back and is screwing up the last entry. Since they're the last language in the list I just had it skip that one and use the original and not read it from the files. You should be able to pick any one of the other 5 languages and translate whichever you choose.

Thanks buddy. I will try and let you know.


It worked. I have another question. Actually last question. I need to edit font files to completely translating for my language. I guess .tex file entensions actually font files and they are in different places. I will send the some examples. Would you help me about this?
http://mm2kiwi.apan.is-a-geek.com/index.php?title=TEX
http://forum.mm2c.com/viewtopic.php?t=1 ... d9f080313c

This noesis script export fonts but maybe can't support import.
https://forum.xentax.com/viewtopic.php? ... ArjVXmCdHg


Personally no, like I said previously image formats aren't really my thing and I hate working with Glyphs and bitmap images. I feel for you I'm guessing you need to add cyrillic character glyphs? It's honestly why I stick to English translations for games because latin characters are always included.
ISKA
Posts: 223
Joined: Mon Apr 09, 2018 11:09 pm

Re: Midnight Club: Street Racing (Ps2) .strtbl

Post by ISKA »

LokiReborn wrote:
ISKA wrote:
ISKA wrote:Thanks buddy. I will try and let you know.


It worked. I have another question. Actually last question. I need to edit font files to completely translating for my language. I guess .tex file entensions actually font files and they are in different places. I will send the some examples. Would you help me about this?
http://mm2kiwi.apan.is-a-geek.com/index.php?title=TEX
http://forum.mm2c.com/viewtopic.php?t=1 ... d9f080313c

This noesis script export fonts but maybe can't support import.
https://forum.xentax.com/viewtopic.php? ... ArjVXmCdHg


Personally no, like I said previously image formats aren't really my thing and I hate working with Glyphs and bitmap images. I feel for you I'm guessing you need to add cyrillic character glyphs? It's honestly why I stick to English translations for games because latin characters are always included.

It's all right :)
ISKA
Posts: 223
Joined: Mon Apr 09, 2018 11:09 pm

Re: Midnight Club: Street Racing (Ps2) .strtbl

Post by ISKA »

LokiReborn wrote:
ISKA wrote:
ISKA wrote:Thanks buddy. I will try and let you know.


It worked. I have another question. Actually last question. I need to edit font files to completely translating for my language. I guess .tex file entensions actually font files and they are in different places. I will send the some examples. Would you help me about this?
http://mm2kiwi.apan.is-a-geek.com/index.php?title=TEX
http://forum.mm2c.com/viewtopic.php?t=1 ... d9f080313c

This noesis script export fonts but maybe can't support import.
https://forum.xentax.com/viewtopic.php? ... ArjVXmCdHg


Personally no, like I said previously image formats aren't really my thing and I hate working with Glyphs and bitmap images. I feel for you I'm guessing you need to add cyrillic character glyphs? It's honestly why I stick to English translations for games because latin characters are always included.


Hello again LokiReborn. Thanks for tool. I finished Midnight Club: Street Racing translation. I will planning to translate other midnigt clubs with release dates. If ı am not mistaken they used .strtbl files. in all midnight clubs. If I sent you to language files can you make a tool for these midnight club games.
LokiReborn
Posts: 190
Joined: Fri Aug 26, 2016 3:11 pm

Re: Midnight Club: Street Racing (Ps2) .strtbl

Post by LokiReborn »

ISKA wrote:
LokiReborn wrote:
ISKA wrote:
It worked. I have another question. Actually last question. I need to edit font files to completely translating for my language. I guess .tex file entensions actually font files and they are in different places. I will send the some examples. Would you help me about this?
http://mm2kiwi.apan.is-a-geek.com/index.php?title=TEX
http://forum.mm2c.com/viewtopic.php?t=1 ... d9f080313c

This noesis script export fonts but maybe can't support import.
https://forum.xentax.com/viewtopic.php? ... ArjVXmCdHg


Personally no, like I said previously image formats aren't really my thing and I hate working with Glyphs and bitmap images. I feel for you I'm guessing you need to add cyrillic character glyphs? It's honestly why I stick to English translations for games because latin characters are always included.


Hello again LokiReborn. Thanks for tool. I finished Midnight Club: Street Racing translation. I will planning to translate other midnigt clubs with release dates. If ı am not mistaken they used .strtbl files. in all midnight clubs. If I sent you to language files can you make a tool for these midnight club games.


Here ya go
ISKA
Posts: 223
Joined: Mon Apr 09, 2018 11:09 pm

Re: Midnight Club: Street Racing (Ps2) .strtbl

Post by ISKA »

LokiReborn wrote:
ISKA wrote:
LokiReborn wrote:
Personally no, like I said previously image formats aren't really my thing and I hate working with Glyphs and bitmap images. I feel for you I'm guessing you need to add cyrillic character glyphs? It's honestly why I stick to English translations for games because latin characters are always included.


Hello again LokiReborn. Thanks for tool. I finished Midnight Club: Street Racing translation. I will planning to translate other midnigt clubs with release dates. If ı am not mistaken they used .strtbl files. in all midnight clubs. If I sent you to language files can you make a tool for these midnight club games.


Here ya go

Hey, thanks buddy. You're a good friend. I'll never forget it.
Allen
Posts: 156
Joined: Tue Sep 01, 2015 9:44 am

Re: Midnight Club: Street Racing (Ps2) .strtbl

Post by Allen »

ISKA wrote:It worked. I have another question. Actually last question. I need to edit font files to completely translating for my language. I guess .tex file entensions actually font files and they are in different places. I will send the some examples. Would you help me about this?
http://mm2kiwi.apan.is-a-geek.com/index.php?title=TEX
http://forum.mm2c.com/viewtopic.php?t=1 ... d9f080313c

This noesis script export fonts but maybe can't support import.
https://forum.xentax.com/viewtopic.php? ... ArjVXmCdHg


After receiving your PM, I did some research. This is a font image conversion plugin. Edit the picture and open it with NOESIS. Right-click and select "EXPORT" and find the .tex format for export.

Save it as "tex_angelstudios_tex.py" and put it in the "plugins/pyton" folder in Noesis.

Code: Select all

# Midtown Madness / Midnight Club .TEX
# Font .tex Exporter: by Allen

# Tex Importer: by barti https://forum.xentax.com/viewtopic.php?t=12738&fbclid=IwAR3hmnYbavLryyVP9c53IGZPBHZXmhNHJs8jyGsdkabJOvtkBArjVXmCdHg#p105226
# Reference from http://mm2kiwi.apan.is-a-geek.com/index.php?title=TEX
# and http://forum.xentax.com/viewtopic.php?f=10&p=9670

from inc_noesis import *

import noesis
import rapi

def registerNoesisTypes():
   handle = noesis.register("Midtown Madness / Midnight Club", ".tex")
   noesis.setHandlerTypeCheck(handle, texCheckType)
   noesis.setHandlerLoadRGBA(handle, texLoadRGBA)
   noesis.setHandlerWriteRGBA(handle, texWriteRGBA)
   return 1

def texCheckType(data):
   return 1

def texLoadRGBA(data, texList):
   tex = AGETexture(NoeBitStream(data))
   texList.append(tex.parseTexture())
   return 1

class AGETexture:

   def __init__(self, reader):
      self.reader = reader

   def parseTexture(self):
      texWidth   = self.reader.readUShort()
      texHeight  = self.reader.readUShort()
      texType    = self.reader.readShort()
      texMips    = self.reader.readShort()
      texUnknown = self.reader.readShort()
      texFlag1   = self.reader.readUByte()
      texFlag2   = self.reader.readUByte()
      texFlag3   = self.reader.readUByte()
      texFlag4   = self.reader.readUByte()
            
      if texType == 1: # P8
         palMap = self.reader.readBytes(256*4)
         pixMap = self.reader.readBytes(texWidth * texHeight)
         pixData = rapi.imageDecodeRawPal(pixMap, palMap, texWidth, texHeight, 8, "b8g8r8p8")
      if texType == 14: # PA8
         palMap = self.reader.readBytes(256*4)
         pixMap = self.reader.readBytes(texWidth * texHeight)
         pixData = rapi.imageDecodeRawPal(pixMap, palMap, texWidth, texHeight, 8, "b8g8r8a8")
      if texType == 15: # P4_MC
         palMap = self.reader.readBytes(16*4)
         pixMap = self.reader.readBytes(int(texWidth * texHeight / 2))
         pixData = rapi.imageDecodeRawPal(pixMap, palMap, texWidth, texHeight, 4, "b8g8r8p8")
      if texType == 16: # PA4_MC
         palMap = self.reader.readBytes(16*4)
         pixMap = self.reader.readBytes(int(texWidth * texHeight / 2))
         pixData = rapi.imageDecodeRawPal(pixMap, palMap, texWidth, texHeight, 4, "b8g8r8a8")
      if texType == 17: # RGB888
         pixMap = self.reader.readBytes(texWidth * texHeight * 3)
         pixData = rapi.imageDecodeRaw(pixMap, texWidth, texHeight, "r8g8b8")
      if texType == 18: # RGBA8888
         pixMap = self.reader.readBytes(texWidth * texHeight * 4)
         pixData = rapi.imageDecodeRaw(pixMap, texWidth, texHeight, "r8g8b8a8")
      # Midnight Club 2 support (textype 26 not fully functional)
      if texType == 22: # DXT1
         pixMap = self.reader.readBytes(int(texWidth * texHeight * 4 / 8))
         pixData = rapi.imageDecodeDXT(pixMap, texWidth, texHeight, noesis.NOESISTEX_DXT1)
      if texType == 26: # DXT5
         pixMap = self.reader.readBytes(int(texWidth * texHeight * 4 / 4))
         pixData = rapi.imageDecodeDXT(pixMap, texWidth, texHeight, noesis.NOESISTEX_DXT5)
         
      #pixData = rapi.imageFlipRGBA32(pixData, texWidth, texHeight, 0, 1)
      return NoeTexture("tex", texWidth, texHeight, pixData, noesis.NOESISTEX_RGBA32)
   
def texWriteRGBA(data, width, height, bs):
        bs.writeShort(width)
        bs.writeShort(height)
        bs.writeShort(16)
        bs.writeShort(1)
        bs.writeShort(0)
        bs.writeByte(1)
        bs.writeByte(0)
        bs.writeByte(1)       
        bs.writeByte(0)       
        imgPix = rapi.imageResample(data, width, height, width, height)
        imgPal = rapi.imageGetPalette(imgPix, width, height, 16, 0, 1)
        idxPix = rapi.imageApplyPalette(imgPix, width, height, imgPal, 16)

        #bgra 32bpp palette
        for i in range(0,16):
                bs.writeUByte(imgPal[i*4+2])
                bs.writeUByte(imgPal[i*4+1])
                bs.writeUByte(imgPal[i*4+0])
                bs.writeUByte(imgPal[i*4+3])
        #4bpp indexed palette image       
        for i in range(width*height//2):
                idx2 = idxPix[i*2+0]
                idx1 = idxPix[i*2+1]
                idx = ((idx1 << 4) | idx2) & 0xff
                bs.writeUByte(idx)
        return 1
ISKA
Posts: 223
Joined: Mon Apr 09, 2018 11:09 pm

Re: Midnight Club: Street Racing (Ps2) .strtbl

Post by ISKA »

Allen wrote:
ISKA wrote:It worked. I have another question. Actually last question. I need to edit font files to completely translating for my language. I guess .tex file entensions actually font files and they are in different places. I will send the some examples. Would you help me about this?
http://mm2kiwi.apan.is-a-geek.com/index.php?title=TEX
http://forum.mm2c.com/viewtopic.php?t=1 ... d9f080313c

This noesis script export fonts but maybe can't support import.
https://forum.xentax.com/viewtopic.php? ... ArjVXmCdHg


After receiving your PM, I did some research. This is a font image conversion plugin. Edit the picture and open it with NOESIS. Right-click and select "EXPORT" and find the .tex format for export.

Save it as "tex_angelstudios_tex.py" and put it in the "plugins/pyton" folder in Noesis.

Code: Select all

# Midtown Madness / Midnight Club .TEX
# Font .tex Exporter: by Allen

# Tex Importer: by barti https://forum.xentax.com/viewtopic.php?t=12738&fbclid=IwAR3hmnYbavLryyVP9c53IGZPBHZXmhNHJs8jyGsdkabJOvtkBArjVXmCdHg#p105226
# Reference from http://mm2kiwi.apan.is-a-geek.com/index.php?title=TEX
# and http://forum.xentax.com/viewtopic.php?f=10&p=9670

from inc_noesis import *

import noesis
import rapi

def registerNoesisTypes():
   handle = noesis.register("Midtown Madness / Midnight Club", ".tex")
   noesis.setHandlerTypeCheck(handle, texCheckType)
   noesis.setHandlerLoadRGBA(handle, texLoadRGBA)
   noesis.setHandlerWriteRGBA(handle, texWriteRGBA)
   return 1

def texCheckType(data):
   return 1

def texLoadRGBA(data, texList):
   tex = AGETexture(NoeBitStream(data))
   texList.append(tex.parseTexture())
   return 1

class AGETexture:

   def __init__(self, reader):
      self.reader = reader

   def parseTexture(self):
      texWidth   = self.reader.readUShort()
      texHeight  = self.reader.readUShort()
      texType    = self.reader.readShort()
      texMips    = self.reader.readShort()
      texUnknown = self.reader.readShort()
      texFlag1   = self.reader.readUByte()
      texFlag2   = self.reader.readUByte()
      texFlag3   = self.reader.readUByte()
      texFlag4   = self.reader.readUByte()
            
      if texType == 1: # P8
         palMap = self.reader.readBytes(256*4)
         pixMap = self.reader.readBytes(texWidth * texHeight)
         pixData = rapi.imageDecodeRawPal(pixMap, palMap, texWidth, texHeight, 8, "b8g8r8p8")
      if texType == 14: # PA8
         palMap = self.reader.readBytes(256*4)
         pixMap = self.reader.readBytes(texWidth * texHeight)
         pixData = rapi.imageDecodeRawPal(pixMap, palMap, texWidth, texHeight, 8, "b8g8r8a8")
      if texType == 15: # P4_MC
         palMap = self.reader.readBytes(16*4)
         pixMap = self.reader.readBytes(int(texWidth * texHeight / 2))
         pixData = rapi.imageDecodeRawPal(pixMap, palMap, texWidth, texHeight, 4, "b8g8r8p8")
      if texType == 16: # PA4_MC
         palMap = self.reader.readBytes(16*4)
         pixMap = self.reader.readBytes(int(texWidth * texHeight / 2))
         pixData = rapi.imageDecodeRawPal(pixMap, palMap, texWidth, texHeight, 4, "b8g8r8a8")
      if texType == 17: # RGB888
         pixMap = self.reader.readBytes(texWidth * texHeight * 3)
         pixData = rapi.imageDecodeRaw(pixMap, texWidth, texHeight, "r8g8b8")
      if texType == 18: # RGBA8888
         pixMap = self.reader.readBytes(texWidth * texHeight * 4)
         pixData = rapi.imageDecodeRaw(pixMap, texWidth, texHeight, "r8g8b8a8")
      # Midnight Club 2 support (textype 26 not fully functional)
      if texType == 22: # DXT1
         pixMap = self.reader.readBytes(int(texWidth * texHeight * 4 / 8))
         pixData = rapi.imageDecodeDXT(pixMap, texWidth, texHeight, noesis.NOESISTEX_DXT1)
      if texType == 26: # DXT5
         pixMap = self.reader.readBytes(int(texWidth * texHeight * 4 / 4))
         pixData = rapi.imageDecodeDXT(pixMap, texWidth, texHeight, noesis.NOESISTEX_DXT5)
         
      #pixData = rapi.imageFlipRGBA32(pixData, texWidth, texHeight, 0, 1)
      return NoeTexture("tex", texWidth, texHeight, pixData, noesis.NOESISTEX_RGBA32)
   
def texWriteRGBA(data, width, height, bs):
        bs.writeShort(width)
        bs.writeShort(height)
        bs.writeShort(16)
        bs.writeShort(1)
        bs.writeShort(0)
        bs.writeByte(1)
        bs.writeByte(0)
        bs.writeByte(1)       
        bs.writeByte(0)       
        imgPix = rapi.imageResample(data, width, height, width, height)
        imgPal = rapi.imageGetPalette(imgPix, width, height, 16, 0, 1)
        idxPix = rapi.imageApplyPalette(imgPix, width, height, imgPal, 16)

        #bgra 32bpp palette
        for i in range(0,16):
                bs.writeUByte(imgPal[i*4+2])
                bs.writeUByte(imgPal[i*4+1])
                bs.writeUByte(imgPal[i*4+0])
                bs.writeUByte(imgPal[i*4+3])
        #4bpp indexed palette image       
        for i in range(width*height//2):
                idx2 = idxPix[i*2+0]
                idx1 = idxPix[i*2+1]
                idx = ((idx1 << 4) | idx2) & 0xff
                bs.writeUByte(idx)
        return 1


Thanks Allen. It's worked.