BOOL DecodeUCI(MEMORY_STREAM *pStream) { UCIInfo uci; PBYTE pbBuffer, pbRaw; Int32 Stride; Large_Integer NewSize; SBitMapHeader header; if ((*(PULONG)pStream->pbBuffer & 0xFFFFFF) != TAG3('UCI')) return False; if (UCIDecodeEx(pStream->lpBuffer, pStream->Size, &uci, False) < 0) return False; InitBitmapHeader(&header, uci.Width, uci.Height, uci.BitsPerPixel, &Stride); NewSize.QuadPart = header.dwFileSize; SetStreamSize(pStream, NewSize); pbBuffer = pStream->pbBuffer; *(SBitMapHeader *)pbBuffer = header; pbBuffer += sizeof(header); pbBuffer += (uci.Height - 1) * Stride; pbRaw = uci.pbBuffer; for (LONG h = 0; h != uci.Height; ++h) { CopyMemory(pbBuffer, pbRaw, uci.Stride); pbBuffer -= Stride; pbRaw += uci.Stride; } UCIFreeEx(&uci); return True; }
PByte CDECL DecodeImage(PByte pbImage, PUInt32 puWidth, PUInt32 puHeight, PUInt32 puBitPerPixel) { Int32 uWidth, uHeight, uBpp, uStride, uStrideRaw, Size; PByte pbDecode, pbDest, pbSrc; #if defined(USE_CACHE) Char szFullPath[MAX_PATH]; PChar name, fmt, path, dir; SCacheIndex *pCache; __asm { mov name, ebx; } #endif do { if ((*(PUInt32)pbImage & 0xFFFFFF) != TAG3('UCI')) break; #if defined(USE_CACHE) __asm { mov fmt, 0x45B6D8; mov path, 0x4EF150; mov eax, 0x46335C; mov eax, [eax]; mov dir, eax; } ++g_UCIReadCount; MYAPI(wsprintfA)(szFullPath, fmt, path, dir, name); pCache = g_ImageCache.Find(szFullPath); if (pCache->pbBuffer && !StrICompareA(pCache->FileName, szFullPath)) { ++g_CacheHitCount; pbImage = (PByte)MYAPI(GlobalAlloc)(GPTR, pCache->Size); if (pbImage == NULL) { goto DEFAULT_PROC; } CopyMemory(pbImage, pCache->pbBuffer, pCache->Size); if (puWidth != NULL) *puWidth = pCache->Width; if (puHeight != NULL) *puHeight = pCache->Height; if (puBitPerPixel != NULL) *puBitPerPixel = pCache->BitPerPixel; return pbImage; } #endif if (MYAPI(UCIDecode)(pbImage, INT_MAX, (LPVoid *)&pbDecode, &uStrideRaw, &uWidth, &uHeight, &uBpp) < 0) break; Size = uHeight * uWidth * 4; pbImage = (PByte)MYAPI(GlobalAlloc)(GPTR, Size); if (pbImage == NULL) { MYAPI(UCIFree)(pbDecode); break; } // uStride = (uWidth * uBpp / 8 + 3) & ~3; pbSrc = pbDecode; pbDest = pbImage; if (puWidth) *puWidth = uWidth; if (puHeight) *puHeight = uHeight; if (puBitPerPixel) *puBitPerPixel = uBpp; if (uBpp == 32) { ULONG Stride = uWidth * 4; for (ULONG Height = uHeight; Height; --Height) { CopyMemory(pbDest, pbSrc, Stride); pbDest += Stride; pbSrc += uStrideRaw; } } else { for (Int32 h = uHeight; h--; ) { PByte src = pbSrc; for (Int32 w = 0; w != uWidth; ++w) { *(PUInt32)pbDest = *(PUInt32)src | 0xFF000000; pbDest += 4; src += 3; } pbSrc += uStrideRaw; } } MYAPI(UCIFree)(pbDecode); #if defined(USE_CACHE) if (pCache->pbBuffer == NULL) ++g_CacheCount; g_ImageCache.Add(pCache, pbImage, Size, uWidth, uHeight, uBpp, szFullPath); #endif return pbImage; } while (0); DEFAULT_PROC: F_DecodeImage OldDecodeImage = (F_DecodeImage)0x42E120; return OldDecodeImage(pbImage, puWidth, puHeight, puBitPerPixel); }
int CDECL my_ov_open_callbacks(void *f, OggVorbis_File *vf, char *initial, long ibytes, ov_callbacks callbacks) { if ((Int32)vf->datasource >= 0) return MYAPI(ov_open_callbacks)(f, vf, initial, ibytes, callbacks); PByte pbBuffer; DWORD dwRead, dwSize; HANDLE hFile, hHeap; PUInt32 p; Large_Integer li; vorbis_info *vi; CAudioPlayback *ap; SFileInfo *info; const BASS_CHANNELINFO *ci; p = (PUInt32)f; info = (SFileInfo *)p[1]; hFile = info->hFile; hHeap = CMem::GetGlobalHeap(); dwSize = info->uSize; pbBuffer = (PByte)MYAPI(HeapAlloc)(hHeap, 0, dwSize); if (pbBuffer == NULL) return 0; do { ZeroMemory(&vf->seekable, sizeof(*vf) - sizeof(vf->datasource)); if (!MYAPI(ReadFile)(hFile, pbBuffer, dwSize, &dwRead, NULL) || dwRead != dwSize) break; if ((*(PUInt32)pbBuffer & 0xFFFFFF) == TAG3('UCA')) { SWaveHeader *h; if (MYAPI(UCADecode2)(pbBuffer, dwRead, &vf->datasource, (int *)&vf->end, 44100) < 0) break; vf->seekable = VOICE; h = (SWaveHeader *)vf->datasource; *(PInt32)&vf->datasource |= 0x80000000; *(PInt32)&vf->offset = sizeof(*h); vi = (vorbis_info *)&vf->current_serialno; vf->vi = vi; vi->channels = h->wChannels; vi->rate = h->dwSamplesPerSec; } else { ap = new CAudioPlayback; if (ap == NULL) break; li.QuadPart = dwSize; if (!ap->Open(pbBuffer, True, &li, True)) { delete ap; break; } vf->datasource = (LPVoid)((Int32)ap | 0x80000000); vi = (vorbis_info *)&vf->current_serialno; vf->vi = vi; ci = ap->GetChannelInfo(); vi->channels = ci->chans; vi->rate = ci->freq; } } while (0); MYAPI(HeapFree)(hHeap, 0, pbBuffer); return 0; }
Void PeekFile(LPWSTR lpFileName, FILE *fp) { FILE *fin; UInt32 len; Char c, *p, *p2, buf[0x1024]; fin = _wfopen(lpFileName, L"r"); if (!fin) return; while (fgets(buf, countof(buf), fin)) { len = strlen(buf) - 1; while (buf[len] == '\n' || buf[len] == '\r') buf[len] = 0; if (buf[0] == 0) continue; p = buf; while (*p == ' ' || *p == '\t') ++p; c = *p; if (c == ';') // comment continue; ++p; if (c == ':') // char name { p2 = strchr(p, ':'); if (p2 == NULL) continue; p = strchr(++p2, ':'); if (p == NULL || p == p2) // correct format :name:voice_name:AK continue; *p = 0; fprintf(fp, "voice.dat voice\\%s.ogg\n", p2); continue; } else if (c == '.') { UInt32 cnt, v = *(PUInt32)p & 0xDFDFDFDF; p2 = strchr(p, ' '); if (p2 == NULL || *++p2 == 0) continue; if (v == TAG4('CALL') || v == TAG4('HORO')) { fprintf(fp, "system.dat script\\%s.txt\n", p2); } for (cnt = 0; cnt != countof(internal); ++cnt) { len = strlen(internal[cnt]); if (!strncmp(p2, internal[cnt], len)) break; } if (cnt != countof(internal)) continue; p = strchr(p2, ' '); if (p) *p = 0; if (v == TAG4('SYST')) // .system { fprintf(fp, "system.dat system\\%s\n", p2); } else if ((v & 0xFFFFFF) == TAG3('IMG')) { PChar pdir, p3; v >>= 24; pdir = v == 0 ? "visual" : v == ('0' & 0xDF) ? "back" : "actor"; fprintf(fp, "image.dat image/%s\\%s.png\n", pdir, p2); continue; p = buf + strlen(buf) + 1; cnt = sprintf(p, "image.dat image/%s\\%s.png\n", pdir, p2); p3 = p; p = p + cnt - 7; c = *p++; if (c <= '9' && c >= '0' && (c = *p), c <= 'z' && c >= 'a') { *p = 'a' - 1; while (++*p != 'z' + 1) fprintf(fp, "%s", p3); } else { fprintf(fp, "%s", p3); } } else if ((v & 0xFFFFFF) == TAG3('BGM'))
// ====================================================================== #include "sharedObject/FirstSharedObject.h" #include "sharedObject/ArrangementDescriptor.h" #include "sharedFile/Iff.h" #include "sharedFoundation/CrcLowerString.h" #include "sharedObject/ArrangementDescriptorList.h" #include "sharedObject/SlotId.h" #include "sharedObject/SlotIdManager.h" #include <vector> // ====================================================================== const Tag TAG_ARG = TAG3(A,R,G); const Tag TAG_ARGD = TAG(A,R,G,D); // ====================================================================== ArrangementDescriptor::ArrangementDescriptor(Iff &iff, const CrcLowerString &name) : m_name(new CrcLowerString(name)), m_referenceCount(0), m_arrangements(new ArrangementVector()) { // load instance data from iff iff.enterForm(TAG_ARGD); // handle version loading const Tag version = iff.getCurrentName(); if (version == TAG_0000)
Bool CSharu::Open(PCWChar pszFileName) { ReleaseAll(); if (file.Open(pszFileName) == False) return False; Bool ret; UInt32 Version, Key; SPackHeader header; SPackHashTableHeader *pHashTable; static Char Seed[] = "8hr48uky,8ugi8ewra4g8d5vbf5hb5s6"; UNREFERENCED_PARAMETER(pHashTable); if (file.Seek(file.FILE_SEEK_END, -(Long)sizeof(header)) == False) return False; if (file.Read(&header, sizeof(header)) == False) return False; Version = *(PUInt32)&header.tag[11]; if (Version > TAG3('3.0') || Version < TAG3('1.0')) return False; header.tag[11] = 0; if (StrICompareA(header.tag, "FilePackVer")) return False; Key = Hash(header.Data, sizeof(header.Data)) & 0x0FFFFFFF; Decrypt(header.Seed, sizeof(header.Seed), Key); if (Version == TAG3('3.0') && memcmp(header.Seed, Seed, sizeof(header.Seed))) return False; // what the f**k is it #if 0 pHashTable = (SPackHashTableHeader *)Alloc(header.HashTableSize); if (pHashTable == NULL) return False; if (file.Seek(file.FILE_SEEK_END, -(Long)(sizeof(header) + header.HashTableSize)) == False) return False; if (file.Read(pHashTable, header.HashTableSize) == False) return False; Version = *(PUInt32)&pHashTable->HashVer[7]; do { ret = False; if (Version < TAG3('1.2') || Version > TAG3('1.3')) break; pHashTable->HashVer[7] = 0; if (lstrcmpiA(pHashTable->HashVer, "HashVer") || pHashTable->SubTableNum != 0x100) break; Decrypt(&pHashTable->Data, pHashTable->CompressedSize, 0x428); UInt32 DecompressSize; LPVoid lpDecrypted = Alloc(pHashTable->Data.DecompressSize); if (lpDecrypted == NULL) break; DecompressSize = Uncompress(&pHashTable->Data, pHashTable->CompressedSize, lpDecrypted); CFileDisk f; if (f.Open(L"K:\\galgame\\¥×¥ê¥ó¥»¥¹¥é¥Ð©`!\\GameData\\test.bin", f.W, f.N)) { f.Write(pHashTable, sizeof(*pHashTable) - sizeof(pHashTable->Data)); f.Write(lpDecrypted, DecompressSize); } Free(lpDecrypted); } while (0); Free(pHashTable); return False; #endif if (Version == TAG3('1.0')) Key = 0xC4; ret = InitIndex(&header, Key); return ret; }