Beispiel #1
0
void CConfig::Load()
{
	static TCHAR path[MAX_PATH];
	std::string folder, file;

	if ( SUCCEEDED( SHGetFolderPath( NULL, CSIDL_APPDATA, NULL, 0, path ) ) )
	{
		folder = std::string( path ) + strenc( "\\notacheat\\" );
		file = std::string( path ) + strenc( "\\notacheat\\gamerfood.ini" );
	}

	CreateDirectory( folder.c_str(), NULL );

	char value_l[32] = { '\0' };

	for ( auto value : ints )
	{
		GetPrivateProfileString( value->category.c_str(), value->name.c_str(), "", value_l, 32, file.c_str() );
		*value->value = atoi( value_l );
	}

	for ( auto value : floats )
	{
		GetPrivateProfileString( value->category.c_str(), value->name.c_str(), "", value_l, 32, file.c_str() );
		*value->value = atof( value_l );
	}

	for ( auto value : bools )
	{
		GetPrivateProfileString( value->category.c_str(), value->name.c_str(), "", value_l, 32, file.c_str() );
		*value->value = !strcmp( value_l, "true" );
	}
}
Beispiel #2
0
void CConfig::Save()
{
	static TCHAR path[ MAX_PATH ];
	std::string folder, file;

	if( SUCCEEDED( SHGetFolderPath( NULL, CSIDL_APPDATA, NULL, 0, path ) ) )
	{
		folder = std::string( path ) + strenc( "\\notacheat\\" );
		file = std::string( path ) + strenc( "\\notacheat\\gamerfood.ini" );
	}

	CreateDirectory( folder.c_str(), NULL );

	for ( auto value : ints )
		WritePrivateProfileString( value->category.c_str(), value->name.c_str(), std::to_string( *value->value ).c_str(), file.c_str() );

	for ( auto value : floats )
		WritePrivateProfileString( value->category.c_str(), value->name.c_str(), std::to_string( *value->value ).c_str(), file.c_str() );

	for ( auto value : bools )
		WritePrivateProfileString( value->category.c_str(), value->name.c_str(), *value->value ? "true" : "false", file.c_str() );
}
Beispiel #3
0
void CConfig::Setup()
{
	SetupValue( Vars.Ragebot.Enabled, false, strenc( "Ragebot" ), strenc( "Enabled" ) );
	SetupValue( Vars.Ragebot.AutoFire, false, strenc( "Ragebot" ), strenc( "AutoFire" ) );
	SetupValue( Vars.Ragebot.Hold, false, strenc( "Ragebot" ), strenc( "Hold" ) );
	SetupValue( Vars.Ragebot.HoldKey, 0, strenc( "Ragebot" ), strenc( "HoldKey" ) );
	SetupValue( Vars.Ragebot.FOV, 180.f, strenc( "Ragebot" ), strenc( "FOV" ) );
	SetupValue( Vars.Ragebot.Silent, true, strenc( "Ragebot" ), strenc( "Silent" ) );
	SetupValue( Vars.Ragebot.TargetMethod, 0, strenc( "Ragebot" ), strenc( "TargetMethod" ) );
	SetupValue( Vars.Ragebot.Hitbox, 6, strenc( "Ragebot" ), strenc( "Hitbox" ) );
	SetupValue( Vars.Ragebot.FriendlyFire, false, strenc( "Ragebot" ), strenc( "FriendlyFire" ) );
	SetupValue( Vars.Ragebot.AutoStop, false, strenc( "Ragebot" ), strenc( "AutoStop" ) );
	SetupValue( Vars.Ragebot.AutoCrouch, false, strenc( "Ragebot" ), strenc( "AutoCrouch" ) );
	SetupValue( Vars.Ragebot.AutoWall, true, strenc( "Ragebot" ), strenc( "AutoWall" ) );
	SetupValue( Vars.Ragebot.AutoWallDmg, 10.f, strenc( "Ragebot" ), strenc( "AutoWallDamage" ) );
	SetupValue( Vars.Ragebot.HitChance, false, strenc( "Ragebot" ), strenc( "HitChance" ) );
	SetupValue( Vars.Ragebot.HitChanceAmt, 50.f, strenc( "Ragebot" ), strenc( "HitChanceAmount" ) );
	SetupValue( Vars.Ragebot.Aimstep, false, strenc( "Ragebot" ), strenc( "Aimstep" ) );
	SetupValue( Vars.Ragebot.AimstepAmount, 15.f, strenc( "Ragebot" ), strenc( "AimstepAmount" ) );
	SetupValue( Vars.Ragebot.HitScanAll, false, strenc( "Ragebot" ), strenc( "HitScanAll" ) );
	SetupValue( Vars.Ragebot.HitScanHitbox, false, strenc( "Ragebot" ), strenc( "HitScanHitbox" ) );
	SetupValue( Vars.Ragebot.UntrustedCheck, true, strenc( "Ragebot" ), strenc( "Anti-Untrust" ) );
	SetupValue( Vars.Ragebot.Antiaim.Enabled, false, strenc( "Ragebot" ), strenc( "AntiaimEnabled" ) );
	SetupValue( Vars.Ragebot.Antiaim.Pitch, 0, strenc( "Ragebot" ), strenc( "AntiaimPitch" ) );
	SetupValue( Vars.Ragebot.Antiaim.Yaw, 0, strenc( "Ragebot" ), strenc( "AntiaimYaw" ) );
	SetupValue( Vars.Ragebot.Antiaim.PSilent, true, strenc( "Ragebot" ), strenc( "AntiaimYaw" ) );


	SetupValue( Vars.Legitbot.Aimbot.Enabled, false, strenc( "Legitbot" ), strenc( "Enabled" ) );
	SetupValue( Vars.Legitbot.Aimbot.AlwaysOn, false, strenc( "Legitbot" ), strenc( "AlwaysOn" ) );
	SetupValue( Vars.Legitbot.Aimbot.Key, 0, strenc( "Legitbot" ), strenc( "Key" ) );
	SetupValue( Vars.Legitbot.Aimbot.OnKey, false, strenc( "Legitbot" ), strenc( "OnKey" ) );
	SetupValue( Vars.Legitbot.Aimbot.FriendlyFire, false, strenc( "Legitbot" ), strenc( "FriendlyFire" ) );
	SetupValue( Vars.Legitbot.Aimbot.Hitbox, 6, strenc( "Legitbot" ), strenc( "Hitbox" ) );
	SetupValue( Vars.Legitbot.Aimbot.FOV, 10.f, strenc( "Legitbot" ), strenc( "FOV" ) );
	SetupValue( Vars.Legitbot.Aimbot.Speed, 5.f, strenc( "Legitbot" ), strenc( "Speed" ) );
	SetupValue( Vars.Legitbot.Aimbot.RCS, true, strenc( "Legitbot" ), strenc( "RCS" ) );
	SetupValue( Vars.Legitbot.Aimbot.RCSAmount, 100.f, strenc( "Legitbot" ), strenc( "RCSAmount" ) );

	SetupValue( Vars.Legitbot.Triggerbot.Enabled, false, strenc( "Triggerbot" ), strenc( "Enabled" ) );
	SetupValue( Vars.Legitbot.Triggerbot.AutoFire, false, strenc( "Triggerbot" ), strenc( "AutoFire" ) );
	SetupValue( Vars.Legitbot.Triggerbot.Key, 0, strenc( "Triggerbot" ), strenc( "Key" ) );
	SetupValue( Vars.Legitbot.Triggerbot.HitChance, false, strenc( "Triggerbot" ), strenc( "HitChance" ) );
	SetupValue( Vars.Legitbot.Triggerbot.HitChanceAmt, 60.f, strenc( "Triggerbot" ), strenc( "HitChanceAmt" ) );
	SetupValue( Vars.Legitbot.Triggerbot.Filter.Head, false, strenc( "Triggerbot" ), strenc( "FilterHead" ) );
	SetupValue( Vars.Legitbot.Triggerbot.Filter.Chest, false, strenc( "Triggerbot" ), strenc( "FilterChest" ) );
	SetupValue( Vars.Legitbot.Triggerbot.Filter.Stomach, false, strenc( "Triggerbot" ), strenc( "FilterStomach" ) );
	SetupValue( Vars.Legitbot.Triggerbot.Filter.Arms, false, strenc( "Triggerbot" ), strenc( "FilterArms" ) );
	SetupValue( Vars.Legitbot.Triggerbot.Filter.Legs, false, strenc( "Triggerbot" ), strenc( "FilterLegs" ) );
	SetupValue( Vars.Legitbot.Triggerbot.Filter.Friendly, false, strenc( "Triggerbot" ), strenc( "FilterFriendly" ) );

	SetupValue( Vars.Visuals.Enabled, true, strenc( "Visuals" ), strenc( "Enabled" ) );
	SetupValue( Vars.Visuals.Box, true, strenc( "Visuals" ), strenc( "Box" ) );
	SetupValue( Vars.Visuals.Skeleton, false, strenc( "Visuals" ), strenc( "Skeleton" ) );
	SetupValue( Vars.Visuals.BulletTrace, false, strenc( "Visuals" ), strenc( "BulletTrace" ) );
	SetupValue( Vars.Visuals.BulletTraceLength, 200.f, strenc( "Visuals" ), strenc( "BulletTraceLength" ) );
	SetupValue( Vars.Visuals.Glow, true, strenc( "Visuals" ), strenc( "Glow" ) );
	SetupValue( Vars.Visuals.CrosshairOn, true, strenc( "Visuals" ), strenc( "CrosshairOn" ) );
	SetupValue( Vars.Visuals.CrosshairType, 0, strenc( "Visuals" ), strenc( "CrosshairType" ) );
	SetupValue( Vars.Visuals.CrosshairStyle, 0, strenc( "Visuals" ), strenc( "CrosshairStyle" ) );
	SetupValue( Vars.Visuals.Info.Name, true, strenc( "Visuals" ), strenc( "InfoName" ) );
	SetupValue( Vars.Visuals.Info.Health, true, strenc( "Visuals" ), strenc( "InfoHealth" ) );
	SetupValue( Vars.Visuals.Info.Weapon, true, strenc( "Visuals" ), strenc( "InfoWeapon" ) );
	SetupValue( Vars.Visuals.Info.Flashed, true, strenc( "Visuals" ), strenc( "InfoFlashed" ) );
	SetupValue( Vars.Visuals.Filter.Enemies, true, strenc( "Visuals" ), strenc( "FilterEnemies" ) );
	SetupValue( Vars.Visuals.Filter.Friendlies, true, strenc( "Visuals" ), strenc( "FilterFriendlies" ) );
	SetupValue( Vars.Visuals.Filter.Weapons, true, strenc( "Visuals" ), strenc( "FilterWeapons" ) );
	SetupValue( Vars.Visuals.Filter.Decoy, true, strenc( "Visuals" ), strenc( "FilterDecoy" ) );
	SetupValue( Vars.Visuals.Filter.C4, true, strenc( "Visuals" ), strenc( "FilterC4" ) );
	SetupValue( Vars.Visuals.Chams.Enabled, true, strenc( "Visuals" ), strenc( "ChamsEnabled" ) );
	SetupValue( Vars.Visuals.Chams.Mode, 0, strenc( "Visuals" ), strenc( "ChamsMode" ) );
	SetupValue( Vars.Visuals.Chams.XQZ, true, strenc( "Visuals" ), strenc( "ChamsXQZ" ) );
	SetupValue( Vars.Visuals.Chams.Wireframe, true, strenc( "Visuals" ), strenc( "ChamsWireframe" ) );
	SetupValue( Vars.Visuals.Removals.Hands, false, strenc( "Visuals" ), strenc( "RemoveHands" ) );
	SetupValue( Vars.Visuals.Removals.Weapon, false, strenc( "Visuals" ), strenc( "RemoveWeapon" ) );
	SetupValue( Vars.Visuals.Removals.VisualRecoil, true, strenc( "Visuals" ), strenc( "RemoveRecoil" ) );
	SetupValue( Vars.Visuals.Removals.Flash, true, strenc( "Visuals" ), strenc( "RemoveFlash" ) );

	SetupValue( Vars.Misc.Bhop, true, strenc( "Misc" ), strenc( "Bhop" ) );
	SetupValue( Vars.Misc.AutoStrafe, false, strenc( "Misc" ), strenc( "AutoStrafe" ) );
	SetupValue( Vars.Misc.Watermark, true, strenc( "Misc" ), strenc( "Watermark" ) );
	SetupValue( Vars.Misc.Ranks, true, strenc( "Misc" ), strenc( "Ranks" ) );
	SetupValue( Vars.Misc.AutoAccept, true, strenc( "Misc" ), strenc( "AutoAccept" ) );
	SetupValue( Vars.Misc.AirStuck, false, strenc( "Misc" ), strenc( "AirStuck" ) );
	SetupValue( Vars.Misc.AirStuckKey, 0, strenc( "Misc" ), strenc( "AirStuckKey" ) );
}
void __stdcall Hooks::DrawModelExecute( void* context, void* state, const ModelRenderInfo_t& info, matrix3x4_t* pCustomBoneToWorld )
{
    H::ModelRender->UnHook();

    if( I::Engine->IsInGame() && G::LocalPlayer )
    {
        if( info.pModel )
        {
            std::string modelName = I::ModelInfo->GetModelName( info.pModel );

            if( modelName.find( strenc( "models/player" ) ) != std::string::npos && Vars.Visuals.Chams.Enabled )
            {
                CBaseEntity* pModelEntity = ( CBaseEntity* )I::ClientEntList->GetClientEntity( info.entity_index );
                if( pModelEntity && pModelEntity->GetAlive() && !pModelEntity->GetDormant() )
                {
                    Color render_color_hidden = pModelEntity->GetTeam() == G::LocalPlayer->GetTeam() ? Color( 72, 219, 75 ) : Color( 232, 209, 32 );
                    Color render_color_visible = pModelEntity->GetTeam() == G::LocalPlayer->GetTeam() ? Color( 84, 167, 255 ) : Color( 200, 60, 60 );

                    if( Vars.Visuals.Chams.XQZ )
                    {
                        ForceMaterial( Vars.Visuals.Chams.Mode == 0 ? hidden_flat : hidden_tex, render_color_hidden );
                        I::ModelRender->DrawModelExecute( context, state, info, pCustomBoneToWorld );

                        if( Vars.Visuals.Chams.Mode == 0 )
                            hidden_flat->SetMaterialVarFlag( MATERIAL_VAR_IGNOREZ, true );
                        else
                            hidden_tex->SetMaterialVarFlag( MATERIAL_VAR_IGNOREZ, true );
                    }

                    if( Vars.Visuals.Chams.Mode == 0 )
                        visible_flat->SetMaterialVarFlag( MATERIAL_VAR_IGNOREZ, false );
                    else
                        visible_tex->SetMaterialVarFlag( MATERIAL_VAR_IGNOREZ, false );

                    ForceMaterial( Vars.Visuals.Chams.Mode == 0 ? visible_flat : visible_tex, render_color_visible );
                    I::ModelRender->DrawModelExecute( context, state, info, pCustomBoneToWorld );
                }
            }

            else if( modelName.find( strenc( "flash" ) ) != std::string::npos && Vars.Visuals.Removals.Flash )
            {
                IMaterial* flash = I::MaterialSystem->FindMaterial( charenc( "effects\\flashbang" ), charenc( TEXTURE_GROUP_CLIENT_EFFECTS ) );
                IMaterial* flashWhite = I::MaterialSystem->FindMaterial( charenc( "effects\\flashbang_white" ), charenc( TEXTURE_GROUP_CLIENT_EFFECTS ) );
                flash->SetMaterialVarFlag( MATERIAL_VAR_NO_DRAW, true );
                flashWhite->SetMaterialVarFlag( MATERIAL_VAR_NO_DRAW, true );
                I::ModelRender->ForcedMaterialOverride( flash );
                I::ModelRender->ForcedMaterialOverride( flashWhite );
            }

            else if( modelName.find( "arms" ) != std::string::npos && Vars.Visuals.Removals.Hands )
            {
                IMaterial* Hands = I::MaterialSystem->FindMaterial( modelName.c_str(), charenc( TEXTURE_GROUP_MODEL ) );
                Hands->SetMaterialVarFlag( MATERIAL_VAR_NO_DRAW, true );
                I::ModelRender->ForcedMaterialOverride( Hands );
            }

            else if( modelName.find( "weapon" ) != std::string::npos && Vars.Visuals.Removals.Weapon )
            {
                if( !( modelName.find( "arms" ) != std::string::npos ) )
                {
                    IMaterial* Weapon = I::MaterialSystem->FindMaterial( modelName.c_str(), charenc( TEXTURE_GROUP_MODEL ) );
                    Weapon->SetMaterialVarFlag( MATERIAL_VAR_NO_DRAW, true );
                    I::ModelRender->ForcedMaterialOverride( Weapon );
                }
            }
        }
    }
    I::ModelRender->DrawModelExecute( context, state, info, pCustomBoneToWorld );
    I::ModelRender->ForcedMaterialOverride( NULL );
    H::ModelRender->ReHook();
}
Beispiel #5
0
void U::SetupInterfaces()
{
	I::Client			= U::CaptureInterface<IBaseClientDll>( strenc( "client.dll" ), strenc( "VClient017" ) );
	I::ClientMode		= **( IClientModeShared*** ) ( ( *( DWORD** ) I::Client )[10] + 0x5 );
	I::ClientEntList	= U::CaptureInterface<IClientEntityList>( strenc( "client.dll" ), strenc( "VClientEntityList003" ) );
	I::Cvar				= U::CaptureInterface<ICVar>( strenc( "vstdlib.dll" ), strenc( "VEngineCvar007" ) );
	I::Engine			= U::CaptureInterface<IEngineClient>( strenc( "engine.dll" ), strenc( "VEngineClient014" ) );
	I::EngineTrace		= U::CaptureInterface<IEngineTrace>( strenc( "engine.dll" ), strenc( "EngineTraceClient004" ) );
	I::InputSystem		= U::CaptureInterface<IInputSystem>( strenc( "inputsystem.dll" ), strenc( "InputSystemVersion001" ) );
	I::Globals			= **( IGlobalVarsBase*** ) ( ( *( DWORD** ) I::Client )[0] + 0x53 );
	I::Surface			= U::CaptureInterface<ISurface>( strenc( "vguimatsurface.dll" ), strenc( "VGUI_Surface031" ) );
	I::VPanel			= U::CaptureInterface<IVPanel>( strenc( "vgui2.dll" ), strenc( "VGUI_Panel009" ) );
	I::RenderView		= U::CaptureInterface<IVRenderView>( strenc( "engine.dll" ), strenc( "VEngineRenderView014" ) );
	I::ModelRender		= U::CaptureInterface<IVModelRender>( strenc( "engine.dll" ), strenc( "VEngineModel016" ) );
	I::MaterialSystem	= U::CaptureInterface<IMaterialSystem>( strenc( "materialsystem.dll" ), strenc( "VMaterialSystem080" ) );
	I::ModelInfo		= U::CaptureInterface<IVModelInfo>( strenc( "engine.dll" ), strenc( "VModelInfoClient004" ) );
	I::Prediction		= U::CaptureInterface<IPrediction>( strenc( "client.dll" ), strenc( "VClientPrediction001" ) );
	I::Physprops		= U::CaptureInterface<IPhysicsSurfaceProps>( strenc( "vphysics.dll" ), strenc( "VPhysicsSurfaceProps001" ) );
	I::DebugOverlay		= U::CaptureInterface<IVDebugOverlay>( strenc( "engine.dll" ), strenc( "VDebugOverlay004" ) );
	I::StudioRender		= U::CaptureInterface<IStudioRender>( strenc( "studiorender.dll" ), strenc( "VStudioRender026" ) );
}
Beispiel #6
0
Datum parse_uri(PG_FUNCTION_ARGS)
{
  TupleDesc tupledesc;
  AttInMetadata *attinmeta;
  text* input=PG_GETARG_TEXT_P(0);
    /* Function is defined STRICT in SQL, so no NULL check is needed. */
  bool normalize=PG_GETARG_BOOL(1);
  bool parse_query=PG_GETARG_BOOL(2);

  char* inp=palloc((1+VARSIZE(input)-VARHDRSZ)*sizeof(char));
  if (!inp) {
    ereport(ERROR,
            (errcode(ERRCODE_OUT_OF_MEMORY),
             errmsg("Memory allocation failed.")));
    PG_RETURN_NULL();
  }
  memcpy(inp,VARDATA(input),VARSIZE(input)-VARHDRSZ);
  inp[VARSIZE(input)-VARHDRSZ]='\0';

  /* Function internals start here */

  int i;
  int memctr;
  UriPathSegmentA* pathseg;
  int quit;
  char* writehere;
  UriParserStateA state;
  UriUriA uri;

  state.uri = &uri;

  if (uriParseUriA(&state, inp) != URI_SUCCESS) {
    uriFreeUriMembersA(&uri);
/*
    ereport(ERROR,
            (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
             errmsg("Unable to parse URI.")));
*/
    PG_RETURN_NULL();
  }

  if (normalize) {
    if (uriNormalizeSyntaxA(&uri) != URI_SUCCESS) {
      uriFreeUriMembersA(&uri);
      PG_RETURN_NULL();
    }
  }

  UriQueryListA* queryList=NULL;
  int itemCount;
  if (parse_query&&(uri.query.afterLast!=uri.query.first)) {
    if (uriDissectQueryMallocA(&queryList, &itemCount, uri.query.first,
                               uri.query.afterLast) != URI_SUCCESS) {
      uriFreeUriMembersA(&uri);
      uriFreeQueryListA(queryList);
      PG_RETURN_NULL();
    }
  }
    

  /* Function internals finish here */
   
  if (get_call_result_type(fcinfo, NULL, &tupledesc) != TYPEFUNC_COMPOSITE) {
    ereport(ERROR,
            (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
             errmsg("function returning record called in context "
                    "that cannot accept type record")));
    PG_RETURN_NULL();
  }
  /* This error should never happen, because the SQL function is defined
     as returning a uri_type. */

  attinmeta = TupleDescGetAttInMetadata(tupledesc);

  char** retval=(char**) palloc(13*sizeof(char*));
  if (!retval) {
    ereport(ERROR,
            (errcode(ERRCODE_OUT_OF_MEMORY),
             errmsg("Memory allocation failed.")));
    PG_RETURN_NULL();
  }
  if (uri.scheme.afterLast==uri.scheme.first) {
    retval[0]=NULL;
  } else {
    retval[0]=(char*) palloc((1+(uri.scheme.afterLast-uri.scheme.first))*sizeof(char)); /* scheme, e.g. "http" */
    if (!retval[0]) {
      ereport(ERROR,
              (errcode(ERRCODE_OUT_OF_MEMORY),
               errmsg("Memory allocation failed.")));
      PG_RETURN_NULL();
    }
    memcpz(retval[0],uri.scheme.first,uri.scheme.afterLast-uri.scheme.first);
  }
  if (uri.userInfo.afterLast==uri.userInfo.first) {
    retval[1]=NULL;
  } else {
    retval[1]=(char*) palloc((1+(uri.userInfo.afterLast-uri.userInfo.first))*sizeof(char)); /* userInfo, e.g. "gpadmin" */
    if (!retval[1]) {
      ereport(ERROR,
              (errcode(ERRCODE_OUT_OF_MEMORY),
               errmsg("Memory allocation failed.")));
      PG_RETURN_NULL();
    }
    memcpz(retval[1],uri.userInfo.first,uri.userInfo.afterLast-uri.userInfo.first);
  }
  if (uri.hostText.afterLast==uri.hostText.first) {
    retval[2]=NULL;
  } else {
    retval[2]=(char*) palloc((1+(uri.hostText.afterLast-uri.hostText.first))*sizeof(char)); /* hostText, e.g. "192.165.0.0" */
    if (!retval[2]) {
      ereport(ERROR,
              (errcode(ERRCODE_OUT_OF_MEMORY),
               errmsg("Memory allocation failed.")));
      PG_RETURN_NULL();
    }
    memcpz(retval[2],uri.hostText.first,uri.hostText.afterLast-uri.hostText.first);
  }
  if (uri.hostData.ip4==NULL) {
    retval[3]=NULL;
  } else {
    retval[3]=(char*) palloc(17*sizeof(char)); /* IPv4 */
    if (!retval[3]) {
      ereport(ERROR,
              (errcode(ERRCODE_OUT_OF_MEMORY),
               errmsg("Memory allocation failed.")));
      PG_RETURN_NULL();
    }
    memcpy(retval[3],"\\000\\000\\000\\000",17);
    for(i=0;i<4;++i) {
      retval[3][1+4*i]+=uri.hostData.ip4->data[i]>> 6;
      retval[3][2+4*i]+=(uri.hostData.ip4->data[i]>> 3)&7;
      retval[3][3+4*i]+=uri.hostData.ip4->data[i]&7;
    }
  }
  if (uri.hostData.ip6==NULL) {
    retval[4]=NULL;
  } else {
    retval[4]=(char*) palloc(65*sizeof(char)); /* IPv6 */
    if (!retval[4]) {
      ereport(ERROR,
              (errcode(ERRCODE_OUT_OF_MEMORY),
               errmsg("Memory allocation failed.")));
      PG_RETURN_NULL();
    }
    memcpy(retval[4],"\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000",65);
    for(i=0;i<16;++i) {
      retval[4][1+4*i]+=uri.hostData.ip6->data[i]>> 6;
      retval[4][2+4*i]+=(uri.hostData.ip6->data[i]>> 3)&7;
      retval[4][3+4*i]+=uri.hostData.ip6->data[i]&7;
    }
  }
  if (uri.hostData.ipFuture.afterLast==uri.hostData.ipFuture.first) {
    retval[5]=NULL;
  } else {
    retval[5]=(char*) palloc((1+(uri.hostData.ipFuture.afterLast-uri.hostData.ipFuture.first))*sizeof(char)); /* ipFuture, text field */
    if (!retval[5]) {
      ereport(ERROR,
              (errcode(ERRCODE_OUT_OF_MEMORY),
               errmsg("Memory allocation failed.")));
      PG_RETURN_NULL();
    }
    memcpz(retval[5],uri.hostData.ipFuture.first,uri.hostData.ipFuture.afterLast-uri.hostData.ipFuture.first);
  }
  if (uri.portText.afterLast==uri.portText.first) {
    retval[6]=NULL;
  } else {
    retval[6]=(char*) palloc((1+(uri.portText.afterLast-uri.portText.first))*sizeof(char)); /* portText, e.g. "80" */
    if (!retval[6]) {
      ereport(ERROR,
              (errcode(ERRCODE_OUT_OF_MEMORY),
               errmsg("Memory allocation failed.")));
      PG_RETURN_NULL();
    }
    memcpz(retval[6],uri.portText.first,uri.portText.afterLast-uri.portText.first);
  }
  if (uri.pathHead==NULL) {
    retval[7]=NULL;
  } else {
    memctr=2;
    pathseg=uri.pathHead;
    do {
      quit=((pathseg==uri.pathTail)||(pathseg->next==NULL));
      memctr+=3+2*(pathseg->text.afterLast-pathseg->text.first);
      pathseg=pathseg->next;
    } while (!quit);
    if (memctr==2) {
      ++memctr;
    }
    retval[7]=(char*) palloc(memctr*sizeof(char)); /* path */
    /* e.g. "{usr,local,lib}" */
    if (!retval[7]) {
      ereport(ERROR,
              (errcode(ERRCODE_OUT_OF_MEMORY),
               errmsg("Memory allocation failed.")));
      PG_RETURN_NULL();
    }
    writehere=retval[7];
    *writehere='{';
    ++writehere;
    pathseg=uri.pathHead;
    do {
      quit=((pathseg==uri.pathTail)||(pathseg->next==NULL));
      writehere=memenc(writehere,pathseg->text.first,pathseg->text.afterLast-pathseg->text.first);
      *writehere=',';
      ++writehere;
      pathseg=pathseg->next;
    } while (!quit);
    if (memctr!=3) {
      --writehere;
    }
    memcpy(writehere,"}",2);
  }
  if (uri.query.afterLast==uri.query.first) {
    retval[8]=NULL;
  } else {
    retval[8]=(char*) palloc((1+(uri.query.afterLast-uri.query.first))*sizeof(char)); /* query without leading "?" */
    if (!retval[8]) {
      ereport(ERROR,
              (errcode(ERRCODE_OUT_OF_MEMORY),
               errmsg("Memory allocation failed.")));
      PG_RETURN_NULL();
    }
    memcpz(retval[8],uri.query.first,uri.query.afterLast-uri.query.first);
  }
  if (uri.fragment.afterLast==uri.fragment.first) {
    retval[9]=NULL;
  } else {
    retval[9]=(char*) palloc((1+(uri.fragment.afterLast-uri.fragment.first))*sizeof(char)); /* fragment without leading "#" */
    if (!retval[9]) {
      ereport(ERROR,
              (errcode(ERRCODE_OUT_OF_MEMORY),
               errmsg("Memory allocation failed.")));
      PG_RETURN_NULL();
    }
    memcpz(retval[9],uri.fragment.first,uri.fragment.afterLast-uri.fragment.first);
  }
  if (uri.absolutePath) {
    retval[10]=(char*) palloc(5*sizeof(char)); /* absolutePath */
    if (!retval[10]) {
      ereport(ERROR,
              (errcode(ERRCODE_OUT_OF_MEMORY),
               errmsg("Memory allocation failed.")));
      PG_RETURN_NULL();
    }
    memcpy(retval[10],"true",5);
  } else {
    retval[10]=(char*) palloc(6*sizeof(char)); /* absolutePath */
    if (!retval[10]) {
      ereport(ERROR,
              (errcode(ERRCODE_OUT_OF_MEMORY),
               errmsg("Memory allocation failed.")));
      PG_RETURN_NULL();
    }
    memcpy(retval[10],"false",6);
  }

  if (parse_query) {
    int key_counter=2;
    int val_counter=2;
    int counter=0;
    for(UriQueryListA* it=queryList;(counter!=itemCount)&&(it!=NULL);
        it=it->next,++counter) {
      if (it->key==NULL) {
        key_counter+=3; /* should never reach here. */
      } else {
        key_counter+=3+2*strlen(it->key);
      }
      if (it->value==NULL) {
        val_counter+=3; /* currently no way to distinguish empty string
                           value (?a=) from null value (?a). This is a GPDB
                           limitation. */
      } else {
        val_counter+=3+2*strlen(it->value);
      }
    }
    if (key_counter==2) {
      ++key_counter;
    }
    if (val_counter==2) {
      ++val_counter;
    }
    retval[11]=palloc(key_counter*sizeof(char));
    if (!retval[11]) {
      ereport(ERROR,
              (errcode(ERRCODE_OUT_OF_MEMORY),
               errmsg("Memory allocation failed.")));
      PG_RETURN_NULL();
    }
    retval[12]=palloc(val_counter*sizeof(char));
    if (!retval[12]) {
      ereport(ERROR,
              (errcode(ERRCODE_OUT_OF_MEMORY),
               errmsg("Memory allocation failed.")));
      PG_RETURN_NULL();
    }
    retval[11][0]='{';
    retval[12][0]='{';
    char* key_ptr=retval[11]+1;
    char* val_ptr=retval[12]+1;
    counter=0;
    for(UriQueryListA* it=queryList;(counter!=itemCount)&&(it!=NULL);
        it=it->next,++counter) {
      if (it->key==NULL) {
        *key_ptr='"';
        ++key_ptr;
        *key_ptr='"';
        ++key_ptr;
        *key_ptr=',';
        ++key_ptr;
        /* should never reach here. */
      } else {
        key_ptr=strenc(key_ptr,it->key);
        *key_ptr=',';
        ++key_ptr;
      }
      if (it->value==NULL) {
        *val_ptr='"';
        ++val_ptr;
        *val_ptr='"';
        ++val_ptr;
        *val_ptr=',';
        ++val_ptr;
                        /* currently no way to distinguish empty string
                           value (?a=) from null value (?a). This is a GPDB
                           limitation. */
      } else {
        val_ptr=strenc(val_ptr,it->value);
        *val_ptr=',';
        ++val_ptr;
      }
    }
    if (key_counter!=3) {
      --key_ptr;
    }
    memcpy(key_ptr,"}",2);
    if (val_counter!=3) {
      --val_ptr;
    }
    memcpy(val_ptr,"}",2);
    uriFreeQueryListA(queryList);
  } else {
    retval[11]=NULL;
    retval[12]=NULL;
  }

  /* There is no need to call pfree. It's called automatically. */

  HeapTuple tuple;
  Datum result;

  tuple=BuildTupleFromCStrings(attinmeta,retval);
  result=HeapTupleGetDatum(tuple);

  /* Free memory start */
  uriFreeUriMembersA(&uri);
  /* Free memory finish */

  PG_RETURN_DATUM(result);
}