bool C4Def::Save(C4Group &hGroup) { StdStrBuf Out; if (! Decompile(&Out, FormatString("%s::DefCore.txt", id.ToString()).getData()) ) return false; return hGroup.Add(C4CFN_DefCore,Out,false,true); }
BOOL C4Scenario::Save(C4Group &hGroup, bool fSaveSection) { char *Buffer; int32_t BufferSize; if (!Decompile(&Buffer,&BufferSize, fSaveSection)) return FALSE; if (!hGroup.Add(C4CFN_ScenarioCore,Buffer,BufferSize,FALSE,TRUE)) { StdBuf Buf; Buf.Take(Buffer, BufferSize); return FALSE; } return TRUE; }
bool C4ObjectInfoCore::Save(C4Group &hGroup, C4DefList *pDefs) { // rank overload by def: Update any NextRank-stuff if (pDefs) UpdateCustomRanks(pDefs); char *Buffer; size_t BufferSize; if (!Decompile(&Buffer,&BufferSize)) return false; if (!hGroup.Add(C4CFN_ObjectInfoCore,Buffer,BufferSize,false,true) ) { delete [] Buffer; return false; } return true; }
BOOL C4ObjectInfoCore::Save(C4Group &hGroup, C4DefList *pDefs) { #ifdef C4ENGINE // rank overload by def: Update any NextRank-stuff if (pDefs) UpdateCustomRanks(pDefs); #endif char *Buffer; size_t BufferSize; if (!Decompile(&Buffer,&BufferSize)) return FALSE; if (!hGroup.Add(C4CFN_ObjectInfoCore,Buffer,BufferSize,FALSE,TRUE) ) { delete [] Buffer; return FALSE; } return TRUE; }
int Wildcard (const char *pszInFile, const char *pszOutFile) { #ifdef _WIN32 struct _finddata_t sFind; // // Split the input file name up // char szDrive [_MAX_DRIVE]; char szDir [_MAX_DIR]; char szFileName [_MAX_FNAME]; char szExtension [_MAX_EXT]; _splitpath (pszInFile, szDrive, szDir, szFileName, szExtension); // // Make a root name // char szInFile [_MAX_PATH]; strcpy (szInFile, szDrive); strcat (szInFile, szDir); int nRootLength = (int) strlen (szInFile); // // Initiate the find // intptr_t id = _findfirst (pszInFile, &sFind); if (id <= 0) return 0; // // Loop through the files // int nCount = 0; do { // // If system, hidden, or subdir, then skip // if ((sFind .attrib & (_A_HIDDEN | _A_SYSTEM | _A_SUBDIR)) != 0) continue; // // Create the file name // strcpy (&szInFile [nRootLength], sFind .name); // // Load the file // UINT32 ulSize; unsigned char *pauchData = NULL; pauchData = NwnLoadFile (szInFile, &ulSize); // // Compile/decompile // if (pauchData == NULL) { printf ("Error: Unable to open file %s\n", sFind .name); continue; } // // Compile/decompile // if (g_fCompile) Compile (pauchData, ulSize, sFind .name, pszOutFile); else Decompile (pauchData, ulSize, sFind .name, pszOutFile); nCount++; } while (_findnext (id, &sFind) >= 0); // // Close the find // _findclose (id); return nCount; #else // // Load the file // UINT32 ulSize; unsigned char *pauchData = NULL; pauchData = NwnLoadFile (pszInFile, &ulSize); if (pauchData == NULL) return 0; // // Compile // if (g_fCompile) Compile (pauchData, ulSize, pszInFile, pszOutFile); else Decompile (pauchData, ulSize, pszInFile, pszOutFile); return 1; #endif }
void VKFragmentDecompilerThread::Task() { m_shader = Decompile(); vk_prog->SetInputs(inputs); }
void VKVertexDecompilerThread::Task() { m_shader = Decompile(); vk_prog->SetInputs(inputs); }
void GLVertexDecompilerThread::Task() { m_shader = Decompile(); }
void GLFragmentDecompilerThread::Task() { m_shader = Decompile(); }
void Decompile(qStr *in, qStr *out) { int i, j; char *p; C_BASE b; while (in->GetS((char *) &b, sizeof(b)) == sizeof(b)) { CStr dt(b.ln); if (in->GetS(dt.GetBuffer(), b.ln) == b.ln) { if (b.bc == BC_FUNC) { C_ARGS v; C_ARG a; CStr cur; p = dt.GetBuffer(); if (b.rn) { for (j = 0; j < b.ln; ++j) p[j] = p[j] ^ b.rn; } out->PutC('%'); out->PutS(dt); if (in->GetS((char *) &v, sizeof(v)) == sizeof(v)) { if (v.cnt > 0) out->PutC('('); else out->PutC('%'); for (i = 0; i < v.cnt; ++i) { if (in->GetS((char *) &a, sizeof(a)) == sizeof(a)) { cur.Grow(a.ln); if (in->GetS(cur.GetBuffer(), a.ln) == (int) a.ln) { p = cur.GetBuffer(); if (b.rn) { for (j = 0; j < (int) a.ln; ++j) p[j] = p[j] ^ b.rn; } if (a.at == ARG_CMP) { qStrReadBuf rTmp(cur); Decompile(&rTmp, out); } else { if (a.at == ARG_QSTR) out->PutC('\''); out->PutS(cur); } if (i < (v.cnt-1)) { out->PutC(','); } } } } if (v.cnt > 0) out->PutC(')'); } } else if (b.bc == BC_OUT) { out->PutS(dt, b.ln); } } } }
void RunCompiled(qCtx *ctx, qStr *in, qStr *out) { int i, j; char *p; C_BASE b; while (in->GetS((char *) &b, sizeof(b)) == sizeof(b) && b.ln > 0) { CStr dt(b.ln); if (in->GetS(dt.GetBuffer(), b.ln) == b.ln) { if (b.bc == BC_FUNC) { p = dt.GetBuffer(); if (b.rn) { for (j = 0; j < b.ln; ++j) p[j] = p[j] ^ b.rn; } qObj *obj; if (ctx->Find(&obj, (const CStr &) dt)) { C_ARGS v; C_ARG a; CStr cur; qArgAry ary; char qmode; if (in->GetS((char *) &v, sizeof(v)) == sizeof(v)) { char *map = obj->GetQmap(); if (!map || *map == 'A') { qmode = !map ? '0' : '1'; for (i = 0; i < v.cnt; ++i) { { if (in->GetS((char *) &a, sizeof(a)) == sizeof(a)) { cur.Grow(a.ln); if (in->GetS(cur.GetBuffer(), a.ln) == (int) a.ln) { p = cur.GetBuffer(); if (b.rn) { for (j = 0; j < (int) a.ln; ++j) p[j] = p[j] ^ b.rn; } ary.Add(cur); ary.SetQuot(i, a.at == ARG_QSTR); if (!ary.GetQuot(i) && qmode == '0') { qStrBuf tmp; if (a.at == ARG_CMP) { qStrReadBuf rTmp(ary[i]); RunCompiled(ctx, &rTmp, &tmp); } else { qStrReadBuf rTmp(ary[i]); ctx->Parse(&rTmp, &tmp); } ary[i] = tmp; } else { if (a.at == ARG_CMP) { if (qmode != '2') { qStrBuf tmp; qStrReadBuf rTmp(ary[i]); Decompile(&rTmp, &tmp); ary[i] = tmp; } else { ary.SetQuot(i, ARG_CMP); } } } } } } } } else { qmode = (*map == '1' ? '1' : '0'); ++map; for (i = 0; i < v.cnt; ++i) { { if (in->GetS((char *) &a, sizeof(a)) == sizeof(a)) { cur.Grow(a.ln); if (in->GetS(cur.GetBuffer(), a.ln) == (int) a.ln) { p = cur.GetBuffer(); if (b.rn) { for (j = 0; j < (int) a.ln; ++j) p[j] = p[j] ^ b.rn; } ary.Add(cur); ary.SetQuot(i, a.at == ARG_QSTR); if (!ary.GetQuot(i) && qmode == '0') { qStrBuf tmp; if (a.at == ARG_CMP) { qStrReadBuf rTmp(ary[i]); RunCompiled(ctx, &rTmp, &tmp); } else { qStrReadBuf rTmp(ary[i]); ctx->Parse(&rTmp, &tmp); } ary[i] = tmp; } else { if (a.at == ARG_CMP) { if (qmode != '2') { qStrBuf tmp; qStrReadBuf rTmp(ary[i]); Decompile(&rTmp, &tmp); ary[i] = tmp; } else { ary.SetQuot(i, ARG_CMP); } } } } } } if (*map) { if (*map != 'A') { qmode = *map; ++map; } } else { qmode = '0'; } } } obj->Eval(ctx, out, v.cnt ? &ary : NULL); } } else { if (ctx->GetStrict()) { ctx->ThrowF(out, 98, "Function '%s' was not found.", (const char *) dt); } else { C_ARGS v; C_ARG a; CStr cur; if (in->GetS((char *) &v, sizeof(v)) == sizeof(v)) { for (i = 0; i < v.cnt; ++i) { if (in->GetS((char *) &a, sizeof(a)) == sizeof(a)) { cur.Grow(a.ln); if (in->GetS(cur.GetBuffer(), a.ln) != (int) a.ln) { break; } } } } out->PutC('%'); out->PutS(dt); if (v.cnt > 0) { out->PutC(T_LP); out->PutS("..."); out->PutC(T_RP); } else { out->PutC('%'); } } } } else if (b.bc == BC_OUT) { out->PutS(dt, b.ln); } } } }