/* 文字列置換(日本語考慮版) */ void CNativeA::Replace_j( const char* pszFrom, const char* pszTo ) { CNativeA cmemWork; int nFromLen = strlen( pszFrom ); int nToLen = strlen( pszTo ); int nBgnOld = 0; int nBgn = 0; while( nBgn <= GetStringLength() - nFromLen ){ if( 0 == memcmp( &GetStringPtr()[nBgn], pszFrom, nFromLen ) ){ if( 0 < nBgn - nBgnOld ){ cmemWork.AppendString( &GetStringPtr()[nBgnOld], nBgn - nBgnOld ); } cmemWork.AppendString( pszTo, nToLen ); nBgn = nBgn + nFromLen; nBgnOld = nBgn; }else{ if( _IS_SJIS_1( (unsigned char)GetStringPtr()[nBgn] ) ) nBgn++; nBgn++; } } if( 0 < GetStringLength() - nBgnOld ){ cmemWork.AppendString( &GetStringPtr()[nBgnOld], GetStringLength() - nBgnOld ); } SetNativeData( cmemWork ); return; }
void CNativeW::Replace( const wchar_t* pszFrom, int nFromLen, const wchar_t* pszTo, int nToLen ) { CNativeW cmemWork; int nBgnOld = 0; int nBgn = 0; while( nBgn <= GetStringLength() - nFromLen ){ if( 0 == wmemcmp( &GetStringPtr()[nBgn], pszFrom, nFromLen ) ){ if( nBgnOld == 0 && nFromLen <= nToLen ){ cmemWork.AllocStringBuffer( GetStringLength() ); } if( 0 < nBgn - nBgnOld ){ cmemWork.AppendString( &GetStringPtr()[nBgnOld], nBgn - nBgnOld ); } cmemWork.AppendString( pszTo, nToLen ); nBgn = nBgn + nFromLen; nBgnOld = nBgn; }else{ nBgn++; } } if( nBgnOld != 0 ){ if( 0 < GetStringLength() - nBgnOld ){ cmemWork.AppendString( &GetStringPtr()[nBgnOld], GetStringLength() - nBgnOld ); } SetNativeData( cmemWork ); }else{ if( this->GetStringPtr() == NULL ){ this->SetString(L""); } } }
static void StringCat(Interpreter *i) { VMHANDLE hStr2 = PopH(i); VMHANDLE hStr1 = *i->hsp; uint8_t *str1, *str2, *str; size_t len1, len2; /* get the first string pointer and length */ str1 = GetStringPtr(hStr1); len1 = GetHeapObjSize(hStr1); /* get the second string pointer and length */ str2 = GetStringPtr(hStr2); len2 = GetHeapObjSize(hStr2); /* allocate the result string */ if (!(*i->hsp = NewString(i->heap, len1 + len2))) Abort(i->sys, "insufficient memory"); str = GetStringPtr(*i->hsp); /* copy the source strings into the result string */ memcpy(str, str1, len1); memcpy(str + len1, str2, len2); /* release the two argument strings */ ObjRelease(i->heap, hStr1); ObjRelease(i->heap, hStr2); }
// 任意位置の文字取得。nIndexは文字単位。 char CNativeA::operator[](int nIndex) const { if( nIndex < GetStringLength() ){ return GetStringPtr()[nIndex]; }else{ return 0; } }
bool CSeqTableColumnInfo::GetString(size_t row, string& v, bool force) const { const string* ptr = GetStringPtr(row, force); if ( !ptr ) { return false; } v = *ptr; return true; }
inline CRunLayer* GetLayerParam(VRuntime* pRuntime, CRunLayout* pLayout) const { switch (eType) { case EXPTYPE_INTEGER: case EXPTYPE_FLOAT: return pRuntime->GetLayer(pLayout, GetInt() - 1); case EXPTYPE_STRING: return pRuntime->GetLayer(pLayout, *GetStringPtr()); } return NULL; }
/** * Get a C-string from a stringid set by a newgrf. */ const char *GetGRFStringPtr(uint16 stringid) { assert(_grf_text[stringid].grfid != 0); /* Remember this grfid in case the string has included text */ _last_grfid = _grf_text[stringid].grfid; const char *str = GetGRFStringFromGRFText(_grf_text[stringid].textholder); if (str != NULL) return str; /* Use the default string ID if the fallback string isn't available */ return GetStringPtr(_grf_text[stringid].def_string); }
/* 大文字 */ void CNativeA::ToUpper() { unsigned char* pBuf = (unsigned char*)GetStringPtr(); int nBufLen = GetStringLength(); int i; int nCharChars; unsigned char uc; for( i = 0; i < nBufLen; ++i ){ // 2005-09-02 D.S.Koba GetSizeOfChar nCharChars = CShiftJis::GetSizeOfChar( (const char *)pBuf, nBufLen, i ); if( nCharChars == 1 ){ uc = (unsigned char)toupper( pBuf[i] ); pBuf[i] = uc; } else if( nCharChars == 2 ){ /* 全角英小文字→全角英大文字 */ if( pBuf[i] == 0x82 && pBuf[i + 1] >= 0x81 && pBuf[i + 1] <= 0x9a ){ pBuf[i] = pBuf[i]; pBuf[i + 1] = pBuf[i + 1] - 0x21; //@@@ 2001.02.03 Start by MIK: ギリシャ文字変換 //大文字:0x839f〜0x83b6 //小文字:0x83bf〜0x83d6 }else if( pBuf[i] == 0x83 && pBuf[i + 1] >= 0xbf && pBuf[i + 1] <= 0xd6 ){ pBuf[i] = pBuf[i]; pBuf[i + 1] = pBuf[i + 1] - 0x20; //@@@ 2001.02.03 End //@@@ 2001.02.03 Start by MIK: ロシア文字変換 //大文字:0x8440〜0x8460 //小文字:0x8470〜0x8491 0x847fがない! }else if( pBuf[i] == 0x84 && pBuf[i + 1] >= 0x70 && pBuf[i + 1] <= 0x91 && pBuf[i + 1] != 0x7f ){ pBuf[i] = pBuf[i]; if( pBuf[i + 1] >= 0x7f ){ pBuf[i + 1] = pBuf[i + 1] - 0x31; }else{ pBuf[i + 1] = pBuf[i + 1] - 0x30; } //@@@ 2001.02.03 End } } if( nCharChars > 0 ){ i += nCharChars - 1; } } return; }
inline int GetVariableIndex(VRuntime* pRuntime, CRunObjType* pType) const { switch (eType) { case EXPTYPE_VARIABLENAME: // Indices match: OK, same object if (pType == eData.vni.pOwnerType) { return eData.vni.varIndex; } else { return pRuntime->TranslatePrivateVariableIndex(pType, eData.vni.pOwnerType, eData.vni.varIndex); } case EXPTYPE_STRING: return pRuntime->GetPVIndexFromName(*GetStringPtr(), pType); //return find_index(pType->privateVars.begin(), pType->privateVars.end(), *GetStringPtr()); case EXPTYPE_INTEGER: return GetInt(); default: return -1; //It will cause a crash if this index is accessed. } }
void InstanceScriptPlayer::RunImplementationCommands(int opcode) { ScriptCore::OpData *instr = &def->instr[curInst]; switch(opcode) { case OP_DESPAWN_ALL: { while(true) { CreatureInstance *source = actInst->GetNPCInstanceByCDefID(GetVarValue(instr->param1)); if(source == NULL) break; else { g_Log.AddMessageFormat("Despawn: %d (%d)", GetVarValue(instr->param1), source->CreatureID); actInst->spawnsys.Despawn(source->CreatureID); } } break; } case OP_DESPAWN: { CreatureInstance *source = actInst->GetInstanceByCID(GetVarValue(instr->param1)); g_Log.AddMessageFormat("Despawn: %d (%d)", GetVarValue(instr->param1), source->CreatureDefID); if(source == NULL) g_Log.AddMessageFormat("Despawn failed, %d does not exist.", GetVarValue(instr->param1)); else actInst->spawnsys.Despawn(GetVarValue(instr->param1)); break; } case OP_SPAWN: actInst->spawnsys.TriggerSpawn(instr->param1, 0, 0); //g_Log.AddMessageFormat("Fired spawn: %d", def->instr[curInst].param1); break; case OP_SPAWNAT: actInst->spawnsys.TriggerSpawn(instr->param1, instr->param2, 0); //g_Log.AddMessageFormat("Fired spawn: %d, creature: %d", def->instr[curInst].param1, def->instr[curInst].param2); break; case OP_SPAWNFLAG: actInst->spawnsys.TriggerSpawn(instr->param1, instr->param2, instr->param3); //g_Log.AddMessageFormat("Fired spawn: %d, creature: %d", def->instr[curInst].param1, def->instr[curInst].param2); break; case OP_SPAWNLOC: { //Pop in reverse order int x = PopVarStack(); int y = PopVarStack(); int z = PopVarStack(); if(x != 0 && y != 0 && z != 0) actInst->SpawnGeneric(instr->param1, x, y, z, 0); } break; case OP_COUNTALIVE: vars[instr->param2] = actInst->CountAlive(instr->param1); break; case OP_GETNPCID: { int creatureID = 0; CreatureInstance *search = actInst->GetNPCInstanceByCDefID(instr->param1); if(search != NULL) creatureID = search->CreatureID; vars[instr->param2] = creatureID; } break; case OP_SETTARGET: { CreatureInstance *source = actInst->GetInstanceByCID(GetVarValue(instr->param1)); CreatureInstance *target = actInst->GetInstanceByCID(GetVarValue(instr->param2)); if(source != NULL && target != NULL) source->SelectTarget(target); } break; case OP_SCAN_NPC_CID: { InstanceLocation *loc = GetLocationByName(GetStringPtr(instr->param1)); int index = VerifyIntArrayIndex(instr->param2); if(index >= 0) ScanNPCCID(loc, intArray[index].arrayData); } break; case OP_SCAN_NPC_CID_FOR: { InstanceLocation *loc = GetLocationByName(GetStringPtr(instr->param1)); int index = VerifyIntArrayIndex(instr->param2); if(index >= 0) ScanNPCCIDFor(loc, instr->param3, intArray[index].arrayData); } break; case OP_GET_CDEF: { int cdef = 0; CreatureInstance *ci = GetNPCPtr(GetVarValue(instr->param1)); if(ci) cdef = ci->CreatureDefID; SetVar(instr->param2, cdef); } break; case OP_GET_HEALTH_PERCENT: { CreatureInstance *ci = GetNPCPtr(GetVarValue(instr->param1)); int health = 0; if(ci) health = static_cast<int>(ci->GetHealthRatio() * 100.0F); SetVar(instr->param2, health); } break; case OP_ORDER_WALK: { CreatureInstance *ci = GetNPCPtr(GetVarValue(instr->param1)); if(ci) { ci->SetServerFlag(ServerFlags::ScriptMovement, true); ci->previousPathNode = 0; //Disable any path links. ci->nextPathNode = 0; ci->tetherNodeX = instr->param2; ci->tetherNodeZ = instr->param3; ci->CurrentTarget.DesLocX = instr->param2; ci->CurrentTarget.DesLocZ = instr->param3; ci->CurrentTarget.desiredRange = 30; ci->Speed = 20; } } break; case OP_GET_TARGET: { int targetID = 0; CreatureInstance *ci = GetNPCPtr(GetVarValue(instr->param1)); if(ci) { if(ci->CurrentTarget.targ != NULL) targetID = ci->CurrentTarget.targ->CreatureID; } SetVar(instr->param2, targetID); } break; case OP_AI_SCRIPT_JUMP: { CreatureInstance *ci = GetNPCPtr(GetVarValue(instr->param1)); if(ci) { if(ci->aiScript) ci->aiScript->JumpToLabel(GetStringPtr(instr->param2)); } } break; case OP_INFO: { char buffer[4096]; int wpos = PrepExt_SendInfoMessage(buffer, GetStringPtr(instr->param1), INFOMSG_INFO); actInst->LSendToAllSimulator(buffer, wpos, -1); } break; case OP_CHAT: { char buffer[4096]; int wpos = PrepExt_GenericChatMessage(buffer, 0, GetStringPtr(instr->param1), GetStringPtr(instr->param2), GetStringPtr(instr->param3)); actInst->LSendToAllSimulator(buffer, wpos, -1); } break; case OP_BROADCAST: { char buffer[4096]; if(actInst->mZoneDefPtr->mGrove) { int wpos = PrepExt_SendInfoMessage(buffer, GetStringPtr(instr->param1), INFOMSG_INFO); actInst->LSendToAllSimulator(buffer, wpos, -1); } else { int wpos = PrepExt_Broadcast(buffer, GetStringPtr(instr->param1)); actInst->LSendToAllSimulator(buffer, wpos, -1); } } break; default: g_Log.AddMessageFormat("Unidentified InstanceScriptPlayer OpCode: %d", instr->opCode); break; } }
static void EvaluateField(const save_field_t *pField, byte *pbBase, byte *pbOriginalRefData/* may be NULL*/) { void *pv = (void *)(pbBase + pField->iOffset); void *pvOriginal = (void *)(pbOriginalRefData + pField->iOffset); switch (pField->eFieldType) { case F_STRING: *(char **)pv = GetStringPtr(*(int *)pv, pbOriginalRefData?*(char**)pvOriginal:NULL); break; case F_GENTITY: *(gentity_t **)pv = GetGEntityPtr(*(int *)pv); break; case F_GROUP: *(AIGroupInfo_t **)pv = GetGroupPtr(*(int *)pv); break; case F_GCLIENT: *(gclient_t **)pv = GetGClientPtr(*(int *)pv); break; case F_ITEM: *(gitem_t **)pv = GetGItemPtr(*(int *)pv); break; case F_VEHINFO: *(vehicleInfo_t **)pv = GetVehicleInfoPtr(*(int *)pv); break; case F_BEHAVIORSET: { char **p = (char **) pv; char **pO= (char **) pvOriginal; for (int i=0; i<NUM_BSETS; i++, p++, pO++) { *p = GetStringPtr(*(int *)p, pbOriginalRefData?*(char **)pO:NULL); } } break; /*MCG case F_BODYQUEUE: { gentity_t **p = (gentity_t **) pv; for (int i=0; i<BODY_QUEUE_SIZE; i++, p++) { *p = GetGEntityPtr(*(int *)p); } } break; */ case F_ALERTEVENT: { alertEvent_t* p = (alertEvent_t *) pv; for (int i=0; i<MAX_ALERT_EVENTS; i++) { p[i].owner = GetGEntityPtr((intptr_t)(p[i].owner)); } } break; case F_AIGROUPS: // convert to ptrs within this into indexes... { AIGroupInfo_t* p = (AIGroupInfo_t *) pv; for (int i=0; i<MAX_FRAME_GROUPS; i++) { p[i].enemy = GetGEntityPtr((intptr_t)(p[i].enemy)); p[i].commander = GetGEntityPtr((intptr_t)(p[i].commander)); } } break; case F_ANIMFILESETS: { animFileSet_t* p = (animFileSet_t *) pv; char *pO; for (int i=0; i<MAX_ANIM_FILES; i++) { for ( int j=0; j<MAX_ANIM_EVENTS; j++ ) { pO = pbOriginalRefData ? level.knownAnimFileSets[i].torsoAnimEvents[j].stringData : NULL; p[i].torsoAnimEvents[j].stringData = GetStringPtr((intptr_t)p[i].torsoAnimEvents[j].stringData, pO); pO = pbOriginalRefData ? level.knownAnimFileSets[i].legsAnimEvents[j].stringData : NULL; p[i].legsAnimEvents[j].stringData = GetStringPtr((intptr_t)p[i].legsAnimEvents[j].stringData, pO); } } } break; // // These fields are patched in when their relevant owners are loaded case F_BOOLPTR: case F_NULL: break; case F_IGNORE: break; default: G_Error ("EvaluateField: unknown field type"); break; } }
/* 半角→全角 */ void CNativeA::ToZenkaku( int bHiragana, /* 1== ひらがな 0==カタカナ //2==英数専用 2001/07/30 Misaka 追加 */ int bHanKataOnly /* 1== 半角カタカナにのみ作用する*/ ) { unsigned char* pBuf = (unsigned char*)GetStringPtr(); int nBufLen = GetStringLength(); int i; int nCharChars; // unsigned char uc; unsigned short usSrc; unsigned short usDes; unsigned char* pBufDes; int nBufDesLen; static unsigned char* pszHanKataSet = (unsigned char*)"。「」、・ヲァィゥェォャュョッーアイウエオカキクケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワン゙゚"; static unsigned char* pszDakuSet = (unsigned char*)"カキクケコサシスセソタチツテトハヒフヘホ"; static unsigned char* pszYouSet = (unsigned char*)"ハヒフヘホ"; BOOL bHenkanOK; pBufDes = new unsigned char[nBufLen * 2 + 1]; if( NULL == pBufDes ){ return; } nBufDesLen = 0; for( i = 0; i < nBufLen; ++i ){ // 2005-09-02 D.S.Koba GetSizeOfChar nCharChars = CShiftJis::GetSizeOfChar( (const char *)pBuf, nBufLen, i ); if( nCharChars == 1){ bHenkanOK = FALSE; if( bHanKataOnly ){ /* 1== 半角カタカナにのみ作用する */ if( NULL != strchr( (const char *)pszHanKataSet, pBuf[i] ) ){ bHenkanOK = TRUE; } }else{ //! 英数変換用に新たな条件を付加 2001/07/30 Misaka if( ( (unsigned char)0x20 <= pBuf[i] && pBuf[i] <= (unsigned char)0x7E ) || ( bHiragana != 2 && (unsigned char)0xA1 <= pBuf[i] && pBuf[i] <= (unsigned char)0xDF ) ){ bHenkanOK = TRUE; } } if( bHenkanOK ){ usSrc = pBuf[i]; if( !bHiragana && pBuf[i] == (unsigned char)'ウ' && pBuf[i + 1] == (unsigned char)'゙' && bHiragana != 2 ){ usDes = (unsigned short)0x8394; /* ヴ */ nCharChars = 2; }else { usDes = (unsigned short)_mbbtombc( usSrc ); /* 濁音 */ if( bHiragana != 2 && pBuf[i + 1] == (unsigned char)'゙' && NULL != strchr( (const char *)pszDakuSet, pBuf[i] ) ){ usDes++; nCharChars = 2; } /* 拗音 */ //! 英数変換用に新たな条件を付加 2001/07/30 Misaka //! bHiragana != 2 //英数変換フラグがオンではない場合 if( bHiragana != 2 && pBuf[i + 1] == (unsigned char)'゚' && NULL != strchr( (const char *)pszYouSet, pBuf[i] ) ){ usDes += 2; nCharChars = 2; } } if( bHiragana == 1 ){ /* ひらがなに変換可能なカタカナならば、ひらがなに変換する */ if( (unsigned short)0x8340 <= usDes && usDes <= (unsigned short)0x837e ){ /* ァ〜ミ */ usDes-= (unsigned short)0x00a1; }else if( (unsigned short)0x8380 <= usDes && usDes <= (unsigned short)0x8393 ){ /* ム〜ン */ usDes-= (unsigned short)0x00a2; } } pBufDes[nBufDesLen] = ( usDes & 0xff00 ) >> 8; pBufDes[nBufDesLen + 1] = ( usDes & 0x00ff ); nBufDesLen += 2; }else{ memcpy( &pBufDes[nBufDesLen], &pBuf[i], nCharChars ); nBufDesLen += nCharChars; } }else
const char* CNativeA::GetStringPtr(int* pnLength) const { if(pnLength)*pnLength=GetStringLength(); return GetStringPtr(); }
//ShiftJISに変換して返す const char* CNativeW::GetStringPtrOld() const { return to_achar(GetStringPtr(),GetStringLength()); }