bool SysTestBase::CommandLineRPC_GetValue(int argc, const char *argv[], Value &value) { string strPrint; bool nRes = false; try { // Skip switches while (argc > 1 && IsSwitchChar(argv[1][0])) { argc--; argv++; } // Method if (argc < 2) throw runtime_error("too few parameters"); string strMethod = argv[1]; // Parameters default to strings std::vector<std::string> strParams(&argv[2], &argv[argc]); Array params = RPCConvertValues(strMethod, strParams); // Execute Object reply = CallRPC(strMethod, params); // Parse reply const Value& result = find_value(reply, "result"); const Value& error = find_value(reply, "error"); if (error.type() != null_type) { // Error strPrint = "error: " + write_string(error, false); // int code = find_value(error.get_obj(), "code").get_int(); } else { value = result; // Result if (result.type() == null_type) strPrint = ""; else if (result.type() == str_type) strPrint = result.get_str(); else strPrint = write_string(result, true); nRes = true; } } catch (boost::thread_interrupted) { throw; } catch (std::exception& e) { strPrint = string("error: ") + e.what(); } catch (...) { PrintExceptionContinue(NULL, "CommandLineRPC()"); throw; } if (strPrint != "") { if (false == nRes) { // cout<<strPrint<<endl; } // fprintf((nRes == 0 ? stdout : stderr), "%s\n", strPrint.c_str()); } return nRes; }
AMD_AOFX_DLL_API AOFX_RETURN_CODE AOFX_DebugSerialize(AOFX_Desc& desc, const char* params) { AMD_OUTPUT_DEBUG_STRING("CALL: " AMD_FUNCTION_NAME " \n"); HRESULT hr = S_OK; ID3D11Texture2D *pDepthT2D = NULL, *pNormalT2D = NULL; std::string strParams(params); std::wstring wstrParams(strParams.begin(), strParams.end()); if (desc.m_pDepthSRV) { std::wstring depth = wstrParams + L".depth.dds"; desc.m_pDepthSRV->GetResource((ID3D11Resource**)&pDepthT2D); hr = DirectX::SaveDDSTextureToFile(desc.m_pDeviceContext, pDepthT2D, depth.c_str()); AMD_SAFE_RELEASE(pDepthT2D); if (hr != S_OK) { AMD_OUTPUT_DEBUG_STRING("AMD_AO DebugSerialize Error : Can't save Depth Texture\n"); return AOFX_RETURN_CODE_FAIL; } } if (desc.m_pNormalSRV) { std::wstring normal = wstrParams + L".normal.dds"; desc.m_pNormalSRV->GetResource((ID3D11Resource**)&pNormalT2D); hr = DirectX::SaveDDSTextureToFile(desc.m_pDeviceContext, pNormalT2D, normal.c_str()); AMD_SAFE_RELEASE(pNormalT2D); if (hr != S_OK) { AMD_OUTPUT_DEBUG_STRING("AMD_AO DebugSerialize Error : Can't save Normal Texture\n"); return AOFX_RETURN_CODE_FAIL; } } strParams += ".txt"; FILE * file = fopen(strParams.c_str(), "wt"); if (file != NULL) { serialize_uint(file, "desc.m_MultiResLayerCount", (uint *)&desc.m_MultiResLayerCount); for (uint i = 0; i < desc.m_MultiResLayerCount; i++) { serialize_uint(file, "desc.m_LayerProcess", (uint *)&desc.m_LayerProcess[i]); serialize_uint(file, "desc.m_BilateralBlurRadius", (uint *)&desc.m_BilateralBlurRadius[i]); serialize_uint(file, "desc.m_SampleCount", (uint *)&desc.m_SampleCount[i]); serialize_uint(file, "desc.m_NormalOption", (uint *)&desc.m_NormalOption[i]); serialize_uint(file, "desc.m_TapType", (uint *)&desc.m_TapType[i]); serialize_float(file, "desc.m_MultiResLayerScale", (float *)&desc.m_MultiResLayerScale[i]); serialize_float(file, "desc.m_PowIntensity", (float *)&desc.m_PowIntensity[i]); serialize_float(file, "desc.m_RejectRadius", (float *)&desc.m_RejectRadius[i]); serialize_float(file, "desc.m_AcceptRadius", (float *)&desc.m_AcceptRadius[i]); serialize_float(file, "desc.m_RecipFadeOutDist", (float *)&desc.m_RecipFadeOutDist[i]); serialize_float(file, "desc.m_LinearIntensity", (float *)&desc.m_LinearIntensity[i]); serialize_float(file, "desc.m_NormalScale", (float *)&desc.m_NormalScale[i]); serialize_float(file, "desc.m_ViewDistanceDiscard", (float *)&desc.m_ViewDistanceDiscard[i]); serialize_float(file, "desc.m_ViewDistanceFade", (float *)&desc.m_ViewDistanceFade[i]); serialize_float(file, "desc.m_DepthUpsampleThreshold", (float *)&desc.m_DepthUpsampleThreshold[i]); } serialize_uint(file, "desc.m_Implementation", (uint *)&desc.m_Implementation); serialize_float4(file, "desc.m_Camera.m_View.r[0]", (float *)&desc.m_Camera.m_View.r[0]); serialize_float4(file, "desc.m_Camera.m_View.r[1]", (float *)&desc.m_Camera.m_View.r[1]); serialize_float4(file, "desc.m_Camera.m_View.r[2]", (float *)&desc.m_Camera.m_View.r[2]); serialize_float4(file, "desc.m_Camera.m_View.r[3]", (float *)&desc.m_Camera.m_View.r[3]); serialize_float4(file, "desc.m_Camera.m_Projection.r[0]", (float *)&desc.m_Camera.m_Projection.r[0]); serialize_float4(file, "desc.m_Camera.m_Projection.r[1]", (float *)&desc.m_Camera.m_Projection.r[1]); serialize_float4(file, "desc.m_Camera.m_Projection.r[2]", (float *)&desc.m_Camera.m_Projection.r[2]); serialize_float4(file, "desc.m_Camera.m_Projection.r[3]", (float *)&desc.m_Camera.m_Projection.r[3]); serialize_float4(file, "desc.m_Camera.m_ViewProjection.r[0]", (float *)&desc.m_Camera.m_ViewProjection.r[0]); serialize_float4(file, "desc.m_Camera.m_ViewProjection.r[1]", (float *)&desc.m_Camera.m_ViewProjection.r[1]); serialize_float4(file, "desc.m_Camera.m_ViewProjection.r[2]", (float *)&desc.m_Camera.m_ViewProjection.r[2]); serialize_float4(file, "desc.m_Camera.m_ViewProjection.r[3]", (float *)&desc.m_Camera.m_ViewProjection.r[3]); serialize_float4(file, "desc.m_Camera.m_View_Inv.r[0]", (float *)&desc.m_Camera.m_View_Inv.r[0]); serialize_float4(file, "desc.m_Camera.m_View_Inv.r[1]", (float *)&desc.m_Camera.m_View_Inv.r[1]); serialize_float4(file, "desc.m_Camera.m_View_Inv.r[2]", (float *)&desc.m_Camera.m_View_Inv.r[2]); serialize_float4(file, "desc.m_Camera.m_View_Inv.r[3]", (float *)&desc.m_Camera.m_View_Inv.r[3]); serialize_float4(file, "desc.m_Camera.m_Projection_Inv.r[0]", (float *)&desc.m_Camera.m_Projection_Inv.r[0]); serialize_float4(file, "desc.m_Camera.m_Projection_Inv.r[1]", (float *)&desc.m_Camera.m_Projection_Inv.r[1]); serialize_float4(file, "desc.m_Camera.m_Projection_Inv.r[2]", (float *)&desc.m_Camera.m_Projection_Inv.r[2]); serialize_float4(file, "desc.m_Camera.m_Projection_Inv.r[3]", (float *)&desc.m_Camera.m_Projection_Inv.r[3]); serialize_float4(file, "desc.m_Camera.m_ViewProjection_Inv.r[0]", (float *)&desc.m_Camera.m_ViewProjection_Inv.r[0]); serialize_float4(file, "desc.m_Camera.m_ViewProjection_Inv.r[1]", (float *)&desc.m_Camera.m_ViewProjection_Inv.r[1]); serialize_float4(file, "desc.m_Camera.m_ViewProjection_Inv.r[2]", (float *)&desc.m_Camera.m_ViewProjection_Inv.r[2]); serialize_float4(file, "desc.m_Camera.m_ViewProjection_Inv.r[3]", (float *)&desc.m_Camera.m_ViewProjection_Inv.r[3]); serialize_float3(file, "desc.m_Camera.m_Position", (float *)&desc.m_Camera.m_Position); serialize_float3(file, "desc.m_Camera.m_Direction", (float *)&desc.m_Camera.m_Direction); serialize_float3(file, "desc.m_Camera.m_Right", (float *)&desc.m_Camera.m_Right); serialize_float3(file, "desc.m_Camera.m_Up", (float *)&desc.m_Camera.m_Up); serialize_float(file, "desc.m_Camera.m_Aspect", (float *)&desc.m_Camera.m_Aspect); serialize_float(file, "desc.m_Camera.m_FarPlane", (float *)&desc.m_Camera.m_FarPlane); serialize_float(file, "desc.m_Camera.m_NearPlane", (float *)&desc.m_Camera.m_NearPlane); serialize_float(file, "desc.m_Camera.m_Fov", (float *)&desc.m_Camera.m_Fov); serialize_float4(file, "desc.m_Camera.m_Color", (float *)&desc.m_Camera.m_Color); serialize_uint2(file, "desc.m_InputSize", (uint*)&desc.m_InputSize); serialize_uint(file, "desc.m_OutputChannelsFlag", (uint *)&desc.m_OutputChannelsFlag); fclose(file); } else { AMD_OUTPUT_DEBUG_STRING("AMD_AO DebugSerialize Error : Can't save AO Parameters\n"); } return AOFX_RETURN_CODE_SUCCESS; }
int CommandLineRPC(int argc, char *argv[]) { std::string strPrint; int nRet = 0; try { // Skip switches while (argc > 1 && IsSwitchChar(argv[1][0])) { argc--; argv++; } // Method if (argc < 2) throw std::runtime_error("too few parameters"); std::string strMethod = argv[1]; // Parameters default to strings std::vector<std::string> strParams(&argv[2], &argv[argc]); json_spirit::Array params = RPCConvertValues(strMethod, strParams); // Execute json_spirit::Object reply = CallRPC(strMethod, params); // Parse reply const json_spirit::Value& result = find_value(reply, "result"); const json_spirit::Value& error = find_value(reply, "error"); if (error.type() != json_spirit::null_type) { // Error strPrint = "error: " + write_string(error, false); int code = find_value(error.get_obj(), "code").get_int(); nRet = abs(code); } else { // Result if (result.type() == json_spirit::null_type) strPrint = ""; else if (result.type() == json_spirit::str_type) strPrint = result.get_str(); else strPrint = write_string(result, true); } } catch (boost::thread_interrupted) { throw; } catch (std::exception& e) { strPrint = std::string("error: ") + e.what(); nRet = abs(RPC_MISC_ERROR); } catch (...) { PrintExceptionContinue(NULL, "CommandLineRPC()"); throw; } if (strPrint != "") { fprintf((nRet == 0 ? stdout : stderr), "%s\n", strPrint.c_str()); } return nRet; }
AMD_AOFX_DLL_API AOFX_RETURN_CODE AOFX_DebugDeserialize(AOFX_Desc& desc, const char* params, ID3D11Texture2D** ppT2D[], ID3D11ShaderResourceView** ppSRV[]) { AMD_OUTPUT_DEBUG_STRING("CALL: " AMD_FUNCTION_NAME " \n"); HRESULT hr = S_OK; std::string strParams(params); std::wstring wstrParams(strParams.begin(), strParams.end()); if (ppT2D != NULL && ppSRV != NULL && ppT2D[0] != NULL && ppSRV[0] != NULL) { std::wstring depth = wstrParams + L".depth.dds"; hr = DirectX::CreateDDSTextureFromFile(desc.m_pDevice, depth.c_str(), (ID3D11Resource**)ppT2D[0], ppSRV[0]); desc.m_pDepthSRV = *ppSRV[0]; } if (ppT2D != NULL && ppSRV != NULL && ppT2D[1] != NULL && ppSRV[1] != NULL) { std::wstring normal = wstrParams + L".normal.dds"; hr = DirectX::CreateDDSTextureFromFile(desc.m_pDevice, normal.c_str(), (ID3D11Resource**)ppT2D[1], ppSRV[1]); desc.m_pNormalSRV = *ppSRV[1]; } strParams += ".txt"; FILE * file = fopen(strParams.c_str(), "rt"); if (file != NULL) { char readStr[1024]; uint multiResLayerCount = 0; deserialize_uint(file, readStr, (uint *)&multiResLayerCount); assert(multiResLayerCount == desc.m_MultiResLayerCount); for (uint i = 0; i < desc.m_MultiResLayerCount; i++) { deserialize_uint(file, readStr, (uint *)&desc.m_LayerProcess[i]); deserialize_uint(file, readStr, (uint *)&desc.m_BilateralBlurRadius[i]); deserialize_uint(file, readStr, (uint *)&desc.m_SampleCount[i]); deserialize_uint(file, readStr, (uint *)&desc.m_NormalOption[i]); deserialize_uint(file, readStr, (uint *)&desc.m_TapType[i]); deserialize_float(file, readStr, (float *)&desc.m_MultiResLayerScale[i]); deserialize_float(file, readStr, (float *)&desc.m_PowIntensity[i]); deserialize_float(file, readStr, (float *)&desc.m_RejectRadius[i]); deserialize_float(file, readStr, (float *)&desc.m_AcceptRadius[i]); deserialize_float(file, readStr, (float *)&desc.m_RecipFadeOutDist[i]); deserialize_float(file, readStr, (float *)&desc.m_LinearIntensity[i]); deserialize_float(file, readStr, (float *)&desc.m_NormalScale[i]); deserialize_float(file, readStr, (float *)&desc.m_ViewDistanceDiscard[i]); deserialize_float(file, readStr, (float *)&desc.m_ViewDistanceFade[i]); deserialize_float(file, readStr, (float *)&desc.m_DepthUpsampleThreshold[i]); } deserialize_uint(file, readStr, (uint *)&desc.m_Implementation); deserialize_float4(file, readStr, (float *)&desc.m_Camera.m_View.r[0]); deserialize_float4(file, readStr, (float *)&desc.m_Camera.m_View.r[1]); deserialize_float4(file, readStr, (float *)&desc.m_Camera.m_View.r[2]); deserialize_float4(file, readStr, (float *)&desc.m_Camera.m_View.r[3]); deserialize_float4(file, readStr, (float *)&desc.m_Camera.m_Projection.r[0]); deserialize_float4(file, readStr, (float *)&desc.m_Camera.m_Projection.r[1]); deserialize_float4(file, readStr, (float *)&desc.m_Camera.m_Projection.r[2]); deserialize_float4(file, readStr, (float *)&desc.m_Camera.m_Projection.r[3]); deserialize_float4(file, readStr, (float *)&desc.m_Camera.m_ViewProjection.r[0]); deserialize_float4(file, readStr, (float *)&desc.m_Camera.m_ViewProjection.r[1]); deserialize_float4(file, readStr, (float *)&desc.m_Camera.m_ViewProjection.r[2]); deserialize_float4(file, readStr, (float *)&desc.m_Camera.m_ViewProjection.r[3]); deserialize_float4(file, readStr, (float *)&desc.m_Camera.m_View_Inv.r[0]); deserialize_float4(file, readStr, (float *)&desc.m_Camera.m_View_Inv.r[1]); deserialize_float4(file, readStr, (float *)&desc.m_Camera.m_View_Inv.r[2]); deserialize_float4(file, readStr, (float *)&desc.m_Camera.m_View_Inv.r[3]); deserialize_float4(file, readStr, (float *)&desc.m_Camera.m_Projection_Inv.r[0]); deserialize_float4(file, readStr, (float *)&desc.m_Camera.m_Projection_Inv.r[1]); deserialize_float4(file, readStr, (float *)&desc.m_Camera.m_Projection_Inv.r[2]); deserialize_float4(file, readStr, (float *)&desc.m_Camera.m_Projection_Inv.r[3]); deserialize_float4(file, readStr, (float *)&desc.m_Camera.m_ViewProjection_Inv.r[0]); deserialize_float4(file, readStr, (float *)&desc.m_Camera.m_ViewProjection_Inv.r[1]); deserialize_float4(file, readStr, (float *)&desc.m_Camera.m_ViewProjection_Inv.r[2]); deserialize_float4(file, readStr, (float *)&desc.m_Camera.m_ViewProjection_Inv.r[3]); deserialize_float3(file, readStr, (float *)&desc.m_Camera.m_Position); deserialize_float3(file, readStr, (float *)&desc.m_Camera.m_Direction); deserialize_float3(file, readStr, (float *)&desc.m_Camera.m_Right); deserialize_float3(file, readStr, (float *)&desc.m_Camera.m_Up); deserialize_float(file, readStr, (float *)&desc.m_Camera.m_Aspect); deserialize_float(file, readStr, (float *)&desc.m_Camera.m_FarPlane); deserialize_float(file, readStr, (float *)&desc.m_Camera.m_NearPlane); deserialize_float(file, readStr, (float *)&desc.m_Camera.m_Fov); deserialize_float4(file, readStr, (float *)&desc.m_Camera.m_Color); deserialize_uint2(file, readStr, (uint*)&desc.m_InputSize); deserialize_uint(file, readStr, (uint *)&desc.m_OutputChannelsFlag); fclose(file); } return AOFX_RETURN_CODE_SUCCESS; }
void CLauncherDialog::OnBnClickedOk() { CString ipAddress; CString port; CString password; CString nick; GetDlgItemText(IDC_EDIT1, ipAddress); if(ipAddress.IsEmpty()) { MessageBox("No ip address entered."); return; } GetDlgItemText(IDC_EDIT2, port); if(port.IsEmpty()) { MessageBox("No port entered."); return; } GetDlgItemText(IDC_EDIT3, password); GetDlgItemText(IDC_EDIT4, nick); if(nick.IsEmpty()) { MessageBox("No nick entered."); return; } // Get the GTA IV install directory from the registry char szInstallDirectory[MAX_PATH]; bool bFoundCustomDirectory = false; if(!SharedUtility::ReadRegistryString(HKEY_LOCAL_MACHINE, "Software\\Rockstar Games\\Grand Theft Auto IV", "InstallFolder", NULL, szInstallDirectory, sizeof(szInstallDirectory)) || !SharedUtility::Exists(szInstallDirectory)) { if(!SharedUtility::ReadRegistryString(HKEY_CURRENT_USER, "Software\\NIV", "gtaivdir", NULL, szInstallDirectory, sizeof(szInstallDirectory)) || !SharedUtility::Exists(szInstallDirectory)) { if(ShowMessageBox("Failed to retrieve GTA IV install directory from registry. Specify your GTA IV path now?", (MB_ICONEXCLAMATION | MB_OKCANCEL)) == IDOK) { // Taken from http://vcfaq.mvps.org/sdk/20.htm BROWSEINFO browseInfo = { 0 }; browseInfo.lpszTitle = "Pick a Directory"; ITEMIDLIST * pItemIdList = SHBrowseForFolder(&browseInfo); if(pItemIdList != NULL) { // Get the name of the selected folder if(SHGetPathFromIDList(pItemIdList, szInstallDirectory)) bFoundCustomDirectory = true; // Free any memory used IMalloc * pIMalloc = 0; if(SUCCEEDED(SHGetMalloc(&pIMalloc))) { pIMalloc->Free(pItemIdList); pIMalloc->Release(); } } } if(!bFoundCustomDirectory) { ShowMessageBox("Failed to retrieve GTA IV install directory from registry. Cannot launch Networked: IV."); return; } } } // Get the full path to LaunchGTAIV.exe String strApplicationPath("%s\\LaunchGTAIV.exe", szInstallDirectory); // Check if LaunchGTAIV.exe exists if(!SharedUtility::Exists(strApplicationPath.Get())) { ShowMessageBox("Failed to find LaunchGTAIV.exe. Cannot launch Networked: IV."); return; } // If we have a custom directory save it if(bFoundCustomDirectory) SharedUtility::WriteRegistryString(HKEY_CURRENT_USER, "Software\\NIV", "gtaivdir", szInstallDirectory, strlen(szInstallDirectory)); // Format the command line params String strParams("\"%s\" -ip %s -port %s -nick %s", strApplicationPath.Get(), ipAddress, port, nick); // Do we have a password? if(!password.IsEmpty()) { // Append it to the command line params strParams += " -password"; strParams += password; } // Save the edit box values SaveInfo(); // Get the full path of the client core String strClientCore("%s" CLIENT_CORE_NAME DEBUG_SUFFIX ".dll", SharedUtility::GetAppPath()); // Check if the client core exists if(!SharedUtility::Exists(strClientCore.Get())) { ShowMessageBox("Failed to find " CLIENT_CORE_NAME DEBUG_SUFFIX ".dll. Cannot launch Networked: IV."); return; } // Get the full path of the launch helper String strLaunchHelper("%s" CLIENT_LAUNCH_HELPER_NAME DEBUG_SUFFIX ".dll", SharedUtility::GetAppPath()); // Check if the launch helper exists if(!SharedUtility::Exists(strLaunchHelper.Get())) { ShowMessageBox("Failed to find " CLIENT_LAUNCH_HELPER_NAME DEBUG_SUFFIX ".dll. Cannot launch Networked: IV."); return; } // Check if LaunchGTAIV.exe is already running if(IsProcessRunning("LaunchGTAIV.exe")) { ShowMessageBox("LaunchGTAIV.exe is already running. Cannot launch Networked: IV."); return; } // Check if GTAIV.exe is already running if(IsProcessRunning("GTAIV.exe")) { ShowMessageBox("GTAIV.exe is already running. Cannot launch Networked: IV."); return; } // Start LaunchGTAIV.exe STARTUPINFO siStartupInfo; PROCESS_INFORMATION piProcessInfo; memset(&siStartupInfo, 0, sizeof(siStartupInfo)); memset(&piProcessInfo, 0, sizeof(piProcessInfo)); siStartupInfo.cb = sizeof(siStartupInfo); if(!CreateProcess(strApplicationPath.Get(), strParams.GetData(), NULL, NULL, TRUE, CREATE_SUSPENDED, NULL, SharedUtility::GetAppPath(), &siStartupInfo, &piProcessInfo)) { ShowMessageBox("Failed to start LaunchGTAIV.exe. Cannot launch Networked: IV."); return; } // Inject LauncherLibrary.dll into LaunchGTAIV.exe int iReturn = SharedUtility::InjectLibraryIntoProcess(piProcessInfo.hProcess, strLaunchHelper.Get()); // Did the injection fail? if(iReturn > 0) { // Terminate the process TerminateProcess(piProcessInfo.hProcess, 0); // Show the error message String strError("Unknown error. Cannot launch Networked: IV."); if(iReturn == 1) strError = "Failed to write library path into remote process. Cannot launch Networked: IV."; else if(iReturn == 2) strError = "Failed to create remote thread in remote process. Cannot launch Networked: IV."; else if(iReturn == 3) strError = "Failed to open the remote process, Cannot launch Networked: IV."; ShowMessageBox(strError.Get()); return; } // Resume the LaunchGTAIV.exe thread ResumeThread(piProcessInfo.hThread); }