Beispiel #1
0
StdStrBuf C4Playback::ReWriteText() {
  // Would work, too, but is currently too slow due to bad buffering inside
  // StdCompilerINIWrite:
  // return
  // DecompileToBuf<StdCompilerINIWrite>(mkNamingAdapt(mkSTLContainerAdapt(chunks),
  // "Rec"));
  StdStrBuf Output;
  for (chunks_t::const_iterator i = chunks.begin(); i != chunks.end(); i++) {
    Output.Append(
        static_cast<const StdStrBuf &>(DecompileToBuf<StdCompilerINIWrite>(
            mkNamingAdapt(mkDecompileAdapt(*i), "Rec"))));
    Output.Append("\n\n");
  }
  return Output;
}
void C4KeyCodeEx::CompileFunc(StdCompiler *pComp, StdStrBuf *pOutBuf)
{
    if (pComp->isCompiler())
    {
        // reading from file
        StdStrBuf sCode;
        bool is_scan_code;
        // read shifts
        DWORD dwSetShift = 0;
        for (;;)
        {
            is_scan_code = pComp->Separator(StdCompiler::SEP_DOLLAR);
            if (!is_scan_code) pComp->NoSeparator();
            pComp->Value(mkParAdapt(sCode, StdCompiler::RCT_Idtf));
            if (is_scan_code) // scan codes start with $. Reassamble the two tokens that were split by StdCompiler
            {
                sCode.Take(FormatString("$%s", sCode.getData()));
                break;
            }
            if (!pComp->Separator(StdCompiler::SEP_PLUS)) break; // no more separator: Parse this as keyboard code
            // try to convert to shift state
            C4KeyShiftState eAddState = String2KeyShift(sCode);
            if (eAddState == KEYS_Undefined)
                pComp->excCorrupt("undefined key shift state: %s", sCode.getData());
            dwSetShift |= eAddState;
        }
        // any code given? Otherwise, keep default
        if (sCode.getLength())
        {
            // last section: convert to key code
            C4KeyCode eCode = String2KeyCode(sCode);
            if (eCode == KEY_Undefined)
            {
                if (pOutBuf)
                {
                    // unknown key, but an output buffer for unknown keys was provided. No failure; caller might resolve key.
                    eCode = KEY_Default;
                }
                else
                {
                    pComp->excCorrupt("undefined key code: %s", sCode.getData());
                }
            }
            dwShift = dwSetShift;
            Key = eCode;
            if (pOutBuf) pOutBuf->Take(std::move(sCode));
        }
    }
    else
    {
        // write shift states
        for (DWORD dwShiftCheck = KEYS_First; dwShiftCheck <= KEYS_Max; dwShiftCheck <<= 1)
            if (dwShiftCheck & dwShift)
            {
                pComp->Value(mkDecompileAdapt(KeyShift2String((C4KeyShiftState) dwShiftCheck)));
                pComp->Separator(StdCompiler::SEP_PLUS);
            }
        // write key
        pComp->Value(mkDecompileAdapt(KeyCode2String(Key, false, false)));
    }
}
Beispiel #3
0
C4NetIOPacket C4PacketBase::pack(uint8_t cStatus, const C4NetIO::addr_t &addr) const
{
	return C4NetIOPacket(DecompileToBuf<StdCompilerBinWrite>(mkInsertAdapt(mkDecompileAdapt(*this), cStatus)), addr);
}