BOOL DTileset::DCoreData::LoadCv5(STRCPTR cv5) { DAssert(cv5); HANDLE file = ::g_Archive.OpenFile(cv5); if (!file) return FALSE; DAssert(sizeof(CV5_TILE) == sizeof(CV5_DOODAD)); UINT size = ::g_Archive.GetFileSize(file); if (size <= CV5_TILE_GROUP_NUM * sizeof(CV5_TILE)) { ::g_Archive.CloseFile(file); return FALSE; } size -= CV5_TILE_GROUP_NUM * sizeof(CV5_TILE); if (size % sizeof(CV5_DOODAD)) { ::g_Archive.CloseFile(file); return FALSE; } UINT dd_num = size / sizeof(CV5_DOODAD); BOOL ret = LoadCv5(file, CV5_TILE_GROUP_NUM, dd_num); ::g_Archive.CloseFile(file); return ret; }
BOOL DTileset::Load(VOID) { DAssert(DBetween(m_Era, 0, L_ERA_NUM)); DString path(ERA_PATH[m_Era]); m_CcData = new DCoreData; if (!m_CcData->Load(path)) { m_CcData->Clear(); return FALSE; } m_NcData = new DCoreData; if (!m_NcData->Load(path + "-nc")) { delete m_NcData; m_NcData = NULL; if (!m_CcData->GenerateThumb()) return FALSE; } else { if (!m_NcData->GenerateThumb()) return FALSE; } HANDLE file = ::g_Archive.OpenFile(path + "\\dddata.bin"); if (!file) return FALSE; BOOL ret = FALSE; UINT size = ::g_Archive.GetFileSize(file); if (size == DOODAD_NUM_MAX * sizeof(DDDATA_BIN)) ret = LoadDddata(file, DOODAD_NUM_MAX); ::g_Archive.CloseFile(file); return ret; }
virtual bool hookHandleEvent(TwEventPort* sender , TwEvent* ev) { TW_UNUSED(sender); DAssert(sender == this); ev->accept(); return false; }
BOOL DChk::Analysis(HANDLE file, UINT size) { DAssert(file); UINT offset = 0U; UINT rd_size = sizeof(SECTIONHEADER); SECTIONHEADER header; SECTIONINFO info; while (::g_Archive.ReadFile(file, &header, rd_size) == rd_size) { offset += rd_size; info.size = header.size; info.offset = offset; offset += header.size; if (offset >= size) return TRUE; m_SectionTable[header.fourcc].push_back(info); if (::g_Archive.SeekFile(file, header.size, SM_CURRENT) == ERROR_POS) break; } return FALSE; }
BOOL DTileset::LoadDddata(HANDLE file, UINT ddnum) { DAssert(file && ddnum); DAssert(!m_Doodad); DDDATA_BIN *dddata = new DDDATA_BIN[ddnum]; UINT size = ddnum * sizeof(DDDATA_BIN); if (::g_Archive.ReadFile(file, dddata, size) != size) { delete [] dddata; return FALSE; } m_Doodad = dddata; return TRUE; }
int get_a_procedure( PCXT pCXT, char *szName ) { HSYM hSym; HMOD hMod; ADDR addr = {0}; HEXE hexe = (HEXE) NULL; SSTR sstr; BOOL fFound = FALSE; sstr.cb = (BYTE) strlen(szName); sstr.lpName = (PUCHAR) szName; sstr.searchmask = SSTR_NoHash; if( !pCXT || !szName || !(*szName) ) { return FALSE; } hMod = SHHMODFrompCXT(pCXT); if (!hMod) { // no symbols return FALSE; } hexe = SHHexeFromHmod(hMod); DAssert(hexe); if (!hexe) { return FALSE; } hSym = PHFindNameInPublics ( (HSYM) NULL, hexe, &sstr, TRUE, PHAtCmp); fFound = (hSym != NULL); if (!fFound) { return FALSE; } else { Dbg(SHAddrFromHsym( &addr, hSym)); emiAddr( addr ) = (HEMI)hexe; ADDR_IS_LI( addr ) = TRUE; // v-vadimp - on Merced we are getting plabel - read the actual procedure entry point address from it if(LppdCur->mptProcessorType == mptia64) { SYFixupAddr(&addr); DWORDLONG dwPLabel[2]; DWORD cb; OSDReadMemory(LppdCur->hpid, LptdCur->htid, &addr, &dwPLabel, sizeof(dwPLabel), &cb); GetAddrOff(addr) = dwPLabel[0]; SYUnFixupAddr(&addr); } return (SHSetCxt ( &addr, pCXT ) != NULL); } } /* get_a_procedure() */
void TwEventPort::installEventHook( TwEventPort* h) { auto it = std::find(m_eventHooks.begin(), m_eventHooks.end(), h); if (it != m_eventHooks.end()) { DAssert(false); return; } m_eventHooks.push_back(h); }
VOID DSmk::TransferPalette(INT type, BUFCPTR pal) { DAssert(type == SUPPORT_PALETTETYPE); CLRPTR color = m_Palette; for (INT i = 0; i < D_COLOR_NUM; i++, color++) { color->red = *pal++; color->green = *pal++; color->blue = *pal++; } }
VOID DScm::MakeMediumMinimap(CONST DTileset &ts, CONST SIZE &size) { DAssert(m_Tile); m_Minimap.SetSize(size); INT w = m_Minimap.GetWidth(); INT h = m_Minimap.GetHeight(); DTileset::MINI_THUMB thumb; LTILECPTR tile = m_Tile; BUFPTR data = m_Minimap.GetData(); DAssert(m_Minimap.GetPitch() == MINIMAP_DIM); for (INT i = 0; i < h; i++) { for (INT j = 0; j < w; j++, tile++) { DVerify(ts.GetThumb(*tile, thumb)); data[j] = thumb.thumb[0][0]; } data += MINIMAP_DIM; } }
BOOL DScm::ReadTile(VOID) { DAssert(!m_Tile); UINT size = m_Chk.GetSectionSize(FOURCC_MTXM, DChk::ST_OVERRIDE); if (size > DIM_HUGE * DIM_HUGE * sizeof(LTILEIDX)) return FALSE; UINT map_size = m_IsoMap.size.cx * m_IsoMap.size.cy; DAssert(map_size > 0); m_Tile = new LTILEIDX[map_size]; map_size *= sizeof(LTILEIDX); DMemClr(m_Tile, map_size); UINT rd_size = DMin(map_size, size); if (rd_size && !m_Chk.GetSectionData(FOURCC_MTXM, DChk::ST_OVERRIDE, m_Tile, rd_size)) return FALSE; return TRUE; }
BOOL DTileset::DCoreData::LoadWpe(STRCPTR wpe) { DAssert(wpe); HANDLE file = ::g_Archive.OpenFile(wpe); if (!file) return FALSE; UINT size = ::g_Archive.GetFileSize(file); if (size != D_COLOR_NUM * sizeof(WPE_COLOR)) { ::g_Archive.CloseFile(file); return FALSE; } DAssert(size == D_COLOR_NUM * sizeof(COLOR)); BOOL ret = FALSE; if (::g_Archive.ReadFile(file, m_Palette, size) == size) ret = TRUE; ::g_Archive.CloseFile(file); return ret; }
DWORD DScm::CalcVerifyHash(CONST VCODE *vcode, VCPTR vdata, UINT vdata_size) { DAssert(vcode && vdata && vdata_size); UINT op_num = DCount(vcode->op); DWORD hash = 0UL; BUFCPTR ptr = static_cast<BUFCPTR>(vdata); vdata_size >>= 2; for (UINT i = 0; i < vdata_size; i++, ptr += 4) { for (UINT j = 0; j < op_num; j++) { switch (vcode->op[j]) { case 0x00: hash ^= *reinterpret_cast<CONST DWORD *>(ptr); break; case 0x01: hash += *reinterpret_cast<CONST DWORD *>(ptr); break; case 0x02: hash -= *reinterpret_cast<CONST DWORD *>(ptr); break; case 0x03: case 0x04: case 0x05: hash ^= vcode->code[ptr[0]]; hash ^= vcode->code[ptr[1]]; hash ^= vcode->code[ptr[2]]; hash ^= vcode->code[ptr[3]]; break; case 0x06: hash = ROTATE_LEFT(hash, ptr[0]); hash = ROTATE_LEFT(hash, ptr[1]); hash = ROTATE_LEFT(hash, ptr[2]); hash = ROTATE_LEFT(hash, ptr[3]); break; case 0x07: hash = ROTATE_RIGHT(hash, ptr[0]); hash = ROTATE_RIGHT(hash, ptr[1]); hash = ROTATE_RIGHT(hash, ptr[2]); hash = ROTATE_RIGHT(hash, ptr[3]); break; default: break; } } } return hash; }
BOOL DTileset::DCoreData::LoadVx4(HANDLE file, UINT mega_num) { DAssert(file && mega_num); VX4_MEGATILE *vx4 = new VX4_MEGATILE[mega_num]; UINT size = mega_num * sizeof(VX4_MEGATILE); if (::g_Archive.ReadFile(file, vx4, size) != size) { delete [] vx4; return FALSE; } m_Vx4 = vx4; m_Vx4Num = mega_num; return TRUE; }
VOID DScm::MakeSmallMinimap(CONST DTileset &ts, CONST SIZE &size) { DAssert(m_Tile); m_Minimap.SetSize(size); DTileset::MINI_THUMB thumb; LTILECPTR tile = m_Tile; BUFPTR data = m_Minimap.GetData(); DAssert(m_Minimap.GetPitch() == MINIMAP_DIM); for (INT i = 0; i < m_IsoMap.size.cy; i++) { for (INT j = 0; j < m_IsoMap.size.cx; j++, tile++) { DVerify(ts.GetThumb(*tile, thumb)); BUFPTR p = data + j * 2; for (INT k = 0; k < 2; k++) { DMemCpy(p, thumb.thumb[k], 2 * sizeof(BYTE)); p += MINIMAP_DIM; } continue; } data += MINIMAP_DIM * 2; } }
BOOL DTileset::DCoreData::LoadCv5Dd(HANDLE file, UINT dd_num) { DAssert(file); if (!dd_num) { m_Cv5DdNum = 0U; return TRUE; } CV5_DOODAD *cv5_dd = new CV5_DOODAD[dd_num]; UINT size = dd_num * sizeof(CV5_DOODAD); if (::g_Archive.ReadFile(file, cv5_dd, size) != size) { delete [] cv5_dd; return FALSE; } m_Cv5Doodad = cv5_dd; m_Cv5DdNum = dd_num; return TRUE; }
BOOL DTileset::DCoreData::LoadCv5(HANDLE file, UINT tile_num, UINT dd_num) { DAssert(file && tile_num); CV5_TILE *cv5_tile = new CV5_TILE[tile_num]; UINT size = tile_num * sizeof(CV5_TILE); if (::g_Archive.ReadFile(file, cv5_tile, size) != size) { delete [] cv5_tile; return FALSE; } if (!LoadCv5Dd(file, dd_num)) { delete [] cv5_tile; return FALSE; } m_Cv5Tile = cv5_tile; m_Cv5TileNum = tile_num; return TRUE; }
BOOL DTileset::DCoreData::LoadVr4(STRCPTR vr4) { DAssert(vr4); HANDLE file = ::g_Archive.OpenFile(vr4); if (!file) return FALSE; UINT size = ::g_Archive.GetFileSize(file); if (!size || size % sizeof(VR4_MINITILE)) { ::g_Archive.CloseFile(file); return FALSE; } m_Vr4Num = size / sizeof(VR4_MINITILE); if (m_Vr4Num > MINITILE_MAX_NUM) return FALSE; m_Vr4File = file; return TRUE; }
BOOL DScm::Create(CONST DTileset &ts, INT def, CONST SIZE &size) { if (m_Valid) return FALSE; DAssert(!m_IsoMap.isom && !m_Minimap.IsValid() && !m_Tile); if (!DBetween(ts.GetEra(), 0, L_ERA_NUM)) return FALSE; if (size.cx <= 0 || size.cx > DIM_MAX || size.cy <= 0 || size.cy > DIM_MAX) return FALSE; m_IsoMap.era = ts.GetEra(); m_IsoMap.def = def; m_IsoMap.size = size; if (!create_iso_map(&m_IsoMap, TRUE)) { Clear(); return FALSE; } // TODO: 随机TILE #if 1 m_Tile = new LTILEIDX[size.cx * size.cy]; DMemCpy(m_Tile, m_IsoMap.tile, size.cx * size.cy * sizeof(LTILEIDX)); #endif if (!MakeMinimap(ts)) { Clear(); return FALSE; } m_Valid = TRUE; m_Edit = TRUE; m_Version = 0x3f; return TRUE; }
BOOL DScm::ReadIsoMap(VOID) { DAssert(!m_IsoMap.isom && !m_IsoMap.tile); if (!create_iso_map(&m_IsoMap, FALSE)) return FALSE; UINT tile_size = m_Chk.GetSectionSize(FOURCC_TILE, DChk::ST_OVERRIDE); if (tile_size) { UINT full_size = m_IsoMap.size.cx * m_IsoMap.size.cy * sizeof(LTILEIDX); UINT copy_size = DMin(tile_size, full_size); if (!m_Chk.GetSectionData(FOURCC_TILE, DChk::ST_OVERRIDE, m_IsoMap.tile, copy_size)) return FALSE; } UINT isom_size = m_Chk.GetSectionSize(FOURCC_ISOM, DChk::ST_OVERRIDE); if (isom_size) { UINT full_size = CALC_ISOM_ROW(m_IsoMap.size.cx) * CALC_ISOM_LINE(m_IsoMap.size.cy) * sizeof(LISOMTILE); UINT copy_size = DMin(isom_size, full_size); if (!m_Chk.GetSectionData(FOURCC_ISOM, DChk::ST_OVERRIDE, m_IsoMap.isom, copy_size)) return FALSE; } UINT dd2_size = m_Chk.GetSectionSize(FOURCC_DD2, DChk::ST_DUPLICATE); UINT dd_num = dd2_size / sizeof(DD2_DATA); if (dd_num) { DD2_DATA *dd2 = new DD2_DATA[dd_num]; if (!m_Chk.GetSectionData(FOURCC_DD2, DChk::ST_DUPLICATE, dd2, dd_num * sizeof(DD2_DATA))) return FALSE; // TODO: delete [] dd2; } // TODO: recover TILE and ISOM return TRUE; }
BOOL DTileset::DCoreData::LoadVx4(STRCPTR vx4) { DAssert(vx4); HANDLE file = ::g_Archive.OpenFile(vx4); if (!file) return FALSE; UINT size = ::g_Archive.GetFileSize(file); if (!size || size % sizeof(VX4_MEGATILE)) { ::g_Archive.CloseFile(file); return FALSE; } UINT mega_num = size / sizeof(VX4_MEGATILE); if (mega_num > MEGATILE_MAX_NUM) { ::g_Archive.CloseFile(file); return FALSE; } BOOL ret = LoadVx4(file, mega_num); ::g_Archive.CloseFile(file); return ret; }
DPalette &DPalette::operator = (CONST DPalette &pal) { DAssert(m_Palette && pal.m_Palette); DMemCpy(m_Palette, pal.m_Palette, D_COLOR_NUM * sizeof(COLOR)); return *this; }
BOOL NEAR LocateFunction( PSTR szStr, PADDR pAddr ) { TML TMLT; TML TMLT2; DWORD bpsegtype = EECODE; DWORD stringindex; PHTM TMList; PHTM pTMList; PHTM pTMList2; int i; EESTATUS eeErr; PSTR p; PSTR Function; PSTR Module = NULL; char Buffer[ 256 ]; BOOL Ok = FALSE; BOOL Found = FALSE; HEXE hexe = (HEXE) NULL; PSTR Str; FuncList = NULL; FuncListSize = 0; eeErr = EEParseBP(szStr, radix, fCaseSensitive, &CxfIp, &TMLT, 0, &stringindex, FALSE); if (eeErr == EEGENERAL) { /* * Kill current error message */ EEFreeTML(&TMLT); // // If no module was specified, try all modules. // strcpy( Buffer, szStr ); if ( p = (PSTR) strchr( (LPCSTR) Buffer, ',' ) ) { if ( p = (PSTR) strpbrk( (PUCHAR) p+1, (PUCHAR) ",}" ) ) { if ( *p == '}' ) { *p++ = ','; *p = '\0'; Ok = TRUE; } else { if (!IsDBCSLeadByte(*p)) { p++; while ( *p == ' ' || *p == '\t' ) { p++; } if ( *p == '}' ) { *p = '\0'; Ok = TRUE; } } } if ( Ok ) { Function = szStr + (p - Buffer); Module = p; } } } else { strcpy( Buffer, "{,," ); Module = Buffer + strlen( Buffer ); Function = szStr; Ok = TRUE; } if ( Ok ) { Str = NULL; TMLT.hTMList = (HDEP) NULL; pTMList = NULL; while ((( hexe = SHGetNextExe( hexe ) ) != 0) ) { *Module = '\0'; strcat( Buffer, SHGetExeName(hexe)); strcat( Buffer, "}" ); strcat( Buffer, Function ); eeErr = EEParseBP(Buffer, radix, fCaseSensitive, &CxfIp, &TMLT2, 0, &stringindex, FALSE); if ( eeErr == EENOERROR ) { if ( !pTMList ) { TMLT = TMLT2; pTMList = (HTM FAR *) MMLpvLockMb( TMLT.hTMList ); } else { pTMList2 = (HTM FAR *) MMLpvLockMb( TMLT2.hTMList ); for (i=0; i< (int) TMLT2.cTMListAct; i++) { DAssert( TMLT2.cTMListAct < TMLT.cTMListMax ); pTMList[ TMLT.cTMListAct++ ] = pTMList2[ i ]; pTMList2[i] = (HDEP) NULL; } MMbUnlockMb( TMLT2.hTMList ); TMLT2.cTMListAct = 0; EEFreeTML(&TMLT2); } } } if (pTMList) { MMbUnlockMb( TMLT.hTMList ); eeErr = EENOERROR; } else { eeErr = EEGENERAL; } } } if (eeErr == EENOERROR) { TMList = (PHTM) MMLpvLockMb( TMLT.hTMList ); while (TMLT.cTMListAct > 1) { eeErr = (EESTATUS) BPTResolve( szStr, &TMLT, &CxfIp, FALSE); if (eeErr != EENOERROR) { break; } if (TMLT.cTMListAct > 1) { ErrorBox(0); } } if (TMLT.cTMListAct == 1) { if (!(eeErr = EEvaluateTM( &TMList[0], SHhFrameFrompCXF(&CxfIp), EEBPADDRESS))) { eeErr = BPADDRFromTM( &TMList[0], &bpsegtype, pAddr); } } } return eeErr == EENOERROR; } /* LocateFunction() */
BOOL GetLocalAtContext ( PTRVIT pvit, PCXF pcxf ) { VIB vibT; PTRVIB pvibCur; int RetStatus = FALSE; // Default is context hasn't changed EESTATUS RetErr; CXF cxf; HMEM hsyml = 0; ULONG strIndex; // If no Vit, we can't do anything (and the context has changed!) if ( !pvit ) { return(FALSE); } // If no Offset or Segment, same treatment if ((GetAddrOff (*SHpADDRFrompCXT (SHpCXTFrompCXF (pcxf))) == 0) && (GetAddrOff (*SHpADDRFrompCXT (SHpCXTFrompCXF (pcxf))) == 0)) { return(FALSE); } // copy context and frame and check to see if the context can // handle locals. cxf = *pcxf; if (!ADDR_IS_LI (*SHpADDRFrompCXT (SHpCXTFrompCXF (&cxf)))) SYUnFixupAddr (SHpADDRFrompCXT (SHpCXTFrompCXF (&cxf))); // // If we don't have a context (no proc or no module) or we are // still in the prolog -- we don't display anything // if (!( cxf.cxt.hProc && cxf.cxt.hMod) || SHIsInProlog(SHpCXTFrompCXF(&cxf))) { pvit->cxf.cxt.hMod = 0; pvit->cxf.cxt.hGrp = 0; pvit->cxf.cxt.hProc = 0; pvit->cxf.cxt.hBlk = 0; pvit->cln = 0; FTFreeAllSib( pvit->pvibChild ); pvit->pvibChild = NULL; return(TRUE); } if ( (pvit->cxf.cxt.hBlk == cxf.cxt.hBlk) && (pvit->cxf.cxt.hProc == cxf.cxt.hProc)) { SHhFrameFrompCXF(&pvit->cxf) = SHhFrameFrompCXF(&cxf); return(FALSE); } // Release the Locals tree FTFreeAllSib( pvit->pvibChild ); pvit->pvibChild = NULL; RetStatus = TRUE; // fill in the Variable Info block Top and clear line count pvit->cxf = cxf; pvit->cln = 0; // make a dummy Variable Info Block to start the search pvibCur = &vibT; pvibCur->pvibSib = pvit->pvibChild; // make the linked list EEGetHSYMList ( &hsyml, &cxf.cxt, HSYMR_lexical + HSYMR_function, NULL, TRUE ); if ( hsyml != (HMEM) NULL ) { PHSL_HEAD lphsymhead; PHSL_LIST lphsyml; WORD i = 0; WORD j = 0; // get the syms lphsymhead = (PHSL_HEAD) MMLpvLockMb ( hsyml ); lphsyml = (PHSL_LIST)(lphsymhead + 1); for ( i = 0; i != lphsymhead->blockcnt; i++ ) { for ( j = 0; j != lphsyml->symbolcnt; j++ ) { // is this a displayable sym? if ( SHCanDisplay ( lphsyml->hSym[j] ) ) { HSYM hSym = lphsyml->hSym[j]; // get the new Variable Info Block. To maintain the tree, the old // Variable Info Block is returned if it exists. if ( !( pvibCur->pvibSib = FTvibGet ( pvibCur->pvibSib, (PTRVIB) pvit) ) ) { goto nomoresyms; } // check to see if this Variable Info Block is an old vib that // isn't correct anymore. We know offset is enough of a check // because we checked the module above. If it is clear the vib chain. if( pvibCur->pvibSib->vibPtr != vibUndefined && pvibCur->pvibSib->hSym != hSym ) { FTvibInit(pvibCur->pvibSib, (PTRVIB) pvit); } // if we have a new tree, we must assign stuff if ( pvibCur->pvibSib->vibPtr == vibUndefined ) { DAssert (hSym != 0); RetErr = EEGetTMFromHSYM(hSym,&pcxf->cxt,&pvibCur->pvibSib->hTMBd, &strIndex, TRUE, TRUE); if ( RetErr != EENOERROR && RetErr != EECATASTROPHIC ) { pvibCur->pvibSib = NULL; goto nextsym; } // assign this stuff only once pvibCur->pvibSib->hSym = hSym; pvibCur->pvibSib->vibPtr = vibSymbol; } // update the parent's (Variable Info block Top) number count // the vit is alway initialized to zero pvibCur = pvibCur->pvibSib; pvibCur->pvibParent->cln += pvibCur->cln; nextsym: ; // must have a statement after a label } } lphsyml = (PHSL_LIST) &(lphsyml->hSym[j]); } nomoresyms: MMbUnlockMb ( hsyml ); } EEFreeHSYMList ( &hsyml ); // free any extra Variable Info Blocks FTFreeAllSib ( pvibCur->pvibSib ); pvibCur->pvibSib = NULL; // load in the child pointer from the dummy vit pvit->pvibChild = vibT.pvibSib; return(RetStatus); } /* GetLocalAtContext() */
DPalette::DPalette(CONST DPalette &pal) { DAssert(FALSE); }
DPalette &DPalette::operator = (PALCPTR pal) { DAssert(m_Palette && pal); DMemCpy(m_Palette, pal, D_COLOR_NUM * sizeof(COLOR)); return *this; }
VOID DPalette::SetColor(INT entry, COLOR color) { DAssert(m_Palette); DAssert(DBetween(entry, 0, D_COLOR_NUM)); m_Palette[entry] = color; }